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

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

Introduction

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

Prototype

@Override
    public List toList() 

Source Link

Usage

From source file:ac.soton.eventb.roseEditor.propertySections.abstracts.AbstractEventBPropertySection.java

License:Open Source License

@Override
public void setInput(final IWorkbenchPart part, final ISelection selection) {
    owner = null;/*w w  w.j  a va 2 s.co m*/
    if (selection.isEmpty() || false == selection instanceof StructuredSelection) {
        super.setInput(part, selection);
        return;
    }
    final StructuredSelection structuredSelection = (StructuredSelection) selection;
    ArrayList<Object> transformedSelection = new ArrayList<Object>(structuredSelection.size());
    for (Object object : structuredSelection.toList()) {
        if (owner == null && object instanceof EventBElement) {
            owner = (EventBElement) object;
        }
        if (object != null) {
            transformedSelection.add(object);
        }
    }
    super.setInput(part, new StructuredSelection(transformedSelection));
}

From source file:ar.com.fluxit.jqa.wizard.page.UsageDefinitionWizardPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;//w  w w. j  a  v a2  s  . c  om
    container.setLayout(layout);

    viewer = new GraphViewer(container, SWT.BORDER);
    viewer.setContentProvider(new LayersGraphContentProvider());
    viewer.setLabelProvider(new LayersGraphLabelProvider());
    viewer.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED);
    LayoutAlgorithm graphLayout = new TreeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING);
    graphLayout.setEntityAspectRatio(0.95);
    viewer.setLayoutAlgorithm(graphLayout, true);
    viewer.applyLayout();
    viewer.getGraphControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    viewer.addPostSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            StructuredSelection selection = (StructuredSelection) event.getSelection();
            if (!selection.isEmpty()) {
                @SuppressWarnings("unchecked")
                List<Object> selectedObjects = selection.toList();
                EntityConnectionData connection = findConnection(selectedObjects);
                if (connection == null) {
                    if (selectedObjects.size() > 1) {
                        LayerDescriptor sourceLayer = (LayerDescriptor) selectedObjects.get(0);
                        LayerDescriptor destinationLayer = (LayerDescriptor) selectedObjects.get(1);
                        sourceLayer.addUsage(destinationLayer);
                        viewer.refresh();
                        viewer.setSelection(StructuredSelection.EMPTY);
                    }
                } else {
                    ((LayerDescriptor) connection.source).removeUsage((LayerDescriptor) connection.dest);
                    viewer.refresh();
                    viewer.setSelection(StructuredSelection.EMPTY);
                }
            }
        }
    });

    final Menu menu = new Menu(viewer.getGraphControl());

    MenuItem layoutMenuItem = new MenuItem(menu, SWT.PUSH);
    layoutMenuItem.setText("Layout");
    layoutMenuItem.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            viewer.applyLayout();
        }
    });

    MenuItem resetMenuItem = new MenuItem(menu, SWT.PUSH);
    resetMenuItem.setText("Reset");
    resetMenuItem.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean openConfirm = MessageDialog.openConfirm(menu.getShell(), "Confirm reset", "Are you sure?");
            if (openConfirm) {
                for (LayerDescriptor layer : getArchitectureDescriptor().getLayers()) {
                    layer.clearUsages();
                    viewer.refresh();
                }
            }
        }
    });

    viewer.getGraphControl().setMenu(menu);
    setControl(container);
    ((WizardDialog) getContainer()).addPageChangedListener(this);
}

From source file:com.amazonaws.eclipse.ec2.ui.ebs.VolumeSelectionTable.java

License:Apache License

@Override
protected void makeActions() {
    refreshAction = new Action() {
        public void run() {
            refreshVolumes();/* w  w  w .  ja  v a  2s. c  o  m*/
        }
    };
    refreshAction.setText("Refresh");
    refreshAction.setToolTipText("Refresh the volume list");
    refreshAction.setImageDescriptor(Ec2Plugin.getDefault().getImageRegistry().getDescriptor("refresh"));

    createAction = new Action() {
        public void run() {
            final CreateNewVolumeDialog dialog = new CreateNewVolumeDialog(
                    Display.getCurrent().getActiveShell());
            if (dialog.open() != IDialogConstants.OK_ID)
                return;

            new CreateVolumeThread(dialog.getAvailabilityZone(), dialog.getSize(), dialog.getSnapshotId())
                    .start();
        }
    };
    createAction.setText("New Volume");
    createAction.setToolTipText("Create a new EBS volume");
    createAction.setImageDescriptor(Ec2Plugin.getDefault().getImageRegistry().getDescriptor("add"));

    releaseAction = new Action() {
        @SuppressWarnings("unchecked")
        @Override
        public void run() {
            StructuredSelection selection = (StructuredSelection) viewer.getSelection();
            new ReleaseVolumesThread((List<Volume>) selection.toList()).start();
        }
    };
    releaseAction.setText("Release Volume");
    releaseAction.setDescription("Release selected volume(s)");
    releaseAction.setImageDescriptor(Ec2Plugin.getDefault().getImageRegistry().getDescriptor("remove"));

    detachAction = new Action() {
        @Override
        public void run() {
            final Volume volume = getSelectedVolume();
            new DetachVolumeThread(volume).start();
        }
    };
    detachAction.setText("Detach Volume");
    detachAction.setToolTipText("Detach the selected volume from all instances.");

    createSnapshotAction = new Action() {
        @Override
        public void run() {
            new CreateSnapshotThread(getSelectedVolume()).start();
        }
    };
    createSnapshotAction.setText("Create Snapshot");
    createSnapshotAction.setToolTipText("Creates a new snapshot of this volume.");
    createSnapshotAction
            .setImageDescriptor(Ec2Plugin.getDefault().getImageRegistry().getDescriptor("snapshot"));
}

From source file:com.amazonaws.eclipse.ec2.ui.views.instances.InstanceSelectionTable.java

License:Apache License

@SuppressWarnings("unchecked")
List<Instance> getAllSelectedInstances() {
    StructuredSelection selection = (StructuredSelection) viewer.getSelection();
    return (List<Instance>) selection.toList();
}

From source file:com.amazonaws.eclipse.ec2.ui.views.instances.InstanceSelectionTable.java

License:Apache License

/**
 * Sets the list of instances to be displayed in the instance table.
 *
 * @param instances/*w ww . j  a  v  a2 s . c o m*/
 *            The list of instances to be displayed in the instance table.
 * @param securityGroupMap
 *            A map of instance IDs to a list of security groups in which
 *            those instances were launched.
 */
private void setInput(final List<Instance> instances, final Map<String, List<String>> securityGroupMap) {
    Display.getDefault().asyncExec(new Runnable() {
        @SuppressWarnings("unchecked")
        public void run() {
            /*
             * Sometimes we see cases where the content provider for a table
             * viewer is null, so we check for that here to avoid causing an
             * unhandled event loop exception. All InstanceSelectionTables
             * should always have a content provider set in the constructor,
             * but for some reason we occasionally still see this happen.
             */
            if (viewer.getContentProvider() == null) {
                return;
            }

            StructuredSelection currentSelection = (StructuredSelection) viewer.getSelection();
            viewer.setInput(new InstancesViewInput(instances, securityGroupMap));

            packColumns();

            Set<String> instanceIds = new HashSet<String>();
            for (Instance instance : (List<Instance>) currentSelection.toList()) {
                instanceIds.add(instance.getInstanceId());
            }

            List<Instance> newSelectedInstances = new ArrayList<Instance>();
            for (TreeItem treeItem : viewer.getTree().getItems()) {
                Instance instance = (Instance) treeItem.getData();

                if (instanceIds.contains(instance.getInstanceId())) {
                    newSelectedInstances.add(instance);
                }
            }

            viewer.setSelection(new StructuredSelection(newSelectedInstances));
        }
    });
}

From source file:com.aptana.editor.php.internal.ui.dialog.CustomFilteredItemsSelectionDialog.java

License:Open Source License

/**
 * Handle selection in the items list by updating labels of selected and unselected items and refresh the details
 * field using the selection./*from  w ww  . j  a v  a  2 s .c om*/
 * 
 * @param selection
 *            the new selection
 */
protected void handleSelected(StructuredSelection selection) {
    IStatus status = new Status(IStatus.OK, PlatformUI.PLUGIN_ID, IStatus.OK, StringUtil.EMPTY, null);

    if (selection.size() == 0) {
        status = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.ERROR, StringUtil.EMPTY, null);

        if (lastSelection != null && getListSelectionLabelDecorator() != null) {
            list.update(lastSelection, null);
        }

        lastSelection = null;

    } else {
        status = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.ERROR, StringUtil.EMPTY, null);

        List<?> items = selection.toList();

        Object item = null;
        IStatus tempStatus = null;

        for (Iterator<?> it = items.iterator(); it.hasNext();) {
            Object o = it.next();

            if (o instanceof ItemsListSeparator) {
                continue;
            }

            item = o;
            tempStatus = validateItem(item);

            if (tempStatus.isOK()) {
                status = new Status(IStatus.OK, PlatformUI.PLUGIN_ID, IStatus.OK, StringUtil.EMPTY, null);
            } else {
                status = tempStatus;
                // if any selected element is not valid status is set to
                // ERROR
                break;
            }
        }

        if (lastSelection != null && getListSelectionLabelDecorator() != null) {
            list.update(lastSelection, null);
        }

        if (getListSelectionLabelDecorator() != null) {
            list.update(items.toArray(), null);
        }

        lastSelection = items.toArray();
    }

    refreshDetails();
    updateStatus(status);
}

From source file:com.aptana.editor.php.internal.ui.dialog.CustomFilteredItemsSelectionDialog.java

License:Open Source License

/**
 * Returns the current selection.//from ww w . ja  v a2s .co  m
 * 
 * @return the current selection
 */
protected StructuredSelection getSelectedItems() {

    StructuredSelection selection = (StructuredSelection) list.getSelection();

    List<?> selectedItems = selection.toList();
    Object itemToRemove = null;

    for (Iterator<?> it = selection.iterator(); it.hasNext();) {
        Object item = it.next();
        if (item instanceof ItemsListSeparator) {
            itemToRemove = item;
            break;
        }
    }

    if (itemToRemove == null) {
        return new StructuredSelection(selectedItems);
    }
    // Create a new selection without the collision
    @SuppressWarnings("rawtypes")
    List<?> newItems = new ArrayList(selectedItems);
    newItems.remove(itemToRemove);
    return new StructuredSelection(newItems);

}

From source file:com.aptana.ide.search.AptanaFileSearchPage.java

License:Open Source License

/**
 * removing matches//from w w w.  j ava2  s.  com
 * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#internalRemoveSelected()
 */
public void internalRemoveSelected() {
    if (this.layout != AptanaFileSearchPage.LAYOUT_MATCHES) {
        super.internalRemoveSelected();
    } else {
        TableViewer cc = (TableViewer) this.getViewer();
        StructuredSelection ss = (StructuredSelection) cc.getSelection();
        List list = ss.toList();
        Match[] ms = new Match[list.size()];
        list.toArray(ms);
        this.getInput().removeMatches(ms);
        getViewPart().updateLabel();
    }
}

From source file:com.aptana.ide.search.ui.filesystem.AptanaFileSystemSearchPage.java

License:Open Source License

/**
 * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#internalRemoveSelected()
 *///from   www  .  ja v  a  2 s .  c o m
public void internalRemoveSelected() {
    if (this.layout == LAYOUT_MATCHES) {
        TableViewer cc = (TableViewer) this.getViewer();
        StructuredSelection ss = (StructuredSelection) cc.getSelection();
        List list = ss.toList();
        Match[] ms = new Match[list.size()];
        list.toArray(ms);
        this.getInput().removeMatches(ms);
        getViewPart().updateLabel();
    } else {
        super.internalRemoveSelected();
    }
}

From source file:com.architexa.diagrams.ui.RSETransferDropTargetListener.java

License:Open Source License

@Override
protected void handleDrop() {
    // Following line needed because if drop detail left as 
    // DND.DROP_MOVE, drag source will assume the resource 
    // is somewhere else after the drop and remove the original
    getCurrentEvent().detail = DND.DROP_COPY;
    if (getCurrentEvent().data != null && getCurrentEvent().data instanceof StructuredSelection) {
        StructuredSelection sel = (StructuredSelection) getCurrentEvent().data;
        dropValues = sel.toList();
    }/* w  w  w .jav  a 2  s  . c om*/
    super.handleDrop();
}