List of usage examples for org.eclipse.jface.viewers IStructuredSelection toArray
public Object[] toArray();
From source file:org.eclipse.debug.internal.ui.views.expression.ExpressionDropAdapter.java
License:Open Source License
/** * Performs the drop when the selection is a collection of IExpressions. * Moves the given expressions from their original locations to the * location of the current target.//from w w w . j ava2 s . c o m * @param selection the dragged selection * @return whether the drop could be completed */ private boolean performExpressionDrop(IStructuredSelection selection) { IExpression targetExpression = getTargetExpression(getCurrentTarget()); if (targetExpression != null) { IExpression[] expressions = new IExpression[selection.size()]; Object[] selectionElements = selection.toArray(); for (int i = 0; i < selectionElements.length; i++) { expressions[i] = getTargetExpression(selectionElements[i]); } IExpressionManager manager = DebugPlugin.getDefault().getExpressionManager(); if (manager instanceof ExpressionManager) { ((ExpressionManager) manager).moveExpressions(expressions, targetExpression, fInsertBefore); } return true; } return false; }
From source file:org.eclipse.debug.internal.ui.views.memory.renderings.CreateRendering.java
License:Open Source License
private void addRenderings() { ISelection selection = fViewer.getSelection(); Object[] renderings = null;/*from w w w .ja va 2 s . co m*/ if (selection instanceof IStructuredSelection) { IStructuredSelection strucSelection = (IStructuredSelection) selection; renderings = strucSelection.toArray(); } if (renderings == null) { Status stat = new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), DebugException.INTERNAL_ERROR, DebugUIMessages.CreateRenderingTab_0, null); DebugUIPlugin.errorDialog(DebugUIPlugin.getShell(), DebugUIMessages.CreateRenderingTab_1, DebugUIMessages.CreateRenderingTab_2, stat); // return; } // ask for debug target and memory block retrieval IMemoryBlockRetrieval standardMemRetrieval = MemoryViewUtil.getMemoryBlockRetrieval(getMemoryBlock()); if (standardMemRetrieval == null) return; // make a copy of the container, may be diposed when a rendering is added IMemoryRenderingContainer container = fContainer; // add memory renderings to Memory Rendering Manager for (int i = 0; i < renderings.length; i++) { if (renderings[i] instanceof IMemoryRenderingType) { try { IMemoryRendering rendering = ((IMemoryRenderingType) renderings[i]).createRendering(); if (rendering != null) { rendering.init(container, getMemoryBlock()); container.addMemoryRendering(rendering); } } catch (CoreException e) { MemoryViewUtil.openError(DebugUIMessages.CreateRendering_0, DebugUIMessages.CreateRendering_1, e); // } } } }
From source file:org.eclipse.debug.internal.ui.views.memory.ResetMemoryBlockAction.java
License:Open Source License
public void selectionChanged(IAction action, ISelection selection) { action.setEnabled(!selection.isEmpty()); if (selection instanceof IStructuredSelection) { IStructuredSelection strucSel = (IStructuredSelection) selection; Object[] objs = strucSel.toArray(); fSelectedMB.clear();/* w ww. ja v a 2s . c o m*/ for (int i = 0; i < objs.length; i++) { if (objs[i] instanceof IMemoryBlock) fSelectedMB.add(objs[i]); if (objs[i] instanceof IMemoryRendering) fSelectedMB.add(((IMemoryRendering) objs[i]).getMemoryBlock()); } } }
From source file:org.eclipse.debug.ui.actions.DebugCommandAction.java
License:Open Source License
public void run() { synchronized (this) { if (!fInitialized) { try { wait();//from w w w .jav a 2 s . c o m } catch (InterruptedException e) { } } } ISelection selection = getContext(); if (selection instanceof IStructuredSelection && isEnabled()) { IStructuredSelection ss = (IStructuredSelection) selection; boolean enabled = execute(ss.toArray()); // disable the action according to the command setEnabled(enabled); } }
From source file:org.eclipse.debug.ui.actions.DebugCommandHandler.java
License:Open Source License
public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); if (window == null) { throw new ExecutionException("No active workbench window."); //$NON-NLS-1$ }//from w w w .j a v a 2 s . c o m fCurrentEnabledTarget = getEnabledTarget(window); ISelection selection = getContextService(window).getActiveContext(); if (selection instanceof IStructuredSelection && isEnabled()) { IStructuredSelection ss = (IStructuredSelection) selection; boolean enabledAfterExecute = execute(window, ss.toArray()); // enable/disable the action according to the command fCurrentEnabledTarget.setEnabled(enabledAfterExecute); } return null; }
From source file:org.eclipse.dltk.internal.corext.refactoring.RefactoringAvailabilityTester.java
License:Open Source License
public static boolean isDeleteAvailable(final IStructuredSelection selection) throws ModelException { if (!selection.isEmpty()) return isDeleteAvailable(selection.toArray()); return false; }
From source file:org.eclipse.dltk.internal.ui.actions.RefreshAction.java
License:Open Source License
private IResource[] getResources(IStructuredSelection selection) { if (selection.isEmpty()) { return new IResource[] { ResourcesPlugin.getWorkspace().getRoot() }; }/*from w ww. j a v a 2 s . c o m*/ List<IResource> result = new ArrayList<IResource>(selection.size()); getResources(result, selection.toArray()); for (Iterator<IResource> iter = result.iterator(); iter.hasNext();) { IResource resource = iter.next(); if (isDescendent(result, resource)) iter.remove(); } return result.toArray(new IResource[result.size()]); }
From source file:org.eclipse.dltk.internal.ui.refactoring.reorg.CutAction.java
License:Open Source License
public void run(IStructuredSelection selection) { try {//from w ww .ja v a 2s . c o m selectionChanged(selection); if (isEnabled()) { fCopyToClipboardAction.run(selection); RefactoringExecutionStarter.startCutRefactoring(selection.toArray(), getShell()); } } catch (CoreException e) { ExceptionHandler.handle(e, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringMessages.OpenRefactoringWizardAction_exception); } catch (InterruptedException e) { //OK } catch (InvocationTargetException e) { ExceptionHandler.handle(e, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringMessages.OpenRefactoringWizardAction_exception); } }
From source file:org.eclipse.dltk.internal.ui.refactoring.reorg.DeleteAction.java
License:Open Source License
public void selectionChanged(IStructuredSelection selection) { if (ReorgUtils.containsOnlyProjects(selection.toList())) { setEnabled(createWorkbenchAction(selection).isEnabled()); return;//from w ww . j av a 2 s. co m } try { setEnabled(RefactoringAvailabilityTester.isDeleteAvailable(selection.toArray())); } catch (CoreException e) { //no ui here - this happens on selection changes // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 if (ScriptModelUtil.isExceptionToBeLogged(e)) DLTKUIPlugin.log(e); setEnabled(false); } }