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:gov.nasa.ensemble.core.plan.editor.lifecycle.AbstractExportPlanAction.java

License:Open Source License

protected IStructuredSelection getCurrentSelection() {
    IStructuredSelection structuredSeleciton = StructuredSelection.EMPTY;
    IEditorPart current = EditorPartUtils.getCurrent(window);
    if (current != null) {
        Object adapter = current.getAdapter(EPlan.class);
        if (adapter instanceof EPlan) {
            EPlan plan = (EPlan) adapter;
            adapter = plan.getAdapter(IResource.class);
            if (adapter != null) {
                structuredSeleciton = new StructuredSelection(adapter);
            }//from   www .j  a v  a  2s. co m
        }
    }

    return structuredSeleciton;
}

From source file:gov.nasa.ensemble.core.plan.editor.merge.operations.MergePlanClipboardCutOperation.java

License:Open Source License

@Override
protected void execute() {
    WidgetUtils.runInDisplayThread(tree, new Runnable() {
        @Override//from  www . j av  a 2s  .  c  o  m
        public void run() {
            TreeItem newSelectedItem = MergeEditor.getNewlySelectedItem(tree);
            if (newSelectedItem != null) {
                newSelection = new StructuredSelection(newSelectedItem.getData());
            } else {
                newSelection = StructuredSelection.EMPTY;
            }
        }
    }, true);
    super.execute();
    WidgetUtils.runInDisplayThread(tree, new Runnable() {
        @Override
        public void run() {
            if ((provider != null) && (newSelection != null)) {
                provider.setSelection(newSelection);
            }
        }
    }, true);
}

From source file:gov.nasa.ensemble.core.plan.resources.ui.profile.editor.ProfileDataPointsEditor.java

License:Open Source License

@SuppressWarnings("unchecked")
private TreeTableViewer createTreeTableViewer(final Composite parent, FormToolkit toolkit,
        final Profile profile) {
    boolean isProfileEditable = isProfileEditable(profile);
    //create tree viewer
    List<AbstractTreeTableColumn> columns = new ProfileDataPointColumnProvider(profile, isProfileEditable)
            .getColumns();// w ww  . j a  va 2 s  . c o  m
    TreeTableColumnConfiguration config = new TreeTableColumnConfiguration(columns.get(0), columns,
            columns.get(0));
    TreeTableComposite ttc = new TreeTableComposite(parent, config, false);
    ttc.setLayout(new TreeTableColumnLayout(false));
    final TreeTableViewer viewer = new TreeTableViewer(ttc, config, null);

    //set providers
    viewer.setContentProvider(new ProfileEditorContentProvider());
    viewer.setLabelProvider(new TreeTableLabelProvider() {
        @Override
        public boolean needsUpdate(Object feature) {
            return false;
        }

        @Override
        public Font getFont(Object element) {
            return null;
        }

        @Override
        public Color getBackground(Object element) {
            return null;
        }
    });

    //if there's any changes in the profile data points... refresh viewer!
    final TransactionalEditingDomain domain = gov.nasa.ensemble.emf.transaction.TransactionUtils
            .getDomain(profile);
    final ResourceSetListenerImpl viewerRefreshListener = new ResourceSetListenerImpl() {
        @Override
        public void resourceSetChanged(ResourceSetChangeEvent event) {
            for (Notification notification : event.getNotifications()) {
                if (notification.getNotifier() == profile
                        && notification.getFeature() == JSciencePackage.Literals.PROFILE__DATA_POINTS) {
                    WidgetUtils.runInDisplayThread(viewer.getTree(), new Runnable() {
                        @Override
                        public void run() {
                            viewer.refresh();
                            parent.getParent().getParent().layout();
                        }
                    });
                }
            }
        }
    };
    if (domain != null) {
        domain.addResourceSetListener(viewerRefreshListener);
    }

    if (isProfileEditable) {
        Composite buttonsComposite = toolkit.createComposite(parent);
        buttonsComposite.setLayout(new GridLayout(2, false));
        buttonsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 2, 1));

        //insert new DataPoint
        final Button insertButton = toolkit.createButton(buttonsComposite, INSERT_BUTTON_TEXT, SWT.PUSH);
        insertButton.setToolTipText(INSERT_TOOLTIP_MESSAGE);
        final SelectionAdapter insertButtonSelectionListener = new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent event) {
                EList<DataPoint> dataPoints = profile.getDataPoints();
                DataPoint newDataPoint;
                if (dataPoints.isEmpty()) {
                    EPlan ePlan = EPlanUtils.getPlanFromResourceSet(profile);
                    Date date = (ePlan != null ? ePlan.getMember(TemporalMember.class).getStartTime()
                            : new Date());
                    newDataPoint = JScienceFactory.eINSTANCE.createEDataPoint(date, null);
                } else {
                    Date date;
                    ISelection selection = viewer.getSelection();
                    if (selection == null || selection.isEmpty()) {
                        date = dataPoints.get(dataPoints.size() - 1).getDate();
                    } else if (selection instanceof StructuredSelection) {
                        Object[] array = ((StructuredSelection) selection).toArray();
                        date = ((DataPoint) array[array.length - 1]).getDate();
                    } else {
                        date = new Date(); //if everything fails... just set to now
                    }
                    newDataPoint = JScienceFactory.eINSTANCE.createEDataPoint(DateUtils.addSeconds(date, 1),
                            null);
                }
                if (!dataPoints.contains(newDataPoint)) {
                    try {
                        AddProfileDataPointOperation op = new AddProfileDataPointOperation(profile,
                                newDataPoint);
                        op.addContext(viewer.getModel().getUndoContext());
                        IOperationHistory history = OperationHistoryFactory.getOperationHistory();
                        history.execute(op, null, null);
                        viewer.setSelection(new StructuredSelection(newDataPoint));
                    } catch (Exception e) {
                        LogUtil.error(e);
                    }
                } else {
                    showOperationError();
                    viewer.setSelection(new StructuredSelection(newDataPoint));
                }

            }
        };
        insertButton.addSelectionListener(insertButtonSelectionListener);

        //remove Data Point
        final Button removeButton = toolkit.createButton(buttonsComposite, REMOVE_BUTTON_TEXT, SWT.PUSH);
        removeButton.setToolTipText(REMOVE_TOOLTIP_MESSAGE);
        removeButton.setEnabled(!viewer.getSelection().isEmpty());
        final SelectionAdapter removeButtonSelectionListener = new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent event) {
                ISelection selection = viewer.getSelection();
                if (!selection.isEmpty()) {
                    if (selection instanceof StructuredSelection) {
                        StructuredSelection ss = (StructuredSelection) selection;
                        int selectionSize = ss.size();
                        DataPoint[] dps = new DataPoint[selectionSize];
                        Iterator<DataPoint> iterator = ss.iterator();
                        int i = 0;
                        while (iterator.hasNext()) {
                            dps[i++] = iterator.next();
                        }
                        RemoveProfileDataPointsOperation op = new RemoveProfileDataPointsOperation(profile,
                                dps);
                        op.addContext(EMFUtils.getUndoContext(profile));
                        IOperationHistory history = OperationHistoryFactory.getOperationHistory();
                        try {
                            history.execute(op, null, null);
                            viewer.setSelection(StructuredSelection.EMPTY);
                        } catch (Exception e) {
                            LogUtil.error(e);
                        }
                    }
                }
            }
        };
        removeButton.addSelectionListener(removeButtonSelectionListener);
        final ISelectionChangedListener removeButtonEnablementListener = new ISelectionChangedListener() {
            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                removeButton.setEnabled(!viewer.getSelection().isEmpty());
            }
        };
        viewer.addSelectionChangedListener(removeButtonEnablementListener);

        //set dispose listener for editable profiles
        viewer.getControl().addDisposeListener(new DisposeListener() {
            @Override
            public void widgetDisposed(DisposeEvent e) {
                if (domain != null) {
                    domain.removeResourceSetListener(viewerRefreshListener);
                }
                insertButton.removeSelectionListener(insertButtonSelectionListener);
                removeButton.removeSelectionListener(removeButtonSelectionListener);
                viewer.removeSelectionChangedListener(removeButtonEnablementListener);
                dispose(viewer);
            }
        });
    } else {
        //set dispose listener for non-editable profiles
        viewer.getControl().addDisposeListener(new DisposeListener() {
            @Override
            public void widgetDisposed(DisposeEvent e) {
                if (domain != null) {
                    domain.removeResourceSetListener(viewerRefreshListener);
                }
                dispose(viewer);
            }
        });
    }
    return viewer;
}

From source file:gov.nasa.ensemble.tests.core.plan.editor.TestCopyPasteManyTimesOperation.java

License:Open Source License

public void testPlanCopyPasteManyTimesOperation000() {
    IStructuredSelection targetSelection = StructuredSelection.EMPTY;
    int copies = 0;
    SelectionProviderAdapter selectionProvider = new SelectionProviderAdapter();
    PlanStructureModifier modifier = PlanStructureModifier.INSTANCE;
    PlanCopyPasteManyTimesOperation operation = new PlanCopyPasteManyTimesOperation(targetSelection, modifier,
            copies, selectionProvider);/*  w  w w  .  ja v  a2  s .com*/
    assertFalse(operation.canExecute());
}

From source file:gov.nasa.ensemble.tests.core.plan.editor.TestCopyPasteManyTimesOperation.java

License:Open Source License

public void testPlanCopyPasteManyTimesOperation100() {
    IStructuredSelection targetSelection = StructuredSelection.EMPTY;
    int copies = 1;
    SelectionProviderAdapter selectionProvider = new SelectionProviderAdapter();

    PlanStructureModifier modifier = PlanStructureModifier.INSTANCE;
    PlanCopyPasteManyTimesOperation operation = new PlanCopyPasteManyTimesOperation(targetSelection, modifier,
            copies, selectionProvider);//from w  w w.j  a v  a 2  s.  c  o  m
    assertFalse(operation.canExecute());
}

From source file:gov.nasa.ensemble.tests.core.plan.editor.TestCopyPasteManyTimesOperation.java

License:Open Source License

public void testPlanCopyPasteManyTimesOperation200() {
    IStructuredSelection targetSelection = StructuredSelection.EMPTY;
    int copies = 2;
    SelectionProviderAdapter selectionProvider = new SelectionProviderAdapter();

    PlanStructureModifier modifier = PlanStructureModifier.INSTANCE;
    PlanCopyPasteManyTimesOperation operation = new PlanCopyPasteManyTimesOperation(targetSelection, modifier,
            copies, selectionProvider);/* w  w  w .  j a v a 2s .c om*/
    assertFalse(operation.canExecute());
}

From source file:gov.redhawk.frontend.ui.internal.section.FrontendSection.java

License:Open Source License

public void unsetPageSelection() {
    page.selectionChanged(inputPart, StructuredSelection.EMPTY);
    setInput(null, null);
}

From source file:gov.redhawk.ui.editor.FormOutlinePage.java

License:Open Source License

/**
 * Gets the selection./*from   w  w  w  . j av  a2s .  co  m*/
 * 
 * @return the selection
 */
@Override
public ISelection getSelection() {
    if (this.treeViewer == null) {
        return StructuredSelection.EMPTY;
    }
    return this.treeViewer.getSelection();
}

From source file:ilg.gnuarmeclipse.managedbuild.packs.ui.TabDevices.java

License:Open Source License

private void devicesTreeSelectionChanged(SelectionChangedEvent event) {

    IStructuredSelection selection = (IStructuredSelection) event.getSelection();

    // System.out.println(selection);

    Object element = selection.getFirstElement();
    if (!(element instanceof Node)) {
        return;//w  w w. j  a  va2 s .co  m
    }

    Node node = (Node) element;

    if (!node.isType(Type.DEVICE)) {
        // Do not allow selections for other nodes than devices
        fDevicesTree.setSelection(StructuredSelection.EMPTY);
        return;
    }

    fSelectedDeviceNode = null;
    fSelectedBoardDeviceNode = null;
    if (node.getParent().isType(Type.BOARD)) {

        // Search for true device node
        fSelectedDeviceNode = findBoardDevice(node);
        if (fSelectedDeviceNode == null) {
            // Do not allow selections for undefined board devices
            fDevicesTree.setSelection(StructuredSelection.EMPTY);
            return;
        }
        fSelectedBoardDeviceNode = node;
    } else {
        // System.out.println("Device " + element);
        fSelectedDeviceNode = node;
    }

    Map<String, String[]> map = collectMemoryMap(fSelectedDeviceNode);

    updateMemoryTableContent(map);

    String arch = DataManager.collectProperty(fSelectedDeviceNode, Node.CORE_PROPERTY, Type.DEVICES_SUBTREE);
    fArchitectureLabel.setText(arch);

    if (fSelectedDeviceNode != null) {
        fDeviceLabel.setText(fSelectedDeviceNode.getName());
    }
}

From source file:ilg.gnumcueclipse.managedbuild.packs.ui.TabDevices.java

License:Open Source License

private void devicesTreeSelectionChanged(SelectionChangedEvent event) {

    IStructuredSelection selection = (IStructuredSelection) event.getSelection();

    if (Activator.getInstance().isDebugging()) {
        System.out.println("Devices.devicesTreeSelectionChanged() " + selection);
    }/*from www.  j  a v a  2s.  c  o  m*/

    Object element = selection.getFirstElement();
    if (!(element instanceof Node)) {
        return;
    }

    Node node = (Node) element;

    if (!node.isType(Type.DEVICE)) {
        // Do not allow selections for other nodes than devices
        fDevicesTree.setSelection(StructuredSelection.EMPTY);
        return;
    }

    fSelectedDeviceNode = null;
    fSelectedBoardDeviceNode = null;
    if (node.getParent().isType(Type.BOARD)) {

        // Search for true device node
        fSelectedDeviceNode = findBoardDevice(node);
        if (fSelectedDeviceNode == null) {
            // Do not allow selections for undefined board devices
            fDevicesTree.setSelection(StructuredSelection.EMPTY);
            return;
        }
        fSelectedBoardDeviceNode = node;
    } else {
        // System.out.println("Device " + element);
        fSelectedDeviceNode = node;
    }

    Map<String, String[]> map = collectMemoryMap(fSelectedDeviceNode);

    updateMemoryTableContent(map);

    String arch = DataManager.collectProperty(fSelectedDeviceNode, Node.CORE_PROPERTY, Type.DEVICES_SUBTREE);
    fArchitectureLabel.setText(arch);

    if (fSelectedDeviceNode != null) {
        fDeviceLabel.setText(fSelectedDeviceNode.getName());
    }
}