|
|
Re: How to get the secondary id of a view in a command [message #545510 is a reply to message #545494] |
Thu, 08 July 2010 06:38 |
syeed Messages: 19 Registered: June 2010 |
Junior Member |
|
|
Hi,
Many thanks for your reply. I tried your solution before but it did not work. Actually my problem is as follows: Please take a look,
i have a graph view called "Views.GraphView". I opened different instances of it from a command called "openGraphView" to show different graphs. the command is as follows:
page.showView("Views.GraphView", Integer.toString(instanceNum++), IWorkbenchPage.VIEW_ACTIVATE);
Now, I have a command called "TreeLayout" on this "Views.GraphView" toolbar, which suppose to change the layout of the graph and it will operate on each instace of the view. But for this, i think, i need to identify which instance of the view is active. the command is as follows:
IViewPart findView = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage(). findView( "Views.GraphView"); //i think in the findView i need to give the id of the view [but how can i put the secondary id!!]
GraphView view = (GraphView) findView;
view.changeLayout(); //i wrote this method in the graph view to change the layout
//i just tried to print the secondary id, but it did not print anyting
System.out.println("From treelayout command:- " + view.getViewSite().getSecondaryId());
Please, provide some solution.
Thanks,
-Syeed
[Updated on: Thu, 08 July 2010 06:39] Report message to a moderator
|
|
|
Re: How to get the secondary id of a view in a command [message #545558 is a reply to message #545510] |
Thu, 08 July 2010 08:29 |
Daniel Krügler Messages: 853 Registered: July 2009 |
Senior Member |
|
|
On 08.07.2010 08:38, syeed wrote:
> Hi,
> Many thanks for your reply. I tried your solution before but it did not
> work. Actually my problem is as follows: Please take a look,
>
> i have a graph view called "Views.GraphView". I opened different
> instances of it from a command called "openGraphView" to show different
> graphs. the command is as follows:
> page.showView("Views.GraphView", Integer.toString(instanceNum++),
> IWorkbenchPage.VIEW_ACTIVATE);
> Now, I have a command called "TreeLayout" on this "Views.GraphView"
> toolbar, which suppose to change the layout of the graph and it will
> operate on each instace of the view. But for this, i think, i need to
> identify which instance of the view is active. the command is as follows:
>
> IViewPart findView =
> HandlerUtil.getActiveWorkbenchWindow(event).getActivePage(). findView(
> "Views.GraphView");
The documentation doesn't say it well, but I believe you need to
change the call to
IViewPart findView =
HandlerUtil.getActiveWorkbenchWindow(event).getActivePage(). findView(
/primaryId/ + ":" + /secondaryId/);
where /primaryId/ = "Views.GraphView" and
/secondaryId/ = Integer.toString(instanceNum++) in your example.
What definitively works is the overload provided findViewReference
which accepts a secondary id. Now you can obtain the view from
the view reference via the getView method.
HTH & Greetings from Bremen,
Daniel Krügler
|
|
|
|
|
Re: How to get the secondary id of a view in a command [message #545983 is a reply to message #545718] |
Fri, 09 July 2010 19:18 |
syeed Messages: 19 Registered: June 2010 |
Junior Member |
|
|
Hi,
Thanks for your reply. I tried org.eclipse.ui.handlers.HandlerUtil.getActivePart(ExecutionE vent), in my TreeLayout command and correctly identifies the current active instane of a view.
But my main problem is not solved yet.. When i tried to apply the command to one instance, it changes all the instances. I think the problem is somwhere else. I am explaining my problem bellow with the code. Please take a look.. I am preety sure you can provide solution.
I have a GraphViewer in the view (GraphView)which displays graphs. Now different instance of the view displays different graphs. Graph contents are provided by the content providers.
Then in TreeLayout command I identity the corrent active instance of the GraphView(using the method provided earlier), 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.
My code is someting like this:
//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.
//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<GraphNode> 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04050 seconds