簡體   English   中英

如何將按鈕添加到Eclipse工具欄並將其連接到功能xml擴展點

[英]How to add button to eclipse toolbar and connecting him to function xml extension Point

您好,我正在嘗試為我的插件在elipse中的主要工具欄添加按鈕。

我已成功將按鈕添加到工具欄,但未能將此按鈕連接到將打開屬性頁的功能。

這是我在xml中的代碼:

    <plugin>
     <extension
         point="org.eclipse.ui.commands">
      <category
            name="Sample Category"
            id="FirstTextHoverTry.commands.category">
      </category>
      <command
            name="Sample Command"
            categoryId="FirstTextHoverTry.commands.category"
            id="FirstTextHoverTry.commands.sampleCommand">
      </command>
   </extension>
   <extension
         point="org.eclipse.ui.handlers">
      <handler
            commandId="FirstTextHoverTry.commands.sampleCommand"
            class="FirstTextHoverTry.SettingPage">
      </handler>
       <extension
             point="org.eclipse.ui.menus">
          <menuContribution
                locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
              <toolbar
                   id="opr.toolbars.sampleToolbar">
                <command
                      commandId="FirstTextHoverTry.Settings.SettingPage.execute"
                      icon="icons/sample.gif"
                      tooltip="Say hello world"
                      id="FirstTextHoverTry.Settings.execute">
                </command>
                </toolbar>
          </menuContribution>
       </extension>

</plugin> 

問題可能出在commandId和id中。

我有一個“包”調用設置,其中包括一個類調用SettingPage,這是我在此類中的代碼。

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.jface.dialogs.MessageDialog;

public class SettingPage extends AbstractHandler {

    public SettingPage() {
    }


    public Object execute(ExecutionEvent event) throws ExecutionException {
        IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
        MessageDialog.openInformation(
                window.getShell(),
                "hi",
                "Need Somthing else probably");
        return null;
    }
}

org.eclipse.ui.handlers擴展點說,你的處理程序類是FirstTextHoverTry.SettingPage -這樣一類被稱為SettingPageFirstTextHoverTry包,而不是Settings包。 因此,請確定軟件包名稱。

暫無
暫無

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

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