【发布时间】:2010-05-22 09:59:22
【问题描述】:
例如我想在我的 Eclipse 插件的一个视图中显示一个给定的字符串(不是固定的),怎么做?thx。
bb@feijiao.info
【问题讨论】:
例如我想在我的 Eclipse 插件的一个视图中显示一个给定的字符串(不是固定的),怎么做?thx。
bb@feijiao.info
【问题讨论】:
如果你关注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 的引用,则可以更改该文本。
【讨论】:
我的解决方案来自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.
...
【讨论】: