Example usage for org.eclipse.jface.viewers SelectionChangedEvent getSelection

List of usage examples for org.eclipse.jface.viewers SelectionChangedEvent getSelection

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers SelectionChangedEvent getSelection.

Prototype

public ISelection getSelection() 

Source Link

Document

Returns the selection.

Usage

From source file:ac.at.tuwien.dsg.uml.statemachine.export.transformation.gui.viewer.MyTreeViewer.java

License:Open Source License

public void createPartControl(Composite parent) {
    treeViewer = new TreeViewer(parent);
    treeViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
    treeViewer.setContentProvider(new FileTreeContentProvider());
    treeViewer.setLabelProvider(new FileTreeLabelProvider());
    treeViewer.setInput(ResourcesPlugin.getWorkspace());
    treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override/*from   ww  w  .jav a 2 s .c  o m*/
        public void selectionChanged(SelectionChangedEvent event) {
            selection = (TreeSelection) event.getSelection();
            TreePath[] selectedPaths = selection.getPaths();
            String selected = selectedPaths[0].getLastSegment().toString();

            System.out.println(selection.toString());
        }
    });
}

From source file:ac.soton.eventb.classdiagrams.diagram.part.ModelElementSelectionPage.java

License:Open Source License

/**
 * @generated//from   w w w  .j a  v a 2  s . co m
 */
public void createControl(Composite parent) {
    initializeDialogUnits(parent);

    Composite plate = new Composite(parent, SWT.NONE);
    plate.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    plate.setLayout(layout);
    setControl(plate);

    Label label = new Label(plate, SWT.NONE);
    label.setText(getSelectionTitle());
    label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));

    modelViewer = new TreeViewer(plate, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    GridData layoutData = new GridData(GridData.FILL_BOTH);
    layoutData.heightHint = 300;
    layoutData.widthHint = 300;
    modelViewer.getTree().setLayoutData(layoutData);
    modelViewer.setContentProvider(new AdapterFactoryContentProvider(
            ClassdiagramsDiagramEditorPlugin.getInstance().getItemProvidersAdapterFactory()));
    modelViewer.setLabelProvider(new AdapterFactoryLabelProvider(
            ClassdiagramsDiagramEditorPlugin.getInstance().getItemProvidersAdapterFactory()));
    if (selectedModelElement != null) {
        modelViewer.setInput(selectedModelElement.eResource());
        modelViewer.setSelection(new StructuredSelection(selectedModelElement));
    }
    modelViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            ModelElementSelectionPage.this.updateSelection((IStructuredSelection) event.getSelection());
        }
    });

    setPageComplete(validatePage());
}

From source file:ac.soton.eventb.emf.diagrams.navigator.action.OpenDiagramAction.java

License:Open Source License

@Override
public void selectionChanged(SelectionChangedEvent event) {
    selection = event.getSelection();
}

From source file:ac.soton.fmusim.components.diagram.part.ModelElementSelectionPage.java

License:Open Source License

/**
 * @generated//  w ww  . ja v  a 2s .c  om
 */
public void createControl(Composite parent) {
    initializeDialogUnits(parent);

    Composite plate = new Composite(parent, SWT.NONE);
    plate.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    plate.setLayout(layout);
    setControl(plate);

    Label label = new Label(plate, SWT.NONE);
    label.setText(getSelectionTitle());
    label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));

    modelViewer = new TreeViewer(plate, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    GridData layoutData = new GridData(GridData.FILL_BOTH);
    layoutData.heightHint = 300;
    layoutData.widthHint = 300;
    modelViewer.getTree().setLayoutData(layoutData);
    modelViewer.setContentProvider(new AdapterFactoryContentProvider(
            ComponentsDiagramEditorPlugin.getInstance().getItemProvidersAdapterFactory()));
    modelViewer.setLabelProvider(new AdapterFactoryLabelProvider(
            ComponentsDiagramEditorPlugin.getInstance().getItemProvidersAdapterFactory()));
    if (selectedModelElement != null) {
        modelViewer.setInput(selectedModelElement.eResource());
        modelViewer.setSelection(new StructuredSelection(selectedModelElement));
    }
    modelViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            ModelElementSelectionPage.this.updateSelection((IStructuredSelection) event.getSelection());
        }
    });

    setPageComplete(validatePage());
}

From source file:ac.soton.fmusim.components.presentation.ComponentsActionBarContributor.java

License:Open Source License

/**
 * This implements {@link org.eclipse.jface.viewers.ISelectionChangedListener},
 * handling {@link org.eclipse.jface.viewers.SelectionChangedEvent}s by querying for the children and siblings
 * that can be added to the selected object and updating the menus accordingly.
 * <!-- begin-user-doc -->//from  w w w .  j a  va2s .  co m
 * <!-- end-user-doc -->
 * @generated
 */
public void selectionChanged(SelectionChangedEvent event) {
    // Remove any menu items for old selection.
    //
    if (createChildMenuManager != null) {
        depopulateManager(createChildMenuManager, createChildActions);
    }
    if (createSiblingMenuManager != null) {
        depopulateManager(createSiblingMenuManager, createSiblingActions);
    }

    // Query the new selection for appropriate new child/sibling descriptors
    //
    Collection<?> newChildDescriptors = null;
    Collection<?> newSiblingDescriptors = null;

    ISelection selection = event.getSelection();
    if (selection instanceof IStructuredSelection && ((IStructuredSelection) selection).size() == 1) {
        Object object = ((IStructuredSelection) selection).getFirstElement();

        EditingDomain domain = ((IEditingDomainProvider) activeEditorPart).getEditingDomain();

        newChildDescriptors = domain.getNewChildDescriptors(object, null);
        newSiblingDescriptors = domain.getNewChildDescriptors(null, object);
    }

    // Generate actions for selection; populate and redraw the menus.
    //
    createChildActions = generateCreateChildActions(newChildDescriptors, selection);
    createSiblingActions = generateCreateSiblingActions(newSiblingDescriptors, selection);

    if (createChildMenuManager != null) {
        populateManager(createChildMenuManager, createChildActions, null);
        createChildMenuManager.update(true);
    }
    if (createSiblingMenuManager != null) {
        populateManager(createSiblingMenuManager, createSiblingActions, null);
        createSiblingMenuManager.update(true);
    }
}

From source file:ac.soton.fmusim.components.presentation.ComponentsEditor.java

License:Open Source License

/**
 * This makes sure that one content viewer, either for the current page or the outline view, if it has focus,
 * is the current one.//from ww  w.ja  v  a2s .co m
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setCurrentViewer(Viewer viewer) {
    // If it is changing...
    //
    if (currentViewer != viewer) {
        if (selectionChangedListener == null) {
            // Create the listener on demand.
            //
            selectionChangedListener = new ISelectionChangedListener() {
                // This just notifies those things that are affected by the section.
                //
                public void selectionChanged(SelectionChangedEvent selectionChangedEvent) {
                    setSelection(selectionChangedEvent.getSelection());
                }
            };
        }

        // Stop listening to the old one.
        //
        if (currentViewer != null) {
            currentViewer.removeSelectionChangedListener(selectionChangedListener);
        }

        // Start listening to the new one.
        //
        if (viewer != null) {
            viewer.addSelectionChangedListener(selectionChangedListener);
        }

        // Remember it.
        //
        currentViewer = viewer;

        // Set the editors selection based on the current viewer's selection.
        //
        setSelection(currentViewer == null ? StructuredSelection.EMPTY : currentViewer.getSelection());
    }
}

From source file:ac.soton.fmusim.components.presentation.ComponentsEditor.java

License:Open Source License

/**
 * This accesses a cached version of the content outliner.
 * <!-- begin-user-doc -->/*from   w  w  w  .j  av  a 2 s. com*/
 * <!-- end-user-doc -->
 * @generated
 */
public IContentOutlinePage getContentOutlinePage() {
    if (contentOutlinePage == null) {
        // The content outline is just a tree.
        //
        class MyContentOutlinePage extends ContentOutlinePage {
            @Override
            public void createControl(Composite parent) {
                super.createControl(parent);
                contentOutlineViewer = getTreeViewer();
                contentOutlineViewer.addSelectionChangedListener(this);

                // Set up the tree viewer.
                //
                contentOutlineViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
                contentOutlineViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
                contentOutlineViewer.setInput(editingDomain.getResourceSet());

                // Make sure our popups work.
                //
                createContextMenuFor(contentOutlineViewer);

                if (!editingDomain.getResourceSet().getResources().isEmpty()) {
                    // Select the root object in the view.
                    //
                    contentOutlineViewer.setSelection(
                            new StructuredSelection(editingDomain.getResourceSet().getResources().get(0)),
                            true);
                }
            }

            @Override
            public void makeContributions(IMenuManager menuManager, IToolBarManager toolBarManager,
                    IStatusLineManager statusLineManager) {
                super.makeContributions(menuManager, toolBarManager, statusLineManager);
                contentOutlineStatusLineManager = statusLineManager;
            }

            @Override
            public void setActionBars(IActionBars actionBars) {
                super.setActionBars(actionBars);
                getActionBarContributor().shareGlobalActions(this, actionBars);
            }
        }

        contentOutlinePage = new MyContentOutlinePage();

        // Listen to selection so that we can handle it is a special way.
        //
        contentOutlinePage.addSelectionChangedListener(new ISelectionChangedListener() {
            // This ensures that we handle selections correctly.
            //
            public void selectionChanged(SelectionChangedEvent event) {
                handleContentOutlineSelection(event.getSelection());
            }
        });
    }

    return contentOutlinePage;
}

From source file:ac.soton.fmusim.components.ui.providers.ComponentsPaletteProvider.java

License:Open Source License

/**
 * @param editor/*  w  ww.j a v a2 s  .  com*/
 * @return
 */
private ToolEntry createImportEntry(final IEditorPart editor) {
    return new ToolEntry(IMPORT_BTN_LABEL, "Import a component",
            ComponentsUIPlugin.imageDescriptorFromPlugin(ComponentsUIPlugin.getPluginID(), "icons/Import.gif"),
            null) {

        private PaletteListener postListener;
        private ISelectionChangedListener preListener;
        private ToolEntry activeTool;

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.gef.palette.ToolEntry#createTool()
         */
        @Override
        public Tool createTool() {
            if (postListener == null) {

                // listener for recording the last selected (active) tool
                preListener = new ISelectionChangedListener() {
                    @Override
                    public void selectionChanged(SelectionChangedEvent event) {
                        Object source = event.getSource();
                        Object element = ((IStructuredSelection) event.getSelection()).getFirstElement();
                        if (source instanceof PaletteViewer && element instanceof ToolEntryEditPart) {
                            PaletteEntry entry = (PaletteEntry) ((ToolEntryEditPart) element).getModel();
                            if (IMPORT_BTN_LABEL.equals(entry.getLabel())) {
                                PaletteViewer palette = (PaletteViewer) source;
                                activeTool = palette.getActiveTool();
                            }
                        }
                    }
                };
                ((DiagramEditor) editor).getDiagramGraphicalViewer().getEditDomain().getPaletteViewer()
                        .addSelectionChangedListener(preListener);

                // listener for unselecting the Import button and selecting previously recorded active tool (by preListener)
                postListener = new PaletteListener() {
                    @Override
                    public void activeToolChanged(PaletteViewer palette, ToolEntry tool) {
                        if (IMPORT_BTN_LABEL.equals(tool.getLabel())) {
                            palette.deselectAll();
                            palette.setActiveTool(activeTool);
                        }
                    }
                };
                ((DiagramEditor) editor).getDiagramGraphicalViewer().getEditDomain().getPaletteViewer()
                        .addPaletteListener(postListener);
            }
            return super.createTool();
        }
    };
}

From source file:alma.acs.eventbrowser.parts.EventDetailPart.java

License:Open Source License

@PostConstruct
public void createPartControl(Composite parent, EMenuService menuService) {
    try {/*w  ww.  j a v  a2 s .c  o  m*/
        em = EventModel.getInstance();
    } catch (Throwable thr) {
        thr.printStackTrace();
        IStatus someStatus = statusReporter.newStatus(IStatus.ERROR, "Connection with NCs failed.", thr);
        statusReporter.report(someStatus, StatusReporter.SHOW);
        throw new RuntimeException(thr);
    }
    logger = em.getLogger();

    viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);

    Table table = viewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    GridLayout gridLayout = new GridLayout();
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    gridLayout.verticalSpacing = 0;
    parent.setLayout(gridLayout);

    TableViewerColumn tvcol = new TableViewerColumn(viewer, SWT.NONE, 0);
    tvcol.setLabelProvider(new DetailNameLabelProvider());
    TableColumn col = tvcol.getColumn();
    col.setText("Name");
    col.setWidth(200);
    col.setAlignment(SWT.LEFT);

    tvcol = new TableViewerColumn(viewer, SWT.NONE, 1);
    tvcol.setLabelProvider(new DetailTypeLabelProvider());
    col = tvcol.getColumn();
    col.setText("Type");
    col.setWidth(100);
    col.setAlignment(SWT.LEFT);

    tvcol = new TableViewerColumn(viewer, SWT.NONE, 2);
    tvcol.setLabelProvider(new DetailValueLabelProvider());
    col = tvcol.getColumn();
    col.setText("Value");
    col.setWidth(200);
    col.setAlignment(SWT.LEFT);

    GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getTable());

    viewer.setContentProvider(new DetailContentProvider());

    hookContextMenu(menuService);

    // Attach a selection listener to our table, which will post selections to the ESelectionService
    // to be processed by CopyDetailsToClipboardHandler
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();

            List<ParsedAnyData> parsedAnyList = new ArrayList<ParsedAnyData>();
            for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
                ParsedAnyData parsedAny = (ParsedAnyData) iterator.next();
                parsedAnyList.add(parsedAny);
            }
            selectionService.setSelection(parsedAnyList.toArray(new ParsedAnyData[0]));
        }
    });
}

From source file:alma.acs.eventbrowser.parts.EventListPart.java

License:Open Source License

/**
 *//*  www. j  ava  2 s  .  c  o  m*/
@PostConstruct
public void postConstruct(Composite parent, final IEclipseContext context, IEventBroker eventBroker,
        EMenuService menuService) {
    try {
        em = EventModel.getInstance();
    } catch (Throwable thr) {
        thr.printStackTrace();
        IStatus someStatus = statusReporter.newStatus(IStatus.ERROR, "Connection with NCs failed.", thr);
        statusReporter.report(someStatus, StatusReporter.SHOW);
        throw new RuntimeException(thr);
    }

    logger = em.getLogger();

    GridLayout gridLayout = new GridLayout();
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    gridLayout.verticalSpacing = 0;
    parent.setLayout(gridLayout);

    // TODO: We currently have the filter text control in the regular view toolbar.
    //       The e3 eventGUI had a "custom tool bar" inserted here.
    //       We should decide which way it's better.

    viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    Table table = viewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    /*
     * "Time "+timeStamp+" "+m_channelName+" "+component+" "+count+"
     * "+channelEventCount+" " +" "+evtTypeName+"
     * "+evtCounter.get(evtTypeName)
     */

    TableViewerColumn tvcol = new TableViewerColumn(viewer, SWT.NONE, 0);
    tvcol.setLabelProvider(new TimeStampLabelProvider());
    TableColumn col = tvcol.getColumn();
    col.setText("Timestamp");
    col.setWidth(180);
    col.setAlignment(SWT.LEFT);

    tvcol = new TableViewerColumn(viewer, SWT.NONE, 1);
    tvcol.setLabelProvider(new EventSourceLabelProvider());
    col = tvcol.getColumn();
    col.setText("Event source");
    col.setWidth(150);
    col.setAlignment(SWT.LEFT);

    tvcol = new TableViewerColumn(viewer, SWT.NONE, 2);
    tvcol.setLabelProvider(new CountLabelProvider());
    col = tvcol.getColumn();
    col.setText("# Events in channel");
    col.setWidth(50);
    col.setAlignment(SWT.LEFT);

    tvcol = new TableViewerColumn(viewer, SWT.NONE, 3);
    tvcol.setLabelProvider(new EventTypeLabelProvider());
    col = tvcol.getColumn();
    col.setText("Event type");
    col.setWidth(150);
    col.setAlignment(SWT.LEFT);

    tvcol = new TableViewerColumn(viewer, SWT.NONE, 4);
    tvcol.setLabelProvider(new EventTypeCountLabelProvider());
    col = tvcol.getColumn();
    col.setText("# Events this type");
    col.setWidth(50);
    col.setAlignment(SWT.LEFT);

    GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getTable());

    viewer.setContentProvider(new EventListViewContentProvider(em));

    // Attach a selection listener to our event list that will post the selected event for the event details list
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection.size() == 1) {
                selectionService.setSelection(selection.getFirstElement());
            }
        }
    });

    viewer.setInput(new Object());

    hookContextMenu(menuService);

    pel = new PopulateEventList(logger, viewer, new StatusLineWriter(eventBroker), em.getEventQueue(),
            "NC Events");
    eventListThread = pel.getThreadForEventList();
    eventListThread.start();
}