tags:

views:

15

answers:

2

Hi,

I am creating a RCP application. I need to open multiple instances of the same view but with different data. I did it by setting secondary id for different instances of the same view. Specifically, 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 "TreeLayout" command looks something like this:

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());

So how can i identify whcih instance of the view is currently active and to operate on it? Please, provide some solution.

Thanks,

-Syeed

A: 

The view.getViewSite().getSecondaryId() method is the good one to identify a secondary view. This method only returns the Null string for the "primary" view: the one opened when user click Window -> Show View - Your View.

I don't understand why your view toolbar button has to operate on all the view instances. TO my eyes, you should have one button in each view instance toolbar operating only in its own view. If you really need to operate from one button to ALL the views I think you will have to keep the open views references yourself, because I think the workbench doesn't provide a findViews method returning a view array.

Manuel Selva
A: 

hi, i tried your first solution but it did not work. And i did not get your second solution properly. In my application a toolbar button appears for each instance of the view. but it worked only for the last instance of the view.

can you please, tell me how can i create a button for each view instance and make it working for that.

Thanks in advance, -syeed

syeed

related questions