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

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

Introduction

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

Prototype

public boolean isEmpty();

Source Link

Document

Returns whether this selection is empty.

Usage

From source file:com.google.dart.tools.ui.callhierarchy.RefreshElementAction.java

License:Open Source License

@Override
public void run() {
    IStructuredSelection selection = (IStructuredSelection) getSelection();
    if (selection.isEmpty()) {
        viewer.getPart().refresh();//from   w ww .ja v a2 s.c o  m
        return;
    }
    List<MethodWrapper> toExpand = new ArrayList<MethodWrapper>();
    for (Iterator<?> iter = selection.iterator(); iter.hasNext();) {
        MethodWrapper element = (MethodWrapper) iter.next();
        boolean isExpanded = viewer.getExpandedState(element);
        element.removeFromCache();
        if (isExpanded) {
            viewer.setExpandedState(element, false);
            toExpand.add(element);
        }
        viewer.refresh(element);
    }
    for (Iterator<MethodWrapper> iter = toExpand.iterator(); iter.hasNext();) {
        MethodWrapper elem = iter.next();
        viewer.setExpandedState(elem, true);
    }
}

From source file:com.google.dart.tools.ui.callhierarchy.RemoveFromViewAction.java

License:Open Source License

/**
 * Checks whether this action can be added for the selected element in the call hierarchy.
 * /*www . j a  v  a  2 s  . c  o  m*/
 * @return <code> true</code> if the action can be added, <code>false</code> otherwise
 */
protected boolean canActionBeAdded() {
    IStructuredSelection selection = (IStructuredSelection) getSelection();
    if (selection.isEmpty()) {
        return false;
    }

    Iterator<?> iter = selection.iterator();
    while (iter.hasNext()) {
        Object element = iter.next();
        if (!(element instanceof MethodWrapper)) {
            return false;
        }
    }

    TreeItem[] items = callHierarchyViewer.getTree().getSelection();
    for (int k = 0; k < items.length; k++) {
        if (!checkForChildren(items[k])) {
            return false;
        }
    }
    return true;
}

From source file:com.google.dart.tools.ui.internal.actions.SelectionConverter.java

License:Open Source License

/**
 * Converts the given structured selection into an array of Java elements. An empty array is
 * returned if one of the elements stored in the structured selection is not of type
 * <code>DartElement</code>//  w  ww. j a  v a  2  s.  co m
 */
public static DartElement[] getElements(IStructuredSelection selection) {
    if (!selection.isEmpty()) {
        DartElement[] result = new DartElement[selection.size()];
        int i = 0;
        for (Iterator<?> iter = selection.iterator(); iter.hasNext(); i++) {
            Object element = iter.next();
            if (!(element instanceof DartElement)) {
                return EMPTY_RESULT;
            }
            result[i] = (DartElement) element;
        }
        return result;
    }
    return EMPTY_RESULT;
}

From source file:com.google.dart.tools.ui.internal.filesview.FilesView.java

License:Open Source License

protected void fillContextMenu(IMenuManager manager) {
    IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();

    // New File/ New Folder 

    if (allElementsAreResources(selection)) {
        manager.add(createFileAction);/*w ww . j a va 2  s.  c o  m*/

    }
    if (selection.size() == 1 && selection.getFirstElement() instanceof IContainer) {
        manager.add(createFolderAction);
    }

    manager.add(createApplicationAction);

    // OPEN GROUP

    if (manager.getItems().length > 0) {
        manager.add(new Separator());
    }

    manager.add(OpenFolderHandler.createCommandAction(getSite().getWorkbenchWindow()));

    // Close folder action (aka Remove from Editor)
    if (!selection.isEmpty() && allElementsAreResources(selection)) {
        // Remove, iff non-empty selection, all elements are IResources
        if (allElementsAreProjects(selection)) {
            manager.add(hideContainerAction);
        }
    }

    // EDIT GROUP

    if (!selection.isEmpty() && allElementsAreResources(selection)) {

        manager.add(new Separator());

        manager.add(copyAction);

        // Copy File Path iff single element and is an IResource

        if (selection.size() == 1) {
            manager.add(copyFilePathAction);
        }

        manager.add(pasteAction);

        if (selection.size() == 1 && selection.getFirstElement() instanceof IFile) {
            manager.add(openAsTextAction);
        }

        manager.add(new Separator());
        manager.add(refreshAction);
    }

    // REFACTOR GROUP

    // Refactor iff all elements are IResources

    if (!selection.isEmpty() && allElementsAreResources(selection)) {
        manager.add(new Separator());
        if (selection.size() == 1) {
            manager.add(renameAction);
            manager.add(moveAction);
        }
        manager.add(cleanUpAction);
        manager.add(new Separator());
        ignoreResourceAction.updateLabel();
        manager.add(ignoreResourceAction);
        if (enableBuilderAction.shouldBeEnabled()) {
            enableBuilderAction.updateLabel();
            manager.add(enableBuilderAction);
        }
        manager.add(new Separator());
        manager.add(deleteAction);
        manager.add(new Separator());
    }
}

From source file:com.google.dart.tools.ui.internal.text.functions.DartElementProvider.java

License:Open Source License

@Override
public Object getInformation2(ITextViewer textViewer, IRegion subject) {
    if (fEditor == null) {
        return null;
    }//from   w  w w. jav a  2 s  .  co m

    try {
        if (fUseCodeResolve) {
            IStructuredSelection sel = SelectionConverter.getStructuredSelection(fEditor);
            if (!sel.isEmpty()) {
                return sel.getFirstElement();
            }
        }
        DartElement element = SelectionConverter.getElementAtOffset(fEditor);
        if (element != null) {
            return element;
        }

        return EditorUtility.getEditorInputDartElement(fEditor, false);
    } catch (DartModelException e) {
        return null;
    }
}

From source file:com.google.devtools.depan.platform.eclipse.ui.widgets.Selections.java

License:Apache License

/**
 * Use when type-coercion occurs late in the process flow.
 *//*from   w  ww  .  j av  a2 s .  c o m*/
public static Object getFirstObject(ISelection selection) {
    if (!(selection instanceof IStructuredSelection)) {
        return null;
    }
    IStructuredSelection choices = ((IStructuredSelection) selection);
    if (choices.isEmpty()) {
        return null;
    }
    return choices.getFirstElement();
}

From source file:com.googlecode.osde.internal.ui.wizards.export.WizardOpenSocialApplicationExportPage.java

License:Apache License

private void validate() {
    IStructuredSelection selection = (IStructuredSelection) projectList.getSelection();
    if (selection.isEmpty()) {
        setErrorMessage(null);//from www .  j a v  a2 s. c  om
        setMessage("Target project is not selected.");
        setPageComplete(false);
        return;
    } else {
        project = (IProject) selection.getFirstElement();
    }
    url = urlText.getText();
    if (StringUtils.isEmpty(url)) {
        setErrorMessage(null);
        setMessage("URL is empty.");
        setPageComplete(false);
        return;
    }
    output = outputText.getText();
    if (StringUtils.isEmpty(output)) {
        setErrorMessage(null);
        setMessage("Output is empty.");
        setPageComplete(false);
        return;
    }
    setErrorMessage(null);
    setMessage(null);
    setPageComplete(true);
}

From source file:com.hangum.tadpole.commons.admin.core.editors.useranddb.UserListComposite.java

License:Open Source License

/**
 * modify user//from w  ww .ja va  2s  . co m
 */
private void modifyUser() {
    IStructuredSelection ss = (IStructuredSelection) userListViewer.getSelection();
    if (!ss.isEmpty()) {
        UserDAO userDao = (UserDAO) ss.getFirstElement();

        ModifyUserDialog dialog = new ModifyUserDialog(getShell(), userDao);
        if (Dialog.OK == dialog.open()) {
            initUI();
        }

    }
}

From source file:com.hangum.tadpole.commons.admin.core.editors.useranddb.UserListComposite.java

License:Open Source License

/**
 * login history/*from   w  w  w  .j  a v  a2 s.c  o m*/
 */
private void loginHistory() {
    IStructuredSelection ss = (IStructuredSelection) userListViewer.getSelection();
    if (!ss.isEmpty()) {
        UserDAO userDao = (UserDAO) ss.getFirstElement();

        UserLoginHistoryDialog dialog = new UserLoginHistoryDialog(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), userDao);
        dialog.open();
    }
}

From source file:com.hangum.tadpole.commons.admin.core.editors.useranddb.UserListComposite.java

License:Open Source License

/**
 * /*from  ww w  . java2 s  . c o  m*/
 */
private void dbList() {
    IStructuredSelection ss = (IStructuredSelection) userListViewer.getSelection();
    if (!ss.isEmpty()) {
        UserDAO userDAO = ((UserDAO) ss.getFirstElement());

        try {
            DBMgntEditorInput userMe = new DBMgntEditorInput(PublicTadpoleDefine.USER_ROLE_TYPE.SYSTEM_ADMIN,
                    userDAO);
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(userMe,
                    DBMgmtEditor.ID);
        } catch (PartInitException e) {
            logger.error("Database Management editor", e); //$NON-NLS-1$

            Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$
            ExceptionDetailsErrorDialog.openError(null, Messages.get().Error, "", errStatus); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }
}