簡體   English   中英

Eclipse插件開發初學者

[英]Eclipse Plugin Development Beginner

public class Activator extends AbstractUIPlugin {

    // The plug-in ID
    public static final String PLUGIN_ID = "my.plugin.alps"; //$NON-NLS-1$

    // The shared instance
    private static Activator plugin;

    /**
     * The constructor
     */
    public Activator() {
    }
    public static void main(String[] args) {

        Activator.getDefault();
    }

    public void start(BundleContext context) throws Exception {
        super.start(context);
        plugin = this;
    }


    public void stop(BundleContext context) throws Exception {
        plugin = null;
        super.stop(context);
    }

    public static Activator getDefault() {
        return plugin;
    }
        public boolean isEnabled() {
            // TODO Auto-generated method stub
            return true;
        }

    public static ImageDescriptor getImageDescriptor(String path) {
        return imageDescriptorFromPlugin(PLUGIN_ID, path);
    }

}

   <extension
         point="org.eclipse.ui.commands">
      <category
            name="Sample Category"
            id="my.plugin.alps.commands.category">
      </category>
      <command
            name="Code Generator"
            categoryId="my.plugin.alps.commands.category"
            id="my.plugin.alps.commands.sampleCommand">
      </command>
   </extension>
   <extension
         point="org.eclipse.ui.handlers">
      <handler
            commandId="my.plugin.alps.commands.sampleCommand"
            class="my.plugin.alps.handlers.SampleHandler">
      </handler>
   </extension>
   <extension
         point="org.eclipse.ui.bindings">
      <key
            commandId="my.plugin.alps.commands.sampleCommand"
            contextId="org.eclipse.ui.contexts.window"
            sequence="M1+6"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
      </key>
   </extension>
   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            locationURI="menu:org.eclipse.ui.main.menu?after=additions">
         <menu
               label="myLearning Portal for SAP (ALPS)"
               id="my.plugin.alps.menus.alps">
            <command
                  commandId="my.plugin.alps.generateCodes"
                  id="my.plugin.alps.menus.generateCodes"
                  label="Generate Codes"
                  style="push">
            </command>
            <command
                  commandId="my.plugin.alps.checkCodes"
                  id="my.plugin.alps.menus.checkCodes"
                  label="Check Codes"
                  style="push">
            </command>
         </menu>
      </menuContribution>
   </extension>
</plugin>

public class SampleHandler extends AbstractHandler {

    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {
        IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
        MessageDialog.openInformation(
                window.getShell(),
                "Alps",
                "Use to generate codes");
        return null;



    }
}

I want it to be clickable and do something. I don't know where to add my source code for its function. 

我是新來的,請幫助我。 非常感謝你。

1.我需要它是可單擊的(運行時顯示為灰色)。2.我需要知道在哪里添加我的代碼以具有其功能。 即,當我單擊菜單時,它將執行某項操作……再次,我創建了自己的插件eclipse。 我是新來的。 如何為我為插件創建的菜單添加功能? 每次我將其作為Eclipse應用程序運行時,菜單均顯示為灰色/無法單擊。 也許我錯過了什么? TIA!

看到上面的代碼,指定的命令ID不匹配。 每當您嘗試將命令與菜單及其處理程序相關聯時,命令ID都應該相同。 嘗試為Menu項及其相應的處理程序提供相同的命令ID。 這樣代碼就可以正常工作了。

請在下面找到修改后的plugin.xml:

<extension
         point="org.eclipse.ui.menus">
      <menuContribution
            locationURI="menu:org.eclipse.ui.main.menu?after=additions">
         <menu
               id="my.plugin.alps.menus.alps"
               label="myLearning Portal for SAP (ALPS)">
            <command
                  commandId="my.plugin.alps.generateCodes"
                  id="my.plugin.alps.menus.generateCodes"
                  label="Generate Codes"
                  style="push">
            </command>
            <command
                  commandId="my.plugin.alps.checkCodes"
                  id="my.plugin.alps.menus.checkCodes"
                  label="Check Codes"
                  style="push">
            </command>
         </menu>
      </menuContribution>
   </extension>
   <extension
         point="org.eclipse.ui.commands">
         <command
               id="my.plugin.alps.generateCodes"
               name="Generate Codes">
         </command>
         <command
               id="my.plugin.alps.checkCodes"
               name="Check Codes">
         </command>
   </extension>
   <extension
         point="org.eclipse.ui.handlers">
      <handler
            class="TestHandler"
            commandId="my.plugin.alps.generateCodes">
      </handler>
   </extension>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM