List of usage examples for org.eclipse.jface.viewers IStructuredSelection iterator
@Override
public Iterator iterator();
From source file:company.ui.properties.CompanyLabelProvider.java
License:Open Source License
/** * Determine there are objects in the structured selection of different * types./* w ww.j a v a2 s . c o m*/ * * @param structuredSelection * the structured selection. * @return true if there are objects of different types in the selection. */ private boolean areDifferentTypes(IStructuredSelection structuredSelection) { if (structuredSelection.size() == 1) { return false; } Iterator i = structuredSelection.iterator(); Object element = i.next(); for (; i.hasNext();) { if (i.next().getClass() != element.getClass()) { return true; } } return false; }
From source file:de.anbos.eclipse.easyshell.plugin.preferences.CommandPage.java
License:Open Source License
private void createTableViewer(Composite parent) { tableViewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); createColumns(parent, tableViewer);/*from www. j ava2 s.c o m*/ final Table table = tableViewer.getTable(); table.setHeaderVisible(true); table.setLinesVisible(true); tableViewer.setLabelProvider(new CommandDataLabelProvider()); tableViewer.setContentProvider(new CommandDataContentProvider()); if (filter != null) { tableViewer.addFilter(filter); } // Get the content for the viewer, setInput will call getElements in the // contentProvider tableViewer.setInput(CommandDataStore.instance()); // Layout the viewer GridData gridData = new GridData(); gridData.verticalAlignment = GridData.FILL; gridData.horizontalSpan = 2; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; gridData.horizontalAlignment = GridData.FILL; tableViewer.getControl().setLayoutData(gridData); tableViewer.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { editDialog(); } }); tableViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection(); int selected = selection.size(); boolean presetSelectedOrNotEqualType = false; Iterator<?> elements = selection.iterator(); PresetType type = PresetType.presetUnknown; while (elements.hasNext()) { CommandData data = (CommandData) elements.next(); if (type == PresetType.presetUnknown) { type = data.getPresetType(); } if (data.getPresetType() == PresetType.presetPlugin || type != data.getPresetType()) { presetSelectedOrNotEqualType = true; break; } } editButton.setEnabled(selected == 1); addCopyButton.setEnabled(selected == 1); removeButton.setEnabled(selected > 0 && !presetSelectedOrNotEqualType); } }); tableViewer.setComparator(new ViewerComparator() { @Override public int compare(Viewer viewer, Object object1, Object object2) { if (!(object1 instanceof CommandData) || !(object2 instanceof CommandData)) { return super.compare(viewer, object1, object2); } CommandData data1 = (CommandData) object1; CommandData data2 = (CommandData) object2; if (data1.getPosition() > data2.getPosition()) { return 1; } if (data1.getPosition() < data2.getPosition()) { return -1; } if (data1.getPosition() == data2.getPosition()) { return 0; } return super.compare(viewer, object1, object2); } @Override public boolean isSorterProperty(Object element, String property) { return true; } }); }
From source file:de.anbos.eclipse.easyshell.plugin.preferences.CommandPage.java
License:Open Source License
private void removeDialog() { // get the selected commands and referenced menus as lists List<CommandData> commands = new ArrayList<CommandData>(); List<MenuData> menus = new ArrayList<MenuData>(); IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection(); Iterator<?> elements = selection.iterator(); while (elements.hasNext()) { CommandData data = (CommandData) elements.next(); commands.add(data);//from ww w . jav a2s. c o m List<MenuData> menusForOne = MenuDataStore.instance().getRefencedBy(data.getId()); menus.addAll(menusForOne); } // ask user String commandNames = ""; PresetType type = PresetType.presetUnknown; for (CommandData command : commands) { if (type == PresetType.presetUnknown) { type = command.getPresetType(); } commandNames += command.getCommandAsComboName() + "\n"; } String title = null; String question = null; if (type == PresetType.presetPluginAndUser) { title = Activator.getResourceString("easyshell.command.page.dialog.remove.user.title"); question = MessageFormat.format( Activator.getResourceString("easyshell.command.page.dialog.remove.user.question"), commandNames); } else { title = Activator.getResourceString("easyshell.command.page.dialog.remove.title"); question = MessageFormat.format( Activator.getResourceString("easyshell.command.page.dialog.remove.question"), commandNames); } int dialogImageType = MessageDialog.QUESTION; if (menus.size() > 0) { dialogImageType = MessageDialog.WARNING; String menuNames = ""; for (MenuData menu : menus) { menuNames += menu.getNameExpanded() + "\n"; } if (type == PresetType.presetPluginAndUser) { title = Activator.getResourceString("easyshell.command.page.dialog.remove.menu.user.title"); question = MessageFormat.format( Activator.getResourceString("easyshell.command.page.dialog.remove.menu.user.question"), commandNames, menuNames); } else { title = Activator.getResourceString("easyshell.command.page.dialog.remove.menu.title"); question = MessageFormat.format( Activator.getResourceString("easyshell.command.page.dialog.remove.menu.question"), commandNames, menuNames); } } MessageDialog dialog = new MessageDialog(null, title, null, question, dialogImageType, new String[] { "Yes", "No" }, 1); // no is the default int result = dialog.open(); if (result == 0) { if (menus.size() >= 0 && type == PresetType.presetUser) { for (MenuData menu : menus) { MenuDataStore.instance().delete(menu); } //MenuDataStore.instance().save(); } for (CommandData command : commands) { if (command.getPresetType() == PresetType.presetUser) { CommandDataStore.instance().delete(command); } else if (command.getPresetType() == PresetType.presetPluginAndUser) { command.removeUserData(); CommandDataStore.instance().replace(command); } } tableViewer.refresh(); } }
From source file:de.anbos.eclipse.easyshell.plugin.preferences.MenuPage.java
License:Open Source License
private void removeDialog() { // get the selected menus as lists List<MenuData> menus = new ArrayList<MenuData>(); IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection(); Iterator<?> elements = selection.iterator(); while (elements.hasNext()) { MenuData data = (MenuData) elements.next(); menus.add(data);/*from w w w .j a v a 2 s. com*/ } if (menus.size() > 0) { String title = Activator.getResourceString("easyshell.menu.page.dialog.remove.title"); String menuNames = ""; for (MenuData menu : menus) { menuNames += menu.getNameExpanded() + "\n"; } String question = MessageFormat .format(Activator.getResourceString("easyshell.menu.page.dialog.remove.question"), menuNames); MessageDialog dialog = new MessageDialog(null, title, null, question, MessageDialog.QUESTION, new String[] { "Yes", "No" }, 1); // no is the default int result = dialog.open(); if (result == 0) { for (MenuData menu : menus) { MenuDataStore.instance().delete(menu); } refreshTableViewer(); } } }
From source file:de.anbos.eclipse.logviewer.plugin.preferences.rule.RulePreferencePage.java
License:Apache License
private void remove() { IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection(); Iterator<?> elements = selection.iterator(); while (elements.hasNext()) { RulePreferenceData data = (RulePreferenceData) elements.next(); store.delete(data);//from ww w .ja va2s . c o m } tableViewer.refresh(); }
From source file:de.bitexpert.eclipse.svn.svnexport.ui.wizards.SubversionExportWizardPage.java
License:Apache License
/** * Creates a new {@link SubversionExportWizardPage}. * * @param IStructuredSelection/*from w ww. j a v a 2 s .c o m*/ */ public SubversionExportWizardPage(IStructuredSelection selection) { super("SVN Export by Revision", selection); this.setTitle("SVN Export by Revision"); this.setDescription("Exports files based on their Revision numbers"); @SuppressWarnings("rawtypes") Iterator selections = selection.iterator(); while (selections.hasNext()) { IResource oCurResource = (IResource) selections.next(); if (IResource.PROJECT == oCurResource.getType()) { this.selectedProject = oCurResource; } } this.maxRevisionNumber = Long.parseLong(getMaxRevNumber()); }
From source file:de.bodden.tamiflex.action.Compare.java
License:Open Source License
@Override public void selectionChanged(IAction action, ISelection selection) { IStructuredSelection sl = (IStructuredSelection) selection; if (sl.size() == 2) { Iterator<?> iter = sl.iterator(); left = (IFile) iter.next();// ww w . j a v a 2 s . c om right = (IFile) iter.next(); } }
From source file:de.cau.cs.kieler.ecoreviz.OpenDiagramHandler.java
License:Open Source License
/** * {@inheritDoc}// ww w . j a v a2 s.c o m */ @SuppressWarnings("unchecked") public Object execute(final ExecutionEvent event) throws ExecutionException { final ISelection selection = HandlerUtil.getCurrentSelection(event); if (selection instanceof IStructuredSelection) { final IStructuredSelection sSelection = (IStructuredSelection) selection; final List<EModelElement> listSelection = new LinkedList<EModelElement>(); if (selection instanceof KlighdTreeSelection) { // do not react on selections in KLighD diagrams return null; } // if all elements are either ecore packages or classes if (Iterators.all(sSelection.iterator(), EPACKAGE_ECLASS_PREDICATE)) { Iterator<EModelElement> emIt = Iterators.filter(sSelection.iterator(), EMODEL_ELEMENT_PREDICATE); while (emIt.hasNext()) { listSelection.add(emIt.next()); } } else { // otherwise check the elements piece by piece for files for (Object o : sSelection.toArray()) { if (o instanceof IFile) { try { IFile f = (IFile) o; ResourceSet rs = new ResourceSetImpl(); Resource r = rs.getResource( URI.createPlatformResourceURI(f.getFullPath().toString(), true), true); if (r.getContents().size() > 0) { if (r.getContents().get(0) instanceof EPackage) { listSelection.add((EModelElement) r.getContents().get(0)); } } } catch (Exception e) { StatusManager.getManager().handle( new Status(IStatus.ERROR, PLUGIN_ID, "Could not load selected file.", e), StatusManager.SHOW); } } else { handleUnknownSelection(selection); return null; } } } EModelElementCollection model = EModelElementCollection.of(listSelection.iterator()); DiagramViewManager.createView("de.cau.cs.kieler.ecoreviz.EModelElementCollectionDiagram", "Ecore Diagram", model, KlighdSynthesisProperties.create()); return null; } handleUnknownSelection(selection); return null; }
From source file:de.cau.cs.kieler.klassviz.handlers.SynthesizeClassDiagramHandler.java
License:Open Source License
/** * Initiates the class diagram synthesis. Therefore a selection of classes, fields and methods, * that is made via the package or project explorer is transferred to a metamodel. After that is * done the selection is saved in the metadata of the plug-in. Then it starts a diagram synthesis * in Xtend.//from www .j a v a 2 s . c o m */ public Object execute(ExecutionEvent event) throws ExecutionException { // Get the Selection ISelection selection = HandlerUtil.getCurrentSelection(event); IStructuredSelection sSelection = (IStructuredSelection) selection; // Transform the model JdtModelTransformation transformation = Guice.createInjector().getInstance(JdtModelTransformation.class); KClassModel classModel; try { classModel = transformation.transform(sSelection); } catch (JavaModelException exception) { IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, "Error while transforming Java model.", exception); StatusManager.getManager().handle(status, StatusManager.SHOW); return null; } // When the List is still empty, there was no IJavaElement in the // Selection and nothing can be visualized. if (!classModel.getPackages().isEmpty()) { // Save the selection that will be visualized. HashSet<IJavaProject> projects = new HashSet<IJavaProject>(); Iterator<?> selectionIter = sSelection.iterator(); while (selectionIter.hasNext()) { Object obj = selectionIter.next(); if (obj instanceof IJavaElement) { projects.add(((IJavaElement) obj).getJavaProject()); } } for (IJavaProject project : projects) { classModel.getJavaProjects().add(project.getElementName()); } saveSelection(classModel, projects); // Start synthesis with Xtend and visualize with KlighD. String viewTitle = projects.iterator().next().getElementName(); DiagramViewManager.createView("de.cau.cs.kieler.klassviz.ClassDataDiagramSynthesis", viewTitle, classModel, null); } return null; }
From source file:de.fkoeberle.autocommit.SelectionSearchUtil.java
License:Open Source License
public static LinkedHashSet<IProject> searchProjectsIn(ISelection selection) { LinkedHashSet<IProject> projects = new LinkedHashSet<IProject>(); if (!(selection instanceof IStructuredSelection)) { return projects; }/*w ww . ja v a 2 s .co m*/ IStructuredSelection structuredSelection = (IStructuredSelection) selection; Iterator<?> iterator = structuredSelection.iterator(); while (iterator.hasNext()) { Object o = iterator.next(); IProject project = null; if (o instanceof IProject) { project = (IProject) o; } else if (o instanceof IAdaptable) { IAdaptable adaptable = (IAdaptable) o; project = (IProject) adaptable.getAdapter(IProject.class); } if (project != null) { projects.add(project); } } return projects; }