1. 控制窗口ApplicationWorkbenchWindowAdvisor
public void preWindowOpen() {
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
//窗口大小,它会自动记录上次关闭时的大小,下次打开时按保存的大小
configurer.setInitialSize(newPoint(400, 300));
configurer.setShowCoolBar(false);
configurer.setShowStatusLine(true);//状态栏
configurer.setTitle("Hello RCPViewer"); //窗口标题
}
CoolBar是一大块区域,包含一个个的toolBar,toolBar里是一个个的小工具按钮。
2. 创建View类
public class MyLabelView extends ViewPart {
public staticfinal String ID="com.gathershell.view.MyLabelView";
private Label label;
public MyLabelView() {
// TODO Auto-generated constructor stub
}
@Override
public voidcreatePartControl(Composite parent) {
label=newLabel(parent,SWT.VERTICAL);
label.setText("HelloView!");
}
@Override
public voidsetFocus() {
// TODO Auto-generated method stub
}
}
ID是一个惟一标识,一般用全路径类名。
3. 在plugin.xml中配置
<extension
point="org.eclipse.ui.views">
<view
name="Label View"
allowMultiple="true"
icon="icons/sample2.gif"
class="com.gathershell.view.MyLabelView"
id="com.gathershell.view.MyLabelView">
</view>
</extension>
4. 控件布局
public class Perspective implements IPerspectiveFactory {
public voidcreateInitialLayout(IPageLayout layout) {
StringeditorArea = layout.getEditorArea();
layout.setEditorAreaVisible(false);
layout.addStandaloneView(MyLabelView.ID, false, IPageLayout.LEFT,0.25f, editorArea);
}
}
然后运行即可。有时作了修改,却看不到变化。这可能是由于某种原因,没有将修改同步过去。这时到与工作空间同级的目录下,删除runtime-RCPViewLearn.application这个文件件即可。RCPViewLearn这个是我所创建的project名字。