List of usage examples for org.eclipse.jface.viewers IStructuredSelection size
public int size();
From source file:com.github.jknack.antlr4ide.ui.railroad.actions.RailroadSelectionLinker.java
License:Open Source License
public void diagramSelectionChanged(final SelectionChangedEvent event) { ISelection selection = event.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; if (structuredSelection.size() == 1) { Object selectedElement = structuredSelection.getFirstElement(); if (selectedElement instanceof IFigure) { IFigure selectedFigure = (IFigure) selectedElement; selectFigure(selectedFigure); boolean isDoubleClick = event instanceof RailroadSelectionProvider.DoubleClickEvent; if ((currentEditor == null || !currentEditor.getInternalSourceViewer().getTextWidget().isFocusControl()) && (isDoubleClick || preferences.isLinkWithEditor())) { selectGrammarText(selectedFigure, isDoubleClick); }/*from www.ja va2 s. co m*/ } } } }
From source file:com.github.sdbg.debug.ui.internal.util.SelectionUtil.java
License:Open Source License
/** * Returns the selected element if the selection consists of a single element only. * //from w w w .j a va 2s . c om * @param s the selection * @return the selected first element or null */ public static Object getSingleElement(ISelection s) { if (!(s instanceof IStructuredSelection)) { return null; } IStructuredSelection selection = (IStructuredSelection) s; if (selection.size() != 1) { return null; } return selection.getFirstElement(); }
From source file:com.github.sdbg.debug.ui.internal.view.RemoveBreakpointAction.java
License:Open Source License
@Override public void selectionChanged(IStructuredSelection sel) { if (sel.size() == 1) { breakpoint = (IBreakpoint) DebugPlugin.getAdapter(sel.getFirstElement(), IBreakpoint.class); } else {//w w w . j a v a 2 s .com breakpoint = null; } setEnabled(breakpoint != null); }
From source file:com.google.cloud.tools.eclipse.appengine.deploy.ui.standard.StandardDeployCommandHandlerTest.java
License:Apache License
private ExecutionEvent getTestExecutionEvent(Object project) { IEvaluationContext context = mock(IEvaluationContext.class); IStructuredSelection selection = mock(IStructuredSelection.class); when(selection.size()).thenReturn(1); when(selection.getFirstElement()).thenReturn(project); when(context.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME)).thenReturn(selection); when(context.getVariable(ISources.ACTIVE_SHELL_NAME)).thenReturn(mock(Shell.class)); return new ExecutionEvent(null /*command */, Collections.EMPTY_MAP, null /* trigger */, context); }
From source file:com.google.cloud.tools.eclipse.appengine.deploy.ui.StandardDeployPreferencesPanelTest.java
License:Apache License
@Test public void testProjectSavedInPreferencesSelected() throws ProjectRepositoryException { IEclipsePreferences node = new ProjectScope(project) .getNode(StandardDeployPreferences.PREFERENCE_STORE_QUALIFIER); node.put("project.id", "projectId1"); node.put("account.email", EMAIL_1); initializeProjectRepository(projectRepository); when(loginService.getAccounts()).thenReturn(new HashSet<>(Arrays.asList(account1, account2))); StandardDeployPreferencesPanel deployPanel = new StandardDeployPreferencesPanel(parent, project, loginService, layoutChangedHandler, true, projectRepository); for (Control control : deployPanel.getChildren()) { if (control instanceof ProjectSelector) { ProjectSelector projectSelector = (ProjectSelector) control; IStructuredSelection selection = projectSelector.getViewer().getStructuredSelection(); assertThat(selection.size(), is(1)); assertThat(((GcpProject) selection.getFirstElement()).getId(), is("projectId1")); return; }//from www. ja va 2s. c o m } ; fail("Did not find ProjectSelector widget"); }
From source file:com.google.cloud.tools.eclipse.projectselector.ProjectSelectorTest.java
License:Apache License
@Test public void testSetProjectMaintainsSelection() { List<GcpProject> projects = getUnsortedProjectList(); GcpProject selectedProject = projects.get(3); ProjectSelector projectSelector = new ProjectSelector(shellResource.getShell()); projectSelector.setProjects(projects); projectSelector.getViewer().setSelection(new StructuredSelection(selectedProject)); projectSelector.setProjects(projects.subList(2, projects.size())); IStructuredSelection selection = projectSelector.getViewer().getStructuredSelection(); assertThat(selection.size(), is(1)); assertThat((GcpProject) selection.getFirstElement(), is(selectedProject)); }
From source file:com.google.cloud.tools.eclipse.ui.util.ProjectFromSelectionHelper.java
License:Apache License
public IProject getProject(ExecutionEvent event) throws CoreException, ExecutionException { ISelection selection = HandlerUtil.getCurrentSelectionChecked(event); if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; if (structuredSelection.size() == 1) { IProject project = AdapterUtil.adapt(structuredSelection.getFirstElement(), IProject.class); if (project == null) { return null; }/* w ww. ja va2 s . c om*/ IFacetedProject facetedProject = facetedProjectHelper.getFacetedProject(project); if (AppEngineStandardFacet.hasAppEngineFacet(facetedProject)) { return project; } } } return null; }
From source file:com.google.code.t4eclipse.tools.utility.SelectionUtility.java
License:Open Source License
public static String getSelectionInfo(IWorkbenchPart part) { String s = "\n\n"; ISelectionProvider provider = part.getSite().getSelectionProvider(); if (provider == null) { s += "NO Selection Provider in this active part:\n"; return s; }/* w w w .j a v a2 s. c o m*/ s += "Selection Provider:\n"; s += provider.getClass().getName() + "\n\n"; ISelection sel = provider.getSelection(); if (sel == null) { s += "Selection is null\n"; return s; } s += "Selection:\n"; s += "class:" + sel.getClass().getName() + "\n"; if (sel instanceof IStructuredSelection) { IStructuredSelection ssel = (IStructuredSelection) sel; s += "\n"; s += "instanceof IStructuredSelection\n"; s += "--first element--:\n"; Object firstElement = ssel.getFirstElement(); if (firstElement == null) { s += " null\n"; } else { s += " class:\n " + firstElement.getClass().getName() + "\n"; s += " tostr:\n"; s += " " + firstElement.toString() + "\n"; } s += " size:" + ssel.size() + "\n"; if (ssel.size() > 1) s += " all elements class:\n"; Object[] eles = ssel.toArray(); for (int i = 0; i < eles.length; i++) { s += " [" + i + "]:" + eles[i].getClass().getName() + "\n"; } } s += "\n\nselection toString():\n"; s += sel.toString() + "\n"; return s; }
From source file:com.google.dart.tools.internal.corext.refactoring.RefactoringAvailabilityTester.java
License:Open Source License
public static boolean isConvertMethodToGetterAvailable(IStructuredSelection selection) throws DartModelException { if (selection.isEmpty() || selection.size() != 1) { return false; }//from ww w . j a va2 s . c om Object first = selection.getFirstElement(); return first instanceof Method && isConvertMethodToGetterAvailable((Method) first); }
From source file:com.google.dart.tools.internal.corext.refactoring.RefactoringAvailabilityTester.java
License:Open Source License
public static boolean isInlineMethodAvailable(IStructuredSelection selection) throws DartModelException { if (selection.isEmpty() || selection.size() != 1) { return false; }/* ww w . j ava2 s. c om*/ Object first = selection.getFirstElement(); return first instanceof Method && isInlineMethodAvailable((Method) first); }