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