how to add Wizards created in New->File->others in

2019-08-12 16:56发布

问题:

I have created a category in File->New->Others say "Enterprise".With some Wizards in it lets say "Instance","Component", etc. Now what i want ,when i right click in Project Explorerand go in New those wizards should be seen their itself. Basically trying to make popup menu of those wizards.

So i created popup menus as:

<extension
         point="org.eclipse.ui.menus">
      <menuContribution
            allPopups="true"
            locationURI="popup:common.new.menu?before=additions">
         <command
               commandId="CommandComponent"
               label="Component"
               style="push">
         </command>
      </menuContribution>
   </extension>
   <extension
         point="org.eclipse.ui.commands">
      <command
            id="CommandComponent"
            name="Component">
      </command>
   </extension>
   <extension
         point="org.eclipse.ui.handlers">
      <handler
            commandId="CommandComponent">
      </handler>
   </extension>

Now how could I give the same class to the handler which I gave to Wizard Component?

Or do I have to write a new class with the same functionality but as per handler format (if it is possible)?

回答1:

You use the org.eclipse.ui.perspectiveExtensions extension point to define the New Wizards which are show at the top level of the New menu using the newWizardShortcut element.

Something like:

<extension
     point="org.eclipse.ui.perspectiveExtensions">
  <perspectiveExtension
        targetID="org.eclipse.jdt.ui.JavaPerspective">
     <newWizardShortcut
           id="org.eclipse.jdt.junit.wizards.NewTestCaseCreationWizard">
     </newWizardShortcut>
  </perspectiveExtension>

(which is the New JUnit Test Case shortcut).

You may need to Reset the Perspective or use Customize Perspective to make the item visible as the user has control over which of these shortcuts is shown.

More info in the help



回答2:

Just like greg-449 mentioned, use the "org.eclipse.ui.perspectiveExtensions" extension point to contribute your elements to the perspective that you want.

When you right click on the project explorer or package explorer and click on New, the projects shown there are dependent on the perspective you are in. If you are in a Java perspective, you will find Java Project. If you are in the PDE perspective, you will find Plugin project. So it's good to contribute your Project type in the perspective you want it.



回答3:

Thanks greg-449 and Henry for your help.

Well this is what i did ,in order to achieve what i was asking for.

A popup menu when i right click in project explorer it shows New->Component Wizard. Which i have added in File->New->Others.

<extension
         point="org.eclipse.ui.menus">
      <menuContribution
            allPopups="false"
            locationURI="popup:common.new.menu?after=new">
         <command
               commandId=" org.eclipse.ui.newWizard"
               style="push">
            <visibleWhen
                  checkEnabled="false">
               <with
                     variable="activeWorkbenchWindow.activePerspective">
                  <equals
                        value="org.eclipse.ui.resourcePerspective">
                  </equals>
               </with>
            </visibleWhen>
            <parameter
                  name="newWizardId"
                  value="Component">
            </parameter>
         </command>
      </menuContribution>
   </extension>