View 将终止按钮添加到eclipse控制台

View 将终止按钮添加到eclipse控制台,view,eclipse-plugin,console,View,Eclipse Plugin,Console,如何将终止按钮添加到eclipse控制台工具栏?我以这种方式创建控制台: IOConsole console = new IOConsole( name, null, null, true ); ConsolePlugin.getDefault().getConsoleManager().addConsoles( new IConsole[]{console} ); 我找到了解决办法。代码如下: <extension point="org.eclipse.ui.c

如何将终止按钮添加到eclipse控制台工具栏?我以这种方式创建控制台:

IOConsole console = new IOConsole( name, null, null, true );
ConsolePlugin.getDefault().getConsoleManager().addConsoles( new IConsole[]{console} );

我找到了解决办法。代码如下:

   <extension
         point="org.eclipse.ui.console.consolePageParticipants">
      <consolePageParticipant
            class="com.plugin.console.ConsoleActions"
            id="com.plugin.console.PageParticipant">
         <enablement>
            <instanceof value="com.plugin.console.Console"/>
         </enablement>
      </consolePageParticipant>
   </extension>
控制台参与者类:

public class ConsoleActions implements IConsolePageParticipant {

    private IPageBookViewPage page;
    private Action remove, stop;
    private IActionBars bars;
    private IConsole console;

    @Override
    public void init(final IPageBookViewPage page, final IConsole console) {
        this.console = console;
        this.page = page;
        IPageSite site = page.getSite();
        this.bars = site.getActionBars();

        createTerminateAllButton();
        createRemoveButton();

        bars.getMenuManager().add(new Separator());
        bars.getMenuManager().add(remove);

        IToolBarManager toolbarManager = bars.getToolBarManager();

        toolbarManager.appendToGroup(IConsoleConstants.LAUNCH_GROUP, stop);
        toolbarManager.appendToGroup(IConsoleConstants.LAUNCH_GROUP,remove);

        bars.updateActionBars();

    }

    private void createTerminateAllButton() {
        ImageDescriptor imageDescriptor = ImageDescriptor.createFromFile(getClass(), "/icons/stop_all_active.gif");
        this.stop = new Action("Terminate all", imageDescriptor) {
            public void run() {
                //code to execute when button is pressed
            }
        };

    }

    private void createRemoveButton() {
        ImageDescriptor imageDescriptor = ImageDescriptor.createFromFile(getClass(), "/icons/remove_active.gif");
        this.remove= new Action("Remove console", imageDescriptor) {
            public void run() {
                //code to execute when button is pressed
            }
        };
    }

    @Override
    public void dispose() {
        remove= null;
        stop = null;
        bars = null;
        page = null;
    }

    @Override
    public Object getAdapter(Class adapter) {
        return null;
    }

    @Override
    public void activated() {
        updateVis();
    }

    @Override
    public void deactivated() {
        updateVis();
    }

    private void updateVis() {

        if (page == null)
            return;
        boolean isEnabled = true;
        stop.setEnabled(isEnabled);
        remove.setEnabled(isEnabled);
        bars.updateActionBars();
    }

}
public class ConsoleActions implements IConsolePageParticipant {

    private IPageBookViewPage page;
    private Action remove, stop;
    private IActionBars bars;
    private IConsole console;

    @Override
    public void init(final IPageBookViewPage page, final IConsole console) {
        this.console = console;
        this.page = page;
        IPageSite site = page.getSite();
        this.bars = site.getActionBars();

        createTerminateAllButton();
        createRemoveButton();

        bars.getMenuManager().add(new Separator());
        bars.getMenuManager().add(remove);

        IToolBarManager toolbarManager = bars.getToolBarManager();

        toolbarManager.appendToGroup(IConsoleConstants.LAUNCH_GROUP, stop);
        toolbarManager.appendToGroup(IConsoleConstants.LAUNCH_GROUP,remove);

        bars.updateActionBars();

    }

    private void createTerminateAllButton() {
        ImageDescriptor imageDescriptor = ImageDescriptor.createFromFile(getClass(), "/icons/stop_all_active.gif");
        this.stop = new Action("Terminate all", imageDescriptor) {
            public void run() {
                //code to execute when button is pressed
            }
        };

    }

    private void createRemoveButton() {
        ImageDescriptor imageDescriptor = ImageDescriptor.createFromFile(getClass(), "/icons/remove_active.gif");
        this.remove= new Action("Remove console", imageDescriptor) {
            public void run() {
                //code to execute when button is pressed
            }
        };
    }

    @Override
    public void dispose() {
        remove= null;
        stop = null;
        bars = null;
        page = null;
    }

    @Override
    public Object getAdapter(Class adapter) {
        return null;
    }

    @Override
    public void activated() {
        updateVis();
    }

    @Override
    public void deactivated() {
        updateVis();
    }

    private void updateVis() {

        if (page == null)
            return;
        boolean isEnabled = true;
        stop.setEnabled(isEnabled);
        remove.setEnabled(isEnabled);
        bars.updateActionBars();
    }

}