如何将按钮添加到eclipse工具栏并将其连接到函数xml扩展点

时间:2016-06-06 10:15:12

标签: xml eclipse eclipse-plugin

您好我正在尝试在插件中添加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。

我有一个&#34;包&#34;调用设置,包括一个类调用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;
    }
}

1 个答案:

答案 0 :(得分:0)

您的org.eclipse.ui.handlers扩展点表示您的处理程序类为FirstTextHoverTry.SettingPage - 因此SettingPage包中的FirstTextHoverTry类称为Settings,而不是 GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => $gridColumns, 'exportConfig'=> [ GridView::CSV=>[ 'label' => 'CSV', 'icon' => '', 'iconOptions' => '', 'showHeader' => false, 'showPageSummary' => false, 'showFooter' => false, 'showCaption' => false, 'filename' => 'yii', 'alertMsg' => 'created', 'options' => ['title' => 'Semicolon - Separated Values'], 'mime' => 'application/csv', 'config' => [ 'colDelimiter' => ";", 'rowDelimiter' => "\r\n", ], ], ], ]); 包。所以修复软件包名称。