#author("2021-12-14T02:32:22+00:00","","")
#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])
-Tyoma - loh )))))<a href="http://www.megspace.com/internet/afreeringtones/">free ringtones</a>http://www.megspace.com/internet/afreeringtones/ringtones-free.htmlhttp://www.megspace.com/internet/afreeringtones/free-motorola-ringtones.htmlhttp://www.megspace.com/internet/afreeringtones/<a href="http://www.megspace.com/internet/afreeringtones/free-ringtones.html">free ringtones</a><a href="http://www.megspace.com/internet/afreeringtones/ringtones-free.html">ringtones free</a>http://www.megspace.com/internet/afreeringtones/free-verizon-ringtones.html<a href="http://www.megspace.com/internet/afreeringtones/free-cell-phone-ringtones.html">free cell phone ringtones</a><a href="http://www.megspace.com/internet/afreeringtones/free-cingular-ringtones.html">free cingular ringtones</a>http://www.megspace.com/internet/afreeringtones/free-verizon-ringtones.html -- [[Pinouk]] &new{2006-10-22 20:15:00 (日)};
-http://www.megspace.com/family/hallowencostume/  <a href="http://www.megspace.com/family/hallowencostume/">halloween costumes</a> halloween costumes -- [[halloween costumes]] &new{2006-10-23 20:17:38 (月)};
-http://www.soduko.org/weblogs/?u=halloweencostumes  <a href="http://www.soduko.org/weblogs/?u=halloweencostumes">halloween costumes</a> halloween costumes -- [[halloween costumes]] &new{2006-10-27 18:32:41 (金)};
#vote(おもしろかった[25],そうでもない[3])

#comment
#topicpath


SIZE(10){現在のアクセス:&counter;}


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS