Search in sources :

Example 66 with StyledString

use of org.eclipse.jface.viewers.StyledString in project bndtools by bndtools.

the class ResolutionTreeLabelProvider method update.

@Override
public void update(ViewerCell cell) {
    Object element = cell.getElement();
    StyledString label = new StyledString();
    Image icon = null;
    if (element instanceof ResolutionTreeItem) {
        ResolutionTreeItem item = (ResolutionTreeItem) element;
        R5LabelFormatter.appendCapability(label, item.getCapability(), shortenNamespaces);
        // Get the icon from the capability namespace
        icon = getImage(R5LabelFormatter.getNamespaceImagePath(item.getCapability().getNamespace()), true);
    } else if (element instanceof Requirement) {
        Requirement requirement = (Requirement) element;
        if (Namespace.RESOLUTION_OPTIONAL.equals(requirement.getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE)))
            label.append(" OPTIONALLY", StyledString.QUALIFIER_STYLER);
        label.append(" REQUIRED BY ", StyledString.QUALIFIER_STYLER);
        Resource resource = requirement.getResource();
        if (resource != null)
            R5LabelFormatter.appendResourceLabel(label, resource);
        else
            label.append(" INITIAL");
        label.append(" [", StyledString.QUALIFIER_STYLER);
        boolean first = true;
        for (Entry<String, String> entry : requirement.getDirectives().entrySet()) {
            String key = entry.getKey();
            if (!key.equals(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE)) {
                if (!first)
                    label.append(",", StyledString.QUALIFIER_STYLER);
                first = false;
                label.append(key + ":=" + entry.getValue(), StyledString.QUALIFIER_STYLER);
            }
        }
        label.append("]", StyledString.QUALIFIER_STYLER);
    }
    cell.setText(label.getString());
    cell.setStyleRanges(label.getStyleRanges());
    cell.setImage(icon);
}
Also used : Requirement(org.osgi.resource.Requirement) Entry(java.util.Map.Entry) Resource(org.osgi.resource.Resource) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Image(org.eclipse.swt.graphics.Image)

Example 67 with StyledString

use of org.eclipse.jface.viewers.StyledString in project bndtools by bndtools.

the class ResolutionChoiceSelectionDialog method createDialogArea.

@SuppressWarnings("unused")
@Override
protected Control createDialogArea(Composite parent) {
    setTitle("Multiple Provider Candidates");
    setMessage("Use the candidate list to specify your preferences. Candidates at the top of the list will be preferred by the resolver.");
    // Create controls
    Composite outer = (Composite) super.createDialogArea(parent);
    Composite contents = new Composite(outer, SWT.NONE);
    Label lblRequirement = new Label(contents, SWT.NONE);
    lblRequirement.setText("Requirement Info");
    lblRequirement.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));
    StyledText txtRequirement = new StyledText(contents, SWT.WRAP | SWT.BORDER);
    txtRequirement.setEditable(false);
    txtRequirement.setCaret(null);
    //        txtRequirement.setBackground(contents.getBackground());
    txtRequirement.setCursor(parent.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
    new Label(contents, SWT.NONE);
    Label lblCandidates = new Label(contents, SWT.NONE);
    lblCandidates.setText("Candidates");
    lblCandidates.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));
    Composite lowerPanel = new Composite(contents, SWT.NONE);
    Table tbl = new Table(lowerPanel, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
    viewer = new CheckboxTableViewer(tbl);
    viewer.setContentProvider(ArrayContentProvider.getInstance());
    viewer.setLabelProvider(new CapabilityLabelProvider());
    btnUp = new Button(lowerPanel, SWT.PUSH);
    btnUp.setText("Move Up");
    btnUp.setEnabled(false);
    btnDown = new Button(lowerPanel, SWT.PUSH);
    btnDown.setText("Move Down");
    btnDown.setEnabled(false);
    Composite cmpPreferences = new Composite(contents, SWT.NONE);
    btnSavePreference = new Button(cmpPreferences, SWT.CHECK | SWT.WRAP);
    txtSavePreference = new StyledText(cmpPreferences, SWT.WRAP);
    txtSavePreference.setEditable(false);
    txtSavePreference.setCaret(null);
    txtSavePreference.setBackground(contents.getBackground());
    txtSavePreference.setCursor(parent.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
    // Events
    txtSavePreference.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            btnSavePreference.setSelection(!btnSavePreference.getSelection());
        }
    });
    // Load data
    StyledString label = createRequirementText();
    txtRequirement.setText(label.getString());
    txtRequirement.setStyleRanges(label.getStyleRanges());
    viewer.setInput(candidates);
    updateSavePreferenceText();
    // Layout
    GridLayout layout;
    GridData gd;
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    contents.setLayoutData(gd);
    layout = new GridLayout(1, false);
    contents.setLayout(layout);
    gd = new GridData(SWT.FILL, SWT.NONE, true, false);
    gd.horizontalIndent = 5;
    txtRequirement.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.NONE, true, false);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    lowerPanel.setLayoutData(gd);
    layout = new GridLayout(2, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    lowerPanel.setLayout(layout);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3);
    gd.widthHint = 450;
    gd.heightHint = 250;
    tbl.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.NONE, false, false);
    btnUp.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.NONE, false, false);
    btnDown.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.NONE, true, false);
    cmpPreferences.setLayoutData(gd);
    layout = new GridLayout(2, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    cmpPreferences.setLayout(layout);
    gd = new GridData(SWT.LEFT, SWT.CENTER, false, false);
    btnSavePreference.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
    txtSavePreference.setLayoutData(gd);
    return contents;
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Table(org.eclipse.swt.widgets.Table) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) CapabilityLabelProvider(bndtools.model.resolution.CapabilityLabelProvider) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) StyledString(org.eclipse.jface.viewers.StyledString) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData)

Example 68 with StyledString

use of org.eclipse.jface.viewers.StyledString in project bndtools by bndtools.

the class ResolutionChoiceSelectionDialog method createRequirementText.

protected StyledString createRequirementText() {
    StyledString label = new StyledString();
    label.append("Namespace: ");
    label.append(requirement.getNamespace() + "\n", BoldStyler.INSTANCE_DEFAULT);
    label.append("Filter: ");
    R5LabelFormatter.appendRequirementLabel(label, requirement, false);
    label.append("\n");
    for (Entry<String, String> entry : requirement.getDirectives().entrySet()) {
        String key = entry.getKey();
        if (!Namespace.REQUIREMENT_FILTER_DIRECTIVE.equals(key) && !Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE.equals(key))
            label.append("    " + key + ":=" + entry.getValue() + "\n");
    }
    if (Namespace.RESOLUTION_OPTIONAL.equals(requirement.getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE)))
        label.append("Optionally ", ItalicStyler.INSTANCE_DEFAULT);
    label.append("Required by Resource: ");
    R5LabelFormatter.appendResourceLabel(label, requirement.getResource());
    return label;
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

Example 69 with StyledString

use of org.eclipse.jface.viewers.StyledString in project bndtools by bndtools.

the class ResourceLabelProvider method update.

@Override
public void update(ViewerCell cell) {
    Resource resource = (Resource) cell.getElement();
    StyledString label = new StyledString();
    try {
        Capability identityCap = ResourceUtils.getIdentityCapability(resource);
        String name = ResourceUtils.getIdentity(identityCap);
        label.append(name);
        Version version = ResourceUtils.getVersion(identityCap);
        label.append(" " + version, StyledString.COUNTER_STYLER);
    } catch (IllegalArgumentException e) {
        label.append("<unknown>");
    }
    try {
        URI uri = ResourceUtils.getURI(ResourceUtils.getContentCapability(resource));
        label.append(" [" + uri + "]", StyledString.QUALIFIER_STYLER);
    } catch (IllegalArgumentException e) {
    // ignore
    }
    cell.setText(label.getString());
    cell.setStyleRanges(label.getStyleRanges());
    cell.setImage(bundleImg);
}
Also used : Capability(org.osgi.resource.Capability) Version(org.osgi.framework.Version) Resource(org.osgi.resource.Resource) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) URI(java.net.URI)

Aggregations

StyledString (org.eclipse.jface.viewers.StyledString)69 Image (org.eclipse.swt.graphics.Image)14 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 Capability (org.osgi.resource.Capability)4 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)3 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)3 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)3 Styler (org.eclipse.jface.viewers.StyledString.Styler)3 TableViewer (org.eclipse.jface.viewers.TableViewer)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