Search in sources :

Example 76 with StyledString

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());
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) StyledString(org.eclipse.jface.viewers.StyledString)

Example 77 with StyledString

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;
}
Also used : Resource(org.osgi.resource.Resource) StyledString(org.eclipse.jface.viewers.StyledString)

Example 78 with StyledString

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);
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString)

Example 79 with StyledString

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);
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) RangeExpression(aQute.bnd.osgi.resource.FilterParser.RangeExpression) WithRangeExpression(aQute.bnd.osgi.resource.FilterParser.WithRangeExpression) SimpleExpression(aQute.bnd.osgi.resource.FilterParser.SimpleExpression) Expression(aQute.bnd.osgi.resource.FilterParser.Expression) WithRangeExpression(aQute.bnd.osgi.resource.FilterParser.WithRangeExpression) RangeExpression(aQute.bnd.osgi.resource.FilterParser.RangeExpression) WithRangeExpression(aQute.bnd.osgi.resource.FilterParser.WithRangeExpression) StyledString(org.eclipse.jface.viewers.StyledString) FilterParser(aQute.bnd.osgi.resource.FilterParser)

Example 80 with StyledString

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);
}
Also used : StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) TableColumn(org.eclipse.swt.widgets.TableColumn) ViewerCell(org.eclipse.jface.viewers.ViewerCell) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Pair(bndtools.types.Pair)

Aggregations

StyledString (org.eclipse.jface.viewers.StyledString)95 Image (org.eclipse.swt.graphics.Image)17 JavaCompletionProposal (org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal)8 LazyJavaCompletionProposal (org.eclipse.jdt.internal.ui.text.java.LazyJavaCompletionProposal)8 ViewerCell (org.eclipse.jface.viewers.ViewerCell)5 GridData (org.eclipse.swt.layout.GridData)5 Table (org.eclipse.swt.widgets.Table)5 Entry (java.util.Map.Entry)4 StyledCellLabelProvider (org.eclipse.jface.viewers.StyledCellLabelProvider)4 Styler (org.eclipse.jface.viewers.StyledString.Styler)4 Capability (org.osgi.resource.Capability)4 EObject (org.eclipse.emf.ecore.EObject)3 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 Label (org.eclipse.swt.widgets.Label)3 Version (org.osgi.framework.Version)3 Resource (org.osgi.resource.Resource)3 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)2 IStatus (org.eclipse.core.runtime.IStatus)2