- 追加された行はこの色です。
- 削除された行はこの色です。
#topicpath
----
//ここにコンテンツを記述します。
***コンテンツ一覧 [#u25b59e3]
#ls2
----
***目次 [#l0d087c0]
#contents
**とりあえずやってみる [#k6a964ed]
JavaWorldの2004年3月号に特集されていたので、Eclipseのプラグイン開発ツールを触ってみました。
Eclipseはこのプラグインの固まりで、すべての機能はプラグインで作成されているみたいです。ようするにEclipseを機能拡張したい場合はこのプラグインという作法に則って作成するわけですね。
まだ全然やり方がわかりません。とりあえずView(パースペクティブ内の一つのタイルのこと)を拡張して、選択しているファイルのファイル名を表示するプラグインを作成しています。
一番簡単なやり方は
- プラグイン開発 >> プラグイン・プロジェクト >> プロジェクト名~
(プロジェクト名はたとえばnu.mine.kino.sampleとか)
-プラグイン・コード生成プログラム >> デフォルト・プラグイン構造~
(何も追加しない単純なテンプレート)
後はすべてデフォルトでOKでよいです。ウィザードが完了すると、単純なプラグイン・プロジェクトの作成完了です。
基本的な構成はできたので、次はプラグインファイル(plugin.xml)の記述です。手順は
-プラグインエディタの拡張タブ >> 追加 >> 汎用ウィザード >> スキーマベースの拡張
-拡張ポイントを org.eclipse.ui.views を選択
-プラグインエディタの拡張タブより、org.eclipse.ui.viewsを右クリック >> 新規 >> Category を追加(Viewを属させるグループの作成)
-さらに拡張タブより、org.eclipse.ui.viewsを右クリック >> 新規 >> View を追加(実際のViewの作成)
とするとViewを追加できます。後はプロパティViewより必要事項を入力します。
ただのビューを表示するだけなら
<extension point="org.eclipse.ui.views">
<category
name="サンプルMyView" <- viewが属するカテゴリ名
id="com.samples.myview"> <- カテゴリのID
</category>
<view
name="シンプルView" <- viewのバーのタイトル
category="com.samples.myview" <- viewが属するカテゴリID
class="com.samples.myview.SimpleView" <- viewを実装するクラス名
id="com.samples.myview.simpleview"> <- viewのID
</view>
</extension>
で十分です。プロパティViewよりclassを選択すると対応するクラス(ここではcom.samples.myview.SimpleView)のスケルトンもウィザードが作ってくれます。
**覚え書き [#j62d232a]
***サンプルのダウンロード [#w152c277]
ヘルプに リッチ・クライアント・プラットフォーム・アプリケーションのビルド という項目があったので、見てみるとサンプルがEclipseのCVS
:pserver:anonymous@dev.eclipse.org:/home/eclipse
からダウンロード可能とのこと。
*** アクティブなエディタへの参照の取得 [#uf7ea3d1]
// ワークベンチの取得
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
//アクティブなエディタの取得
IEditorPart editor = window.getActivePage().getActiveEditor();
AbstractTextEditor aEditor = (AbstractTextEditor) editor;
*** エディタ内のドキュメントを取得 [#o1b1fa35]
IDocument document =
aEditor.getDocumentProvider().getDocument(editor.getEditorInput());
***プラグインのディレクトリを取得する(2.0系) [#rf1a32e3]
Log4jの初期化のためにlog4j.xmlを読み込むなど、プラグインディレクトリのパスを取得する場面は結構ありますが、その方法です。
String pluginDirectory = Platform
.resolve(getDefault().getDescriptor().getInstallURL()).getPath();
で取得できます。
ちなみにLog4jの初期化などはAbstractUIPluginのサブクラス(勝手に作られるヤツ)で
public void startup() throws CoreException {
super.startup();
String pluginDirectory = null;
try {
pluginDirectory =
Platform
.resolve(getDefault().getDescriptor().getInstallURL())
.getPath();
} catch (IOException e) {
e.printStackTrace();
}
DOMConfigurator.configure(new File(pluginDirectory, "lib/log4j.xml").toString());
}
などとstartup()をOverrideすればよいでしょうか。
***プラグインのディレクトリを取得する(3.0系) [#ae45800c]
Eclipse3.0から上のやり方は deprecated になりました。2.0で
String pluginDirectory = Platform
.resolve(getDefault().getDescriptor().getInstallURL()).getPath();
だったのを3.0では
URL entry = getDefault().getBundle().getEntry("/");
String pluginDirectory = Platform.resolve(entry).getPath();
と書き換えます。
http://www3.vis.ne.jp/~asaki/p_diary/diary.cgi?Date=2004-09-05
***外部のライブラリを使用する [#dc5c9f14]
プラグインディレクトリにlibディレクトリなどを作成しておいて、plugin.xmlで
<runtime>
<library name="hoge.jar"/>
<library name="lib/fuga.jar"/> <-外部ライブラリ
</runtime>
とすればOKです。
*** プロジェクトへの参照を取得する [#u15a6a98]
いわゆるEclipseのプロジェクトへの参照を取得する方法です。
IWorkspaceRoot myWorkspaceRoot =
ResourcesPlugin.getWorkspace().getRoot();
IProject project = myWorkspaceRoot.getProject([プロジェクト名の文字列]);
***ポップアップメニューの拡張 [#sfc14d79]
<extension point="org.eclipse.ui.popupMenus">
<objectContribution
objectClass="org.eclipse.core.resources.IResource" <- ファイルとか、フォルダだったら表示
objectClass="org.eclipse.jdt.core.ICompilationUnit" <- いわゆるソースファイルだったら
objectClass="org.eclipse.core.resources.IFile" <- ファイルだったら表示
objectClass="org.eclipse.core.resources.IFolder" <- フォルダだったら表示
id="nu.mine.kino.IResource">
<action label="スクリプト生成(&R)"
class="nu.mine.kino.HogeAction"
menubarPath="additions" <- すでにあるメニューに追加
enablesFor="1" <- 選択したファイルが1つだけの時有効
id="nu.mine.kino.HogeAction">
</action>
</objectContribution>
</extension>
***デバッグするためのダイアログを出したい [#a91aa3cd]
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
Shell shell = window.getShell();
MessageDialog.openInformation(shell, "タイトル","メッセージ");
が定番でしょう。windowオブジェクトはメソッドを記述するクラスによってはフィールドから得られたりしますが。。
***ウィンドウに配置されているViewを取得する。 [#z76cff34]
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
IViewReference[] references = page.getViewReferences();
for (int i = 0; i < references.length; i++) {
IViewPart view = references[i].getView(false); <- Viewへの参照が取得できました
MessageDialog.openInformation(window.getShell(), "ViewのtoString()", view.toString());
}
***ウィンドウに配置されているViewを、ID指定で取得する。 [#i39484e4]
IWorkbenchPage workbenchPage = editor.getSite().getPage();
try {
HogeView view =
(HogeView) workbenchPage.showView("HogeViewのID");
} catch (PartInitException e) {
}
***おなじViewを複数開く [#t81ac22d]
Eclipse3.0から(だと思う)同じウィンドウを複数開くことができるようです。
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage workbenchPage = workbench
.getActiveWorkbenchWindow().getActivePage();
try {
HogeView view =
(HogeView) workbenchPage
.showView("HogeViewのID", "HogeViewの別のID(Uniqueならよい?)",
IWorkbenchPage.VIEW_ACTIVATE);
} catch (PartInitException e) {
}
http://d.hatena.ne.jp/muimy/20040804 から情報をいただきました。
***プラグインのパッケージング手順 [#i4b96068]
-build.propertiesに、パッケージしたいものを記述する(bin.includesにlib/hoge.jarとかicons/*とか)
-plugin.xmlの右クリック >> Antビルドファイルの作成 でbuild.xml作成
-javac要素はソースコードのエンコーディングが考慮されてないので、追加(encoding="EUC-JP"など)。
-ant zip.pluginでZIPが作成される。
-完了。
トラブル(↓メモ書き状態)
-plugin.xmlの右クリック>>Antビルドファイルの作成 は、コンパイルのエンコーディングが考慮されない(encoding="EUC-JP"などを追加する必要あり)
-build.propertiesに、パッケージしたいものを記述する(bin.includesに書く)
***パッケージ化するとインスタンスを生成できない。 [#kecb2ad7]
[[パッケージ化するとインスタンスを生成できない。:http://groups.yahoo.co.jp/group/eclipse-ml/message/1019?expand=1]]
私も同じトラブルに遭遇しました。
プラグインをパッケージングすると、何故かエラーになってしまうというもの。ビューを開こうとすると
インスタンスを生成できませんでした。
と言われてしまうんだけど、エラーを調べようにもどこにエラーが表示されているのかも分からないので困っていました。
そこでネットを探していたところ、同じような内容の投稿が。とりあえずこれを見て、プラグインのログは
-ウィンドウ→ビューの表示→その他→PDEランタイム→エラー・ログ で「エラーログビュー」を開く。
-エラーログビューで、該当エラーをダブルクリックし「エラーのプロパティー」を開く。
-「状況詳細」を選択します(状況詳細はない場合もあります)。→ここにStackTraceなどが表示されます。
というところまで分かりました。感謝!!
そのエラーログを見ると、xml関連のライブラリがないと。どうもプラグインをパッケージした場合と、ランタイムワークベンチで稼動しているVMのバージョンの違いが原因でした。((WebSphereStudioはJ2SE1.3だったためだ〜))
plugin.xmlに、
<library name="lib/xercesImpl.jar"/>
<library name="lib/xml-apis.jar"/>
を追加して、ようやく動きました。疲れた...。。。
***プラグインがロードされるタイミング [#lf696913]
http://www-6.ibm.com/jp/developerworks/opensource/040604/j_os-ecspy1.html
***拡張ポイントクラス(IExtension)から、そのクラスローダでメソッドを実行する [#ncca9c7b]
-2.1バージョン
// IExtensionからそれが宣言されているプラグインをIPluginDescriptorとして取り出す。
IPluginDescriptor descriptor =
extension.getDeclaringPluginDescriptor();
// そのプラグイン用のクラスローダを取得。
ClassLoader classLoader = descriptor.getPluginClassLoader();
DOMConfigurator configurator = (DOMConfigurator) classLoader
.loadClass("org.apache.log4j.xml.DOMConfigurator")
.newInstance();
-3.0バージョン
String namespace = extension.getNamespace();
Bundle bundleOfExtension = Platform.getBundle(namespace);
DOMConfigurator configurator = (DOMConfigurator) bundleOfExtension
.loadClass("org.apache.log4j.xml.DOMConfigurator")
.newInstance();
***プラグインクラスに必ず定義したいメソッド [#bf1fd810]
public static void log(String message, Exception e) {
IStatus status = new Status(IStatus.ERROR, getPluginId(),
IStatus.ERROR, message, e);
getDefault().getLog().log(status);
}
public static void log(String message) {
log(message, null);
}
public static void log(Exception e) {
StringWriter stringWriter = new StringWriter();
e.printStackTrace(new PrintWriter(stringWriter));
String message = stringWriter.getBuffer().toString();
log(message, e);
}
public static String getPluginId() {
return getDefault().getBundle().getSymbolicName();
}
***リファクタリング >> ストリングの外部化 [#m6e7d7f7]
|チェック|Externalize|外部化して、//$NON-NLS-1$ をつける|
|×|Ignore|以後無視するよう、//$NON-NLS-1$ をつける|
|×'|Internalize|//$NON-NLS-1$ をはずすもしくはなにもしない|
***関連リンク [#dc95429f]
-[[Extension Pointsのリファレンスページ:http://www.eclipse.org/documentation/html/plugins/org.eclipse.platform.doc.isv/doc/reference/extension-points/]]
-[[Eclipseプラグイン・アーキテクチャーに関するノート:http://www.genpaku.org/other/eclipse/plugin_architecturej/plugin_architecture.html]]
-[[プラグイン開発の2.1系のJavaDoc:http://download2.eclipse.org/downloads/documentation/2.0/html/plugins/org.eclipse.platform.doc.isv/reference/api/index.html]]
-[[プラグイン開発の3.0系のJavaDoc:http://www.jlab.net/eclipse/doc/3.0/]]
-[[ObserveEclipse:http://www13.plala.or.jp/observe/index.html]]
-[[パースペクティブのカスタマイズ:http://www.eclipse.org/articles/using-perspectives/PerspectiveArticle.html]]
-[[本家のドキュメントのサイト:http://www.eclipse.org/documentation/main.html]]
-[[JFaceウィザードの開発:http://www-6.ibm.com/jp/developerworks/opensource/030808/j_os-ecjfw.html]]
-[[サンプルコーディング集:http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets]]
-[[プラグイン指向Eclipse開発講座:http://www.javadeveloper.jp/members/regular/Rensai.category_rensai_article_eclipse.dhtml]]
-[[Eclipse Forms Programming Guide:http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/pde-ui-home/working/EclipseForms/EclipseForms.html]]
-[[Preference Dialogのサンプル:http://jssst03.c.u-tokyo.ac.jp/~ichiyama/cgi-bin/hiki/hiki.cgi?PreferenceDialog]]
***IBM developerWorks [#q7277582]
-[[Eclipseのヘルプ・システムを使ってプロジェクトを文書化する:http://www-6.ibm.com/jp/developerworks/opensource/040326/j_os-echelp.html]]
-[[SWTアプリケーションにコンテンツ・アシスタントを備える:http://www-6.ibm.com/jp/developerworks/opensource/040123/j_os-ecca.html]]
-[[EclipseでのJava Development Toolsの拡張:http://www-6.ibm.com/jp/developerworks/opensource/031212/j_os-ecjdt.html]]
-[[ActiveXコントロールをSWTアプリケーションへ統合する:http://www-6.ibm.com/jp/developerworks/opensource/030829/j_os-activex.html]]
-[[Java Web Startを使用して、SWTアプリケーションを配置する:http://www-6.ibm.com/jp/developerworks/opensource/030822/j_os-jws.html]]
-[[Eclipse Workbench以外でのEclipse GUIの使用 第1回: スタンドアロン・モードでJFaceおよびSWTを使用する:http://www-6.ibm.com/jp/developerworks/opensource/030328/j_os-ecgui1.html]]
-[[Eclipse Workbench以外でのEclipse GUIの使用 第2回: JFaceイメージ・レジストリーを使用する:http://www-6.ibm.com/jp/developerworks/opensource/030418/j_os-ecgui2.html]]
-[[Eclipse Workbench以外でのEclipse GUIの使用 第3回: アクション、メニュー、およびツールバーを追加する:http://www-6.ibm.com/jp/developerworks/opensource/030502/j_os-ecgui3.html]]
-[[Eclipseプラグインの国際化対応:http://www-6.ibm.com/jp/developerworks/opensource/020823/j_os-i18n.html]]
-[[国際化対応Eclipseプラグインをテストする:http://www-6.ibm.com/jp/developerworks/opensource/020920/j_os-i18n2.html]]
-[[顧客問題の分析にEclipseツールを活用する方法:http://www-6.ibm.com/jp/developerworks/opensource/030905/j_os-ecdiag.html]]
-[[Runtime SpyでEclipseの起動パフォーマンスを調整する: 第1回:http://www-6.ibm.com/jp/developerworks/opensource/040604/j_os-ecspy1.html]]
***Eclipseのサイトの technical articles [#x17bcc5d]
基本
-[[Creating an Eclipse View:http://www.eclipse.org/articles/viewArticle/ViewArticle2.html]]
-[[Preferences in the Eclipse Workbench UI:http://www.eclipse.org/articles/Article-Preferences/preferences.htm]]
-[[Contributing Actions to the Eclipse Workbench:http://www.eclipse.org/articles/Article-action-contribution/Contributing%20Actions%20to%20the%20Eclipse%20Workbench.html]]
-[[Creating JFace Wizards:http://www.eclipse.org/articles/Article-JFace%20Wizards/wizardArticle.html]]
-[[Simplifying Preference Pages with Field Editors:http://www.eclipse.org/articles/Article-Field-Editors/field_editors.html]]
-[[Branding Your Application:http://www.eclipse.org/articles/Article-Branding/branding-your-application.html]]
-[[Eclipse Rich Client Platform:http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/platform-ui-home/rcp/index.html]]
-[[Take control of your properties:http://www.eclipse.org/articles/Article-Properties-View/properties-view.html]]
難しい
-[[Using Perspectives in the Eclipse UI:http://www.eclipse.org/articles/using-perspectives/PerspectiveArticle.html]]
-[[How to use the JFace Tree Viewer:http://www.eclipse.org/articles/treeviewer-cg/TreeViewerArticle.htm]]
-[[Building and delivering a table editor with SWT/JFace:http://www.eclipse.org/articles/Article-Table-viewer/table_viewer.html]]
-[[Drag and Drop in the Eclipse UI:http://www.eclipse.org/articles/Article-Workbench-DND/drag_drop.html]]
-[[Eclipse Forms Programming Guide:http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/pde-ui-home/working/EclipseForms/EclipseForms.html]]
-[[Handling code samples in Eclipse 3.0:http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/pde-ui-home/working/samples/samples.html]]
-[[Levels Of Integration:http://www.eclipse.org/articles/Article-Levels-Of-Integration/Levels%20Of%20Integration.html]]
-[[On the Job: The Eclipse Jobs API:http://www.eclipse.org/articles/Article-Concurrency/jobs-api.html]]
-[[SWT Standard Widget Toolkit - Development Resources:http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/platform-swt-home/dev.html?rev=HEAD&content-type=text/html]]
**[[Eclipseプラグイン開発:http://yoichiro.cocolog-nifty.com/eclipse/]] [#yd461a90]
#showrss(http://yoichiro.cocolog-nifty.com/eclipse/index.rdf,,24,1)
----
この記事は
#vote(おもしろかった[9],そうでもない[1])
#comment
#topicpath
SIZE(10){現在のアクセス:&counter;}