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

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

Introduction

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

Prototype

public Object getFirstElement();

Source Link

Document

Returns the first element in this selection, or null if the selection is empty.

Usage

From source file:ac.soton.xeventb.internal.ui.XTextConvertHandler.java

License:Open Source License

/**
 * Get the current only selected object. If more than one objects are
 * selected, return <code>null</code>.
 * /*www.j a va 2  s  .c  o  m*/
 * @param event
 *          the execution event
 * @return the only selected object.
 * @throws ExecutionException
 *          if some unexpected error occurs.
 */
private Object getCurrentSelectedObject(final ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
    if ((selection instanceof IStructuredSelection)) {
        IStructuredSelection ssel = ((IStructuredSelection) selection);
        int _size = ssel.size();
        boolean _tripleEquals = (_size == 1);
        if (_tripleEquals) {
            return ssel.getFirstElement();
        }
    }
    return null;
}

From source file:actions.RenameAction.java

License:Open Source License

public void selectionChanged(IAction action, ISelection selection) {
    selectedObject = null;//w ww.  j  a v  a  2s  .c o m
    selectedNameAttribute = null;
    selectedROAttribute = null;
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structedSelection = (IStructuredSelection) selection;
        if (structedSelection.size() > 0 && ALLOWED_TYPES != null
                && isSupportedType(structedSelection.getFirstElement())) {
            selectedObject = (EObject) structedSelection.getFirstElement();
        }
    }
    if (selectedObject != null && ALLOWED_TYPES != null && !isObjectReadOnly(selectedObject)) {
        action.setEnabled(true);
    } else
        action.setEnabled(false);

}

From source file:algsymboleditor.wizards.NewFencedWizardPage.java

License:Open Source License

/**
 * Checks the current workbench selection for suitability, and then
 * initializes the wizard page./*from w w  w  . j  av  a2s  .  c om*/
 */
private void initialize() {
    if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) {
        IStructuredSelection ssel = (IStructuredSelection) selection;
        if (ssel.size() > 1)
            return;
        Object obj = ssel.getFirstElement();
        if (obj instanceof IResource) {
            IContainer container;
            if (obj instanceof IContainer)
                container = (IContainer) obj;
            else
                container = ((IResource) obj).getParent();
            containerText.setText(container.getFullPath().toString());
        }
    }
    fileText.setText("new_file.algfenced");
}

From source file:algsymboleditor.wizards.NewQuotientWizardPage.java

License:Open Source License

/**
 * Checks the current workbench selection for suitability, and then
 * initializes the wizard page./*from  w  w w.j  a  v a 2 s.c o m*/
 */
private void initialize() {
    if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) {
        IStructuredSelection ssel = (IStructuredSelection) selection;
        if (ssel.size() > 1)
            return;
        Object obj = ssel.getFirstElement();
        if (obj instanceof IResource) {
            IContainer container;
            if (obj instanceof IContainer)
                container = (IContainer) obj;
            else
                container = ((IResource) obj).getParent();
            containerText.setText(container.getFullPath().toString());
        }
    }
    fileText.setText("new_file.algquotient");
}

From source file:algsymboleditor.wizards.NewSymbolWizardPage.java

License:Open Source License

/**
 * Checks the current workbench selection for suitability, and then
 * initializes the wizard page./*from   www  .  ja  v  a  2 s . c o m*/
 */
private void initialize() {
    if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) {
        IStructuredSelection ssel = (IStructuredSelection) selection;
        if (ssel.size() > 1)
            return;
        Object obj = ssel.getFirstElement();
        if (obj instanceof IResource) {
            IContainer container;
            if (obj instanceof IContainer)
                container = (IContainer) obj;
            else
                container = ((IResource) obj).getParent();
            containerText.setText(container.getFullPath().toString());
        }
    }
    fileText.setText("new_file.algsymbol");
}

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

License:Open Source License

/**
 * See http://www.vogella.com/articles/EclipseJFaceTree/article.html
 *///from   w ww .java 2  s  .c  o  m
@PostConstruct
public void postConstruct(Composite parent, final IEclipseContext context, EMenuService menuService,
        IEventBroker eventBroker) {
    try {
        eventModel = 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);
    }
    //      eventModel.getLogger().info("ChannelTreePart got EventModel instance.");

    statusLineWriter = new StatusLineWriter(eventBroker);

    viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    viewer.setContentProvider(new ChannelTreeContentProvider());
    viewer.setLabelProvider(new ChannelTreeLabelProvider());
    // Expand the tree. '2' means to show only the visible top-level nodes.
    viewer.setAutoExpandLevel(2);

    viewer.setComparator(new ServiceViewerComparator());

    // Provide the root node to the ContentProvider
    viewer.setInput(eventModel.getNotifyServicesRoot());

    // Expand with doubleclick
    viewer.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection thisSelection = (IStructuredSelection) event.getSelection();
            Object selectedNode = thisSelection.getFirstElement();
            viewer.setExpandedState(selectedNode, !viewer.getExpandedState(selectedNode));
        }
    });

    // Attach a selection listener to our tree that will post selections to the ESelectionService
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            selectionService
                    .setSelection(selection.size() == 1 ? selection.getFirstElement() : selection.toArray());
        }
    });

    // TODO: Take care of help system. Here's the E3 code:
    //      // Create the help context id for the viewer's control
    //      PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "alma.acs.eventbrowser.viewer");

    hookContextMenu(menuService);

    // TODO: this could be used by handlers etc, currently it's not
    context.set(ChannelTreePart.class, this);
}

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

License:Open Source License

/**
 *//*  w  w  w.j a  va  2 s  . co  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();
}

From source file:applicationWorkbench.actions.PlannerPrintAction.java

License:Open Source License

/**
 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
 *      org.eclipse.jface.viewers.ISelection)
 *///from   ww w . j  ava 2 s. c  o m
public void selectionChanged(IAction action, ISelection selection) {
    if (!(selection instanceof IStructuredSelection))
        return;
    IStructuredSelection sel = (IStructuredSelection) selection;
    if (sel.size() != 1)
        return;
    selectedFile = (IFile) sel.getFirstElement();
    try {
        InputStream is = selectedFile.getContents(false);
        ObjectInputStream ois = new ObjectInputStream(is);
        setContents(ois.readObject());
        ois.close();
    } catch (Exception e) {
        util.Logger.singleton().error(e);
    }

}

From source file:ar.com.tadp.xml.rinzo.core.outline.XMLOutlinePage.java

License:Open Source License

protected void handleDoubleClick(DoubleClickEvent event) {
    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    Object element = selection.getFirstElement();
    TreeViewer viewer = this.getTreeViewer();
    if (viewer.isExpandable(element)) {
        viewer.setExpandedState(element, !viewer.getExpandedState(element));
    }/*from ww  w. j av a2s.com*/
}

From source file:ar.com.tadp.xml.rinzo.core.RinzoXMLEditor.java

License:Open Source License

public void selectionChanged(SelectionChangedEvent event) {
    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    if (!selection.isEmpty()) {
        Object element = selection.getFirstElement();
        if (element != null && element instanceof XMLNode) {
            XMLNode node = (XMLNode) element;
            this.selectAndReveal(node.getSelectionOffset(), node.getSelectionLength());
        }/*  w  w w  . j  a  v a2  s  .c  o  m*/
    }
}