use of org.eclipse.jface.viewers.StyledString in project bndtools by bndtools.
the class StatusLabelProvider method update.
@Override
public void update(ViewerCell cell) {
IStatus status = (IStatus) cell.getElement();
switch(status.getSeverity()) {
case IStatus.ERROR:
if (imgError == null)
imgError = AbstractUIPlugin.imageDescriptorFromPlugin(Plugin.PLUGIN_ID, "icons/error_obj.gif").createImage();
cell.setImage(imgError);
break;
case IStatus.WARNING:
if (imgWarning == null)
imgWarning = AbstractUIPlugin.imageDescriptorFromPlugin(Plugin.PLUGIN_ID, "icons/warning_obj.gif").createImage();
cell.setImage(imgWarning);
break;
case IStatus.INFO:
if (imgInfo == null)
imgInfo = AbstractUIPlugin.imageDescriptorFromPlugin(Plugin.PLUGIN_ID, "icons/information.gif").createImage();
cell.setImage(imgInfo);
break;
case IStatus.OK:
case IStatus.CANCEL:
default:
break;
}
StyledString label = new StyledString(status.getMessage());
if (status.getException() != null)
label.append(": " + status.getException().toString(), StyledString.QUALIFIER_STYLER);
cell.setText(label.getString());
cell.setStyleRanges(label.getStyleRanges());
}
use of org.eclipse.jface.viewers.StyledString in project bndtools by bndtools.
the class RequirementWithResourceLabelProvider method getLabel.
@Override
public StyledString getLabel(Requirement requirement) {
StyledString label = new StyledString();
Resource resource = requirement.getResource();
if (!(resource == null || resource.getCapabilities("osgi.content").isEmpty()))
appendResourceLabel(label, resource);
if (Namespace.RESOLUTION_OPTIONAL.equals(requirement.getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE)))
label.append(" optionally", StyledString.QUALIFIER_STYLER);
label.append(" requires ", StyledString.QUALIFIER_STYLER);
super.getLabel(label, requirement);
return label;
}
use of org.eclipse.jface.viewers.StyledString in project bndtools by bndtools.
the class R5LabelFormatter method appendNamespaceWithValue.
public static void appendNamespaceWithValue(StyledString label, String ns, String value, boolean shorten) {
String prefix = ns;
if (shorten) {
if (IdentityNamespace.IDENTITY_NAMESPACE.equals(ns))
prefix = "id";
else if (BundleNamespace.BUNDLE_NAMESPACE.equals(ns))
prefix = "";
else if (HostNamespace.HOST_NAMESPACE.equals(ns))
prefix = "host";
else if (ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE.equals(ns))
prefix = "";
else if (PackageNamespace.PACKAGE_NAMESPACE.equals(ns))
prefix = "";
else if (ServiceNamespace.SERVICE_NAMESPACE.equals(ns))
prefix = "";
else if (ContractNamespace.CONTRACT_NAMESPACE.equals(ns))
prefix = "";
else if ("osgi.whiteboard".equals(ns))
prefix = "";
}
if (prefix.length() > 0)
label.append(prefix + "=", StyledString.QUALIFIER_STYLER);
label.append(value, BoldStyler.INSTANCE_DEFAULT);
}
use of org.eclipse.jface.viewers.StyledString in project bndtools by bndtools.
the class R5LabelFormatter method appendRequirementLabel.
public static void appendRequirementLabel(StyledString label, Requirement requirement, boolean shorten) {
String namespace = requirement.getNamespace();
String filter = requirement.getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
boolean optional = Namespace.RESOLUTION_OPTIONAL.equals(requirement.getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE));
FilterParser fp = new FilterParser();
if (filter == null) {
if (namespace.contains("$")) {
Pattern pattern = Pattern.compile("\\{(.*?)\\}");
Matcher matcher = pattern.matcher(namespace);
label.append(namespace);
while (matcher.find()) {
int begin = matcher.start(1);
int end = matcher.end(1);
label.setStyle(begin, end - begin, BoldStyler.INSTANCE_DEFAULT);
}
} else {
label.append(namespace + ": <no filter>", ItalicStyler.INSTANCE_ERROR);
}
} else {
try {
Expression exp = fp.parse(filter);
if (exp instanceof WithRangeExpression) {
appendNamespaceWithValue(label, namespace, ((WithRangeExpression) exp).printExcludingRange(), shorten);
RangeExpression range = ((WithRangeExpression) exp).getRangeExpression();
if (range != null)
label.append(" ").append(formatRangeString(range), StyledString.COUNTER_STYLER);
} else if (ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE.equals(namespace)) {
Matcher matcher = EE_PATTERN.matcher(filter);
if (matcher.find()) {
String eename = matcher.group(1);
String version = matcher.group(2);
appendNamespaceWithValue(label, namespace, eename, true);
label.append(" ").append(version, StyledString.COUNTER_STYLER);
} else {
appendNamespaceWithValue(label, namespace, filter, true);
}
} else {
appendNamespaceWithValue(label, namespace, filter, true);
}
} catch (Exception e) {
label.append(namespace + ": ", StyledString.QUALIFIER_STYLER);
label.append("<parse error>", ItalicStyler.INSTANCE_ERROR);
}
}
boolean first = true;
for (Entry<String, String> directive : requirement.getDirectives().entrySet()) {
if (Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE.equals(directive.getKey()) || Namespace.REQUIREMENT_FILTER_DIRECTIVE.equals(directive.getKey()))
// deal with the filter: and resolution: directives separately
continue;
StringBuilder buf = new StringBuilder();
buf.append(first ? " " : ", ");
buf.append(directive.getKey()).append(":=").append(directive.getValue());
label.append(buf.toString(), StyledString.QUALIFIER_STYLER);
first = false;
}
if (optional) {
label.setStyle(0, label.length(), StyledString.QUALIFIER_STYLER);
label.append(" <optional>", ItalicStyler.INSTANCE_DEFAULT);
}
}
use of org.eclipse.jface.viewers.StyledString in project bndtools by bndtools.
the class AddFilesToRepositoryWizardPage method createControl.
@Override
@SuppressWarnings("unused")
public void createControl(Composite parent) {
setTitle("Add Files to Repository");
Composite composite = new Composite(parent, SWT.NONE);
new Label(composite, SWT.NONE).setText("Selected files:");
// Spacer;
new Label(composite, SWT.NONE);
Table table = new Table(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
table.setLinesVisible(true);
table.setHeaderVisible(true);
TableColumn col;
col = new TableColumn(table, SWT.NONE);
col.setText("Path");
col.setWidth(300);
col = new TableColumn(table, SWT.NONE);
col.setText("Bundle Name/Version");
col.setWidth(300);
viewer = new TableViewer(table);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new StyledCellLabelProvider() {
@Override
public void update(ViewerCell cell) {
File file = (File) cell.getElement();
Pair<String, String> bundleId = bsnMap.get(file);
int index = cell.getColumnIndex();
if (index == 0) {
if (bundleId == null) {
cell.setImage(errorImg);
} else {
cell.setImage(jarImg);
}
StyledString label = new StyledString(file.getName());
String parentPath = file.getParent();
if (parentPath != null) {
label.append(" (" + parentPath + ")", StyledString.QUALIFIER_STYLER);
}
cell.setText(label.getString());
cell.setStyleRanges(label.getStyleRanges());
} else if (index == 1) {
if (bundleId == null) {
cell.setImage(errorImg);
cell.setText("Not a JAR file");
} else {
String bsn = bundleId.getFirst();
String version = bundleId.getSecond();
if (bsn == null) {
cell.setImage(warnImg);
cell.setText("Not a Bundle JAR");
} else {
cell.setImage(okayImg);
StyledString styledString = new StyledString(bsn);
if (version != null) {
styledString.append(" [" + version + "]", StyledString.COUNTER_STYLER);
cell.setText(styledString.getString());
cell.setStyleRanges(styledString.getStyleRanges());
}
}
}
}
}
});
viewer.setInput(files);
validate();
final Button btnAdd = new Button(composite, SWT.PUSH);
btnAdd.setText("Add JARs...");
final Button btnAddExternal = new Button(composite, SWT.PUSH);
btnAddExternal.setText("Add External JARs...");
final Button btnRemove = new Button(composite, SWT.NONE);
btnRemove.setText("Remove");
btnRemove.setEnabled(false);
// LISTENERS
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
btnRemove.setEnabled(!viewer.getSelection().isEmpty());
}
});
btnAdd.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doAdd();
}
});
btnAddExternal.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doAddExternal();
}
});
btnRemove.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doRemove();
}
});
// LAYOUT
composite.setLayout(new GridLayout(2, false));
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 4));
btnAdd.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
btnRemove.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
setControl(composite);
}
Aggregations