List of usage examples for org.eclipse.jface.viewers IStructuredSelection toArray
public Object[] toArray();
From source file:com.microsoft.tfs.client.eclipse.ui.egit.teamexplorer.TeamExplorerGitRepositoriesSection.java
License:Open Source License
public void addMenuItems() { final MenuManager popupMenuManager = new MenuManager("#popup"); //$NON-NLS-1$ final Menu menu = popupMenuManager.createContextMenu(treeViewer.getControl()); popupMenuManager.setRemoveAllWhenShown(true); popupMenuManager.addMenuListener(new IMenuListener() { @Override//from www . j av a 2 s .c om public void menuAboutToShow(final IMenuManager manager) { if (treeViewer.getSelection().isEmpty()) { return; } if (treeViewer.getSelection() instanceof IStructuredSelection) { final IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection(); final Object[] nodes = selection.toArray(); final Object firstNode = selection.getFirstElement(); if (firstNode instanceof TfsGitRepositoryJson) { final TfsGitRepositoryJson repoJson = (TfsGitRepositoryJson) firstNode; manager.add(new OpenInEGitAction(repoJson)); manager.add(new OpenInWebAction(context, repoJson)); manager.add(new Separator()); manager.add(new GitWizardAction(nodes)); manager.add(new Separator()); manager.add(new CopyAction( Messages.getString("TeamExplorerGitRepositoriesSection.CopyCloneUrlAction"), //$NON-NLS-1$ treeViewer.getControl().getDisplay(), repoJson.getRemoteUrl(), true)); } } } }); treeViewer.getControl().setMenu(menu); }
From source file:com.minres.scviewer.ui.views.SelectionTableView.java
License:Open Source License
/** * Shows the given selection in this view. *//*from ww w. j a va2 s . c om*/ 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.minres.scviewer.ui.views.TxOutlinePage.java
License:Open Source License
private Action makeStreamAction(String text, String imgDescriptor, final IStructuredSelection selection, boolean enabled, final boolean remove) { Action action = new Action() { @SuppressWarnings("unchecked") public void run() { if (selection != null) for (Object obj : selection.toArray()) { if (obj instanceof IWaveform) { if (remove) editor.removeStreamFromList((IWaveform<? extends IWaveformEvent>) obj); else editor.addStreamToList((IWaveform<? extends IWaveformEvent>) obj); } else if (obj instanceof IHierNode) { LinkedList<IHierNode> queue = new LinkedList<IHierNode>(); LinkedList<IWaveform<? extends IWaveformEvent>> streams = new LinkedList<IWaveform<? extends IWaveformEvent>>(); queue.add((IHierNode) obj); while (queue.size() > 0) { IHierNode n = queue.poll(); if (n instanceof IWaveform) streams.add((IWaveform<? extends IWaveformEvent>) n); queue.addAll(n.getChildNodes()); }/*from ww w.j a v a 2s. c o m*/ if (remove) editor.removeStreamsFromList(streams.toArray(new IWaveform[] {})); else editor.addStreamsToList(streams.toArray(new IWaveform[] {})); } } } }; action.setText(text); action.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(imgDescriptor)); if (selection.getFirstElement() instanceof IWaveform && editor.getStreamList().contains(selection.getFirstElement())) action.setEnabled(false); else action.setEnabled(true); return action; }
From source file:com.nextep.designer.sqlclient.ui.handlers.CopyDatalineHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { final ISelection s = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService() .getSelection();//from ww w . j a va 2 s .com if (!s.isEmpty() && s instanceof IStructuredSelection) { final IStructuredSelection sel = (IStructuredSelection) s; // Preparing our buffer final StringBuffer buf = new StringBuffer(500); // Iterating over selected lines for (Object o : sel.toArray()) { if (o instanceof ISQLRowResult) { buf.append(ExportHelper.buildCSVLine((ISQLRowResult) o)); } } // Copying to system clipboard Clipboard cb = new Clipboard(Display.getDefault()); TextTransfer textTransfer = TextTransfer.getInstance(); cb.setContents(new Object[] { buf.toString() }, new Transfer[] { textTransfer }); } return null; }
From source file:com.nextep.designer.vcs.ui.handlers.VersionCompareHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection s = HandlerUtil.getCurrentSelection(event); if (s == null || s.isEmpty()) { return null; }/* w ww . j a va2s. c om*/ if (s instanceof IStructuredSelection) { IStructuredSelection sel = (IStructuredSelection) s; IVersionInfo mainVersion = null; IVersionInfo otherVersion = null; // Retrieving selected versions from selection for (Object o : sel.toArray()) { if (mainVersion == null) { mainVersion = VersionHelper.getVersionInfo(o); } else { otherVersion = VersionHelper.getVersionInfo(o); } } // Have we got anything selected? If so we compare if (mainVersion != null) { final IVersionInfo sourceVersion = otherVersion == null ? mainVersion.getPreviousVersion() : otherVersion; VCSUIPlugin.getComparisonUIManager().compare(mainVersion.getReference(), mainVersion, sourceVersion); } } return null; }
From source file:com.nokia.carbide.cpp.internal.project.ui.views.RefreshSelectionAction.java
License:Open Source License
@Override public void run() { IStructuredSelection selection = getStructuredSelection(); if (selection.isEmpty()) { // refresh the entire view view.getViewer().refresh();/*from w w w. j av a 2 s.c o m*/ return; } for (Object o : selection.toArray()) { if (o instanceof ISPNViewRefreshable) { ((ISPNViewRefreshable) o).refresh(); view.getViewer().refresh(o); } else if (o instanceof ICProject) { // this refreshes the viewer as well view.refreshProject((ICProject) o); } else { view.getViewer().refresh(o); } } }
From source file:com.nokia.carbide.cpp.internal.project.ui.views.RefreshSelectionAction.java
License:Open Source License
@Override protected boolean updateSelection(IStructuredSelection selection) { // enabled if selection is does not contain any IFile's. everything // else that could be selected is IProject or SPNContainer's. if (!selection.isEmpty()) { for (Object o : selection.toArray()) { if (o instanceof IFile) { return false; }//from w ww . j a va 2 s .co m if (o instanceof ICElement && !(o instanceof IParent)) { // disable refresh for c elements that don't have children return false; } } } return true; }
From source file:com.nokia.carbide.search.system.ui.text.AbstractTextSearchViewPage.java
License:Open Source License
/** * Note: this is internal API and should not be called from clients outside * of the search plug-in./*w w w . j a va 2 s . c om*/ * <p> * Removes the currently selected match. Does nothing if no match is * selected. * </p> * * @noreference This method is not intended to be referenced by clients. */ public void internalRemoveSelected() { AbstractTextSearchResult result = getInput(); if (result == null) return; StructuredViewer viewer = getViewer(); IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); HashSet set = new HashSet(); if (viewer instanceof TreeViewer) { ITreeContentProvider cp = (ITreeContentProvider) viewer.getContentProvider(); collectAllMatchesBelow(result, set, cp, selection.toArray()); } else { collectAllMatches(set, selection.toArray()); } navigateNext(true); Match[] matches = new Match[set.size()]; set.toArray(matches); result.removeMatches(matches); }
From source file:com.nokia.s60ct.gui.actions.CreateDuplicateAction.java
License:Open Source License
public void selectionChanged(IAction action, ISelection selection) { selectedObjects.clear();// ww w . j a v a 2 s . c o m if (selection instanceof IStructuredSelection) { IStructuredSelection structedSelection = (IStructuredSelection) selection; Object[] objects = structedSelection.toArray(); if (objects.length != 0) { Frame frame = (Frame) objects[0]; if (frame.isTemplate()) { action.setEnabled(false); } else { this.frame = frame; action.setEnabled(true); } } } }
From source file:com.nokia.s60ct.gui.actions.CreateParentSettingDuplicateAction.java
License:Open Source License
public void selectionChanged(IAction action, ISelection selection) { IStructuredSelection structedSelection = (IStructuredSelection) selection; Object[] objects = structedSelection.toArray(); parentSetting = (ParentSetting) objects[0]; if (parentSetting.getType().equals(TYPE.SEQUENCE)) action.setEnabled(true);//w w w. j a v a 2 s . c om else action.setEnabled(false); }