use of org.eclipse.jface.viewers.StyledString in project bndtools by bndtools.
the class R5LabelFormatter method appendCapability.
public static void appendCapability(StyledString label, Capability cap, boolean shorten) {
String ns = cap.getNamespace();
Object nsValue = cap.getAttributes().get(getMainAttributeName(ns));
String versionAttributeName = getVersionAttributeName(ns);
if (nsValue != null) {
appendNamespaceWithValue(label, ns, nsValue.toString(), shorten);
if (versionAttributeName != null) {
Object version = cap.getAttributes().get(versionAttributeName);
if (version != null) {
label.append(", " + versionAttributeName, StyledString.QUALIFIER_STYLER);
label.append(" " + version.toString(), BoldStyler.INSTANCE_COUNTER);
}
}
} else {
label.append(ns, BoldStyler.INSTANCE_DEFAULT);
}
label.append(" ", StyledString.QUALIFIER_STYLER);
if (!cap.getAttributes().isEmpty()) {
boolean first = true;
for (Entry<String, Object> entry : cap.getAttributes().entrySet()) {
String key = entry.getKey();
if (!key.equals(ns) && !key.equals(versionAttributeName)) {
if (first)
label.append("[", StyledString.QUALIFIER_STYLER);
else
label.append(", ", StyledString.QUALIFIER_STYLER);
first = false;
label.append(key + "=", StyledString.QUALIFIER_STYLER);
label.append(entry.getValue() != null ? entry.getValue().toString() : "<null>", StyledString.QUALIFIER_STYLER);
}
}
if (!first)
label.append("]", StyledString.QUALIFIER_STYLER);
}
if (!cap.getDirectives().isEmpty()) {
label.append(" ");
boolean first = true;
for (Entry<String, String> directive : cap.getDirectives().entrySet()) {
label.append(directive.getKey() + ":=" + directive.getValue(), StyledString.QUALIFIER_STYLER);
if (!first)
label.append(", ", StyledString.QUALIFIER_STYLER);
}
}
}
use of org.eclipse.jface.viewers.StyledString in project bndtools by bndtools.
the class R5LabelFormatter method appendResourceLabel.
public static void appendResourceLabel(StyledString label, Resource resource) {
Capability identity = ResourceUtils.getIdentityCapability(resource);
String name = ResourceUtils.getIdentity(identity);
if (name == null) {
if (resource != null) {
name = resource.toString();
} else {
name = "<unknown>";
}
}
label.append(name, BoldStyler.INSTANCE_DEFAULT);
Version version = ResourceUtils.getVersion(identity);
if (version != null)
label.append(" " + version, StyledString.COUNTER_STYLER);
}
use of org.eclipse.jface.viewers.StyledString in project bndtools by bndtools.
the class RequirementLabelProvider method update.
@Override
public void update(ViewerCell cell) {
Object element = cell.getElement();
if (element instanceof Requirement) {
Requirement requirement = (Requirement) element;
StyledString label = getLabel(requirement);
cell.setText(label.getString());
cell.setStyleRanges(label.getStyleRanges());
Image icon = getImage(R5LabelFormatter.getNamespaceImagePath(requirement.getNamespace()), true);
if (icon != null)
cell.setImage(icon);
}
}
use of org.eclipse.jface.viewers.StyledString in project bndtools by bndtools.
the class RequirementWithResourceLabelProvider method appendResourceLabel.
protected void appendResourceLabel(StyledString label, Resource resource) {
Capability identity = ResourceUtils.getIdentityCapability(resource);
String name = ResourceUtils.getIdentity(identity);
if (name == null) {
if (resource != null) {
name = resource.toString();
} else {
name = "<unknown>";
}
}
label.append(name);
Version version = ResourceUtils.getVersion(identity);
if (version != null)
label.append(" " + version, StyledString.COUNTER_STYLER);
}
use of org.eclipse.jface.viewers.StyledString in project bndtools by bndtools.
the class WorkspacePreviewPage method createControl.
@Override
public void createControl(Composite parent) {
setTitle("Preview Changes");
//$NON-NLS-1$
setImageDescriptor(Plugin.imageDescriptorFromPlugin("icons/bndtools-wizban.png"));
imgAdded = AbstractUIPlugin.imageDescriptorFromPlugin(Plugin.PLUGIN_ID, "icons/incoming.gif").createImage(parent.getDisplay());
imgOverwrite = AbstractUIPlugin.imageDescriptorFromPlugin(Plugin.PLUGIN_ID, "icons/conflict.gif").createImage(parent.getDisplay());
imgError = AbstractUIPlugin.imageDescriptorFromPlugin(Plugin.PLUGIN_ID, "icons/error_obj.gif").createImage(parent.getDisplay());
int columns = 4;
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(columns, false);
composite.setLayout(layout);
setControl(composite);
Label lblTitle = new Label(composite, SWT.NONE);
lblTitle.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, columns, 1));
// Table
tblOutputs = new Table(composite, SWT.BORDER | SWT.CHECK);
tblOutputs.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, columns, 1));
vwrOutputs = new CheckboxTableViewer(tblOutputs);
vwrOutputs.setContentProvider(ArrayContentProvider.getInstance());
vwrOutputs.setLabelProvider(new StyledCellLabelProvider() {
@Override
public void update(ViewerCell cell) {
StyledString label;
Image icon;
String path = (String) cell.getElement();
String error = resourceErrors.get(path);
if (error != null) {
label = new StyledString(path, ItalicStyler.INSTANCE_ERROR);
icon = imgError;
} else {
label = new StyledString(path);
icon = existingFiles.contains(path) ? imgOverwrite : imgAdded;
}
cell.setText(path);
cell.setStyleRanges(label.getStyleRanges());
cell.setImage(icon);
}
});
vwrOutputs.setSorter(new ViewerSorter(Collator.getInstance()));
// Details display
final Label lblDetails = new Label(composite, SWT.NONE);
lblDetails.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, columns, 1));
lblDetails.setText(MSG_NOTHING_SELECTED);
// Button Panel
Label spacer1 = new Label(composite, SWT.NONE);
spacer1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
Button btnSelectNonConflict = new Button(composite, SWT.PUSH);
btnSelectNonConflict.setText("Select Non-Conflicting");
btnSelectNonConflict.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
modifyLock.modifyOperation(new Runnable() {
@Override
public void run() {
checkedPaths.clear();
for (Entry<String, Resource> entry : templateOutputs.entries()) {
String path = entry.getKey();
if (!existingFiles.contains(path))
checkedPaths.add(path);
}
vwrOutputs.setCheckedElements(checkedPaths.toArray());
}
});
}
});
Button btnSelectAll = new Button(composite, SWT.PUSH);
btnSelectAll.setText("Select All");
btnSelectAll.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
vwrOutputs.setAllChecked(true);
}
});
Button btnSelectNone = new Button(composite, SWT.PUSH);
btnSelectNone.setText("Select None");
btnSelectNone.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
vwrOutputs.setAllChecked(false);
}
});
// Listeners
vwrOutputs.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection sel = (IStructuredSelection) vwrOutputs.getSelection();
if (sel.isEmpty()) {
lblDetails.setText(MSG_NOTHING_SELECTED);
} else {
String path = (String) sel.getFirstElement();
String resourceError = resourceErrors.get(path);
if (resourceError != null) {
lblDetails.setText(resourceError);
} else if (existingFiles.contains(path)) {
lblDetails.setText("This file already exists and will be overwritten");
} else {
lblDetails.setText("This file will be created");
}
}
}
});
vwrOutputs.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(final CheckStateChangedEvent event) {
modifyLock.ifNotModifying(new Runnable() {
@Override
public void run() {
final String updatedPath = (String) event.getElement();
if (event.getChecked()) {
checkedPaths.add(updatedPath);
// Check any directories that are parents of this path
modifyLock.modifyOperation(new Runnable() {
@Override
public void run() {
for (Entry<String, Resource> entry : templateOutputs.entries()) {
String path = entry.getKey();
if (path.endsWith("/") && updatedPath.startsWith(path)) {
checkedPaths.add(path);
vwrOutputs.setChecked(path, true);
}
}
}
});
} else {
checkedPaths.remove(updatedPath);
// Uncheck any paths that are descendants of this path
if (updatedPath.endsWith("/")) {
modifyLock.modifyOperation(new Runnable() {
@Override
public void run() {
for (Entry<String, Resource> entry : templateOutputs.entries()) {
String path = entry.getKey();
if (path.startsWith(updatedPath)) {
checkedPaths.remove(path);
vwrOutputs.setChecked(path, false);
}
}
}
});
}
}
}
});
}
});
}
Aggregations