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

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

Introduction

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

Prototype

@Override
    public Object getFirstElement() 

Source Link

Usage

From source file:com.nokia.tools.variant.confml.ui.views.ConfMLNavigator.java

License:Open Source License

private MenuManager createOpenMenu() {

    MenuManager openWithManager = new MenuManager("&Open With", "OpenWith");

    openWithManager.addMenuListener(new IMenuListener() {
        public void menuAboutToShow(IMenuManager manager) {

            ISelection selection = getViewer().getSelection();
            IContributionItem[] items = manager.getItems();

            if (selection instanceof StructuredSelection) {
                StructuredSelection structuredSelection = (StructuredSelection) selection;
                Object firstElement = structuredSelection.getFirstElement();

                if (firstElement instanceof EConfMLDocument) {
                    for (int i = 0; i < items.length; i++) {
                        if (items[i].getId()
                                .equalsIgnoreCase("com.nokia.tools.variant.confml.ui.confmlvieweditor")) {
                            items[i].setVisible(false);
                            break;
                        }/*w  w w  .  j a v a 2  s .  com*/
                    }
                } else if (firstElement instanceof EAppView) {
                    for (int i = 0; i < items.length; i++) {
                        if (items[i].getId()
                                .equalsIgnoreCase("com.nokia.tools.variant.confml.ui.confmleditor")) {
                            items[i].setVisible(false);
                            break;
                        }
                    }
                }
            }
        }

    });
    return openWithManager;
}

From source file:com.nokia.tools.variant.editor.actions.CopyAction.java

License:Open Source License

@Override
public void run() {

    if (editor != null) {

        SettingsViewer settingsViewer = editor.getSettingsViewer();
        if (settingsViewer == null) {
            return;
        }/*from w  w  w .  j  a  v  a2  s  .  com*/
        ISelection selection = settingsViewer.getSelection();

        if (selection.isEmpty()) {
            if (editor.getSc().isFocused()) {
                Text text = editor.getSc().getAutocmpleteText().getText();
                text.copy();
                text.update();
            }
            return;
        }

        if (selection instanceof StructuredSelection) {
            StructuredSelection structuredSelection = (StructuredSelection) selection;
            Map<Object, Composite> elementToWidgetMap = settingsViewer.getElementToWidgetMap();
            Composite composite = elementToWidgetMap.get(structuredSelection.getFirstElement());

            if (composite instanceof BaseConfMLWidget) {
                BaseConfMLWidget baseConfMLWidget = (BaseConfMLWidget) composite;
                baseConfMLWidget.copy();
            }
        }
    } else {

        if (control != null) {

            if (control instanceof StringFieldEditor) {
                ((StringFieldEditor) control).copy();

            } else if (control instanceof Text) {
                ((Text) control).copy();
            }
        }
    }
}

From source file:com.nokia.tools.variant.editor.actions.CutAction.java

License:Open Source License

@Override
public void run() {

    if (editor != null) {
        SettingsViewer settingsViewer = editor.getSettingsViewer();
        if (settingsViewer == null) {
            return;
        }/*w w w. j  av  a2  s  . c om*/

        ISelection selection = settingsViewer.getSelection();

        if (selection.isEmpty()) {
            if (editor.getSc().isFocused()) {
                Text text = editor.getSc().getAutocmpleteText().getText();
                text.cut();
                text.update();
            }
            return;
        }

        if (selection instanceof StructuredSelection) {
            StructuredSelection structuredSelection = (StructuredSelection) selection;
            Map<Object, Composite> elementToWidgetMap = settingsViewer.getElementToWidgetMap();
            Composite composite = elementToWidgetMap.get(structuredSelection.getFirstElement());

            if (composite instanceof BaseConfMLWidget) {
                BaseConfMLWidget baseConfMLWidget = (BaseConfMLWidget) composite;
                baseConfMLWidget.cut();
            }
        }

    } else {

        if (control != null) {

            if (control instanceof StringFieldEditor) {
                ((StringFieldEditor) control).cut();

            } else if (control instanceof Text) {
                ((Text) control).cut();
            }
        }
    }
}

From source file:com.nokia.tools.variant.editor.actions.DeleteAction.java

License:Open Source License

@Override
public void run() {

    if (editor != null) {

        SettingsViewer settingsViewer = editor.getSettingsViewer();
        if (settingsViewer == null) {
            return;
        }//from  w w  w  .jav a  2 s.  c  o m
        ISelection selection = settingsViewer.getSelection();

        if (selection.isEmpty()) {
            if (editor.getSc().isFocused()) {
                Text text = editor.getSc().getAutocmpleteText().getText();
                executeDeleteAction(text);
            }
            return;
        }

        if (selection instanceof StructuredSelection) {
            StructuredSelection structuredSelection = (StructuredSelection) selection;
            Map<Object, Composite> elementToWidgetMap = settingsViewer.getElementToWidgetMap();
            Composite composite = elementToWidgetMap.get(structuredSelection.getFirstElement());

            if (composite instanceof BaseConfMLWidget) {
                BaseConfMLWidget baseConfMLWidget = (BaseConfMLWidget) composite;
                baseConfMLWidget.delete();
            }
        }

    } else {

        if (control != null) {

            if (control instanceof StringFieldEditor) {
                ((StringFieldEditor) control).delete();

            } else if (control instanceof Text) {
                executeDeleteAction((Text) control);
            }
        }
    }
}

From source file:com.nokia.tools.variant.editor.actions.PasteAction.java

License:Open Source License

@Override
public void run() {

    if (editor != null) {

        SettingsViewer settingsViewer = editor.getSettingsViewer();
        if (settingsViewer == null) {
            return;
        }//from  ww  w.j a  v  a  2s  . com

        ISelection selection = settingsViewer.getSelection();

        if (selection.isEmpty()) {
            if (editor.getSc().isFocused()) {
                Text text = editor.getSc().getAutocmpleteText().getText();
                text.paste();
                text.update();
            }
            return;
        }

        if (selection instanceof StructuredSelection) {
            StructuredSelection structuredSelection = (StructuredSelection) selection;
            Map<Object, Composite> elementToWidgetMap = settingsViewer.getElementToWidgetMap();
            Composite composite = elementToWidgetMap.get(structuredSelection.getFirstElement());

            if (composite instanceof BaseConfMLWidget) {
                BaseConfMLWidget baseConfMLWidget = (BaseConfMLWidget) composite;
                baseConfMLWidget.paste();
            }
        }

    } else {

        if (control != null) {

            if (control instanceof StringFieldEditor) {
                ((StringFieldEditor) control).paste();

            } else if (control instanceof Text) {
                ((Text) control).paste();
            }
        }
    }
}

From source file:com.nokia.tools.variant.editor.editors.EditorViewerContentProvider.java

License:Open Source License

public DropTargetListener getDropTargetListener(final Object element) {
    if (element instanceof BaseConfMLWidget) {
        BaseConfMLWidget widget = (BaseConfMLWidget) element;
        return new WidgetDropTargetListener(widget, widget.getData());
    } else {//from   w ww .  ja  v a  2 s . c  om
        return new DropTargetListener() {

            public void dragEnter(DropTargetEvent event) {
                event.detail = DND.DROP_NONE;
                if (isData() && (getData() instanceof StructuredSelection)) {
                    StructuredSelection selection = (StructuredSelection) getData();
                    Object result = selection.getFirstElement();
                    if (element instanceof UISetting) {
                        UISetting uiSetting = (UISetting) element;
                        Setting setting = uiSetting.getSetting();
                        // CPF v2
                        if (setting instanceof FileSystemEntrySetting) {
                            if ((((FileSystemEntrySetting) setting).isFile()) && (result instanceof File)) {
                                event.detail = DND.DROP_DEFAULT;
                            }
                            if (!(((FileSystemEntrySetting) setting).isFile())
                                    && (result instanceof Directory)) {
                                event.detail = DND.DROP_DEFAULT;
                            }
                        }
                        // CPF v1
                        if (setting instanceof SimpleSetting) {
                            if (setting.getType().equals(TYPE.SIMPLE_FILE) && (result instanceof File)) {
                                event.detail = DND.DROP_DEFAULT;
                            }
                            if (setting.getType().equals(TYPE.SIMPLE_FOLDER) && (result instanceof Directory)) {
                                event.detail = DND.DROP_DEFAULT;
                            }
                        }
                    }
                }
            }

            public void dragLeave(DropTargetEvent event) {

            }

            public void dragOperationChanged(DropTargetEvent event) {

            }

            public void dragOver(DropTargetEvent event) {

            }

            public void drop(DropTargetEvent event) {
                if (event.data != null && event.data instanceof StructuredSelection) {
                    StructuredSelection selection = (StructuredSelection) event.data;
                    Object result = selection.getFirstElement();
                    iHaveFileAndelement(result, element);
                }
            }

            public void dropAccept(DropTargetEvent event) {

            }

        };
    }

}

From source file:com.nokia.tools.variant.editor.listeners.WidgetDropTargetListener.java

License:Open Source License

public void drop(DropTargetEvent event) {
    if (event.data instanceof StructuredSelection && uiSetting != null) {
        StructuredSelection ss = (StructuredSelection) event.data;
        Object firstElement = ss.getFirstElement();
        if (firstElement instanceof UISetting) {
            Setting source = ((UISetting) firstElement).getSetting();
            Setting target = uiSetting.getSetting();

            EObject sourceParent = checkFileSetting(source).eContainer();
            EObject targetParent = checkFileSetting(target).eContainer();
            if (sourceParent instanceof SequenceItem && targetParent instanceof SequenceItem
                    && sourceParent.eContainer() == targetParent.eContainer() && sourceParent != targetParent) {

                MoveSequenceItemAction action = new MoveSequenceItemAction((SequenceItem) sourceParent,
                        (SequenceItem) targetParent);
                DragAndDropActionRegistry.setAction(action);

            }//www.  j a  v a  2 s .c o m

        }

    }
    DragAndDropActionRegistry.setStartUISettingWidget(null);
}

From source file:com.nokia.tools.variant.views.changesview.ChangesViewPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));

    final Label changesCount = new Label(composite, SWT.NONE);

    changesTV = new GenericTableViewer(composite);

    changesTV.addColumn(new Column(ViewsMessages.CHANGES_COLUMN_1_NAME, COLUMN_1_WIDTH));
    changesTV.addColumn(new Column(ViewsMessages.CHANGES_COLUMN_2_NAME, COLUMN_2_WIDTH));
    changesTV.addColumn(new Column(ViewsMessages.CHANGES_COLUMN_3_NAME, COLUMN_3_WIDTH));
    changesTV.addColumn(new Column(ViewsMessages.CHANGES_COLUMN_4_NAME, COLUMN_4_WIDTH));

    changesTV.setContentProvider(new ChangesContentProvider());
    changesTV.setLabelProvider(new ChangesLabelProvider());
    changesTV.setInput(view);//from   w  ww  .  j a  va 2s. co m

    changesTV.populateTableViewer();

    adapter = new EContentAdapter() {

        public void notifyChanged(Notification notification) {
            super.notifyChanged(notification);
            if (notification.getEventType() == Notification.REMOVING_ADAPTER) {
                return;
            }

            if (notification.getEventType() == Notification.ADD
                    || notification.getEventType() == Notification.ADD_MANY
                    || notification.getEventType() == Notification.REMOVE
                    || notification.getEventType() == Notification.REMOVE_MANY) {
                changesTV.getTv().refresh();
            }

            if (notification.getEventType() == Notification.SET) {
                changesTV.getTv().refresh();
            }

            changesCount.setText(changesTV.getRowCount() + " " + ViewsMessages.CHANGES);
            changesCount.pack();
        }

    };

    view.eAdapters().add(adapter);

    changesTV.getTv().getTable().addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            view.eAdapters().remove(adapter);

        }

    });

    changesTV.getTv().addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
            if (activePage != null) {
                IEditorPart activeEditor = activePage.getActiveEditor();
                if (activeEditor instanceof ISelectionProvider) {
                    StructuredSelection selection = (StructuredSelection) event.getSelection();
                    Setting setting = (Setting) selection.getFirstElement();
                    StructuredSelection structuredSelection = new StructuredSelection(setting);

                    ISelectionProvider provider = (ISelectionProvider) activeEditor;
                    provider.setSelection(structuredSelection);
                }
            }

        }

    });

    changesCount.setText(changesTV.getRowCount() + " " + ViewsMessages.CHANGES);
}

From source file:com.nokia.tools.variant.views.errorview.ErrorsViewPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    topComposite = new Composite(parent, SWT.NONE);
    topComposite.setLayout(new GridLayout(3, false));

    errorCount = new Label(topComposite, SWT.NONE);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    errorCount.setLayoutData(gd);//from   w  w w . j  av a 2  s .  c o m

    filterLbl = new Label(topComposite, SWT.NONE);
    filterLbl.setText("Show results:");

    filterCombo = new Combo(topComposite, SWT.READ_ONLY);

    fillFilterCombo();

    // default selection
    filterCombo.select(0);

    filterCombo.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            Combo combo = (Combo) e.widget;
            selectionIndex = combo.getSelectionIndex();
            errorTV.getTv().resetFilters();
            if (selectionIndex != 0) {
                errorsViewerFilter = new ComboViewerFilter(combo.getItem(selectionIndex));
                errorTV.getTv().addFilter(errorsViewerFilter);
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {

        }
    });

    errorTV = new GenericTableViewer(topComposite);

    GridData layoutData = (GridData) errorTV.getTv().getTable().getLayoutData();
    layoutData.horizontalSpan = 3;
    errorTV.getTv().getTable().setLayoutData(layoutData);

    errorTV.addColumn(new Column(ViewsMessages.ERROR_COLUMN_1_NAME, COLUMN_1_WIDTH));
    errorTV.addColumn(new Column(ViewsMessages.ERROR_COLUMN_2_NAME, COLUMN_2_WIDTH));
    errorTV.addColumn(new Column(ViewsMessages.ERROR_COLUMN_3_NAME, COLUMN_3_WIDTH));

    errorTV.setContentProvider(new ErrorsContentProvider());
    errorTV.setLabelProvider(new ErrorsLabelProvider());
    errorTV.setInput(errorsInput);

    errorsInput.eAdapters().add(adapter);
    errorTV.getTv().getTable().addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            errorsInput.eAdapters().remove(adapter);
            adapter = null;

        }

    });
    errorTV.populateTableViewer();
    errorTV.getTv().addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
            if (activePage != null) {
                IEditorPart activeEditor = activePage.getActiveEditor();
                if (activeEditor instanceof ISelectionProvider) {
                    StructuredSelection selection = (StructuredSelection) event.getSelection();
                    Error errorElement = (Error) selection.getFirstElement();
                    StructuredSelection structuredSelection = new StructuredSelection(
                            errorElement.getSetting());

                    ISelectionProvider provider = (ISelectionProvider) activeEditor;
                    provider.setSelection(structuredSelection);
                }
            }

        }

    });

    errorCount.setText(errorsInput.getErrors().size() + " " + ViewsMessages.ERRORS);
}

From source file:com.nokia.tools.variant.views.notesview.NotesViewPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));

    final Label notesCount = new Label(composite, SWT.NONE);

    notesTV = new GenericTableViewer(composite);

    notesTV.addColumn(new Column(ViewsMessages.NOTES_COLUMN_1_NAME, COLUMN_1_WIDTH));
    notesTV.addColumn(new Column(ViewsMessages.NOTES_COLUMN_2_NAME, COLUMN_2_WIDTH));
    notesTV.addColumn(new Column(ViewsMessages.NOTES_COLUMN_3_NAME, COLUMN_3_WIDTH));

    notesTV.setContentProvider(new NotesContentProvider());
    notesTV.setLabelProvider(new NotesLabelProvider());
    notesTV.setInput(view);/*from www. jav a 2  s .com*/

    notesTV.populateTableViewer();

    adapter = new EContentAdapter() {

        public void notifyChanged(Notification notification) {
            super.notifyChanged(notification);
            if (notification.getEventType() == Notification.REMOVING_ADAPTER) {
                return;
            }

            if (notification.getEventType() == Notification.ADD
                    || notification.getEventType() == Notification.ADD_MANY
                    || notification.getEventType() == Notification.REMOVE
                    || notification.getEventType() == Notification.REMOVE_MANY
                    || (notification.getEventType() == Notification.SET
                            && notification.getFeatureID(Setting.class) == ConfmlPackage.SETTING__NOTE)) {
                if (notesTV != null && notesTV.getTv() != null) {
                    notesTV.getTv().refresh();
                    notesCount.setText(notesTV.getRowCount() + " " + ViewsMessages.NOTES);
                    notesCount.pack();
                }
            }
        }

    };

    view.eAdapters().add(adapter);

    notesTV.populateTableViewer();
    notesTV.getTv().addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
            if (activePage != null) {
                IEditorPart activeEditor = activePage.getActiveEditor();
                if (activeEditor instanceof ISelectionProvider) {
                    StructuredSelection selection = (StructuredSelection) event.getSelection();
                    Setting setting = (Setting) selection.getFirstElement();
                    StructuredSelection structuredSelection = new StructuredSelection(setting);

                    ISelectionProvider provider = (ISelectionProvider) activeEditor;
                    provider.setSelection(structuredSelection);
                }
            }

        }

    });

    notesCount.setText(notesTV.getRowCount() + " " + ViewsMessages.NOTES);
}