RCP软件包括左侧导航视图、右上部编辑器、右下部属性视图;软件启动后,默认打开左侧导航视图和中下部属性视图,左侧导航树只有三级(Family、Parent和Child),其中Family没有 任何属性,Parent和Child只有三个属性(名称、年龄、性别);导航树能提供右键菜单进行(新建、删除、复制、剪切、粘贴、撤销、重做),给出代码和plugin.xml
时间: 2023-07-10 10:10:04 浏览: 109
以下是一个简单的RCP应用程序的代码和plugin.xml文件:
代码:
```java
package com.example.rcp.application;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
public class RCPApplication extends ApplicationWindow {
public RCPApplication() {
super(null);
}
protected Control createContents(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
container.setLayout(new FillLayout());
return container;
}
protected MenuManager createMenuManager() {
MenuManager menuManager = new MenuManager();
MenuManager fileMenu = new MenuManager("&File");
MenuManager editMenu = new MenuManager("&Edit");
MenuManager helpMenu = new MenuManager("&Help");
menuManager.add(fileMenu);
menuManager.add(editMenu);
menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
menuManager.add(helpMenu);
fileMenu.add(new ExitAction());
editMenu.add(new CopyAction());
editMenu.add(new PasteAction());
helpMenu.add(new AboutAction());
return menuManager;
}
protected void configureShell(Shell shell) {
super.configureShell(shell);
shell.setSize(500, 500);
shell.setText("RCP Application");
PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, "com.example.rcp.application");
}
public static void main(String[] args) {
RCPApplication application = new RCPApplication();
application.setBlockOnOpen(true);
application.open();
Display.getCurrent().dispose();
}
private class ExitAction extends Action {
public ExitAction() {
super("&Exit@Ctrl+Q", PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_QUIT));
}
public void run() {
close();
}
}
private class CopyAction extends Action {
public CopyAction() {
super("&Copy@Ctrl+C", PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
}
public void run() {
// copy logic
}
}
private class PasteAction extends Action {
public PasteAction() {
super("&Paste@Ctrl+V", PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
}
public void run() {
// paste logic
}
}
private class AboutAction extends Action {
public AboutAction() {
super("&About", PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
}
public void run() {
// about dialog
}
}
public static class NavigationView extends ViewPart {
public void createPartControl(Composite parent) {
// navigation view logic
}
public void setFocus() {
// focus logic
}
}
public static class PropertyView extends ViewPart {
public void createPartControl(Composite parent) {
// property view logic
}
public void setFocus() {
// focus logic
}
}
}
```
plugin.xml:
```xml
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension point="org.eclipse.ui.views">
<view
name="Navigation View"
class="com.example.rcp.application.RCPApplication$NavigationView"
id="com.example.rcp.application.navigationView">
</view>
<view
name="Property View"
class="com.example.rcp.application.RCPApplication$PropertyView"
id="com.example.rcp.application.propertyView">
</view>
</extension>
<extension point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension
targetID="org.eclipse.ui.resourcePerspective">
<view
id="com.example.rcp.application.navigationView"
relationship="left"
relative="org.eclipse.ui.views.ResourceNavigator">
</view>
<view
id="com.example.rcp.application.propertyView"
relationship="bottom"
relative="org.eclipse.ui.views.PropertySheet">
</view>
</perspectiveExtension>
</extension>
<extension point="org.eclipse.ui.popupMenus">
<objectContribution
adaptable="false"
id="com.example.rcp.application.copyObjectContribution"
name="Copy">
<action
class="com.example.rcp.application.RCPApplication$CopyAction"
enablesFor="1"
id="com.example.rcp.application.copyAction"
label="Copy">
</action>
<objectClass
name="*">
</objectClass>
</objectContribution>
<objectContribution
adaptable="false"
id="com.example.rcp.application.pasteObjectContribution"
name="Paste">
<action
class="com.example.rcp.application.RCPApplication$PasteAction"
enablesFor="1"
id="com.example.rcp.application.pasteAction"
label="Paste">
</action>
<objectClass
name="*">
</objectClass>
</objectContribution>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.ui.popup.any">
<menu
id="com.example.rcp.application.editMenu"
label="Edit">
<command
commandId="org.eclipse.ui.edit.copy"
id="com.example.rcp.application.copyCommand"
label="Copy">
</command>
<command
commandId="org.eclipse.ui.edit.paste"
id="com.example.rcp.application.pasteCommand"
label="Paste">
</command>
</menu>
</menuContribution>
</extension>
</plugin>
```
请注意,代码和plugin.xml只是示例,并且缺少完整的实现。您需要根据您的应用程序需求进行修改和调整。
阅读全文