List of usage examples for org.eclipse.jface.viewers StructuredSelection size
@Override public int size()
From source file:org.eclipse.e4.demo.simpleide.navigator.internal.ResourceNavigator.java
License:Open Source License
@Inject public ResourceNavigator(Composite parent, final IEclipseContext context, IWorkspace workspace) { final Realm realm = SWTObservables.getRealm(parent.getDisplay()); this.context = context; parent.setLayout(new FillLayout()); TreeViewer viewer = new TreeViewer(parent, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); selectionService// w w w. j ava 2 s .com .setSelection(selection.size() == 1 ? selection.getFirstElement() : selection.toArray()); // context.modify(IServiceConstants.ACTIVE_SELECTION, selection.size() == 1 ? selection.getFirstElement() : selection.toArray()); } }); IObservableFactory setFactory = new IObservableFactory() { public IObservable createObservable(Object element) { if (element instanceof IContainer && ((IContainer) element).exists()) { IObservableSet observableSet = observableSets.get(element); if (observableSet == null) { observableSet = new WritableSet(realm); try { observableSet.addAll(Arrays.asList(((IContainer) element).members())); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } observableSets.put((IContainer) element, observableSet); } return observableSet; } return Observables.emptyObservableSet(); } }; viewer.setContentProvider(new ObservableSetTreeContentProvider(setFactory, new TreeStructureAdvisor() { public Boolean hasChildren(Object element) { return Boolean.valueOf(element instanceof IContainer); } })); viewer.setLabelProvider(new LabelProvider() { public String getText(Object element) { if (element instanceof IResource) return ((IResource) element).getName(); return element == null ? "" : element.toString(); } }); viewer.setSorter(new ViewerSorter()); viewer.setInput(workspace.getRoot()); viewer.addOpenListener(new IOpenListener() { public void open(OpenEvent event) { MSimpleIDEApplication app = (MSimpleIDEApplication) application; IStructuredSelection s = (IStructuredSelection) event.getSelection(); for (Object o : s.toArray()) { if (o instanceof IFile) { IFile f = (IFile) o; context.set(IFile.class, f); String fExt = f.getFileExtension(); EDITOR: for (MEditorPartDescriptor desc : app.getEditorPartDescriptors()) { for (String ext : desc.getFileextensions()) { if (ext.equals(fExt)) { context.set(MEditorPartDescriptor.class, desc); System.err.println("Opening with: " + desc); Command cmd = commandService.getCommand("simpleide.command.openeditor"); ParameterizedCommand pCmd = ParameterizedCommand.generateCommand(cmd, null); handlerService.executeHandler(pCmd); break EDITOR; } } } } } } }); setupContextMenu(viewer, parent.getShell()); workspace.addResourceChangeListener(listener); }
From source file:org.eclipse.e4.tools.css.spy.CssSpyDialog.java
License:Open Source License
private void updateForWidgetSelection(ISelection sel) { disposeHighlights();//from ww w . j a v a 2 s. c o m if (sel.isEmpty()) { return; } StructuredSelection selection = (StructuredSelection) sel; for (Object s : selection.toList()) { if (s instanceof Widget) { highlightWidget((Widget) s); } } populate(selection.size() == 1 && selection.getFirstElement() instanceof Widget ? (Widget) selection.getFirstElement() : null); }
From source file:org.eclipse.egit.ui.internal.repository.RepositoriesView.java
License:Open Source License
private void reactOnSelection(ISelection selection) { if (selection instanceof StructuredSelection) { StructuredSelection ssel = (StructuredSelection) selection; if (ssel.size() != 1) return; if (ssel.getFirstElement() instanceof IResource) showResource((IResource) ssel.getFirstElement()); if (ssel.getFirstElement() instanceof IAdaptable) { IResource adapted = (IResource) ((IAdaptable) ssel.getFirstElement()).getAdapter(IResource.class); if (adapted != null) showResource(adapted);/*from w ww . j av a 2 s. c o m*/ } } }
From source file:org.eclipse.egit.ui.internal.staging.StagingView.java
License:Open Source License
private void reactOnSelection(ISelection selection) { if (selection instanceof StructuredSelection) { StructuredSelection ssel = (StructuredSelection) selection; if (ssel.size() != 1) return; Object firstElement = ssel.getFirstElement(); if (firstElement instanceof IResource) showResource((IResource) firstElement); else if (firstElement instanceof RepositoryTreeNode) { RepositoryTreeNode repoNode = (RepositoryTreeNode) firstElement; reload(repoNode.getRepository()); } else if (firstElement instanceof IAdaptable) { IResource adapted = (IResource) ((IAdaptable) firstElement).getAdapter(IResource.class); if (adapted != null) showResource(adapted);// www . ja v a2 s . c o m } } }
From source file:org.eclipse.emf.cdo.dawn.examples.acore.diagram.sheet.AcorePropertySection.java
License:Open Source License
/** * @generated// ww w . ja va 2 s.c o m */ @Override 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)); }
From source file:org.eclipse.emf.ecoretools.internal.views.EcoreToolsViewsDragTargetAdapter.java
License:Open Source License
/** * {@inheritDoc}/*from w w w. j a v a2 s .c om*/ * * @see org.eclipse.swt.dnd.DragSourceAdapter#dragStart(org.eclipse.swt.dnd.DragSourceEvent) */ @Override public void dragStart(final DragSourceEvent event) { final ISelection selection = provider.getSelection(); if (selection instanceof StructuredSelection) { StructuredSelection sSelection = (StructuredSelection) selection; List<EObject> ecoreObjects = new ArrayList<EObject>(sSelection.size()); Iterator<Object> it = sSelection.iterator(); while (it.hasNext()) { Object obj = it.next(); if (obj instanceof EObject) { ecoreObjects.add((EObject) obj); } else if (obj instanceof WrappedEClass) { ecoreObjects.add(((WrappedEClass) obj).getWrappedEClass()); } } ISelection unwrapped = new StructuredSelection(ecoreObjects); LocalSelectionTransfer.getInstance().setSelection(unwrapped); LocalSelectionTransfer.getInstance().setSelectionSetTime(event.time & 0xFFFFFFFFL); event.doit = true; } }
From source file:org.eclipse.emf.eef.runtime.ui.widgets.EEFSelectionDialog.java
License:Open Source License
/** * {@inheritDoc}/*from ww w . j a v a2 s.c o m*/ * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) */ protected Control createDialogArea(Composite parent) { Composite control = new Composite(parent, SWT.NONE); control.setLayoutData(new GridData(GridData.FILL_BOTH)); control.setLayout(new GridLayout()); Label message = new Label(control, SWT.NONE); message.setText("Select the element(s) to process:"); int style = SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER; if (multi) { style |= SWT.MULTI; } selectionViewer = new TreeViewer(control, style); selectionViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); for (ViewerFilter filter : filters) { selectionViewer.addFilter(filter); } selectionViewer.setContentProvider(getContentProvider()); selectionViewer.setLabelProvider(getLabelProvider()); selectionViewer.setInput(input); selectionViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { StructuredSelection sSel = (StructuredSelection) selectionViewer.getSelection(); if (sSel.size() == 0) { EEFSelectionDialog.this.selection = null; } else if (sSel.size() == 1) { EEFSelectionDialog.this.selection = sSel.getFirstElement(); } else { EEFSelectionDialog.this.selection = sSel.toList(); } } }); return control; }
From source file:org.eclipse.emf.eef.runtime.ui.widgets.EReferenceEditor.java
License:Open Source License
/** * Update the list buttons.//w w w . j a v a2 s. c om */ protected void updateButtons() { StructuredSelection selection = (StructuredSelection) tree.getSelection(); addButton.setEnabled(shouldEnableAdd(selection)); if (selection.size() == 0) { removeButton.setEnabled(false); upButton.setEnabled(false); downButton.setEnabled(false); } else if (selection.size() == 1) { removeButton.setEnabled(shouldEnableRemove(selection)); upButton.setEnabled(shouldEnableUp(selection)); downButton.setEnabled(shouldEnableDown(selection)); } else { removeButton.setEnabled(shouldEnableRemove(selection)); upButton.setEnabled(false); downButton.setEnabled(false); } }
From source file:org.eclipse.gmf.graphdef.editor.sheet.AbstractCustomSectionParent.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 ww w . ja v a 2s.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); } } mySavedSelection = transformedSelection; super.setInput(part, new StructuredSelection(transformedSelection)); }
From source file:org.eclipse.gmf.runtime.common.ui.services.elementselection.ElementSelectionComposite.java
License:Open Source License
/** * Handles a selection change and validates the new selection. */// w ww .jav a 2 s .co m private void handleSelectionChange() { StructuredSelection selection = (StructuredSelection) tableViewer.getSelection(); if (selection.size() == 0) { // nothing selected selectedElements.clear(); handleSelection(false); return; } List selectionList = selection.toList(); // get the current selected elements List currentSelectedElements = new ArrayList(); for (Iterator iter = selectionList.iterator(); iter.hasNext();) { AbstractMatchingObject matchingObject = (AbstractMatchingObject) iter.next(); currentSelectedElements.add(matchingObject); } // validate selection boolean isValidSelection = isValidSelection(currentSelectedElements); // store the selection selectedElements.clear(); if (isValidSelection) { selectedElements.addAll(currentSelectedElements); } // update UI based on selection handleSelection(isValidSelection); }