Example usage for org.eclipse.jface.viewers IStructuredSelection getFirstElement

List of usage examples for org.eclipse.jface.viewers IStructuredSelection getFirstElement

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers IStructuredSelection getFirstElement.

Prototype

public Object getFirstElement();

Source Link

Document

Returns the first element in this selection, or null if the selection is empty.

Usage

From source file:com.aptana.git.ui.internal.history.CommitFileDiffViewer.java

License:Open Source License

CommitFileDiffViewer(final Composite parent, final GitHistoryPage historyPage) {
    super(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);

    final Table rawTable = getTable();
    rawTable.setHeaderVisible(true);/*from   w ww.  ja  v  a2  s .co  m*/
    rawTable.setLinesVisible(false);

    final TableLayout layout = new TableLayout();
    rawTable.setLayout(layout);
    createColumns(rawTable, layout);

    setContentProvider(new CommitDiffContentProvider());
    setLabelProvider(new SingleCommitLabelProvider());

    addOpenListener(new IOpenListener() {
        public void open(final OpenEvent event) {
            final ISelection s = event.getSelection();
            if (s.isEmpty() || !(s instanceof IStructuredSelection))
                return;
            final IStructuredSelection iss = (IStructuredSelection) s;
            final Diff d = (Diff) iss.getFirstElement();
            showTwoWayFileDiff(d);
        }
    });

    MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(new IMenuListener() {
        public void menuAboutToShow(IMenuManager manager) {
            manager.add(new OpenRevisionAction(historyPage.getSite().getPage(), getTable()));
            // Other plug-ins can contribute there actions here
            manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
        }
    });

    Menu menu = menuMgr.createContextMenu(getControl());
    getControl().setMenu(menu);
}

From source file:com.aptana.git.ui.internal.history.GitHistoryPage.java

License:Open Source License

private void attachCommitSelectionChanged() {
    graph.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(final SelectionChangedEvent event) {
            final ISelection s = event.getSelection();
            if (s.isEmpty() || !(s instanceof IStructuredSelection)) {
                commentViewer.setText(""); //$NON-NLS-1$
                fileViewer.setInput(null);
                return;
            }/*from w  w w .j a  va2 s . c om*/

            final IStructuredSelection sel = ((IStructuredSelection) s);
            GitCommit commit = (GitCommit) sel.getFirstElement();
            // TODO If we know the user's github project URL, we can point them to the GitHub URL for this instead
            // of generating our own!
            commentViewer.setText(commitToHTML(commit));
            fileViewer.setInput(commit);
        }
    });
}

From source file:com.aptana.ide.core.ui.actions.ActionDelegate.java

License:Open Source License

/**
 * Returns a valid selection// ww w. j  a va  2s . c  o m
 * 
 * @param selection
 * @return Object
 */
protected Object getValidSingleSelection(ISelection selection) {
    if (selection instanceof IStructuredSelection == false) {
        return null;
    }

    IStructuredSelection structuredSelection = ((IStructuredSelection) selection);

    if (structuredSelection.size() > 1) {
        return null;
    }

    return structuredSelection.getFirstElement();
}

From source file:com.aptana.ide.core.ui.dialogs.TableEditor.java

License:Open Source License

/**
 * Remove the type from the table//from ww w  . j a  v  a  2 s. co m
 */
public void editSelectedResourceType() {
    ISelection selection = _viewer.getSelection();
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection select = (IStructuredSelection) selection;
        Object o = select.getFirstElement();
        for (int i = 0; i < _listeners.size(); i++) {
            IAddItemListener l = _listeners.get(i);
            o = l.editItem(o);
            refreshTable();
        }
    }
}

From source file:com.aptana.ide.core.ui.editors.FileCompareEditorInput.java

License:Open Source License

/**
 * @see org.eclipse.compare.CompareEditorInput#createDiffViewer(org.eclipse.swt.widgets.Composite)
 *///from   ww w.  j  a va 2 s . com
public Viewer createDiffViewer(Composite parent) {
    fDiffViewer = new DiffTreeViewer(parent, getCompareConfiguration()) {
        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 te = ((MyDiffNode) element).getId();
                        if (te != null)
                            enable = !ITypedElement.FOLDER_TYPE.equals(te.getType());
                    } else
                        enable = true;
                }
            }
            fOpenAction.setEnabled(enable);

            manager.add(fOpenAction);

            super.fillContextMenu(manager);
        }
    };
    return fDiffViewer;
}

From source file:com.aptana.ide.debug.internal.ui.actions.EditDetailFormatterAction.java

License:Open Source License

/**
 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
 *///from   ww w . j  a va2 s .c om
public void run(IAction action) {
    IStructuredSelection selection = getCurrentSelection();
    if (selection == null || selection.size() != 1) {
        return;
    }
    Object element = selection.getFirstElement();
    String typeName;
    try {
        if (element instanceof IJSVariable) {
            typeName = ((IJSVariable) element).getReferenceTypeName();
        } else {
            return;
        }
    } catch (DebugException e) {
        IdeLog.logError(DebugUiPlugin.getDefault(), StringUtils.EMPTY, e);
        return;
    }
    JSDetailFormattersManager detailFormattersManager = JSDetailFormattersManager.getDefault();
    DetailFormatter detailFormatter = detailFormattersManager.getAssociatedDetailFormatter(typeName);
    if (new DetailFormatterDialog(DebugUiPlugin.getActivePage().getWorkbenchWindow().getShell(),
            detailFormatter, null, false, true).open() == Window.OK) {
        detailFormattersManager.setAssociatedDetailFormatter(detailFormatter);
        refreshCurrentSelection();
    }
}

From source file:com.aptana.ide.debug.internal.ui.actions.NewDetailFormatterAction.java

License:Open Source License

/**
 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
 *//*from  w ww .  ja v  a 2  s . co m*/
public void run(IAction action) {
    IStructuredSelection selection = getCurrentSelection();
    if (selection == null || selection.size() != 1) {
        return;
    }
    Object element = selection.getFirstElement();
    String typeName;
    try {
        if (element instanceof IJSVariable) {
            typeName = ((IJSVariable) element).getReferenceTypeName();
        } else {
            return;
        }
    } catch (DebugException e) {
        IdeLog.logError(DebugUiPlugin.getDefault(), StringUtils.EMPTY, e);
        return;
    }
    JSDetailFormattersManager detailFormattersManager = JSDetailFormattersManager.getDefault();
    DetailFormatter detailFormatter = new DetailFormatter(typeName, StringUtils.EMPTY, true);
    if (new DetailFormatterDialog(DebugUiPlugin.getActivePage().getWorkbenchWindow().getShell(),
            detailFormatter, null, true, false).open() == Window.OK) {
        detailFormattersManager.setAssociatedDetailFormatter(detailFormatter);
        refreshCurrentSelection();
    }
}

From source file:com.aptana.ide.debug.internal.ui.actions.NewWatchpointAction.java

License:Open Source License

public void run(IAction action) {
    IStructuredSelection selection = getCurrentSelection();
    if (selection == null || selection.size() != 1) {
        return;/*from   w w  w .jav a 2 s .  c  o  m*/
    }
    Object element = selection.getFirstElement();
    try {
        if (element instanceof IJSVariable) {
            JSDebugModel.createWatchpoint((IJSVariable) element);
            refreshCurrentSelection();
        }
    } catch (CoreException e) {
        IdeLog.logError(DebugUiPlugin.getDefault(), StringUtils.EMPTY, e);
        return;
    }
}

From source file:com.aptana.ide.debug.internal.ui.actions.OpenScriptSourceAction.java

License:Open Source License

/**
 * @see org.eclipse.ui.actions.SelectionProviderAction#selectionChanged(org.eclipse.jface.viewers.IStructuredSelection)
 *//*from   www  .j  ava2s  .co m*/
public void selectionChanged(IStructuredSelection selection) {
    if (selection.size() == 1) {
        Object element = selection.getFirstElement();
        if (element instanceof IJSScriptElement) {
            scriptElement = (IJSScriptElement) element;
            String location = scriptElement.getLocation();
            if (location != null) {
                setEnabled(true);
                int lineNumber = scriptElement.getBaseLine();
                Object sourceElement = DebugUITools.lookupSource(scriptElement, getSourceLocator(scriptElement))
                        .getSourceElement();
                IEditorInput editorInput = SourceDisplayUtil.getEditorInput(sourceElement);
                if (editorInput != null) {
                    IEditorPart editorPart = SourceDisplayUtil.findEditor(editorInput);
                    if (editorPart != null) {
                        SourceDisplayUtil.revealLineInEditor(editorPart, lineNumber);
                    }
                }
                return;
            }
        }
    } else {
        scriptElement = null;
    }
    setEnabled(false);
}

From source file:com.aptana.ide.debug.internal.ui.actions.RemoveDetailFormatterAction.java

License:Open Source License

/**
 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
 *///from   ww w.j  a  v a2 s.  c  om
public void run(IAction action) {
    IStructuredSelection selection = getCurrentSelection();
    if (selection == null || selection.size() != 1) {
        return;
    }
    Object element = selection.getFirstElement();
    String typeName;
    try {
        if (element instanceof IJSVariable) {
            typeName = ((IJSVariable) element).getReferenceTypeName();
        } else {
            return;
        }
    } catch (DebugException e) {
        IdeLog.logError(DebugUiPlugin.getDefault(), StringUtils.EMPTY, e);
        return;
    }
    JSDetailFormattersManager detailFormattersManager = JSDetailFormattersManager.getDefault();
    DetailFormatter detailFormatter = detailFormattersManager.getAssociatedDetailFormatter(typeName);
    detailFormattersManager.removeAssociatedDetailFormatter(detailFormatter);
    refreshCurrentSelection();
}