Search in sources :

Example 31 with StyledString

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

the class CapabilityLabelProvider method update.

@Override
public void update(ViewerCell cell) {
    Capability cap = (Capability) cell.getElement();
    StyledString label = new StyledString();
    R5LabelFormatter.appendCapability(label, cap, shortenNamespaces);
    cell.setText(label.toString());
    cell.setStyleRanges(label.getStyleRanges());
    // Get the icon from the capability namespace
    Image icon = getImage(R5LabelFormatter.getNamespaceImagePath(cap.getNamespace()), true);
    if (icon != null)
        cell.setImage(icon);
}
Also used : Capability(org.osgi.resource.Capability) StyledString(org.eclipse.jface.viewers.StyledString) Image(org.eclipse.swt.graphics.Image)

Example 32 with StyledString

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

the class VersionedClauseLabelProvider method update.

@Override
public void update(ViewerCell cell) {
    aQute.bnd.build.model.clauses.VersionedClause clause = (aQute.bnd.build.model.clauses.VersionedClause) cell.getElement();
    StyledString label = new StyledString(clause.getName());
    String version = clause.getVersionRange();
    if (version != null) {
        label.append(" " + version, StyledString.COUNTER_STYLER);
    }
    cell.setText(label.getString());
    cell.setStyleRanges(label.getStyleRanges());
    cell.setImage(bundleImg);
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

Example 33 with StyledString

use of org.eclipse.jface.viewers.StyledString in project AutoRefactor by JnRouvignac.

the class ChooseRefactoringWizardPage method createRefactoringsTable.

private void createRefactoringsTable(Composite parent) {
    tableViewer = newCheckList(parent, BORDER | H_SCROLL | CHECK | NO_FOCUS | HIDE_SELECTION);
    createColumns(tableViewer);
    tableViewer.setContentProvider(new ArrayContentProvider());
    final List<RefactoringRule> refactorings = AllRefactoringRules.getAllRefactoringRules();
    tableViewer.setInput(refactorings);
    tableViewer.setCheckStateProvider(new CheckStateProvider(refactorings));
    tableViewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object o1, Object o2) {
            return ((RefactoringRule) o1).getName().compareTo(((RefactoringRule) o2).getName());
        }
    });
    tableViewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object refactoring) {
            final String filter = filterText.getText().toLowerCase();
            final RefactoringRule rule = (RefactoringRule) refactoring;
            final String description = rule.getDescription().toLowerCase();
            final String name = rule.getName().toLowerCase();
            return description.contains(filter) || name.contains(filter);
        }
    });
    ColumnViewerToolTipSupport.enableFor(tableViewer, ToolTip.NO_RECREATE);
    tableViewer.setLabelProvider(new StyledCellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            final String filter = filterText.getText().toLowerCase();
            final String name = ((RefactoringRule) cell.getElement()).getName();
            cell.setText(name);
            cell.setStyleRanges(getStyleRanges(name, filter));
        }

        private StyleRange[] getStyleRanges(String text, String filter) {
            final int matchIndex = text.toLowerCase().indexOf(filter);
            final int matchLength = filter.length();
            if (matchIndex != -1 && matchLength != 0) {
                final StyledString styledString = new StyledString(text, defaultStyler);
                styledString.setStyle(matchIndex, matchLength, underlineStyler);
                return styledString.getStyleRanges();
            }
            return null;
        }

        @Override
        public String getToolTipText(Object refactoring) {
            return ((RefactoringRule) refactoring).getDescription();
        }

        @Override
        public Point getToolTipShift(Object object) {
            return new Point(10, 20);
        }
    });
    final Table table = tableViewer.getTable();
    table.setLinesVisible(false);
    tableViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
    packColumns(table);
    table.setFocus();
}
Also used : StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) Table(org.eclipse.swt.widgets.Table) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) TableViewer(org.eclipse.jface.viewers.TableViewer) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) Viewer(org.eclipse.jface.viewers.Viewer) ICheckStateProvider(org.eclipse.jface.viewers.ICheckStateProvider) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Point(org.eclipse.swt.graphics.Point) ViewerCell(org.eclipse.jface.viewers.ViewerCell) RefactoringRule(org.autorefactor.refactoring.RefactoringRule) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData)

Example 34 with StyledString

use of org.eclipse.jface.viewers.StyledString in project eclipse.platform.text by eclipse.

the class CompletionProposalPopup2 method setProposals.

/**
 * Initializes the proposal selector with these given proposals.
 *
 * @param proposals the proposals
 */
private void setProposals(ICompletionProposal[] proposals) {
    if (Helper2.okToUse(fProposalTable)) {
        ICompletionProposal oldProposal = getSelectedProposal();
        if (oldProposal instanceof ICompletionProposalExtension2)
            ((ICompletionProposalExtension2) oldProposal).unselected(fViewer);
        fFilteredProposals = proposals;
        int selectionIndex = 0;
        fProposalTable.setRedraw(false);
        try {
            fProposalTable.removeAll();
            Point selection = fViewer.getSelectedRange();
            int endOffset;
            endOffset = selection.x + selection.y;
            IDocument document = fViewer.getDocument();
            boolean validate = false;
            if (selection.y != 0 && document != null)
                validate = true;
            TableItem item;
            ICompletionProposal p;
            for (int i = 0; i < proposals.length; i++) {
                p = proposals[i];
                item = new TableItem(fProposalTable, SWT.NULL);
                if (p.getImage() != null)
                    item.setImage(p.getImage());
                String displayString;
                StyleRange[] styleRanges = null;
                if (fIsColoredLabelsSupportEnabled && p instanceof ICompletionProposalExtension6) {
                    StyledString styledString = ((ICompletionProposalExtension6) p).getStyledDisplayString();
                    displayString = styledString.getString();
                    styleRanges = styledString.getStyleRanges();
                } else
                    displayString = p.getDisplayString();
                item.setText(displayString);
                if (fIsColoredLabelsSupportEnabled)
                    TableOwnerDrawSupport.storeStyleRanges(item, 0, styleRanges);
                item.setData(p);
                if (validate && validateProposal(document, p, endOffset, null)) {
                    selectionIndex = i;
                    validate = false;
                }
            }
        } finally {
            fProposalTable.setRedraw(true);
        }
        resizeProposalSelector(false);
        selectProposal(selectionIndex, false);
    }
}
Also used : ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) TableItem(org.eclipse.swt.widgets.TableItem) StyleRange(org.eclipse.swt.custom.StyleRange) ICompletionProposalExtension2(org.eclipse.jface.text.contentassist.ICompletionProposalExtension2) Point(org.eclipse.swt.graphics.Point) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Point(org.eclipse.swt.graphics.Point) IDocument(org.eclipse.jface.text.IDocument) ICompletionProposalExtension6(org.eclipse.jface.text.contentassist.ICompletionProposalExtension6)

Example 35 with StyledString

use of org.eclipse.jface.viewers.StyledString in project xtext-xtend by eclipse.

the class JvmOutlineTests method testActiveAnnotation.

@Test
public void testActiveAnnotation() throws Exception {
    InputStream inputStream = JvmOutlineTests.class.getResourceAsStream("TestAA.txt");
    String model = Files.readStreamIntoString(inputStream);
    XtendFile aaXtendFile = getWorkbenchTestHelper().xtendFile("aatest/TestAA.xtend", model);
    WorkbenchTestHelper.addExportedPackages(getWorkbenchTestHelper().getProject(), "aatest");
    AssertBuilder aaFile = newAssertBuilder(aaXtendFile).numChildren(4);
    aaFile.child(0, "aatest");
    aaFile.child(1, "import declarations");
    aaFile.child(2, "TestAAnnotation");
    aaFile.child(3, "TestAAProcessor");
    List<String> deps = newArrayList(WorkbenchTestHelper.DEFAULT_REQ_BUNDLES);
    deps.add(WorkbenchTestHelper.TESTPROJECT_NAME);
    final IProject clientProj = WorkbenchTestHelper.createPluginProject(WorkbenchTestHelper.TESTPROJECT_NAME + "-client", Iterables.toArray(deps, String.class));
    IResourcesSetupUtil.waitForBuild();
    XtendFile xtendFile = getWorkbenchTestHelper().xtendFile(clientProj, "clienttest/TestAAClient.xtend", "package clienttest @aatest.TestAAnnotation class AAOutlineTest { override void myPublicMethod() {}}");
    AssertBuilder clientAAFile = newAssertBuilder(xtendFile).numChildren(3);
    clientAAFile.leaf(0, "clienttest");
    clientAAFile.child(1, "AAOutlineTest").leaf(0, "myPublicMethod() : void");
    StyledString styledString = new StyledString("AAOutlineTestInterface - clienttest.test", StyledString.QUALIFIER_STYLER);
    AssertBuilder createdtype = clientAAFile.child(2, styledString).numChildren(1);
    createdtype.child(0, new StyledString("myPublicMethod()", StyledString.QUALIFIER_STYLER).append(" : void", StyledString.DECORATIONS_STYLER));
    WorkbenchTestHelper.deleteProject(clientProj);
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) InputStream(java.io.InputStream) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

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