#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])
-http://halloween.kilu.de/ <a href="http://halloween.kilu.de/">halloween costumes</a> halloween costumes -- [[halloween costumes]] &new{2006-10-17 00:06:48 (火)};
-http://www.blog.newsjungle.com/promdresses/ <a href="http://www.blog.newsjungle.com/promdresses/">prom dresses</a> prom dresses -- [[prom dresses]] &new{2006-10-17 00:44:01 (火)};
-Hi all[URL="http://halloween.kilu.de/newborn-halloween-costumes.html"]newborn halloween costumes[/URL]http://halloween.kilu.de/baby-halloween-costumes.html<a href="http://halloween.kilu.de/halloween-costumes-for-children.html">halloween costumes for children</a>[URL="http://halloween.kilu.de/boys-halloween-costumes.html"]boys halloween costumes[/URL][URL="http://halloween.kilu.de/quick-easy-halloween-costumes.html"]quick easy halloween costumes[/URL][URL="http://halloween.kilu.de/discount-halloween-costumes.html"]discount halloween costumes[/URL]http://halloween.kilu.de/halloween-costumes.htmlhttp://halloween.kilu.de/kids-halloween-costumes.htmlhttp://halloween.kilu.de/halloween-costumes-for-babies.html[URL="http://halloween.kilu.de/childrens-halloween-costumes.html"]children's halloween costumes[/URL] -- [[Bush]] &new{2006-10-17 09:50:00 (火)};
-http://blogshot.nl/replicas <a href="http://blogshot.nl/replicas">replica watches</a> replica watches -- [[replica watches]] &new{2006-10-17 22:41:38 (火)};
-http://www.anyboard.net/suggest/posts/3921.html  <a href="http://www.anyboard.net/suggest/posts/3921.html">buy viagra</a> buy viagra -- [[buy viagra]] &new{2006-10-18 18:45:53 (水)};
-http://www.anyboard.net/suggest/posts/3924.html <a href="http://www.anyboard.net/suggest/posts/3924.html">halloween costumes</a> halloween costumes -- [[halloween costumes]] &new{2006-10-18 19:16:49 (水)};
-<a href="http://www.anyboard.net/suggest/posts/4316.html">ringtones</a><a href="http://www.anyboard.net/suggest/posts/4320.html">free ringtones</a><a href="http://www.anyboard.net/suggest/posts/4317.html">download free ringtones</a><a href="http://www.anyboard.net/suggest/posts/4318.html">free nokia ringtones</a><a href="http://www.anyboard.net/suggest/posts/4332.html">ringtone</a><a href="http://www.anyboard.net/suggest/posts/4331.html">polyphonic ringtones</a><a href="http://www.anyboard.net/suggest/posts/4333.html">verizon ringtones</a><a href="http://www.anyboard.net/suggest/posts/4327.html">free sprint ringtones</a><a href="http://www.anyboard.net/suggest/posts/4329.html">nextel ringtones</a><a href="http://www.anyboard.net/suggest/posts/4328.html">motorola ringtones</a>http://www.anyboard.net/suggest/posts/4316.htmlhttp://www.anyboard.net/suggest/posts/4320.htmlhttp://www.anyboard.net/suggest/posts/4317.htmlhttp://www.anyboard.net/suggest/posts/4318.htmlhttp://www.anyboard.net/suggest/posts/4332.htmlhttp://www.anyboard.net/suggest/posts/4331.htmlhttp://www.anyboard.net/suggest/posts/4333.htmlhttp://www.anyboard.net/suggest/posts/4327.htmlhttp://www.anyboard.net/suggest/posts/4329.htmlhttp://www.anyboard.net/suggest/posts/4328.html -- [[ringtones]] &new{2006-10-20 03:05:19 (金)};

#comment
#topicpath


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


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