List of usage examples for org.eclipse.jface.viewers IStructuredSelection toList
public List toList();
List
. From source file:com.iw.plugins.spindle.wizards.migrate.MigrationWizard.java
License:Mozilla Public License
private void setContext() { context.reset();/*from www . j a va2 s . c om*/ IStructuredSelection scope = (IStructuredSelection) scopePage.getSelection(); List scopeList = new ArrayList(scope.toList()); scopeList.add(context.getContextModel().getUnderlyingStorage()); context.setScope(scopeList); IStructuredSelection constraints = (IStructuredSelection) actionPage.getSelection(); List chosenContraints = constraints.toList(); boolean migratingPages = chosenContraints.contains(new Integer(context.MIGRATE_UPGRADE_PAGES)); context.setConstraints(constraints.toArray()); boolean scopeContainsUndefined = definePage.setUndefined(collectUndefined()); if (migratingPages && scopeContainsUndefined) { canFinish = false; actionPage.setShowUndefinedPage(true); } else { canFinish = true; actionPage.setShowUndefinedPage(false); } context.constructMigrators(); }
From source file:com.kdmanalytics.toif.report.internal.handlers.ExportSelectionHandler.java
License:Open Source License
/** * write the findings to the csv file.//from ww w . ja v a 2 s .c om * * @param selection * the selected element from the report * @param writer * the file writer to use to output * @throws IOException */ private void writeFindings(IStructuredSelection selection, FileWriter writer) throws IOException { Set<FindingEntry> entries = new HashSet<FindingEntry>(); for (Object object : selection.toList()) { if (object instanceof IToifReportEntry) { IToifReportEntry reportItem = (IToifReportEntry) object; entries.add(reportItem.getFindingEntry()); } } for (FindingEntry entry : entries) { ToolGroup tool = (ToolGroup) entry.getParent(); LocationGroup location = (LocationGroup) tool.getParent(); // sfp writer.append(entry.getSfp()); writer.append('\t'); // cwe writer.append(entry.getCwe()); writer.append('\t'); String valid = ""; // valid if (Citing.UNKNOWN == entry.isOk()) { valid = "unknown"; } else { valid = "" + (Citing.TRUE == entry.isOk()); } writer.append(valid.toUpperCase()); writer.append('\t'); // trust writer.append(entry.getTrust() + ""); writer.append('\t'); // resource writer.append(location.getPath()); writer.append('\t'); // linenumber writer.append(location.getToifLineNumber()); writer.append('\t'); // kdmLineNumber if (location.getRealLineNumber() != null) { writer.append(location.getRealLineNumber()); } else { writer.append(""); } writer.append('\t'); // tool writer.append(tool.toString()); writer.append('\t'); // description writer.append(entry.getDescription()); writer.append('\n'); } }
From source file:com.kdmanalytics.toif.report.internal.handlers.SetTrustHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { final IStructuredSelection ss = (IStructuredSelection) HandlerUtil.getCurrentSelection(event); final ReportView view = (ReportView) HandlerUtil.getActivePart(event); final Shell shell = HandlerUtil.getActiveShell(event); final Integer value = getNewTrustValue(shell); IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) { if (value != null) { List<FindingEntry> entries = new ArrayList<FindingEntry>(ss.size()); for (Object o : ss.toList()) { if (o instanceof ToifReportEntry) { IToifReportEntry toifReportEntry = (IToifReportEntry) o; if (toifReportEntry.getFindingEntry() != null) { entries.add(toifReportEntry.getFindingEntry()); }// w w w. ja v a2 s .c o m } } ModelUtil.setTrustValuesOnFindings(entries, view.getReportInput(), value, monitor); } } }; try { new ProgressMonitorDialog(shell).run(true, false, runnable); } catch (InvocationTargetException e) { System.err.println("Unable to Set trust values." + e); } catch (InterruptedException e) { System.err.println("Unable to Set trust values." + e); } view.refresh(); return null; }
From source file:com.laex.cg2d.screeneditor.views.LayersViewPart.java
License:Open Source License
/** * Selected layers./* ww w.ja v a 2 s .c o m*/ * * @return the list */ private List<LayerItem> selectedLayers() { IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection(); if (selection.isEmpty()) { return new ArrayList<LayerItem>(); } List<LayerItem> selected = selection.toList(); return selected; }
From source file:com.liferay.ide.server.ui.action.CreateDBConnectAction.java
License:Open Source License
@Override public void selectionChanged(IAction action, ISelection selection) { super.selectionChanged(action, selection); if (!selection.isEmpty()) { if (selection instanceof IStructuredSelection) { final IStructuredSelection sel = (IStructuredSelection) selection; if (sel.toList().size() > 1) { action.setEnabled(sel.toList().size() == 1); }/*from w w w . jav a2s . c o m*/ } } }
From source file:com.liferay.ide.server.ui.action.OpenLiferayHomeFolderServerAction.java
License:Open Source License
@Override public void selectionChanged(IAction action, ISelection selection) { super.selectionChanged(action, selection); if ((selectedServer != null) && (selection instanceof IStructuredSelection)) { final IPath path = selectedServer.getRuntime().getLocation(); boolean enabled = false; if (path != null) { try { final IStructuredSelection sel = (IStructuredSelection) selection; final String launchCmd = ServerUIUtil.getSystemExplorerCommand(path.toFile()); if (!CoreUtil.isNullOrEmpty(launchCmd) && (sel.toList().size() == 1)) { enabled = true;//from w w w. jav a 2 s.c o m } } catch (IOException e) { } } action.setEnabled(enabled); } }
From source file:com.mansfield.pde.api.tools.internal.ui.preferencepages.TargetBaselinePreferencePage.java
License:Open Source License
/** * @return the current selection from the table viewer *///from w w w .j av a 2 s . c o m @SuppressWarnings("unchecked") protected List<Object> getCurrentSelection() { IStructuredSelection ss = (IStructuredSelection) fTableViewer.getSelection(); if (ss.isEmpty()) { return new ArrayList<Object>(); } return (List<Object>) ss.toList(); }
From source file:com.mentor.nucleus.bp.core.ui.Selection.java
License:Open Source License
private ISelection adaptSelection(ISelection selection) { List<Object> adapted = new ArrayList<Object>(); IStructuredSelection ss = (IStructuredSelection) selection; for (Object object : ss.toList()) { if (object instanceof NonRootModelElement) adapted.add(object);//from w ww.j ava 2s .c om else { Object adapter = adaptElement(object); if (adapter != null) adapted.add(adapter); else adapted.add(object); } } return new StructuredSelection(adapted); }
From source file:com.mentor.nucleus.bp.core.util.TransactionUtil.java
License:Open Source License
/** * Checks the current selection to see if any read only ones will * be affected. A dialog is displayed which gives the user the * chance to cancel the transaction in case of read only resource * existence./*from ww w . j a v a 2 s.c o m*/ */ public static boolean modifySelectedResources(String title, String message) { boolean readonlyItemFound = false; IStructuredSelection selection = Selection.getInstance().getStructuredSelection(); for (int i = 0; i < selection.size(); i++) { if (selection.toList().get(i) instanceof NonRootModelElement) { NonRootModelElement nrme = (NonRootModelElement) selection.toList().get(i); if (PersistenceManager.getHierarchyMetaData().isComponentRoot(nrme)) { if ((nrme != null) && (nrme.getFile() != null)) { ResourceAttributes attributes = nrme.getFile().getResourceAttributes(); if (attributes != null && attributes.isReadOnly()) { readonlyItemFound = true; break; } } } } } if (readonlyItemFound) { Shell context = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); boolean result = UIUtil.openQuestion(context, title, message, true); if (result == true) { // We need to change the readonly status of the file if we are // dealing with a rename as operating systems leave the renamed // file as readonly. This causes a problem for us as later we must // persist the name change. // // If there is only one item in the selection, change the file status // to writable. If only one item exists we are dealing with either // the deletion of one element (in which case it does not matter if // we change the file status) or a rename in which case we must change // the status if (selection.size() == 1) { NonRootModelElement nrme = (NonRootModelElement) selection.toList().get(0); if (PersistenceManager.getHierarchyMetaData().isComponentRoot(nrme)) { if ((nrme != null) && (nrme.getFile() != null)) { ResourceAttributes attributes = nrme.getFile().getResourceAttributes(); if (attributes != null) { attributes.setReadOnly(false); try { nrme.getFile().setResourceAttributes(attributes); } catch (CoreException e) { CorePlugin.logError("Unable to set component as writable.", e); } } } } } } return result; } else { return true; } }
From source file:com.mentor.nucleus.bp.ui.graphics.editor.ModelEditor.java
License:Open Source License
@Override public void notifySelectionLink() { if (getGraphicalEditor() == null) { return;//from www . ja v a 2 s .c om } // this notification is sent immediately after // a selection has been transferred from the explorer // tree // we only want to zoom selected if the selection is not // already visible IStructuredSelection selection = (IStructuredSelection) getGraphicalEditor().getEditorSite() .getSelectionProvider().getSelection(); boolean zoomSelected = false; for (Object selected : selection.toList()) { if (selected instanceof AbstractGraphicalEditPart) { IFigure figure = ((AbstractGraphicalEditPart) selected).getFigure(); Viewport viewport = ((FigureCanvas) getGraphicalEditor().getCanvas()).getViewport(); Rectangle viewportBounds = viewport.getBounds().getCopy(); Rectangle figureBounds = figure.getBounds().getCopy(); figure.translateToAbsolute(figureBounds); if (!viewportBounds.intersects(figureBounds)) { zoomSelected = true; break; } } } if (zoomSelected) { getGraphicalEditor().zoomSelected(); } }