List of usage examples for org.eclipse.jface.viewers StyledString append
public StyledString append(StyledString string)
From source file:at.bestsolution.efxclipse.tooling.css.ui.contentassist.CssDslRealtimeProposalProvider.java
License:Open Source License
public void complete_css_property(ruleset model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { URI uri = model.eResource().getURI(); List<CssProperty> properties = extension.getAllProperties(uri); if (properties != null) { Map<Integer, String> alternateSource = new HashMap<Integer, String>(); Map<Integer, CssProperty> filterMap = new HashMap<Integer, CssProperty>(); for (CssProperty property : properties) { CssProperty old = filterMap.put(property.eqHash, property); if (old != null) { String x = alternateSource.get(property.eqHash); if (x != null) { alternateSource.put(property.eqHash, x + ", " + property.parent.fQName); } else { alternateSource.put(property.eqHash, old.parent.fQName + ", " + property.parent.fQName); }/* ww w .j av a2 s. c o m*/ } } for (CssProperty property : filterMap.values()) { StyledString displayString = new StyledString(); String name = property.name + " "; String nfo = ""; String alternate = alternateSource.get(property.eqHash); if (alternate == null) { nfo = "(" + property.parent.fQName + ")"; } else { nfo = "( " + alternate + " )"; } displayString.append(name); displayString.append(nfo); displayString.setStyle(name.length(), nfo.length(), new Styler() { @Override public void applyStyles(TextStyle textStyle) { textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_GRAY); } }); Image img = labelProvider.getImage(CssDslFactory.eINSTANCE.createcss_property()); ConfigurableCompletionProposal cp = (ConfigurableCompletionProposal) createCompletionProposal( property.name, displayString, img, context); if (cp != null) { cp.setAdditionalProposalInfo(model); cp.setHover(new PropertyHover(property)); cp.setTriggerCharacters(new char[] { ' ' }); cp.setTextApplier(new IReplacementTextApplier() { @Override public void apply(IDocument document, ConfigurableCompletionProposal proposal) throws BadLocationException { document.replace(proposal.getReplacementOffset(), proposal.getReplacementLength(), proposal.getReplacementString() + ": "); proposal.setCursorPosition(proposal.getCursorPosition() + 2); } }); acceptor.accept(cp); } } } // List<Property> properties = extension.getProperties(uri); // // // if (properties != null) { // // for (Property property : properties) { // // // ConfigurableCompletionProposal cp = (ConfigurableCompletionProposal) createCompletionProposal(property.getName(), property.getName(), null, context); // cp.setAdditionalProposalInfo(model); // //cp.setHover(new HoverImpl(extension.getDocForProperty(model.eResource().getURI(), property.getName()))); // // cp.setHover(new PropertyHover(uri, property.getName())); // // cp.setImage(labelProvider.getImage(CssDslFactory.eINSTANCE.createcss_property())); // // StyledString displayString = new StyledString(); // String name = property.getName() + " "; // String nfo = "(" + "defined in package lala" + ")"; // // displayString.append(name); // displayString.append(nfo); // // displayString.setStyle(name.length(), nfo.length(), new Styler() { // @Override // public void applyStyles(TextStyle textStyle) { // textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_GRAY); // } // }); // // // cp.setDisplayString(displayString); // acceptor.accept(cp); // } // } }
From source file:at.bestsolution.efxclipse.tooling.css.ui.contentassist.CssDslRealtimeProposalProvider.java
License:Open Source License
private void handlePropertyCompletion(URI uri, EObject model, List<CssTok> prefixToks, String prefix, String elementName, String propertyName, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { List<Proposal> proposals = extension.findProposals(uri, elementName, propertyName, prefixToks, prefix); for (Proposal p : proposals) { StyledString displayString = new StyledString(); String name = p.getLabel() + " "; String nfo = "( " + p.getLabel() + " )"; displayString.append(name); displayString.append(nfo);/* w ww. j a v a 2 s. co m*/ displayString.setStyle(name.length(), nfo.length(), new Styler() { @Override public void applyStyles(TextStyle textStyle) { textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_GRAY); } }); // TODO fix image Image img = labelProvider.getImage(CssDslFactory.eINSTANCE.createcss_property()); ConfigurableCompletionProposal cp = (ConfigurableCompletionProposal) createCompletionProposal( p.getProposal(), displayString, img, context); if (cp != null) { cp.setAdditionalProposalInfo(model); //cp.setHover(new PropertyHover(property)); cp.setAutoInsertable(true); cp.setTriggerCharacters(new char[] { ' ' }); if (p instanceof DialogProposal) { final DialogProposal dProp = (DialogProposal) p; cp.setTextApplier(new ReplacementTextApplier() { // @Override public String getActualReplacementString(ConfigurableCompletionProposal proposal) { return dProp.openProposal(); } }); } else { cp.setTextApplier(new IReplacementTextApplier() { @Override public void apply(IDocument document, ConfigurableCompletionProposal proposal) throws BadLocationException { // proposal.setReplaceContextLength((proposal.getReplacementString() + " ").length()); System.err.println("apply " + proposal.getReplacementString()); if (",".equals(proposal.getReplacementString())) { document.replace(proposal.getReplacementOffset() - 1, proposal.getReplacementLength() + 1, proposal.getReplacementString() + " "); // proposal.setCursorPosition(proposal.getCursorPosition() + 1); } else if (",".equals(proposal.getReplacementString())) { document.replace(proposal.getReplacementOffset() - 1, proposal.getReplacementLength() + 1, proposal.getReplacementString() + "\n"); } else { document.replace(proposal.getReplacementOffset(), proposal.getReplacementLength(), proposal.getReplacementString() + " "); proposal.setCursorPosition(proposal.getCursorPosition() + 1); } } }); } acceptor.accept(cp); } } }
From source file:at.bestsolution.efxclipse.tooling.fxgraph.ui.outline.FXGraphOutlineTreeProvider.java
License:Open Source License
public Object _text(Element element) { if (element.getValue() != null || element.getName() != null || element.getFactory() != null) { StyledString s = new StyledString(); s.append(element.getType().getSimpleName()); if (element.getValue() != null) { s.append("(" + getSimplePropertValue(element.getValue()) + ")"); }// w w w .j a va 2 s . c o m if (element.getFactory() != null) { s.append("#", StyledString.QUALIFIER_STYLER); s.append(element.getFactory(), StyledString.QUALIFIER_STYLER); } if (element.getName() != null) { s.append(" - " + element.getName(), StyledString.QUALIFIER_STYLER); } return s; } return element.getType() != null ? element.getType().getSimpleName() : ""; }
From source file:au.gov.ga.earthsci.layer.ui.DrawOrderLabelProvider.java
License:Apache License
@Override public StyledString getStyledText(Object element) { StyledString string = new StyledString(getText(element)); if (element instanceof DrawOrderModel.LayerDrawOrderModelElement) { DrawOrderModel.LayerDrawOrderModelElement layerElement = (DrawOrderModel.LayerDrawOrderModelElement) element; String structure = buildStructureString(layerElement.node.getParent()); if (structure != null) { string.append(" "); //$NON-NLS-1$ string.append("(" + structure + ")", structureStyler); //$NON-NLS-1$//$NON-NLS-2$ }//from ww w .jav a2 s . c om } return string; }
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 w w w . ja va 2s. co m*/ } 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.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode.java
License:Open Source License
/** * Computes a styled string describing the UI node suitable for tree views. * Similar to {@link #getShortDescription()} but styles the Strings. * * @return A styled string describing the UI node suitable for tree views. *//*from ww w . j a va 2 s .c o m*/ public StyledString getStyledDescription() { String uiName = mDescriptor.getUiName(); // Special case: for <view>, show the class attribute value instead. // This is done here rather than in the descriptor since this depends on // node instance data. if (SdkConstants.VIEW_TAG.equals(uiName) && mXmlNode instanceof Element) { Element element = (Element) mXmlNode; String cls = element.getAttribute(ATTR_CLASS); if (cls != null) { uiName = cls.substring(cls.lastIndexOf('.') + 1); } } StyledString styledString = new StyledString(); String attr = getDescAttribute(); if (attr != null) { // Don't append the two when it's a repeat, e.g. Button01 (Button), // only when the ui name is not part of the attribute if (attr.toLowerCase(Locale.US).indexOf(uiName.toLowerCase(Locale.US)) == -1) { styledString.append(attr); styledString.append(String.format(" (%1$s)", uiName), StyledString.DECORATIONS_STYLER); } else { styledString.append(attr); } } if (styledString.length() == 0) { styledString.append(uiName); } return styledString; }
From source file:com.android.ide.eclipse.auidt.internal.editors.uimodel.UiElementNode.java
License:Open Source License
/** * Computes a styled string describing the UI node suitable for tree views. * Similar to {@link #getShortDescription()} but styles the Strings. * * @return A styled string describing the UI node suitable for tree views. */// w w w . j ava2 s . c o m public StyledString getStyledDescription() { String uiName = mDescriptor.getUiName(); // Special case: for <view>, show the class attribute value instead. // This is done here rather than in the descriptor since this depends on // node instance data. if (LayoutDescriptors.VIEW_VIEWTAG.equals(uiName) && mXmlNode instanceof Element) { Element element = (Element) mXmlNode; String cls = element.getAttribute(ATTR_CLASS); if (cls != null) { uiName = cls.substring(cls.lastIndexOf('.') + 1); } } StyledString styledString = new StyledString(); String attr = getDescAttribute(); if (attr != null) { // Don't append the two when it's a repeat, e.g. Button01 (Button), // only when the ui name is not part of the attribute if (attr.toLowerCase(Locale.US).indexOf(uiName.toLowerCase(Locale.US)) == -1) { styledString.append(attr); styledString.append(String.format(" (%1$s)", uiName), StyledString.DECORATIONS_STYLER); } else { styledString.append(attr); } } if (styledString.length() == 0) { styledString.append(uiName); } return styledString; }
From source file:com.github.sdbg.debug.ui.internal.dialogs.LaunchConfigLabelProvider.java
License:Open Source License
@Override public StyledString getStyledText(Object element) { StyledString str = new StyledString(); str.append(getText(element)); if (element instanceof ILaunchConfiguration) { ILaunchConfiguration config = (ILaunchConfiguration) element; String appendText = getAppendText(config); if (appendText != null) { str.append(appendText, StyledString.QUALIFIER_STYLER); }/* ww w . j ava 2s . c o m*/ } return str; }
From source file:com.google.dart.tools.search.internal.ui.text.FileLabelProvider.java
License:Open Source License
private int appendShortenedGap(String content, int start, int end, int charsToCut, boolean isFirst, StyledString str) { int gapLength = end - start; if (!isFirst) { gapLength -= MIN_MATCH_CONTEXT;//w w w .j a va 2 s . c om } if (end < content.length()) { gapLength -= MIN_MATCH_CONTEXT; } if (gapLength < MIN_MATCH_CONTEXT) { // don't cut, gap is too small str.append(content.substring(start, end)); return charsToCut; } int context = MIN_MATCH_CONTEXT; if (gapLength > charsToCut) { context += gapLength - charsToCut; } if (!isFirst) { str.append(content.substring(start, start + context)); // give all extra context to the right side of a match context = MIN_MATCH_CONTEXT; } str.append(fgEllipses, StyledString.QUALIFIER_STYLER); if (end < content.length()) { str.append(content.substring(end - context, end)); } return charsToCut - gapLength + fgEllipses.length(); }
From source file:com.google.dart.tools.search.internal.ui.text.FileLabelProvider.java
License:Open Source License
@SuppressWarnings("unchecked") private StyledString getLineElementLabel(LineElement lineElement) { int lineNumber = lineElement.getLine(); String lineNumberString = Messages.format(SearchMessages.FileLabelProvider_line_number, new Integer(lineNumber)); StyledString str = new StyledString(lineNumberString, StyledString.QUALIFIER_STYLER); Match[] matches = lineElement.getMatches(fPage.getInput()); Arrays.sort(matches, fMatchComparator); String content = lineElement.getContents(); int pos = evaluateLineStart(matches, content, lineElement.getOffset()); int length = content.length(); int charsToCut = getCharsToCut(length, matches); // number of characters to leave away if the line is too long for (int i = 0; i < matches.length; i++) { FileMatch match = (FileMatch) matches[i]; int start = Math.max(match.getOriginalOffset() - lineElement.getOffset(), 0); // append gap between last match and the new one if (pos < start) { if (charsToCut > 0) { charsToCut = appendShortenedGap(content, pos, start, charsToCut, i == 0, str); } else { str.append(content.substring(pos, start)); }/*from ww w . ja va 2 s . c om*/ } // append match int end = Math.min(match.getOriginalOffset() + match.getOriginalLength() - lineElement.getOffset(), lineElement.getLength()); str.append(content.substring(start, end), DecoratingFileSearchLabelProvider.HIGHLIGHT_STYLE); pos = end; } // append rest of the line if (charsToCut > 0) { appendShortenedGap(content, pos, length, charsToCut, false, str); } else { str.append(content.substring(pos)); } return str; }