use of org.bndtools.utils.swt.AddRemoveButtonBarPart in project bndtools by bndtools.
the class EditableParametersPart method createControl.
public Control createControl(Composite parent) {
this.parent = parent;
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
composite.setLayout(layout);
Label titleLabel = new Label(composite, SWT.NONE);
titleLabel.setText(title);
titleLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1));
Table table = new Table(composite, SWT.BORDER | SWT.MULTI);
viewer = new TableViewer(table);
viewer.setContentProvider(ArrayContentProvider.getInstance());
final Image iconImg = imageDescriptor.createImage(parent.getDisplay());
viewer.setLabelProvider(new StyledCellLabelProvider() {
@Override
public void update(ViewerCell cell) {
@SuppressWarnings("unchecked") Pair<String, Attrs> entry = (Pair<String, Attrs>) cell.getElement();
StyledString label = new StyledString(entry.getFirst(), BoldStyler.INSTANCE_DEFAULT);
for (Entry<String, String> attribEntry : entry.getSecond().entrySet()) {
label.append("; " + attribEntry.getKey() + "=", StyledString.QUALIFIER_STYLER);
label.append(attribEntry.getValue());
}
cell.setText(label.toString());
cell.setStyleRanges(label.getStyleRanges());
cell.setImage(iconImg);
}
});
viewer.setInput(entries);
GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
gd.widthHint = 280;
gd.heightHint = 80;
table.setLayoutData(gd);
final AddRemoveButtonBarPart buttonBarPart = new AddRemoveButtonBarPart();
ToolBar buttonBar = buttonBarPart.createControl(composite, SWT.FLAT | SWT.VERTICAL);
buttonBar.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
final Image imgEdit = ImageDescriptor.createFromURL(BUNDLE.getEntry("icons/edit.gif")).createImage(parent.getDisplay());
final Image imgEditDisabled = ImageDescriptor.createFromURL(BUNDLE.getEntry("icons/edit-disabled.gif")).createImage(parent.getDisplay());
final ToolItem btnEdit = new ToolItem(buttonBar, SWT.PUSH);
btnEdit.setImage(imgEdit);
btnEdit.setDisabledImage(imgEditDisabled);
buttonBarPart.setRemoveEnabled(false);
btnEdit.setEnabled(false);
buttonBarPart.addListener(new AddRemoveListener() {
@Override
public void addSelected() {
doAdd();
}
@Override
public void removeSelected() {
doRemove();
}
});
btnEdit.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doEdit();
}
});
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
boolean enabled = !viewer.getSelection().isEmpty();
buttonBarPart.setRemoveEnabled(enabled);
btnEdit.setEnabled(enabled);
}
});
viewer.addOpenListener(new IOpenListener() {
@Override
public void open(OpenEvent event) {
doEdit();
}
});
table.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.DEL && e.stateMask == 0)
doRemove();
}
});
composite.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent ev) {
iconImg.dispose();
imgEdit.dispose();
imgEditDisabled.dispose();
}
});
return composite;
}
use of org.bndtools.utils.swt.AddRemoveButtonBarPart in project bndtools by bndtools.
the class ReposPreferencePage method createContents.
@Override
protected Control createContents(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(1, false);
layout.marginRight = 10;
composite.setLayout(layout);
Group group = new Group(composite, SWT.NONE);
group.setText("Templates Repositories");
group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
group.setLayout(new GridLayout(2, false));
final Button btnEnableTemplateRepo = new Button(group, SWT.CHECK);
btnEnableTemplateRepo.setText("Enable templates repositories");
btnEnableTemplateRepo.setSelection(enableTemplateRepo);
btnEnableTemplateRepo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
ControlDecoration decoration = new ControlDecoration(btnEnableTemplateRepo, SWT.RIGHT | SWT.TOP, composite);
decoration.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
decoration.setMarginWidth(3);
decoration.setDescriptionText("These repositories are used to load\ntemplates, in addition to repositories\nconfigured in the Bnd OSGi Workspace.");
decoration.setShowHover(true);
decoration.setShowOnlyOnFocus(false);
Label lblRepos = new Label(group, SWT.NONE);
lblRepos.setText("Repository URLs:");
lblRepos.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
final Table tblRepos = new Table(group, SWT.BORDER | SWT.MULTI);
vwrRepos = new TableViewer(tblRepos);
vwrRepos.setContentProvider(ArrayContentProvider.getInstance());
vwrRepos.setLabelProvider(new URLLabelProvider(tblRepos.getDisplay()));
vwrRepos.setInput(templateRepos);
GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
gd.widthHint = 260;
gd.heightHint = 80;
tblRepos.setLayoutData(gd);
tblRepos.setEnabled(enableTemplateRepo);
final AddRemoveButtonBarPart addRemoveRepoPart = new AddRemoveButtonBarPart();
Control addRemovePanel = addRemoveRepoPart.createControl(group, SWT.FLAT | SWT.VERTICAL);
addRemovePanel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
addRemoveRepoPart.setRemoveEnabled(false);
addRemoveRepoPart.addListener(new AddRemoveListener() {
@Override
public void addSelected() {
doAddRepo();
}
@Override
public void removeSelected() {
doRemoveRepo();
}
});
vwrRepos.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
addRemoveRepoPart.setRemoveEnabled(!vwrRepos.getSelection().isEmpty());
}
});
tblRepos.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.DEL && e.stateMask == 0)
doRemoveRepo();
}
});
btnEnableTemplateRepo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent ev) {
enableTemplateRepo = btnEnableTemplateRepo.getSelection();
tblRepos.setEnabled(enableTemplateRepo);
validate();
}
});
return composite;
}
Aggregations