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:aspectminingtool.views.Sinergia.ViewPartSinergia.java

License:Open Source License

/**
 * Create the actions./*from   www  .ja v  a 2 s. c o m*/
 */
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);
            selectAsSeedAction.setEnabled(sel.size() > 0);
        }
    });
}

From source file:aspectminingtool.views.UniqueMethods.ViewPartUniqueMethods.java

License:Open Source License

/**
 * Create the actions./*from  www .  j av a2  s.  c  om*/
 */
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) tableViewerLeft.getSelection();
            selectAllActionCallsTable.setEnabled(sel.size() > 0);
            openActionTableRight.setEnabled(sel.size() > 0);
        }
    });

}

From source file:at.bitandart.zoubek.mervin.comments.CommentsView.java

License:Open Source License

/**
 * extracts all EObject link targets from the given selection.
 * /*from w  w w  .ja  v  a 2 s. com*/
 * @param selection
 *            the selection containing the link targets.
 * @return a list of EObject link targets, does not return null.
 */
private List<EObject> extractLinkTargets(IStructuredSelection selection) {

    List<EObject> targets = new ArrayList<EObject>(selection.size());

    Iterator<?> iterator = selection.iterator();
    while (iterator.hasNext()) {

        Object element = iterator.next();
        if (element instanceof EObject) {

            targets.add((EObject) element);

        } else if (element instanceof GraphicalEditPart) {

            // GMF edit part -> use semantic model
            EObject semanticElement = ((GraphicalEditPart) element).resolveSemanticElement();
            targets.add(extractFromTemporaryContainer(semanticElement));

        } else if (element instanceof ConnectionEditPart) {

            // GMF edit part -> use semantic model
            EObject semanticElement = ((ConnectionEditPart) element).resolveSemanticElement();
            targets.add(extractFromTemporaryContainer(semanticElement));

        } else if (element instanceof EditPart) {

            // GEF edit part -> use model if it is an EObject
            Object model = ((EditPart) element).getModel();
            if (model instanceof EObject) {
                targets.add((EObject) model);
            }

        }

    }

    return targets;
}

From source file:at.bitandart.zoubek.mervin.property.diff.PropertyDiffView.java

License:Open Source License

/**
 * creates the input object for the tree diff viewer based on the given
 * selection./*from   w w w.  j a  va 2  s.c  om*/
 * 
 * @param selection
 *            the selection used to create the input object for.
 * @return the input object for the tree diff viewer.
 */
private Object createInputFromSelection(IStructuredSelection selection) {

    Comparison comparison = getComparison(selection);

    List<SelectionEntry> modelEntries = new ArrayList<>(selection.size());

    Iterator<?> selectionIterator = selection.iterator();
    int selectionIndex = 1;
    while (selectionIterator.hasNext()) {

        Object object = selectionIterator.next();
        EObject selectedSemanticModelElement = diagramModelHelper.getSemanticModel(object);
        View selectedNotationModelElement = diagramModelHelper.getNotationModel(object);

        ModelReview currentModelReview = getCurrentModelReview();
        if (currentModelReview != null) {

            View originalNotationModelElement = (View) currentModelReview.getUnifiedModelMap().inverse()
                    .get(selectedNotationModelElement);

            if (originalNotationModelElement != null) {
                selectedNotationModelElement = originalNotationModelElement;
            }
        }

        Match semanticModelMatch = comparison.getMatch(selectedSemanticModelElement);
        Match notationModelMatch = comparison.getMatch(selectedNotationModelElement);

        /*
         * create an entry only if the selection contains a model element
         * contained in the comparison
         */
        if (semanticModelMatch != null || notationModelMatch != null) {
            SelectionEntry modelEntry = new SelectionEntry("#" + selectionIndex, semanticModelMatch,
                    notationModelMatch);
            modelEntries.add(modelEntry);

            // TODO add other (referencing, context, etc...) notation models

            selectionIndex++;
        }

    }

    return modelEntries;
}

From source file:at.medevit.menus.parts.SelectorPart.java

License:Open Source License

/**
 * Create contents of the view part./* ww  w.j a  va 2s.  c om*/
 */
@PostConstruct
public void createControls(Composite parent) {
    parent.setLayout(new GridLayout(1, false));

    // -- person selector
    Label lblPerson = new Label(parent, SWT.NONE);
    lblPerson.setText("Person");

    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    composite.setLayout(new TableColumnLayout());

    selectPersonTV = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION);
    selectPersonTV.setLabelProvider(new AdapterFactoryLabelProvider(mipaf));
    selectPersonTV.setContentProvider(new AdapterFactoryContentProvider(mipaf));
    selectPersonTV.setInput(SampleModel.getDirectory());
    selectPersonTV.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();

            Person p = (Person) selection.getFirstElement();

            selectionService.setSelection(selection.size() == 1 ? p : selection.toArray());

            if (selection.size() == 1) {
                if (p.getPartner() != null) {
                    partnerPersonTV.setSelection(new StructuredSelection(p.getPartner()));
                } else {
                    partnerPersonTV.setSelection(null);
                }
            }
        }
    });
    ViewerFilter[] filters = new ViewerFilter[] { new PersonViewerFilter(selectPersonTV) };
    selectPersonTV.setFilters(filters);

    menuService.registerContextMenu(selectPersonTV.getTable(), SELECTOR_POPUPMENU_ID);

    // -- partner selector
    Label lblPartner = new Label(parent, SWT.NONE);
    lblPartner.setText("Partner");

    Composite composite2 = new Composite(parent, SWT.NONE);
    composite2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    composite2.setLayout(new TableColumnLayout());

    partnerPersonTV = new TableViewer(composite2, SWT.BORDER | SWT.FULL_SELECTION);
    partnerPersonTV.setLabelProvider(new AdapterFactoryLabelProvider(mipaf));
    partnerPersonTV.setContentProvider(new AdapterFactoryContentProvider(mipaf));
    partnerPersonTV.setInput(SampleModel.getDirectory());

}

From source file:at.spardat.xma.guidesign.presentation.action.GuidesignActionBarContributor.java

License:Open Source License

/**
 * This implements {@link ISelectionChangedListener},
 * handling {@link SelectionChangedEvents} by querying for the children and siblings
 * that can be added to the selected object and updating the menus accordingly.
 * <!-- begin-user-doc -->//from ww w. j  ava 2  s .  c  om
 * <!-- 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);
    }
    if (editMenuManager != null) {
        depopulateManager(editMenuManager, editActions);
    }
    // Query the new selection for appropriate new child/sibling descriptors
    //
    Collection newChildDescriptors = null;
    Collection newSiblingDescriptors = null;

    Object object = null;
    ISelection selection = event.getSelection();
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structSels = (IStructuredSelection) selection;
        if (structSels.size() == 1) {
            object = ((IStructuredSelection) selection).getFirstElement();
            EditingDomain domain = ((IEditingDomainProvider) activeEditorPart).getEditingDomain();
            newChildDescriptors = domain.getNewChildDescriptors(object, null);
            newSiblingDescriptors = domain.getNewChildDescriptors(null, object);
        }
        //create edit actions
        editActions = generateEditActions(structSels);
    }

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

    if (editMenuManager != null) {
        populateManager(editMenuManager, editActions, null);
        editMenuManager.update(true);
    }
}

From source file:au.gov.ga.earthsci.application.handlers.ShowViewDialog.java

License:Apache License

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    composite.setLayout(new FillLayout());

    TableViewer viewer = new TableViewer(composite, SWT.NONE);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new PartLabelProvider());

    //TODO this part collection is simply a list of parts that have been shown before
    //need to improve this collection so that it removes duplicates, and also contains
    //parts that are registered but have never been displayed
    viewer.setInput(application.getDescriptors());

    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override/* w w w .java2 s  .  c  o  m*/
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection s = (IStructuredSelection) event.getSelection();
            selection = new MPartDescriptor[s.size()];
            Iterator<?> iterator = s.iterator();
            for (int i = 0; iterator.hasNext(); i++) {
                MPartDescriptor part = (MPartDescriptor) iterator.next();
                selection[i++] = part;
            }
        }
    });

    return composite;
}

From source file:au.gov.ga.earthsci.application.parts.layer.LayerTreePart.java

License:Apache License

@PostConstruct
public void init(Composite parent, EMenuService menuService) {
    LayerOpacityToolControl.setPartContext(context);

    viewer = new CheckboxTreeViewer(parent, SWT.MULTI);
    viewer.getTree().setBackgroundImage(ImageRegistry.getInstance().get(ImageRegistry.ICON_TRANSPARENT));
    context.set(TreeViewer.class, viewer);

    clipboard = new Clipboard(shell.getDisplay());
    context.set(Clipboard.class, clipboard);

    IListProperty childrenProperty = new MultiListProperty(
            new IListProperty[] { BeanProperties.list("children") }); //$NON-NLS-1$

    ObservableListTreeContentProvider contentProvider = new ObservableListTreeContentProvider(
            childrenProperty.listFactory(), null);
    viewer.setContentProvider(contentProvider);

    //TreeViewerEditor.create(viewer, new SecondClickColumnViewerEditorActivationStrategy(viewer), ColumnViewerEditor.DEFAULT);

    IObservableSet knownElements = contentProvider.getKnownElements();
    IObservableMap enabledMap = BeanProperties.value("enabled").observeDetail(knownElements); //$NON-NLS-1$
    IObservableMap opacityMap = BeanProperties.value("opacity").observeDetail(knownElements); //$NON-NLS-1$
    IObservableMap nameMap = BeanProperties.value("name").observeDetail(knownElements); //$NON-NLS-1$
    IObservableMap labelMap = BeanProperties.value("label").observeDetail(knownElements); //$NON-NLS-1$
    IObservableMap statusMap = BeanProperties.value("status").observeDetail(knownElements); //$NON-NLS-1$
    IObservableMap anyChildrenEnabledMap = BeanProperties.value("anyChildrenEnabled") //$NON-NLS-1$
            .observeDetail(knownElements);
    IObservableMap allChildrenEnabledMap = BeanProperties.value("allChildrenEnabled") //$NON-NLS-1$
            .observeDetail(knownElements);
    IObservableMap childrenMap = BeanProperties.value("children").observeDetail(knownElements); //$NON-NLS-1$
    IObservableMap expandedMap = BeanProperties.value("expanded").observeDetail(knownElements); //$NON-NLS-1$

    IObservableMap[] labelAttributeMaps = new IObservableMap[] { enabledMap, opacityMap, nameMap, labelMap,
            anyChildrenEnabledMap, allChildrenEnabledMap, statusMap };

    labelProvider = new LayerTreeLabelProvider(labelAttributeMaps);
    viewer.setLabelProvider(labelProvider);
    viewer.setCheckStateProvider(new LayerTreeCheckStateProvider());

    viewer.setInput(model.getRootNode());
    viewer.setExpandedElements(getExpandedNodes());

    IMapChangeListener childrenListener = new IMapChangeListener() {
        @Override//from   w  w  w .j  a  va2 s.  c  o  m
        public void handleMapChange(MapChangeEvent event) {
            //for any children added, expand the nodes
            Set<?> addedKeys = event.diff.getAddedKeys();
            for (Object o : addedKeys) {
                if (o instanceof ILayerTreeNode) {
                    ((ILayerTreeNode) o).getParent().getValue().setExpanded(true);
                }
            }
        }
    };
    IMapChangeListener expandedListener = new IMapChangeListener() {
        @Override
        public void handleMapChange(MapChangeEvent event) {
            //ensure the expanded elements are kept in sync with the model
            viewer.getTree().getDisplay().asyncExec(new Runnable() {
                @Override
                public void run() {
                    if (!viewer.getTree().isDisposed()) {
                        viewer.setExpandedElements(getExpandedNodes());
                    }
                }
            });
        }
    };
    childrenMap.addMapChangeListener(childrenListener);
    childrenMap.addMapChangeListener(expandedListener);
    expandedMap.addMapChangeListener(expandedListener);

    viewer.addCheckStateListener(new ICheckStateListener() {
        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            Object element = event.getElement();
            if (element instanceof ILayerTreeNode) {
                ILayerTreeNode node = (ILayerTreeNode) element;
                node.enableChildren(event.getChecked());
            }
        }
    });

    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            List<?> list = selection.toList();
            ILayerTreeNode[] array = list.toArray(new ILayerTreeNode[list.size()]);
            selectionService.setSelection(array.length == 1 ? array[0] : array);
        }
    });

    viewer.addTreeListener(new ITreeViewerListener() {
        @Override
        public void treeExpanded(TreeExpansionEvent event) {
            ILayerTreeNode layerNode = (ILayerTreeNode) event.getElement();
            layerNode.setExpanded(true);
        }

        @Override
        public void treeCollapsed(TreeExpansionEvent event) {
            ILayerTreeNode layerNode = (ILayerTreeNode) event.getElement();
            layerNode.setExpanded(false);
        }
    });

    viewer.getTree().addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDoubleClick(MouseEvent e) {
            ViewerCell cell = viewer.getCell(new Point(e.x, e.y));
            if (cell == null)
                return;

            ILayerTreeNode layer = (ILayerTreeNode) cell.getElement();
            selectLayer(layer);
        }

        @Override
        public void mouseDown(MouseEvent e) {
            ViewerCell cell = viewer.getCell(new Point(e.x, e.y));
            if (cell == null) {
                viewer.setSelection(StructuredSelection.EMPTY);
            }
        }
    });

    viewer.getTree().addTraverseListener(new TraverseListener() {
        @Override
        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_RETURN) {
                IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
                if (selection.size() == 1) {
                    ILayerTreeNode layer = (ILayerTreeNode) selection.getFirstElement();
                    selectLayer(layer);
                }
            }
        }
    });

    viewer.setCellEditors(new CellEditor[] { new TextCellEditor(viewer.getTree(), SWT.BORDER) });
    viewer.setColumnProperties(new String[] { "layer" }); //$NON-NLS-1$

    viewer.setCellModifier(new ICellModifier() {
        @Override
        public void modify(Object element, String property, Object value) {
            if (element instanceof Item) {
                element = ((Item) element).getData();
            }
            ((ILayerTreeNode) element).setLabel((String) value);
        }

        @Override
        public Object getValue(Object element, String property) {
            if (element instanceof Item) {
                element = ((Item) element).getData();
            }
            return ((ILayerTreeNode) element).getLabelOrName();
        }

        @Override
        public boolean canModify(Object element, String property) {
            return true;
        }
    });

    ColumnViewerEditorActivationStrategy activationStrategy = new ColumnViewerEditorActivationStrategy(viewer) {
        @Override
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            return event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
        }
    };
    TreeViewerEditor.create(viewer, activationStrategy, ColumnViewerEditor.KEYBOARD_ACTIVATION);

    //add drag and drop support
    int ops = DND.DROP_COPY | DND.DROP_MOVE;
    viewer.addDragSupport(ops, new Transfer[] { LayerTransfer.getInstance() },
            new LayerTreeDragSourceListener(viewer));
    viewer.addDropSupport(ops, new Transfer[] { LayerTransfer.getInstance(), FileTransfer.getInstance() },
            new LayerTreeDropAdapter(viewer, model, context));

    //add context menu
    menuService.registerContextMenu(viewer.getTree(), "au.gov.ga.earthsci.application.layertree.popupmenu"); //$NON-NLS-1$
}

From source file:bndtools.editor.components.ComponentDetailsPage.java

License:Open Source License

void fillReferenceSection(FormToolkit toolkit, Section section) {

    ToolBar toolbar = new ToolBar(section, SWT.FLAT);
    section.setTextClient(toolbar);//from  w  w  w  .j  a va  2 s .co  m

    final ToolItem addItem = new ToolItem(toolbar, SWT.PUSH);
    addItem.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD));

    final ToolItem editItem = new ToolItem(toolbar, SWT.PUSH);
    editItem.setImage(imgEdit);
    editItem.setToolTipText("Edit");
    editItem.setEnabled(false);

    final ToolItem removeItem = new ToolItem(toolbar, SWT.PUSH);
    removeItem.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE));
    removeItem.setDisabledImage(
            PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE_DISABLED));
    removeItem.setToolTipText("Remove");
    removeItem.setEnabled(false);

    Composite composite = toolkit.createComposite(section);
    section.setClient(composite);

    tableReferences = toolkit.createTable(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    tableReferences.setHeaderVisible(true);
    tableReferences.setLinesVisible(false);

    TableColumn col;
    col = new TableColumn(tableReferences, SWT.NONE);
    col.setWidth(100);
    col.setText("Name");

    col = new TableColumn(tableReferences, SWT.NONE);
    col.setWidth(200);
    col.setText("Interface");

    col = new TableColumn(tableReferences, SWT.NONE);
    col.setWidth(35);
    col.setText("Card.");

    col = new TableColumn(tableReferences, SWT.NONE);
    col.setWidth(100);
    col.setText("Target");

    viewerReferences = new TableViewer(tableReferences);
    viewerReferences.setContentProvider(new ArrayContentProvider());
    viewerReferences.setLabelProvider(new ComponentSvcRefTableLabelProvider());

    // Listeners
    viewerReferences.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) viewerReferences.getSelection();
            editItem.setEnabled(selection.size() == 1);
            removeItem.setEnabled(!selection.isEmpty());
        }
    });
    addItem.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            doAddReference();
        };
    });
    editItem.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            doEditReference();
        };
    });
    removeItem.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            doRemoveReference();
        }
    });

    // Layout
    GridData gd;
    GridLayout layout;

    layout = new GridLayout(1, false);
    layout.verticalSpacing = 5;
    layout.horizontalSpacing = 0;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    composite.setLayout(layout);

    gd = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 3);
    gd.widthHint = 250;
    gd.heightHint = 70;
    tableReferences.setLayoutData(gd);
}

From source file:bndtools.editor.components.ComponentListPart.java

License:Open Source License

void createSection(Section section, FormToolkit toolkit) {
    section.setText(Messages.ComponentListPart_listSectionTitle);

    Composite composite = toolkit.createComposite(section);
    section.setClient(composite);//from  ww w  . jav a  2  s . co m

    table = toolkit.createTable(composite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);

    viewer = new TableViewer(table);
    viewer.setUseHashlookup(true);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new ServiceComponentLabelProvider());

    final Button btnAdd = toolkit.createButton(composite, Messages.ComponentListPart_addButton, SWT.PUSH);
    final Button btnRemove = toolkit.createButton(composite, Messages.ComponentListPart_RemoveButton, SWT.PUSH);

    toolkit.paintBordersFor(section);

    // Listeners
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            ArrayList<ServiceComponent> selectedComponents = new ArrayList<ServiceComponent>(selection.size());

            @SuppressWarnings("rawtypes")
            Iterator iterator = selection.iterator();
            while (iterator.hasNext()) {
                String name = (String) iterator.next();
                ServiceComponent component = componentMap.get(name);
                if (component != null)
                    selectedComponents.add(component);
            }

            managedForm.fireSelectionChanged(ComponentListPart.this,
                    new StructuredSelection(selectedComponents));
            btnRemove.setEnabled(!selection.isEmpty());
        }
    });
    viewer.addOpenListener(new IOpenListener() {
        public void open(OpenEvent event) {
            String name = (String) ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (name != null) {
                doOpenComponent(name);
            }
        }
    });
    viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { ResourceTransfer.getInstance() },
            new ComponentListDropAdapter(viewer));
    btnAdd.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            try {
                doAdd();
            } catch (Exception x) {
                Plugin.logError("Error adding component", x);
            }
        }
    });
    btnRemove.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            doRemove();
        }
    });

    // Layout
    GridData gd;
    section.setLayoutData(new GridData(GridData.FILL_BOTH));
    composite.setLayout(new GridLayout(2, false));
    gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3);
    gd.widthHint = 250;
    table.setLayoutData(gd);
    btnAdd.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    btnRemove.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
}