2011-08-13 19 views
2

私は、menuContributions + popupを使用して、plugin.xmlにコンテキストメニューを表示しています。私はそれだけでプロジェクト(たとえば、動的Webプロジェクト)(メニューのみ親プロジェクトフォルダの右クリックで表示されます)と ポップアップメニューの可視性を特定のプロジェクトタイプに限定する方法はありますか?

    1. 特定の種類の特定のフォルダ(例:ウェブコンテンツ)への可視性です制限する必要があるとそれはProject Folder構造内のサブフォルダです。

    私は

    <menuContribution locationURI="popup:common.new.menu?after=additions"> 
          <command 
           label="Web Wiz" 
           commandId="commandId" 
           icon="icons/sample.gif"> 
           <visibleWhen> 
            <with variable="selection"> 
              <iterate ifEmpty="false" 
             operator="or"> 
            <instanceof 
              value="org.eclipse.core.resources.IProject"/> 
            </iterate> 
            </with> 
           </visibleWhen> 
          </command> 
         </menuContribution> 
    

    を使用することによって、ある程度1)の条件を達成することができましたが、それはプロジェクトのすべての種類のために表示されます...私は動的Webプロジェクトにそれを制限する必要があります、plugin.xmlのこの要件を満たすために追加する必要があるのは何ですか?

  • 答えて

    4
    1. プロジェクトタイプをテストするpropertyTesterを追加します。あなたは日食の助けで、プロパティ・テスターに​​ついて読む、または拡張ヘルプ自身でできるvisibleWhen

    テスター

  • 使用:)

    EDIT - だけでなく、この1をチェックアウト - http://wiki.eclipse.org/Command_Core_Expressions#Property_Testers(第二の条件については、組み込みのユーザーが使用できる実装を提供することができ、特にResourcePropertyTester、)

  • +0

    \t \t \t \t \t \t \t \t \tは、Webのためのトリックを行いましたプロジェクトタイプ、私はプロジェクトの.projectファイルから特定のプロジェクトの性質を得ることができました。 – Abbas

    +0

    私は第2の条件のために不動産テスターを使用し、必要な点検を行うことができました。 – Abbas

    2

    <test forcePluginActivation="true" 
          property="testWizard.propertyTester.checkFolder" 
          value="org.eclipse.wst.jsdt.core.jsNature" 
        </test> 
    

    は次に


    <extension 
         point="org.eclipse.core.expressions.propertyTesters"> 
        <propertyTester   
         class="testwizard.wizards.MyPropTester" 
          id="MyPropTesterFolder" 
          namespace="testWizard.propertyTester" 
          properties="checkFolder" 
          type="org.eclipse.core.resources.IFolder"> 
        </propertyTester> 
    

    フォルダの一種として定義することができるプロパティテスターへの参照であり、それは、サブフォルダは

    package testwizard.wizards; 
    
    import org.eclipse.core.expressions.PropertyTester; 
    import org.eclipse.core.resources.IFolder; 
    import org.eclipse.core.runtime.CoreException; 
    
    public class MyPropTester extends PropertyTester{ 
    
        @Override 
        public boolean test(Object receiver, String property, Object[] args, 
          Object expectedValue) { 
    
         IFolder folder=(IFolder)receiver; 
         String folderPath=folder.getProjectRelativePath().toString(); 
         String arr[]=folderPath.split("/");  
         try { 
          if(folder.getProject().hasNature(expectedValue.toString())) 
          { 
           if(arr[0].equals("XYZ")) 
           { 
            return true; 
           } 
          } 
         } catch (CoreException e) { 
          // TODO Auto-generated catch block 
          e.printStackTrace(); 
         } 
    
         return false; 
        } 
    
    } 
    
    3
    <menuContribution locationURI="popup:common.new.menu?after=additions"> 
        <command 
          label="Web Wiz" 
          commandId="commandId" 
          icon="icons/sample.gif"> 
        <visibleWhen> 
         <with variable="selection"> 
         <iterate operator="and" ifEmpty="false"> 
          <test 
            property="org.eclipse.core.resources.projectNature" 
            value="your-project-nature" /> 
         </iterate> 
        </with> 
        </visibleWhen> 
    </command> 
    <menuContribution> 
    
    に以下のように試験することができます
    +0

    注:上記の ''は 'Package Explorer'ではうまく動作しません。私が見たすべてのナビゲータに対して、 ''を使うことができます。 – porcoesphino

    関連する問題