Top / Eclipse / プラグイン開発のTIPS集 / ヘルプを実装する

Eclipseのヘルプはワークベンチのメニューの

ヘルプ >> ヘルプ目次

にありますが、このhtmlベースのヘルプも拡張して好きなヘルプを載せることができます。そして拡張するための拡張ポイントがorg.eclipse.help.toc拡張ポイントです。

この拡張ポイントで目次となるファイル(xml形式)を指定し、そのxmlファイルで目次に対応するhtmlファイルを指定します。

拡張ポイント

org.eclipse.help.toc

必須プラグイン

org.eclipse.help.appserver
org.eclipse.help.base
org.eclipse.help.ui
org.eclipse.help.webapp
org.eclipse.tomcat

plugin.xmlのサンプル

<extension
    point="org.eclipse.help.toc">
   <toc primary="true" file="toc.xml"/>  <-トップの目次となるxmlファイル。
   <toc file="tocconcepts.xml"/>
   <toc file="tocgettingstarted.xml"/>
   <toc file="tocreference.xml"/>
   <toc file="tocsamples.xml"/>
   <toc file="toctasks.xml"/>
</extension>

目次となるxml(ここではtoc.xml)のサンプル

<?xml version="1.0" encoding="UTF-8"?>
<?NLS TYPE="org.eclipse.help.toc"?>

<toc label="Sample Table of Contents" topic="html/toc.html">
↑目次のSample Table of Contents をクリックしたときに
  表示されるhtmlはhtml/toc.htmlです、の意味
   <topic label="Getting Started">
      <anchor id="gettingstarted"/>
   </topic>
   <topic label="Concepts"> <-目次にConceptsと表示
      <anchor id="concepts"/> <-toc.xml#conceptsとなってる箇所をここに挿入
   </topic>
   <topic label="Tasks">
      <anchor id="tasks"/>
   </topic>
   <topic label="Reference">
      <anchor id="reference"/>
   </topic>
   <topic label="Samples">
      <anchor id="samples"/>
   </topic>
</toc>

<anchor id="concepts"/> でリンクされるtocconcepts.xml

<?xml version="1.0" encoding="UTF-8"?>
<?NLS TYPE="org.eclipse.help.toc"?>

<toc label="Concepts" link_to="toc.xml#concepts"> <-ここでリンクされてる
  <topic label="Main Topic"  href="html/concepts/maintopic.html"> 
    <topic label="Sub Topic" href="html/concepts/subtopic.html" /> 
  </topic>
  <topic label="Main Topic 2">
    <topic label="Sub Topic 2" href="html/concepts/subtopic2.html" /> 
  </topic> 
</toc>
capture.png

ポイント

htmlファイル群は圧縮できる。

目次ファイル内で別の目次ファイルを指定できる

ヘルプメニューからではなく、アクションやボタンなどでヘルプを起動する

ヘルプメニューの「ヘルプ目次」は

ActionFactory.HELP_CONTENTS.create(window)

でアクションを取得できます。このクラスは実体は

org.eclipse.ui.internal.actions.HelpContentsAction

なのですが、このrunメソッドからヘルプの起動方法を拝借しました。なかでは以下のようなことをやってます。

final IWorkbenchWindow workbenchWindow = getSite().getWorkbenchWindow();
if (workbenchWindow == null) {
  // action has been disposed
  return;
}
// This may take a while, so use the busy indicator
BusyIndicator.showWhile(null, new Runnable() {
  public void run() {
    workbenchWindow.getWorkbench().getHelpSystem()
        .displayHelp();
  }
});

これでヘルプが起動できます。

ヘルプから、プログラムを呼び出す

org.eclipse.help.ILiveHelpAction? クラスを使うと、ヘルプ上からプログラムを呼び出すことができます。例えば、ヘルプで「下のリンクをクリックするとパースペクティブを変更します」なんてリンクを作ることができるわけです。Eclipseのヘルプってようするにhtmlなわけですが、htmlからクライアントのプログラムが起動できるのって、レガシーなJ2EEを作ってきた私からすると、なんか衝撃的です。

関連リンク


この記事は

選択肢 投票
おもしろかった 2  
そうでもない 0  

Top / Eclipse / プラグイン開発のTIPS集 / ヘルプを実装する

現在のアクセス:15847


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