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.nokia.carbide.cpp.internal.project.ui.editors.images.SelectOrAddImagesDialogBase.java

License:Open Source License

/**
 * Handle the change of selection inside the thumbnail viewer.
 * @param selection//from w ww .  ja  va  2s .com
 */
protected void handleThumbnailViewerSelectionChanged(IStructuredSelection selection) {
    selectedImages = selection.toList();
    Button okButton = getButton(IDialogConstants.OK_ID);
    if (okButton != null)
        okButton.setEnabled(selection != null && !selection.isEmpty());
}

From source file:com.nokia.carbide.cpp.internal.project.ui.views.OpenFileGroup.java

License:Open Source License

public void fillContextMenu(IMenuManager menu) {

    IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
    boolean onlyFilesSelected = !selection.isEmpty() && allResourcesAreOfType(selection, IResource.FILE);

    if (onlyFilesSelected) {
        openFileAction.selectionChanged(selection);
        menu.add(openFileAction);// w w w  .  j av  a2s  . co m
        fillOpenWithMenu(menu, selection);
    }

    if (selection.size() == 1 && selection.getFirstElement() instanceof INonWorkspaceFileEntry) {
        openNonWorkspaceFileAction.selectionChanged(selection);
        menu.add(openNonWorkspaceFileAction);
    }

    if (selection.size() == 1 && selection.getFirstElement() instanceof IMBMMIFFileEntry) {
        openMBMMIFAction.selectionChanged(selection);
        menu.add(openMBMMIFAction);
    }
}

From source file:com.nokia.carbide.cpp.internal.project.ui.views.OpenProjectGroup.java

License:Open Source License

/**
 * Adds the open project, close project and refresh resource actions to the
 * context menu./*from  w w w  .  j av  a  2s.c  om*/
 * <p>
 * refresh-no closed project selected
 * </p>
 * <p>
 * Both the open project and close project action may be on the menu at the
 * same time.
 * </p>
 * <p>
 * No disabled action should be on the context menu.
 * </p>
 * 
 * @param menu
 *            context menu to add actions to
 */
public void fillContextMenu(IMenuManager menu) {
    IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
    boolean isProjectSelection = true;
    boolean hasOpenProjects = false;
    boolean hasClosedProjects = false;
    boolean hasBuilder = true; // false if any project is closed or does not have builder 
    Iterator resources = selection.iterator();

    while (resources.hasNext()
            && (!hasOpenProjects || !hasClosedProjects || hasBuilder || isProjectSelection)) {
        Object next = resources.next();
        IProject project = null;

        if (next instanceof IProject) {
            project = (IProject) next;
        } else if (next instanceof IAdaptable) {
            project = (IProject) ((IAdaptable) next).getAdapter(IProject.class);
        }

        if (project == null) {
            isProjectSelection = false;
            continue;
        }
        if (project.isOpen()) {
            hasOpenProjects = true;
            if (hasBuilder && !hasBuilder(project)) {
                hasBuilder = false;
            }
        } else {
            hasClosedProjects = true;
            hasBuilder = false;
        }
    }

    if (!selection.isEmpty() && isProjectSelection && !ResourcesPlugin.getWorkspace().isAutoBuilding()
            && hasBuilder) {
        // Allow manual incremental build only if auto build is off.
        buildAction.selectionChanged(selection);
        menu.add(buildAction);
        cleanAction.selectionChanged(selection);
        menu.add(cleanAction);
    }

    if (!hasClosedProjects) {
        refreshAction.selectionChanged(selection);
        menu.add(refreshAction);
    }
    if (isProjectSelection) {
        if (hasClosedProjects) {
            openProjectAction.selectionChanged(selection);
            menu.add(openProjectAction);
        }
        if (hasOpenProjects) {
            closeProjectAction.selectionChanged(selection);
            menu.add(closeProjectAction);
            closeUnrelatedProjectsAction.selectionChanged(selection);
            menu.add(closeUnrelatedProjectsAction);
        }
    }
    menu.add(new Separator());
    menu.add(new GroupMarker(BUILD_GROUP_MARKER));
    menu.add(new GroupMarker(BUILD_GROUP_MARKER_END));
}

From source file:com.nokia.carbide.cpp.internal.project.ui.views.RefactorActionGroup.java

License:Open Source License

@Override
public void fillContextMenu(IMenuManager menu) {
    IStructuredSelection celements = (IStructuredSelection) getContext().getSelection();
    IStructuredSelection selection = SelectionConverter.convertSelectionToResources(celements);

    boolean anyResourceSelected = !selection.isEmpty() && SelectionConverter.allResourcesAreOfType(selection,
            IResource.PROJECT | IResource.FOLDER | IResource.FILE);

    copyAction.selectionChanged(selection);
    menu.add(copyAction);/* ww w . java 2  s  .co  m*/
    pasteAction.selectionChanged(selection);
    menu.add(pasteAction);

    if (anyResourceSelected) {
        deleteAction.selectionChanged(selection);
        menu.add(deleteAction);
        moveAction.selectionChanged(selection);
        menu.add(moveAction);
        renameAction.selectionChanged(selection);
        menu.add(renameAction);
    }
}

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  ww . ja  v  a  2s.  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  www .  j  a  v a  2 s. c o 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.cpp.internal.project.ui.views.SymbianProjectNavigatorView.java

License:Open Source License

/**
 * Handles an open event from the viewer.
 * Opens an editor on the selected element(s).
 *
 * @param event the open event//from www. java2 s  .c  o m
 */
protected void handleOpen(OpenEvent event) {
    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    if (!selection.isEmpty() && selection.getFirstElement() instanceof IMBMMIFFileEntry) {
        editMBMMIFFile(selection);
    } else {
        getActionGroup().runDefaultAction(selection);
    }

}

From source file:com.nokia.carbide.cpp.internal.project.ui.wizards.NewSymbianOSCppClassWizard.java

License:Open Source License

@Override
public void addPages() {
    String title = Messages.getString("NewSymbianOSCppClassWizard.ChooseProjectPageTitle"); //$NON-NLS-1$
    String description = Messages.getString("NewSymbianOSCppClassWizard.ChooseProjectPageDesc"); //$NON-NLS-1$
    chooseProjectPage = new ChooseProjectPage(title, description);

    title = Messages.getString("NewSymbianOSCppClassWizard.ChooseClassLocationTitle"); //$NON-NLS-1$
    description = Messages.getString("NewSymbianOSCppClassWizard.ChooseClassLocationDesc"); //$NON-NLS-1$
    chooseClassLocationPage = new ClassNameAndLocationPage(title, description);

    IStructuredSelection selection = getSelection();
    if (!selection.isEmpty()) {
        Object object = selection.getFirstElement();
        if (object instanceof ICProject)
            object = ((ICProject) object).getProject();
        if (object instanceof IProject)
            chooseProjectPage.setInitialSelection((IProject) object);
    }//from  ww w.  java2 s .c  o  m
    addPage(chooseProjectPage);
    addPage(chooseClassLocationPage);
    super.addPages();
}

From source file:com.nokia.carbide.cpp.uiq.components.sbbCustomizer.SBBCustomizerComposite.java

License:Open Source License

/**
 * @param parent/*  ww  w . j  a v a2  s .  c  o  m*/
 * @param style
 * @param instance 
 */
public SBBCustomizerComposite(Composite parent, int style, EObject instance) {
    super(parent, style);
    IComponentInstance componentInstance = (IComponentInstance) EcoreUtil.getRegisteredAdapter(instance,
            IComponentInstance.class);
    component = componentInstance.getComponent();

    String[] styles = SBBLayoutData.getComponentSBBTypes(component);
    initData(styles);

    getThumbnailViewer().addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (!selection.isEmpty()) {
                String value = (String) selection.getFirstElement();
                ThumbData thumbData = dataMap.get(value);
                getDescriptionText().setText(thumbData.description);
                selectedValue = thumbData;
            }
        }
    });
    getThumbnailViewer().setContentProvider(new ArrayContentProvider());
    getThumbnailViewer().setLabelProvider(new LabelProvider() {
        public Image getImage(Object element) {
            String value = (String) element;
            ThumbData thumbData = dataMap.get(value);
            return thumbData.image;
        }

        public String getText(Object element) {
            String value = (String) element;
            ThumbData thumbData = dataMap.get(value);
            return thumbData.caption;
        }
    });
    getThumbnailViewer().setInput(dataMap.keySet());
    getThumbnailViewer().getComposite().setFocus();

    setViewerTitle(Messages.getString("SBBCustomizerComposite.ViewerTitle")); //$NON-NLS-1$
    setDescriptionTitle(Messages.getString("SBBCustomizerComposite.DescriptionTitle")); //$NON-NLS-1$
}

From source file:com.nokia.carbide.cpp.uiq.ui.vieweditor.CommandsPage.java

License:Open Source License

/**
 * Gets the object current selected/*from w  w w  .j  av a2s  .com*/
 * @return Object from the domain
 */
private Object getSelectionTree() {
    Object domain = null;
    IStructuredSelection selection = (IStructuredSelection) commandsTreeViewer.getSelection();
    if (!selection.isEmpty()) {
        domain = selection.getFirstElement();
    }
    return domain;
}