Eclipseのメニューバーやポップアップメニューは org.eclipse.ui.menus 拡張ポイントで制御することができますが、ある条件下でのみポップアップメニューを表示するとかの表示制御は下記のように、visibleWhen タグで行うことができます。 <extension point="org.eclipse.ui.menus"> <menuContribution locationURI="popup:org.eclipse.ui.popup.any"> <menu id="nu.mine.kino.plugin.newaction.menus.sampleMenu" label="トップのメニュー"> <command commandId="nu.mine.kino.plugin.samples.rcp.command" style="push"> </command> <command commandId="nu.mine.kino.plugin.newaction.commands.sampleCommand" style="push"> </command> <visibleWhen> <with variable="activeMenuSelection"> <iterate ifEmpty="false"> <-ifEmptyは、Selectionがなかった時の判定。 <adapt type="org.eclipse.jdt.core.IJavaElement"> </adapt> </iterate> </with> </visibleWhen> </menu> </menuContribution> </extension> このようにmenuやcommandに対して <visibleWhen> <with variable="activeMenuSelection"> <iterate ifEmpty="false"> <adapt type="org.eclipse.jdt.core.IJavaElement"> </adapt> </iterate> </with> </visibleWhen> という条件を設定できるって事ですね。 色々な条件指定 †選択しているオブジェクトの種類で制御 †<visibleWhen> <with variable="activeMenuSelection"> <iterate ifEmpty="false"> <-ifEmptyは、Selectionがなかった時の判定。 <adapt type="org.eclipse.jdt.core.IJavaElement"> </adapt> </iterate> </with> </visibleWhen> 複雑な条件。 †<visibleWhen checkEnabled="false"> <with variable="activeMenuSelection"> <!-- 選択したオブジェクトが --> <!-- (1),(2),(3)どれかを満たせばOK --> <or> <iterate ifEmpty="false" > <adapt type="org.eclipse.jface.text.ITextSelection" /> (1) </iterate> //エディタなどで、テキストを選んだら <and> <count value="1" /> 選択したオブジェクトが一つ且つ、 <iterate ifEmpty="false" > <adapt type="org.eclipse.jdt.core.ICompilationUnit" /> (2) </iterate> 選択されたモノの、Collection の中身がICompilationUnit ならば </and> <and> <count value="1" /> 選択したオブジェクトが一つ且つ、 <iterate ifEmpty="false" > <adapt type="org.eclipse.core.resources.IResource" /> (3) </iterate> 選択されたモノの、Collection の中身がIResourceならば </and> </or> </with> </visibleWhen> あるビューがアクティブになった場合に表示 †<extension point="org.eclipse.core.expressions.definitions"> <definition id="nu.mine.kino.plugin.samples.rcp.view3.isActive"> <with variable="activePartId"> <equals value="nu.mine.kino.plugin.samples.rcp.view3"></equals> </with> </definition> </extension> <visibleWhen> <reference definitionId="nu.mine.kino.plugin.samples.rcp.view3.isActive"> </reference> </visibleWhen> variableで指定できるパラメタ †<with variable="activeMenuSelection"> この変数に設定できる項目は org.eclipse.ui.ISources に定義されているようです。 package org.eclipse.ui; import org.eclipse.core.expressions.IEvaluationContext; import org.eclipse.ui.part.IShowInSource; public interface ISources { public static final String ACTIVE_CONTEXT_NAME = "activeContexts"; public static final String ACTIVE_ACTION_SETS_NAME = "activeActionSets"; public static final String ACTIVE_SHELL_NAME = "activeShell"; public static final String ACTIVE_WORKBENCH_WINDOW_SHELL_NAME = "activeWorkbenchWindowShell"; public static final String ACTIVE_WORKBENCH_WINDOW_NAME = "activeWorkbenchWindow"; public static final String ACTIVE_WORKBENCH_WINDOW_IS_COOLBAR_VISIBLE_NAME = ACTIVE_WORKBENCH_WINDOW_NAME + ".isCoolbarVisible"; public static final String ACTIVE_WORKBENCH_WINDOW_IS_PERSPECTIVEBAR_VISIBLE_NAME = ACTIVE_WORKBENCH_WINDOW_NAME + ".isPerspectiveBarVisible"; public static final String ACTIVE_WORKBENCH_WINDOW_ACTIVE_PERSPECTIVE_NAME = ACTIVE_WORKBENCH_WINDOW_NAME + ".activePerspective"; public static final String ACTIVE_EDITOR_NAME = "activeEditor"; public static final String ACTIVE_EDITOR_ID_NAME = "activeEditorId"; public static final String ACTIVE_MENU_EDITOR_INPUT_NAME = "activeMenuEditorInput"; public static final String ACTIVE_FOCUS_CONTROL_NAME = "activeFocusControl"; public static final String ACTIVE_FOCUS_CONTROL_ID_NAME = "activeFocusControlId"; } ちなみに全体はこんな感じ。関係ないところは省いてます。 package org.eclipse.ui; import org.eclipse.core.expressions.IEvaluationContext; import org.eclipse.ui.part.IShowInSource; public interface ISources { /** * The variable name for the active contexts. This is for use with the * <code>ISourceProvider</code> and <code>IEvaluationContext</code>. * @since 3.2 */ public static final String ACTIVE_CONTEXT_NAME = "activeContexts"; //$NON-NLS-1$ /** * The variable name for the active action sets. This is for use with the * {@link ISourceProvider} and {@link IEvaluationContext}. * @since 3.2 */ public static final String ACTIVE_ACTION_SETS_NAME = "activeActionSets"; //$NON-NLS-1$ /** * The variable name for the active shell. This is for use with the * <code>ISourceProvider</code> and <code>IEvaluationContext</code>. */ public static final String ACTIVE_SHELL_NAME = "activeShell"; //$NON-NLS-1$ /** * The variable name for the active workbench window shell. This is for use * with the <code>ISourceProvider</code> and * <code>IEvaluationContext</code>. * @since 3.2 */ public static final String ACTIVE_WORKBENCH_WINDOW_SHELL_NAME = "activeWorkbenchWindowShell"; //$NON-NLS-1$ /** * The variable name for the active workbench window. This is for use with * the <code>ISourceProvider</code> and <code>IEvaluationContext</code>. */ public static final String ACTIVE_WORKBENCH_WINDOW_NAME = "activeWorkbenchWindow"; //$NON-NLS-1$ /** * The variable name for the coolbar visibility state of the active * workbench window. This is for use with the <code>ISourceProvider</code> * and <code>IEvaluationContext</code>. * * @since 3.3 */ public static final String ACTIVE_WORKBENCH_WINDOW_IS_COOLBAR_VISIBLE_NAME = ACTIVE_WORKBENCH_WINDOW_NAME + ".isCoolbarVisible"; //$NON-NLS-1$ /** * The variable name for the perspective bar visibility state of the active * workbench window. This is for use with the <code>ISourceProvider</code> * and <code>IEvaluationContext</code>. * * @since 3.3 */ public static final String ACTIVE_WORKBENCH_WINDOW_IS_PERSPECTIVEBAR_VISIBLE_NAME = ACTIVE_WORKBENCH_WINDOW_NAME + ".isPerspectiveBarVisible"; //$NON-NLS-1$ /** * The variable name for the current perspective of the active workbench * window. This is for use with the <code>ISourceProvider</code> and * <code>IEvaluationContext</code>. * * @since 3.4 */ public static final String ACTIVE_WORKBENCH_WINDOW_ACTIVE_PERSPECTIVE_NAME = ACTIVE_WORKBENCH_WINDOW_NAME + ".activePerspective"; //$NON-NLS-1$ /** * The variable name for the active editor part. This is for use with the * <code>ISourceProvider</code> and <code>IEvaluationContext</code>. * @since 3.2 */ public static final String ACTIVE_EDITOR_NAME = "activeEditor"; //$NON-NLS-1$ /** * The variable name for the active editor identifier. This is for use with * the <code>ISourceProvider</code> and <code>IEvaluationContext</code>. * * @since 3.2 */ public static final String ACTIVE_EDITOR_ID_NAME = "activeEditorId"; //$NON-NLS-1$ /** * The variable name for the <b>local</b> editor input which is sometimes * available while a context menu is visible. * * @since 3.3 */ public static final String ACTIVE_MENU_EDITOR_INPUT_NAME = "activeMenuEditorInput"; //$NON-NLS-1$ /** * The variable name for the active focus Control, when provided by the * IFocusService. * * @since 3.3 */ public static final String ACTIVE_FOCUS_CONTROL_NAME = "activeFocusControl"; //$NON-NLS-1$ /** * The variable name for the active focus Control id, when provided by the * IFocusService. * * @since 3.3 */ public static final String ACTIVE_FOCUS_CONTROL_ID_NAME = "activeFocusControlId"; //$NON-NLS-1$ } これらが全て、この箇所の変数として有効なのかはまだよく分かりませんが。。 この記事は 現在のアクセス:11097 |