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.tools.s60.editor.actions.layers.RenameLayerAction.java

License:Open Source License

@Override
protected boolean calculateEnabled() {
    if (getImage() instanceof IAnimatedImage)
        return false;
    IStructuredSelection sel = getHost().getSelection();
    if (!sel.isEmpty() && sel.getFirstElement() instanceof ILayer) {
        return !((ILayer) sel.getFirstElement()).isBackground();
    }/* ww  w. ja  va2s  .  c o m*/
    return false;
}

From source file:com.nokia.tools.s60.editor.ui.dialogs.FailureListDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    if (title != null) {
        parent.getShell().setText(title);
    }/*from  w  ww  . jav a 2  s  .  c  om*/

    Composite composite = (Composite) super.createDialogArea(parent);
    Composite fc = new Composite(composite, SWT.NONE);
    fc.setLayoutData(new GridData(GridData.FILL_BOTH));

    GridLayout gridLayout = new GridLayout();
    fc.setLayout(gridLayout);

    Label msgLabel = new Label(fc, SWT.NONE);
    msgLabel.setText(Messages.FailureListDialog_message);

    TableViewer viewer = new TableViewer(fc, SWT.BORDER | SWT.FULL_SELECTION | SWT.VERTICAL);
    table = viewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    TableColumn tableColumn = new TableColumn(table, SWT.NONE);
    tableColumn.setWidth(25);
    TableColumn tableColumn1 = new TableColumn(table, SWT.NONE);
    tableColumn1.setWidth(500);
    tableColumn1.setText(Messages.FailureListDialog_element_lbl);
    TableColumn tableColumn2 = new TableColumn(table, SWT.NONE);
    tableColumn2.setWidth(300);
    tableColumn2.setText(Messages.FailureListDialog_detail_lbl);
    table.setLayoutData(new GridData(600, 200));

    new Label(fc, SWT.NONE);

    Label detailLabel = new Label(fc, SWT.NONE);
    detailLabel.setText(Messages.FailureListDialog_description_lbl);

    detail = new StyledText(fc, SWT.BORDER | SWT.VERTICAL | SWT.HORIZONTAL);
    GridData gridData = new GridData();
    gridData.grabExcessHorizontalSpace = false;
    gridData.verticalAlignment = org.eclipse.swt.layout.GridData.FILL;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
    gridData.heightHint = 200;
    gridData.widthHint = 600;
    detail.setLayoutData(gridData);

    viewer.setContentProvider(new IStructuredContentProvider() {
        public Object[] getElements(Object inputElement) {
            if (inputElement instanceof List) {
                return ((List) inputElement).toArray();
            }
            return null;
        }

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });

    viewer.setLabelProvider(new ITableLabelProvider() {
        Image err_image = S60WorkspacePlugin.getImageDescriptor("icons/error_tsk.gif").createImage();

        Image warn_image = S60WorkspacePlugin.getImageDescriptor("icons/warn_tsk.gif").createImage();

        Image info_image = S60WorkspacePlugin.getImageDescriptor("icons/info_tsk.gif").createImage();

        public Image getColumnImage(Object element, int columnIndex) {
            if (columnIndex == 0) {
                ESeverity severity = (((IFailure) element).getSeverity());
                if (ESeverity.INFO == severity) {
                    return info_image;
                } else if (ESeverity.WARN == severity) {
                    return warn_image;
                } else if (ESeverity.ERROR == severity) {
                    return err_image;
                }
            }
            return null;
        }

        public String getColumnText(Object element, int columnIndex) {
            if (columnIndex == 1) {
                return ((IFailure) element).getSource();
            }

            if (columnIndex == 2) {
                return ((IFailure) element).getMessage();
            }
            return null;
        }

        public void addListener(ILabelProviderListener listener) {
        }

        public void dispose() {
            err_image.dispose();
            warn_image.dispose();
            info_image.dispose();
        }

        public boolean isLabelProperty(Object element, String property) {
            return false;
        }

        public void removeListener(ILabelProviderListener listener) {
        }

    });

    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            if (sel.isEmpty()) {
                detail.setText("");
            } else {
                IFailure f = (IFailure) sel.getFirstElement();
                detail.setText(f.getDetail());
            }
        }
    });

    viewer.setInput(failures);

    viewer.setSelection(new StructuredSelection(failures.get(0)));

    return composite;
}

From source file:com.nokia.tools.s60.editor.ui.views.ActiveLayersPage.java

License:Open Source License

public void selectionChanged(SelectionChangedEvent event) {

    // update action toolbar
    IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
    if (selection.getFirstElement() instanceof ILayer) {
        layersViewAddEffectDropDown.setEnabled(true);
    } else {//w w w . j  a v a 2  s.  c  o  m
        layersViewAddEffectDropDown.setEnabled(false);
    }

    if (selection.getFirstElement() instanceof ILayerEffect) {
        EffectControlsEditorPage page = getEffectControlsEditorPage();
        if (page != null) {
            page.inputChanged((ILayerEffect) ((IStructuredSelection) event.getSelection()).getFirstElement());
        }
    } else {
        EffectControlsEditorPage page = getEffectControlsEditorPage();
        if (page != null) {
            page.inputChanged(null);
        }
    }
    if (selection.isEmpty()) {
        fireEffectSelection(null);
        fireLayerSelection(null);
    } else {
        if (selection.getFirstElement() instanceof ILayer) {
            fireEffectSelection(null);
            fireLayerSelection((ILayer) selection.getFirstElement());
        } else if (selection.getFirstElement() instanceof ILayerEffect) {
            fireLayerSelection(null);
            fireEffectSelection((ILayerEffect) selection.getFirstElement());
        }
    }
}

From source file:com.nokia.tools.s60.editor.ui.views.AddEffectDropDown.java

License:Open Source License

private void _build() {
    IStructuredSelection sel = (IStructuredSelection) page.getSelection();
    if (!sel.isEmpty()) {
        if (sel.getFirstElement() instanceof ILayer) {
            ILayer layer = (ILayer) sel.getFirstElement();
            List<ILayerEffect> effects = layer.getLayerEffects();
            final List<ILayerEffect> availableEffects = layer.getAvailableLayerEffects();
            Separator betweenLayerSep = null;
            boolean actionAdded = false;
            for (ILayerEffect a : effects) {
                AddEffectAction action = new AddEffectAction(a, availableEffects);
                if (action.isEnabled()) {
                    //                     separator before  ChannelBlend
                    if (actionAdded)
                        if (a.getName().equals(IMediaConstants.CHANNELBLENDING)
                                || a.getName().equals(IMediaConstants.ALPHABLENDING)) {
                            if (betweenLayerSep == null) {
                                betweenLayerSep = new Separator();
                                betweenLayerSep.fill(menu, -1);
                            }/*from   w  ww.j av  a2  s. co m*/
                        }
                    ActionContributionItem item = new ActionContributionItem(action);
                    item.fill(menu, -1);
                    actionAdded = true;
                }
            }
        }
    }
}

From source file:com.nokia.tools.s60.views.ResourceViewPage.java

License:Open Source License

/**
 * shows and selects element (group), that contains item in selection
 * //from  www  .j a  v  a2s .c  o  m
 * @param selection
        
 */
public void showSelection(IStructuredSelection sel) {
    if (inputs == null)
        return;
    if (!sel.isEmpty() && sel.getFirstElement() instanceof ScreenEditorPart) {
        return;
    }

    Object data = sel.isEmpty() ? null : sel.getFirstElement();
    if (sel.getFirstElement() instanceof DiagramGraphicalEditPart) {
        data = ((DiagramGraphicalEditPart) sel.getFirstElement()).getChildren().get(0);
    }
    // List<Object> iconViewSel = new ArrayList<Object>();
    IContentData modelItem = findModelItem(data);

    // iconViewSel.add(modelItem);

    if (modelItem instanceof ThemeScreenData) {
        // click on the editor screen - do not clean selection
        return;
    }

    setInputAsCollapsed();

    // clears the old selected item
    clearSelection();

    IResourceViewerSelectionHelper2 helper = getResourceSelectionHelper(modelItem);

    if (modelItem != null && (selectedIAL == null
            || !((String) selectedIAL.getData()).equals(modelItem.getRoot().getType()))) {

        IEmbeddedEditorDescriptor desc = null;
        if (null != modelItem.getRoot())
            desc = ExtensionManager.getEmbeddedEditorDescriptorByContentType(modelItem.getRoot().getType());

        if (null != desc) {
            IEmbeddedEditorCustomizer customizer = desc.getEmbeddedEditorCustomizer();
            for (ImageLabel label : ials) {
                if (((String) label.getText()).equals(customizer.getCategoryName(modelItem.getRoot()))) {
                    setSelectedThumb(label, false);
                }
            }
        } else {
            for (ImageLabel label : ials) {
                if (((String) label.getData()).equals(modelItem.getRoot().getType())) {
                    setSelectedThumb(label, false);
                }
            }
        }
    }
    if (modelItem != null && (selectedIAL != null
            && ((String) selectedIAL.getData()).equals(modelItem.getRoot().getType()))) {
        String modelItemName = modelItem.getName();
        boolean selectedIALisWantedIAL = false;

        if (inputs.size() > 0 && inputs.get(0).getGroups().size() > 0) {
            for (IResourceTableCategoryItem cat : inputs.get(0).getGroups().get(0).getCategories()) {
                if (cat instanceof ResourceTableCategory) {
                    if (cat.getName().equals(modelItemName)) {
                        selectedIALisWantedIAL = true;
                        break;
                    }
                }
            }
        }

        if (selectedIALisWantedIAL) {
            setSelectedThumb(selectedIAL, false);
        } else {

            IEmbeddedEditorDescriptor desc = ExtensionManager
                    .getEmbeddedEditorDescriptorByContentType(modelItem.getRoot().getType());
            if (null != desc) {
                IEmbeddedEditorCustomizer customizer = desc.getEmbeddedEditorCustomizer();
                for (ImageLabel label : ials) {
                    if (((String) label.getText()).equals(customizer.getCategoryName(modelItem.getRoot()))) {
                        setSelectedThumb(label, false);
                    }
                }
            } else {
                for (ImageLabel label : ials) {
                    if (((String) label.getData()).equals(modelItem.getRoot().getType())) {
                        setSelectedThumb(label, false);
                    }
                }
            }
        }

    } else if (selectedIAL != null) {
        setSelectedThumb(selectedIAL, false);
    }

    if (helper != null) {
        ResourceTableCategory cat = helper.getCategoryToPin(inputs, modelItem);
        if (cat != null) {

            if (selectedCategory != null) {
                selectedCategory.setExtracted(false);
                selectedCategory.getParent().setExtracted(false);
                selectedCategory = (ResourceTableCategory) cat;
            } else {
                selectedCategory = (ResourceTableCategory) cat;
            }
            if (!(selectedCategory instanceof ColorResourceTableCategory)) {
                for (int i = 0; i < selectedCategory.getItems().size(); i++) {
                    if (modelItem.getParent().getName().equals(selectedCategory.getItems().get(i).getName())) {
                        selectedItem = selectedCategory.getItems().get(i);
                        break;
                    }
                }
            }
            ((ResourceTableCategory) cat).setExtracted(true);
            ((ResourceTableCategory) cat).getParent().setExtracted(true);
            if (selectedCategory != null) {
                if (!(selectedCategory instanceof ColorResourceTableCategory || selectedItem == null)) {
                    selectedCategory = null;
                    selectedGroup = null;
                }
            }
        }
    }
    // iconViewSel.add(Boolean.FALSE);
    // refreshIconView(new StructuredSelection(iconViewSel), false);

    // refresh even when no selection is there, to clear the selection
    refreshKeepingIndex();
    if (selectedItem != null) {
        scrollToVisible(selectedItem);
    }

    //update the new selection
    setSelectionWithoutUpdatingListeners(sel);
}

From source file:com.nokia.tools.s60ct.confml.actions.RemoveSequenceItemsAction.java

License:Open Source License

@Override
public void initSelectionListener() {
    selectionListener = new ISelectionListener() {

        public void selectionChanged(IWorkbenchPart part, ISelection selection) {

            if (selection instanceof IStructuredSelection) {
                IStructuredSelection ss = (IStructuredSelection) selection;
                if (!ss.isEmpty()) {
                    Object[] array = ss.toArray();
                    for (int i = 0; i < array.length; i++) {
                        Object object = array[i];
                        if (object instanceof ESimpleSetting || object instanceof EResourceSetting) {
                            ESequenceSettingImpl seqItem = findSeqSetting((EObject) object);
                            if (seqItem != null) {
                                if (widget != null && !widget.isDisposed()
                                        && widget.getData() instanceof ESetting) {
                                    ESetting setting = ((ESetting) widget //WRONG?!?
                                            .getData());
                                    if (seqItem == setting) {
                                        setEnabled(true);
                                        return;
                                    } else {
                                        setEnabled(false);
                                        return;
                                    }/*from w  w  w  . j  a v  a  2  s.c  om*/
                                }
                            }
                        }
                    }
                }
            }
            //   setEnabled(false);
        }
    };
    //   this.addListenerObject(selectionListener);
}

From source file:com.nokia.tools.s60ct.confml.commands.AbstractSelectionCommand.java

License:Open Source License

public boolean isSelectionOK() {

    ISelectionProvider provider = getEditor();
    if (provider != null) {
        IStructuredSelection selection = (IStructuredSelection) provider.getSelection();
        if (!selection.isEmpty() && selection.getFirstElement().equals(getModel())) {
            return true;
        } else {/*w w  w  .ja  va 2  s . c  om*/
            return false;
        }
    }

    return true;
}

From source file:com.nokia.tools.s60ct.resources.resources.ResourceUtil.java

License:Open Source License

/**
 * @param selection/*from  ww  w  . j a  va2 s. c o  m*/
 * @return Test if selection is from the same directory or not
 */
public static boolean checkSelectionForCopyOrMove(IStructuredSelection selection) {
    if (selection.isEmpty()) {
        return false;
    }
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection ss = (IStructuredSelection) selection;
        List list = ss.toList();

        if (list.size() == 1) {
            return true;
        }

        int size = list.size();
        for (int i = 0; i < size - 1; i++) {
            Object o1 = list.get(i);
            Object o2 = list.get(i + 1);

            if (o1 instanceof ResourceStorage && o2 instanceof ResourceStorage) {
                ResourceStorage rs1 = (ResourceStorage) o1;
                ResourceStorage rs2 = (ResourceStorage) o2;
                ELibraryElement o1fse = rs1.getFileSystemElement();
                ELibraryElement o2fse = rs2.getFileSystemElement();

                if (o1fse.eContainer() != o2fse.eContainer()) {
                    return false;
                }
            } else {
                return false;
            }
        }
    }
    return true;
}

From source file:com.nokia.tools.screen.ui.views.ResourcePage.java

License:Open Source License

/**
 * shows and selects element (group), that contains item in selection
 * //from  w w w.  ja  va2s.co m
 */
public void showSelection(IStructuredSelection sel) {

    if (viewer == null)
        return;

    Object data = sel.isEmpty() ? null : sel.getFirstElement();

    // IContentData modelItem = findModelItem(data, themeContent);
    IContentData modelItem = findModelItem(data);
    IResourceViewerSelectionHelper helper = viewer.getResourceSelectionHelper(modelItem);

    if (modelItem != null) {
        // find Task and ComponentGroup, that contains selection
        IContentData task = helper.findTaskContaining(modelItem);

        if (task == null)
            return;

        final IContentData compGroup = helper.findGroupContaining(modelItem, task);
        final IContentData minorGroup = helper.findMinorGroup(modelItem, task, compGroup);

        // selects appropriate elements
        if (compGroup != null && minorGroup != null) {
            suppressViewerEvents = true;
            try {
                final Map map = viewer.getVisualPartMap();

                Iterator it = map.values().iterator();
                while (it.hasNext()) {
                    EditPart element = (EditPart) it.next();
                    if (element.getModel() instanceof CombinedTemplateCreationEntry) {
                        CombinedTemplateCreationEntry entry = (CombinedTemplateCreationEntry) element
                                .getModel();
                        if (entry.getTemplate() == compGroup || entry.getTemplate() == minorGroup) {

                            // set viewer selection is the same no
                            // action
                            if (viewer.getSelectedEditParts().size() == 0
                                    || viewer.getSelectedEditParts().get(0) != element) {
                                viewer.reveal(element);
                                viewer.select(element);
                                viewer.setActiveTool(entry);
                            }

                            if (viewer
                                    // enter only if the section supports
                                    // position viewer
                                    .getResourceSelectionHelper(compGroup).supportsPositionViewer()) {
                                // update also selection in position viewer
                                if (minorGroup != null) {
                                    it = positionViewer.getVisualPartMap().values().iterator();
                                    while (it.hasNext()) {
                                        element = (EditPart) it.next();
                                        if (element.getModel() instanceof CombinedTemplateCreationEntry) {
                                            entry = (CombinedTemplateCreationEntry) element.getModel();
                                            if (entry.getTemplate() == minorGroup) {
                                                if (positionViewer.getSelectedEditParts().size() == 0
                                                        || positionViewer.getSelectedEditParts()
                                                                .get(0) != element) {
                                                    IResourceSection section = viewer
                                                            .getResourceSection(modelItem);
                                                    if (section instanceof IResourceViewRectProvider) {
                                                        positionViewer.rectProvider = (IResourceViewRectProvider) section;
                                                    }
                                                    positionViewer.reveal(element);
                                                    _shouldRefreshIconView = false;
                                                    positionViewer.select(element);
                                                }

                                                List<Object> iconViewSel = new ArrayList<Object>();
                                                for (Iterator iter = sel.iterator(); iter.hasNext();) {
                                                    IContentData mItem = findModelItem(iter.next());
                                                    if (mItem != null) {

                                                        iconViewSel.add(mItem);
                                                    }
                                                }

                                                /*
                                                 * add parameter
                                                 * 'Boolean.FALSE' to
                                                 * selection so that icon
                                                 * view will be notified tot
                                                 * to try synchronize with
                                                 * editor and stuck in
                                                 * event-loop
                                                 */
                                                _shouldRefreshIconView = true;
                                                iconViewSel.add(Boolean.FALSE);
                                                refreshIconView(new StructuredSelection(iconViewSel), false);
                                                return;
                                            }
                                        }
                                    }
                                }
                            } else { // the section does not support
                                // position viewer, clear it
                                updatePositionViewer(null);
                                refreshIconView(new StructuredSelection(new Object[] { Boolean.FALSE }), false);
                            }
                            return;
                        }
                    }
                }
            } finally {
                suppressViewerEvents = false;
            }
        }
    } else {

        refreshIconView(new StructuredSelection(new Object[] { Boolean.FALSE }), false);
        return;
    }
}

From source file:com.nokia.tools.screen.ui.wizards.ExportWizardPage1.java

License:Open Source License

private void listOpenWorkspaceProjects() {
    lstProjects.removeAll();//  ww  w .  j  av a  2  s. co  m
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    Arrays.sort(projects, new Comparator<IProject>() {
        /*
         * (non-Javadoc)
         * 
         * @see java.util.Comparator#compare(T, T)
         */
        public int compare(IProject o1, IProject o2) {
            return o1.getName().compareToIgnoreCase(o2.getName());
        }
    });

    for (IProject project : projects) {
        try {
            if (project.isOpen()) {
                lstProjects.add(project.getName());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (lstProjects.getItemCount() > 0) {
        lstProjects.select(0);
        strSelProjects = new String[] { lstProjects.getItem(0) };

        IStructuredSelection sel = ((ExportWizard) getWizard()).getSelection();
        if (sel != null && !sel.isEmpty()) {
            if (sel.getFirstElement() instanceof IResource) {
                IProject project = ((IResource) sel.getFirstElement()).getProject();
                int idx = Arrays.asList(lstProjects.getItems()).indexOf(project.getName());
                if (idx >= 0) {
                    lstProjects.select(idx);
                    strSelProjects = new String[] { lstProjects.getItem(idx) };
                }
            }
        }
    }

}