Search in sources :

Example 26 with StyledString

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

Example 27 with StyledString

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

Example 28 with StyledString

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

Example 29 with StyledString

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

Example 30 with StyledString

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);
                                        }
                                    }
                                }
                            });
                        }
                    }
                }
            });
        }
    });
}
Also used : CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) Label(org.eclipse.swt.widgets.Label) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) StyledString(org.eclipse.jface.viewers.StyledString) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) GridLayout(org.eclipse.swt.layout.GridLayout) Entry(java.util.Map.Entry) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Resource(org.bndtools.templating.Resource) StyledString(org.eclipse.jface.viewers.StyledString) ViewerCell(org.eclipse.jface.viewers.ViewerCell) GridData(org.eclipse.swt.layout.GridData) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

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