List of usage examples for org.eclipse.jface.viewers StructuredSelection isEmpty
@Override public boolean isEmpty()
From source file:org.eclipse.scout.rt.ui.rap.mobile.form.fields.tablefield.RwtScoutList.java
License:Open Source License
public ITableRow[] getUiSelectedRows() { StructuredSelection uiSelection = (StructuredSelection) getUiTableViewer().getSelection(); TreeSet<ITableRow> sortedRows = new TreeSet<ITableRow>(new RowIndexComparator()); if (uiSelection != null && !uiSelection.isEmpty()) { for (Object o : uiSelection.toArray()) { ITableRow row = (ITableRow) o; sortedRows.add(row);/*from w w w . j a v a 2s . c om*/ } } return sortedRows.toArray(new ITableRow[sortedRows.size()]); }
From source file:org.eclipse.scout.rt.ui.swt.basic.table.SwtScoutTable.java
License:Open Source License
public ITableRow[] getSwtSelectedRows() { StructuredSelection uiSelection = (StructuredSelection) getSwtTableViewer().getSelection(); TreeSet<ITableRow> sortedRows = new TreeSet<ITableRow>(new RowIndexComparator()); if (uiSelection != null && !uiSelection.isEmpty()) { for (Object o : uiSelection.toArray()) { ITableRow row = (ITableRow) o; sortedRows.add(row);/*from w ww . ja v a 2 s. co m*/ } } return sortedRows.toArray(new ITableRow[sortedRows.size()]); }
From source file:org.eclipse.team.internal.ccvs.ui.TableViewerAction.java
License:Open Source License
public void run() { if (viewer.getSelection() instanceof StructuredSelection) { StructuredSelection selection = (StructuredSelection) viewer.getSelection(); if (!selection.isEmpty()) { Iterator selectionIter = selection.iterator(); StringBuffer buf = new StringBuffer(); ITag firstTag = (ITag) selectionIter.next(); buf.append(firstTag.getName()); while (selectionIter.hasNext()) { String tagName = ((ITag) selectionIter.next()).getName(); buf.append(System.getProperty("line.separator", "\n")).append(tagName); //$NON-NLS-1$ //$NON-NLS-2$ }//w ww .j a va 2 s.c om Clipboard clipboard = new Clipboard(Display.getDefault()); Object[] data = new Object[] { buf.toString() }; Transfer[] dataTypes = new Transfer[] { TextTransfer.getInstance() }; try { clipboard.setContents(data, dataTypes); } catch (SWTError e) { if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) { throw e; } } finally { clipboard.dispose(); } } } }
From source file:org.eclipse.ui.tests.adaptable.AdaptedResourceNavigator.java
License:Open Source License
/** * Reveal and select the passed element selection in self's visual component *///from www .j a v a2s . c om public void selectReveal(ISelection selection) { StructuredSelection ssel = convertSelection(selection); if (!ssel.isEmpty()) { getViewer().setSelection(ssel, true); } }
From source file:org.eclipse.viatra.integration.zest.viewer.ZestContentViewer.java
License:Open Source License
@Override public void setSelection(ISelection selection, boolean reveal) { if (selection.isEmpty()) { getSelectionModel().clearSelection(); } else if (selection instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) selection; if (!structuredSelection.isEmpty()) { List<IContentPart<? extends javafx.scene.Node>> toBeSelectedParts = new ArrayList<>(); for (Object toBeSelectedContent : structuredSelection.toArray()) { IContentPart<? extends javafx.scene.Node> toBeSelectedPart = viewer.getContentPartMap() .get(toBeSelectedContent); if (toBeSelectedPart != null) { toBeSelectedParts.add(toBeSelectedPart); if (reveal) { // TODO: we need to reveal all in a single step viewer.reveal(toBeSelectedPart); }//from w w w. j a va 2 s . c om } else { throw new IllegalArgumentException( toBeSelectedContent + " is not visualized by a content part of this viewer."); } } getSelectionModel().prependToSelection(toBeSelectedParts); } } else { throw new IllegalArgumentException( "A non-empty selection of unsupported type '" + selection.getClass() + "' was passed in."); } }
From source file:org.eclipse.vtp.modules.standard.ui.properties.FragmentVariableMappingPanel.java
License:Open Source License
public void createControls(Composite parent) { Composite comp = new Composite(parent, SWT.NONE); comp.setBackground(parent.getBackground()); comp.setLayout(new GridLayout(2, true)); Table expectedVariableTable = new Table(comp, SWT.FULL_SELECTION | SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER); expectedVariableTable.setHeaderVisible(true); TableColumn nameColumn = new TableColumn(expectedVariableTable, SWT.NONE); nameColumn.setText("Variable Name"); nameColumn.setWidth(150);// www . j a va2s. co m TableColumn typeColumn = new TableColumn(expectedVariableTable, SWT.NONE); typeColumn.setText("Variable Type"); typeColumn.setWidth(150); expectedVariableViewer = new TableViewer(expectedVariableTable); expectedVariableViewer.setContentProvider(new ExpectedVariableContentProvider()); expectedVariableViewer.setLabelProvider(new ExpectedVariableLabelProvider()); expectedVariableViewer.setInput(this); GridData gd = new GridData(GridData.FILL_BOTH); expectedVariableTable.setLayoutData(gd); expectedVariableViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { if (currentBrand == null) return; try { StructuredSelection selection = (StructuredSelection) event.getSelection(); if (!selection.isEmpty()) { updating = true; InputBinding vd = (InputBinding) selection.getFirstElement(); InputBrandBinding brandBinding = vd.getBrandBinding(currentBrand); InputItem inputItem = brandBinding.getValue(); inheritButton.setSelection(false); noChangeButton.setSelection(false); staticButton.setSelection(false); expressionButton.setSelection(false); appVariableButton.setSelection(false); if (brandBinding.hasParent() && brandBinding.isInherited()) { inheritButton.setSelection(true); staticText.setText(""); staticText.setEnabled(false); expressionText.setText(""); expressionText.setEnabled(false); appVariableViewer.setSelection(null); appVariableViewer.getControl().setEnabled(false); } else { String type = inputItem.getType(); if (type.equals(InputItem.NONE)) { noChangeButton.setSelection(true); staticText.setText(""); staticText.setEnabled(false); expressionText.setText(""); expressionText.setEnabled(false); appVariableViewer.setSelection(null); appVariableViewer.getControl().setEnabled(false); } else if (type.equals(InputItem.STATIC)) { staticButton.setSelection(true); staticText.setText(inputItem.getValue()); staticText.setEnabled(true); expressionText.setText(""); expressionText.setEnabled(false); appVariableViewer.setSelection(null); appVariableViewer.getControl().setEnabled(false); } else if (type.equals(InputItem.EXPRESSION)) { expressionButton.setSelection(true); staticText.setText(""); staticText.setEnabled(false); expressionText.setText(inputItem.getValue()); expressionText.setEnabled(true); appVariableViewer.setSelection(null); appVariableViewer.getControl().setEnabled(false); } else if (type.equals(InputItem.VARIABLE)) { staticText.setText(""); staticText.setEnabled(false); expressionText.setText(""); expressionText.setEnabled(false); appVariableButton.setSelection(true); for (Iterator<Variable> i = applicationVariables.iterator(); i.hasNext();) { Variable v = i.next(); if (v.getName().equals(inputItem.getValue())) { appVariableViewer.setSelection(new StructuredSelection(v)); } } appVariableViewer.getControl().setEnabled(true); } else throw new RuntimeException("Unknown mapping type found."); } updating = false; } } catch (RuntimeException e) { e.printStackTrace(); } } }); mappingComposite = new Composite(comp, SWT.NONE); gd = new GridData(GridData.FILL_BOTH); mappingComposite.setLayoutData(gd); mappingComposite.setBackground(comp.getBackground()); mappingComposite.setLayout(new GridLayout(1, false)); inheritButton = new Button(mappingComposite, SWT.RADIO); inheritButton.setBackground(mappingComposite.getBackground()); inheritButton.setText("Inherit from parent Brand"); gd = new GridData(GridData.FILL_HORIZONTAL); gd.exclude = true; inheritButton.setLayoutData(gd); inheritButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { if (updating) return; updating = true; if (inheritButton.getSelection()) { StructuredSelection selection = (StructuredSelection) expectedVariableViewer.getSelection(); if (!selection.isEmpty()) { staticText.setText(""); staticText.setEnabled(false); expressionText.setText(""); expressionText.setEnabled(false); appVariableViewer.setSelection(null); appVariableViewer.getControl().setEnabled(false); InputBinding vd = (InputBinding) selection.getFirstElement(); InputBrandBinding brandBinding = vd.getBrandBinding(currentBrand); brandBinding.setValue(null); } } updating = false; } }); noChangeButton = new Button(mappingComposite, SWT.RADIO); noChangeButton.setBackground(mappingComposite.getBackground()); noChangeButton.setText("Do not change this variable"); gd = new GridData(GridData.FILL_HORIZONTAL); noChangeButton.setLayoutData(gd); noChangeButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { if (updating) return; updating = true; if (noChangeButton.getSelection()) { StructuredSelection selection = (StructuredSelection) expectedVariableViewer.getSelection(); if (!selection.isEmpty()) { staticText.setText(""); staticText.setEnabled(false); expressionText.setText(""); expressionText.setEnabled(false); appVariableViewer.setSelection(null); appVariableViewer.getControl().setEnabled(false); InputBinding vd = (InputBinding) selection.getFirstElement(); InputBrandBinding brandBinding = vd.getBrandBinding(currentBrand); InputItem inputItem = brandBinding.getValue(); if (brandBinding.isInherited()) { inputItem = new InputItem(); } inputItem.setType(InputItem.NONE); inputItem.setValue(""); brandBinding.setValue(inputItem); } } updating = false; } }); staticButton = new Button(mappingComposite, SWT.RADIO); staticButton.setBackground(mappingComposite.getBackground()); staticButton.setText("Use this value"); gd = new GridData(GridData.FILL_HORIZONTAL); staticButton.setLayoutData(gd); staticButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { if (updating) return; updating = true; if (staticButton.getSelection()) { StructuredSelection selection = (StructuredSelection) expectedVariableViewer.getSelection(); if (!selection.isEmpty()) { staticText.setText(""); staticText.setEnabled(true); expressionText.setText(""); expressionText.setEnabled(false); appVariableViewer.setSelection(null); appVariableViewer.getControl().setEnabled(false); InputBinding vd = (InputBinding) selection.getFirstElement(); InputBrandBinding brandBinding = vd.getBrandBinding(currentBrand); InputItem inputItem = brandBinding.getValue(); if (brandBinding.isInherited()) { inputItem = new InputItem(); } inputItem.setType(InputItem.STATIC); inputItem.setValue(""); brandBinding.setValue(inputItem); } } updating = false; } }); staticText = new Text(mappingComposite, SWT.SINGLE | SWT.BORDER); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalIndent = 15; staticText.setLayoutData(gd); staticText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (updating) return; StructuredSelection selection = (StructuredSelection) expectedVariableViewer.getSelection(); if (!selection.isEmpty()) { InputBinding vd = (InputBinding) selection.getFirstElement(); InputBrandBinding brandBinding = vd.getBrandBinding(currentBrand); InputItem inputItem = brandBinding.getValue(); if (brandBinding.isInherited()) { inputItem = new InputItem(); } // if(inputItem.getType().equals(InputItem.STATIC)) // { inputItem.setValue(staticText.getText()); brandBinding.setValue(inputItem); // } } } }); expressionButton = new Button(mappingComposite, SWT.RADIO); expressionButton.setBackground(mappingComposite.getBackground()); expressionButton.setText("Use this Javascript expression"); gd = new GridData(GridData.FILL_HORIZONTAL); expressionButton.setLayoutData(gd); expressionButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { if (updating) return; updating = true; if (expressionButton.getSelection()) { StructuredSelection selection = (StructuredSelection) expectedVariableViewer.getSelection(); if (!selection.isEmpty()) { staticText.setText(""); staticText.setEnabled(false); expressionText.setText(""); expressionText.setEnabled(true); appVariableViewer.setSelection(null); appVariableViewer.getControl().setEnabled(false); InputBinding vd = (InputBinding) selection.getFirstElement(); InputBrandBinding brandBinding = vd.getBrandBinding(currentBrand); InputItem inputItem = brandBinding.getValue(); if (brandBinding.isInherited()) { inputItem = new InputItem(); } inputItem.setType(InputItem.EXPRESSION); inputItem.setValue(""); brandBinding.setValue(inputItem); } } updating = false; } }); expressionText = new Text(mappingComposite, SWT.SINGLE | SWT.BORDER); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalIndent = 15; expressionText.setLayoutData(gd); expressionText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (updating) return; StructuredSelection selection = (StructuredSelection) expectedVariableViewer.getSelection(); if (!selection.isEmpty()) { InputBinding vd = (InputBinding) selection.getFirstElement(); InputBrandBinding brandBinding = vd.getBrandBinding(currentBrand); InputItem inputItem = brandBinding.getValue(); if (brandBinding.isInherited()) { inputItem = new InputItem(); } // if(inputItem.getType().equals(InputItem.EXPRESSION)) // { inputItem.setValue(expressionText.getText()); brandBinding.setValue(inputItem); // } } } }); appVariableButton = new Button(mappingComposite, SWT.RADIO); appVariableButton.setBackground(mappingComposite.getBackground()); appVariableButton.setText("Use this application variable"); gd = new GridData(GridData.FILL_HORIZONTAL); appVariableButton.setLayoutData(gd); appVariableButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { if (updating) return; updating = true; if (appVariableButton.getSelection()) { StructuredSelection selection = (StructuredSelection) expectedVariableViewer.getSelection(); if (!selection.isEmpty()) { staticText.setText(""); staticText.setEnabled(false); expressionText.setText(""); expressionText.setEnabled(false); appVariableViewer.setSelection(null); appVariableViewer.getControl().setEnabled(true); InputBinding vd = (InputBinding) selection.getFirstElement(); InputBrandBinding brandBinding = vd.getBrandBinding(currentBrand); InputItem inputItem = brandBinding.getValue(); if (brandBinding.isInherited()) { inputItem = new InputItem(); } inputItem.setType(InputItem.VARIABLE); inputItem.setValue(""); brandBinding.setValue(inputItem); } } updating = false; } }); Table appVariableTable = new Table(mappingComposite, SWT.FULL_SELECTION | SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER); appVariableTable.setHeaderVisible(true); TableColumn appVariableNameColumn = new TableColumn(appVariableTable, SWT.NONE); appVariableNameColumn.setText("Variable Name"); appVariableNameColumn.setWidth(150); TableColumn appVariableTypeColumn = new TableColumn(appVariableTable, SWT.NONE); appVariableTypeColumn.setText("Variable Type"); appVariableTypeColumn.setWidth(150); appVariableViewer = new TableViewer(appVariableTable); appVariableViewer.setContentProvider(new ApplicationVariableContentProvider()); appVariableViewer.setLabelProvider(new ApplicationVariableLabelProvider()); appVariableViewer.setInput(this); gd = new GridData(GridData.FILL_BOTH); gd.horizontalIndent = 15; appVariableViewer.getControl().setLayoutData(gd); appVariableViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { if (updating) return; StructuredSelection selection = (StructuredSelection) expectedVariableViewer.getSelection(); if (!selection.isEmpty()) { InputBinding vd = (InputBinding) selection.getFirstElement(); InputBrandBinding brandBinding = vd.getBrandBinding(currentBrand); InputItem inputItem = brandBinding.getValue(); if (brandBinding.isInherited()) { inputItem = new InputItem(); } // if(mapping.getMappingType() == ApplicationFragmentVariableMapping.MAPPING_VARIABLE) // { StructuredSelection appSel = (StructuredSelection) event.getSelection(); if (appSel.isEmpty()) inputItem.setValue(""); else inputItem.setValue(((Variable) appSel.getFirstElement()).getName()); brandBinding.setValue(inputItem); // } } } }); this.setControl(comp); }
From source file:org.fusesource.ide.camel.editor.restconfiguration.RestEditorTestIT.java
License:Open Source License
@Test public void openCamelFileMoveToRESTPage() throws Exception { IEditorPart openEditorOnFileStore = openFileInEditor(REST_PROJECT); assertThat(openEditorOnFileStore).isNotNull(); assertThat(openEditorOnFileStore).isInstanceOf(CamelEditor.class); readAndDispatch(20);/* w w w .ja v a 2 s . com*/ // ensure that the REST tab is available and select it assertThat(((CamelEditor) openEditorOnFileStore).getRestEditor()).isNotNull(); CamelEditor camelEditor = (CamelEditor) openEditorOnFileStore; camelEditor.setActiveEditor(camelEditor.getRestEditor()); assertThat(camelEditor.getActivePage()).isEqualTo(CamelEditor.REST_CONF_INDEX); RestConfigEditor restEditor = camelEditor.getRestEditor(); camelEditor.setActiveEditor(restEditor); readAndDispatch(20); // grab the selection from the REST tab, which should be a REST Element StructuredSelection ssel = (StructuredSelection) restEditor.getSelection(); assertThat(ssel.isEmpty()).isFalse(); assertThat(ssel.getFirstElement()).isInstanceOf(RestElement.class); // stash the selection RestElement initialSelection = (RestElement) ssel.getFirstElement(); // switch to the source tab and back again, which refreshes the REST model flipTabsToRefreshModel(camelEditor); // grab the selection again StructuredSelection secondSsel = (StructuredSelection) restEditor.getSelection(); // Now make sure we have re-selected the rest element properly RestElement secondSelection = (RestElement) secondSsel.getFirstElement(); assertThat(secondSelection.getId()).isEqualTo(initialSelection.getId()); // now try with operations restEditor .selectRestVerbElement((RestVerbElement) secondSelection.getRestOperations().values().toArray()[0]); StructuredSelection opSsel1 = (StructuredSelection) restEditor.getSelection(); assertThat(opSsel1.isEmpty()).isFalse(); assertThat(opSsel1.getFirstElement()).isInstanceOf(RestVerbElement.class); // stash the first operation RestVerbElement initialRVE = (RestVerbElement) opSsel1.getFirstElement(); // switch to the source tab and back again, which refreshes the REST model flipTabsToRefreshModel(camelEditor); // now make sure we have re-selected the operation properly StructuredSelection opSsel2 = (StructuredSelection) restEditor.getSelection(); assertThat(opSsel1.getFirstElement() instanceof RestVerbElement).isTrue(); RestVerbElement secondRVE = (RestVerbElement) opSsel2.getFirstElement(); assertThat(initialRVE.getId()).isEqualTo(secondRVE.getId()); // next up, try to select the second rest element in the list // (/say (rest1) comes after /repeat (rest2)) RestElement secondRestElement = (RestElement) restEditor.getCtx().getRestElements().get("rest1"); restEditor.selectRestElement(secondRestElement); // switch to the source tab and back again, which refreshes the REST model flipTabsToRefreshModel(camelEditor); // grab the selection again StructuredSelection thirdSsel = (StructuredSelection) restEditor.getSelection(); // Now make sure we have re-selected the second rest element properly RestElement thirdSelection = (RestElement) thirdSsel.getFirstElement(); assertThat(thirdSelection.getId()).isEqualTo(secondRestElement.getId()); }
From source file:org.hibernate.eclipse.launch.ConnectionProfileCtrl.java
License:Open Source License
/** * //www . j a v a 2 s.co m * @return current selected connection wrapper, will always return non-null. */ private ConnectionWrapper getSelectedConnection() { StructuredSelection selection = (StructuredSelection) comboControl.getSelection(); if (null == selection || selection.isEmpty()) { return NO_CONNECTION_PLACEHOLDER; } ConnectionWrapper cw = (ConnectionWrapper) selection.getFirstElement(); return cw; }
From source file:org.jboss.tools.common.editor.AbstractSelectionProvider.java
License:Open Source License
public void setSelection(ISelection selection) { if (!(selection instanceof StructuredSelection)) return;// w w w . j av a2s. c om StructuredSelection ss = (StructuredSelection) selection; if (!ss.isEmpty() && (ss.getFirstElement() instanceof XModelObject)) setSelectedModelObject((XModelObject) ss.getFirstElement()); }
From source file:org.jboss.tools.common.model.ui.attribute.editor.JavaChoicerFieldEditor.java
License:Open Source License
public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); JavaElement element = selection.isEmpty() ? null : (JavaElement) selection.getFirstElement(); if (element != null && !ROOT_PATH.equals(element.getPath())) { valueChanged(element.getPath()); } else {//from w w w . j a va2s. c o m valueChanged(EMPTY_PATH); } }