private void createToolbarButton () { if ( this.button == null ) { final int index = this.toolBarNavigator.calculateToolbarIndex ( this.descriptor ); if ( index < 0 ) { return; } this.button = new ToolItem ( this.toolbar, SWT.RADIO, index ); this.button.setText ( this.descriptor.getName () ); this.button.addSelectionListener ( new SelectionAdapter () { @Override public void widgetSelected ( final org.eclipse.swt.events.SelectionEvent e ) { showView ( ToolBarNavigatorItem.this.descriptor.getId () ); }; } ); // set current state this.button.setImage ( this.currentButtonImage ); } }
public void toolBarSetEnable(String toolItemId, boolean enable) { try { final int i = toolItemsIds.get(toolItemId).intValue(); final boolean enabled = enable; getDisplay().asyncExec(new Runnable() { public void run() { if (toolBar.isDisposed()) return; ToolItem[] toolItems = toolBar.getItems(); ToolItem toolItem = toolItems[i]; if (toolItem != null) toolItem.setEnabled(enabled); } }); } catch (Exception e) { } ; }
public void toolBarSetSelection(String toolItemId, boolean select) { try { final int i = toolItemsIds.get(toolItemId).intValue(); final boolean selected = select; getDisplay().syncExec(new Runnable() { public void run() { if (toolBar.isDisposed()) return; ToolItem[] toolItems = toolBar.getItems(); ToolItem toolItem = toolItems[i]; if (toolItem != null) toolItem.setSelection(selected); } }); } catch (Exception e) { } ; }
private void deleteToolItem(ToolBar toolBar) { ToolItem tltmDelete = new ToolItem(toolBar, SWT.NONE); tltmDelete.setWidth(5); tltmDelete.setImage(ImagePathConstant.DELETE_BUTTON.getImageFromRegistry()); tltmDelete.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { for (TableItem tableItem : inputFieldTable.getSelection()) { inputFields.remove(String.valueOf(tableItem.getData())); } inputFieldTableViewer.refresh(); dialog.refreshErrorLogs(); addCusrsorToLastRow(); } }); }
private void createContent() { toolBar = new ToolBar(this, SWT.HORIZONTAL); toolBar.setEnabled(false); GridLayout layout = new GridLayout(); GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false); toolBar.setLayout(layout); toolBar.setLayoutData(layoutData); ToolItem cancelProcessToolItem = new ToolItem(toolBar, SWT.PUSH); cancelProcessToolItem.setText(resourceBundle.getString("cancel_process")); cancelProcessToolItem.addListener(SWT.Selection, event -> { listeners.forEach(DBProcessInfoViewListener::dbProcessInfoViewCancelProcessToolItemClicked); }); ToolItem terminateProcessToolItem = new ToolItem(toolBar, SWT.PUSH); terminateProcessToolItem.setText(resourceBundle.getString("kill_process")); terminateProcessToolItem.addListener(SWT.Selection, event -> { listeners.forEach(DBProcessInfoViewListener::dbProcessInfoViewTerminateProcessToolItemClicked); }); processInfoText = new Text(this, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL); GridData textLayoutData = new GridData(SWT.FILL, SWT.BOTTOM, true, false); textLayoutData.heightHint = 200; processInfoText.setLayoutData(textLayoutData); }
@Override public void runWithEvent(final Event event) { if (showMenuForDefaultAction) { final ToolItem item = (ToolItem) event.widget; final Rectangle itemRectangle = item.getBounds(); final Point point = item.getParent().toDisplay(new Point(itemRectangle.x, itemRectangle.y)); final Menu menu = getSubActionMenu(item.getParent()); menu.setLocation(point.x, point.y + itemRectangle.height); menu.setVisible(true); } else { final IAction defaultSubAction = getDefaultSubAction(); if (defaultSubAction != null && defaultSubAction.isEnabled()) { defaultSubAction.runWithEvent(event); } } }
public void createSection(final TGToolBar toolBar) { this.undo = new ToolItem(toolBar.getControl(), SWT.PUSH); this.undo.addSelectionListener(toolBar.createActionProcessor(TGUndoAction.NAME)); this.redo = new ToolItem(toolBar.getControl(), SWT.PUSH); this.redo.addSelectionListener(toolBar.createActionProcessor(TGRedoAction.NAME)); this.menuItem = new ToolItem(toolBar.getControl(), SWT.PUSH); this.menuItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { createMenu(toolBar, (ToolItem) event.widget); } }); this.loadIcons(toolBar); this.loadProperties(toolBar); }
public static void addSelectionListener(Widget w, SelectionListener l) { if (w instanceof MenuItem) addSelectionListener((MenuItem) w, l); else if (w instanceof ToolItem) addSelectionListener((ToolItem) w, l); else if (w instanceof Button) addSelectionListener((Button) w, l); else if (w instanceof DropDownToolItem) { addSelectionListener((DropDownToolItem) w, l); } else if (w instanceof CTabFolder) { addSelectionListener((CTabFolder) w, l); } else if (w instanceof Combo){ addSelectionListener((Combo) w, l); } else throw new RuntimeException("Widget type not supported for selection events: " + w); }
private void createDivisionTypeMenu(TGToolBar toolBar, ToolItem item) { TGDuration duration = TablatureEditor.getInstance(toolBar.getContext()).getTablature().getCaret().getDuration(); Menu menu = new Menu(item.getParent().getShell()); for( int i = 0 ; i < TGDivisionType.ALTERED_DIVISION_TYPES.length ; i ++ ){ TGDivisionType divisionType = TGDivisionType.ALTERED_DIVISION_TYPES[i]; MenuItem menuItem = new MenuItem(menu, SWT.CHECK); menuItem.setText(toolBar.toCheckString(Integer.toString(TGDivisionType.ALTERED_DIVISION_TYPES[i].getEnters()), (divisionType.isEqual(duration.getDivision())))); menuItem.addSelectionListener(this.createDivisionTypeAction(toolBar, divisionType)); } Rectangle rect = item.getBounds(); Point pt = item.getParent().toDisplay(new Point(rect.x, rect.y)); menu.setLocation(pt.x, pt.y + rect.height); menu.setVisible(true); }
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); ToolBar bar = new ToolBar(shell, SWT.BORDER|SWT.VERTICAL); for (int i = 0; i < 4; i++) { ToolItem item = new ToolItem(bar, 0); // item.setText("Item " + i); item.setImage(Images.APPLICATION); } bar.pack(); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
protected Control createContents(Composite parent) { // --- Create the window title. --- getShell().setText("CoolBar Test"); String asCoolItemSection[] = { "File", "Formatting", "Search" }; CoolBar composite = new CoolBar(parent, SWT.NONE); for (int idxCoolItem = 0; idxCoolItem < 3; ++idxCoolItem) { CoolItem item = new CoolItem(composite, SWT.NONE); ToolBar tb = new ToolBar(composite, SWT.FLAT); for (int idxItem = 0; idxItem < 3; ++idxItem) { ToolItem ti = new ToolItem(tb, SWT.NONE); ti .setText(asCoolItemSection[idxCoolItem] + " Item #" + idxItem); } Point p = tb.computeSize(SWT.DEFAULT, SWT.DEFAULT); tb.setSize(p); Point p2 = item.computeSize(p.x, p.y); item.setControl(tb); item.setSize(p2); } return composite; }
@Override public void setEnabled(boolean value) { super.setEnabled(value); regionsPagingToolBar.setToolbarEnabled(value); for (ToolItem ti : additionalToolItems) ti.setEnabled(value); text.setEnabled(value); if (!value) { text.setLineBullet(0, text.getLineCount(), null); text.setStyleRange(null); text.setBackground(Colors.getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND)); } else text.setBackground(Colors.getSystemColor(SWT.COLOR_WHITE)); undoRedo.setEnabled(value); if (value && showWordGraphEditorItem!=null) setWordGraphEditorVisibility(showWordGraphEditorItem.getSelection()); }
@Override public void runWithEvent(final Event event) { if (event.widget instanceof ToolItem) { final ToolItem toolItem = (ToolItem) event.widget; final Control control = toolItem.getParent(); @SuppressWarnings("hiding") final Menu menu = getMenu(control); final Rectangle bounds = toolItem.getBounds(); final Point topLeft = new Point(bounds.x, bounds.y + bounds.height); menu.setLocation(control.toDisplay(topLeft)); menu.setVisible(true); } }
@Override public void runWithEvent(Event event) { if (event.widget instanceof ToolItem) { final ToolItem toolItem = (ToolItem) event.widget; final Control control = toolItem.getParent(); final Menu menu = getMenuCreator().getMenu(control); final Rectangle bounds = toolItem.getBounds(); final Point topLeft = new Point(bounds.x, bounds.y + bounds.height); menu.setLocation(control.toDisplay(topLeft)); menu.setVisible(true); } }
private ToolItem addItemToToolBar(ToolBar bar, String text, String toolTip, int type) { ToolItem cit = new ToolItem(bar, type); if (text != null) cit.setText(text); if (toolTip != null) cit.setToolTipText(toolTip); return cit; }
private ToolItem addItemToToolBar(ToolBar bar, String text, String toolTip, int type, Listener listener, Image icon) { ToolItem item = addItemToToolBar(bar, text, toolTip, type); if (listener != null) item.addListener(SWT.Selection, listener); if (icon != null) item.setImage(icon); return item; }
private ToolItem addItemToToolBar(ToolBar bar, String text, String toolTip, int type, SelectionAdapter listener, Image icon) { ToolItem item = addItemToToolBar(bar, text, toolTip, type); if (listener != null) item.addSelectionListener(listener); if (icon != null) item.setImage(icon); return item; }
private void setToolItemIcon(ToolItem toolItem, String iconPath, String text, String tooltip) { try { toolItem.setImage(ConvertigoPlugin.getDefault().getStudioIcon(iconPath)); } catch (IOException e1) { toolItem.setText(text); } toolItem.setToolTipText(tooltip); }
private void initIcons(){ Object [][] tmp_buttons = { {bt_back,"back"}, {bt_forward,"forward"}, {bt_refresh,"refresh"}, {bt_stop,"stop"}, {bt_go,"go"}, {bt_allow_alert,"allow alert box"}, {bt_tab_new,"new tab"}, {bt_tab_close,"close tab"}, {bt_tab_previous,"previous tab"}, {bt_tab_next,"next tab"} }; buttons = new HashMap<String, ToolItem>(tmp_buttons.length); for(int i=0;i<tmp_buttons.length;i++){ buttons.put((String) tmp_buttons[i][1], (ToolItem)tmp_buttons[i][0]); ((ToolItem)tmp_buttons[i][0]).setToolTipText((String)tmp_buttons[i][1]); setEnable((String)tmp_buttons[i][1],true); } }
private void dialogBuild(ToolItem buildModeItem, MenuItem menuItem) { MobileBuilderBuildMode newBuildMode = (MobileBuilderBuildMode) menuItem.getData(); if (dialogBuild(newBuildMode)) { buildModeItem.setImage(menuItem.getImage()); buildModeItem.setToolTipText("Rebuild in: " + buildMode.label() + "\n" + buildMode.description()); try { JSONObject device = new JSONObject(FileUtils.readFileToString(devicePref, "UTF-8")); device.put("buildMode", buildMode.name()); FileUtils.write(devicePref, device.toString(4), "UTF-8"); } catch (Exception ex) { Engine.logStudio.debug("Cannot save build mode", ex); } } }
void toolBarSetEnable(String toolItemId, boolean enable) { final int i = toolItemsIds.get(toolItemId).intValue(); final boolean enabled = enable; getDisplay().syncExec(new Runnable() { public void run() { ToolItem[] toolItems = toolBar.getItems(); ToolItem toolItem = toolItems[i]; if (toolItem != null) toolItem.setEnabled(enabled); } }); }
void toolBarSetSelection(String toolItemId, boolean select) { final int i = toolItemsIds.get(toolItemId).intValue(); final boolean selected = select; getDisplay().syncExec(new Runnable() { public void run() { ToolItem[] toolItems = toolBar.getItems(); ToolItem toolItem = toolItems[i]; if (toolItem != null) toolItem.setSelection(selected); } }); }
/** * Creates the toolbar. */ private void createToolBar(Composite composite, Object layoutData) { toolBar = new ToolBar(composite, SWT.FLAT); toolBar.addListener(SWT.KeyUp, createToolbarCommandHandler()); if (layoutData != null) toolBar.setLayoutData(layoutData); if (nativeFilter != null) { nativeFilterAdapter = (FilterAdapter) nativeFilterAdapterMap.get(nativeFilter.getClass()); if (nativeFilterAdapter != null) { nativeToolItem = nativeFilterAdapter.create(toolBar); nativeToolItem.setSelection(true); } } hexDumpToolItem = createHexDumpToolItem(); if (nativeFilterAdapter == null) { // Default button changes for these instances. hexDumpToolItem.setSelection(true); // Prevent NullPointerExceptions if the nativeFilterAdapter does not apply. nativeFilterAdapter = hexFilterAdapter; } rawDumpToolItem = createRawDumpToolItem(); new ToolItem(toolBar, SWT.SEPARATOR); copyToolItem = createCopyToolItem(); new ToolItem(toolBar, SWT.SEPARATOR); createPrintToolItem(); toolBar.pack(); }
/** * Create the hex dump tool item (button). */ protected ToolItem createHexDumpToolItem() { hexFilterAdapter = new HexFilterAdapter(this, textBundle.get("FileViewerWindow.HexDumpButton"), //$NON-NLS-1$ textBundle.get("FileViewerWindow.HexDumpTooltip"), //$NON-NLS-1$ imageManager.get(ImageManager.ICON_VIEW_IN_HEX)); hexFilterAdapter.setHexSelected(); ToolItem toolItem = hexFilterAdapter.create(toolBar); return toolItem; }
/** * Create the raw dump tool item (button). */ protected ToolItem createRawDumpToolItem() { rawDumpFilterAdapter = new RawDumpFilterAdapter(this, textBundle.get("FileViewerWindow.RawDumpButton"), //$NON-NLS-1$ textBundle.get("FileViewerWindow.RawDumpTooltip"), //$NON-NLS-1$ imageManager.get(ImageManager.ICON_VIEW_IN_RAW_HEX)); rawDumpFilterAdapter.setDumpSelected(); ToolItem toolItem = rawDumpFilterAdapter.create(toolBar); return toolItem; }
/** * Create the copy tool item (button). */ protected ToolItem createCopyToolItem() { ToolItem toolItem = new ToolItem(toolBar, SWT.PUSH); toolItem.setImage(imageManager.get(ImageManager.ICON_COPY)); toolItem.setText(textBundle.get("FileViewerWindow.CopyButton")); //$NON-NLS-1$ toolItem.setToolTipText(textBundle.get("FileViewerWindow.CopyTooltip")); //$NON-NLS-1$ toolItem.setEnabled(true); toolItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { getContentTypeAdapter().copy(); } }); return toolItem; }
/** * Create the print tool item (button). */ protected ToolItem createPrintToolItem() { ToolItem toolItem = new ToolItem(toolBar, SWT.PUSH); toolItem.setImage(imageManager.get(ImageManager.ICON_PRINT_FILE)); toolItem.setText(textBundle.get("PrintButton")); //$NON-NLS-1$ toolItem.setToolTipText(textBundle.get("FileViewerWindow.PrintTooltip")); //$NON-NLS-1$ toolItem.setEnabled(true); toolItem.addSelectionListener(new SelectionAdapter () { public void widgetSelected(SelectionEvent e) { getContentTypeAdapter().print(); } }); return toolItem; }
/** * Handle selection events. */ public void widgetSelected(SelectionEvent event) { /** * A selection event will be fired when a drop down tool * item is selected in the main area and in the drop * down arrow. Examine the event detail to determine * where the widget was selected. */ if (event.detail == SWT.ARROW) { /* * The drop down arrow was selected. */ if (visible) { // Hide the menu to give the Arrow the appearance of being a toggle button. setMenuVisible(false); } else { // Position the menu below and vertically aligned with the the drop down tool button. final ToolItem toolItem = (ToolItem) event.widget; final ToolBar toolBar = toolItem.getParent(); Rectangle toolItemBounds = toolItem.getBounds(); Point point = toolBar.toDisplay(new Point(toolItemBounds.x, toolItemBounds.y)); menu.setLocation(point.x, point.y + toolItemBounds.height); setMenuVisible(true); } } else { /* * Main area of drop down tool item selected. * An application would invoke the code to perform the action for the tool item. */ } }
private void addToolItem(ToolBar toolBar) { ToolItem tltmNewItem = new ToolItem(toolBar, SWT.NONE); tltmNewItem.setImage(ImagePathConstant.ADD_BUTTON.getImageFromRegistry()); tltmNewItem.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { inputFields.add("Field"); dialog.refreshErrorLogs(); } }); }
/** * Returns tool-item of tool-bar * * @param toolBarId * @param toolItemId * @return * ToolItem of given id. */ public ToolItem getToolItemFromToolBarManger(String toolBarId, String toolItemId) { ToolBarContributionItem toolBarContributionItem = getToolBarMangerOrMenuManagerFromCoolBar(toolBarId); if (toolBarContributionItem != null && toolBarContributionItem.getToolBarManager() != null) { for (IContributionItem contributionItem : toolBarContributionItem.getToolBarManager().getItems()) { if (contributionItem instanceof HandledContributionItem && StringUtils.equals(toolItemId, contributionItem.getId())) { ToolItem item = (ToolItem) ((HandledContributionItem) contributionItem).getWidget(); return item; } } } return null; }
/** * Enable disable run button. * * @param enable the new run job enabled */ public void setRunJobEnabled(boolean enable) { Display.getDefault().asyncExec(new Runnable() { @Override public void run() { setBaseEnabled(enable); ToolItem item = WorkbenchWidgetsUtils.INSTANCE.getToolItemFromToolBarManger( Constants.RUN_STOP_BUTTON_TOOLBAR_ID, Constants.RUN_BUITTON_TOOLITEM_ID); if (item != null) { item.setEnabled(enable); } } }); }
/** * Enable/Disable stop button * * @param enable */ public void setStopJobEnabled(boolean enable) { Display.getDefault().asyncExec(new Runnable() { @Override public void run() { setBaseEnabled(enable); ToolItem item = WorkbenchWidgetsUtils.INSTANCE.getToolItemFromToolBarManger( Constants.RUN_STOP_BUTTON_TOOLBAR_ID, Constants.STOP_BUITTON_TOOLITEM_ID); if (item != null) { item.setEnabled(enable); } } }); }
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { // Sanity check. if (null == event) { return null; } // Class check. if (!(event.getTrigger() instanceof Event)) { return null; } final Event eventWidget = (Event) event.getTrigger(); // Makes sure event came from a ToolItem. if (!(eventWidget.widget instanceof ToolItem)) { return null; } final ToolItem toolItem = (ToolItem) eventWidget.widget; // Creates fake selection event. final Event newEvent = new Event(); newEvent.button = 1; newEvent.widget = toolItem; newEvent.detail = SWT.ARROW; newEvent.x = toolItem.getBounds().x; newEvent.y = toolItem.getBounds().y + toolItem.getBounds().height; // Dispatches the event. toolItem.notifyListeners(SWT.Selection, newEvent); return null; }
public BufferedToolItem( ToolBar tool_bar, int attributes ) { super( new ToolItem( tool_bar, attributes )); item = (ToolItem)getWidget(); }