/* (non-Javadoc) * @see org.eclipse.tcf.te.tcf.ui.dialogs.AbstractArraySelectionDialog#updateEnablement(org.eclipse.jface.viewers.TableViewer) */ @Override protected void updateEnablement(TableViewer viewer) { if (viewer.getTable().getSelectionCount() == 0) { viewer.getTable().setSelection(0); } Entry entry = getSelectedEntry(); // Adjust the OK button enablement Button okButton = getButton(IDialogConstants.OK_ID); SWTControlUtil.setEnabled( okButton, entry != null && entry.delegate.validate(entry.peerNode, entry.data)); if (menuExecute != null) { menuExecute.setEnabled(entry != null && entry.delegate.validate(entry.peerNode, entry.data)); } // Adjust the edit button enablement Button editButton = getButton(EDIT_ID); SWTControlUtil.setEnabled(editButton, entry != null); if (menuEdit != null) { menuEdit.setEnabled(entry != null); } // Adjust the copy button enablement Button copyButton = getButton(COPY_ID); SWTControlUtil.setEnabled(copyButton, entry != null); if (menuCopy != null) { menuCopy.setEnabled(entry != null); } if (menuRemove != null) { menuRemove.setEnabled(entry != null); } }
@Override public void widgetSelected(SelectionEvent e) { clipSelection(); int selectionLen = Math.abs(e.y - e.x); cutItem.setEnabled(!readOnly && selectionLen > 0); copyItem.setEnabled(selectionLen > 0); pasteItem.setEnabled(!readOnly); }
// restarts maze and window buttons (after win) private void restart() { shell.removeKeyListener(keyListener); shell.removeMouseWheelListener(mouseWheelListener); generateMenuItem.setEnabled(true); loadMenuItem.setEnabled(true); loadRemoteMenuItem.setEnabled(true); saveMenuItem.setEnabled(false); solveMenuItem.setEnabled(false); }
/** * Locate an action (a menu item, actually) with the given id in the current menu bar and run it. * * @param actionId the action to find * @return true if an action was found, false otherwise */ private boolean runAction(String actionId) { MWindow window = app.getSelectedElement(); if (window == null) { return false; } MMenu topMenu = window.getMainMenu(); MMenuItem item = findAction(actionId, topMenu); if (item == null || !item.isEnabled()) { return false; } try { // disable the about and prefs items -- they shouldn't be // able to be run when another item is being triggered final Display display = Display.getDefault(); MenuItem aboutItem = null; boolean aboutEnabled = true; MenuItem prefsItem = null; boolean prefsEnabled = true; Menu appMenuBar = display.getMenuBar(); if (appMenuBar != null) { aboutItem = findMenuItemById(appMenuBar, SWT.ID_ABOUT); if (aboutItem != null) { aboutEnabled = aboutItem.getEnabled(); aboutItem.setEnabled(false); } prefsItem = findMenuItemById(appMenuBar, SWT.ID_PREFERENCES); if (prefsItem != null) { prefsEnabled = prefsItem.getEnabled(); prefsItem.setEnabled(false); } } try { simulateMenuSelection(item); } finally { if (prefsItem != null) { prefsItem.setEnabled(prefsEnabled); } if (aboutItem != null) { aboutItem.setEnabled(aboutEnabled); } } } catch (Exception e) { // theoretically, one of // SecurityException,Illegal*Exception,InvocationTargetException,NoSuch*Exception // not expected to happen at all. log(e); // return false? } return true; }
@Override public void setMode(CommandLineMode mode) { if (mode == CommandLineMode.DEFAULT) { commandLineText.setEditable(true); if (registerModeSelection != null) { commandLineText.replaceTextRange(registerModeSelection.x, 1, ""); commandLineText.setSelection(registerModeSelection); registerModeSelection = null; } else { // Reset any selection made in a readonly mode, otherwise we need to check if // cut/copy needs to be enabled. commandLineText.setSelection(commandLineText.getCaretOffset()); } readOnly = false; } else if (mode == CommandLineMode.REGISTER) { if (registerModeSelection == null) { Point sel = commandLineText.getSelection(); int leftOffset = Math.min(sel.x, sel.y); commandLineText.replaceTextRange(leftOffset, 0, "\""); registerModeSelection = sel; readOnly = true; } } else if (mode == CommandLineMode.MESSAGE || mode == CommandLineMode.MESSAGE_CLIPPED) { commandLineText.setEditable(false); setPosition(0); commandLineText.setTopIndex(0); readOnly = true; pasteItem.setEnabled(false); commandLineText.setWordWrap(mode == CommandLineMode.MESSAGE); } }
@Override public void close() { commandLineText.setVisible(false); commandLineText.setEditable(true); registerModeSelection = null; prompt = ""; contentsOffset = 0; resetContents(""); commandLineText.setWordWrap(true); readOnly = false; copyItem.setEnabled(false); cutItem.setEnabled(false); pasteItem.setEnabled(true); }
@Override public void menuShown(MenuEvent e) { oldListener.menuShown(e); // now lets see if we have a rascal menu IStructuredSelection selection = (IStructuredSelection) selectionProvider.getSelection(); if (selection.size() != 1) { return; } final TestElement testElement = (TestElement) selection.getFirstElement(); if (TestNameTranslator.isRascalTestElement(testElement)) { MenuItem gotoFile = ((Menu) e.getSource()).getItem(0); Listener oldListener = gotoFile.getListeners(SWT.Selection)[0]; gotoFile.removeListener(SWT.Selection, oldListener); gotoFile.addListener( SWT.Selection, new TypedListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { TestNameTranslator.tryOpenRascalTest(testElement); } })); } else if (TestNameTranslator.isRascalSuiteElement(testElement)) { MenuItem gotoFile = ((Menu) e.getSource()).getItem(0); gotoFile.setEnabled(false); } }
private void updateMenuItem() { final MenuItem item = (MenuItem) this.widget; final boolean shouldBeEnabled = isEnabled(); // disabled command + visibility follows enablement == disposed if (item.isDisposed()) { return; } String text = this.label; text = updateMnemonic(text); final String keyBindingText = null; if (text != null) { if (keyBindingText == null) { item.setText(text); } else { item.setText(text + '\t' + keyBindingText); } } if (item.getSelection() != this.checkedState) { item.setSelection(this.checkedState); } if (item.getEnabled() != shouldBeEnabled) { item.setEnabled(shouldBeEnabled); } }
/** * Recursive method to create a menu from the contribute items of a manger * * @param menu actual menu * @param items manager contributor items */ private void createMenu(Menu menu, IContributionItem[] items) { for (IContributionItem item : items) { if (item instanceof MenuManager) { MenuManager manager = (MenuManager) item; MenuItem subMenuItem = new MenuItem(menu, SWT.CASCADE); subMenuItem.setText(manager.getMenuText()); Menu subMenu = new Menu(Display.getCurrent().getActiveShell(), SWT.DROP_DOWN); subMenuItem.setMenu(subMenu); createMenu(subMenu, manager.getItems()); } else if (item instanceof ActionContributionItem) { ActionContributionItem actionItem = (ActionContributionItem) item; if (actionItem.getAction() instanceof CustomSelectionAction) { final CustomSelectionAction action = (CustomSelectionAction) actionItem.getAction(); MenuItem actionEnrty = new MenuItem(menu, SWT.CHECK); action.setSelection(getLastRawSelection()); actionEnrty.setText(actionItem.getAction().getText()); actionEnrty.setSelection(action.isChecked()); actionEnrty.setEnabled(action.canExecute()); actionEnrty.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { action.run(); } }); } } } }
public Object createWidget(final MUIElement element, Object parent) { if (!(element instanceof MMenu)) return null; final MMenu menuModel = (MMenu) element; Menu newMenu = null; if (parent instanceof Decorations) { MUIElement container = (MUIElement) ((EObject) element).eContainer(); if (container instanceof MWindow) { newMenu = new Menu((Decorations) parent, SWT.BAR); newMenu.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent e) { cleanUp(menuModel); } }); } else { newMenu = new Menu((Decorations) parent, SWT.POP_UP); } } else if (parent instanceof Menu) { int addIndex = calcVisibleIndex(menuModel); MenuItem newItem = new MenuItem((Menu) parent, SWT.CASCADE, addIndex); setItemText(menuModel, newItem); newItem.setImage(getImage(menuModel)); newItem.setEnabled(menuModel.isEnabled()); return newItem; } else if (parent instanceof Control) { newMenu = new Menu((Control) parent); } return newMenu; }
public void fill(Menu menu, int index) { if (getParent() instanceof MenuManager) { ((MenuManager) getParent()).addMenuListener(menuListener); } if (!dirty) { return; } if (currentManager != null && currentManager.getSize() > 0) { IMenuService service = (IMenuService) locator.getService(IMenuService.class); service.releaseContributions(currentManager); currentManager.removeAll(); } currentManager = new MenuManager(); fillMenu(currentManager); IContributionItem[] items = currentManager.getItems(); if (items.length == 0) { MenuItem item = new MenuItem(menu, SWT.NONE, index++); item.setText(NO_TARGETS_MSG); item.setEnabled(false); } else { for (int i = 0; i < items.length; i++) { if (items[i].isVisible()) { items[i].fill(menu, index++); } } } dirty = false; }
public MenuItem getOptimizeCatalogsMenuItem() { if (optimizeCatalogsMenuItem == null) { new MenuItem(getCatalogs(), SWT.SEPARATOR); optimizeCatalogsMenuItem = new MenuItem(getCatalogs(), SWT.PUSH); optimizeCatalogsMenuItem.setText("&optimize"); Image img = new Image(getMaster().getDisplay(), "images/optimize.png"); optimizeCatalogsMenuItem.setImage(img); optimizeCatalogsMenuItem.setEnabled(false); } return optimizeCatalogsMenuItem; }
private void createRemoveMenuItem() { MenuItem removeItem = new MenuItem(popupMenu, SWT.PUSH); removeItem.setText("Delete"); ImageDescriptor descriptor = ImageDescriptor.createFromURL( Plugin.getDefault().getBundle().getEntry(getDeleteImagePath())); removeItem.setImage(SharedImages.INSTANCE.getImage(descriptor)); removeItem.setEnabled(hasSelection()); removeItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { removeSelectedObject(); } }); }
private void setEnabled(MHandledMenuItem itemModel, MenuItem newItem) { ParameterizedCommand cmd = itemModel.getWbCommand(); if (cmd == null) { return; } final IEclipseContext lclContext = getContext(itemModel); EHandlerService service = lclContext.get(EHandlerService.class); final IEclipseContext staticContext = EclipseContextFactory.create(HMI_STATIC_CONTEXT); ContributionsAnalyzer.populateModelInterfaces( itemModel, staticContext, itemModel.getClass().getInterfaces()); try { itemModel.setEnabled(service.canExecute(cmd, staticContext)); } finally { staticContext.dispose(); } newItem.setEnabled(itemModel.isEnabled()); }
/* * (non-Javadoc) * * @see * org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#processContents * (org.eclipse.e4.ui.model.application.ui.MElementContainer) */ @Override public void processContents(MElementContainer<MUIElement> container) { if (container.getChildren().size() == 0) { Object obj = container.getWidget(); if (obj instanceof MenuItem) { MenuItem mi = (MenuItem) obj; if (mi.getMenu() == null) { mi.setMenu(new Menu(mi)); } Menu menu = mi.getMenu(); MenuItem menuItem = new MenuItem(menu, SWT.PUSH); menuItem.setText(MenuManagerRendererFilter.NUL_MENU_ITEM); menuItem.setEnabled(false); } } super.processContents(container); Object obj = container.getWidget(); Object menuObj = container; if ((obj instanceof Menu) && (((Menu) obj).getStyle() & SWT.BAR) != 0 && (menuObj instanceof MMenu)) { MMenu menuModel = (MMenu) menuObj; IEclipseContext ctx = getContext(container); ExpressionContext eContext = new ExpressionContext(ctx); ArrayList<MMenuContribution> toContribute = new ArrayList<MMenuContribution>(); ContributionsAnalyzer.gatherMenuContributions( menuModel, application.getMenuContributions(), menuModel.getElementId(), toContribute, eContext, false); addMenuBarContributions(menuModel, toContribute, ctx, eContext); } }
/** * Create a MenuItem * * @param parent Containing menu * @param style Item's style * @param text Item's text (optional: null) * @param icon Item's icon (optional: null) * @param accel Item's accelerator (optional: <0) * @param enabled Item's enabled state * @param callback Name of zero-arg method to call */ protected MenuItem createMenuItem( Menu parent, int style, String text, Image icon, int accel, boolean enabled, String callback) { MenuItem mi = new MenuItem(parent, style); if (text != null) { mi.setText(text); } if (icon != null) { mi.setImage(icon); } if (accel != -1) { mi.setAccelerator(accel); } mi.setEnabled(enabled); if (callback != null) { registerCallback(mi, this, callback); } return mi; }
/** * Updates the menu item for this sub menu. The menu item is disabled if this sub menu is empty. * Does nothing if this menu is not a submenu. */ private void updateMenuItem() { /* * Commented out until proper solution to enablement of * menu item for a sub-menu is found. See bug 30833 for * more details. * if (menuItem != null && !menuItem.isDisposed() && menuExist()) { IContributionItem items[] = getItems(); boolean enabled = false; for (int i = 0; i < items.length; i++) { IContributionItem item = items[i]; enabled = item.isEnabled(); if(enabled) break; } // Workaround for 1GDDCN2: SWT:Linux - MenuItem.setEnabled() always causes a redraw if (menuItem.getEnabled() != enabled) menuItem.setEnabled(enabled); } */ // Partial fix for bug #34969 - diable the menu item if no // items in sub-menu (for context menus). if (menuItem != null && !menuItem.isDisposed() && menuExist()) { boolean enabled = removeAllWhenShown || menu.getItemCount() > 0; // Workaround for 1GDDCN2: SWT:Linux - MenuItem.setEnabled() always causes a redraw if (menuItem.getEnabled() != enabled) { // We only do this for context menus (for bug #34969) Menu topMenu = menu; while (topMenu.getParentMenu() != null) { topMenu = topMenu.getParentMenu(); } if ((topMenu.getStyle() & SWT.BAR) == 0) { menuItem.setEnabled(enabled); } } } }
@Override void initWidgets() { shell.setLayout(new GridLayout(2, false)); // init msg box msgBox = new MessageBox(shell, SWT.ICON_INFORMATION); // user key press listener keyListener = new KeyListener() { @Override public void keyReleased(KeyEvent arg0) {} @Override public void keyPressed(KeyEvent e) { if (e.keyCode == SWT.ARROW_UP) { mazeWidget.moveDown(); } else if (e.keyCode == SWT.ARROW_DOWN) { mazeWidget.moveUp(); } else if (e.keyCode == SWT.ARROW_RIGHT) { mazeWidget.moveRight(); } else if (e.keyCode == SWT.ARROW_LEFT) { mazeWidget.moveLeft(); } else if (e.keyCode == SWT.PAGE_UP) { // play stairs sound mazeWidget.moveFront(); } else if (e.keyCode == SWT.PAGE_DOWN) { // play downstairs sound mazeWidget.moveBack(); } } }; // user mouse wheel listener (zoom in/out) mouseWheelListener = new MouseWheelListener() { @Override public void mouseScrolled(MouseEvent e) { // if both ctrl and wheel are being operated if ((e.stateMask & SWT.CTRL) != 0) mazeWidget.setSize( mazeWidget.getSize().x + e.count, mazeWidget.getSize().y + e.count); } }; // menu Menu menuBar = new Menu(shell, SWT.BAR); // ****FILE MENU**** MenuItem cascadeFileMenuItem = new MenuItem(menuBar, SWT.CASCADE); cascadeFileMenuItem.setText("File"); Menu fileMenu = new Menu(shell, SWT.DROP_DOWN); cascadeFileMenuItem.setMenu(fileMenu); MenuItem settingsMenuItem = new MenuItem(fileMenu, SWT.PUSH); settingsMenuItem.setText("Settings"); settingsMenuItem.addSelectionListener( new SelectionListener() { // CHANGE SETTINGS DIALOG @Override public void widgetSelected(SelectionEvent arg0) { // loads dynamic dialgo form for the properties class ClassGUIDialogLoader dialog = new ClassGUIDialogLoader( shell, SWT.DIALOG_TRIM | SWT.SYSTEM_MODAL, Properties.class, prop); // SUBMIT CHANGE SETTINGS EVENT dialog.setSubmitListener( new SelectionListener() { @Override public void widgetSelected(SelectionEvent arg0) { Properties newProp = (Properties) dialog.getInstance(); try { PropertiesHandler.writeProperties(newProp, "res/properties/properties.xml"); } catch (IOException e) { showMessage("Notice", "Couldn't write new properties"); return; } showMessage("Notice", "You must restart for changed to take effect"); } @Override public void widgetDefaultSelected(SelectionEvent arg0) {} }); dialog.showDialog(); } @Override public void widgetDefaultSelected(SelectionEvent arg0) {} }); MenuItem exitMenuItem = new MenuItem(fileMenu, SWT.PUSH); exitMenuItem.setText("Exit"); exitMenuItem.addSelectionListener( new SelectionListener() { @Override public void widgetSelected(SelectionEvent arg0) { // safe exit setCommandAndNotify(cli.getCommandByInput("exit"), null); close(); } @Override public void widgetDefaultSelected(SelectionEvent arg0) { // TODO Auto-generated method stub } }); // ****MAZE MENU**** MenuItem cascadeMazeMenuItem = new MenuItem(menuBar, SWT.CASCADE); cascadeMazeMenuItem.setText("Game"); Menu mazeMenu = new Menu(shell, SWT.DROP_DOWN); cascadeMazeMenuItem.setMenu(mazeMenu); generateMenuItem = new MenuItem(mazeMenu, SWT.PUSH); generateMenuItem.setText("Generate Your Maze"); // **LOAD/SAVE LOCALLY** loadMenuItem = new MenuItem(mazeMenu, SWT.PUSH); loadMenuItem.setText("Load Maze From File"); loadMenuItem.addSelectionListener( new SelectionListener() { @Override public void widgetSelected(SelectionEvent arg0) { FileDialog fd = new FileDialog(shell, SWT.OPEN); fd.setText("Load Maze File"); fd.setFilterExtensions(new String[] {"*.maz"}); String selectedMaze = fd.open(); if (selectedMaze != null) { // build the name based on the file name(in CLI you can just // insert a new name) String mazeName = selectedMaze.substring( selectedMaze.lastIndexOf("\\") + 1, selectedMaze.lastIndexOf(".")); String commandLine = "load maze " + selectedMaze + " " + mazeName; if (cli.getCommandByInput(commandLine) != null) setCommandAndNotify(cli.getCommandByInput(commandLine), commandLine.split(" ")); } } @Override public void widgetDefaultSelected(SelectionEvent arg0) {} }); saveMenuItem = new MenuItem(mazeMenu, SWT.PUSH); saveMenuItem.setText("Save Maze To File"); saveMenuItem.addSelectionListener( new SelectionListener() { @Override public void widgetSelected(SelectionEvent arg0) { FileDialog fd = new FileDialog(shell, SWT.SAVE); fd.setText("Save Maze File"); fd.setFilterExtensions(new String[] {"*.maz"}); String selectedMaze = fd.open(); if (selectedMaze != null) { String commandLine = "save maze " + currentMaze + " " + selectedMaze; if (cli.getCommandByInput(commandLine) != null) setCommandAndNotify(cli.getCommandByInput(commandLine), commandLine.split(" ")); } } @Override public void widgetDefaultSelected(SelectionEvent arg0) { // TODO Auto-generated method stub } }); saveMenuItem.setEnabled(false); // REMOTE LOAD loadRemoteMenuItem = new MenuItem(mazeMenu, SWT.PUSH); loadRemoteMenuItem.setText("Load Maze From Server"); loadRemoteMenuItem.addSelectionListener( new SelectionListener() { @Override public void widgetSelected(SelectionEvent arg0) { String commandLine = "get remote cached mazes"; setCommandAndNotify(cli.getCommandByInput(commandLine), null); } @Override public void widgetDefaultSelected(SelectionEvent arg0) {} }); solveMenuItem = new MenuItem(mazeMenu, SWT.PUSH); solveMenuItem.setText("Please Help me to solve"); shell.setMenuBar(menuBar); solveMenuItem.setEnabled(false); solveMenuItem.addSelectionListener( new SelectionListener() { @Override // SOLVE MAZE EVENT public void widgetSelected(SelectionEvent arg0) { solveMenuItem.setEnabled(false); generateMenuItem.setEnabled(false); // builds a command based on current maze and current solve // algorithm specified in the properties String commandLine = "solve " + currentMaze; setCommandAndNotify(cli.getCommandByInput(commandLine), commandLine.split(" ")); } @Override public void widgetDefaultSelected(SelectionEvent arg0) { // TODO Auto-generated method stub } }); // GENERATE MAZE EVENT generateMenuItem.addSelectionListener( new SelectionListener() { @Override public void widgetSelected(SelectionEvent arg0) { // loads dynamic maze form dialog (name,levels,width,height) ClassGUIDialogLoader dialog = new ClassGUIDialogLoader( shell, SWT.DIALOG_TRIM | SWT.SYSTEM_MODAL, Maze3DFormDetailes.class); dialog.setSubmitListener( new SelectionListener() { @Override public void widgetSelected(SelectionEvent arg0) { Maze3DFormDetailes mazeForm = (Maze3DFormDetailes) dialog.getInstance(); // validates fields(not null and in range) if (mazeForm != null && mazeForm.getName() != null && !mazeForm.getName().isEmpty() && mazeForm.getLevels() != null && !mazeForm.getLevels().equals(0) && mazeForm.getHeight() != null && !mazeForm.getHeight().equals(0) && mazeForm.getWidth() != null && !mazeForm.getWidth().equals(0)) { // builds the command String commandLine = "generate 3d maze " + mazeForm.getName() + " " + mazeForm.getLevels() + " " + mazeForm.getHeight() + " " + mazeForm.getWidth(); setCommandAndNotify( cli.getCommandByInput(commandLine), commandLine.split(" ")); // sets the current maze name to the user specified // maze // name currentMaze = mazeForm.getName(); } } @Override public void widgetDefaultSelected(SelectionEvent arg0) {} }); dialog.showDialog(); } @Override public void widgetDefaultSelected(SelectionEvent arg0) { // TODO Auto-generated method stub } }); shell.addListener( SWT.Close, new Listener() { @Override public void handleEvent(Event e) { setCommandAndNotify(cli.getCommandByInput("exit"), null); // close(); } }); }
/* * (non-Javadoc) * * @see org.eclipse.jface.action.ContributionItem#update(java.lang.String) */ public void update(String id) { if (widget != null) { if (widget instanceof MenuItem) { MenuItem item = (MenuItem) widget; String text = label; if (text == null) { if (command != null) { try { text = command.getCommand().getName(); } catch (NotDefinedException e) { WorkbenchPlugin.log( "Update item failed " //$NON-NLS-1$ + getId(), e); } } } // TODO: [bm] key bindings // text = updateMnemonic(text); // // String keyBindingText = null; // if (command != null) { // TriggerSequence[] bindings = bindingService // .getActiveBindingsFor(command); // if (bindings.length > 0) { // keyBindingText = bindings[0].format(); // } // } // if (text != null) { // if (keyBindingText == null) { item.setText(text); // } else { // item.setText(text + '\t' + keyBindingText); // } // } updateIcons(); if (item.getSelection() != checkedState) { item.setSelection(checkedState); } boolean shouldBeEnabled = isEnabled(); if (item.getEnabled() != shouldBeEnabled) { item.setEnabled(shouldBeEnabled); } } else if (widget instanceof ToolItem) { ToolItem item = (ToolItem) widget; if (icon != null) { updateIcons(); } else if (label != null) { item.setText(label); } if (tooltip != null) item.setToolTipText(tooltip); else { String text = label; if (text == null) { if (command != null) { try { text = command.getCommand().getName(); } catch (NotDefinedException e) { WorkbenchPlugin.log( "Update item failed " //$NON-NLS-1$ + getId(), e); } } } if (text != null) { item.setToolTipText(text); } } if (item.getSelection() != checkedState) { item.setSelection(checkedState); } boolean shouldBeEnabled = isEnabled(); if (item.getEnabled() != shouldBeEnabled) { item.setEnabled(shouldBeEnabled); } } } }
/** * Constructor. * * @param parent Cf. parent {@link FigureCanvas#FigureCanvas(Composite, int)}. * @param style Cf. parent {@link FigureCanvas#FigureCanvas(Composite, int)}. */ public ConnectionCanvas(Composite parent, int style) { super(parent, style); // create canvas parentFigure = new Figure(); parentFigure.setLayoutManager(new XYLayout()); setContents(parentFigure); // add a MouseListener to handle the selection of connections parentFigure.addMouseListener( new MouseListener() { public void mouseDoubleClicked(MouseEvent e) { // } public void mousePressed(MouseEvent e) { if (e.button == 1) { // clear the previous selection setSelection(null, (e.getState() & SWT.CONTROL) != 0); // gather the connections indicated with the mouse click Set<ConnectionFigure> selection = findConnectionsAt(e.x, e.y, DEFAULT_TOLERANCE); // set the new selection setSelection(selection, (e.getState() & SWT.CONTROL) != 0); // enable the 'delete' menu item, if connections are selected, disable otherwise deleteMenuItem.setEnabled(!selection.isEmpty()); } } public void mouseReleased(MouseEvent e) { // } }); // add a KeyListener to handle deletion of connections this.addKeyListener( new KeyListener() { @Override public void keyReleased(KeyEvent e) { // if DEL was pressed delete the currently selected connections if (e.character == SWT.DEL) { deleteSelectedConnections(); } } @Override public void keyPressed(KeyEvent e) { // } }); // create the context menu contextMenu = new Menu(this); setMenu(contextMenu); deleteMenuItem = new MenuItem(contextMenu, SWT.NONE); deleteMenuItem.setEnabled(false); deleteMenuItem.setText(Messages.delete); // add a SelectionListener to the 'delete' menu item to handle deletion of connections deleteMenuItem.addSelectionListener( new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { // } public void widgetSelected(SelectionEvent e) { deleteSelectedConnections(); } }); }
/** * Creates the table component attaching it to the given composite object * * @param parent composite object * @return The created table component */ public Table createTable(Composite parent) { int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.HIDE_SELECTION | SWT.FULL_SELECTION; Table table = new Table(parent, style); GridData gridData = new GridData(GridData.FILL_BOTH); gridData.grabExcessVerticalSpace = true; gridData.horizontalSpan = 3; table.setLayoutData(gridData); table.setLinesVisible(true); table.setHeaderVisible(true); table.setToolTipText(TexlipsePlugin.getResourceString("tableviewTableTooltip")); TableColumn column; for (int i = 0; i < TexRow.COLUMNS; i++) { column = new TableColumn(table, SWT.LEFT, 0); column.setText(columnNames[i]); column.setWidth(50); } // The way to add listener to column, so that rows are sorted when header is clicked /* column.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { tableViewer.setSorter(new TexRowSorter()); } }); */ menu = new Menu(parent); MenuItem mi; mi = new MenuItem(menu, SWT.SINGLE); mi.setText(TexlipsePlugin.getResourceString("tableviewInsertRow")); mi.setEnabled(true); mi.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { TexRow row = (TexRow) ((IStructuredSelection) viewer.getSelection()).getFirstElement(); int index = -1; if (row != null) index = rowList.indexOf(row); if (index != -1) rowList.insertRow(index); else rowList.addRow(); // FIXME this is probably never executed } }); mi = new MenuItem(menu, SWT.SINGLE); mi.setText(TexlipsePlugin.getResourceString("tableviewDeleteRow")); mi.setEnabled(true); mi.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { TexRow row = (TexRow) ((IStructuredSelection) viewer.getSelection()).getFirstElement(); if (row != null) { rowList.removeRow(row); } } }); mi = new MenuItem(menu, SWT.SINGLE); mi.setText(TexlipsePlugin.getResourceString("tableviewClearAll")); mi.setEnabled(true); mi.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { rowList.clearAll(); } }); new MenuItem(menu, SWT.SEPARATOR); mi = new MenuItem(menu, SWT.SINGLE); mi.setText(TexlipsePlugin.getResourceString("tableviewRowUp")); mi.setEnabled(true); mi.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { TexRow row = (TexRow) ((IStructuredSelection) viewer.getSelection()).getFirstElement(); if (row != null) { rowList.move(row, rowList.indexOf(row) - 1); } } }); mi = new MenuItem(menu, SWT.SINGLE); mi.setText(TexlipsePlugin.getResourceString("tableviewRowDown")); mi.setEnabled(true); mi.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { TexRow row = (TexRow) ((IStructuredSelection) viewer.getSelection()).getFirstElement(); if (row != null) { rowList.move(row, rowList.indexOf(row) + 2); } } }); mi = new MenuItem(menu, SWT.SINGLE); mi.setText(TexlipsePlugin.getResourceString("tableviewDuplicateRow")); mi.setEnabled(true); mi.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { TexRow row = (TexRow) ((IStructuredSelection) viewer.getSelection()).getFirstElement(); if (row != null) { rowList.copy(row, rowList.indexOf(row)); } } }); new MenuItem(menu, SWT.SEPARATOR); mi = new MenuItem(menu, SWT.SINGLE); mi.setText(TexlipsePlugin.getResourceString("tableviewEditorImport")); mi.setEnabled(true); mi.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { // Get selection from texteditor IEditorPart targetEditor = TexlipsePlugin.getCurrentWorkbenchPage().getActiveEditor(); if (!(targetEditor instanceof ITextEditor)) { return; } TexSelections selection = new TexSelections((ITextEditor) targetEditor); TexRow row = (TexRow) ((IStructuredSelection) viewer.getSelection()).getFirstElement(); int index = 0; if (row != null) index = rowList.indexOf(row); rowList.importSelection(selection, index); } }); mi = new MenuItem(menu, SWT.SINGLE); mi.setText(TexlipsePlugin.getResourceString("tableviewEditorExport")); mi.setEnabled(true); mi.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String value = rowList.export(); // transfer string to clipboard Clipboard cb = new Clipboard(null); TextTransfer textTransfer = TextTransfer.getInstance(); cb.setContents(new Object[] {value}, new Transfer[] {textTransfer}); } }); mi = new MenuItem(menu, SWT.SINGLE); mi.setText(TexlipsePlugin.getResourceString("tableviewRawExport")); mi.setEnabled(true); mi.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String value = rowList.exportRaw(); // transfer string to clipboard Clipboard cb = new Clipboard(null); TextTransfer textTransfer = TextTransfer.getInstance(); cb.setContents(new Object[] {value}, new Transfer[] {textTransfer}); } }); new MenuItem(menu, SWT.SEPARATOR); mi = new MenuItem(menu, SWT.SINGLE); mi.setText(TexlipsePlugin.getResourceString("tableviewFlipRows")); mi.setEnabled(true); mi.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { rowList.flipRowsAndColumns(); } }); mi = new MenuItem(menu, SWT.SINGLE); mi.setText(TexlipsePlugin.getResourceString("tableviewMirrorColumns")); mi.setEnabled(true); mi.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { rowList.mirrorColumns(); } }); mi = new MenuItem(menu, SWT.SINGLE); mi.setText(TexlipsePlugin.getResourceString("tableviewMirrorRows")); mi.setEnabled(true); mi.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { rowList.mirrorRows(); } }); table.setMenu(menu); return (table); }
private void addMenuItem(Menu menu, final Class<? extends SceneNodeComponent> componentType) { MenuItem item = new MenuItem(menu, PUSH); item.setText(MetaTypes.getMetaType(componentType).getName()); item.addListener(SWT.Selection, (e) -> addComponent(Reflection.newInstance(componentType))); item.setEnabled(target.getComponent(ComponentType.getBaseType(componentType), true) == null); }
private void updateMenuStates() { itemConnectAndJoin.setEnabled(modeClient == GuiClientMode.DISCONNECTED); itemCreateJoinAndPlay.setEnabled( modeClient == GuiClientMode.DISCONNECTED && modeServer == GuiServerMode.NO_SERVER); itemCreateJoin.setEnabled( modeClient == GuiClientMode.DISCONNECTED && modeServer == GuiServerMode.NO_SERVER); itemObserve.setEnabled(modeClient == GuiClientMode.DISCONNECTED); itemJoin.setEnabled(modeClient == GuiClientMode.MONITOR); itemDisconnect.setEnabled(modeClient != GuiClientMode.DISCONNECTED); itemCreateGame.setEnabled(modeClient == GuiClientMode.DISCONNECTED); itemCreateServerLocal.setEnabled(modeServer == GuiServerMode.NO_SERVER); itemCreateServer.setEnabled(modeServer == GuiServerMode.NO_SERVER); itemShutdownServer.setEnabled(modeServer != GuiServerMode.NO_SERVER); itemCreateGame.setEnabled(modeServer != GuiServerMode.NO_SERVER); clientWhiteboard.setActionsEnabled(modeClient == GuiClientMode.PLAYING); }
private void addAutomationMenu(final Menu menu, final SingleResource selectedResource) { MenuItem startItem = new MenuItem(menu, SWT.NONE); startItem.setText(Constants.START_RESOURCE_AUTOMATION); startItem.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { // Block starting resource level // automation if any attribute level // automation is in progress for the // selected resource boolean started = resourceManager.isAttributeAutomationStarted(selectedResource); if (started) { MessageDialog.openInformation( Display.getDefault().getActiveShell(), "Attribute automation is in progress", "Attribute level automation for this resource is already in progress!!!\nPlease stop all " + "running attribute level automations to start resource level automation."); } else { // Start the automation // Fetch the settings data List<AutomationSettingHelper> automationSettings; automationSettings = AutomationSettingHelper.getAutomationSettings(null); // Open the settings dialog AutomationSettingDialog dialog = new AutomationSettingDialog( Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), automationSettings); dialog.create(); if (dialog.open() == Window.OK) { String automationType = dialog.getAutomationType(); String updateFreq = dialog.getUpdateFrequency(); AutoUpdateType autoType = AutoUpdateType.valueOf(automationType); int updFreq = Utility.getUpdateIntervalFromString(updateFreq); boolean status = resourceManager.startResourceAutomationUIRequest( autoType, updFreq, selectedResource); if (!status) { String statusMsg = "Automation request failed!!!"; MessageDialog.openInformation( Display.getDefault().getActiveShell(), "Automation Status", statusMsg); } } } } }); MenuItem stopItem = new MenuItem(menu, SWT.NONE); stopItem.setText(Constants.STOP_RESOURCE_AUTOMATION); stopItem.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { boolean status = resourceManager.stopResourceAutomationUIRequest(selectedResource); if (!status) { String statusMsg = "Automation stop failed."; MessageDialog.openInformation( Display.getDefault().getActiveShell(), "Automation Status", statusMsg); } } }); // Set the initial visibility of menu items boolean status = resourceManager.isResourceAutomationStarted(selectedResource); startItem.setEnabled(!status); stopItem.setEnabled(status); }
private void fillMenu(final Menu m) { if (history.size() > 0) { TestResultLP lp = new TestResultLP(); for (int a = history.size() - 1; a >= 0; a--) { final TestSuite ts = history.get(a); MenuItem mi = new MenuItem(m, SWT.RADIO); mi.setText(lp.getText(ts)); mi.setImage(lp.getImage(ts)); if (historyIndex != a) { final int idx = a; mi.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { historyIndex = idx; setInput(ts, false); } }); } else { mi.setSelection(true); } } new MenuItem(m, SWT.SEPARATOR); /** clear all terminated * */ MenuItem mi = new MenuItem(m, SWT.PUSH); mi.setText(UITexts.test_history_clear); mi.setImage(HaskellUIImages.getImage(IImageNames.REMOVE_ALL)); mi.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { int a = 0; for (Iterator<TestSuite> it = history.iterator(); it.hasNext(); ) { final TestSuite ts = it.next(); /** terminated= !PENDING * */ if (ts.getRoot().isFinished()) { it.remove(); /** history index moves too * */ if (historyIndex >= a) { historyIndex--; } } } /** defensive * */ if (historyIndex < 0) { historyIndex = history.size() - 1; } if (historyIndex >= 0) { setInput(history.get(historyIndex), false); } else { clear(); /** remove * */ } } }); } else { /** nothing to show * */ MenuItem mi = new MenuItem(m, SWT.PUSH); mi.setText(UITexts.test_history_none); mi.setEnabled(false); } }
public EclipseCommandLineUI(final StyledText commandLineText, final EditorAdaptor editorAdaptor) { clipboard = editorAdaptor.getRegisterManager().getRegister(RegisterManager.REGISTER_NAME_CLIPBOARD); this.commandLineText = commandLineText; commandLineText.addCaretListener(this); commandLineText.addSelectionListener(this); this.defaultCaret = commandLineText.getCaret(); this.endCharCaret = CaretUtils.createCaret(CaretType.RECTANGULAR, commandLineText); commandLineText.setCaret(endCharCaret); contextMenu = new Menu(commandLineText); cutItem = new MenuItem(contextMenu, SWT.DEFAULT); cutItem.setText("Cut"); cutItem.setEnabled(false); copyItem = new MenuItem(contextMenu, SWT.DEFAULT); copyItem.setText("Copy\tCtrl-Y "); copyItem.setEnabled(false); pasteItem = new MenuItem(contextMenu, SWT.DEFAULT); pasteItem.setText("Paste\tCtrl-R +"); selectAllItem = new MenuItem(contextMenu, SWT.DEFAULT); selectAllItem.setText("Select All"); commandLineText.setMenu(contextMenu); cutItem.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { copySelectionToClipboard(); erase(); } }); copyItem.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { copySelectionToClipboard(); } }); pasteItem.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { RegisterContent content = clipboard.getContent(); if (content.getPayloadType() == ContentType.TEXT || content.getPayloadType() == ContentType.LINES) { String text = content.getText(); text = VimUtils.replaceNewLines(text, " "); type(text); } } }); selectAllItem.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { commandLineText.setSelection(contentsOffset, commandLineText.getCharCount()); // Manually trigger selection listener because for some reason the method call above // doesn't. Event e2 = new Event(); e2.widget = commandLineText; e2.x = contentsOffset; e2.y = commandLineText.getCharCount(); EclipseCommandLineUI.this.widgetSelected(new SelectionEvent(e2)); } }); }
/** * Enable or disable the menus that allow the user to change the simulation. These menus should be * disabled whily a simulation is being loaded. * * @param enabled true if we want to allow the user to change the simulation, false otherwise */ public void simulationChangeMenuesEnabled(final boolean enabled) { simulationCloseItem.setEnabled(enabled); simulationOpenJarItem.setEnabled(enabled); simulationOpenDirItem.setEnabled(enabled); }