List of usage examples for org.eclipse.jface.viewers IStructuredSelection isEmpty
public boolean isEmpty();
From source file:com.nabsys.nabeeplus.widgets.PopupList.java
License:Open Source License
/** * Launches the Popup List, waits for an item to be selected and then closes the PopupList. * * @param rect the initial size and location of the PopupList; the dialog will be * positioned so that it does not run off the screen and the largest number of items are visible * * @return the text of the selected item or null if no item is selected *///from w w w. ja va 2 s.c om public String open(Rectangle rect) { shell.setBounds(rect); shell.open(); Display display = shell.getDisplay(); while (!shell.isDisposed() && shell.isVisible()) { if (!display.readAndDispatch()) display.sleep(); } String result = null; if (!shell.isDisposed()) { IStructuredSelection selection = (IStructuredSelection) list.getSelection(); if (!selection.isEmpty()) { PopupListModel popupListModel = (PopupListModel) selection.getFirstElement(); result = popupListModel.getID(); } shell.dispose(); } return result; }
From source file:com.netxforge.screens.editing.base.actions.handlers.DynamicScreensActionHandler.java
License:Open Source License
@Override public void handleSelection(IStructuredSelection ss) { this.selection = ss; if (BaseEditingActivator.DEBUG && !ss.isEmpty()) { BaseEditingActivator.TRACE.trace(null, "update selection: " + ss); }/* ww w .j a v a2 s . c o m*/ for (IAction action : actions) { if (action instanceof com.netxforge.screens.editing.base.actions.BaseSelectionListenerAction) { com.netxforge.screens.editing.base.actions.BaseSelectionListenerAction bsla = (com.netxforge.screens.editing.base.actions.BaseSelectionListenerAction) action; bsla.selectionChanged(ss); } else if (action instanceof org.eclipse.ui.actions.BaseSelectionListenerAction) { org.eclipse.ui.actions.BaseSelectionListenerAction bsla = (org.eclipse.ui.actions.BaseSelectionListenerAction) action; bsla.selectionChanged(ss); } } }
From source file:com.nextep.designer.dbgm.ui.editors.DomainEditorComponent.java
License:Open Source License
@Override public Control create(Composite parent) { final Composite editor = new Composite(parent, SWT.NONE); GridLayout l = new GridLayout(2, false); l.marginBottom = l.marginHeight = l.marginLeft = l.marginRight = l.marginTop = l.marginWidth = 0; editor.setLayout(l);/*from www . j ava 2s .c o m*/ Table t = DomainTable.create(editor); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 2); gd.heightHint = 250; t.setLayoutData(gd); domainViewer = new TableViewer(t); final DomainContentProvider provider = new DomainContentProvider(); domainViewer.setContentProvider(provider); domainViewer.setLabelProvider(new DomainLabelProvider()); CellEditor[] editors = new CellEditor[5]; editors[1] = new TextCellEditor(t); editors[2] = new TextCellEditor(t); editors[3] = new TextCellEditor(t); editors[4] = new TextCellEditor(t); domainViewer.setCellEditors(editors); domainViewer.setColumnProperties(new String[] { COL_SEL, COL_NAME, COL_DESC, COL_LENGTH, COL_PRECISION }); domainViewer.setSorter(new ViewerSorter()); domainViewer.setCellModifier(new ICellModifier() { @Override public boolean canModify(Object element, String property) { return !COL_SEL.equals(property); } @Override public Object getValue(Object element, String property) { final IDomain d = (IDomain) element; if (COL_NAME.equals(property)) { return notNull(d.getName()); } if (COL_DESC.equals(property)) { return notNull(d.getDescription()); } if (COL_LENGTH.equals(property)) { return notNull(d.getLengthExpr()); } if (COL_PRECISION.equals(property)) { return notNull(d.getPrecisionExpr()); } return null; } @Override public void modify(Object element, String property, Object value) { final IDomain d = (IDomain) ((TableItem) element).getData(); if (COL_NAME.equals(property)) { d.setName((String) value); } else if (COL_DESC.equals(property)) { d.setDescription((String) value); } else if (COL_LENGTH.equals(property)) { d.setLengthExpr((String) value); } else if (COL_PRECISION.equals(property)) { d.setPrecisionExpr((String) value); } } }); Button addButton = new Button(editor, SWT.PUSH); addButton.setText(UIMessages.getString("component.typedListBlock.add")); //$NON-NLS-1$ addButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); addButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IDomain d = (IDomain) UIControllerFactory.getController(IElementType.getInstance(IDomain.TYPE_ID)) .newInstance(null); provider.add(d); domainViewer.editElement(d, 1); } }); Button removeButton = new Button(editor, SWT.PUSH); removeButton.setText(UIMessages.getString("component.typedListBlock.remove")); //$NON-NLS-1$ removeButton.setLayoutData(new GridData(SWT.FILL, SWT.UP, false, false)); removeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { ISelection s = domainViewer.getSelection(); if (s instanceof IStructuredSelection) { for (Object o : ((IStructuredSelection) s).toList()) { final IDomain d = (IDomain) o; // Removing vendor types for (IDomainVendorType t : new ArrayList<IDomainVendorType>(d.getVendorTypes())) { d.removeVendorType(t); } CorePlugin.getIdentifiableDao().delete(d); // Removing domain domainViewer.remove(d); } } } }); final IDatatypeService datatypeService = CorePlugin.getService(IDatatypeService.class); datatypeService.reset(); final Collection<IDomain> domains = datatypeService.getDomains(); domainViewer.setInput(domains); // Domain vendor type section final Table typeTab = DomainTable.createDomainType(editor); final TableViewer typeViewer = new TableViewer(typeTab); GridData typeData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2); typeData.heightHint = 200; typeTab.setLayoutData(typeData); Button addTypeButton = new Button(editor, SWT.PUSH); addTypeButton.setText(UIMessages.getString("component.typedListBlock.add")); //$NON-NLS-1$ addTypeButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); addTypeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { final IDomain domain = getSelectedDomain(); if (domain == null) { MessageDialog.openWarning(editor.getShell(), DBGMUIMessages.getString("domainPrefNoSelectionTitle"), //$NON-NLS-1$ DBGMUIMessages.getString("domainPrefNoSelection")); //$NON-NLS-1$ return; } final Object o = UIControllerFactory .getController(IElementType.getInstance(IDomainVendorType.TYPE_ID)) .emptyInstance(null, domain); typeViewer.editElement(o, 0); } }); Button removeTypeButton = new Button(editor, SWT.PUSH); removeTypeButton.setText(UIMessages.getString("component.typedListBlock.remove")); //$NON-NLS-1$ removeTypeButton.setLayoutData(new GridData(SWT.FILL, SWT.UP, false, false)); typeViewer.setContentProvider(new DomainTypeContentProvider()); typeViewer.setLabelProvider(new DomainTypeLabelProvider()); typeViewer.setColumnProperties(new String[] { COL_VENDOR, COL_TYPE, COL_LENGTH, COL_PRECISION }); CellEditor[] typeEditors = new CellEditor[4]; typeEditors[0] = new ComboBoxCellEditor(typeTab, sortedVendors.toArray(new String[sortedVendors.size()]), SWT.READ_ONLY); typeEditors[1] = new TextCellEditor(typeTab); typeEditors[2] = new TextCellEditor(typeTab); typeEditors[3] = new TextCellEditor(typeTab); typeViewer.setCellEditors(typeEditors); typeViewer.setCellModifier(new ICellModifier() { @Override public boolean canModify(Object element, String property) { return true; } @Override public Object getValue(Object element, String property) { IDomainVendorType t = (IDomainVendorType) element; if (COL_VENDOR.equals(property)) { if (t.getDBVendor() != null) { return sortedVendors.indexOf(t.getDBVendor().toString()); } else { return 0; } } else if (COL_TYPE.equals(property)) { if (t.getDatatype() != null) { return notNull(t.getDatatype().getName()); } else { return ""; //$NON-NLS-1$ } } else if (COL_LENGTH.equals(property)) { if (t.getDatatype() != null && t.getDatatype().getLength() != null) { return String.valueOf(t.getDatatype().getLength()); } else { return ""; //$NON-NLS-1$ } } else if (COL_PRECISION.equals(property)) { if (t.getDatatype() != null && t.getDatatype().getPrecision() != null) { return String.valueOf(t.getDatatype().getPrecision()); } else { return ""; //$NON-NLS-1$ } } return null; } @Override public void modify(Object element, String property, Object value) { IDomainVendorType t = (IDomainVendorType) ((TableItem) element).getData(); if (COL_VENDOR.equals(property)) { String val = sortedVendors.get((Integer) value); for (DBVendor v : DBVendor.values()) { if (v.toString().equals(val)) { t.setDBVendor(v); } } } else if (COL_TYPE.equals(property)) { if (t.getDatatype() == null) { t.setDatatype(Datatype.getDefaultDatatype()); } t.getDatatype().setName((String) value); t.notifyListeners(ChangeEvent.MODEL_CHANGED, null); } else if (COL_LENGTH.equals(property)) { try { if (value != null && !"".equals(((String) value).trim())) { //$NON-NLS-1$ t.getDatatype().setLength(Integer.valueOf((String) value)); } else { t.getDatatype().setLength(null); } } catch (NumberFormatException e) { t.getDatatype().setLength(null); } t.notifyListeners(ChangeEvent.MODEL_CHANGED, null); } else if (COL_PRECISION.equals(property)) { try { if (value != null && !"".equals(((String) value).trim())) { //$NON-NLS-1$ t.getDatatype().setPrecision(Integer.valueOf((String) value)); } else { t.getDatatype().setPrecision(null); } } catch (NumberFormatException e) { t.getDatatype().setPrecision(null); } t.notifyListeners(ChangeEvent.MODEL_CHANGED, null); } } }); domainViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { if (event.getSelection() instanceof IStructuredSelection) { final IStructuredSelection sel = (IStructuredSelection) event.getSelection(); if (!sel.isEmpty()) { typeViewer.setInput(sel.getFirstElement()); } else { typeViewer.setInput(null); } } } }); removeTypeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { ISelection s = typeViewer.getSelection(); if (s instanceof IStructuredSelection) { final IStructuredSelection sel = (IStructuredSelection) s; if (!sel.isEmpty()) { for (Object o : sel.toList()) { if (o instanceof IDomainVendorType) { final IDomainVendorType vt = (IDomainVendorType) o; vt.getDomain().removeVendorType(vt); } } } } } }); return editor; }
From source file:com.nextep.designer.dbgm.ui.editors.DomainEditorComponent.java
License:Open Source License
/** * @return teh currently selected domain, or <code>null</code> if no * selection/* w ww .j a v a 2s . c o m*/ */ private IDomain getSelectedDomain() { if (domainViewer.getSelection() instanceof IStructuredSelection) { final IStructuredSelection sel = (IStructuredSelection) domainViewer.getSelection(); if (sel.isEmpty()) { return null; } else { return (IDomain) sel.getFirstElement(); } } return null; }
From source file:com.nextep.designer.dbgm.ui.handlers.AddTableToDiagramHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection s = HandlerUtil.getCurrentSelection(event); if (s instanceof IStructuredSelection) { final IStructuredSelection sel = (IStructuredSelection) s; if (!sel.isEmpty() && sel.getFirstElement() instanceof DiagramEditPart) { final DiagramEditPart diagPart = (DiagramEditPart) sel.getFirstElement(); // Retrieving our current diagram IDiagram diagram = (IDiagram) ((DiagramEditPart) sel.getFirstElement()).getModel(); diagram = VCSUIPlugin.getVersioningUIService().ensureModifiable(diagram); promptForTableAdditions(event, diagram); }/*from ww w . j a v a2 s. co m*/ } // TODO Auto-generated method stub return null; }
From source file:com.nextep.designer.dbgm.ui.handlers.EditDiagramItemHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection s = HandlerUtil.getCurrentSelection(event); if (s instanceof IStructuredSelection) { final IStructuredSelection sel = (IStructuredSelection) s; if (!sel.isEmpty()) { if (sel.size() > WARN_DIALOG_ABOVE) { final boolean confirmed = MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), MessageFormat.format(DBGMUIMessages.getString("editDiagramItemWarnCountTitle"), sel.size()), MessageFormat.format(DBGMUIMessages.getString("editDiagramItemWarnCount"), sel.size(), sel.size())); if (!confirmed) { return null; }//from ww w .j av a 2 s . c o m } for (Iterator<?> it = sel.iterator(); it.hasNext();) { final Object o = it.next(); if (o instanceof DiagramItemPart || o instanceof ConnectionEditPart) { Object model = ((GraphicalEditPart) o).getModel(); Object innerModel = model; if (model instanceof IDiagramItem) { innerModel = ((IDiagramItem) model).getItemModel(); } if (innerModel instanceof ITypedObject) { UIControllerFactory.getController(((ITypedObject) innerModel).getType()) .defaultOpen((ITypedObject) innerModel); } } } } } return null; }
From source file:com.nextep.designer.ui.handlers.EditTypedItemHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection s = HandlerUtil.getCurrentSelection(event); if (s instanceof IStructuredSelection) { final IStructuredSelection sel = (IStructuredSelection) s; if (!sel.isEmpty()) { // Warning before opening too many editors if (sel.size() > WARN_DIALOG_ABOVE) { final boolean confirmed = MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), MessageFormat.format(UIMessages.getString("editItemWarnCountTitle"), sel.size()), //$NON-NLS-1$ MessageFormat.format(UIMessages.getString("editItemWarnCount"), sel.size(), sel //$NON-NLS-1$ .size())); if (!confirmed) { return null; }// w w w .jav a 2 s .c o m } // If OK, we open everything final Iterator<?> selIt = sel.iterator(); while (selIt.hasNext()) { final Object o = selIt.next(); if ((o instanceof ITypedObject) && !(o instanceof IConnector<?, ?>)) { final ITypedObject t = (ITypedObject) o; UIControllerFactory.getController(t.getType()).defaultOpen(t); } } } } return null; }
From source file:com.nextep.designer.vcs.gef.VersionInfoFigure.java
License:Open Source License
public void paintFigure(Graphics graphics) { Rectangle bounds = getBounds().getCopy().resize(-2, -2).translate(1, 1); graphics.setBackgroundColor(ColorConstants.darkGray); graphics.fillOval(bounds.getTranslated(1, 1)); graphics.setBackgroundColor(getLocalBackgroundColor()); graphics.fillOval(bounds);/* ww w .j av a 2 s. c om*/ if (selected) { graphics.setForegroundColor(ColorConstants.red); Rectangle redBox = getBounds().getCopy().resize(-1, -1); graphics.drawRectangle(redBox); } //Handling selection ISelection sel = provider.getSelection(); if (sel instanceof IStructuredSelection) { IStructuredSelection s = (IStructuredSelection) sel; if (!s.isEmpty() && s.getFirstElement() == version) { graphics.setForegroundColor(ColorConstants.blue); graphics.setLineWidth(2); graphics.drawRectangle(getBounds()); } } graphics.restoreState(); }
From source file:com.nextep.designer.vcs.ui.handlers.AbstractVersionHandler.java
License:Open Source License
/** * @see org.eclipse.core.commands.AbstractHandler#isEnabled() *//*from w ww. j a v a 2 s .c om*/ @Override public boolean isEnabled() { // log.debug(this.getClass().getSimpleName() + ": isEnabled() called."); final ISelectionProvider provider = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .getActivePart().getSite().getSelectionProvider(); final ISelection s = provider.getSelection(); if (s instanceof IStructuredSelection) { final IStructuredSelection sel = (IStructuredSelection) s; if (sel.isEmpty()) { return false; } else { for (Object o : sel.toList()) { if (o instanceof IVersionable<?>) { // Our selection might not point to the current workspace object if the // UI is not yet synched with latest model object so we refetch it from // reference final IVersionable<?> selectedVersion = (IVersionable<?>) o; try { final IVersionable<?> workspaceVersion = (IVersionable<?>) VersionHelper .getReferencedItem(selectedVersion.getReference()); if (log.isDebugEnabled()) { log.debug("HANDLER ENABLEMENT (" + this.getClass().getName() //$NON-NLS-1$ + ") : Checking state of " + workspaceVersion + " version " //$NON-NLS-1$//$NON-NLS-2$ + workspaceVersion.getVersion()); } if (!isEnabled(workspaceVersion)) { return false; } } catch (ErrorException e) { // this will happen when we switch workspace and the current selection // cannot be found, we disable everything in this case return false; } } else { return false; } } return true; } } return false; }
From source file:com.nextep.designer.vcs.ui.handlers.OpenTypedObjectAction.java
License:Open Source License
@Override public void run() { final IStructuredSelection sel = (IStructuredSelection) selectionProvider.getSelection(); if (!sel.isEmpty()) { // Warning before opening too many editors if (sel.size() > WARN_DIALOG_ABOVE) { final boolean confirmed = MessageDialog.openConfirm(page.getWorkbenchWindow().getShell(), MessageFormat.format(UIMessages.getString("editItemWarnCountTitle"), sel.size()), //$NON-NLS-1$ MessageFormat.format(UIMessages.getString("editItemWarnCount"), sel.size(), sel.size())); //$NON-NLS-1$ if (!confirmed) { return; }//from w w w. ja va2 s .com } // If OK, we open everything final Iterator<?> selIt = sel.iterator(); while (selIt.hasNext()) { final Object o = selIt.next(); if ((o instanceof ITypedObject) && !(o instanceof IConnector<?, ?>)) { final ITypedObject t = (ITypedObject) o; UIControllerFactory.getController(t.getType()).defaultOpen(t); } } } }