List of usage examples for org.eclipse.jface.viewers StructuredSelection isEmpty
@Override public boolean isEmpty()
From source file:es.cv.gvcase.mdt.common.composites.MembersComposite.java
License:Open Source License
/** * Execute movement.//from w ww .j av a 2 s . co m * * @param up * the up */ private void executeMovement(boolean up) { if (memberElementsViewer.getSelection() instanceof StructuredSelection) { StructuredSelection selection = (StructuredSelection) memberElementsViewer.getSelection(); if (!selection.isEmpty()) { List membersToMove = selection.toList(); List movedMembers = moveMembers(getMemberElements(), membersToMove, up); CompoundCommand c = new CompoundCommand(); for (Object o : selection.toList()) { c.append(MoveCommand.create(getEMFEditDomain(), getElement(), getFeatureUnderEdition(), o, movedMembers.indexOf(o))); } getEMFEditDomain().getCommandStack().execute(c); memberElementsViewer.setSelection(selection); } } return; }
From source file:es.cv.gvcase.mdt.common.util.MDTUtil.java
License:Open Source License
/** * Selectes the editparts that represent the given elements in the selection * in the given editor./* w w w. j a v a 2 s . c o m*/ * * @param activeEditor * @param selection */ public static void setSelectionInEditor(IEditorPart activeEditor, ISelection selection) { if (activeEditor instanceof IDiagramWorkbenchPart) { // set editor selection; select EditParts IDiagramGraphicalViewer viewer = ((IDiagramWorkbenchPart) activeEditor).getDiagramGraphicalViewer(); if (viewer == null) { return; } List<EditPart> editPartsToSelect = MDTUtil.getEditPartsFromSelection(selection, viewer); StructuredSelection selectedEditParts = new StructuredSelection(editPartsToSelect); viewer.setSelection(selectedEditParts); if (!selectedEditParts.isEmpty()) { EditPart editPart = (EditPart) selectedEditParts.getFirstElement(); viewer.reveal(editPart); } } }
From source file:es.cv.gvcase.mdt.db.properties.sections.IndexesPropertySection.java
License:Open Source License
@Override protected EList<DetailComposite> createComposites(Composite parent) { EList<DetailComposite> composites = new BasicEList<DetailComposite>(); NameComposite nc = new NameComposite(parent, parent.getStyle()); ExpressionComposite ec = new ExpressionComposite(parent, parent.getStyle()); MembersComposite mc = new TableMembersComposite(parent, parent.getStyle(), this.getWidgetFactory(), SQLConstraintsPackage.eINSTANCE.getIndex_Members(), "Index members") { /* (non-Javadoc) * @see es.cv.gvcase.mdt.common.composites.MembersComposite#getMemberElements() *///from w w w . j a va 2s .c o m @Override protected EList<EObject> getMemberElements() { EList<EObject> members = new BasicEList<EObject>(); EList<EObject> originalMembers = super.getMemberElements(); if (originalMembers == null) { return ECollections.emptyEList(); } for (EObject eo : originalMembers) { if (eo instanceof IndexMember) { members.add(((IndexMember) eo).getColumn()); } } return members; } public void handleAddButtonSelected() { if (this.getCandidateElementsViewer().getSelection() instanceof StructuredSelection) { StructuredSelection selection = (StructuredSelection) this.getCandidateElementsViewer() .getSelection(); if (!selection.isEmpty()) { Iterator iterator = selection.iterator(); while (iterator.hasNext()) { Object next = iterator.next(); if (next instanceof Column && getElement() instanceof Index) { if (!containsColumn((Index) getElement(), (Column) next)) { executeAddCommand(next); } } } refresh(); } } } private boolean containsColumn(Index index, Column column) { if (index == null || column == null) return false; for (IndexMember im : index.getMembers()) { if (im.getColumn() != null && im.getColumn().equals(column)) { return true; } } return false; } public void handleRemoveButtonSelected() { if (this.getMemberElementsViewer().getSelection() instanceof StructuredSelection) { StructuredSelection selection = (StructuredSelection) this.getMemberElementsViewer() .getSelection(); if (!selection.isEmpty()) { Iterator iterator = selection.iterator(); while (iterator.hasNext()) { executeRemoveCommand(iterator.next()); } refresh(); } } } private void executeAddCommand(Object objectToAdd) { if (getEMFEditDomain() == null || !(objectToAdd instanceof Column)) return; IndexMember im = SQLConstraintsFactory.eINSTANCE.createIndexMember(); Column col = (Column) objectToAdd; String colName = ""; if (col.getName() != null) colName = col.getName(); CompoundCommand cc = new CompoundCommand(); cc.append(SetCommand.create(getEMFEditDomain(), im, EcorePackage.eINSTANCE.getENamedElement_Name(), colName)); cc.append(SetCommand.create(getEMFEditDomain(), im, SQLConstraintsPackage.eINSTANCE.getIndexMember_Column(), col)); cc.append(AddCommand.create(getEMFEditDomain(), getElement(), SQLConstraintsPackage.eINSTANCE.getIndex_Members(), im)); getEMFEditDomain().getCommandStack().execute(cc); } private void executeRemoveCommand(Object objectToRemove) { if (getEMFEditDomain() == null || !(objectToRemove instanceof Column) || !(getElement() instanceof Index)) return; Index index = (Index) getElement(); Column column = (Column) objectToRemove; IndexMember imToRemove = getIndexMember(index, column); Command command = DeleteCommand.create(getEMFEditDomain(), imToRemove); getEMFEditDomain().getCommandStack().execute(command); } private IndexMember getIndexMember(Index index, Column column) { if (index == null || column == null) return null; for (IndexMember im : index.getMembers()) { if (im.getColumn() != null && im.getColumn().equals(column)) { return im; } } return null; } }; mc.setLabelProvider(getLabelProvider()); mc.setEnableOrdering(true); if (getCandidateElements() != null) { mc.setCandidateElements(getCandidateElements()); } composites.add(nc); composites.add(ec); composites.add(mc); return composites; }
From source file:eu.geclipse.jsdl.ui.internal.pages.sections.SweepOrderSection.java
License:Open Source License
private void createSection(final Composite parent, final FormToolkit toolkit) { // general form settings this.shell = parent.getShell(); String sectionTitle = "Sweep order"; //$NON-NLS-1$ String sectionDescription = "Specify the order of parameters sweep and their dependency from each other"; //$NON-NLS-1$ Composite client = FormSectionFactory.createGridStaticSection(toolkit, parent, sectionTitle, sectionDescription, 3);//from ww w . j a va2 s .co m // sweep order tree Composite treeComp = toolkit.createComposite(client); GridData gData = new GridData(GridData.FILL_BOTH); gData.horizontalSpan = 3; treeComp.setLayoutData(gData); treeComp.setLayout(new GridLayout(2, false)); this.viewer = new TreeViewer(treeComp, SWT.BORDER); this.viewer.setContentProvider(new SweepOrderCProvider()); this.viewer.setLabelProvider(new SweepOrderLProvider()); gData = new GridData(GridData.GRAB_HORIZONTAL); gData = new GridData(); gData.horizontalAlignment = GridData.FILL; gData.verticalAlignment = GridData.FILL; gData.grabExcessHorizontalSpace = true; gData.verticalSpan = 6; gData.heightHint = 300; this.viewer.getTree().setLayoutData(gData); this.viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(final SelectionChangedEvent event) { ISelection sel = SweepOrderSection.this.viewer.getSelection(); if (sel instanceof StructuredSelection) { StructuredSelection sSel = (StructuredSelection) sel; if (sSel.getFirstElement() instanceof SweepType) { SweepType type = (SweepType) sSel.getFirstElement(); int i = 0; boolean found = false; for (String item : SweepOrderSection.this.sweepCombo.getItems()) { if (item.equals(getNameForSweep(type))) { found = true; break; } i++; } if (found) { SweepOrderSection.this.sweepCombo.select(i); setValuesField(SweepOrderSection.this.adapter.getValuesForParameter( SweepOrderSection.this.sweepCombo.getItem(i), SweepOrderSection.this.inerSweepList)); } } else if (sSel.isEmpty()) { SweepOrderSection.this.sweepCombo.deselectAll(); setValuesField(null); } } updateButtons(); } }); this.manager = createMenu(); // tree buttons composite Composite buttonComp = toolkit.createComposite(treeComp); buttonComp.setLayout(new GridLayout(1, true)); this.newButton = toolkit.createButton(buttonComp, "New sweep...", SWT.PUSH); //$NON-NLS-1$ this.newButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); this.independentButton = toolkit.createButton(buttonComp, "Independent sweep...", //$NON-NLS-1$ SWT.PUSH); gData = new GridData(GridData.FILL_HORIZONTAL); gData.verticalIndent = 15; this.independentButton.setLayoutData(gData); this.sameLevelButton = toolkit.createButton(buttonComp, "Sweep on the same level...", //$NON-NLS-1$ SWT.PUSH); this.sameLevelButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); this.innerButton = toolkit.createButton(buttonComp, "Inner sweep...", //$NON-NLS-1$ SWT.PUSH); this.innerButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); this.deleteButton = toolkit.createButton(buttonComp, "Delete", SWT.PUSH); //$NON-NLS-1$ gData = new GridData(GridData.FILL_HORIZONTAL); gData.verticalIndent = 15; this.deleteButton.setLayoutData(gData); updateButtons(); // values controls toolkit.createLabel(client, "Sweep element"); //$NON-NLS-1$ this.sweepCombo = new Combo(client, SWT.NONE | SWT.READ_ONLY); gData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL); gData.widthHint = 200; gData.horizontalSpan = 2; this.sweepCombo.setLayoutData(gData); this.sweepCombo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { setValuesField(SweepOrderSection.this.adapter.getValuesForParameter( SweepOrderSection.this.sweepCombo.getText(), SweepOrderSection.this.inerSweepList)); updateButtons(); } }); toolkit.createLabel(client, "Parameter values\n(put each value in new line)"); //$NON-NLS-1$ this.textArea = new Text(client, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.BORDER); gData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL); gData.heightHint = 70; gData.widthHint = 160; this.textArea.setLayoutData(gData); this.textArea.addKeyListener(new KeyListener() { public void keyPressed(final KeyEvent e) { // do nothing } public void keyReleased(final KeyEvent e) { List<String> val = new ArrayList<String>(); for (String value : SweepOrderSection.this.textArea.getText() .split(System.getProperty("line.separator"))) //$NON-NLS-1$ { val.add(value); } SweepType sweep = SweepOrderSection.this.adapter.findSweepElement( SweepOrderSection.this.sweepCombo.getText(), SweepOrderSection.this.inerSweepList); AssignmentType assignment = null; if (sweep != null && sweep.getAssignment() != null) { for (int j = 0; j < sweep.getAssignment().size(); j++) { if (((AssignmentType) sweep.getAssignment().get(j)).getParameter() .contains(SweepOrderSection.this.sweepCombo.getText())) { assignment = (AssignmentType) sweep.getAssignment().get(j); break; } } } if (assignment != null) { SweepOrderSection.this.adapter.setFunctionValues(assignment, val); contentChanged(); } updateButtons(); } }); // values buttons composite Composite buttonValComp = toolkit.createComposite(client); buttonValComp.setLayout(new GridLayout(1, true)); this.addFunctionButton = toolkit.createButton(buttonValComp, "Define loop...", //$NON-NLS-1$ SWT.PUSH); gData = new GridData(); this.addFunctionButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { SweepLoopDialog dialog = new SweepLoopDialog(SweepOrderSection.this.shell); if (dialog.open() == Window.OK) { List<BigInteger> exceptions = new ArrayList<BigInteger>(); if (dialog.getExceptionsReturn() != null) { for (String exc : dialog.getExceptionsReturn()) { exceptions.add(new BigInteger(exc)); } } appendTextToTextArea(SweepOrderSection.this.adapter.createLOOPString( new BigInteger(dialog.getStartReturn()), new BigInteger(dialog.getEndReturn()), new BigInteger(dialog.getStepReturn()), exceptions)); updateButtons(); } } }); this.addFunctionButton.setLayoutData(gData); updateButtons(); addButtonsListeners(); }
From source file:eu.geclipse.ui.dialogs.ConfigureFiltersDialog.java
License:Open Source License
ISelectionChangedListener createTableSelectionListener() { return new ISelectionChangedListener() { private IGridFilterConfiguration selectedConfiguration; public void selectionChanged(final SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); if (selection != null) { if (saveFilter()) { this.selectedConfiguration = (IGridFilterConfiguration) selection.getFirstElement(); enableConfiguration(this.selectedConfiguration); for (IFilterComposite filterComposite : ConfigureFiltersDialog.this.composites) { filterComposite.setFilter(this.selectedConfiguration); }/*from w w w.ja v a 2s . c o m*/ } else { ConfigureFiltersDialog.this.tableViewer.removeSelectionChangedListener(this); ConfigureFiltersDialog.this.tableViewer.setSelection(this.selectedConfiguration != null ? new StructuredSelection(this.selectedConfiguration) : null); ConfigureFiltersDialog.this.tableViewer.addSelectionChangedListener(this); } } setEnabledComposites(selection != null && !selection.isEmpty()); } }; }
From source file:eu.geclipse.ui.dialogs.ConfigureFiltersDialog.java
License:Open Source License
private void createDeleteButton(final Composite parent) { Button button = createButton(parent, Messages.getString("ConfigureFiltersDialog.delete_button")); //$NON-NLS-1$ button.addSelectionListener(new SelectionAdapter() { /* (non-Javadoc) * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) *//* w ww .ja v a2 s . c om*/ @Override public void widgetSelected(final SelectionEvent e) { if (saveFilter()) { StructuredSelection selection = (StructuredSelection) ConfigureFiltersDialog.this.tableViewer .getSelection(); if (selection == null || selection.isEmpty()) { MessageDialog.openWarning(getShell(), Messages.getString("ConfigureFiltersDialog.delete_filter"), //$NON-NLS-1$ Messages.getString("ConfigureFiltersDialog.select_filter")); //$NON-NLS-1$ } else { IGridFilterConfiguration configuration = (IGridFilterConfiguration) selection .getFirstElement(); ConfigureFiltersDialog.this.tableViewer.remove(configuration); ConfigureFiltersDialog.this.configurations.remove(configuration); selectDefaultConfiguration(); } } } }); }
From source file:ext.org.eclipse.jdt.internal.ui.javaeditor.breadcrumb.EditorBreadcrumb.java
License:Open Source License
private boolean doOpen(ISelection selection) { if (!(selection instanceof StructuredSelection)) return false; StructuredSelection structuredSelection = (StructuredSelection) selection; if (structuredSelection.isEmpty()) return false; return open(structuredSelection.getFirstElement()); }
From source file:ext.org.eclipse.jdt.internal.ui.javaeditor.breadcrumb.EditorBreadcrumb.java
License:Open Source License
private boolean doReveal(ISelection selection) { if (!(selection instanceof StructuredSelection)) return false; StructuredSelection structuredSelection = (StructuredSelection) selection; if (structuredSelection.isEmpty()) return false; if (fOldTextSelection != null) { getTextEditor().getSelectionProvider().setSelection(fOldTextSelection); boolean result = reveal(structuredSelection.getFirstElement()); fOldTextSelection = getTextEditor().getSelectionProvider().getSelection(); getTextEditor().getSelectionProvider().setSelection(new StructuredSelection(this)); return result; } else {/* w ww. ja va 2s . c o m*/ return reveal(structuredSelection.getFirstElement()); } }
From source file:fr.ifpen.emptooling.reverse.ui.handlers.ReverseToEcoreHandler.java
License:Open Source License
/** * the command has been executed, so extract extract the needed information * from the application context./*from ww w . j a va2s. c om*/ */ public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); Shell activeShell = HandlerUtil.getActiveShell(event); StructuredSelection sSelection = (StructuredSelection) window.getSelectionService().getSelection(); if (!sSelection.isEmpty()) { Object selection = sSelection.getFirstElement(); if (selection instanceof IJavaProject) { javaProject = (IJavaProject) selection; if (javaPackages.isEmpty()) { try { for (IPackageFragment pf : javaProject.getPackageFragments()) { if (pf.getKind() == IPackageFragmentRoot.K_SOURCE && pf.hasChildren()) { javaPackages.add(pf); } } } catch (JavaModelException e) { e.printStackTrace(); } } } else { if (selection instanceof IPackageFragment && ((IPackageFragment) selection).getElementType() == IJavaElement.PACKAGE_FRAGMENT) { this.javaPackages.add((IPackageFragment) selection); this.javaProject = ((IPackageFragment) selection).getJavaProject(); } } ReverseToEcoreWizard wizard = new ReverseToEcoreWizard(); WizardDialog dialog = new WizardDialog(activeShell, wizard); wizard.setWindowTitle("Reverse configuration"); if (dialog.open() == Window.OK) { final ReverseSettings reverseSettings = new ReverseSettings(); reverseSettings.rootNsPrefix = wizard.getBaseNSPrefix(); reverseSettings.rootNsURI = wizard.getBaseURI(); reverseSettings.rootPackageName = javaProject.getElementName(); final IContainer target = wizard.getTargetContainer(); IRunnableWithProgress operation = new ReverseToEcoreRunnable(javaProject, javaPackages, reverseSettings, target); try { PlatformUI.getWorkbench().getProgressService().run(true, true, operation); } catch (InvocationTargetException e) { IStatus status = new Status(IStatus.ERROR, ReverseUIPlugin.PLUGIN_ID, e.getMessage(), e); ReverseUIPlugin.getPlugin().getLog().log(status); } catch (InterruptedException e) { IStatus status = new Status(IStatus.ERROR, ReverseUIPlugin.PLUGIN_ID, e.getMessage(), e); ReverseUIPlugin.getPlugin().getLog().log(status); } } } return null; }
From source file:gov.nasa.ensemble.core.detail.emf.binding.TableBindingFactory.java
License:Open Source License
private Button addEditButton(final Composite composite, final String title, final EditingDomain domain, final FormToolkit toolkit, final TreeTableViewer viewer) { toolkit.setBorderStyle(SWT.BORDER);// w w w . j ava 2 s . c o m final Shell shell = composite.getShell(); final Button edit = new Button(composite, SWT.NO_BACKGROUND); edit.setText("Edit"); edit.setEnabled(false); //by default nothing is selected edit.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { ISelection s = viewer.getSelection(); if (s instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) s; if (!structuredSelection.isEmpty()) { EditTableDialog dialog = new EditTableDialog(shell, title, structuredSelection, domain, toolkit); dialog.open(); } } } }); viewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { ISelection s = event.getSelection(); if (s instanceof StructuredSelection) { edit.setEnabled(!s.isEmpty()); } else { edit.setEnabled(false); } } }); return edit; }