List of usage examples for org.eclipse.jface.viewers StructuredSelection size
@Override public int size()
From source file:org.jboss.tools.jsf.ui.editor.JSFContextMenuProvider.java
License:Open Source License
private XModelObject[] getTargets(StructuredSelection ss) { if (ss.size() < 2) return null; Iterator it = ss.iterator();//from ww w .j av a 2 s .co m ArrayList<XModelObject> l = new ArrayList<XModelObject>(); while (it.hasNext()) { XModelObject o = getTarget(it.next()); if (o != null) l.add(o); } return l.toArray(new XModelObject[0]); }
From source file:org.jboss.tools.jst.web.tiles.ui.editor.TilesContextMenuProvider.java
License:Open Source License
private XModelObject[] getTargets(StructuredSelection ss) { if (ss.size() < 2) return null; Iterator it = ss.iterator();// w w w. j a v a 2 s . c o m ArrayList l = new ArrayList(); while (it.hasNext()) { XModelObject o = getTarget(it.next()); if (o != null) l.add(o); } return (XModelObject[]) l.toArray(new XModelObject[0]); }
From source file:org.jboss.tools.windup.ui.internal.editor.RulesetEditorRulesSection.java
License:Open Source License
private void createButtons(Composite parent) { Composite container = toolkit.createComposite(parent); toolkit.paintBordersFor(container);//from ww w . j a v a 2s. c o m GridLayoutFactory.fillDefaults().applyTo(container); GridDataFactory.fillDefaults().grab(false, true).applyTo(container); Button addButton = createButton(container, Messages.RulesetEditor_AddRule); addButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { Document document = (Document) treeViewer.getInput(); Element rulesetElement = domService.findOrCreateRulesetElement(document); Element rulesElement = domService.findOrCreateRulesElement(rulesetElement); //createRule(rulesElement); } }); this.removeButton = createButton(container, Messages.RulesetEditor_remove); removeButton.addSelectionListener(new SelectionAdapter() { @SuppressWarnings("unchecked") @Override public void widgetSelected(SelectionEvent e) { removeNodes(((IStructuredSelection) treeViewer.getSelection()).toList()); } }); createPlaceholder(container); createPlaceholder(container); createPlaceholder(container); this.upButton = createButton(container, Messages.RulesetEditor_Rules_up); this.downButton = createButton(container, Messages.RulesetEditor_Rules_down); upButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { StructuredSelection ss = (StructuredSelection) treeViewer.getSelection(); if (!ss.isEmpty() && ss.size() == 1) { Node node = (Node) ss.getFirstElement(); if (node instanceof Element && node.getParentNode() instanceof Element) { ISelection selection = treeViewer.getSelection(); domService.insertBeforePreviousSibling(node); treeViewer.setSelection(selection); } } } }); downButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { StructuredSelection ss = (StructuredSelection) treeViewer.getSelection(); if (!ss.isEmpty() && ss.size() == 1) { Node node = (Node) ss.getFirstElement(); if (node instanceof Element && node.getParentNode() instanceof Element) { ISelection selection = treeViewer.getSelection(); domService.insertAfterNextSibling(node); treeViewer.setSelection(selection); } } } }); }
From source file:org.jboss.tools.windup.ui.internal.explorer.IssueExplorer.java
License:Open Source License
@Override public void createPartControl(Composite aParent) { super.createPartControl(aParent); getCommonViewer().addDoubleClickListener(new OpenIssueListener()); getCommonViewer().addSelectionChangedListener((e) -> { StructuredSelection ss = (StructuredSelection) e.getSelection(); if (ss.size() == 1) { Object selection = ss.getFirstElement(); IMarker type = null;/*from w w w . ja v a2 s . co m*/ if (selection instanceof IssueNode) { type = ((IssueNode) selection).getType(); } context.set(IMarker.class, type); } }); context.get(MApplication.class).getContext().set(IssueExplorerService.class, new IssueExplorerService() { @Override public TreeViewer getViewer() { return getCommonViewer(); } }); }
From source file:org.jkiss.dbeaver.ui.editors.binary.BinaryEditor.java
License:Open Source License
@Override public void setSelection(ISelection selection) { if (selection.isEmpty()) return;/*from w ww. j a v a2 s . co m*/ StructuredSelection aSelection = (StructuredSelection) selection; long[] startEnd = (long[]) aSelection.getFirstElement(); long start = startEnd[0]; long end = start; if (startEnd.length > 1) { end = startEnd[1]; } if (aSelection.size() > 1) { startEnd = (long[]) aSelection.toArray()[1]; end = startEnd[0]; if (startEnd.length > 1) { end = startEnd[1]; } } manager.setSelection(start, end); }
From source file:org.lamport.org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.java
License:Open Source License
protected Control createDialogArea(Composite parent) { Composite dialogArea = (Composite) super.createDialogArea(parent); Composite content = new Composite(dialogArea, SWT.NONE); GridData gd = new GridData(GridData.FILL_BOTH); content.setLayoutData(gd);//from www .j a va2 s .c o m GridLayout layout = new GridLayout(); layout.numColumns = 1; layout.marginWidth = 0; layout.marginHeight = 0; content.setLayout(layout); final Label headerLabel = createHeader(content); pattern = new Text(content, SWT.SINGLE | SWT.BORDER | SWT.SEARCH | SWT.ICON_CANCEL); pattern.getAccessible().addAccessibleListener(new AccessibleAdapter() { public void getName(AccessibleEvent e) { e.result = LegacyActionTools.removeMnemonics(headerLabel.getText()); } }); gd = new GridData(GridData.FILL_HORIZONTAL); pattern.setLayoutData(gd); final Label listLabel = createLabels(content); final Composite comp = createContentComposite(content); list = new TableViewer(comp, (multi ? SWT.MULTI : SWT.SINGLE) | SWT.BORDER | SWT.V_SCROLL | SWT.VIRTUAL); list.getTable().getAccessible().addAccessibleListener(new AccessibleAdapter() { public void getName(AccessibleEvent e) { if (e.childID == ACC.CHILDID_SELF) { e.result = LegacyActionTools.removeMnemonics(listLabel.getText()); } } }); list.setContentProvider(contentProvider); list.setLabelProvider(getItemsListLabelProvider()); list.setInput(new Object[0]); list.setItemCount(contentProvider.getNumberOfElements()); gd = new GridData(GridData.FILL_BOTH); applyDialogFont(list.getTable()); gd.heightHint = list.getTable().getItemHeight() * 15; list.getTable().setLayoutData(gd); createPopupMenu(); pattern.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { applyFilter(); } }); pattern.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.keyCode == SWT.ARROW_DOWN) { if (list.getTable().getItemCount() > 0) { list.getTable().setFocus(); } } } }); list.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); handleSelected(selection); } }); list.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { handleDoubleClick(); } }); list.getTable().addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.keyCode == SWT.DEL) { List selectedElements = ((StructuredSelection) list.getSelection()).toList(); Object item = null; boolean isSelectedHistory = true; for (Iterator it = selectedElements.iterator(); it.hasNext();) { item = it.next(); if (item instanceof ItemsListSeparator || !isHistoryElement(item)) { isSelectedHistory = false; break; } } if (isSelectedHistory) removeSelectedItems(selectedElements); } if (e.keyCode == SWT.ARROW_UP && (e.stateMask & SWT.SHIFT) != 0 && (e.stateMask & SWT.CTRL) != 0) { StructuredSelection selection = (StructuredSelection) list.getSelection(); if (selection.size() == 1) { Object element = selection.getFirstElement(); if (element.equals(list.getElementAt(0))) { pattern.setFocus(); } if (list.getElementAt( list.getTable().getSelectionIndex() - 1) instanceof ItemsListSeparator) list.getTable().setSelection(list.getTable().getSelectionIndex() - 1); list.getTable().notifyListeners(SWT.Selection, new Event()); } } if (e.keyCode == SWT.ARROW_DOWN && (e.stateMask & SWT.SHIFT) != 0 && (e.stateMask & SWT.CTRL) != 0) { if (list.getElementAt(list.getTable().getSelectionIndex() + 1) instanceof ItemsListSeparator) list.getTable().setSelection(list.getTable().getSelectionIndex() + 1); list.getTable().notifyListeners(SWT.Selection, new Event()); } } }); createExtendedContentArea(comp); details = new DetailsContentViewer(content, SWT.BORDER | SWT.FLAT); details.setVisible(toggleStatusLineAction.isChecked()); details.setContentProvider(new NullContentProvider()); details.setLabelProvider(getDetailsLabelProvider()); applyDialogFont(content); restoreDialog(getDialogSettings()); if (initialPatternText != null) { pattern.setText(initialPatternText); } switch (selectionMode) { case CARET_BEGINNING: pattern.setSelection(0, 0); break; case FULL_SELECTION: pattern.setSelection(0, initialPatternText.length()); break; } // apply filter even if pattern is empty (display history) applyFilter(); return dialogArea; }
From source file:org.lamport.tla.toolbox.tool.tlc.ui.dialog.TLAFilteredItemsSelectionDialog.java
License:Open Source License
protected void handleSelected(StructuredSelection selection) { if (selection != null && selection.size() == 0) { // unset the sourceviewer when the filter turned the search results // empty//from w ww. j a v a 2s .co m sourceViewer.setDocument(new Document(EMPTY_STRING)); } else if (selection != null && selection.getFirstElement() instanceof Module) { final Module module = (Module) selection.getFirstElement(); try { sourceViewer.setDocument(new Document(new String(Files.readAllBytes(module.getFile().toPath())))); } catch (IOException e) { sourceViewer.setDocument(new Document(EMPTY_STRING)); } } else if (selection != null && selection.getFirstElement() instanceof Model) { final Model model = (Model) selection.getFirstElement(); try { // By default, show the model's comment/description and fall-back // to its constants. If there are no constants, the last fall-back // is the model's name. final List<String> fallbacksFallback = new ArrayList<String>(); fallbacksFallback.add(model.getName()); final String attribute = model.getComments(); if (!EMPTY_STRING.equals(attribute)) { sourceViewer.setDocument(new Document(attribute)); } else { sourceViewer.setDocument(new Document(ModelHelper.prettyPrintConstants(model, "\n", true))); } } catch (final CoreException ignored) { sourceViewer.setDocument(new Document(EMPTY_STRING)); } } else if (selection != null && selection.getFirstElement() instanceof Spec) { final Spec spec = (Spec) selection.getFirstElement(); final Path path = spec.getRootFile().getLocation().makeAbsolute().toFile().toPath(); try { sourceViewer.setDocument(new Document(new String(Files.readAllBytes(path)))); } catch (IOException e) { sourceViewer.setDocument(new Document(EMPTY_STRING)); } } else if (selection != null && selection.getFirstElement() instanceof ItemsListSeparator) { sourceViewer.setDocument(new Document(EMPTY_STRING)); } super.handleSelected(selection); }
From source file:org.locationtech.udig.validation.ui.ValidationDialog.java
License:Open Source License
/** * Creates the validation test suite selection area of the dialog. This area displays a tree of * validations that the user may select and modify. The first tier of the tree contains the * available validation plugins, and the second tier contains instances of the test. * //from w w w .j a v a 2 s .co m * @return the composite used for the validations selection area * @throws Exception */ protected Composite createValidationSelectionArea(Composite parent) throws Exception { Font font = parent.getFont(); Composite comp = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(1, false); layout.marginHeight = 5; layout.marginWidth = 5; comp.setLayout(layout); comp.setFont(font); Label treeLabel = new Label(comp, SWT.NONE); treeLabel.setFont(font); treeLabel.setText(Messages.ValidationDialog_validations); GridData labelData = new GridData(); treeLabel.setLayoutData(labelData); ValidationProcessor tempProcessor = loadDialogState(ApplicationGIS.getActiveMap()); if (tempProcessor == null) { processor = createProcessor(null, null); defaultTestSuite = "testSuite1"; //$NON-NLS-1$ } else { processor = tempProcessor; if (processor.getTestSuiteDTOs().size() == 1) { // a single testSuite exists, grab its name defaultTestSuite = (String) processor.getTestSuiteDTOs().keySet().toArray()[0]; } else if (processor.getTestSuiteDTOs().size() == 0) { // there is no... testSuite, create one processor = createProcessor(null, null); defaultTestSuite = "testSuite1"; //$NON-NLS-1$ } else { // there are multiple testSuites, choose the largest one String thisTestSuite = ""; //$NON-NLS-1$ int mostTests = -1; for (Iterator i = processor.getTestSuiteDTOs().keySet().iterator(); i.hasNext();) { Object thisKey = i.next(); int numTests = ((TestSuiteDTO) processor.getTestSuiteDTOs().get(thisKey)).getTests().size(); if (numTests > mostTests) { mostTests = numTests; thisTestSuite = (String) thisKey; } } defaultTestSuite = thisTestSuite; } } // create the treeViewer (list of possible validations (plugins) + prepared tests) treeViewer = new CheckboxTreeViewer(comp); treeViewer.setLabelProvider(new ValidationTreeLabelProvider()); treeViewer.setSorter(new WorkbenchViewerSorter()); contentProvider = new ValidationTreeContentProvider(); treeViewer.setContentProvider(contentProvider); treeViewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { Object element = event.getElement(); Object[] children = contentProvider.getChildren(element); if (children != null && children.length > 0) { // parent element was modified, adjust the children accordingly for (int i = 0; i < children.length; i++) { treeViewer.setChecked(children[i], event.getChecked()); } // all children are in the same state, therefore the parent is not grayed treeViewer.setGrayed(element, false); } Object parent = contentProvider.getParent(element); if (parent != null) { // child element was modified Object[] siblings = contentProvider.getChildren(parent); boolean oneSiblingChecked = false; boolean allSiblingsChecked = true; for (int i = 0; i < siblings.length; i++) { if (treeViewer.getChecked(siblings[i])) { oneSiblingChecked = true; } else { allSiblingsChecked = false; } } if (allSiblingsChecked) { // mark parent checked and NOT grayed out treeViewer.setGrayed(parent, false); treeViewer.setChecked(parent, true); } else { if (oneSiblingChecked) { // mark parent checked and grayed out treeViewer.setGrayChecked(parent, true); } else { // mark parent NOT checked treeViewer.setGrayChecked(parent, false); } } } } }); // populate the tree treeViewer.setInput(processor); treeViewer.expandAll(); Control control = treeViewer.getControl(); GridData gd = new GridData(GridData.FILL_BOTH); gd.heightHint = 250; // initial height of treeViewer (in pixels?) gd.verticalSpan = 3; control.setLayoutData(gd); control.setFont(font); // composite to hold the new/delete/save/... buttons buttonComposite = new Composite(comp, SWT.NONE); gd = new GridData(GridData.FILL_HORIZONTAL); gd.widthHint = 200; buttonComposite.setLayoutData(gd); buttonComposite.setFont(comp.getFont()); GridLayout buttonLayout = new GridLayout(2, false); buttonComposite.setLayout(buttonLayout); // construct the new validation test button newButton = new Button(buttonComposite, SWT.PUSH); newButton.setFont(parent.getFont()); newButton.setText(Messages.ValidationDialog_new); newButton.setEnabled(false); newButton.addSelectionListener(new NewTestListener()); setButtonLayoutData(newButton); // construct the delete validation test button deleteButton = new Button(buttonComposite, SWT.PUSH); deleteButton.setFont(parent.getFont()); deleteButton.setText(Messages.ValidationDialog_delete); deleteButton.setEnabled(false); deleteButton.addSelectionListener(new DeleteTestListener()); setButtonLayoutData(deleteButton); // construct treeViewer listener treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { if (!event.getSelection().isEmpty()) { StructuredSelection selection = (StructuredSelection) event.getSelection(); if (selection.size() == 1) { Object element = selection.getFirstElement(); selectedTreeItem = element; //record the current selection so other events can figure out who is selected if (element instanceof TestDTO) { //test instance was selected newButton.setEnabled(false); deleteButton.setEnabled(true); nameText.setText(((TestDTO) element).getName()); nameText.setEditable(true); descText.setText(((TestDTO) element).getDescription()); descText.setEditable(true); tableViewer.setInput(element); // pass the args (inside the testDTO) tableViewer.getControl().setEnabled(true); resizeTable(); } else if (element instanceof PlugInDTO) { //validation parent (plugin) was selection newButton.setEnabled(true); deleteButton.setEnabled(false); nameText.setText(((PlugInDTO) selection.getFirstElement()).getName()); nameText.setEditable(false); descText.setText(((PlugInDTO) selection.getFirstElement()).getDescription()); descText.setEditable(false); tableViewer.setInput(null); //hide arguments tableViewer.getControl().setEnabled(false); } else { // this shouldn't be called newButton.setEnabled(false); deleteButton.setEnabled(false); nameText.setText(""); //$NON-NLS-1$ nameText.setEditable(false); descText.setText(""); //$NON-NLS-1$ descText.setEditable(false); tableViewer.setInput(null); //hide arguments tableViewer.getControl().setEnabled(false); } } else { //more than one selection was made selectedTreeItem = null; newButton.setEnabled(false); deleteButton.setEnabled(false); nameText.setEditable(false); descText.setEditable(false); tableViewer.setInput(null); //hide arguments tableViewer.getControl().setEnabled(false); } updateButtons(); } } }); treeViewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { updateButtons(); if (event.getElement() instanceof PlugInDTO) { if (event.getChecked()) { //select the parent if is not already ISelection selection; if (selectedTreeItem != event.getElement()) { selection = new StructuredSelection(event.getElement()); treeViewer.setSelection(selection); } //automatically create a child if none exist if (!contentProvider.hasChildren(selectedTreeItem)) { TestDTO newTest = addTest(); selection = new StructuredSelection(newTest); treeViewer.setSelection(selection); } } } } }); return comp; }
From source file:org.mwc.cmap.grideditor.table.actons.GridEditorActionGroup.java
License:Open Source License
@Override public void fillContextMenu(final IMenuManager menu) { initActions();/*from w ww . j a v a2 s. c o m*/ menu.add(myInsertRowAction); menu.add(myDeleteRowAction); menu.add(myInterpolateAction); menu.add(new Separator()); menu.add(myExportAction); menu.add(new Separator()); menu.add(myShowVisItemsAction); menu.add(myTrackSelectionAction); menu.add(new Separator()); // right, find the selection final StructuredSelection sel = (StructuredSelection) myView.getUI().getTable().getTableViewer() .getSelection(); // do we have something? if (sel.size() > 0) { // create an array of the items being edited final Editable[] items = new Editable[sel.size()]; int index = 0; @SuppressWarnings("rawtypes") final Iterator iter = sel.iterator(); while (iter.hasNext()) { items[index++] = (Editable) iter.next(); } // collate the other metadata final GriddableWrapper wrapper = (GriddableWrapper) myView.getUI().getTable().getTableViewer() .getInput(); // fill the layers objects final Layer[] topLayers = new Layer[sel.size()]; final Layer[] parentLayers = new Layer[sel.size()]; for (int i = 0; i < sel.size(); i++) { topLayers[i] = wrapper.getWrapper().getTopLevelLayer(); parentLayers[i] = wrapper.getWrapper().getTopLevelLayer(); } final Layers theLayers = wrapper.getWrapper().getLayers(); // create a drop-down menu for this item RightClickSupport.getDropdownListFor(menu, items, topLayers, parentLayers, theLayers, true); } }
From source file:org.mwc.debrief.core.editors.PlotOutlinePage.java
License:Open Source License
void fillContextMenu(final IMenuManager manager) { // get the selected item final StructuredSelection sel = (StructuredSelection) _treeViewer.getSelection(); // right, we only worry about primary, secondary, hide, reveal if something // is selected if (sel.size() > 0) { // ok, allow hide/reveal manager.add(_hideAction);/*from www . jav a 2 s. c o m*/ manager.add(_revealAction); // have a look at the data-types to sort out whether to primary/secondary if (isValidPrimary(sel)) manager.add(_makePrimary); if (isValidSecondary(sel)) { manager.add(_makeSecondary); manager.add(_addAsSecondary); } // now stick in the separator anyway manager.add(new Separator()); } // drillDownAdapter.addNavigationActions(manager); // Other plug-ins can contribute there actions here manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); // hey, sort out the data-specific items // build up a list of menu items // create some lists to store our selected items final Editable[] eList = new Editable[sel.size()]; final Layer[] parentLayers = new Layer[sel.size()]; final Layer[] updateLayers = new Layer[sel.size()]; // right, now populate them final Object[] oList = sel.toArray(); for (int i = 0; i < oList.length; i++) { final EditableWrapper wrapper = (EditableWrapper) oList[i]; eList[i] = wrapper.getEditable(); // sort out the parent layer final EditableWrapper theParent = wrapper.getParent(); // hmm, did we find one? if (theParent != null) // yes, store it parentLayers[i] = (Layer) wrapper.getParent().getEditable(); else // nope - store a null (to indicate it's a top-level layer) parentLayers[i] = null; updateLayers[i] = wrapper.getTopLevelLayer(); } // ok, sort out what we can do with all of this... RightClickSupport.getDropdownListFor(manager, eList, updateLayers, parentLayers, _myLayers, false); }