@Override public StyledString getStyledText(Object element) { if (element instanceof IResource) { IResource resource = (IResource) element; // Un-analyzed resources are grey. if (!DartCore.isAnalyzed(resource)) { return new StyledString(resource.getName(), StyledString.QUALIFIER_STYLER); } StyledString string = new StyledString(resource.getName()); DartElement dartElement = DartCore.create(resource); // Append the library name to library units. if (dartElement instanceof CompilationUnit) { if (((CompilationUnit) dartElement).definesLibrary()) { DartLibrary library = ((CompilationUnit) dartElement).getLibrary(); string.append(" [" + library.getDisplayName() + "]", StyledString.QUALIFIER_STYLER); } } return string; } return workbenchLabelProvider.getStyledText(element); }
public StyledString createStyledStringForVersion( final ExtensionGeneratorDelegate.Metadata metadata) { String _version = metadata.getVersion(); final StyledString result = new StyledString(_version); StringConcatenation _builder = new StringConcatenation(); _builder.append(" "); String _name = metadata.getName(); _builder.append(_name, " "); result.append(_builder.toString(), StyledString.QUALIFIER_STYLER); String _license = metadata.getLicense(); boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(_license); boolean _not = (!_isNullOrEmpty); if (_not) { StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append(" "); _builder_1.append("under "); String _license_1 = metadata.getLicense(); _builder_1.append(_license_1, " "); result.append(_builder_1.toString(), StyledString.QUALIFIER_STYLER); } String _description = metadata.getDescription(); boolean _isNullOrEmpty_1 = StringExtensions.isNullOrEmpty(_description); boolean _not_1 = (!_isNullOrEmpty_1); if (_not_1) { StringConcatenation _builder_2 = new StringConcatenation(); _builder_2.append(" "); _builder_2.append("- "); String _description_1 = metadata.getDescription(); _builder_2.append(_description_1, " "); result.append(_builder_2.toString(), StyledString.COUNTER_STYLER); } return result; }
private void highlightPattern(String pattern, String data, StyledString result) { Styler highlightStyle = isDeemphasized() ? GREY_UNDERLINE : UNDERLINE; Styler plainStyle = isDeemphasized() ? GREY : NULL_STYLER; if (StringUtil.hasText(pattern)) { int dataPos = 0; int dataLen = data.length(); int patternPos = 0; int patternLen = pattern.length(); while (dataPos < dataLen && patternPos < patternLen) { int pChar = pattern.charAt(patternPos++); int highlightPos = data.indexOf(pChar, dataPos); if (dataPos < highlightPos) { result.append(data.substring(dataPos, highlightPos), plainStyle); } result.append(data.charAt(highlightPos), highlightStyle); dataPos = highlightPos + 1; } if (dataPos < dataLen) { result.append(data.substring(dataPos), plainStyle); } } else { // no pattern to highlight result.append(data, plainStyle); } }
/* (non-Javadoc) * @see org.sourceforge.jsonedit.core.core.outline.elements.JsonElement#getStyledString() */ @Override public StyledString getStyledString() { StyledString styledString = new StyledString(); StyledString.Styler style1 = StyledString.createColorRegistryStyler("RED", "WHITE"); styledString.append(message, style1); return styledString; }
private List<ICompletionProposal> generateCompletionProposal( IMember member, CompilationUnit compilationUnit, ITypedRegion region, String matchValue) throws CoreException { List<ICompletionProposal> completionProposals = new ArrayList<ICompletionProposal>(); IAnnotationBinding pathAnnotationBinding = JdtUtils.resolveAnnotationBinding(member, compilationUnit, Path.class); String pathAnnotationValue = (String) JdtUtils.resolveAnnotationAttributeValue(pathAnnotationBinding, "value"); if (pathAnnotationValue != null && pathAnnotationValue.contains("{") && pathAnnotationValue.contains("}")) { List<String> uriParams = extractParamsFromUriTemplateFragment(pathAnnotationValue); for (String uriParam : uriParams) { String replacementValue = "\"" + uriParam + "\""; if (replacementValue.startsWith(matchValue)) { String displayString = uriParam + " - JAX-RS Mapping"; StyledString displayStyledString = new StyledString(displayString); displayStyledString.setStyle( uriParam.length(), displayString.length() - uriParam.length(), StyledString.QUALIFIER_STYLER); completionProposals.add( new AnnotationCompletionProposal( replacementValue, displayStyledString, region, icon, member, compilationUnit)); } } } return completionProposals; }
private StyledString getConnectionString(final ConnectionHolder holder) { final ConnectionService service = holder.getConnectionService(); final ConnectionDescriptor desc = holder.getConnectionInformation(); final StyledString str = new StyledString(makeLabel(desc.getConnectionInformation())); if (service != null) { str.append(" [", StyledString.DECORATIONS_STYLER); // $NON-NLS-1$ final Connection connection = service.getConnection(); if (connection != null) { str.append( String.format("%s", holder.getConnectionState()), StyledString.DECORATIONS_STYLER); // $NON-NLS-1$ } str.append("]", StyledString.DECORATIONS_STYLER); // $NON-NLS-1$ } if (desc.getServiceId() != null) { str.append( String.format(" (%s)", desc.getServiceId()), StyledString.QUALIFIER_STYLER); // $NON-NLS-1$ } return str; }
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; } 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(); }
/** * Literal lists can be used where names can appear - i.e. something has "a list of names" as * name. * * @param ele * @return */ StyledString text(LiteralList ele) { StyledString label = new StyledString(); label.append("[", EXPR_STYLER); label.append(literalNames(ele.getElements())); label.append("]", EXPR_STYLER); return label; }
@Test public void should_getStyledText_supportNull() throws Exception { final ContractConstraint constraint = ProcessFactory.eINSTANCE.createContractConstraint(); constraint.setExpression(null); final StyledString styledText = labelProvider.getStyledText(constraint); assertThat(styledText.toString()).doesNotContain("\n").doesNotContain("\r"); }
/** * Appends a string with styles to the {@link StyledString}. * * @param string the string to append * @return returns a reference to this object */ public StyledString append(StyledString string) { if (string.length() == 0) { return this; } int offset = fBuffer.length(); fBuffer.append(string.toString()); List otherRuns = string.fStyleRuns; if (otherRuns != null && !otherRuns.isEmpty()) { for (int i = 0; i < otherRuns.size(); i++) { StyleRun curr = (StyleRun) otherRuns.get(i); if (i == 0 && curr.offset != 0) { appendStyleRun(null, offset); // appended string will // start with the default // color } appendStyleRun(curr.style, offset + curr.offset); } } else { appendStyleRun(null, offset); // appended string will start with // the default color } return this; }
@Override public StyledString getStyledText(Object element) { if (element instanceof IStructuredSelection) element = ((IStructuredSelection) element).getFirstElement(); if (element instanceof Repository) { Repository repositoryNode = (Repository) element; StyledString styledString = new StyledString(repositoryNode.getName()); if (repositoryNode.getResources() != null) { styledString.append( " (" + repositoryNode.getResources().size() + ") ", StyledString.QUALIFIER_STYLER); } return styledString; } if (element instanceof Resource) { StyledString styledString = new StyledString(((Resource) element).getName()); if (((Resource) element).getDescriptor() == null) { styledString.append( " describes (" + ((Resource) element).getDescribes().size() + ") resources", StyledString.COUNTER_STYLER); } return styledString; } return null; }
@Override public void update(ViewerCell cell) { EObject o = (EObject) cell.getElement(); String label = ""; // $NON-NLS-1$ Image img = null; AbstractComponentEditor elementEditor = getEditor().getEditor(o.eClass()); if (elementEditor != null) { label = elementEditor.getDetailLabel(o); label = label == null ? elementEditor.getLabel(o) : label; img = elementEditor.getImage(o, composite.getDisplay()); } List<String> parentPath = new ArrayList<String>(); while (o.eContainer() != null) { o = o.eContainer(); elementEditor = getEditor().getEditor(o.eClass()); if (elementEditor != null) { parentPath.add(0, elementEditor.getLabel(o)); } } String parentString = ""; // $NON-NLS-1$ for (String p : parentPath) { parentString += "/" + p; // $NON-NLS-1$ } StyledString s = new StyledString(label); s.append(" - " + parentString, StyledString.DECORATIONS_STYLER); // $NON-NLS-1$ cell.setStyleRanges(s.getStyleRanges()); cell.setText(s.getString()); cell.setImage(img); }
private StyledString getStyledText(CeylonHierarchyNode n) { Declaration dec = getDisplayedDeclaration(n); if (dec == null) { return new StyledString(); } IPreferenceStore prefs = getPreferences(); StyledString result = getQualifiedDescriptionFor( dec, prefs.getBoolean(TYPE_PARAMS_IN_OUTLINES), prefs.getBoolean(PARAMS_IN_OUTLINES), prefs.getBoolean(PARAM_TYPES_IN_OUTLINES), prefs.getBoolean(RETURN_TYPES_IN_OUTLINES), getPrefix(), getFont()); /*if (d.isClassOrInterfaceMember()) { Declaration container = (Declaration) d.getContainer(); result.append(" in ") .append(container.getName(), Highlights.TYPE_ID_STYLER); }*/ result.append(" - ", PACKAGE_STYLER).append(getPackageLabel(dec), PACKAGE_STYLER); if (n.isNonUnique()) { result.append(" - and other supertypes").append(getViewInterfacesShortcut()); } return result; }
protected XtendFeatureNode createNodeForFeature( IOutlineNode parentNode, final JvmDeclaredType inferredType, JvmFeature jvmFeature, EObject semanticFeature, int inheritanceDepth) { final boolean synthetic = typeExtensions.isSynthetic(jvmFeature); Object text = getText(synthetic ? jvmFeature : semanticFeature); ImageDescriptor image = getImageDescriptor(synthetic ? jvmFeature : semanticFeature); if (jvmFeature.getDeclaringType() != inferredType) { if (getCurrentMode() == SHOW_INHERITED_MODE) { StyledString label = (text instanceof StyledString) ? (StyledString) text : new StyledString(text.toString()); label.append( new StyledString( " - " + jvmFeature.getDeclaringType().getIdentifier(), StyledString.COUNTER_STYLER)); return factory.createXtendFeatureNode( parentNode, jvmFeature, image, label, true, synthetic, inheritanceDepth); } return null; } else { return factory.createXtendFeatureNode( parentNode, semanticFeature, image, text, true, synthetic, inheritanceDepth); } }
@Test public void should_getStyledText_strip_expression_charriage() throws Exception { final ContractConstraint constraint = ProcessFactory.eINSTANCE.createContractConstraint(); constraint.setExpression("toto == true && \n titi == false \r"); final StyledString styledText = labelProvider.getStyledText(constraint); assertThat(styledText.toString()).doesNotContain("\n").doesNotContain("\r"); }
private StyledString appendStyled(StyledString s, Object a, Styler styler) { if (a instanceof String) s.append((String) a, styler); else if (a instanceof StyledString) { if (styler != null) s.append(a.toString(), styler); // restyle else s.append((StyledString) a); } else s.append(a.toString(), styler); return s; }
@Override public String getText(Object element) { StyledString styledText = getStyledText(element); if (styledText != null) { return styledText.getString(); } return null; }
@Override public void update(ViewerCell cell) { Object element = cell.getElement(); StyledString styledText = getStyledText(element); cell.setText(styledText.toString()); cell.setStyleRanges(styledText.getStyleRanges()); cell.setImage(getImage(element)); super.update(cell); }
// By default, use full string of styled text @Override public String getDescription(Object anElement) { StyledString styledText = getStyledText(anElement); if (styledText != null) { return styledText.getString(); } return null; }
@Override public StyledString getStyledDisplayString() { StyledString result = new StyledString(); highlightPattern(getHighlightPattern(), getBaseDisplayString(), result); Type type = getType(); if (type != null) { String typeStr = typeUtil.niceTypeName(type); result.append(" : " + typeStr, StyledString.DECORATIONS_STYLER); } return result; }
private static void parameters(Tree.TypeParameterList tpl, StyledString label) { if (tpl != null && !tpl.getTypeParameterDeclarations().isEmpty()) { label.append("<"); int len = tpl.getTypeParameterDeclarations().size(), i = 0; for (Tree.TypeParameterDeclaration p : tpl.getTypeParameterDeclarations()) { label.append(name(p.getIdentifier()), TYPE_STYLER); if (++i < len) label.append(", "); } label.append(">"); } }
@Override public StyledString getStyledLabel() { StyledString resultLabel = new StyledString(); resultLabel.append(super.name); if (!this.enumConstant) { resultLabel.append(String.format(" : %1s ", this.fieldType), new TypeInformationStyle()); } resultLabel.append( String.format(" [%1s.%2s] ", super.elementPackage, this.fieldClass), new LocationStyle()); return resultLabel; }
@Override public StyledString getStyledDisplayText() { StyledString ss = new StyledString(); if (isFirst()) ss.append("("); else { ss.append(super.getDisplayText(), FontUtils.KEYWORDS_STYLER); ss.append(" ("); } if (getChildren().isEmpty()) ss.append(")"); return ss; }
StyledString text(AtExpression o) { StyledString label = new StyledString(); Object lo = doGetText(o.getLeftExpr()); appendStyled(label, lo); label.append("["); for (Expression expr : o.getParameters()) { appendStyled(label, doGetText(expr)); } label.append("]"); return label; }
private void updateInput() { if (this.infoText == null || !this.inputChanged) { return; } if (this.labelProvider == null) { this.labelProvider = new RLabelProvider( RLabelProvider.LONG | RLabelProvider.HEADER | RLabelProvider.NAMESPACE); } if (this.input != null) { final Image image = this.labelProvider.getImage(this.input.getElement()); this.titleImage.setImage( (image != null) ? image : SharedUIResources.getImages().get(SharedUIResources.PLACEHOLDER_IMAGE_ID)); final StyledString styleString = this.labelProvider.getStyledText( this.input.getElement(), this.input.getElementName(), this.input.getElementAttr()); if (this.input.isElementOfActiveBinding()) { styleString.append(" (active binding)", StyledString.QUALIFIER_STYLER); } this.titleText.setText(styleString.getString()); this.titleText.setStyleRanges(styleString.getStyleRanges()); if (this.input.hasDetail()) { this.infoText.setText( this.input.getDetailTitle() + '\n' + ((this.input.getDetailInfo() != null) ? this.input.getDetailInfo() : "")); //$NON-NLS-1$ final StyleRange title = new StyleRange(0, this.input.getDetailTitle().length(), null, null); title.underline = true; this.infoText.setStyleRange(title); } else { this.infoText.setText(""); // $NON-NLS-1$ } } else { this.titleImage.setImage( SharedUIResources.getImages().get(SharedUIResources.PLACEHOLDER_IMAGE_ID)); this.titleText.setText(""); // $NON-NLS-1$ this.infoText.setText(""); // $NON-NLS-1$ } if ((this.mode & MODE_FOCUS) != 0) { getToolBarManager().update(true); } else { setStatusText( (this.input.getControl() != null && this.input.getControl().isFocusControl()) ? InformationDispatchHandler.getTooltipAffordanceString() : ""); //$NON-NLS-1$ } this.inputChanged = false; }
public StyledString getStyledText(Object element) { // need to compare classes as everything is 'instanceof GitModelCommit' if (element.getClass().equals(GitModelCommit.class)) { String formattedName = createChangeSetLabel((GitModelCommit) element); StyledString string = new StyledString(formattedName); GitModelCommit commit = (GitModelCommit) element; String format = " [" + getAbbreviatedId(commit) + "]"; // $NON-NLS-1$//$NON-NLS-2$ string.append(format, StyledString.DECORATIONS_STYLER); return string; } return getDelegateLabelProvider().getStyledText(element); }
void applyTo( StyledString styled, String otherText, Side side, Direction direction, boolean highlightChanges) { String text = styled.getString(); int index = styled.getString().indexOf(":"); Styler styler = highlightChanges ? stringStyler : fieldStyler; if (index == -1) styled.setStyle(0, text.length(), styler); else styled.setStyle(index + 2, text.length() - (index + 2), styler); if (highlightChanges) applySpecificDiffs(styled, otherText, side, direction); }
@Override public StyledString getStyledDisplayString() { if (styledString == null) { styledString = new StyledString(); styledString.append(text, StyledString.QUALIFIER_STYLER); if (right != null) { styledString.append(" - "); styledString.append(text, StyledString.DECORATIONS_STYLER); } } return styledString; }
@Override public StyledString getStyledText(Object arg) { if (arg instanceof IResource) { IResource resource = (IResource) arg; StyledString text = new StyledString(); if (isFailedStatus(resource)) { text.append(((IStatus) resource).getMessage()); } else { text.append(StringUtils.humanize(resource.getKind().toString())); text.append(resource.getName(), StyledString.QUALIFIER_STYLER); } return text; } return null; }
@Override public StyledString getStyledText(Object element) { StyledString string = CElementLabels.getStyledTextLabel( element, (evaluateTextFlags(element) | CElementLabels.COLORIZE)); if (string.length() == 0 && (element instanceof IStorage)) { string = new StyledString(fStorageLabelProvider.getText(element)); } String decorated = decorateText(string.getString(), element); if (decorated != null) { return StyledCellLabelProvider.styleDecoratedString( decorated, StyledString.DECORATIONS_STYLER, string); } return string; }