Search in sources :

Example 1 with PrivatePackageTableLabelProvider

use of bndtools.editor.common.PrivatePackageTableLabelProvider in project bndtools by bndtools.

the class PrivatePackagesPart method createSection.

void createSection(Section section, FormToolkit toolkit) {
    section.setText("Private Packages");
    section.setDescription("The listed packages will be included in the bundle but not exported.");
    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("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("Remove");
    removeItem.setEnabled(false);
    Composite composite = toolkit.createComposite(section);
    section.setClient(composite);
    table = toolkit.createTable(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    viewer = new TableViewer(table);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new PrivatePackageTableLabelProvider());
    // Listeners
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            managedForm.fireSelectionChanged(PrivatePackagesPart.this, event.getSelection());
            removeItem.setEnabled(!viewer.getSelection().isEmpty());
        }
    });
    viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer(), TextTransfer.getInstance(), ResourceTransfer.getInstance() }, new PackageDropAdapter<String>(viewer) {

        @Override
        protected String createNewEntry(String packageName) {
            return packageName;
        }

        @Override
        protected void addRows(int index, Collection<String> rows) {
            if (rows.isEmpty())
                // skip marking dirty
                return;
            if (index == -1) {
                packages.addAll(rows);
                viewer.add(rows.toArray());
            } else {
                packages.addAll(index, rows);
                viewer.refresh();
            }
            viewer.setSelection(new StructuredSelection(rows));
            markDirty();
        }

        @Override
        protected int indexOf(Object object) {
            return 0;
        }
    });
    table.addKeyListener(new KeyAdapter() {

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

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            doRemovePackages();
        }
    });
    // Layout
    GridLayout layout = new GridLayout(1, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    composite.setLayout(layout);
    GridData gd;
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.heightHint = 75;
    gd.widthHint = 75;
    table.setLayoutData(gd);
}
Also used : PrivatePackageTableLabelProvider(bndtools.editor.common.PrivatePackageTableLabelProvider) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ToolBar(org.eclipse.swt.widgets.ToolBar) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) ToolItem(org.eclipse.swt.widgets.ToolItem)

Aggregations

PrivatePackageTableLabelProvider (bndtools.editor.common.PrivatePackageTableLabelProvider)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 KeyAdapter (org.eclipse.swt.events.KeyAdapter)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 ToolBar (org.eclipse.swt.widgets.ToolBar)1 ToolItem (org.eclipse.swt.widgets.ToolItem)1