List of usage examples for org.eclipse.jface.viewers IStructuredSelection iterator
@Override
public Iterator iterator();
From source file:com.rcpcompany.uibindings.utils.SelectionUtils.java
License:Open Source License
/** * Computes and returns a list with the objects of the selection that are - or can adapt to - * the specified base class.// w w w. ja va2 s.c o m * * @param <T> the type of the baseClass * @param selection the selection to handle * @param baseClass the wanted base class * @return a list with the found objects */ public static <T> List<T> computeSelection(ISelection selection, Class<T> baseClass) { if (!(selection instanceof IStructuredSelection)) return EMPTY_LIST; final IStructuredSelection ss = (IStructuredSelection) selection; List<T> list = null; for (final Iterator e = ss.iterator(); e.hasNext();) { final Object next = e.next(); T c = (T) Platform.getAdapterManager().getAdapter(next, baseClass); if (c != null) { // OK } else if (baseClass.isInstance(next)) { c = (T) next; } else if (next instanceof IAdaptable) { c = (T) ((IAdaptable) next).getAdapter(baseClass); } if (c != null) { if (list == null) { list = new ArrayList<T>(ss.size()); } list.add(c); } } if (list == null) return EMPTY_LIST; return list; }
From source file:com.rcpcompany.utils.selection.SelectionUtils.java
License:Open Source License
/** * Computes and returns a list with the objects of the selection that are - * or can adapt to - the specified base class. * /*w w w. j a va2 s . c o m*/ * @param <T> * the type of the baseClass * @param selection * the selection to handle * @param baseClass * the wanted base class * @return a list with the found objects */ @SuppressWarnings("unchecked") public static <T> List<T> computeSelection(ISelection selection, Class<T> baseClass) { if (!(selection instanceof IStructuredSelection)) return Collections.EMPTY_LIST; final IStructuredSelection ss = (IStructuredSelection) selection; List<T> list = null; for (final Iterator<?> e = ss.iterator(); e.hasNext();) { final Object next = e.next(); T c = (T) Platform.getAdapterManager().getAdapter(next, baseClass); if (c != null) { // OK } else if (baseClass.isInstance(next)) { c = (T) next; } else if (next instanceof IAdaptable) { c = (T) ((IAdaptable) next).getAdapter(baseClass); } if (c != null) { if (list == null) { list = new ArrayList<T>(ss.size()); } list.add(c); } } if (list == null) return Collections.EMPTY_LIST; return list; }
From source file:com.redhat.ceylon.eclipse.core.classpath.CeylonClasspathUtil.java
License:Apache License
/** * Get the Ivy classpath container from the selection in the Java package view * /*from www . j a v a 2 s . c o m*/ * @param selection * the selection * @return * @throws JavaModelException */ public static CeylonClasspathContainer getCeylonClasspathContainer(IStructuredSelection selection) { if (selection == null) { return null; } for (Iterator it = selection.iterator(); it.hasNext();) { Object element = it.next(); CeylonClasspathContainer cp = (CeylonClasspathContainer) CeylonPlugin.adapt(element, CeylonClasspathContainer.class); if (cp != null) { return cp; } if (element instanceof ClassPathContainer) { // FIXME: we shouldn't check against internal JDT API but there are not adaptable to // useful class return jdt2CeylonCPC((ClassPathContainer) element); } } return null; }
From source file:com.remainsoftware.tycho.pombuilder.ui.internal.actions.DisableNatureAction.java
License:Open Source License
@Override public void run(IAction action) { if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; for (Iterator<?> it = structuredSelection.iterator(); it.hasNext();) { Object element = it.next(); IProject project = null;//from w w w . j a va 2 s . co m if (element instanceof IProject) { project = (IProject) element; } else if (element instanceof IAdaptable) { project = (IProject) ((IAdaptable) element).getAdapter(IProject.class); } if (project != null) { try { disableNature(project); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } }
From source file:com.remainsoftware.tycho.pombuilder.ui.internal.actions.EnableNatureAction.java
License:Open Source License
@Override public void run(IAction action) { if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; for (Iterator<?> it = structuredSelection.iterator(); it.hasNext();) { Object element = it.next(); IProject project = null;//from w w w .j a v a 2s. com if (element instanceof IProject) { project = (IProject) element; } else if (element instanceof IAdaptable) { project = (IProject) ((IAdaptable) element).getAdapter(IProject.class); } if (project != null) { try { enableNature(project, structuredSelection.size() == 1); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } }
From source file:com.safi.workshop.sqlexplorer.dbstructure.DBTreeActionGroup.java
License:Open Source License
private INode[] getSelectedNodes() { // find our target node.. IStructuredSelection selection = (IStructuredSelection) _treeViewer.getSelection(); // check if we have a valid selection if (selection == null) { return null; }/*w ww .j a va 2 s .co m*/ List<INode> selectedNodes = new ArrayList<INode>(); Iterator<?> it = selection.iterator(); while (it.hasNext()) { Object object = it.next(); if (object instanceof INode) { selectedNodes.add((INode) object); } } if (selectedNodes.size() == 0) { return null; } INode[] nodes = selectedNodes.toArray(new INode[selectedNodes.size()]); return nodes; }
From source file:com.salesforce.ide.ui.handlers.BaseHandler.java
License:Open Source License
protected static List<IResource> getSelectedResources(final IStructuredSelection selection) { final IAdapterManager adapterManager = Platform.getAdapterManager(); final List<IResource> selectedResources = new ArrayList<>(); for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) { final IResource selectedResource = (IResource) adapterManager.getAdapter(iterator.next(), IResource.class); if (null != selectedResource) { selectedResources.add(selectedResource); }/*from w ww . jav a2s. c o m*/ } return selectedResources; }
From source file:com.salesforce.ide.ui.handlers.SaveToServerHandler.java
License:Open Source License
private static SaveToServerActionController buildController(final IStructuredSelection selection) { final IAdapterManager adapterManager = Platform.getAdapterManager(); final List<IResource> selectedResources = new ArrayList<>(); for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) { final IResource selectedResource = (IResource) adapterManager.getAdapter(iterator.next(), IResource.class); if (null != selectedResource) { selectedResources.add(selectedResource); }// w ww.j a va 2s.com } final List<IResource> filteredResources = filter(selectedResources); if (filteredResources.isEmpty()) return null; final IProject project = filteredResources.get(0).getProject(); for (final IResource resource : filteredResources) { if (!project.equals(resource.getProject())) { logger.warn( "Unable to save resources from multiple projects at the same time. Only saving resources from " + project.getName()); break; } } return buildController(selection, filteredResources, project); }
From source file:com.sap.dirigible.ide.db.viewer.views.actions.DeleteTableAction.java
License:Open Source License
@SuppressWarnings("rawtypes") public void run() { IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); TreeParent parent = null;/*from w w w . j ava 2 s. c o m*/ for (Iterator nextSelection = selection.iterator(); nextSelection.hasNext();) { Object obj = nextSelection.next(); if (TreeObject.class.isInstance(obj)) { if (((TreeObject) obj).getTableDefinition() != null) { TableDefinition tableDefinition = ((TreeObject) obj).getTableDefinition(); boolean confirm = MessageDialog.openConfirm(viewer.getControl().getShell(), DELETE_TABLE, String.format(WARNING_THIS_ACTION_WILL_DELETE_THE_TABLE_AND_ALL_OF_ITS_CONTENT_CONTINUE, tableDefinition.getTableName())); if (!confirm) { continue; } parent = ((TreeObject) obj).getParent(); IDbConnectionFactory connectionFactory = parent.getConnectionFactory(); try { deleteTable(tableDefinition, connectionFactory); } catch (SQLException e) { showMessage(String.format(FAILED_TO_DELETE_TABLE_S, tableDefinition.getTableName())); logger.error(e.getMessage(), e); } } } } if (parent != null) { RefreshViewAction refresh = new RefreshViewAction(viewer, parent.getChildren()[0]); refresh.run(); } }
From source file:com.sap.dirigible.ide.workspace.wizard.project.commands.DownloadProjectHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event); if (selection.size() == 1) { Object firstElement = selection.getFirstElement(); if (firstElement instanceof IProject) { IProject project = (IProject) firstElement; DownloadDialog downloadDialog = new DownloadDialog(HandlerUtil.getActiveShell(event)); downloadDialog.setURL(DownloadProjectServiceHandler.getUrl(project.getName())); downloadDialog.open();//ww w . j a va 2s. c o m } } else if (selection.size() > 1) { StringBuffer projectNames = new StringBuffer(); Iterator<?> iterator = selection.iterator(); boolean dot = false; while (iterator.hasNext()) { Object element = iterator.next(); if (element instanceof IProject) { IProject project = (IProject) element; if (dot) { projectNames.append(RepositoryDataStore.PROJECT_NAME_SEPARATOR); } projectNames.append(project.getName()); dot = true; } } DownloadDialog downloadDialog = new DownloadDialog(HandlerUtil.getActiveShell(event)); downloadDialog.setURL(DownloadProjectServiceHandler.getUrl(projectNames.toString())); downloadDialog.open(); } return null; }