如何在开发Eclipse插件时在View中显示给定内容?

时间:2010-05-22 09:59:22

标签: java eclipse plugins

e.g。我想在我的Eclipse插件的一个视图中显示一个给定的字符串(不是固定的),该怎么做?thx。

bb@feijiao.info

2 个答案:

答案 0 :(得分:1)

如果您按照RCP tutorial,您会看到您可以定义自己的视图:

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() {
    }
}

这将为您提供带有自定义文字的视图。

alt text http://www.vogella.de/articles/RichClientPlatform/images/addview200.gif

如果您保留对用于显示某些文字的org.eclipse.swt.widgets.Text的引用,则可以更改该文字。

答案 1 :(得分:1)

我的解决方案来自VonC的想法。

//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.
...