Example usage for org.eclipse.jface.viewers StructuredSelection EMPTY

List of usage examples for org.eclipse.jface.viewers StructuredSelection EMPTY

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers StructuredSelection EMPTY.

Prototype

StructuredSelection EMPTY

To view the source code for org.eclipse.jface.viewers StructuredSelection EMPTY.

Click Source Link

Document

The canonical empty selection.

Usage

From source file:com.nokia.sdt.utils.ui.ThumbnailGridViewer.java

License:Open Source License

protected synchronized void inputChanged(Object input, Object oldInput) {
    super.inputChanged(input, oldInput);
    resetElements(input);//from   w  w  w .jav  a 2 s .  c  om
    setSelection(StructuredSelection.EMPTY);
    redraw();
}

From source file:com.nokia.tools.media.utils.timeline.impl.TreeTimeLine.java

License:Open Source License

public @Override void setSelectedRow(final ITimeLineRow row) {
    super.setSelectedRow(row);

    Runnable runnable = new Runnable() {
        public void run() {
            final int idx = Arrays.asList(getVisibleRows()).indexOf(row);
            if (idx < 0) {
                treeViewer.setSelection(StructuredSelection.EMPTY);
                return;
            }//from   ww w .ja  va2 s . c  o  m

            final TreeItem[] items = collectTreeItems();
            if (idx < items.length) {
                TreeItem[] selection = treeViewer.getTree().getSelection();
                if (selection.length == 0 || selection[0] != items[idx]) {
                    if (!treeViewer.getTree().isFocusControl()) {
                        treeViewer.getTree().setFocus();
                    }
                    treeViewer.setSelection(new StructuredSelection(items[idx].getData()));
                }
            }
        }
    };

    if (Display.getCurrent() != null) {
        runnable.run();
    } else {
        Display.getDefault().syncExec(runnable);
    }
}

From source file:com.nokia.tools.s60.editor.Series60EditorPart.java

License:Open Source License

private void activateViewer() {
    IWorkbenchPage page = getSite().getWorkbenchWindow().getActivePage();
    IWorkbenchPart activePart = page.getActivePart();
    if (activePart == this) {
        // we need to reactivate the editor in order to have
        // the workbench
        // selection service hooked into the graphical
        // viewer immediately,
        for (IViewReference ref : page.getViewReferences()) {
            IViewPart part = ref.getView(false);
            if (part != null) {
                ISelectionProvider provider = ((IViewSite) part.getSite()).getSelectionProvider();
                if (provider != null) {
                    // clears the selection to prevent from re-selecting and
                    // thus causing screen switching again
                    ((IViewSite) part.getSite()).getSelectionProvider().setSelection(StructuredSelection.EMPTY);
                }/*ww w . j  av a  2  s . c  o m*/
                page.activate(part);
                break;
            }
        }
    }

    if (page.getActiveEditor() != null) {
        page.activate(this);
    }
}

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

License:Open Source License

public ISelection getSelection() {
    IPage page = getCurrentPage();/* ww  w . j  a va 2 s .c  o m*/
    if (page instanceof ISelectionProvider) {
        return ((ISelectionProvider) page).getSelection();
    }
    return StructuredSelection.EMPTY;
}

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

License:Open Source License

/**
 * Called from resource view to set icon-set to be displayed
 */// ww  w .  j av  a  2  s  . c  o  m
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    if (!listenOnSelection || part instanceof IconView) {
        return;
    }

    //  selections from resource viewer
    // if (part instanceof ResourceViewPart || part == null) {
    // if (selection instanceof IStructuredSelection && !(part instanceof
    // IconView)) {
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection sel = (IStructuredSelection) selection;
        if (sel.size() == 0) {
            return;
        }

        // convert edit parts to content data
        // filters out the duplicates
        Set<Object> set = new HashSet<Object>(sel.size());
        for (Object object : sel.toArray()) {
            IContentData data = null;
            if (object instanceof EditPart || object instanceof IScreenElement) {
                data = findModelItem(object);
            } else if (object instanceof IContentData) {
                data = (IContentData) object;
            }
            if (data != null) {
                ISkinnableEntityAdapter ca = (ISkinnableEntityAdapter) data
                        .getAdapter(ISkinnableEntityAdapter.class);
                if (ca != null) {
                    // cares only about the skinnable entities
                    set.add(data);
                }
            }
        }

        if (set.isEmpty()) {
            //  clears the view
            initializePage(StructuredSelection.EMPTY, null, null);
            repopulateContents(StructuredSelection.EMPTY);
            return;
        }
        List<Object> cdSel = new ArrayList<Object>(set.size());
        for (Object obj : set) {
            cdSel.add(obj);
        }

        // selection raised from editor,
        // editor
        if (part == sourceEditor) {
            cdSel.add(Boolean.FALSE);
        }

        sel = new StructuredSelection(cdSel);

        List<Object> newSelection = new ArrayList<Object>();

        if (ctrl_active || shift_active) {
            // preserve selection
            // add non-visible elements from current component view
            // selection
            List<IContentData> nonVisuals = new ArrayList<IContentData>();
            for (int i = 0; selectedItems != null && i < selectedItems.size(); i++) {
                IContentData data = selectedItems.get(i);
                if (!isVisibleOnScreen(data)) {
                    nonVisuals.add(data);
                }
            }

            List<Object> _selection = new ArrayList<Object>();
            _selection.addAll(Arrays.asList(sel.toArray()));

            if (selectedItems != null) {
                newSelection.addAll(selectedItems);
            }

            // add added elements
            for (int i = 0; i < _selection.size(); i++) {
                Object obj = _selection.get(i);
                if (!newSelection.contains(obj) || obj instanceof Boolean) {
                    newSelection.add(obj);
                }
            }

            // remove removed elements
            for (int i = 0; selectedItems != null && i < selectedItems.size(); i++) {
                Object obj = selectedItems.get(i);
                if (!_selection.contains(obj)) {
                    // preserve non-visible
                    if (!nonVisuals.contains(obj)) {
                        newSelection.remove(obj);
                    }
                }
            }
        } else {
            newSelection = sel.toList();
        }

        final StructuredSelection newSel = new StructuredSelection(newSelection);

        if (sel.size() == 0 || (sel.size() > 0 && sel.getFirstElement() instanceof IContentData)) {
            IContentData tmpData = (IContentData) (sel.getFirstElement());
            if (tmpData != null
                    && (tmpData.getParent() instanceof IContent
                            || tmpData.getAdapter(IScreenAdapter.class) != null)
                    || tmpData instanceof ThemeScreenReferData) {
                return;
            }
            IContentAdapter adapter = (IContentAdapter) sourceEditor.getAdapter(IContentAdapter.class);
            IContent content = ScreenUtil.getPrimaryContent(adapter.getContents());
            if (tmpData != null && !(tmpData.getRoot() instanceof IContent)) {
                // removed from the content
                tmpData = content.findById(tmpData.getId());
            }
            final IContentData newCategory = sel.size() == 0 || tmpData == null ? null : tmpData.getParent();
            com.nokia.tools.platform.core.Display newDisplay = (com.nokia.tools.platform.core.Display) content
                    .getAttribute(ContentAttribute.DISPLAY.name());
            final Dimension newResolution = newDisplay == null ? null
                    : new Dimension(newDisplay.getWidth(), newDisplay.getHeight());

            if (currentCategory != newCategory || (newResolution != null && !newResolution.equals(resolution))
                    || currentCategory == null || getItems().size() != container.getChildren().length) {
                initializePage(newSel, newCategory, newResolution);
                Display.getDefault().asyncExec(new Runnable() {
                    public void run() {
                        repopulateContents(newSel);
                    }
                });

                return;
            }
        }
        // always sets the selection because the selection on the main
        // editor might have changed
        setSelection(newSel);
    }

}

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

License:Open Source License

public ISelection getSelection() {
    if (lastSelectedItems == selectedItems) {
        return lastSelection;
    }//from w ww. j av  a 2  s  .  c o m
    if (selectedItems != null) {
        IContentData[] selectedData = findScreenData(selectedItems);
        if (selectedData.length > 0) {
            lastSelection = new StructuredSelection(selectedData);
            lastSelectedItems = selectedItems;
            return lastSelection;
        }
    }
    lastSelection = StructuredSelection.EMPTY;
    lastSelectedItems = selectedItems;
    return lastSelection;
}

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

License:Open Source License

public void setSelection(final ISelection selection) {
    this.selection = selection;
    Display.getDefault().asyncExec(new Runnable() {

        public void run() {
            for (ISelectionChangedListener listener : selectionListeners) {
                if (listener != null) {
                    listener.selectionChanged(new SelectionChangedEvent(ResourceViewPage.this,
                            selection == null ? StructuredSelection.EMPTY : selection));
                }//from   w  w  w  .  j a  va 2 s .  co  m
            }
        }

    });
}

From source file:com.nokia.tools.s60ct.model.confml.presentation.ConfmlEditor.java

License:Open Source License

/**
 * Handles what to do with changed resources on activation. <!--
 * begin-user-doc --> <!-- end-user-doc -->
 * //from   w  w  w  .  jav a2 s .  c  o m
 * @generated
 */
protected void handleChangedResources() {
    if (!changedResources.isEmpty() && (!isDirty() || handleDirtyConflict())) {

        if (isDirty()) {
            changedResources.addAll(editingDomain.getResourceSet().getResources());
        }
        editingDomain.getCommandStack().flush();

        updateProblemIndication = false;
        for (Resource resource : changedResources) {
            if (resource.isLoaded()) {
                resource.unload();
                try {
                    resource.load(Collections.EMPTY_MAP);
                } catch (IOException exception) {
                    if (!resourceToDiagnosticMap.containsKey(resource)) {
                        resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
                    }
                }
            }
        }

        if (AdapterFactoryEditingDomain.isStale(editorSelection)) {
            setSelection(StructuredSelection.EMPTY);
        }

        //         updateProblemIndication = true;
        //         updateProblemIndication();
    }
}

From source file:com.nokia.tools.screen.ui.utils.SimpleSelectionProvider.java

License:Open Source License

public SimpleSelectionProvider(Object data) {
    if (data != null) {
        sel = new StructuredSelection(data);
    } else {/*from  w ww  .ja v a  2 s. c  om*/
        sel = StructuredSelection.EMPTY;
    }
}

From source file:com.nokia.tools.variant.common.ui.views.GenericPageBookView.java

License:Open Source License

/**
 * Construct the view and initialize it/* w w  w .  j a  v  a  2  s . c o  m*/
 * 
 * @param interfaceType
 *            {@link IPage} extension interface to look for
 * @param defaultText
 *            Default view message
 * @param helpId
 *            Help context ID or <code>null</code>
 */
protected GenericPageBookView(Class<T> interfaceType, String defaultText, String helpId) {
    this.pageInterface = interfaceType;
    this.defaultText = defaultText;
    this.helpContextId = helpId;
    lastSelection = StructuredSelection.EMPTY;

}