List of usage examples for org.eclipse.jface.viewers StyledString getString
public String getString()
From source file:at.bestsolution.eclipse.properties.PropertyContentOutlinePage.java
License:Open Source License
@Override public void createControl(Composite parent) { super.createControl(parent); TreeViewer viewer = getTreeViewer(); viewer.setLabelProvider(new StyledCellLabelProvider() { @Override//from w w w . ja va 2 s . com public void update(ViewerCell cell) { Object element = cell.getElement(); if (element instanceof PropertyGroup) { cell.setText(((PropertyGroup) element).name); cell.setImage(Activator.getDefault().getImageRegistry().get(Activator.GROUP_ICON)); cell.setStyleRanges(null); } else if (element instanceof Property) { cell.setImage(Activator.getDefault().getImageRegistry().get(Activator.KEY_ICON)); StyledString s = new StyledString(((Property) element).pair.key); String text = ((Property) element).pair.value; if (text.length() > 20) { text = text.substring(0, 20) + "..."; } s.append(" : " + text, StyledString.DECORATIONS_STYLER); cell.setStyleRanges(s.getStyleRanges()); cell.setText(s.getString()); } super.update(cell); } }); viewer.setContentProvider(new HierarchicalContentProvider()); if (isSorted()) { setSorted(true); } createHierarchicalStructure(); if (isHierarchical()) { viewer.setInput(hierarchicalStructure); } else { viewer.setInput(flatStructure); } }
From source file:at.bestsolution.efxclipse.tooling.jdt.ui.internal.editors.outline.PropertyContentOutlinePage.java
License:Open Source License
@Override public void createControl(Composite parent) { super.createControl(parent); TreeViewer viewer = getTreeViewer(); viewer.setLabelProvider(new StyledCellLabelProvider() { @Override// www . j a v a 2 s .c o m public void update(ViewerCell cell) { Object element = cell.getElement(); if (element instanceof PropertyGroup) { cell.setText(((PropertyGroup) element).name); cell.setImage(JavaFXUIPlugin.getDefault().getImageRegistry().get(JavaFXUIPlugin.GROUP_ICON)); cell.setStyleRanges(null); } else if (element instanceof Property) { cell.setImage(JavaFXUIPlugin.getDefault().getImageRegistry().get(JavaFXUIPlugin.KEY_ICON)); StyledString s = new StyledString(((Property) element).pair.key); String text = ((Property) element).pair.value; if (text.length() > 20) { text = text.substring(0, 20) + "..."; } s.append(" : " + text, StyledString.DECORATIONS_STYLER); cell.setStyleRanges(s.getStyleRanges()); cell.setText(s.getString()); } super.update(cell); } }); viewer.setContentProvider(new HierarchicalContentProvider()); if (isSorted()) { setSorted(true); } createHierarchicalStructure(); if (isHierarchical()) { viewer.setInput(hierarchicalStructure); } else { viewer.setInput(flatStructure); } }
From source file:bndtools.editor.components.MethodProposalLabelProvider.java
License:Open Source License
@Override public void update(ViewerCell cell) { StyledString styledString = getStyledString(cell.getElement()); cell.setText(styledString.getString()); cell.setStyleRanges(styledString.getStyleRanges()); }
From source file:bndtools.editor.pkgpatterns.HeaderClauseLabelProvider.java
License:Open Source License
@Override public void update(ViewerCell cell) { @SuppressWarnings("unchecked") C clause = (C) cell.getElement();/*w ww .j a v a 2s . com*/ cell.setImage(packageImg); StyledString styledString = new StyledString(clause.getName()); String version = clause.getAttribs().get(org.osgi.framework.Constants.VERSION_ATTRIBUTE); if (version != null) { styledString.append(": " + version, StyledString.COUNTER_STYLER); } decorate(styledString, clause); cell.setText(styledString.getString()); cell.setStyleRanges(styledString.getStyleRanges()); }
From source file:bndtools.editor.pkgpatterns.PkgPatternsLabelProvider.java
License:Open Source License
@Override public void update(ViewerCell cell) { HeaderClause clause = (HeaderClause) cell.getElement(); cell.setImage(packageImg);//from w ww.j ava 2s.c o m StyledString styledString = new StyledString(clause.getName()); String resolution = clause.getAttribs().get(Constants.RESOLUTION_DIRECTIVE); if (org.osgi.framework.Constants.RESOLUTION_OPTIONAL.equals(resolution)) { styledString.append(" <optional>", UIConstants.ITALIC_QUALIFIER_STYLER); } String version = clause.getAttribs().get(org.osgi.framework.Constants.VERSION_ATTRIBUTE); if (version != null) { styledString.append(": " + version, StyledString.COUNTER_STYLER); } cell.setText(styledString.getString()); cell.setStyleRanges(styledString.getStyleRanges()); }
From source file:bndtools.model.importanalysis.ImportsExportsTreeLabelProvider.java
License:Open Source License
@Override public void update(ViewerCell cell) { if (IMPORTS_PLACEHOLDER.equals(cell.getElement())) { if (cell.getColumnIndex() == 0) { cell.setImage(pkgFolderImg); cell.setText("Import Packages"); }//from ww w . j av a 2 s . com } else if (EXPORTS_PLACEHOLDER.equals(cell.getElement())) { if (cell.getColumnIndex() == 0) { cell.setImage(pkgFolderImg); cell.setText("Export Packages"); } } else if (REQUIRED_PLACEHOLDER.equals(cell.getElement())) { if (cell.getColumnIndex() == 0) { cell.setImage(bundleFolderImg); cell.setText("Required Bundles"); } } else if (cell.getElement() instanceof ImportUsedByPackage) { if (cell.getColumnIndex() == 0) { StyledString styledString = new StyledString("Used By: ", UIConstants.ITALIC_QUALIFIER_STYLER); styledString.append(((ImportUsedByPackage) cell.getElement()).usedByName); cell.setText(styledString.getString()); cell.setStyleRanges(styledString.getStyleRanges()); } } else if (cell.getElement() instanceof ImportUsedByClass) { if (cell.getColumnIndex() == 0) { ImportUsedByClass importUsedBy = (ImportUsedByClass) cell.getElement(); String fqn = importUsedBy.clazz.getFQN(); String className = fqn.substring(fqn.lastIndexOf('.') + 1); cell.setText(className); cell.setImage(classImg); } } else if (cell.getElement() instanceof ExportUsesPackage) { if (cell.getColumnIndex() == 0) { StyledString styledString = new StyledString("Uses: ", UIConstants.ITALIC_QUALIFIER_STYLER); styledString.append(((ExportUsesPackage) cell.getElement()).name); cell.setText(styledString.getString()); cell.setStyleRanges(styledString.getStyleRanges()); } } else if (cell.getElement() instanceof RequiredBundle) { RequiredBundle rb = (RequiredBundle) cell.getElement(); switch (cell.getColumnIndex()) { case 0: StyledString label; if (rb.isSatisfied()) label = new StyledString(rb.getName(), StyledString.QUALIFIER_STYLER); else label = new StyledString(rb.getName()); String version = rb.getAttribs().get(Constants.BUNDLE_VERSION_ATTRIBUTE); if (version != null) label.append(" " + version, StyledString.COUNTER_STYLER); String resolution = rb.getAttribs().get(Constants.RESOLUTION_DIRECTIVE); boolean optional = org.osgi.framework.Constants.RESOLUTION_OPTIONAL.equals(resolution); if (resolution != null) label.append(" <" + resolution + ">", UIConstants.ITALIC_QUALIFIER_STYLER); cell.setText(label.getString()); cell.setStyleRanges(label.getStyleRanges()); if (optional) cell.setImage(requiredBundleOptImg); else if (rb.isSatisfied()) cell.setImage(requiredBundleSatisfiedImg); else cell.setImage(requiredBundleImg); break; case 1: cell.setText(formatAttribs(rb.getAttribs())); break; default: break; } } else if (cell.getElement() instanceof ImportPackage || cell.getElement() instanceof ExportPackage) { HeaderClause entry = (HeaderClause) cell.getElement(); switch (cell.getColumnIndex()) { case 0: boolean selfImport = false; if (entry instanceof ImportPackage) { selfImport = ((ImportPackage) entry).isSelfImport(); } StyledString styledString; if (selfImport) { styledString = new StyledString(entry.getName(), StyledString.QUALIFIER_STYLER); } else { styledString = new StyledString(entry.getName()); } String version = entry.getAttribs().get(Constants.VERSION_ATTRIBUTE); if (version != null) styledString.append(" " + version, StyledString.COUNTER_STYLER); String resolution = entry.getAttribs().get(Constants.RESOLUTION_DIRECTIVE); boolean optional = org.osgi.framework.Constants.RESOLUTION_OPTIONAL.equals(resolution); if (resolution != null) { styledString.append(" <" + resolution + ">", UIConstants.ITALIC_QUALIFIER_STYLER); } cell.setText(styledString.getString()); cell.setStyleRanges(styledString.getStyleRanges()); if (optional) { cell.setImage(packageOptImg); } else if (selfImport) { cell.setImage(packageImpExpImg); } else { cell.setImage(packageImg); } break; case 1: cell.setText(formatAttribs(entry.getAttribs())); break; default: break; } } }
From source file:com.aptana.editor.common.scripting.snippets.SnippetTemplateProposalTest.java
License:Open Source License
@Test public void testTriggerNumberMatches() throws BadLocationException { Mockery context = new Mockery() { {/* w w w . ja va2 s . c o m*/ setImposteriser(ClassImposteriser.INSTANCE); } }; // Set up the document we're operating on final IDocument document = new Document("echo \n"); final ITextViewer viewer = new TextViewer(UIUtils.getActiveShell(), 0); viewer.setDocument(document); final Template[] templates = new Template[3]; SnippetsCompletionProcessor snippetsCompletionProcessor = new SnippetsCompletionProcessor() { protected org.eclipse.jface.text.templates.Template[] getTemplates(String contextTypeId) { String contextId = "com.aptana.contenttype.unknown __dftl_partition_content_type"; // Create the snippet we want to apply SnippetElement se1 = new SnippetElement(""); se1.setDisplayName("something1"); se1.setExpansion("Yahoo1!"); templates[0] = new SnippetTemplate(se1, "echo", contextId); SnippetElement se2 = new SnippetElement(""); se2.setDisplayName("something1"); se2.setExpansion("Yahoo2!"); templates[1] = new SnippetTemplate(se2, "echo", contextId); SnippetElement se3 = new SnippetElement(""); se3.setDisplayName("other"); se3.setExpansion("Bingo!"); templates[2] = new SnippetTemplate(se3, "ego", contextId); return templates; }; }; ICompletionProposal[] snippets = snippetsCompletionProcessor.computeCompletionProposals(viewer, 1); assertEquals("Expected snippets length do not match", 3, snippets.length); // Let's check the 1st and 2nd snippets for (int i = 0; i < snippets.length - 1; i++) { assertTrue(snippets[i] instanceof SnippetTemplateProposal); StyledString styledActivationString = ((SnippetTemplateProposal) snippets[i]) .getStyledActivationString(); String styleStr = "echo " + (i + 1); assertEquals("Style string of snippets templates do not match", styleStr, styledActivationString.getString().trim()); } // Create snippet proposal, then apply it to the document DocumentSnippetTemplateContext tc = new DocumentSnippetTemplateContext( new SnippetTemplateContextType("scope"), document, 0, 4); SnippetTemplateProposal p = new SnippetTemplateProposal(templates[1], tc, new Region(0, 0), null, 0); // Make sure the snippet validates DocumentEvent event = new DocumentEvent(document, 4, 0, ""); assertTrue("Snippet proposal incorrectly failed validation!", p.validate(document, 4, event)); // Now make sure the snippet got applied correctly p.apply(viewer, '2', 0, 4); assertEquals("Yahoo2! \n", document.get()); context.assertIsSatisfied(); }
From source file:com.cubrid.common.ui.query.control.jface.text.contentassist.CompletionProposalPopup.java
License:Open Source License
private void handleSetData(Event event) { TableItem item = (TableItem) event.item; int index = fProposalTable.indexOf(item); if (0 <= index && index < fFilteredProposals.length) { ICompletionProposal current = fFilteredProposals[index]; String displayString;/*from www. ja va 2 s. co m*/ StyleRange[] styleRanges = null; if (fIsColoredLabelsSupportEnabled && current instanceof ICompletionProposalExtension6) { StyledString styledString = ((ICompletionProposalExtension6) current).getStyledDisplayString(); displayString = styledString.getString(); styleRanges = styledString.getStyleRanges(); } else displayString = current.getDisplayString(); item.setText(displayString); if (fIsColoredLabelsSupportEnabled) TableOwnerDrawSupport.storeStyleRanges(item, 0, styleRanges); item.setImage(current.getImage()); item.setData(current); } else { // this should not happen, but does on win32 } }
From source file:com.google.dart.tools.search.internal.ui.text.FileLabelProvider.java
License:Open Source License
public StyledString getStyledString(File resource) { if (!resource.exists()) { return new StyledString(SearchMessages.FileLabelProvider_removed_resource_label); }//from www . j a va 2 s. c o m String name = BasicElementLabels.getResourceName(resource); if (fOrder == SHOW_LABEL) { return getColoredLabelWithCounts(resource, new StyledString(name)); } String pathString = BasicElementLabels.getParentPathLabel(resource, false); if (fOrder == SHOW_LABEL_PATH) { StyledString str = new StyledString(name); String decorated = Messages.format(fgSeparatorFormat, new String[] { str.getString(), pathString }); StyledCellLabelProvider.styleDecoratedString(decorated, StyledString.QUALIFIER_STYLER, str); return getColoredLabelWithCounts(resource, str); } StyledString str = new StyledString(Messages.format(fgSeparatorFormat, new String[] { pathString, name })); return getColoredLabelWithCounts(resource, str); }
From source file:com.google.dart.tools.search.internal.ui.text.FileLabelProvider.java
License:Open Source License
public StyledString getStyledString(IResource resource) { if (!resource.exists()) { return new StyledString(SearchMessages.FileLabelProvider_removed_resource_label); }//from w ww . ja va 2 s. c o m String name = BasicElementLabels.getResourceName(resource); if (fOrder == SHOW_LABEL) { return getColoredLabelWithCounts(resource, new StyledString(name)); } String pathString = BasicElementLabels.getPathLabel(resource.getParent().getFullPath(), false); if (fOrder == SHOW_LABEL_PATH) { StyledString str = new StyledString(name); String decorated = Messages.format(fgSeparatorFormat, new String[] { str.getString(), pathString }); StyledCellLabelProvider.styleDecoratedString(decorated, StyledString.QUALIFIER_STYLER, str); return getColoredLabelWithCounts(resource, str); } StyledString str = new StyledString(Messages.format(fgSeparatorFormat, new String[] { pathString, name })); return getColoredLabelWithCounts(resource, str); }