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

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

Introduction

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

Prototype

public int size();

Source Link

Document

Returns the number of elements selected in this selection.

Usage

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

License:Open Source License

/**
 * See http://www.vogella.com/articles/EclipseJFaceTree/article.html
 *//*  ww  w . j a v  a 2s  . 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

/**
 *//*from  w  ww .  j a v a2s  .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)
 *//* ww  w  .  ja v a 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.fluxit.jqa.viewer.TargetPackagesDragListener.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from  w  w w.j ava2 s  . com*/
public void dragStart(DragSourceEvent event) {
    IStructuredSelection selection = (IStructuredSelection) getTableViewer().getSelection();
    // Get the current selection at start because the table changes while
    // selecting the target Layer. Also, allocates a new IJavaElement array
    // because JavaElementTransfer.javaToNative
    currentSelection = ((List<IJavaElement>) selection.toList()).toArray(new IJavaElement[selection.size()]);
    // Sets the target of drag
    getDragViewerHolder().setValue(getTableViewer());
    getDragInputHolder().setValue((Collection<IJavaElement>) getTableViewer().getInput());
}

From source file:ariba.ideplugin.eclipse.wizards.AWProjectDetailsPage.java

License:Apache License

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;/*from  ww w.  ja  v a2s .  c  o  m*/
            if (obj instanceof IContainer)
                container = (IContainer) obj;
            else
                container = ((IResource) obj).getParent();
        }
    }
}

From source file:ariba.ideplugin.eclipse.wizards.AWProjectTemplatePage.java

License:Apache License

/**
 * Tests if the current workbench selection is a suitable container to use.
 *///  w  w w.  j a  v a  2 s.  com

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();
        }
    }

}

From source file:aspectminingtool.views.FanIn.ViewPartFanIn.java

License:Open Source License

/**
 * Create the actions.// w w w  . ja  v a 2s  .  c o  m
 */
public void createActions() {

    selectAllActionMethodsTable = new Action("Select All") {
        public void run() {
            selectAll(tableViewerLeft);
        }
    };

    selectAllActionCallsTable = new Action("Select All") {
        public void run() {
            selectAll(tableViewerRight);
        }
    };

    // Add selection listener.
    tableViewerLeft.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) tableViewerLeft.getSelection();
            openActionTableLeft.setEnabled(sel.size() > 0);
            selectAllActionMethodsTable.setEnabled(sel.size() > 0);
            selectAsSeedOperation.setEnabled(sel.size() > 0);
        }
    });

    tableViewerRight.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) tableViewerRight.getSelection();
            selectAllActionCallsTable.setEnabled(sel.size() > 0);
            openActionTableRight.setEnabled(sel.size() > 0);
        }
    });

}

From source file:aspectminingtool.views.FanInSeeds.ViewPartFanInSeeds.java

License:Open Source License

/**
 * Create the actions./*  ww  w  . j a  v  a  2  s.  c  o  m*/
 */
public void createActions() {
    openItemActionMethodsTable = new Action("Open") {
        public void run() {
            IStructuredSelection sel = (IStructuredSelection) tableViewerLeft.getSelection();
            Iterator iter = sel.iterator();
            while (iter.hasNext()) {
                MethodDescription methodDescription = (MethodDescription) iter.next();
                if (methodDescription != null) {
                    String id = methodDescription.getMethod().getClass_id();
                    openResource(id);
                }

            }
        }
    };

    deleteAction = new Action("Delete") {
        public void run() {
            IStructuredSelection sel = (IStructuredSelection) tableViewerLeft.getSelection();
            Iterator iter = sel.iterator();
            while (iter.hasNext()) {
                MethodDescription methodDescription = (MethodDescription) iter.next();
                if (methodDescription != null) {
                    ((SeedsModel) model).removeMethodDescription(methodDescription);
                }

            }

        }
    };

    selectAllActionMethodsTable = new Action("Select All") {
        public void run() {
            selectAll(tableViewerLeft);
        }
    };

    openItemActionCallsTable = new Action("Open") {
        public void run() {
            IStructuredSelection sel = (IStructuredSelection) tableViewerRight.getSelection();
            Iterator iter = sel.iterator();
            while (iter.hasNext()) {
                Call_Counted callCounted = (Call_Counted) iter.next();
                String name = callCounted.getCaller_id();
                int index = name.indexOf("//");
                name = name.substring(0, index);
                openResource(name);

            }
        }
    };

    selectAllActionCallsTable = new Action("Select All") {
        public void run() {
            selectAll(tableViewerRight);
        }
    };

    // Add selection listener.
    tableViewerLeft.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) tableViewerLeft.getSelection();
            openItemActionMethodsTable.setEnabled(sel.size() > 0);
            selectAllActionMethodsTable.setEnabled(sel.size() > 0);
            deleteAction.setEnabled(sel.size() > 0);
        }
    });

    tableViewerRight.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) tableViewerLeft.getSelection();
            selectAllActionCallsTable.setEnabled(sel.size() > 0);
            openItemActionCallsTable.setEnabled(sel.size() > 0);
        }
    });

}

From source file:aspectminingtool.views.RedirectorFinder.ViewPartRedirectorFinder.java

License:Open Source License

/**
 * Create the actions.//from   w ww .  j  a v a2s .c o m
 */
public void createActions() {

    //      selectAsSeedAction = new Action("Select As a Seed") {
    //         public void run() {
    //            IStructuredSelection sel = (IStructuredSelection)tableViewerLeft.getSelection();
    //            Iterator iter = sel.iterator();
    //            while (iter.hasNext()) {
    //               RedirectorFinderResults redirFinderResul = (RedirectorFinderResults) iter.next();
    //               Method method = redirFinderResul.getMetodo();
    //               ViewPartUtil.selectAsSeed(method, ViewPartFanInSeeds.ID_VIEW, ((FanInModel)model).getCalls(method.getId()), ((FanInModel)model).getProjectModel());
    //               //selectAsSeedOperation(method.getMetodo());
    //
    //            }

    selectAllActionMethodsTable = new Action("Select All") {
        public void run() {
            selectAll(tableViewerLeft);
        }
    };

    selectAllActionCallsTable = new Action("Select All") {
        public void run() {
            selectAll(tableViewerRight);
        }
    };

    // Add selection listener.
    tableViewerLeft.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) tableViewerLeft.getSelection();
            openActionTableLeft.setEnabled(sel.size() > 0);
            selectAllActionMethodsTable.setEnabled(sel.size() > 0);
            selectAsSeedOperation.setEnabled(sel.size() > 0);
        }
    });

    tableViewerRight.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) tableViewerRight.getSelection();
            selectAllActionCallsTable.setEnabled(sel.size() > 0);
            openActionTableRight.setEnabled(sel.size() > 0);
        }
    });

}

From source file:aspectminingtool.views.Sinergia.Seeds.ViewPartSinergiaSeedsDesc.java

License:Open Source License

/**
 * Create the actions.//from   w w  w.  j ava  2s .c om
 */
public void createActions() {

    selectAllTableLeft = new Action("Select All") {
        public void run() {
            selectAll(tableViewerLeft);
        }
    };
    // Add selection listener.
    tableViewerLeft.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) tableViewerLeft.getSelection();
            openActionTableLeft.setEnabled(sel.size() > 0);
            selectAllTableLeft.setEnabled(sel.size() > 0);
        }
    });
}