Search in sources :

Example 71 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 72 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 73 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)

Example 74 with StyledString

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

the class PluginClauseLabelProvider method update.

@Override
public void update(ViewerCell cell) {
    HeaderClause header = (HeaderClause) cell.getElement();
    String className = header.getName();
    StyledString label = new StyledString(className);
    Map<String, String> attribs = header.getAttribs();
    if (!attribs.isEmpty())
        label.append(" ");
    for (Iterator<Entry<String, String>> iter = attribs.entrySet().iterator(); iter.hasNext(); ) {
        Entry<String, String> entry = iter.next();
        label.append(entry.getKey(), StyledString.QUALIFIER_STYLER);
        label.append("=", StyledString.QUALIFIER_STYLER);
        label.append(entry.getValue(), StyledString.COUNTER_STYLER);
        if (iter.hasNext())
            label.append(", ");
    }
    cell.setText(label.toString());
    cell.setStyleRanges(label.getStyleRanges());
    Image image = images.get(className);
    if (image == null) {
        IConfigurationElement configElem = configElements.get(className);
        if (configElem != null) {
            String iconPath = configElem.getAttribute("icon");
            if (iconPath != null) {
                ImageDescriptor descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(configElem.getContributor().getName(), iconPath);
                if (descriptor != null) {
                    image = descriptor.createImage();
                    images.put(className, image);
                }
            }
        }
    }
    if (image == null) {
        image = images.get("__DEFAULT__");
        if (image == null) {
            image = AbstractUIPlugin.imageDescriptorFromPlugin(Plugin.PLUGIN_ID, "/icons/plugin.png").createImage();
            images.put("__DEFAULT__", image);
        }
    }
    cell.setImage(image);
}
Also used : Entry(java.util.Map.Entry) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Image(org.eclipse.swt.graphics.Image) HeaderClause(aQute.bnd.build.model.clauses.HeaderClause) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 75 with StyledString

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

the class PluginDeclarationLabelProvider method update.

@Override
public void update(ViewerCell cell) {
    IConfigurationElement element = (IConfigurationElement) cell.getElement();
    boolean deprecated = element.getAttribute("deprecated") != null;
    Styler mainStyler = deprecated ? new StrikeoutStyler(null) : null;
    StyledString label = new StyledString(element.getAttribute("name"), mainStyler);
    Styler classStyle = deprecated ? new StrikeoutStyler(StyledString.QUALIFIER_STYLER) : StyledString.QUALIFIER_STYLER;
    label.append(" [" + element.getAttribute("class") + "]", classStyle);
    cell.setText(label.toString());
    cell.setStyleRanges(label.getStyleRanges());
    String iconPath = element.getAttribute("icon");
    if (iconPath != null) {
        ImageDescriptor descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(element.getContributor().getName(), iconPath);
        if (descriptor != null) {
            Image image = descriptor.createImage();
            images.add(image);
            cell.setImage(image);
        }
    }
}
Also used : StrikeoutStyler(org.bndtools.utils.jface.StrikeoutStyler) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Styler(org.eclipse.jface.viewers.StyledString.Styler) StrikeoutStyler(org.bndtools.utils.jface.StrikeoutStyler) Image(org.eclipse.swt.graphics.Image) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

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