List of usage examples for org.eclipse.jface.viewers IStructuredSelection toArray
public Object[] toArray();
From source file:com.telink.tc32eclipse.ui.TC32UIPlugin.java
License:Open Source License
/** * Shows the given selection in this view. *///from w w w. j a va 2 s .c o m public void showSelection(IWorkbenchPart sourcepart, ISelection selection) { //setContentDescription(sourcepart.getTitle() + " (" + selection.getClass().getName() + ")"); if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; showItems(ss.toArray()); } if (selection instanceof ITextSelection) { ITextSelection ts = (ITextSelection) selection; showText(ts.getText()); } if (selection instanceof IMarkSelection) { IMarkSelection ms = (IMarkSelection) selection; try { showText(ms.getDocument().get(ms.getOffset(), ms.getLength())); } catch (BadLocationException ble) { } } }
From source file:com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView.java
License:Open Source License
public TreeObject[] getSelectedTreeObjects() { TreeObject[] treeObjects = null;/*ww w . j av a2 s. c o m*/ ISelection selection = viewer.getSelection(); if (!selection.isEmpty()) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; Object[] treeArray = structuredSelection.toArray(); treeObjects = new TreeObject[structuredSelection.size()]; for (int i = 0; i < treeObjects.length; i++) treeObjects[i] = (TreeObject) treeArray[i]; } return treeObjects; }
From source file:com.vectrace.MercurialEclipse.actions.OpenMercurialRevisionAction.java
License:Open Source License
@Override public void run() { IStructuredSelection structSel = selection; Object[] objArray = structSel.toArray(); for (int i = 0; i < objArray.length; i++) { Object tempRevision = objArray[i]; final IFileRevision revision = (IFileRevision) tempRevision; if (revision == null || !revision.exists()) { MessageDialog.openError(shell, Messages.getString("OpenMercurialRevisionAction.error.deletedRevision"), //$NON-NLS-1$ Messages.getString("OpenMercurialRevisionAction.error.cantOpen")); //$NON-NLS-1$ } else {/*from w w w . jav a2 s . co m*/ SafeUiJob runnable = new SafeUiJob( Messages.getString("OpenMercurialRevisionAction.job.openingEditor")) { //$NON-NLS-1$ @Override public IStatus runSafe(IProgressMonitor monitor) { IStorage file; try { file = revision.getStorage(monitor); if (file instanceof IFile) { // if this is the current workspace file, open it ResourceUtils.openEditor(wPage, (IFile) file); } else { // not current revision MercurialRevisionEditorInput fileRevEditorInput = new MercurialRevisionEditorInput( revision); if (!editorAlreadyOpenOnContents(fileRevEditorInput)) { String id = fileRevEditorInput.getEditorID(); wPage.openEditor(fileRevEditorInput, id); } } return super.runSafe(monitor); } catch (CoreException e) { MercurialEclipsePlugin.logError(e); return e.getStatus(); } } }; runnable.schedule(); } } }
From source file:com.vectrace.MercurialEclipse.history.CompareRevisionAction.java
License:Open Source License
@Override protected boolean updateSelection(IStructuredSelection sSelection) { if (sSelection.size() != 1 && sSelection.size() != 2) { return false; }//from w w w . java2s . c o m if (sSelection.size() == 1) { Object element = sSelection.getFirstElement(); if (element instanceof MercurialRevision) { MercurialRevision rev = (MercurialRevision) element; if (rev.getResource() instanceof IFile) { selection = sSelection.toArray(); return true; } } return false; } else if (enableCompareWithPrev && sSelection.size() == 2) { selection = sSelection.toArray(); return sSelection.toArray()[1] instanceof FileStatus; } selection = sSelection.toArray(); return true; }
From source file:com.vectrace.MercurialEclipse.menu.SynchronizeChangesetHandler.java
License:Open Source License
/** * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) *//* w w w. j a v a2 s . c o m*/ public Object execute(ExecutionEvent event) throws ExecutionException { changeset = null; IStructuredSelection selection = HandlerUtil.getCurrentStructuredSelection(event); try { if (selection != null && selection.size() == 1) { Object selectionObject = selection.toArray()[0]; if (selectionObject instanceof GroupedUncommittedChangeSet) { changeset = (GroupedUncommittedChangeSet) selectionObject; } } if (changeset == null) { // NOP return null; } run(getSelectedChangeset()); } catch (Exception e) { MessageDialog.openError(getShell(), Messages.getString("SingleResourceHandler.hgSays"), //$NON-NLS-1$ e.getMessage() + Messages.getString("SingleResourceHandler.seeErrorLog")); //$NON-NLS-1$ throw new ExecutionException(e.getMessage(), e); } return null; }
From source file:com.vectrace.MercurialEclipse.synchronize.actions.CreateNewChangesetSynchronizeAction.java
License:Open Source License
@Override protected SynchronizeModelOperation getSubscriberOperation(final ISynchronizePageConfiguration configuration, IDiffElement[] elements) {/*from w w w . j a v a 2 s . com*/ IStructuredSelection sel = getStructuredSelection(); if (isSupported(sel.toArray())) { return new SynchronizeModelOperation(configuration, elements) { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { Viewer viewer = configuration.getPage().getViewer(); if (!(viewer instanceof ContentViewer)) { return; } CommonViewer commonViewer = (CommonViewer) viewer; final HgChangeSetContentProvider csProvider = OpenAction .getProvider(commonViewer.getNavigatorContentService()); IUncommitted uc = csProvider.getUncommittedEntry(); if (uc instanceof UncommittedChangesetGroup) { ((UncommittedChangesetGroup) uc).create(new IFile[0]); } else { MercurialEclipsePlugin.logError("Unexped invocation of CreateNewChangesetSynchronizeAction", new IllegalStateException()); } } }; } return null; }
From source file:com.vectrace.MercurialEclipse.synchronize.actions.CreateNewChangesetSynchronizeAction.java
License:Open Source License
@Override protected boolean updateSelection(IStructuredSelection selection) { boolean updateSelection = super.updateSelection(selection); if (!updateSelection) { Object[] array = selection.toArray(); return isSupported(array); }/*from w w w. j a va 2s . co m*/ return updateSelection; }
From source file:com.vectrace.MercurialEclipse.synchronize.actions.DeleteAction.java
License:Open Source License
@Override protected SynchronizeModelOperation getSubscriberOperation(ISynchronizePageConfiguration config, IDiffElement[] elements) {/*from w w w . j ava2s .co m*/ List<IResource> selectedResources = new ArrayList<IResource>(); IStructuredSelection sel = getStructuredSelection(); if (sel.size() == 1 && sel.getFirstElement() instanceof GroupedUncommittedChangeSet) { final GroupedUncommittedChangeSet changeSet = (GroupedUncommittedChangeSet) sel.getFirstElement(); return new SynchronizeModelOperation(config, elements) { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { changeSet.getGroup().delete(changeSet); } }; } Object[] objects = sel.toArray(); for (Object object : objects) { if (object instanceof WorkingChangeSet) { selectedResources.addAll(((WorkingChangeSet) object).getFiles()); } else if (!(object instanceof ChangeSet)) { IResource resource = ResourceUtils.getResource(object); if (resource != null) { selectedResources.add(resource); } } } IResource[] resources = new IResource[selectedResources.size()]; selectedResources.toArray(resources); return new DeleteOperation(configuration, elements, resources); }
From source file:com.vectrace.MercurialEclipse.synchronize.actions.DeleteAction.java
License:Open Source License
@Override protected final boolean updateSelection(IStructuredSelection selection) { boolean updateSelection = super.updateSelection(selection); if (!updateSelection) { if (selection.size() == 1 && selection.getFirstElement() instanceof GroupedUncommittedChangeSet) { GroupedUncommittedChangeSet changeSet = (GroupedUncommittedChangeSet) selection.getFirstElement(); if (changeSet.isDefault()) { return false; }// w ww . j a v a 2s . com return true; } Object[] array = selection.toArray(); for (Object object : array) { if (!isSupported(object)) { return false; } } return true; } return updateSelection; }
From source file:com.vectrace.MercurialEclipse.synchronize.actions.EditChangesetSynchronizeAction.java
License:Open Source License
@Override protected boolean updateSelection(IStructuredSelection selection) { boolean updateSelection = super.updateSelection(selection); if (!updateSelection) { Object[] array = selection.toArray(); if (selection.size() != 1) { return false; }//from ww w . j a v a 2 s . c om return isSupported(array[0]); } return updateSelection; }