List of usage examples for org.eclipse.jface.viewers StructuredSelection iterator
@Override
public Iterator iterator()
From source file:org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers.EnableEventOnSessionHandler.java
License:Open Source License
@Override public boolean isEnabled() { // Get workbench page for the Control View IWorkbenchPage page = getWorkbenchPage(); if (page == null) { return false; }/*w ww . j a v a 2s. c om*/ TraceSessionComponent session = null; // Check if one session is selected ISelection selection = page.getSelection(ControlView.ID); if (selection instanceof StructuredSelection) { StructuredSelection structered = ((StructuredSelection) selection); for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) { Object element = iterator.next(); if (element instanceof TraceSessionComponent) { // Add only if corresponding TraceSessionComponents is inactive and not destroyed TraceSessionComponent tmpSession = (TraceSessionComponent) element; if (tmpSession.getSessionState() == TraceSessionState.INACTIVE && !tmpSession.isDestroyed()) { session = tmpSession; } } } } boolean isEnabled = (session != null); fLock.lock(); try { fParam = null; if (isEnabled) { fParam = new CommandParameter(session); } } finally { fLock.unlock(); } return isEnabled; }
From source file:org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers.ImportHandler.java
License:Open Source License
@Override public boolean isEnabled() { // Get workbench page for the Control View IWorkbenchPage page = getWorkbenchPage(); if (page == null) { return false; }/*from ww w . j a v a 2 s .c o m*/ // Check if one or more session are selected ISelection selection = page.getSelection(ControlView.ID); TraceSessionComponent session = null; if (selection instanceof StructuredSelection) { StructuredSelection structered = ((StructuredSelection) selection); for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) { Object element = iterator.next(); if (element instanceof TraceSessionComponent) { // Add only TraceSessionComponents that are inactive and not // destroyed TraceSessionComponent tmpSession = (TraceSessionComponent) element; if ((tmpSession.isSnapshotSession() || tmpSession.isLiveTrace() || (tmpSession.getSessionState() == TraceSessionState.INACTIVE)) && (!tmpSession.isDestroyed())) { session = tmpSession; } } } } boolean isEnabled = session != null; fLock.lock(); try { fParam = null; if (isEnabled) { fParam = new CommandParameter(session); } } finally { fLock.unlock(); } return isEnabled; }
From source file:org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers.RefreshHandler.java
License:Open Source License
@Override public boolean isEnabled() { // Get workbench page for the Control View IWorkbenchPage page = getWorkbenchPage(); if (page == null) { return false; }//from w ww . ja v a2s . c om TargetNodeComponent node = null; // Check if one or more session are selected ISelection selection = page.getSelection(ControlView.ID); if (selection instanceof StructuredSelection) { StructuredSelection structered = ((StructuredSelection) selection); for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) { Object element = iterator.next(); if (element instanceof TraceControlComponent) { TraceControlComponent component = (TraceControlComponent) element; boolean isConnected = component.getTargetNodeState() == TargetNodeState.CONNECTED; if (isConnected) { while ((component != null) && component.getClass() != TargetNodeComponent.class) { component = (TraceControlComponent) component.getParent(); } if (component != null) { node = (TargetNodeComponent) component; } } } } } boolean isEnabled = node != null; fLock.lock(); try { fNode = null; if (isEnabled) { fNode = node; } } finally { fLock.unlock(); } return isEnabled; }
From source file:org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers.SnaphshotHandler.java
License:Open Source License
@Override public boolean isEnabled() { // Get workbench page for the Control View IWorkbenchPage page = getWorkbenchPage(); if (page == null) { return false; }/*from w w w.j a v a2 s . c o m*/ List<TraceSessionComponent> sessions = new ArrayList<>(0); // Check if one session is selected ISelection selection = page.getSelection(ControlView.ID); if (selection instanceof StructuredSelection) { StructuredSelection structered = ((StructuredSelection) selection); for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) { Object element = iterator.next(); if (element instanceof TraceSessionComponent) { // Add only if corresponding TraceSessionComponent is an active snapshot session and not destroyed TraceSessionComponent session = (TraceSessionComponent) element; if (session.isSnapshotSession() && session.getSessionState() == TraceSessionState.ACTIVE && !session.isDestroyed()) { sessions.add(session); } } } } boolean isEnabled = !sessions.isEmpty(); fLock.lock(); try { fSessions = null; if (isEnabled) { fSessions = sessions; } } finally { fLock.unlock(); } return isEnabled; }
From source file:org.eclipse.linuxtools.rpmstubby.popup.actions.StubifyPomAction.java
License:Open Source License
@Override public void run(IAction action) { IFile pomFile = null;//from ww w.java 2 s .c o m StructuredSelection structuredSelection = (StructuredSelection) selection; for (Iterator<?> selectionIter = structuredSelection.iterator(); selectionIter.hasNext();) { Object selected = selectionIter.next(); if (selected instanceof IFile) { pomFile = (IFile) selected; } else { // FIXME: error } } SpecfilePomWriter specfileWriter = new SpecfilePomWriter(); specfileWriter.write(pomFile); }
From source file:org.eclipse.mdht.uml.ui.properties.internal.sections.UMLAdvancedSection.java
License:Open Source License
@Override public void setInput(IWorkbenchPart part, ISelection selection) { if (selection.isEmpty() || false == selection instanceof StructuredSelection) { super.setInput(part, selection); return;//from ww w. ja v a2 s. c o m } final StructuredSelection structuredSelection = (StructuredSelection) Selections .unwrap((StructuredSelection) selection); inputIsWrapper = structuredSelection != selection; ArrayList<Object> transformedSelection = new ArrayList<Object>(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.mylyn.internal.cdt.ui.CDTEditorMonitor.java
License:Open Source License
/** * Only public for testing/*ww w. ja va 2s . c o m*/ */ @Override public void handleWorkbenchPartSelection(IWorkbenchPart part, ISelection selection, boolean contributeToContext) { try { ICElement selectedElement = null; if (selection instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) selection; if (structuredSelection.equals(currentSelection)) { return; } currentSelection = structuredSelection; // Object selectedObject = // structuredSelection.getFirstElement(); for (Iterator<?> iterator = structuredSelection.iterator(); iterator.hasNext();) { Object selectedObject = iterator.next(); if (selectedObject instanceof ICElement) { ICElement checkedElement = checkIfAcceptedAndPromoteIfNecessary((ICElement) selectedObject); if (checkedElement == null) { return; } else { selectedElement = checkedElement; } } if (selectedElement != null) { super.handleElementSelection(part, selectedElement, contributeToContext); } } } else { if (part instanceof CEditor) { currentEditor = (CEditor) part; selectedElement = SelectionConverter.getElementAtOffset(currentEditor); if (selectedElement == null) { return; // nothing selected } if (selectedElement != null) { if (selectedElement.equals(lastSelectedElement)) { super.handleElementEdit(part, selectedElement, contributeToContext); } else if (!selectedElement.equals(lastSelectedElement)) { super.handleElementSelection(part, selectedElement, contributeToContext); } } ICElement checkedElement = checkIfAcceptedAndPromoteIfNecessary(selectedElement); if (checkedElement == null) { return; } else { selectedElement = checkedElement; } } } if (selectedElement != null) { lastSelectedElement = selectedElement; } } catch (CModelException e) { // ignore, fine to fail to resolve an element if the model is not // up-to-date } }
From source file:org.eclipse.mylyn.internal.java.ui.JavaEditingMonitor.java
License:Open Source License
/** * Only public for testing. Note: Two sequential selections on the same element are deemed to be an edit of the * selection as this is the best guess that can be made. See bug 252306. *//* www . j ava 2 s .co m*/ @Override public void handleWorkbenchPartSelection(IWorkbenchPart part, ISelection selection, boolean contributeToContext) { try { IJavaElement selectedElement = null; if (selection instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) selection; if (structuredSelection.equals(currentSelection)) { return; } currentSelection = structuredSelection; for (Iterator<?> iterator = structuredSelection.iterator(); iterator.hasNext();) { Object selectedObject = iterator.next(); if (selectedObject instanceof IJavaElement) { IJavaElement checkedElement = checkIfAcceptedAndPromoteIfNecessary( (IJavaElement) selectedObject); if (checkedElement == null) { return; } else { selectedElement = checkedElement; } } if (selectedElement != null) { super.handleElementSelection(part, selectedElement, contributeToContext); } } } else { if (selection instanceof TextSelection && part instanceof JavaEditor) { currentEditor = (JavaEditor) part; TextSelection textSelection = (TextSelection) selection; selectedElement = SelectionConverter.resolveEnclosingElement(currentEditor, textSelection); if (selectedElement instanceof IPackageDeclaration) { // HACK: ignoring these selections return; } IJavaElement[] resolved = SelectionConverter.codeResolve(currentEditor); if (resolved != null && resolved.length == 1 && !resolved[0].equals(selectedElement)) { lastResolvedElement = resolved[0]; } boolean selectionResolved = false; if (selectedElement instanceof IMethod && lastSelectedElement instanceof IMethod) { // navigation between two elements if (lastResolvedElement != null && lastSelectedElement != null && lastResolvedElement.equals(selectedElement) && !lastSelectedElement.equals(lastResolvedElement)) { super.handleNavigation(part, selectedElement, JavaReferencesProvider.ID, contributeToContext); selectionResolved = true; } else if (lastSelectedElement != null && lastSelectedElement.equals(lastResolvedElement) && !lastSelectedElement.equals(selectedElement)) { super.handleNavigation(part, selectedElement, JavaReferencesProvider.ID, contributeToContext); selectionResolved = true; } } else if (selectedElement != null && lastSelectedElement != null && !lastSelectedElement.equals(selectedElement)) { if (lastSelectedElement.getElementName().equals(selectedElement.getElementName())) { // navigation between two elements if (selectedElement instanceof IMethod && lastSelectedElement instanceof IMethod) { super.handleNavigation(part, selectedElement, JavaImplementorsProvider.ID, contributeToContext); selectionResolved = true; } else if (selectedElement instanceof IType && lastSelectedElement instanceof IType) { super.handleNavigation(part, selectedElement, JavaImplementorsProvider.ID, contributeToContext); selectionResolved = true; } } } if (selectedElement != null) { // selection of an element if (!selectionResolved && selectedElement.equals(lastSelectedElement)) { super.handleElementEdit(part, selectedElement, contributeToContext); } else if (!selectedElement.equals(lastSelectedElement)) { super.handleElementSelection(part, selectedElement, contributeToContext); } } IJavaElement checkedElement = checkIfAcceptedAndPromoteIfNecessary(selectedElement); if (checkedElement == null) { return; } else { selectedElement = checkedElement; } } } if (selectedElement != null) { lastSelectedElement = selectedElement; } } catch (JavaModelException e) { // ignore, fine to fail to resolve an element if the model is not up-to-date } catch (Throwable t) { StatusHandler.log(new Status(IStatus.ERROR, JavaUiBridgePlugin.ID_PLUGIN, "Failed to update model based on selection", t)); //$NON-NLS-1$ } }
From source file:org.eclipse.mylyn.internal.resources.ui.ResourceInteractionMonitor.java
License:Open Source License
@Override protected void handleWorkbenchPartSelection(IWorkbenchPart part, ISelection selection, boolean contributeToContext) { // ignore events from the synchronize view to avoid files jumping between change sets when selected if (ID_SYNCHRONIZE_VIEW.equals(part.getSite().getId())) { return;/* www . j av a 2s . c om*/ } if (selection instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) selection; // Object selectedObject = structuredSelection.getFirstElement(); for (Iterator<?> iterator = structuredSelection.iterator(); iterator.hasNext();) { Object selectedObject = iterator.next(); IResource resource; if (selectedObject instanceof IResource) { resource = (IResource) selectedObject; super.handleElementSelection(part, resource, contributeToContext); } } } else if (selection instanceof TextSelection) { if (part instanceof EditorPart) { try { Object object = ((EditorPart) part).getEditorInput().getAdapter(IResource.class); if (object instanceof IFile) { IFile file = (IFile) object; if (file.getFileExtension() != null && !ContextCore.getContentTypes().contains(file.getFileExtension())) { super.handleElementEdit(part, object, contributeToContext); } } } catch (Throwable t) { StatusHandler.log(new Status(IStatus.ERROR, ResourcesUiBridgePlugin.ID_PLUGIN, "Failed to resolve resource edit", t)); //$NON-NLS-1$ } } } }
From source file:org.eclipse.mylyn.internal.tasks.ui.search.RepositorySearchResultView.java
License:Open Source License
private void moveToCategory(AbstractTaskCategory category) { StructuredSelection selection = (StructuredSelection) this.getViewer().getSelection(); for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) { Object selectedObject = iterator.next(); if (selectedObject instanceof ITask) { ITask task = (ITask) selectedObject; TasksUiInternal.getTaskList().addTask(task, category); }/*w w w. j a v a2 s . c o m*/ } }