0
votes

I want to open a View which includes table when operation is executed.

I can open view by viewId by that code:

    display.asyncExec(new Runnable(){

        public void run() {
        ApplicationGIS.getView(true, viewId);

    }});

This view's id defined on plugin.xml but I have to pass some parameters to the table on this view. I can create my custom view programatically but this time i can't open it becuase I don't have its id. Here is my view class:

public class MyCustomView extends ViewPart {

    private Text text;
    private Table table;
    private TableViewer tableViewer;


    @Override
    public void createPartControl(Composite parent) {
        // TODO Auto-generated method stub
        parent.setLayout(new GridLayout(4, false));

        Composite composite = new Composite(parent, SWT.NONE);
        composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1));
        composite.setLayout(new GridLayout(2, false));

        text = new Text(composite, SWT.BORDER);
        text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

        Composite composite_1 = new Composite(composite, SWT.NONE);
        composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
        GridLayout gl_composite_1 = new GridLayout(1, false);
        gl_composite_1.horizontalSpacing = 0;
        gl_composite_1.marginHeight = 0;
        gl_composite_1.marginWidth = 0;
        gl_composite_1.verticalSpacing = 0;
        composite_1.setLayout(gl_composite_1);

        tableViewer = new TableViewer(composite_1, SWT.BORDER | SWT.FULL_SELECTION);

        table = tableViewer.getTable();
        table.setHeaderVisible(true);
        table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    }

    @Override
    public void setFocus() {
        // TODO Auto-generated method stub

    }
}

So how can I access this programmatically created view and open it?

3
What Eclipse version do you use 3.x or 4.x? - Chriss
I am using 3.x. btw I will try your answer, thanks. - cgrgcn

3 Answers

7
votes

In Eclipse 3.x you can open a View like this:

MyView view = (MyView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(viewer_ID);

Or if you are implementing a command handler, you can call:

HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().showView(viewId);

To set some content you can simply add a method like void setInput(MyContent input) to your ViewPart and pass the needed arguments to this method, after opening it.

1
votes

I had the exact same problem. I wanted to create additional views from the one registered in the plugin. These URL's will get you what you want:

http://wiki.eclipse.org/FAQ_How_do_I_open_multiple_instances_of_the_same_view

http://www.java-tips.org/other-api-tips/eclipse/how-to-create-multiple-instances-of-one-viewpart.html

PlatformUI.getWorkbench().getActiveWorkbenchWindow().
getActivePage().showView(String viewID,String secondaryID,int Mode);
0
votes

From @Chriss answer;

I added a method setInput(parameter) to my view and then I can pass my values to my custom view like this

    MyCustomView view = new MyCustomView();     
    view.setInput(parameter);
    display.asyncExec(new Runnable(){

        public void run() {
        ApplicationGIS.getView(true, viewId);


    }});

and this works.