List of usage examples for org.eclipse.jface.viewers IStructuredSelection getFirstElement
public Object getFirstElement();
null
if the selection is empty. From source file:com.aptana.ui.io.compare.FileStoreCompareEditorInput.java
License:Open Source License
@Override public Viewer createDiffViewer(Composite parent) { fDiffViewer = new DiffTreeViewer(parent, getCompareConfiguration()) { @Override//from w ww .j a v a 2 s .c o m protected void fillContextMenu(IMenuManager manager) { if (fOpenAction == null) { fOpenAction = new Action() { public void run() { handleOpen(null); } }; Utilities.initAction(fOpenAction, getBundle(), "action.CompareContents."); //$NON-NLS-1$ } boolean enable = false; ISelection selection = getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; if (ss.size() == 1) { Object element = ss.getFirstElement(); if (element instanceof MyDiffNode) { ITypedElement typedElement = ((MyDiffNode) element).getId(); if (typedElement != null) { enable = !ITypedElement.FOLDER_TYPE.equals(typedElement.getType()); } } else { enable = true; } } } fOpenAction.setEnabled(enable); manager.add(fOpenAction); super.fillContextMenu(manager); } }; return fDiffViewer; }
From source file:com.aptana.ui.widgets.CListTable.java
License:Open Source License
/** * @param parent//from www . j a va 2 s . c om * the parent composite * @param style * the style bits */ public CListTable(Composite parent, int style) { super(parent, style); items = new ArrayList<Object>(); listeners = new ArrayList<Listener>(); setLayout(GridLayoutFactory.fillDefaults().create()); descriptionLabel = new Label(this, SWT.WRAP); descriptionLabel.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); Composite buttons = new Composite(this, SWT.NONE); buttons.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).create()); buttons.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); addButton = new Button(buttons, SWT.PUSH); addButton.setToolTipText(StringUtil.ellipsify(CoreStrings.ADD)); addButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { boolean itemAdded = false; Object newItem = null; for (Listener listener : listeners) { newItem = listener.addItem(); if (newItem != null) { items.add(newItem); itemAdded = true; } } if (itemAdded) { tableViewer.refresh(); tableViewer.setSelection(new StructuredSelection(newItem)); for (Listener listener : listeners) { listener.itemsChanged(getItems()); } } } }); addButton.setImage(SWTUtils.getImage(UIPlugin.getDefault(), "/icons/add.gif")); //$NON-NLS-1$ editButton = new Button(buttons, SWT.PUSH); editButton.setToolTipText(StringUtil.ellipsify(CoreStrings.EDIT)); editButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection(); if (!selection.isEmpty()) { Object element = selection.getFirstElement(); items.remove(element); Object newElement = null; boolean changed = false; for (Listener listener : listeners) { newElement = listener.editItem(element); if (newElement != null) { items.add(newElement); changed = true; } } if (changed) { tableViewer.refresh(); tableViewer.setSelection(new StructuredSelection(newElement)); for (Listener listener : listeners) { listener.itemsChanged(getItems()); } } } } }); editButton.setImage(SWTUtils.getImage(UIPlugin.getDefault(), "/icons/edit.png")); //$NON-NLS-1$ removeButton = new Button(buttons, SWT.PUSH); removeButton.setToolTipText(CoreStrings.REMOVE); removeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection(); Object[] elements = selection.toArray(); for (Object element : elements) { items.remove(element); } tableViewer.refresh(); updateStates(); for (Listener listener : listeners) { listener.itemsChanged(getItems()); } } }); removeButton.setImage(SWTUtils.getImage(UIPlugin.getDefault(), "/icons/delete.gif")); //$NON-NLS-1$ createTable(this); }
From source file:com.arc.cdt.debug.seecode.internal.ui.SeeCodeConfigPage.java
License:Open Source License
/** * Returns the current C element context from which to initialize default * settings, or <code>null</code> if none. Note, if possible we will * return the IBinary based on config entry as this may be more usefull then * just the project./* www .j a v a2 s . c o m*/ * * NOTE: this code was copied from AbstractCDebuggerTab that no longer * was accessible since the CDT folks refactored things (2/8/06) * * @return C element context. */ public static ICElement getContext(ILaunchConfiguration config, String platform) { String projectName = null; String programName = null; IWorkbenchPage page = LaunchUIPlugin.getActivePage(); Object obj = null; try { projectName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String) null); programName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, (String) null); } catch (CoreException e) { } if (projectName != null && !projectName.equals("")) { //$NON-NLS-1$ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); ICProject cProject = CCorePlugin.getDefault().getCoreModel().create(project); if (cProject != null && cProject.exists()) { obj = cProject; } } else { if (page != null) { ISelection selection = page.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; if (!ss.isEmpty()) { obj = ss.getFirstElement(); } } } } if (obj instanceof IResource) { ICElement ce = CoreModel.getDefault().create((IResource) obj); if (ce == null) { IProject pro = ((IResource) obj).getProject(); ce = CoreModel.getDefault().create(pro); } obj = ce; } if (obj instanceof ICElement) { if (platform != null && !platform.equals("*")) { //$NON-NLS-1$ ICDescriptor descriptor; try { descriptor = CCorePlugin.getDefault() .getCProjectDescription(((ICElement) obj).getCProject().getProject(), false); if (descriptor != null) { String projectPlatform = descriptor.getPlatform(); if (!projectPlatform.equals(platform) && !projectPlatform.equals("*")) { //$NON-NLS-1$ obj = null; } } } catch (CoreException e) { } } if (obj != null) { if (programName == null || programName.equals("")) { //$NON-NLS-1$ return (ICElement) obj; } ICElement ce = (ICElement) obj; IProject project; project = (IProject) ce.getCProject().getResource(); IPath programFile; //<CUSTOMIZATION> handle absolute exe paths if (new File(programName).isAbsolute()) { programFile = new Path(programName); } //</CUSTOMIZATION> else { programFile = project.getFile(programName).getLocation(); } ce = CCorePlugin.getDefault().getCoreModel().create(programFile); if (ce != null && ce.exists()) { return ce; } return (ICElement) obj; } } if (page != null) { IEditorPart part = page.getActiveEditor(); if (part != null) { IEditorInput input = part.getEditorInput(); return (ICElement) input.getAdapter(ICElement.class); } } return null; }
From source file:com.arc.cdt.debug.seecode.internal.ui.SeeCodeMenuBarManager.java
License:Open Source License
/** * Called when the debug view selection changed. Refresh the SeeCode menus * if necessary.//from www. j a va 2s.com * * @param selection */ private void setDebugViewSelection(ISelection selection) { if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; Object o = ss.getFirstElement(); if (!(o instanceof ILaunch) && !(o instanceof IStackFrame) && !(o instanceof IThread) && !(o instanceof IDebugTarget) && o instanceof IAdaptable) { IDebugTarget target = (IDebugTarget) ((IAdaptable) o).getAdapter(IDebugTarget.class); if (target != null) o = target; else { ILaunch launch = (ILaunch) ((IAdaptable) o).getAdapter(ILaunch.class); if (launch != null) o = launch; } } if (o instanceof ILaunch) { IDebugTarget targets[] = ((ILaunch) o).getDebugTargets(); if (targets != null && targets.length > 0) { // We assume all targets of a launch will have same session. o = targets[0]; } } if (o instanceof IStackFrame) { o = ((IStackFrame) o).getThread(); } if (o instanceof IThread) { o = ((IThread) o).getDebugTarget(); } //To get the seecode engine interface, we extract // "session" object that should have an adapter for // EngineInterface. if (o instanceof IAdaptable) { ICDITarget target = (ICDITarget) ((IAdaptable) o).getAdapter(ICDITarget.class); // We don't want to "select" a session before its target is running. // If the engine is in the process of loading a program and // attempting to display an error box. A call back into the engine would deadlock. CR2140. if (target != null && target.isTerminated()) target = null; // get rid of debug view if target terminated. setDebugTarget(target); } else setDebugTarget(null); } else { // NOTE: during animation, as stackframes change, the selection may go empty for a very short // time as an artifact of the Tree viewer. Ignore such a case by observing if the last thing // we were looking at is still active. if (mTarget == null || mTarget.isTerminated()) setDebugTarget(null); } }
From source file:com.arc.cdt.debug.seecode.ui.views.AbstractEngineBasedView.java
License:Open Source License
protected void setEngineSource(final IStructuredSelection selection) { if (fIsVisible && !selection.isEmpty()) { // At this point, we are NOT in the UI thread. final Object element = selection.getFirstElement(); final EngineInterface engine = Utilities.computeEngineFromSelection(selection); if (engine != null) { // We may be making calls into the engine to get threads, stackframes, etc. // If we're the UI thread and the engine hangs then the whole GUI hangs. // Thus, we invoke it from another thread. if (Thread.currentThread() == mCards.getDisplay().getThread()) { engine.enqueue(new Runnable() { @Override// w w w . java2 s . com public void run() { setEngineSourceInternal(element, engine); } }, this); return; } } setEngineSourceInternal(element, engine); } }
From source file:com.arc.cdt.debug.seecode.ui.views.SeeCodeCommandView.java
License:Open Source License
@Override protected void setEngineSource(IStructuredSelection selection) { super.setEngineSource(selection); fSelectedSession = null;/*from w w w . j av a 2 s . co m*/ //If we're actually referencing the Launch (i.e. no particular target), and // we have a multi-process session, then send commands to the CMPD controller // so that they can be broadcast to every process, subject to focus qualifications. if (!selection.isEmpty()) { // At this point, we are NOT in the UI thread. Object element = selection.getFirstElement(); if (element instanceof ILaunch) { fSelectedSession = computeSessionFrom(element); } else { fCommandProcs.clear(); for (Object select : selection.toList()) { EngineInterface engine = Utilities.computeEngineFromSelection(select); if (engine != null) { ICommandProcessor cp = getCommandProcessor(engine); if (!fCommandProcs.contains(cp)) fCommandProcs.add(cp); } } } } }
From source file:com.archimatetool.editor.diagram.DiagramEditorFindReplaceProvider.java
License:Open Source License
private EditPart getFirstSelectedEditPart() { IStructuredSelection selection = (IStructuredSelection) fGraphicalViewer.getSelection(); EditPart editPart = (EditPart) selection.getFirstElement(); return (editPart instanceof AbstractDiagramPart) ? null : editPart; }
From source file:com.archimatetool.editor.views.tree.actions.CloseModelAction.java
License:Open Source License
@Override public void update(IStructuredSelection selection) { Object selected = selection.getFirstElement(); setEnabled(selected instanceof IArchimateModel); }
From source file:com.archimatetool.editor.views.tree.actions.NewFolderAction.java
License:Open Source License
@Override public void update(IStructuredSelection selection) { Object selected = selection.getFirstElement(); setEnabled(selected instanceof IFolder); }
From source file:com.archimatetool.editor.views.tree.actions.OpenDiagramAction.java
License:Open Source License
@Override public void update(IStructuredSelection selection) { Object selected = selection.getFirstElement(); setEnabled(selected instanceof IDiagramModel); }