【Java】EclipseRCPアプリ作成の基本。【GUI】
はじめに
EclipseRCPアプリケーションを作るための基本中の基本を纏めてみました。
ここではViewに何も表示されていないカラッポのウィンドウアプリを作ってみます。
!注意!
必要なライブラリはすでに組み込まれている前提で記述します。
ちなみにeclipseで plug-in project を作成すれば必要なライブラリは自動的に読み込まれます。
最も基本となるクラス
最も基本となるクラスはこれら。
- Application
- Perspective
- ApplicationActionBarAdvisor
- ApplicationWorkbenchAdvisor
- ApplicationWorkbenchWindowAdvisor
Application.java
public class Application implements IPlatformRunnable {
public Object run(Object args) throws Exception {
Display display = PlatformUI.createDisplay();
try {
int returnCode = PlatformUI.createAndRunWorkbench(display,
new ApplicationWorkbenchAdvisor());
if (returnCode == PlatformUI.RETURN_RESTART) {
return IPlatformRunnable.EXIT_RESTART;
}
return IPlatformRunnable.EXIT_OK;
} finally {
display.dispose();
}
}
}
Perspective.java
public class Perspective implements IPerspectiveFactory {
public void createInitialLayout(IPageLayout layout) {
}
}
ApplicationActionBarAdvisor.java
public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
super(configurer);
}
protected void makeActions(IWorkbenchWindow window) {
}
protected void fillMenuBar(IMenuManager menuBar) {
}
}
ApplicationWorkbenchAdvisor.java
public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
private static final String PERSPECTIVE_ID = "rcpdemo.perspective";
public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
return new ApplicationWorkbenchWindowAdvisor(configurer);
}
public String getInitialWindowPerspectiveId() {
return PERSPECTIVE_ID;
}
}
ApplicationWorkbenchWindowAdvisor.java
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
super(configurer);
}
public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) {
return new ApplicationActionBarAdvisor(configurer);
}
public void preWindowOpen() {
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setInitialSize(new Point(400, 300));
configurer.setShowCoolBar(false);
configurer.setShowStatusLine(false);
configurer.setTitle("Hello RCP");
}
}
スタンドアロンなアプリとしてエクスポート
Eclipseプロジェクトエクスプローラから右クリックでExportを行なえば単独アプリとして出力することが出来ます。
RCPアプリの起動設定は configuration/config.ini に記述されています。
参考
Rich Client Tutorial Part 1
http://www.eclipse.org/articles/Article-RCP-1/tutorial1.html
RCPのチラシノウラ
http://goodjob.boy.jp/chirashinoura/search/RCP.html