tags:

views:

21

answers:

0

Hi,

I have some problem managing the RCP Views and commands. In my application, I have a view (GraphView, its a ViewPart) which displays graphs using GraphViewer (ZEST graph viewer). Now different instance of the view(GraphView) displays different graphs. Graph contents are provided by the content providers.

Then in a command (TreeLayout command) I identity the current active instance of the GraphView, then get the GraphViewer in it and try to change the layout and node names. But the problem is, If i change the layout or rename any node it automatically applied to all the instances of the GraphView. Also if I close the last instace of the GraphView, then the command did not work at all for the others. How can i solve it? Its really a problem for me.. please help.

Follwoing is the code snippest.

First, i gave the GrahView class,which holds the GraphViewer. Then, the TreeLayout command that suppose to change the layout and node names in the current active instance of the GraphView.

//view to create graphs.

public class GraphView extends ViewPart implements IZoomableWorkbenchPart{

public static final String ID = "Views.GraphView"; static GraphViewer viewer = null;

public void createPartControl(Composite parent) {

//creates the GraphViewer viewer = new GraphViewer(parent, SWT.NONE);

//setting the content provider for the graph. viewer.setContentProvider( new GraphViewContentProvider());

//setting the lable provider for the graph viewer.setLabelProvider(new GraphViewLabelProvider());

//setting the initial layout for the graph. viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING)) ; viewer.setInput(new Object());

//creating the toolbar to hold the zoom menu. fillToolBar(); }

/** Returns the GraphViewer. this method is called from TreeLayout command/ public GraphViewer getGraphViewer() { return viewer; }

/** * Passing the focus request to the viewer's control. */ public void setFocus() { //viewer.getControl().setFocus(); }

private void fillToolBar() { ZoomContributionViewItem toolbarZoomContributionViewItem = new ZoomContributionViewItem(this); IActionBars bars = getViewSite().getActionBars(); bars.getMenuManager().add(toolbarZoomContributionViewItem); }

@Override public AbstractZoomableViewer getZoomableViewer() { return viewer; }

}

TreeLayout command: Identify the current active instace of the GraphView and change the layout and node name in the GraphViewer of that instance. It has the following code:

//Get the current active instance of the GraphView IWorkbenchPart view = org.eclipse.ui.handlers.HandlerUtil.getActivePart(event); IViewPart part = (IViewPart)view; GraphView gView = (GraphView)part;

//Get the GraphViewer on this GraphView. GraphViewer viewer = gView.getGraphViewer();

//Change the layout. But I applied to the last opened instance of the GraphView.. not on others. viewer.setLayoutAlgorithm(new TreeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);

//change the node name of the graph. But it changes node names in the current active instance as well as all the instance opende after it. List nodeList = viewer.getGraphControl().getNodes(); for (Object c : nodeList) ((GraphNode) c).setText("rajit");

OpenGraphView command: Opens different instances of the GraphView with secondary id's.

page.showView("Views.GraphView", "secondaryId"+ Integer.toString(instanceNum++), IWorkbenchPage.VIEW_ACTIVATE);

Many thanks in advance.

-Syeed

related questions