@Override protected void update(Model model) { // Check if (toolbar == null) return; // For each item for (final ToolItem item : toolbar.getItems()) { // Check group if (!(item.getData() instanceof MainMenuGroup)) { MainMenuItem mItem = (MainMenuItem) item.getData(); item.setEnabled(mItem == null || mItem.isEnabled(model)); } } }
public void handleEvent(Event event) { if (psTB.isDisposed()) { return; } MUIElement changedElement = (MUIElement) event.getProperty(UIEvents.EventTags.ELEMENT); if (psME == null || !(changedElement instanceof MPerspective)) return; String attName = (String) event.getProperty(UIEvents.EventTags.ATTNAME); Object newValue = event.getProperty(UIEvents.EventTags.NEW_VALUE); MWindow perspWin = modelService.getTopLevelWindowFor(changedElement); MWindow switcherWin = modelService.getTopLevelWindowFor(psME); if (perspWin != switcherWin) return; MPerspective perspective = (MPerspective) changedElement; if (!perspective.isToBeRendered()) return; for (ToolItem ti : psTB.getItems()) { if (ti.getData() == perspective) { updateToolItem(ti, attName, newValue); } } // update the size fixSize(); }
protected ToolItem getItemFor(MPerspective persp) { if (psTB == null) return null; for (ToolItem ti : psTB.getItems()) { if (ti.getData() == persp) return ti; } return null; }
private void selectPerspective(String id) { for (ToolItem item : bar.getItems()) item.setSelection(((String) item.getData()).equals(id)); try { PlatformUI.getWorkbench() .showPerspective(id, PlatformUI.getWorkbench().getActiveWorkbenchWindow()); DataOverviewView.reset(); } catch (WorkbenchException e) { if (Log.error(this)) Log.error(this, "Unable to change perspective", e); } }
private void disposeToolItems() { for (int i = 0; i < toolItemList.size(); i++) { ToolItem item = (ToolItem) toolItemList.get(i); if (!item.isDisposed()) { Object data = item.getData(); if (data != null && data instanceof Menu) { Menu menu = (Menu) data; if (!menu.isDisposed()) { menu.dispose(); } } item.dispose(); } } }
private void track(MouseEvent e) { // Create and track the feedback overlay if (dragShell == null) createFeedback(); // Move the drag shell Rectangle b = dragItem.getBounds(); Point p = new Point(e.x, e.y); p = dragShell.getDisplay().map(dragItem.getParent(), null, p); dragShell.setLocation(p.x - (b.width / 2), p.y - (b.height / 2)); // Set the cursor feedback ToolBar bar = (ToolBar) e.widget; ToolItem curItem = bar.getItem(new Point(e.x, e.y)); if (curItem != null && curItem.getData() instanceof MPerspective) { psTB.setCursor(psTB.getDisplay().getSystemCursor(SWT.CURSOR_HAND)); } else { psTB.setCursor(psTB.getDisplay().getSystemCursor(SWT.CURSOR_NO)); } }
public void handleEvent(Event event) { if (psTB.isDisposed()) { return; } MUIElement changedElement = (MUIElement) event.getProperty(UIEvents.EventTags.ELEMENT); if (psME == null || !(changedElement instanceof MPerspectiveStack)) return; MWindow perspWin = modelService.getTopLevelWindowFor(changedElement); MWindow switcherWin = modelService.getTopLevelWindowFor(psME); if (perspWin != switcherWin) return; MPerspectiveStack perspStack = (MPerspectiveStack) changedElement; if (!perspStack.isToBeRendered()) return; MPerspective selElement = perspStack.getSelectedElement(); for (ToolItem ti : psTB.getItems()) { ti.setSelection(ti.getData() == selElement); } }
/** * @see com.aptana.ide.core.ui.widgets.ToolTip#shouldCreateToolTip(org.eclipse.swt.widgets.Event) */ protected boolean shouldCreateToolTip(Event event) { boolean shouldCreateToolTip = super.shouldCreateToolTip(event); if (shouldCreateToolTip) { ToolItem item = tb.getItem(new Point(event.x, event.y)); if (item == null) { return false; } Object data2 = item.getData(); ContributionItem citem = (ContributionItem) data2; if (citem instanceof ActionContributionItem) { ActionContributionItem cm = (ActionContributionItem) citem; IAction action = cm.getAction(); String id = action.getId(); if (id != null) { if (id.equals(this.id)) { return true; } } } } return false; }
public static String getSelectedPerspective() { if (bar == null || bar.isDisposed()) return null; for (ToolItem item : bar.getItems()) if (item.getSelection()) return (String) item.getData(); return null; }
/** * Attempts to update the existing toolbar actions, if the action list is similar to the current * list. Returns false if this cannot be done and the contents must be replaced. */ private boolean updateActions(@NonNull List<RuleAction> actions) { List<RuleAction> before = mPrevActions; List<RuleAction> after = actions; if (before == null) { return false; } if (!before.equals(after) || after.size() > mLayoutToolBar.getItemCount()) { return false; } int actionIndex = 0; for (int i = 0, max = mLayoutToolBar.getItemCount(); i < max; i++) { ToolItem item = mLayoutToolBar.getItem(i); int style = item.getStyle(); Object data = item.getData(); if (data != null) { // One action can result in multiple toolbar items (e.g. a choice action // can result in multiple radio buttons), so we've have to replace all of // them with the corresponding new action RuleAction prevAction = before.get(actionIndex); while (prevAction != data) { actionIndex++; if (actionIndex == before.size()) { return false; } prevAction = before.get(actionIndex); if (prevAction == data) { break; } else if (!(prevAction instanceof RuleAction.Separator)) { return false; } } RuleAction newAction = after.get(actionIndex); assert newAction.equals(prevAction); // Maybe I can do this lazily instead? // Update action binding to the new action item.setData(newAction); // Sync button states: the checked state is not considered part of // RuleAction equality if ((style & SWT.CHECK) != 0) { assert newAction instanceof Toggle; Toggle toggle = (Toggle) newAction; item.setSelection(toggle.isChecked()); } else if ((style & SWT.RADIO) != 0) { assert newAction instanceof Choices; Choices choices = (Choices) newAction; String current = choices.getCurrent(); String id = (String) item.getData(ATTR_ID); boolean selected = Strings.nullToEmpty(current).equals(id); item.setSelection(selected); } } else { // Must be a separator, or a label (which we insert for nested widgets) assert (style & SWT.SEPARATOR) != 0 || !item.getText().isEmpty() : item; } } return true; }