/** The table viewer selection has changed. Update the toolbar and menu enablements */ private void handleSelection() { ISelection selection = tableViewer.getSelection(); if (selection == null || !(selection instanceof IStructuredSelection)) { return; } IStructuredSelection structuredSelection = (IStructuredSelection) selection; List selectionList = structuredSelection.toList(); boolean selectionEmpty = structuredSelection.isEmpty(); boolean firstRowSelected = true; boolean lastRowSelected = true; if (!selectionEmpty) { SortFilterElement element = (SortFilterElement) selectionList.get(0); if (tableViewer.getElementAt(0).equals(element)) { firstRowSelected = true; } else { firstRowSelected = false; } element = (SortFilterElement) selectionList.get(selectionList.size() - 1); if (tableViewer.getElementAt(tableViewer.getTable().getItemCount() - 1).equals(element)) { lastRowSelected = true; } else { lastRowSelected = false; } } if (moveUpToolItem != null) { moveUpToolItem.setEnabled(!firstRowSelected && !selectionEmpty); } if (moveDownToolItem != null) { moveDownToolItem.setEnabled(!lastRowSelected && !selectionEmpty); } }
private org.eclipse.swt.widgets.ToolItem addToolItem( final org.eclipse.swt.widgets.ToolBar toolbar, final org.eclipse.swt.examples.paint.Tool tool) { final java.lang.String id = tool.group + '.' + tool.name; org.eclipse.swt.widgets.ToolItem item = new org.eclipse.swt.widgets.ToolItem(toolbar, tool.type); item.setText(getResourceString(id + ".label")); item.setToolTipText(getResourceString(id + ".tooltip")); item.setImage(tool.image); item.addSelectionListener( new org.eclipse.swt.events.SelectionAdapter() { public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { tool.action.run(); } }); final int childID = toolbar.indexOf(item); toolbar .getAccessible() .addAccessibleListener( new org.eclipse.swt.accessibility.AccessibleAdapter() { public void getName(org.eclipse.swt.accessibility.AccessibleEvent e) { if (e.childID == childID) { e.result = getResourceString(id + ".description"); } } }); return item; }
private static ToolItem createNewToolItem(Composite parent, final ToolBar toolBar) { final Menu menu = NewMenuItemViewProvider.createMenu(parent); final ToolItem toolItem = createToolItem(toolBar, NEW, NEW, null, SWT.DROP_DOWN); toolItem.addSelectionListener( new SelectionListener() { private static final long serialVersionUID = -2281618627759204367L; @Override public void widgetSelected(SelectionEvent e) { if (e.detail == SWT.ARROW) { Rectangle rect = toolItem.getBounds(); Point pt = new Point(rect.x, rect.y + rect.height); pt = toolBar.toDisplay(pt); menu.setLocation(pt.x, pt.y); menu.setVisible(true); } } @Override public void widgetDefaultSelected(SelectionEvent e) { // } }); return toolItem; }
/** 添加帮助按钮,备注,这里的配置与其他的不一样 robert 2012-09-06 */ protected Control createHelpToolItem(Composite parent) { // ROBERTHELP xml 转换器配置 String language = CommonFunction.getSystemLanguage(); final String helpUrl = MessageFormat.format( "/net.heartsome.cat.ts.ui.help/html/{0}/ch08.html#configure-xml-converter", language); Image helpImage = JFaceResources.getImage(DLG_IMG_HELP); ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS); toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND); toolBar.setCursor(cursor); toolBar.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent e) { cursor.dispose(); } }); ToolItem helpItem = new ToolItem(toolBar, SWT.NONE); helpItem.setImage(helpImage); helpItem.setToolTipText(JFaceResources.getString("helpToolTip")); // $NON-NLS-1$ helpItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpUrl); } }); return toolBar; }
public ToolItem addButton(String toolTipText, Image image) { ToolItem toolButton = new ToolItem(toolBar, SWT.PUSH); toolButton.setToolTipText(toolTipText); toolButton.setImage(image); return toolButton; }
/** * Determines if the selection was on the dropdown affordance and, if so, opens the drop down menu * (populated using the same id as this item... * * @param event The <code>SWT.Selection</code> event to be tested * @return <code>true</code> iff a drop down menu was opened */ private boolean openDropDownMenu(Event event) { Widget item = event.widget; if (item != null) { int style = item.getStyle(); if ((style & SWT.DROP_DOWN) != 0) { if (event.detail == 4) { // on drop-down button ToolItem ti = (ToolItem) item; final MenuManager menuManager = new MenuManager(); Menu menu = menuManager.createContextMenu(ti.getParent()); menuManager.addMenuListener( new IMenuListener() { public void menuAboutToShow(IMenuManager manager) { String id = getId(); if (dropDownMenuOverride != null) { id = dropDownMenuOverride; } menuService.populateContributionManager(menuManager, "menu:" + id); // $NON-NLS-1$ } }); // position the menu below the drop down item Rectangle b = ti.getBounds(); Point p = ti.getParent().toDisplay(new Point(b.x, b.y + b.height)); menu.setLocation(p.x, p.y); // waiting for SWT // 0.42 menu.setVisible(true); return true; // we don't fire the action } } } return false; }
/* * Creates a button with a help image. This is only used if there * is an image available. */ private ToolBar createLocalizationImageButton(Composite parent, Image image) { ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS); ((GridLayout) parent.getLayout()).numColumns++; toolBar.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, false, false)); final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND); toolBar.setCursor(cursor); toolBar.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent e) { cursor.dispose(); } }); final ToolItem item = new ToolItem(toolBar, SWT.NONE); item.setImage(image); languageSet.associate( "localizationToolTip", //$NON-NLS-1$ new TranslatableTextInput( Activator.getLocalizableText( "LocalizableTrayDialog.localizationToolTip")) { //$NON-NLS-1$ @Override public void updateControl(String text) { item.setToolTipText(text); } }); item.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { localizationPressed(); } }); return toolBar; }
private void addSearchButton(ToolBar toolBar) { final Text search = new Text(toolBar, SWT.SEARCH | SWT.ICON_CANCEL); search.setSize(100, SWT.DEFAULT); search.setMessage(Messages.LabelSearch); ToolItem toolItem = new ToolItem(toolBar, SWT.SEPARATOR); toolItem.setWidth(search.getSize().x); toolItem.setControl(search); search.addModifyListener( new ModifyListener() { @Override public void modifyText(ModifyEvent e) { String filter = search.getText().trim(); if (filter.length() == 0) { filterPattern = null; securities.refresh(); } else { filterPattern = Pattern.compile( ".*" + filter + ".*", Pattern.CASE_INSENSITIVE); // $NON-NLS-1$ //$NON-NLS-2$ securities.refresh(); } } }); }
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(); }
@Override protected Control createControl(Composite parent) { super.createControl(parent); ToolBar buttons = new ToolBar(parent, SWT.FLAT | SWT.WRAP); ToolItem changeImage = new ToolItem(buttons, SWT.PUSH); changeImage.setImage( JaspersoftStudioPlugin.getInstance().getImage("icons/resources/equalizer--arrow.png")); changeImage.setToolTipText("Set exporter properties"); changeImage.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { createPopupMenu(); if (popupMenu.isVisible()) { popupMenu.setVisible(false); } else { locatePopupMenu(popupMenu); popupMenu.setVisible(true); } } }); return buttons; }
void relayout() { ToolItem[] items = getItems(); boolean hasText = false, hasImage = false; for (int i = 0; i < items.length; i++) { ToolItem item = items[i]; if (item != null) { item.resizeControl(); hasText |= item.text != null && item.text.length() > 0; hasImage |= item.image != null; } } int type = OS.GTK_TOOLBAR_ICONS; if (hasText && hasImage) { if ((style & SWT.RIGHT) != 0) { type = OS.GTK_TOOLBAR_BOTH_HORIZ; } else { type = OS.GTK_TOOLBAR_BOTH; } } else if (hasText) { type = OS.GTK_TOOLBAR_TEXT; } else if (hasImage) { type = OS.GTK_TOOLBAR_ICONS; } OS.gtk_toolbar_set_style(handle, type); }
public ExpandButton(Composite parent) { expandImage = SATC_Activator.getImageDescriptor(EXPAND_ICON).createImage(); collapseImage = SATC_Activator.getImageDescriptor(COLLAPSE_ICON).createImage(); toolBar = new ToolBar(parent, SWT.FLAT); toolItem = new ToolItem(toolBar, SWT.PUSH); toolItem.setImage(expandImage); toolItem.addSelectionListener( new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent arg0) { // } @Override public void widgetSelected(SelectionEvent event) { setSelection(!selected); if (listeners != null) { for (SelectionListener listener : listeners) { listener.widgetSelected(event); } } } }); }
private ToolBar createHelpImageButton(Composite parent, Image image) { ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS); ((GridLayout) parent.getLayout()).numColumns++; toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER)); final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND); toolBar.setCursor(cursor); toolBar.addDisposeListener( new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { cursor.dispose(); } }); ToolItem item = new ToolItem(toolBar, SWT.NONE); item.setImage(image); item.setToolTipText(JFaceResources.getString("helpToolTip")); // $NON-NLS-1$ item.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { helpPressed(); } }); return toolBar; }
/** * Determines if the selection was on the dropdown affordance and, if so, opens the drop down menu * (populated using the same id as this item... * * @param event The <code>SWT.Selection</code> event to be tested * @return <code>true</code> iff a drop down menu was opened */ private boolean openDropDownMenu(final Event event) { final Widget item = event.widget; if (item != null) { final int style = item.getStyle(); if ((style & SWT.DROP_DOWN) != 0) { if (event.detail == 4) { // on drop-down button final ToolItem ti = (ToolItem) item; final MenuManager menuManager = new MenuManager(); final Menu menu = menuManager.createContextMenu(ti.getParent()); if (this.workbenchHelpSystem != null) { this.workbenchHelpSystem.setHelp(menu, this.helpContextId); } initDropDownMenu(menuManager); // position the menu below the drop down item final Point point = ti.getParent().toDisplay(new Point(event.x, event.y)); menu.setLocation(point.x, point.y); // waiting for SWT // 0.42 menu.setVisible(true); return true; // we don't fire the action } } } return false; }
private void handleWidgetSelection(Event e, ToolItem item) { boolean selection = item.getSelection(); int style = item.getStyle(); IAction action = (IAction) actionMap.get(item); if ((style & (SWT.TOGGLE | SWT.CHECK)) != 0) { if (action.getStyle() == IAction.AS_CHECK_BOX) { action.setChecked(selection); } } else if ((style & SWT.RADIO) != 0) { if (action.getStyle() == IAction.AS_RADIO_BUTTON) { action.setChecked(selection); } } else if ((style & SWT.DROP_DOWN) != 0) { if (e.detail == 4) { // on drop-down button if (action.getStyle() == IAction.AS_DROP_DOWN_MENU) { IMenuCreator mc = action.getMenuCreator(); ToolItem ti = (ToolItem) item; if (mc != null) { Menu m = mc.getMenu(ti.getParent()); if (m != null) { Point point = ti.getParent().toDisplay(new Point(e.x, e.y)); m.setLocation(point.x, point.y); // waiting m.setVisible(true); return; // we don't fire the action } } } } } action.runWithEvent(e); }
private static ToolItem createPublishToolItem(final ToolBar toolBar, final Shell shell) { ToolItem toolItem = createToolItem(toolBar, EMPTY, PUBLISH_TOOL_TIP_TEXT, PUBLISH_ICON); toolItem.addSelectionListener( new SelectionListener() { private static final long serialVersionUID = 3334607710375924130L; @Override public void widgetSelected(SelectionEvent e) { StatusLineManagerUtil.getDefaultStatusLineManager().removeAll(); try { publish(); } catch (Exception ex) { logger.error(ex.getMessage(), ex); StatusLineManagerUtil.setErrorMessage(ex.getMessage()); MessageDialog.openError(shell, ACTIVATION_FAILED, ex.getMessage()); } WebViewerView.refreshWebViewerViewIfVisible(); } @Override public void widgetDefaultSelected(SelectionEvent e) { // } }); return toolItem; }
@Override public void update(final ModelEvent event) { // Enable/Disable sort button if (event.part == ModelPart.OUTPUT || event.part == ModelPart.INPUT || event.part == ModelPart.SELECTED_VIEW_CONFIG) { if (model != null && model.getOutput() != null) { groupsButton.setEnabled(true); subsetButton.setEnabled(true); } else { groupsButton.setEnabled(false); subsetButton.setEnabled(false); } } // Update model if (event.part == ModelPart.MODEL) { model = (Model) event.data; reset(); } if (event.part == ModelPart.SELECTED_VIEW_CONFIG) { subsetButton.setSelection(model.getViewConfig().isSubset()); } if (event.part == ModelPart.SELECTED_ATTRIBUTE) { table.setSelectedAttribute((String) event.data); } }
/* * Overridden so that clicking in the title menu area closes the dialog. Also creates a close box menu in the title * area. */ protected Control createTitleMenuArea(Composite parent) { Composite titleComposite = (Composite) super.createTitleMenuArea(parent); titleComposite.addMouseListener(clickListener); ToolBar toolBar = new ToolBar(titleComposite, SWT.FLAT); ToolItem closeButton = new ToolItem(toolBar, SWT.PUSH, 0); GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(toolBar); closeButton.setImage( UIEplPlugin.getDefault().getImageRegistry().get((UIEplPlugin.IMG_TOOL_CLOSE))); closeButton.setHotImage( UIEplPlugin.getDefault().getImageRegistry().get((UIEplPlugin.IMG_TOOL_CLOSE_HOT))); closeButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { close(); } }); toolBar.addMouseListener( new MouseAdapter() { public void mouseDown(MouseEvent e) { close(); } }); return titleComposite; }
@SuppressWarnings("unused") // SWT constructors have side effects, they are not unused private ToolBar createLintControls() { ToolBar toolBar = new ToolBar(this, SWT.FLAT | SWT.RIGHT | SWT.HORIZONTAL); // Separate from adjacent toolbar new ToolItem(toolBar, SWT.SEPARATOR); ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages(); mLintButton = new ToolItem(toolBar, SWT.PUSH); mLintButton.setToolTipText("Show Lint Warnings for this Layout"); mLintButton.setImage(sharedImages.getImage(ISharedImages.IMG_OBJS_WARN_TSK)); mLintButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { CommonXmlEditor editor = mEditor.getEditorDelegate().getEditor(); IFile file = editor.getInputFile(); if (file != null) { EclipseLintClient.showErrors(getShell(), file, editor); } } }); return toolBar; }
/** Add a separator to the toolbar, unless there already is one there at the end already */ private static void addSeparator(ToolBar toolBar) { int n = toolBar.getItemCount(); if (n > 0 && (toolBar.getItem(n - 1).getStyle() & SWT.SEPARATOR) == 0) { ToolItem separator = new ToolItem(toolBar, SWT.SEPARATOR); separator.setWidth(15); } }
private void updateToolBar() { if (toolbar != null) { ResourceManager parentResourceManager = JFaceResources.getResources(); LocalResourceManager localManager = new LocalResourceManager(parentResourceManager); for (int i = 0; i < toolbar.getItemCount(); i++) { ToolItem item = toolbar.getItem(i); IAction action = (IAction) actionMap.get(item); if (action != null) { ImageDescriptor image = null; if (action.isEnabled() && action.getImageDescriptor() != null) image = action.getImageDescriptor(); else if (action.isEnabled() && action.getImageDescriptor() != null) image = action.getDisabledImageDescriptor(); if (image != null) item.setImage(localManager.createImageWithDefault(image)); item.setToolTipText(action.getToolTipText()); if (IAction.AS_CHECK_BOX == action.getStyle()) { item.setSelection(action.isChecked()); } } } disposeOldImages(); imageManager = localManager; if (toolbar.isFocusControl()) toolbar.setFocus(); } }
long /*int*/ menuItemSelected(long /*int*/ widget, ToolItem item) { Event event = new Event(); switch (item.style) { case SWT.DROP_DOWN: /* * Feature in GTK. The DROP_DOWN item does not * contain arrow button in the overflow menu. So, it * is impossible to select the menu of that item. * The fix is to consider the item selection * as Arrow click, in order to popup the drop-down. */ event.detail = SWT.ARROW; GtkAllocation allocation = new GtkAllocation(); OS.gtk_widget_get_allocation(widget, allocation); event.x = allocation.x; if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth() - allocation.width - event.x; event.y = allocation.y + allocation.height; break; case SWT.RADIO: if ((style & SWT.NO_RADIO_GROUP) == 0) item.selectRadio(); break; case SWT.CHECK: boolean currentSelection = item.getSelection(); item.setSelection(!currentSelection); } item.sendSelectionEvent(SWT.Selection, event, false); return 0; }
private void updateIcons() { if (this.widget instanceof MenuItem) { final MenuItem item = (MenuItem) this.widget; final LocalResourceManager m = new LocalResourceManager(JFaceResources.getResources()); try { item.setImage(this.icon == null ? null : m.createImage(this.icon)); } catch (final DeviceResourceException e) { this.icon = ImageDescriptor.getMissingImageDescriptor(); item.setImage(m.createImage(this.icon)); // as we replaced the failed icon, log the message once. StatusManager.getManager() .handle( new Status( IStatus.ERROR, SharedUIResources.PLUGIN_ID, "Failed to load image", e)); //$NON-NLS-1$ } disposeOldImages(); this.localResourceManager = m; } else if (this.widget instanceof ToolItem) { final ToolItem item = (ToolItem) this.widget; final LocalResourceManager m = new LocalResourceManager(JFaceResources.getResources()); item.setDisabledImage(this.disabledIcon == null ? null : m.createImage(this.disabledIcon)); item.setHotImage(this.hoverIcon == null ? null : m.createImage(this.hoverIcon)); item.setImage(this.icon == null ? null : m.createImage(this.icon)); disposeOldImages(); this.localResourceManager = m; } }
static long /*int*/ MenuItemSelectedProc(long /*int*/ widget, long /*int*/ user_data) { Display display = Display.getCurrent(); ToolItem item = (ToolItem) display.getWidget(user_data); if (item != null) { return item.getParent().menuItemSelected(widget, item); } return 0; }
private static ToolItem createToolItem( ToolBar toolBar, String text, String toolTipText, Image image, int style) { ToolItem toolItem = new ToolItem(toolBar, style); toolItem.setText(text); toolItem.setToolTipText(toolTipText); toolItem.setImage(image); return toolItem; }
@Override public void reset() { table.reset(); groupsButton.setEnabled(false); subsetButton.setEnabled(false); ascendingButton.setEnabled(false); descendingButton.setEnabled(false); }
private void createToolBar(final Composite parent) { ToolBar toolBar = new ToolBar(parent, SWT.NONE); toolBar.setLayoutData( GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).create()); ToolItem toolItem = new ToolItem(toolBar, SWT.NONE); toolItem.setText("Camera Demo"); Widgets.onToolItem(toolItem).useAsTitle(); }
/** {@inheritDoc} */ @Override public void sceneSelectionModeChanged(final SceneSelectionModeEvent event) { final SelectionMode selectionMode = event.getSelectionMode(); objectSelection.setSelection(selectionMode == SelectionMode.OBJECT); faceSelection.setSelection(selectionMode == SelectionMode.FACE); edgeSelection.setSelection(selectionMode == SelectionMode.EDGE); vertexSelection.setSelection(selectionMode == SelectionMode.VERTEX); }
@Override void removeControl(Control control) { super.removeControl(control); ToolItem[] items = getItems(); for (int i = 0; i < items.length; i++) { ToolItem item = items[i]; if (item.control == control) item.setControl(null); } }
@Override public void commandChanged(CommandEvent commandEvent) { myItem.setEnabled(myCommand.getCommand().isEnabled()); try { myItem.setToolTipText(myCommand.getCommand().getDescription()); } catch (final NotDefinedException ex) { LogUtils.error(this, ex); } }