List of usage examples for org.eclipse.jface.viewers StructuredSelection size
@Override public int size()
From source file:org.mwc.debrief.core.editors.PlotOutlinePage.java
License:Open Source License
/** * find out if the selection is valid for setting as primary * // w w w . j a va 2 s. c o m * @param ss * @return */ protected boolean isValidPrimary(final StructuredSelection ss) { boolean res = false; // we can only do this for one entry! if (ss.size() == 1) { final EditableWrapper pw = (EditableWrapper) ss.getFirstElement(); final Editable pl = pw.getEditable(); // hey, first see if it's even a candidate if (pl instanceof WatchableList) // do we have a track data listener? if (_theTrackDataListener != null) { // now see if it's already the primary if (pl != _theTrackDataListener.getPrimaryTrack()) { res = true; } } } return res; }
From source file:org.mwc.debrief.core.editors.PlotOutlinePage.java
License:Open Source License
/** * find out if the selection is valid for setting as primary * /*from w w w.ja v a 2s . c o m*/ * @param ss * @return */ protected boolean isValidSecondary(final StructuredSelection ss) { boolean res = false; if (ss.size() >= 1) { Iterator<?> iter = ss.iterator(); while (iter.hasNext()) { EditableWrapper pw = (EditableWrapper) iter.next(); final Editable pl = pw.getEditable(); if (!(pl instanceof WatchableList)) { // nope - we can just make them all secondaries! drop out res = false; break; } else { // hey, it's a maybe. res = true; // ok, it's a candidate. now see if it's already one of the secondaries if (_theTrackDataListener == null) { CorePlugin.logError(Status.INFO, "PROBLEM: Outline View does not hold track data listener. Maintaner to track this occurrence", null); } else { final WatchableList[] secs = _theTrackDataListener.getSecondaryTracks(); if (secs != null) { for (int i = 0; i < secs.length; i++) { final WatchableList thisList = secs[i]; if (thisList == pl) { res = false; break; } } } } } } } return res; }
From source file:org.neuro4j.studio.core.diagram.sheet.Neuro4jPropertySection.java
License:Apache License
/** * @generated/*from www .j a v a 2s.c o m*/ */ public void setInput(IWorkbenchPart part, ISelection selection) { if (selection.isEmpty() || false == selection instanceof StructuredSelection) { super.setInput(part, selection); return; } final StructuredSelection structuredSelection = ((StructuredSelection) selection); ArrayList transformedSelection = new ArrayList(structuredSelection.size()); for (Iterator it = structuredSelection.iterator(); it.hasNext();) { Object r = transformSelection(it.next()); if (r != null) { transformedSelection.add(r); } } // super.setInput(part, new StructuredSelection(transformedSelection)); selection = new StructuredSelection(transformedSelection); IEditingDomainProvider provider = (IEditingDomainProvider) part.getAdapter(IEditingDomainProvider.class); if (provider != null) { EditingDomain theEditingDomain = provider.getEditingDomain(); if (theEditingDomain instanceof TransactionalEditingDomain) { setEditingDomain((TransactionalEditingDomain) theEditingDomain); } } // Set the eObject for the section, too. The workbench part may not // adapt to IEditingDomainProvider, in which case the selected EObject // will be used to derive the editing domain. if (!selection.isEmpty() && selection instanceof IStructuredSelection) { Object firstElement = ((IStructuredSelection) selection).getFirstElement(); if (firstElement != null) { EObject adapted = unwrap(firstElement); if (adapted != null) { setEObject(adapted); } } } page.selectionChanged(part, selection); }
From source file:org.opentravel.schemas.utils.RCPUtils.java
License:Apache License
/** * @param selection//from ww w. ja v a 2s . com * must by {@link StructuredSelection}. * @param clazz * @return extract object of provided type or his sub-types from selection. */ @SuppressWarnings("unchecked") public static <T> List<T> extractObjects(ISelection selection, Class<T> clazz) { if (selection instanceof StructuredSelection) { StructuredSelection ss = (StructuredSelection) selection; List<T> ret = new ArrayList<T>(ss.size()); for (Object o : ss.toList()) { if (clazz.isAssignableFrom(o.getClass())) { ret.add((T) o); } } return ret; } return Collections.emptyList(); }
From source file:org.ow2.aspirerfid.ide.bpwme.diagram.sheet.BusinessStepPropertySection.java
License:Open Source License
public void setInput(IWorkbenchPart part, ISelection selection) { if (selection.isEmpty() || false == selection instanceof StructuredSelection) { super.setInput(part, selection); return;/*from w w w. ja va2 s.c o m*/ } final StructuredSelection structuredSelection = ((StructuredSelection) selection); ArrayList transformedSelection = new ArrayList(structuredSelection.size()); for (Iterator it = structuredSelection.iterator(); it.hasNext();) { Object r = transformSelection(it.next()); if (r != null) { transformedSelection.add(r); } } super.setInput(part, new StructuredSelection(transformedSelection)); MasterDataBuilder mdb = MasterDataBuilder.getInstance(); MainControl mc = MainControl.getMainControl(); IStructuredSelection selection1 = (IStructuredSelection) getSelection(); if (selection1.getFirstElement() instanceof org.ow2.aspirerfid.ide.bpwme.impl.OLCBProcImpl) { mdb.setOLCBProc(mc.getOLCBProc()); } }
From source file:org.python.pydev.outline.ParsedModel.java
License:Open Source License
public SimpleNode[] getSelectionPosition(StructuredSelection sel) { if (sel.size() == 1) { // only sync the editing view if it is a single-selection Object firstElement = sel.getFirstElement(); ASTEntryWithChildren p = ((ParsedItem) firstElement).getAstThis(); if (p == null) { return null; }/*from www . j a v a 2 s .com*/ SimpleNode node = p.node; if (node instanceof ClassDef) { ClassDef def = (ClassDef) node; node = def.name; } else if (node instanceof Attribute) { Attribute attribute = (Attribute) node; node = attribute.attr; } else if (node instanceof FunctionDef) { FunctionDef def = (FunctionDef) node; node = def.name; } else if (node instanceof Import) { ArrayList<SimpleNode> ret = new ArrayList<SimpleNode>(); Import importToken = (Import) node; for (int i = 0; i < importToken.names.length; i++) { aliasType aliasType = importToken.names[i]; //as ... if (aliasType.asname != null) { ret.add(aliasType.asname); } ret.add(aliasType.name); } return ret.toArray(new SimpleNode[0]); } else if (node instanceof ImportFrom) { ArrayList<SimpleNode> ret = new ArrayList<SimpleNode>(); ImportFrom importToken = (ImportFrom) node; boolean found = false; for (int i = 0; i < importToken.names.length; i++) { found = true; aliasType aliasType = importToken.names[i]; //as ... if (aliasType.asname != null) { ret.add(aliasType.asname); } ret.add(aliasType.name); } if (!found) { ret.add(importToken.module); } return ret.toArray(new SimpleNode[0]); } return new SimpleNode[] { node }; } return null; }
From source file:org.python.pydev.shared_ui.outline.BaseOutlinePage.java
License:Open Source License
/** * create the outline view widgets/* w ww.j a v a2 s. c om*/ */ @Override public void createControl(Composite parent) { super.createControl(parent); // this creates a tree viewer try { createParsedOutline(); // selecting an item in the outline scrolls the document selectionListener = new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { if (linkWithEditor == null) { return; } try { unlinkAll(); StructuredSelection sel = (StructuredSelection) event.getSelection(); boolean alreadySelected = false; if (sel.size() == 1) { // only sync the editing view if it is a single-selection IParsedItem firstElement = (IParsedItem) sel.getFirstElement(); ErrorDescription errorDesc = firstElement.getErrorDesc(); //select the error if (errorDesc != null && errorDesc.message != null) { int len = errorDesc.errorEnd - errorDesc.errorStart; editorView.setSelection(errorDesc.errorStart, len); alreadySelected = true; } } if (!alreadySelected) { ISimpleNode[] node = getOutlineModel().getSelectionPosition(sel); editorView.revealModelNodes(node); } } finally { relinkAll(); } } }; addSelectionChangedListener(selectionListener); createActions(); //OK, instead of using the default selection engine, we recreate it only to handle mouse //and key events directly, because it seems that sometimes, SWT creates spurious select events //when those shouldn't be created, and there's also a risk of creating loops with the selection, //as when one selection arrives when we're linked, we have to perform a selection and doing that //selection could in turn trigger a new selection, so, we remove that treatment and only start //selections from interactions the user did. //see: Cursor jumps to method definition when an error is detected //https://sourceforge.net/tracker2/?func=detail&aid=2057092&group_id=85796&atid=577329 TreeViewer treeViewer = getTreeViewer(); treeViewer.removeSelectionChangedListener(this); Tree tree = treeViewer.getTree(); tree.addMouseListener(new MouseListener() { public void mouseDoubleClick(MouseEvent e) { tryToMakeSelection(); } public void mouseDown(MouseEvent e) { } public void mouseUp(MouseEvent e) { tryToMakeSelection(); } }); tree.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { if (e.keyCode == SWT.ARROW_UP || e.keyCode == SWT.ARROW_DOWN) { tryToMakeSelection(); } } }); onControlCreated.call(getTreeViewer()); createdCallbacksForControls = callRecursively(onControlCreated, filter, new ArrayList()); } catch (Throwable e) { Log.log(e); } }
From source file:org.springframework.tooling.ls.eclipse.gotosymbol.dialogs.GotoSymbolDialog.java
License:Open Source License
private void installWidgetListeners(Text pattern, TreeViewer list) { pattern.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.keyCode == SWT.ARROW_DOWN) { if (list.getTree().getItemCount() > 0) { list.getTree().setFocus(); TreeItem[] items = list.getTree().getItems(); if (items != null && items.length > 0) { list.getTree().setSelection(items[0]); //programatic selection may not fire selection events so... list.getTree().notifyListeners(SWT.Selection, new Event()); }//from w ww. ja v a 2 s . c o m } } else if (e.character == '\r') { performOk(list); } } }); list.getTree().addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { 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(getFirstElement(list))) { pattern.setFocus(); list.setSelection(new StructuredSelection()); list.getTree().notifyListeners(SWT.Selection, new Event()); } } } else if (e.character == '\r') { performOk(list); } // if (e.keyCode == SWT.ARROW_DOWN // && (e.stateMask & SWT.SHIFT) != 0 // && (e.stateMask & SWT.CTRL) != 0) { // // list.getTree().notifyListeners(SWT.Selection, new Event()); // } } }); list.addDoubleClickListener(e -> performOk(list)); }
From source file:org.springsource.ide.eclipse.commons.quicksearch.ui.QuickSearchDialog.java
License:Open Source License
@Override protected Control createDialogArea(Composite parent) { Composite dialogArea = (Composite) super.createDialogArea(parent); dialogArea.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { QuickSearchDialog.this.dispose(); }// w ww . j ava 2 s .c o m }); Composite content = createNestedComposite(dialogArea, 1, false); GridData gd = new GridData(GridData.FILL_BOTH); content.setLayoutData(gd); final Label headerLabel = createHeader(content); Composite inputRow = createNestedComposite(content, 10, true); GridDataFactory.fillDefaults().grab(true, false).applyTo(inputRow); pattern = new Text(inputRow, 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()); } }); GridDataFactory.fillDefaults().span(6, 1).grab(true, false).applyTo(pattern); Composite searchInComposite = createNestedComposite(inputRow, 2, false); GridDataFactory.fillDefaults().span(4, 1).grab(true, false).applyTo(searchInComposite); Label searchInLabel = new Label(searchInComposite, SWT.NONE); searchInLabel.setText(" In: "); searchIn = new Text(searchInComposite, SWT.SINGLE | SWT.BORDER | SWT.ICON_CANCEL); searchIn.setToolTipText("Search in (comma-separated list of '.gitignore' style inclusion patterns)"); GridDataFactory.fillDefaults().grab(true, false).applyTo(searchIn); final Label listLabel = createLabels(content); sashForm = new SashForm(content, SWT.VERTICAL); GridDataFactory.fillDefaults().grab(true, true).applyTo(sashForm); list = new TableViewer(sashForm, (multi ? SWT.MULTI : SWT.SINGLE) | SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL | SWT.VIRTUAL); // ColumnViewerToolTipSupport.enableFor(list, ToolTip.NO_RECREATE); list.getTable().setHeaderVisible(true); list.getTable().setLinesVisible(true); 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); // new ScrollListener(list.getTable().getVerticalBar()); // new SelectionChangedListener(list); TableViewerColumn col = new TableViewerColumn(list, SWT.RIGHT); col.setLabelProvider(LINE_NUMBER_LABEL_PROVIDER); col.getColumn().setText("Line"); col.getColumn().setWidth(40); col = new TableViewerColumn(list, SWT.LEFT); col.getColumn().setText("Text"); col.setLabelProvider(LINE_TEXT_LABEL_PROVIDER); col.getColumn().setWidth(400); col = new TableViewerColumn(list, SWT.LEFT); col.getColumn().setText("Path"); col.setLabelProvider(LINE_FILE_LABEL_PROVIDER); col.getColumn().setWidth(150); new TableResizeHelper(list).enableResizing(); //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(e -> { applyFilter(false); }); searchIn.addModifyListener(e -> { applyPathMatcher(); }); pattern.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.keyCode == SWT.ARROW_DOWN) { if (list.getTable().getItemCount() > 0) { list.getTable().setFocus(); list.getTable().select(0); //programatic selection may not fire selection events so... refreshDetails(); } } } }); 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.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(); } list.getTable().notifyListeners(SWT.Selection, new Event()); } } if (e.keyCode == SWT.ARROW_DOWN && (e.stateMask & SWT.SHIFT) != 0 && (e.stateMask & SWT.CTRL) != 0) { list.getTable().notifyListeners(SWT.Selection, new Event()); } } }); createDetailsArea(sashForm); sashForm.setWeights(new int[] { 5, 1 }); 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(false); return dialogArea; }
From source file:org.switchyard.tools.ui.common.WSDLPortTypeSelectionDialog.java
License:Open Source License
@Override protected void handleSelected(StructuredSelection selection) { // update portTypes list if (selection.isEmpty() || selection.size() != 1 || !(selection.getFirstElement() instanceof IResource)) { _portTypesList.setInput(null);/*from w w w . j a va 2 s .com*/ return; } Definition definition = _wsdlDefinitions.get(selection.getFirstElement()); if (definition == null) { // we need to load the definition final IResource wsdlFile = (IResource) selection.getFirstElement(); final Definition[] holder = new Definition[1]; BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() { public void run() { try { ResourceSet resourceSet = new ResourceSetImpl(); WSDLResourceImpl resource = (WSDLResourceImpl) resourceSet.getResource( URI.createPlatformResourceURI(wsdlFile.getFullPath().toString(), true), true); holder[0] = resource.getDefinition(); } catch (Exception e) { e.printStackTrace(); } } }); definition = holder[0]; _wsdlDefinitions.put(wsdlFile, definition); } Collection<?> portTypes = definition == null ? Collections.emptyList() : definition.getEPortTypes(); _portTypesList.setInput(portTypes); if (portTypes.size() > 0) { selection = new StructuredSelection(portTypes.iterator().next()); } else { selection = StructuredSelection.EMPTY; } _portTypesList.setSelection(selection, true); }