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

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

Introduction

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

Prototype

public int size();

Source Link

Document

Returns the number of elements selected in this selection.

Usage

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

License:Open Source License

/**
 * Returns a valid selection/* w  w  w . j a  v  a 2 s  . co 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.actions.ActionDelegate.java

License:Open Source License

/**
 * Returns a valid array of selections/*from   www  .java2  s. co  m*/
 * 
 * @param selection
 * @return Object[]
 */
protected Object[] getValidSelection(ISelection selection) {
    if (selection instanceof IStructuredSelection == false) {
        return null;
    }

    IStructuredSelection structuredSelection = ((IStructuredSelection) selection);

    if (structuredSelection.size() == 0) {
        return new Object[0];
    } else {
        return structuredSelection.toArray();
    }
}

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   w w  w. j  av  a  2  s .co  m
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)
 */// ww  w  . jav  a2s  . c  o 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 = 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  www.j a va  2 s .  com*/
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;/* www .  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)
 *///  w  ww.  j a  v a2 s  .c  o 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   w w  w.  java  2  s  .c o 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 = detailFormattersManager.getAssociatedDetailFormatter(typeName);
    detailFormattersManager.removeAssociatedDetailFormatter(detailFormatter);
    refreshCurrentSelection();
}

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

License:Open Source License

/**
 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
 *      org.eclipse.jface.viewers.ISelection)
 *//*from  w ww.  j  a  v  a  2s  .c  om*/
public void selectionChanged(IAction action, ISelection selection) {
    fSelection = null;
    if (!action.isEnabled()) {
        return;
    }
    int enabled = 0;
    int size = -1;
    if (selection instanceof IStructuredSelection) {
        fSelection = selection;
        IStructuredSelection sSelection = (IStructuredSelection) selection;
        size = sSelection.size();
        IExpressionManager manager = DebugPlugin.getDefault().getExpressionManager();
        Iterator iterator = sSelection.iterator();
        while (iterator.hasNext()) {
            IVariable variable = (IVariable) iterator.next();
            if (manager.hasWatchExpressionDelegate(variable.getModelIdentifier())) {
                enabled++;
            } else {
                break;
            }
        }
        if (enabled != size) {
            action.setEnabled(false);
        }
    } else if (selection instanceof ITextSelection) {
        fSelection = selection;
        ITextSelection tSelection = (ITextSelection) selection;
        if (tSelection.getLength() == 0) {
            action.setEnabled(false);
        }
    }
}

From source file:com.aptana.ide.debug.internal.ui.launchConfigurations.HttpServerSettingsTab.java

License:Open Source License

private void updatePage(IStructuredSelection selection) {
    fRemoveButton.setEnabled(!selection.isEmpty());
    fEditButton.setEnabled(selection.size() == 1);
}