List of usage examples for org.eclipse.jface.viewers IStructuredSelection toArray
public Object[] toArray();
From source file:lumina.ui.views.blueprint.PlanDropListener.java
/** * Obtains the list of devices being dragged over the plan view. * /*from w w w .j ava2 s. c o m*/ * @return a list of devices. */ private Device[] getDraggingDevices() { final ISelection selection = planView.getDraggingSelection(); if (selection instanceof IStructuredSelection) { final IStructuredSelection s = (IStructuredSelection) selection; final Object[] objects = s.toArray(); final Device[] devices = ModelUtils.toDevices(objects); return devices; } else { return null; } }
From source file:lumina.ui.views.TreeDragAndDropListener.java
/** * Obtains the list of items of the current selection. * // w ww . ja v a2 s. c o m * @return the model items corresponding to the selection of the tree. */ private ModelItem[] getSelection() { final ISelection selection = treeViewer.getSelection(); if (selection instanceof IStructuredSelection) { final IStructuredSelection structuredSelection = (IStructuredSelection) selection; final Object[] selectedObjects = structuredSelection.toArray(); final ModelItem[] items = ModelUtils.toModelItems(selectedObjects); return items; } return null; }
From source file:lumina.ui.views.TreeDragAndDropListener.java
/** * Gets the tree selection.//from w ww . ja v a 2 s. c om * * @return the tree selection */ final ModelItem[] getTreeSelection() { final ISelection selection = treeViewer.getSelection(); if (selection instanceof IStructuredSelection) { final IStructuredSelection structSelection = (IStructuredSelection) selection; return ModelUtils.toModelItems(structSelection.toArray()); } return null; }
From source file:melnorme.lang.ide.ui.launch.BaseLaunchShortcut.java
License:Open Source License
@Override public void launch(ISelection selection, String mode) { if (selection instanceof IStructuredSelection) { IStructuredSelection ssel = (IStructuredSelection) selection; launchElements(ssel.toArray(), mode); }//w w w. j a va 2s. co m }
From source file:mpj_express_debugger.MPJExpressParameterTab.java
License:Open Source License
private void handleParametersRemoveButtonSelected() { IStructuredSelection selection = (IStructuredSelection) fViewer.getSelection(); Object[] keys = selection.toArray(); for (int i = 0; i < keys.length; i++) { String key = (String) keys[i]; Map params = (Map) fViewer.getInput(); params.remove(key);/*from w w w . j av a 2 s . c o m*/ } fViewer.refresh(); setParametersButtonsEnableState(); updateLaunchConfigurationDialog(); }
From source file:net.bioclipse.cdk.ui.handlers.CalculateTanimotoHandler.java
License:Open Source License
public Object execute(ExecutionEvent event) throws ExecutionException { ISelection sel = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection(); DecimalFormat formatter = new DecimalFormat("0.00"); if (!sel.isEmpty()) { if (sel instanceof IStructuredSelection) { try { IStructuredSelection ssel = (IStructuredSelection) sel; ICDKManager cdkmanager = net.bioclipse.cdk.business.Activator.getDefault().getJavaCDKManager(); // In case of two files, we compare each other, else we ask // for a comparision file if (ssel.toArray().length == 2) { ICDKMolecule calculateFor = cdkmanager.loadMolecule((IFile) ssel.toArray()[0]); ICDKMolecule reference = cdkmanager.loadMolecule((IFile) ssel.toArray()[1]); double similarity = cdkmanager.calculateTanimoto(calculateFor, reference); MessageBox mb = new MessageBox(new Shell(), SWT.ICON_INFORMATION | SWT.OK); mb.setText("Similarity"); mb.setMessage(((IFile) ssel.toArray()[0]).getName() + " and " + ((IFile) ssel.toArray()[1]).getName() + " similarity: " + formatter.format(similarity * 100) + "%"); mb.open();// www.j a v a2s . c o m } else { TanimotoWizard wiz = new TanimotoWizard(ssel); WizardDialog dialog = new WizardDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), wiz); dialog.open(); } } catch (Exception ex) { LogUtils.handleException(ex, logger); } } } return null; }
From source file:net.bioclipse.cdk.ui.handlers.Create2dHandlerWithReset.java
License:Open Source License
/** * This method creates the coordinates and saves the file on the selection. * /* w ww .j a v a2 s.c o m*/ * @param withReset If true, the other set of coordinates is set to null. This should be used on mol files, since these can only hold one set (3d or 2d). * @param make3D true = 3d is generated, false = 2d is generated. */ public static void doCreation(final boolean withReset, final boolean make3D) { ISelection sel = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection(); if (!sel.isEmpty()) { if (sel instanceof IStructuredSelection) { MessageBox mb = new MessageBox(new Shell(), SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION); final IStructuredSelection ssel = (IStructuredSelection) sel; mb.setText("Change " + ssel.size() + " file(s)"); mb.setMessage("Do you want to write the " + (make3D ? "3D" : "2D") + " coordinates into the existing file? If no, new file(s) will be created."); final int makenewfile = mb.open(); if (makenewfile == SWT.CANCEL) return; final IFile[] filestosaveto = new IFile[ssel.size()]; for (int i = 0; i < ssel.toArray().length; i++) { if (makenewfile == SWT.NO) { SaveAsDialog dialog = new SaveAsDialog(new Shell()); dialog.setOriginalFile((IFile) ssel.toArray()[i]); int saveasreturn = dialog.open(); if (saveasreturn != SaveAsDialog.CANCEL) { IPath result = dialog.getResult(); if (dialog.getResult().getFileExtension() == null) result = result.addFileExtension(((IFile) ssel.toArray()[i]).getFileExtension()); filestosaveto[i] = ((IFile) ssel.toArray()[i]).getWorkspace().getRoot().getFile(result); } else { return; } } } try { List<IMolecule> mols = new ArrayList<IMolecule>(); for (int i = 0; i < ssel.toArray().length; i++) { ICDKMolecule mol; mols.add( Activator.getDefault().getJavaCDKManager().loadMolecule((IFile) ssel.toArray()[i])); } if (make3D) { //This try-catch is not working try { Activator.getDefault().getJavaCDKManager().generate3dCoordinates(mols, new BioclipseUIJob<List<IMolecule>>() { @Override public void runInUI() { List<IMolecule> newMols = getReturnValue(); if (newMols != null) handlePostProduction(withReset, make3D, makenewfile, ssel, filestosaveto, newMols); } }); } catch (Exception e) { if (e.getCause().getCause() instanceof NoSuchAtomTypeException) { mb = new MessageBox(new Shell(), SWT.OK | SWT.ICON_WARNING); mb.setText("Problems handling atom types in " + ((IFile) ssel.toArray()[Integer .parseInt(e.getMessage().split(" ")[e.getMessage().split(" ").length - 1])]) .getName()); mb.setMessage( "We cannot handle this structure since it contains unknown atom types. We recommend you leave this out from generation!"); mb.open(); } else { throw e; } } } else { Activator.getDefault().getJavaCDKManager().generate2dCoordinates(mols, new BioclipseUIJob<List<IMolecule>>() { @Override public void runInUI() { List<IMolecule> newMols = getReturnValue(); handlePostProduction(withReset, make3D, makenewfile, ssel, filestosaveto, newMols); } }); } } catch (Exception e) { LogUtils.handleException(e, logger, net.bioclipse.cdk.ui.Activator.PLUGIN_ID); } } } }
From source file:net.bioclipse.cdk.ui.handlers.Create2dHandlerWithReset.java
License:Open Source License
private static void handlePostProduction(boolean withReset, boolean make3D, int makenewfile, IStructuredSelection ssel, IFile[] filestosaveto, List<IMolecule> mols) { for (int i = 0; i < mols.size(); i++) { IMolecule mol = mols.get(i);// ww w . j a va 2s .c o m if (withReset) { //we set the other coordinates to null, since when writing out, they might override for (IAtom atom : ((ICDKMolecule) mol).getAtomContainer().atoms()) { if (make3D) atom.setPoint2d(null); else atom.setPoint3d(null); } } if (makenewfile == SWT.YES) { try { Activator.getDefault().getJavaCDKManager().saveMolecule(mol, (IFile) ssel.toArray()[i], true); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } } else if (makenewfile == SWT.NO) { try { Activator.getDefault().getJavaCDKManager().saveMolecule(mol, filestosaveto[i], true); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } } } }
From source file:net.bioclipse.cdk.ui.wizards.SelectFilesWizardPage.java
License:Open Source License
private boolean containsMolecule(IStructuredSelection selectedFiles) throws CoreException, IOException { if (selectedFiles != null) { for (int i = 0; i < selectedFiles.toArray().length; i++) { if (selectedFiles.toArray()[i] instanceof IFile) { if (ChemoinformaticUtils.isMolecule((IFile) selectedFiles.toArray()[i])) return true; }//from w ww . j a va2s.c om } } return false; }
From source file:net.bioclipse.cdk.ui.wizards.SelectFileWizardPage.java
License:Open Source License
private boolean containsMolecule(IStructuredSelection selectedFiles) throws CoreException, IOException { if (selectedFiles != null) { for (int i = 0; i < selectedFiles.toArray().length; i++) { if (selectedFiles.toArray()[i] instanceof IFile) { if (ChemoinformaticUtils.isMolecule((IFile) selectedFiles.toArray()[i])) return true; }/*www. ja v a2 s.c o m*/ } } return false; }