Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 动态更改eclipse标题中的按钮上的文本_Java_Eclipse_Eclipse Plugin_Swt - Fatal编程技术网

Java 动态更改eclipse标题中的按钮上的文本

Java 动态更改eclipse标题中的按钮上的文本,java,eclipse,eclipse-plugin,swt,Java,Eclipse,Eclipse Plugin,Swt,我正在eclipse中创建一个视图来显示堆栈跟踪,我希望通过标题中的按钮可以访问该视图。因此,我使用plugin.xml框架创建了一个扩展,基本上如下所示: <extension point="org.eclipse.ui.commands"> <command categoryId="com.commands.category" id="commands.tracing" name="0 Traces">

我正在eclipse中创建一个视图来显示堆栈跟踪,我希望通过标题中的按钮可以访问该视图。因此,我使用plugin.xml框架创建了一个扩展,基本上如下所示:

<extension
    point="org.eclipse.ui.commands">
  <command
        categoryId="com.commands.category"
        id="commands.tracing"
        name="0 Traces">
  </command>
 </extension>

这将创建一个以“0轨迹”作为文本的按钮。但是,我希望在侦听器中收集的每个跟踪中增加按钮中的数字。基本上,我只需要能够编辑Java文件标题中的按钮,而不是plugin.xml文件中的按钮。但我不知道该怎么做!我已经查看了EclipseSDK帮助,但没有找到任何内容。请帮忙


我也愿意在基于eclipse构建的应用程序中使用任何其他方法来实现这一点,只要文本发生更改并单击文本打开一个视图。

我相信标题使用图标,但不确定是否可以使用文本。您可以在上下文(弹出式)菜单中添加一个条目,该菜单将显示跟踪的数量,并在单击该项时启动视图

我基于Eclipse附带的Hello,World命令模板,并添加了一个菜单贡献

我扩展了CompoundContributionItem作为菜单贡献,如下所示


/**
 * Menu contribution which will update it's label to show the number of current
 * traces.
 */
public class TraceWindowContributionItem extends CompoundContributionItem {
    private static int demoTraceCount = 0;
    /**
     * Implemented to create a label which displays the number of traces.
     */
    @Override
    protected IContributionItem[] getContributionItems() {

        //Here is your dynamic label.
        final String label = getTraceCount() + " traces";

        //Create other items needed for creation of contribution.
        final String id = "test.dynamicContribution";
        final IServiceLocator serviceLocator = findServiceLocator();
        final String commandId = "test.commands.sampleCommand";
        final Map parameters = new HashMap();

        //Here is the contribution which will be displayed in the menu.
        final CommandContributionItem contribution = new CommandContributionItem(
                serviceLocator, id, commandId, parameters, null, null, null,
                label, null, null, SWT.NONE);

        return new IContributionItem[] { contribution };
    }

    /**
     * Demo method simply increments by 1 each time the popup is shown. Your
     * code would store or query for the actual trace count each time.
     * @return
     */
    private int getTraceCount() {
        return demoTraceCount++;
    }

    /**
     * Find the service locator to give to the contribution.
     */
    private IServiceLocator findServiceLocator() {
        return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    }
}

现在我们需要将其连接到将启动视图的命令和处理程序中

这是我的plugin.xml


<!-- Wire up our dynamic menu contribution which will show the number of traces -->
<extension
     point="org.eclipse.ui.menus">
  <menuContribution
        locationURI="popup:org.eclipse.ui.popup.any?after=additions">
     <dynamic
           class="test.TraceWindowContributionItem"
           id="test.dynamicContribution">
     </dynamic>
  </menuContribution>
</extension>
<!-- Command and handler for launching the traces view -->
<extension
     point="org.eclipse.ui.commands">
  <category
        name="Sample Category"
        id="test.commands.category">
  </category>
  <command
        categoryId="test.commands.category"
        defaultHandler="test.handlers.SampleHandler"
        id="test.commands.sampleCommand"
        name="Sample Command">
  </command>
</extension>
<extension
     point="org.eclipse.ui.handlers">
  <handler
        commandId="test.commands.sampleCommand"
        class="test.handlers.SampleHandler">
  </handler>
</extension>