- 追加された行はこの色です。
- 削除された行はこの色です。
#topicpath
----
#contents
**概要 [#lc70b365]
Eclipseのプラグインを勉強しているついでに、Eclipse3.0で導入されたRCPを使ってみました。RCPとはEclipseベース(ワークベンチベースっていったほうがいいかもしんない)のアプリケーションを作成するためのフレームワークです。今まではプラグインを作って、Eclipseにプラグインしてたわけですが、プラグインが単体で稼働するようになったと考えればよいと思います。
前々からEclipseをベースにして、開発ツール(WebSphereStudioみたいなパターン)だけでなく普通のアプリケーションもこの上で構築できるんでないのってかんがえてたんですが、まさにそのためのフレームワークみたいですね。
手順はプラグインを作るのと基本的に一緒です。必ず作らなくちゃいけないモノは
-org.eclipse.core.runtime.IPlatformRunnable の実装クラス(実際のアプリケーションになります)
-org.eclipse.ui.application.WorkbenchAdvisor のサブクラス(ワークベンチの設定をします)
-org.eclipse.ui.IPerspectiveFactory の実装クラス(パースペクティブを構築します)
です。
***IPlatformRunnable の実装クラス [#l49f6af6]
IPlatformRunnable の実装クラスはrunメソッドをオーバーライドすればよいようです。たぶんおきまりで、こんな感じ。
public Object run(Object args) throws Exception {
// WorkbenchAdvisorの作成
WorkbenchAdvisor advisor = new SampleWorkbenchAdvisor();
Display display = PlatformUI.createDisplay();
try {
int ret = PlatformUI.createAndRunWorkbench(display, advisor);
if (ret == PlatformUI.RETURN_RESTART) {
return IPlatformRunnable.EXIT_RESTART;
} else {
return IPlatformRunnable.EXIT_OK;
}
} finally {
display.dispose();
}
}
***WorkbenchAdvisor のサブクラス [#s83eece8]
ワークベンチ(ウィンドウとか、外枠、みたいなイメージ)を構築する設定を行います。RCPアプリケーションはパースペクティブを一つ持つのですが、そのパースペクティブID(plugin.xmlで指定したID)を返すメソッドをオーバーライドします。
public String getInitialWindowPerspectiveId() {
return "nu.mine.kino.sample.SamplePerspectiveFactory";
}
***IPerspectiveFactory の実装クラス [#l2b25add]
RCPアプリケーションで使用するパースペクティブを構築します。たとえばこんな感じ。
public void createInitialLayout(IPageLayout layout) {
layout.addView("nu.mine.nu.sample.SampleView", IPageLayout.TOP,
IPageLayout.RATIO_MAX, IPageLayout.ID_EDITOR_AREA);
}
("nu.mine.nu.sample.SampleView"というIDのビューをパースペクティブにセット、の意味)
**実際にやってみる。 [#c69ff7cc]
-新規 >> プラグイン・プロジェクト を選択。
-プロジェクト名に nu.mine.kino.sample と入れて「次へ」をクリック
#ref(01.png)
#ref(02.png)
-plugin.xmlのエディタが起動するので、Dependenciesで
org.eclipse.ui
org.eclipse.core.runtime
を追加。
-Extensionsで使用する拡張ポイントを追加。追加する拡張ポイントは
org.eclipse.ui.perspectives
org.eclipse.core.runtime.applications
です。''org.eclipse.core.runtime.applications はIdを指定するのを忘れないようにしましょう。''
#ref(04.png)
-上の拡張ポイントに追加したapplicationやperspectiveの具象クラスを作成します。エディタからclass*:をクリックするとテンプレートを作成してくれます。ここでは
nu.mine.kino.sample.SampleApplication
nu.mine.kino.sample.SamplePerspectiveFactory
というID/Class名のクラスを作成しました。最終的にplugin.xmlの内容は以下のようになりました。
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<plugin
id="nu.mine.kino.sample"
name="Sample プラグイン"
version="1.0.0"
provider-name="">
<runtime>
<library name="sample.jar">
<export name="*"/>
</library>
</runtime>
<requires>
<import plugin="org.eclipse.ui"/>
<import plugin="org.eclipse.core.runtime"/>
</requires>
<extension
id="SampleApplication"
point="org.eclipse.core.runtime.applications">
<application>
<run class="nu.mine.kino.sample.SampleApplication"/>
</application>
</extension>
<extension
point="org.eclipse.ui.perspectives">
<perspective
class="nu.mine.kino.sample.SamplePerspectiveFactory"
name="サンプル・パースペクティブ"
id="nu.mine.kino.sample.SamplePerspectiveFactory"/>
</extension>
</plugin>
-プラグインエディタから作成したクラス2つに上で書いた内容を(とりあえず)記述します。またWorkbenchAdvisorのサブクラスも自分で作成し、上のメソッドをオーバーライドしておきます。
最終的に以下のファイルができあがりました。
#ref(SampleApplication.java)
#ref(SamplePerspectiveFactory.java)
#ref(SampleWorkbenchAdvisor.java)
#ref(plugin.xml)
***いよいよ実行 [#aef8b688]
いよいよ実行します。ランタイムワークベンチを作成して、プラグインを起動するようにやればよいのですが、ポイントは実行するプログラムを自分が作成した、IPlatformRunnable の実装クラスにすることです。
#ref(05.png)
また、プラグインおよびフラグメントタブ内で、自分が作成したプラグインと依存しているプラグインだけにチェックを入れておきます((すべてを非選択にして、自分のプラグインを選択、でAdd Required Plug-insをクリック))。
#ref(06.png)
以上でランタイムワークベンチを起動すると、何にもビューを配置していない空のアプリケーションが起動しました!!
#ref(07.png)
コンソールに"nu.mine.nu.sample.SampleView"なんてビューねえよって出てますが、作ってないですからね。拡張ポイントから拡張してビューを作れば表示されました。。
***products拡張ポイントについて [#v89ca80d]
Eclipseのサイトに[[Branding your application:http://www.eclipse.org/articles/Article-Branding/branding-your-application.html]]という記事が出ていました。ようするにEclipseベースのRCPアプリケーションにスプラッシュスクリーンを追加したり、独自のアイコンのExeファイルを作成したり、〜についてなどというバージョン表示のダイアログを追加するなど、製品アプリケーションのようにするための方法を説明しています。
さてorg.eclipse.core.runtime.applications 拡張ポイントでアプリケーションを作成しましたが、上のような様々な機能を追加するにはapplications拡張ポイントに加え、更に別の拡張ポイント、org.eclipse.core.runtime.products拡張ポイントを使用します。
<extension id="product" <-このIDを指定しないと、使えない!注意!!
point="org.eclipse.core.runtime.products">
<product
name="%productName"
application="nu.mine.kino.sample.SampleApplication">
↑[プラグインのID].[org.eclipse.core.runtime.applicationsポイントのid属性]
</extension>
あとはpropertyタグでさまざまなプロパティを設定することで機能を追加していきます。設定できるプロパティ値は[[RCPをBrandingするときに使うプロパティ値>Eclipse/プラグイン開発のTIPS集/RCPをBrandingするときに使うプロパティ値]]や[[RCPの製品情報などの画面を追加する>Eclipse/プラグイン開発のTIPS集/RCPの製品情報などの画面を追加する]]を参照してください。
----
この記事は
#vote(おもしろかった[4],そうでもない[0])
-Good site! <a href="http://astra.sitesfree.com/acyclovir.html">acyclovir</a> <a href="http://astra.sitesfree.com/adipex.html">adipex</a> <a href="http://astra.sitesfree.com/allegra.html">allegra</a> <a href="http://astra.sitesfree.com/alprazolam.html">alprazolam</a> <a href="http://astra.sitesfree.com/ambien.html">ambien</a> [url=http://astra.sitesfree.com/acyclovir.html]acyclovir[/url] [url=http://astra.sitesfree.com/adipex.html]adipex[/url] [url=http://astra.sitesfree.com/allegra.html]allegra[/url] [url=http://astra.sitesfree.com/alprazolam.html]alprazolam[/url] [url=http://astra.sitesfree.com/ambien.html]ambien[/url] -- [[Valerio]] &new{2006-11-07 13:38:33 (火)};
-http://www.forum-hoster.de/phpbb/?mforum=promdresses <a href="http://www.forum-hoster.de/phpbb/?mforum=promdresses">prom dresses</a> prom dresses -- [[prom dresses]] &new{2006-11-08 15:45:37 (水)};
-Hi, nice site http://zzzc.forumcommunity.net/ <a href=http://zzzc.forumcommunity.net/>bankruptcy</a> -- [[Kal]] &new{2006-11-09 18:30:24 (木)};
-http://www.forumfactory.com/cgi-bin/fserver1/foren/F_0727/cutecast.pl <a href="http://www.forumfactory.com/cgi-bin/fserver1/foren/F_0727/cutecast.pl">Christmas gifts</a> Christmas gifts -- [[Christmas gifts]] &new{2006-11-11 07:43:50 (土)};
#comment
#topicpath
SIZE(10){現在のアクセス:&counter;}