views:

71

answers:

2

e.g. I'd like to show one given string(not fixed one) in one view of my Eclipse plugin,how to do it?thx.

[email protected]

+1  A: 

If you follow the RCP tutorial, you will see that you can define your own view:

package de.vogella.rcp.intro.view;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;

public class MyView extends ViewPart {

    @Override
    public void createPartControl(Composite parent) {
        Text text = new Text(parent, SWT.BORDER);
        text.setText("Imagine a fantastic user interface here");
    }

    @Override
    public void setFocus() {
    }
}

That will give you a View with a custom text.

alt text

If you keep a reference to the org.eclipse.swt.widgets.Text used to display some text, you can change that text.

VonC
Well,I wanna open one view defined by myself by clicking PopupMenu.I need to get the selected file(s) to do sth.,then,display some things in the View.How to keep a reference to the Text or things like that?I think the view is initialized by WorkBench or sth. although it's defined by myself...
@user347744: if it is defined by yourself, you can specialize that class with any method you need, including one setting text on the SWT Text field. No need to keep a *direct* reference to the field itself. Only one the right View defined by you.
VonC
@VonC: thank you very much,I think I found the solution.
@user347744: that is great. You could post details of your solution as an answer for other to use. If you want you can even accept your own answer as the official one for this question.
VonC
@VonC: Can I ask you one question about Eclipse plugin?
@user347744: it would be better to ask it as a new question on Stack Overflow, for me *and others* to answer ;)
VonC
@VonC: well,I asked this question a few days ago,but no response.So I wanna get one expert or big guy to help.Here is the link:http://stackoverflow.com/questions/2902732/on-eclipse-plug-inhow-to-implement-such-a-property-viewMaybe I did not spell it out yet...Thx. for your concern.
+1  A: 

my solution from VonC's thought.

//below codes are working for View.
//variable to keep reference to Canvas
private Canvas canvas = null;
...

//copy
public void createPartControl(Composite parent) {
    Canvas canvas = new Canvas(parent, SWT.BORDER | 
            SWT.NO_MERGE_PAINTS | SWT.NONE );
    this.canvas = canvas;
}

//...

//one getter method to get canvas
public Canvas getCanvas(){
    return this.canvas;
}
//////////////////////////////////
//////////////////////////////////
//below codes are working in PopupMenu's action
page.showView("org.act.bpel2automata.views.GraphView");
IViewPart view = page.findView("org.act.bpel2automata.views.GraphView");

//GraphView is defined by myself,               
if(view instanceof GraphView){
    GraphView gView = (GraphView)view;
    Canvas canvas = gView.getCanvas();
}

//other operations,like draw lines or sth.
...
Great feedback! +1
VonC