List of usage examples for org.eclipse.jface.viewers IStructuredSelection toList
public List toList();
List
. From source file:com.archimatetool.editor.views.tree.actions.DeleteAction.java
License:Open Source License
@Override public void update(IStructuredSelection selection) { setEnabled(false);//from w w w . j a v a2 s .c o m for (Object element : selection.toList()) { if (DeleteCommandHandler.canDelete(element)) { // At least one element can be deleted setEnabled(true); break; } } }
From source file:com.archimatetool.editor.views.tree.commands.DuplicateCommandHandler.java
License:Open Source License
/** * @param selection/*from w w w .j a v a 2 s. c o m*/ * @return True if we can duplicate anything in selection */ public static boolean canDuplicate(IStructuredSelection selection) { for (Object element : selection.toList()) { if (canDuplicate(element)) { // At least one element can be duplicated return true; } } return false; }
From source file:com.archimatetool.editor.views.tree.TreeModelViewerDragDropHandler.java
License:Open Source License
/** * @return True if target is valid//from w ww . j a v a2 s . c om */ boolean isValidDropTarget(DropTargetEvent event) { // File from desktop onto blank area if (isFileDragOperation(event.currentDataType)) { return event.item == null; } // Local Tree Selection... // Dragging onto a Folder Object parent = getTargetParent(event); if (parent instanceof IFolder) { IFolder targetfolder = (IFolder) parent; IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer() .getSelection(); for (Object object : selection.toList()) { // must have the same top folder type - a restriction which one day we should not enforce! if (!hasCommonAncestorFolder(targetfolder, (EObject) object)) { return false; } if (!canDropObject(object, (TreeItem) event.item)) { return false; } } return true; } return false; }
From source file:com.archimatetool.editor.views.tree.TreeModelViewerFindReplaceProvider.java
License:Open Source License
@SuppressWarnings("unchecked") private List<Object> getSelectedObjects() { IStructuredSelection selection = (IStructuredSelection) fTreeModelViewer.getSelection(); return selection.toList(); }
From source file:com.archimatetool.templates.dialog.TemplateManagerDialogDragDropHandler.java
License:Open Source License
/** * @return True if target is valid// ww w . j a va 2 s . co m */ private boolean isValidDropTarget(DropTargetEvent event) { Object parent = getTargetParent(event); if (parent instanceof ITemplateGroup) { ITemplateGroup targetGroup = (ITemplateGroup) parent; IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer() .getSelection(); for (Object object : selection.toList()) { if (targetGroup.getTemplates().contains(object)) { return false; } } return true; } return false; }
From source file:com.architexa.diagrams.relo.jdt.actions.Script2Action.java
License:Open Source License
/** * @see IActionDelegate#selectionChanged(IAction, ISelection) *///from w w w. j av a2s .co m public void selectionChanged(IAction action, ISelection selection) { if (selection instanceof IStructuredSelection) { IStructuredSelection iss = (IStructuredSelection) selection; //printTypes("selectionChanged", iss.toList()); selList.clear(); selList.addAll(asListObject(iss.toList())); } else { System.err.println("Selection not structured! Type:" + selection.getClass().toString()); } }
From source file:com.astra.ses.spell.dev.scheck.ui.handlers.CleanCheckCommand.java
License:Open Source License
/** * the command has been executed, so extract extract the needed information * from the application context./*from w w w . j a va 2 s . c o m*/ */ @SuppressWarnings("unchecked") public Object execute(ExecutionEvent event) throws ExecutionException { // Obtain the current selection via the selection service IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); ISelectionService sservice = window.getSelectionService(); ISelection selection = sservice.getSelection(); List<IResource> items = null; // The selection may be a structured selection or text selected in an editor part if (selection instanceof IStructuredSelection) { IStructuredSelection sselection = (IStructuredSelection) selection; items = (List<IResource>) sselection.toList(); } else if ((selection instanceof ITextSelection)) { IEditorPart editor = window.getActivePage().getActiveEditor(); // If an editor is selected if (editor != null) { SpellEditorInfo info = (SpellEditorInfo) editor.getAdapter(SpellEditorInfo.class); // If the editor could adapt if (info != null) { items = new ArrayList<IResource>(); items.add(info.getFile()); } } } if (items.size() == 0) { MarkerManager.cleanMarkers(); } else { CleanCheckJob job = new CleanCheckJob(items); JobHelper.executeJob(job, true, true); } return null; }
From source file:com.astra.ses.spell.dev.scheck.ui.handlers.GenerateReportCommand.java
License:Open Source License
/** * the command has been executed, so extract extract the needed information * from the application context./*from w ww.j a v a 2 s . co m*/ */ @SuppressWarnings("unchecked") public Object execute(ExecutionEvent event) throws ExecutionException { // Gather all markers // Get the list of known issues List<IMarker> markers = null; IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); ISelectionService sservice = window.getSelectionService(); ISelection selection = sservice.getSelection(); // If nothing selected, generate all issues known if ((selection == null) || (selection.isEmpty())) { markers = MarkerManager.getAllMarkers(); } else { List<IResource> selectedItems = null; // The selection may be a structured selection or text selected in an editor part if (selection instanceof IStructuredSelection) { IStructuredSelection sselection = (IStructuredSelection) selection; selectedItems = (List<IResource>) sselection.toList(); } else if ((selection instanceof ITextSelection)) { IEditorPart editor = window.getActivePage().getActiveEditor(); // If an editor is selected if (editor != null) { SpellEditorInfo info = (SpellEditorInfo) editor.getAdapter(SpellEditorInfo.class); // If the editor could adapt if (info != null) { selectedItems = new ArrayList<IResource>(); selectedItems.add(info.getFile()); } } } // Gather only the resources selected for processing if (selectedItems != null) { markers = new ArrayList<IMarker>(); for (IResource res : selectedItems) { markers.addAll(MarkerManager.getAllMarkers(res)); } } } // If no issues known, dont continue if (markers.size() == 0) { MessageDialog.openWarning(window.getShell(), "Report generation", "No semantic issues to report"); return null; } String output = ""; DirectoryDialog dialog = new DirectoryDialog(Display.getCurrent().getActiveShell(), SWT.SAVE); dialog.setText("Select directory for generated report files"); dialog.setFilterPath(System.getProperty("user.home")); output = dialog.open(); if ((output != null) && (!output.isEmpty())) { File dir = new File(output); if (!dir.exists()) { MessageDialog.openError(window.getShell(), "Cannot generate reports", "Given directory does not exist"); return null; } if (!dir.canWrite()) { MessageDialog.openError(window.getShell(), "Cannot generate reports", "Cannot write to given directory"); return null; } GenerateReportFilesJob job = new GenerateReportFilesJob(output, markers); JobHelper.executeJob(job, true, true); if (job.numGenerated > 0) { MessageDialog.openInformation(window.getShell(), "Reports generated", "Generated " + job.numGenerated + " files in '" + output + "'"); } } return null; }
From source file:com.astra.ses.spell.dev.scheck.ui.handlers.PerformCheckCommand.java
License:Open Source License
/** * the command has been executed, so extract extract the needed information * from the application context.//from w w w.j av a 2 s . c om */ @SuppressWarnings("unchecked") public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); ISelectionService sservice = window.getSelectionService(); ISelection selection = sservice.getSelection(); List<IResource> items = null; // The selection may be a structured selection or text selected in an editor part if (selection instanceof IStructuredSelection) { IStructuredSelection sselection = (IStructuredSelection) selection; items = (List<IResource>) sselection.toList(); } else if ((selection instanceof ITextSelection)) { IEditorPart editor = window.getActivePage().getActiveEditor(); // If an editor is selected if (editor != null) { SpellEditorInfo info = (SpellEditorInfo) editor.getAdapter(SpellEditorInfo.class); // If the editor could adapt if (info != null) { items = new ArrayList<IResource>(); items.add(info.getFile()); } } } // If we have items to process if (items.size() > 0) { PerformCheckJob job = new PerformCheckJob(items); JobHelper.executeJob(job, true, true); String message = ""; if (job.numProcessedItems > 0) { message = "Checked " + job.numProcessedItems + " files"; if (job.notProcessed.size() > 0) { message += "\n\nThe following files have not been processed:\n\n"; for (String reason : job.notProcessed) { message += " " + reason + "\n"; } } } else { message = "No check was carried out"; if (job.notProcessed.size() > 0) { message += "\n\nThe following files have not been processed:\n\n"; for (String reason : job.notProcessed) { message += " " + reason + "\n"; } } } MessageDialog.openInformation(window.getShell(), "Semantic check", message); } return null; }
From source file:com.astra.ses.spell.gui.dialogs.DictionaryEditorDialog.java
License:Open Source License
/*************************************************************************** * //from w w w. j av a 2 s . com **************************************************************************/ @SuppressWarnings("unchecked") private void doMergeSelected() { List<TypedVariable> selected = new ArrayList<TypedVariable>(); IStructuredSelection sel = (IStructuredSelection) m_fileTable.getSelection(); if (!sel.isEmpty()) { selected.addAll(sel.toList()); mergeVariables(selected); } }