Search in sources :

Example 46 with ToolItem

use of org.eclipse.swt.widgets.ToolItem in project bndtools by bndtools.

the class TestSuiteLabelProvider method createSection.

private void createSection(Section section, FormToolkit toolkit) {
    section.setText(Messages.TestSuitesPart_section_junit_tests);
    Composite composite = toolkit.createComposite(section);
    section.setClient(composite);
    // Section toolbar buttons
    ToolBar toolbar = new ToolBar(section, SWT.FLAT);
    section.setTextClient(toolbar);
    final ToolItem addItem = new ToolItem(toolbar, SWT.PUSH);
    addItem.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD));
    addItem.setToolTipText(Messages.TestSuitesPart_add);
    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(Messages.TestSuitesPart_remove);
    removeItem.setEnabled(false);
    Table table = toolkit.createTable(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    viewer = new TableViewer(table);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new TestSuiteLabelProvider());
    toolbar = new ToolBar(composite, SWT.FLAT | SWT.HORIZONTAL | SWT.RIGHT);
    final ToolItem btnMoveUp = new ToolItem(toolbar, SWT.PUSH);
    btnMoveUp.setText("Up");
    btnMoveUp.setImage(imgUp);
    btnMoveUp.setEnabled(false);
    final ToolItem btnMoveDown = new ToolItem(toolbar, SWT.PUSH);
    btnMoveDown.setText("Down");
    btnMoveDown.setImage(imgDown);
    btnMoveDown.setEnabled(false);
    // LISTENERS
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            boolean enabled = selection != null && !selection.isEmpty();
            removeItem.setEnabled(enabled);
            btnMoveUp.setEnabled(enabled);
            btnMoveDown.setEnabled(enabled);
            getManagedForm().fireSelectionChanged(TestSuitesPart.this, selection);
        }
    });
    viewer.addOpenListener(new IOpenListener() {

        @Override
        public void open(OpenEvent event) {
            String name = (String) ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (name != null)
                doOpenSource(name);
        }
    });
    viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { ResourceTransfer.getInstance() }, new TestSuiteListDropAdapter());
    addItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doAdd();
        }
    });
    removeItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doRemove();
        }
    });
    table.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.character == SWT.DEL) {
                doRemove();
            } else if (e.character == '+') {
                doAdd();
            }
        }
    });
    btnMoveUp.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doMoveUp();
        }
    });
    btnMoveDown.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doMoveDown();
        }
    });
    // Layout
    GridLayout layout;
    layout = new GridLayout(1, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = 0;
    layout.horizontalSpacing = 0;
    composite.setLayout(layout);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    // gd.widthHint = 75;
    gd.heightHint = 75;
    table.setLayoutData(gd);
    toolbar.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
}
Also used : Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) KeyAdapter(org.eclipse.swt.events.KeyAdapter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) KeyEvent(org.eclipse.swt.events.KeyEvent) IOpenListener(org.eclipse.jface.viewers.IOpenListener) GridLayout(org.eclipse.swt.layout.GridLayout) ToolBar(org.eclipse.swt.widgets.ToolBar) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) ToolItem(org.eclipse.swt.widgets.ToolItem) OpenEvent(org.eclipse.jface.viewers.OpenEvent)

Example 47 with ToolItem

use of org.eclipse.swt.widgets.ToolItem in project sling by apache.

the class MVPEditor method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    // now add the node type dropbox-combo
    Composite header = new Composite(composite, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    layout.numColumns = 3;
    header.setLayout(layout);
    Label label = new Label(header, SWT.WRAP);
    label.setText("Modify property " + property.getName() + ":");
    GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
    data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
    label.setLayoutData(data);
    label.setFont(parent.getFont());
    ToolBar buttonBar = new ToolBar(header, SWT.NONE);
    ToolItem invisible = new ToolItem(buttonBar, SWT.NONE);
    ToolItem plus = new ToolItem(buttonBar, SWT.NONE);
    plus.setImage(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_ADD).createImage());
    plus.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            plus();
        }
    });
    final ToolItem minus = new ToolItem(buttonBar, SWT.NONE);
    minus.setImage(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE).createImage());
    minus.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            minus();
        }
    });
    minus.setEnabled(false);
    Composite tableParent = new Composite(composite, SWT.NONE);
    final GridData layoutData = new GridData(GridData.FILL_BOTH);
    layoutData.heightHint = 150;
    tableParent.setLayoutData(layoutData);
    TableColumnLayout tableLayout = new TableColumnLayout();
    tableParent.setLayout(tableLayout);
    viewer = new TableViewer(tableParent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    viewer.getTable().setLinesVisible(true);
    viewer.getTable().setHeaderVisible(true);
    // accessing property here directly, instead of going via (JcrProperty)inputElement;
    String[] rawLines = property.getValuesAsString();
    // convert raw lines to Line objects for easier editing management
    for (int i = 0; i < rawLines.length; i++) {
        lines.add(new Line(rawLines[i]));
    }
    viewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return lines.toArray();
        }
    });
    TableViewerColumn column0 = new TableViewerColumn(viewer, SWT.NONE);
    column0.getColumn().setText("Type");
    column0.getColumn().setResizable(true);
    column0.getColumn().setWidth(100);
    tableLayout.setColumnData(column0.getColumn(), new ColumnWeightData(20, 100));
    column0.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            try {
                cell.setText(property.getTypeAsString());
                cell.setForeground(greyColor);
            } catch (Exception e) {
                cell.setText("n/a");
                cell.setForeground(greyColor);
            }
        }
    });
    TableViewerColumn column1 = new TableViewerColumn(viewer, SWT.NONE);
    column1.getColumn().setText("Value");
    column1.getColumn().setResizable(true);
    column1.getColumn().setWidth(200);
    tableLayout.setColumnData(column1.getColumn(), new ColumnWeightData(80, 200));
    column1.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            Line line = (Line) cell.getElement();
            cell.setText(line.getValue());
        }
    });
    column1.setEditingSupport(new EditingSupport(viewer) {

        @Override
        protected void setValue(Object element, Object value) {
            Line line = (Line) element;
            line.setValue(String.valueOf(value));
            // trigger a refresh:
            viewer.setInput(property);
        }

        @Override
        protected Object getValue(Object element) {
            final Line line = (Line) element;
            final String value = line.getValue();
            System.out.println("Value=" + value);
            return value;
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            return new TextCellEditor(viewer.getTable());
        }

        @Override
        protected boolean canEdit(Object element) {
            // all values are editable
            return true;
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            final ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection iss = (IStructuredSelection) selection;
                if (iss.isEmpty()) {
                    minus.setEnabled(false);
                } else {
                    minus.setEnabled(true);
                }
            } else {
                minus.setEnabled(false);
            }
        }
    });
    viewer.setInput(property);
    return composite;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) Label(org.eclipse.swt.widgets.Label) EditingSupport(org.eclipse.jface.viewers.EditingSupport) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) ToolItem(org.eclipse.swt.widgets.ToolItem) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ViewerCell(org.eclipse.jface.viewers.ViewerCell) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 48 with ToolItem

use of org.eclipse.swt.widgets.ToolItem in project bndtools by bndtools.

the class RepositoryBundleSelectionPart method createSection.

void createSection(Section section, FormToolkit toolkit) {
    // Toolbar buttons
    ToolBar toolbar = new ToolBar(section, SWT.FLAT);
    section.setTextClient(toolbar);
    fillToolBar(toolbar);
    Composite composite = toolkit.createComposite(section);
    section.setClient(composite);
    table = toolkit.createTable(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL);
    viewer = new TableViewer(table);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(getLabelProvider());
    // Listeners
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ToolItem remove = getRemoveItemTool();
            if (remove != null)
                remove.setEnabled(isRemovable(event.getSelection()));
        }
    });
    ViewerDropAdapter dropAdapter = new ViewerDropAdapter(viewer) {

        @Override
        public void dragEnter(DropTargetEvent event) {
            super.dragEnter(event);
            event.detail = DND.DROP_COPY;
        }

        @Override
        public boolean validateDrop(Object target, int operation, TransferData transferType) {
            if (FileTransfer.getInstance().isSupportedType(transferType))
                return true;
            if (ResourceTransfer.getInstance().isSupportedType(transferType))
                return true;
            if (URLTransfer.getInstance().isSupportedType(transferType))
                return true;
            ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
            if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
                return false;
            }
            Iterator<?> iterator = ((IStructuredSelection) selection).iterator();
            while (iterator.hasNext()) {
                if (!selectionIsDroppable(iterator.next())) {
                    return false;
                }
            }
            return true;
        }

        private boolean selectionIsDroppable(Object element) {
            return element instanceof RepositoryBundle || element instanceof RepositoryBundleVersion || element instanceof ProjectBundle || element instanceof RepositoryResourceElement;
        }

        @Override
        public boolean performDrop(Object data) {
            TransferData transfer = getCurrentEvent().currentDataType;
            if (URLTransfer.getInstance().isSupportedType(transfer)) {
                String urlStr = (String) URLTransfer.getInstance().nativeToJava(transfer);
                return handleURLDrop(urlStr);
            } else if (data instanceof String[]) {
                return handleFileNameDrop((String[]) data);
            } else if (data instanceof IResource[]) {
                return handleResourceDrop((IResource[]) data);
            } else {
                return handleSelectionDrop();
            }
        }

        private boolean handleResourceDrop(IResource[] resources) {
            File[] files = new File[resources.length];
            for (int i = 0; i < resources.length; i++) {
                files[i] = resources[i].getLocation().toFile();
            }
            return handleFileDrop(files);
        }

        private boolean handleFileNameDrop(String[] paths) {
            File[] files = new File[paths.length];
            for (int i = 0; i < paths.length; i++) {
                files[i] = new File(paths[i]);
            }
            return handleFileDrop(files);
        }

        private boolean handleFileDrop(File[] files) {
            if (files.length > 0) {
                BndPreferences prefs = new BndPreferences();
                boolean hideWarning = prefs.getHideWarningExternalFile();
                if (!hideWarning) {
                    MessageDialogWithToggle dialog = MessageDialogWithToggle.openWarning(getSection().getShell(), "Add External Files", "External files cannot be directly added to a project, they must be added to a local repository first.", "Do not show this warning again.", false, null, null);
                    if (Window.CANCEL == dialog.getReturnCode())
                        return false;
                    if (dialog.getToggleState()) {
                        prefs.setHideWarningExternalFile(true);
                    }
                }
                AddFilesToRepositoryWizard wizard = new AddFilesToRepositoryWizard(null, files);
                WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
                if (Window.OK == dialog.open()) {
                    List<Pair<String, String>> addingBundles = wizard.getSelectedBundles();
                    List<VersionedClause> addingClauses = new ArrayList<VersionedClause>(addingBundles.size());
                    for (Pair<String, String> addingBundle : addingBundles) {
                        Attrs attribs = new Attrs();
                        attribs.put(Constants.VERSION_ATTRIBUTE, addingBundle.getSecond());
                        addingClauses.add(new VersionedClause(addingBundle.getFirst(), attribs));
                    }
                    handleAdd(addingClauses);
                }
                return true;
            }
            return false;
        }

        private boolean handleSelectionDrop() {
            ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
            if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
                return false;
            }
            List<VersionedClause> adding = new LinkedList<VersionedClause>();
            Iterator<?> iterator = ((IStructuredSelection) selection).iterator();
            while (iterator.hasNext()) {
                Object item = iterator.next();
                if (item instanceof RepositoryBundle) {
                    VersionedClause newClause = RepositoryBundleUtils.convertRepoBundle((RepositoryBundle) item);
                    adding.add(newClause);
                } else if (item instanceof RepositoryBundleVersion) {
                    RepositoryBundleVersion bundleVersion = (RepositoryBundleVersion) item;
                    VersionedClause newClause = RepositoryBundleUtils.convertRepoBundleVersion(bundleVersion, phase);
                    adding.add(newClause);
                } else if (item instanceof RepositoryResourceElement) {
                    RepositoryResourceElement elt = (RepositoryResourceElement) item;
                    VersionedClause newClause = RepositoryBundleUtils.convertRepoBundleVersion(elt.getRepositoryBundleVersion(), phase);
                    adding.add(newClause);
                }
            }
            handleAdd(adding);
            return true;
        }

        private boolean handleURLDrop(String urlStr) {
            try {
                URI uri = new URI(sanitizeUrl(urlStr));
                AddJpmDependenciesWizard wizard = new AddJpmDependenciesWizard(uri);
                WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
                if (dialog.open() == Window.OK) {
                    Set<ResourceDescriptor> resources = wizard.getResult();
                    List<VersionedClause> newBundles = new ArrayList<VersionedClause>(resources.size());
                    for (ResourceDescriptor resource : resources) {
                        Attrs attrs = new Attrs();
                        attrs.put(Constants.VERSION_ATTRIBUTE, resource.version != null ? resource.version.toString() : Version.emptyVersion.toString());
                        VersionedClause clause = new VersionedClause(resource.bsn, attrs);
                        newBundles.add(clause);
                    }
                    handleAdd(newBundles);
                    return true;
                }
                return false;
            } catch (URISyntaxException e) {
                MessageDialog.openError(getSection().getShell(), "Error", "The dropped URL was invalid: " + urlStr);
                return false;
            }
        }

        private String sanitizeUrl(String urlStr) {
            int newline = urlStr.indexOf('\n');
            if (newline > -1)
                return urlStr.substring(0, newline).trim();
            return urlStr;
        }

        private void handleAdd(Collection<VersionedClause> newClauses) {
            if (newClauses == null || newClauses.isEmpty())
                return;
            List<VersionedClause> toAdd = new LinkedList<VersionedClause>();
            for (VersionedClause newClause : newClauses) {
                boolean found = false;
                for (ListIterator<VersionedClause> iter = bundles.listIterator(); iter.hasNext(); ) {
                    VersionedClause existing = iter.next();
                    if (newClause.getName().equals(existing.getName())) {
                        int index = iter.previousIndex();
                        iter.set(newClause);
                        viewer.replace(newClause, index);
                        found = true;
                        break;
                    }
                }
                if (!found)
                    toAdd.add(newClause);
            }
            bundles.addAll(toAdd);
            viewer.add(toAdd.toArray());
            markDirty();
        }
    };
    dropAdapter.setFeedbackEnabled(false);
    dropAdapter.setExpandEnabled(false);
    viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer(), FileTransfer.getInstance(), ResourceTransfer.getInstance(), URLTransfer.getInstance() }, dropAdapter);
    table.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.character == SWT.DEL) {
                doRemove();
            } else if (e.character == '+') {
                doAdd();
            }
        }
    });
    // Layout
    GridLayout layout = new GridLayout(1, false);
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    composite.setLayout(layout);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.widthHint = 50;
    gd.heightHint = getTableHeightHint();
    table.setLayoutData(gd);
}
Also used : RepositoryBundle(bndtools.model.repo.RepositoryBundle) RepositoryBundleVersion(bndtools.model.repo.RepositoryBundleVersion) BndPreferences(bndtools.preferences.BndPreferences) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) KeyAdapter(org.eclipse.swt.events.KeyAdapter) ArrayList(java.util.ArrayList) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ProjectBundle(bndtools.model.repo.ProjectBundle) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) LinkedList(java.util.LinkedList) Collection(java.util.Collection) File(java.io.File) AddFilesToRepositoryWizard(bndtools.wizards.workspace.AddFilesToRepositoryWizard) Attrs(aQute.bnd.header.Attrs) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) TransferData(org.eclipse.swt.dnd.TransferData) ISelection(org.eclipse.jface.viewers.ISelection) ToolItem(org.eclipse.swt.widgets.ToolItem) Pair(bndtools.types.Pair) Composite(org.eclipse.swt.widgets.Composite) ViewerDropAdapter(org.eclipse.jface.viewers.ViewerDropAdapter) RepositoryResourceElement(bndtools.model.repo.RepositoryResourceElement) ToolBar(org.eclipse.swt.widgets.ToolBar) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) AddJpmDependenciesWizard(org.bndtools.core.ui.wizards.jpm.AddJpmDependenciesWizard) TableViewer(org.eclipse.jface.viewers.TableViewer) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IResource(org.eclipse.core.resources.IResource) ResourceDescriptor(aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)

Example 49 with ToolItem

use of org.eclipse.swt.widgets.ToolItem in project bndtools by bndtools.

the class RunBlacklistPart method fillToolBar.

private void fillToolBar(ToolBar toolbar) {
    // Add Bundle
    addBundleTool = new ToolItem(toolbar, SWT.PUSH);
    addBundleTool.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD));
    addBundleTool.setToolTipText("Add Bundle Requirement");
    addBundleTool.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doAddBundle();
        }
    });
    // Remove
    removeTool = new ToolItem(toolbar, SWT.PUSH);
    removeTool.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE));
    removeTool.setDisabledImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE_DISABLED));
    removeTool.setToolTipText("Remove");
    removeTool.setEnabled(false);
    removeTool.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doRemove();
        }
    });
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 50 with ToolItem

use of org.eclipse.swt.widgets.ToolItem in project bndtools by bndtools.

the class AddRemoveButtonBarPart method createControl.

public ToolBar createControl(Composite parent, int style) {
    toolbar = new ToolBar(parent, style);
    btnAdd = new ToolItem(toolbar, SWT.PUSH);
    btnAdd.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD));
    btnAdd.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            for (AddRemoveListener l : listeners) {
                l.addSelected();
            }
        }
    });
    btnRemove = new ToolItem(toolbar, SWT.PUSH);
    btnRemove.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE));
    btnRemove.setDisabledImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE_DISABLED));
    btnRemove.setToolTipText("Remove");
    btnRemove.setEnabled(false);
    btnRemove.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            for (AddRemoveListener l : listeners) {
                l.removeSelected();
            }
        }
    });
    return toolbar;
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ToolBar(org.eclipse.swt.widgets.ToolBar) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ToolItem(org.eclipse.swt.widgets.ToolItem)

Aggregations

ToolItem (org.eclipse.swt.widgets.ToolItem)140 ToolBar (org.eclipse.swt.widgets.ToolBar)110 SelectionEvent (org.eclipse.swt.events.SelectionEvent)91 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)81 GridData (org.eclipse.swt.layout.GridData)73 Composite (org.eclipse.swt.widgets.Composite)64 GridLayout (org.eclipse.swt.layout.GridLayout)58 Image (org.eclipse.swt.graphics.Image)36 Label (org.eclipse.swt.widgets.Label)32 Point (org.eclipse.swt.graphics.Point)26 DisposeEvent (org.eclipse.swt.events.DisposeEvent)25 DisposeListener (org.eclipse.swt.events.DisposeListener)24 Cursor (org.eclipse.swt.graphics.Cursor)20 FillLayout (org.eclipse.swt.layout.FillLayout)18 SelectionListener (org.eclipse.swt.events.SelectionListener)17 TableViewer (org.eclipse.jface.viewers.TableViewer)16 Text (org.eclipse.swt.widgets.Text)16 Display (org.eclipse.swt.widgets.Display)15 ArrayList (java.util.ArrayList)14 List (java.util.List)14