/** * Disposes all menu items and re-creates them. * * @return an empty {@link List} */ public List<ToolItem> updateMenuItems() { if (menuCoolBar != null) { menuCoolBar.dispose(); } create(); layout(); return Collections.emptyList(); }
public void packCoolBar() { Point size = this.getSize(); coolBar.setSize(coolBar.computeSize(size.x, size.y)); }
private void createToolBar(Composite parent) { final Composite toolbarComposite = new Composite(parent, SWT.NONE); GridLayoutFactory.swtDefaults().numColumns(1).applyTo(toolbarComposite); toolbarComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); CoolBarManager coolBarManager = new CoolBarManager(SWT.HORIZONTAL | SWT.FLAT); { ToolBarManager manager = new ToolBarManager(SWT.HORIZONTAL | SWT.FLAT); IAction homeAction = new Action() { @Override public void run() { close(); } }; homeAction.setToolTipText(Messages.ControlPanelWindow_ReturnActionTooltip); homeAction.setImageDescriptor(Images.getImageDescriptor(Images.PANEL_HOME)); manager.add(homeAction); IAction saveAction = new Action() { @Override public void run() { if (getModel() != null) { save(); } else { saveAs(); } } }; saveAction.setMenuCreator( new ActionMenuCreator() { @Override protected void fill(MenuManager manager) { manager.add( new Action(Messages.ControlPanelWindow_SaveAction) { { dbc.bindValue( Actions.observeEnabled(this), new ComputedValue() { @Override protected Object calculate() { return getModel() != null; } }); } @Override public void run() { save(); } }); manager.add( new Action(Messages.ControlPanelWindow_SaveAsAction) { @Override public void run() { saveAs(); } }); } }); dbc.bindValue( Actions.observeToolTipText(saveAction), new ComputedValue() { @Override protected Object calculate() { if (getModel() != null) { return Messages.ControlPanelWindow_SaveAction; } else { return Messages.ControlPanelWindow_SaveAsAction; } } }); ISharedImages sharedImages = WorkbenchPlugin.getDefault().getSharedImages(); saveAction.setImageDescriptor( sharedImages.getImageDescriptor(ISharedImages.IMG_ETOOL_SAVE_EDIT)); saveAction.setDisabledImageDescriptor( sharedImages.getImageDescriptor(ISharedImages.IMG_ETOOL_SAVE_EDIT_DISABLED)); manager.add(saveAction); coolBarManager.add(manager); } { ToolBarManager manager = new ToolBarManager(SWT.HORIZONTAL | SWT.FLAT); manager.add(createRecordAction()); manager.add(createReplayAction()); coolBarManager.add(manager); } { ToolBarManager manager = new ToolBarManager(SWT.HORIZONTAL | SWT.FLAT); manager.add(createRecordingModeAction()); manager.add(createAssertingModeAction()); if (Q7UIPlugin.isImageRecognitionAllowed()) { manager.add(createImageRecognitionModeAction()); } coolBarManager.add(manager); } coolBar = coolBarManager.createControl(toolbarComposite); GridDataFactory.fillDefaults().grab(true, true).applyTo(coolBar); coolBar.addListener( SWT.Resize, new Listener() { public void handleEvent(Event event) { getShell().layout(); } }); }