org.eclipse.jface.viewers.StyledString Java Examples

The following examples show how to use org.eclipse.jface.viewers.StyledString. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SARLLabelProvider.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Replies the text for the given element.
 *
 * @param element the element.
 * @return the text.
 */
protected StyledString text(SarlBehaviorUnit element) {
	final StyledString text = new StyledString("on ", StyledString.DECORATIONS_STYLER); //$NON-NLS-1$
	text.append(getHumanReadableName(element.getName()));
	if (element.getGuard() != null) {
		String txt = null;
		final ICompositeNode node = NodeModelUtils.getNode(element.getGuard());
		if (node != null) {
			txt = node.getText().trim();
		}
		if (Strings.isNullOrEmpty(txt)) {
			txt = "[" + Messages.SARLLabelProvider_2 + "]"; //$NON-NLS-1$//$NON-NLS-2$
		} else {
			assert txt != null;
			final String dots = "..."; //$NON-NLS-1$
			if (txt.length() > BEHAVIOR_UNIT_TEXT_LENGTH + dots.length()) {
				txt = "[" + txt.substring(0, BEHAVIOR_UNIT_TEXT_LENGTH) + dots + "]"; //$NON-NLS-1$//$NON-NLS-2$
			} else {
				txt = "[" + txt + "]"; //$NON-NLS-1$//$NON-NLS-2$
			}
		}
		text.append(" "); //$NON-NLS-1$
		text.append(txt, StyledString.DECORATIONS_STYLER);
	}
	return text;
}
 
Example #2
Source File: DiffStyle.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
void applyTo(StyledString styled, String otherText, Site site, ActionType action) {
	String text = styled.getString();
	if (text.isEmpty())
		return;
	styled.setStyle(0, text.length(), defaultStyler);
	LinkedList<Diff> diffs = getDiffs(text, otherText, site, action);
	boolean showDelete = doShowDelete(site, action);
	boolean showInsert = doShowInsert(site, action);
	int index = 0;
	for (Diff diff : diffs) {
		if (showDelete && diff.operation == Operation.DELETE) {
			styled.setStyle(index, diff.text.length(), deleteStyler);
			index += diff.text.length();
		} else if (showInsert && diff.operation == Operation.INSERT) {
			styled.setStyle(index, diff.text.length(), insertStyler);
			index += diff.text.length();
		} else if (diff.operation == Operation.EQUAL) {
			index += diff.text.length();
		}
	}
}
 
Example #3
Source File: CompletionProposalLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Appends the parameter list to <code>buffer</code>.
 *
 * @param buffer the buffer to append to
 * @param methodProposal the method proposal
 * @return the modified <code>buffer</code>
 */
private StyledString appendUnboundedParameterList(StyledString buffer, CompletionProposal methodProposal) {
	// TODO remove once https://bugs.eclipse.org/bugs/show_bug.cgi?id=85293
	// gets fixed.
	char[] signature= SignatureUtil.fix83600(methodProposal.getSignature());
	char[][] parameterNames= methodProposal.findParameterNames(null);
	char[][] parameterTypes= Signature.getParameterTypes(signature);

	for (int i= 0; i < parameterTypes.length; i++)
		parameterTypes[i]= createTypeDisplayName(SignatureUtil.getLowerBound(parameterTypes[i]));

	if (Flags.isVarargs(methodProposal.getFlags())) {
		int index= parameterTypes.length - 1;
		parameterTypes[index]= convertToVararg(parameterTypes[index]);
	}
	return appendParameterSignature(buffer, parameterTypes, parameterNames);
}
 
Example #4
Source File: XtendProposalProvider.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void completeParameter_Name(final EObject model, Assignment assignment, final ContentAssistContext context,
		final ICompletionProposalAcceptor acceptor) {
	if (model instanceof XtendParameter) {
		final List<XtendParameter> siblings = EcoreUtil2.getSiblingsOfType(model, XtendParameter.class);
		Set<String> alreadyTaken = Sets.newHashSet();
		for(XtendParameter sibling: siblings) {
			alreadyTaken.add(sibling.getName());
		}
		alreadyTaken.addAll(getAllKeywords());
		completions.getVariableProposals(model, XtendPackage.Literals.XTEND_PARAMETER__PARAMETER_TYPE,
				VariableType.PARAMETER, alreadyTaken, new JdtVariableCompletions.CompletionDataAcceptor() {
					@Override
					public void accept(String replaceText, StyledString label, Image img) {
						acceptor.accept(createCompletionProposal(replaceText, label, img, context));
					}
				});
	} else {
		super.completeParameter_Name(model, assignment, context, acceptor);
	}
}
 
Example #5
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 6 votes vote down vote up
public StyledStringVisitor(CloneStructureNode node, CloneDiffSide position) {
	this.styledString = new StyledString();
	List<ASTNodeDifference> differences = node.getMapping().getNodeDifferences();
	//TextStyle Experiment
	keywordStyle = initializeKeywordStyle();
	stringStyle = initializeStringStyle();
	ordinaryStyle = initializeOrdinaryStyle();
	differenceStyle = initializeDifferenceStyle();
	namedConstantStyle = initializeNamedConstantStyle();
	nonStaticFieldStyle = initializeNonStaticFieldStyle();
	staticMethodCallStyle = initializeStaticMethodCallStyle();

	if(node.isElseIf()) {
		styledString.append("else", new StyledStringStyler(keywordStyle));
		appendSpace();
	}
	//Use the List of ASTNodeDifferences to recover actual ASTNodes and place them into a new list
	astNodesThatAreDifferences = new ArrayList<ASTNode>();
	generateDifferenceASTNodes(differences, position);
}
 
Example #6
Source File: ModulaContextualCompletionProposal.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a new completion proposal. All fields are initialized based on the provided information.
 *
 * @param replacementString the actual string to be inserted into the document
 * @param replacementOffset the offset of the text to be replaced
 * @param replacementLength the length of the text to be replaced
 * @param cursorPosition the position of the cursor following the insert relative to replacementOffset
 * @param image the image to display for this proposal
 * @param displayString the string to be displayed for the proposal
 * @param contextInformation the context information associated with this proposal
 * @param additionalProposalInfo the additional information associated with this proposal
 */
public ModulaContextualCompletionProposal(String replacementString, int replacementOffset, int replacementLength, 
        int cursorPosition, Image image, StyledString displaySString, IContextInformation contextInformation, String additionalProposalInfo) {
    Assert.isNotNull(replacementString);
    Assert.isTrue(replacementOffset >= 0);
    Assert.isTrue(replacementLength >= 0);
    Assert.isTrue(cursorPosition >= 0);

    fReplacementString= replacementString;
    fReplacementOffset= replacementOffset;
    fReplacementLength= replacementLength;
    fCursorPosition= cursorPosition;
    fImage= image;
    fDisplaySString= displaySString;
    fContextInformation= contextInformation;
    fAdditionalProposalInfo= additionalProposalInfo;
}
 
Example #7
Source File: SARLProposalProvider.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
public void completeAOPMember_Guard(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
	if (model instanceof SarlBehaviorUnit) {
		final SarlBehaviorUnit behaviorUnit = (SarlBehaviorUnit) model;
		final XExpression guardExpr = behaviorUnit.getGuard();
		if (guardExpr != null) {
			// Generate the proposals by considering the guard expression as an anchor.
			createLocalVariableAndImplicitProposals(guardExpr, IExpressionScope.Anchor.BEFORE, context, acceptor);
			return;
		}
		final XExpression body = behaviorUnit.getExpression();
		if (body != null) {
			// Generate the proposals by considering that all elements that accessible from the body are accessible from the guard to.
			// "it" is missed => it is manually added.
			final ICompletionProposal itProposal = createCompletionProposal(
					this.keywords.getItKeyword(),
					new StyledString(this.keywords.getItKeyword()),
					this.imageHelper.getImage(this.images.forLocalVariable(0)),
					SARLContentProposalPriorities.CONTEXTUAL_KEYWORD_PRIORITY,
					context.getPrefix(), context);
			acceptor.accept(itProposal);
			createLocalVariableAndImplicitProposals(body, context, acceptor);
		}
	}
}
 
Example #8
Source File: Strings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Adds special marks so that that the given styled string is readable in a BiDi environment.
 * 
 * @param styledString the styled string
 * @return the processed styled string
 * @since 3.4
 */
public static StyledString markLTR(StyledString styledString) {
	
	/*
	 * NOTE: For performance reasons we do not call  markLTR(styledString, null)
	 */
	
	if (!USE_TEXT_PROCESSOR)
		return styledString;

	String inputString= styledString.getString();
	String string= TextProcessor.process(inputString);
	if (string != inputString)
		insertMarks(styledString, inputString, string);
	return styledString;
}
 
Example #9
Source File: SelectModulaSourceFileDialog.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public StyledString getStyledText(Object element) {
    String text= getText(element);
    StyledString string= new StyledString(text);
    
    if (element instanceof ListItem) {
        ListItem li = (ListItem)element;
        if (li.isDelimiter()) {
            string.setStyle(0, text.length(), StyledString.QUALIFIER_STYLER);
        } else { 
            int concatPos = text.indexOf(CONCAT_STRING);
            String modName = concatPos == -1 ? text : text.substring(0, concatPos);

            if (sourceFileItemsFilter != null) {
                ArrayList<Integer> ints = sourceFileItemsFilter.getMatchedIntervals(modName); 
                markMatchingRegions(string, ints, boldStyler);
            }

            if (concatPos != -1) {
                string.setStyle(concatPos, text.length() - concatPos, StyledString.QUALIFIER_STYLER);
            }
        }
    }

    return string;
}
 
Example #10
Source File: XtextOutlineTreeProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void createRuleNode(IOutlineNode parentNode, AbstractRule rule, boolean isShowGrammar, boolean isLocalRule) {
	StyledString text = (StyledString) textDispatcher.invoke(rule);
	if (isShowGrammar) {
		EObject grammar = rule.eContainer();
		if (grammar instanceof Grammar)
			text.append(new StyledString(" (" + ((Grammar) grammar).getName() + ")", StyledString.COUNTER_STYLER));
	}
	Image image = imageDispatcher.invoke(rule);
	RuleNode ruleNode = new RuleNode(rule, parentNode, image, text, isLeafDispatcher.invoke(rule));
	ruleNode.setFullText(new StyledString().append(text).append(getReturnTypeText(rule)));
	if (isLocalRule) {
		ICompositeNode parserNode = NodeModelUtils.getNode(rule);
		if (parserNode != null)
			ruleNode.setTextRegion(parserNode.getTextRegion());
		ruleNode.setShortTextRegion(locationInFileProvider.getSignificantTextRegion(rule));
	}
}
 
Example #11
Source File: DiagramLabelProvider.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void update(ViewerCell cell) {
       if (cell.getElement() instanceof DiagramFileStore) {
       	DiagramFileStore filseStore = (DiagramFileStore) cell.getElement();
           StyledString styledString = new StyledString();

           styledString.append(fileStoreLabelProvider.getText(filseStore), null);
           if(filseStore.hasMigrationReport()){
           	  styledString.append(" -- ",StyledString.DECORATIONS_STYLER) ;
           	  styledString.append( Messages.migrationOngoing ,StyledString.COUNTER_STYLER) ;
           }
       
           cell.setText(styledString.getString());
           cell.setImage(fileStoreLabelProvider.getImage(filseStore)) ;
           cell.setStyleRanges(styledString.getStyleRanges());
       }
	super.update(cell);
}
 
Example #12
Source File: CodetemplatesProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public void completeNestedKeyword(Keyword keyword, ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor, TemplateData data) {
	String keywordValue = keyword.getValue();
	String escapedKeywordValue = keywordValue.replace("$", "$$");
	StyledString displayString = new StyledString(keywordValue);
	if (!keywordValue.equals(escapedKeywordValue)) {
		displayString = new StyledString(escapedKeywordValue)
			.append(" - ", StyledString.QUALIFIER_STYLER)
			.append(keywordValue, StyledString.COUNTER_STYLER)
			.append(" - Keyword", StyledString.QUALIFIER_STYLER);
	} else {
		displayString = displayString.append(" - Keyword", StyledString.QUALIFIER_STYLER);
	}
	ConfigurableCompletionProposal proposal = (ConfigurableCompletionProposal) createCompletionProposal(escapedKeywordValue,
			displayString,
			getImage(keyword),
			contentAssistContext);
	getPriorityHelper().adjustKeywordPriority(proposal, contentAssistContext.getPrefix());
	if (proposal != null)
		proposal.setPriority(proposal.getPriority() * 2);
	acceptor.accept(proposal);
}
 
Example #13
Source File: AppEngineProjectElement.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
public StyledString getStyledLabel() {
  StyledString result = new StyledString("App Engine");
  result.append(" [", StyledString.QUALIFIER_STYLER);
  result.append(getEnvironmentType(), StyledString.QUALIFIER_STYLER);
  result.append(": ", StyledString.QUALIFIER_STYLER);
  result.append(getRuntime(), StyledString.QUALIFIER_STYLER);
  result.append("]", StyledString.QUALIFIER_STYLER);
  result.append(" - " + descriptorFile.getName(), StyledString.DECORATIONS_STYLER);
  return result;
}
 
Example #14
Source File: JavaElementLabels.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the styled label of a classpath container.
 * The returned label is BiDi-processed with {@link TextProcessor#process(String, String)}.
 *
 * @param containerPath the path of the container
 * @param project the project the container is resolved in
 * @return the label of the classpath container
 *
 * @since 3.4
 */
public static StyledString getStyledContainerEntryLabel(IPath containerPath, IJavaProject project) {
	try {
		IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, project);
		String description= null;
		if (container != null) {
			description= container.getDescription();
		}
		if (description == null) {
			ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
			if (initializer != null) {
				description= initializer.getDescription(containerPath, project);
			}
		}
		if (description != null) {
			StyledString str= new StyledString(description);
			if (containerPath.segmentCount() > 0 && JavaRuntime.JRE_CONTAINER.equals(containerPath.segment(0))) {
				int index= description.indexOf('[');
				if (index != -1) {
					str.setStyle(index, description.length() - index, DECORATIONS_STYLE);
				}
			}
			return Strings.markLTR(str);
		}
	} catch (JavaModelException e) {
		// ignore
	}
	return new StyledString(BasicElementLabels.getPathLabel(containerPath, false));
}
 
Example #15
Source File: CompletionProposalCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IJavaCompletionProposal createLabelProposal(CompletionProposal proposal) {
	String completion= String.valueOf(proposal.getCompletion());
	int start= proposal.getReplaceStart();
	int length= getLength(proposal);
	StyledString label= fLabelProvider.createSimpleLabel(proposal);
	int relevance= computeRelevance(proposal);

	return new JavaCompletionProposal(completion, start, length, null, label, relevance);
}
 
Example #16
Source File: DefaultEObjectLabelProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testGetStyledTextFallbackText() throws Exception {
	DefaultEObjectLabelProvider defaultLabelProvider = new DefaultEObjectLabelProvider();
	ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
	parserRule.setName("testCreateStyledString");
	StyledString styledText = defaultLabelProvider.getStyledText(parserRule);
	assertEquals("testCreateStyledString", styledText.getString());
}
 
Example #17
Source File: ApplicationFileStoreLabelProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private String appendAppTokens(final ApplicationFileStore fileStore, final StyledString styledString)
        throws ReadFileStoreException {
    styledString.append("  ");
    List<ApplicationNode> applications = fileStore.getContent().getApplications();
    styledString.append(
            applications.stream()
                    .map(application -> "../apps/" + application.getToken())
                    .collect(Collectors.joining(", ")),
            StyledString.COUNTER_STYLER);
    return styledString.getString();
}
 
Example #18
Source File: CompletionProposalLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
StyledString createLabelWithTypeAndDeclaration(CompletionProposal proposal) {
	char[] name= proposal.getCompletion();
	if (!isThisPrefix(name))
		name= proposal.getName();

	StyledString buf= new StyledString();
	buf.append(name);
	char[] typeName= Signature.getSignatureSimpleName(proposal.getSignature());
	if (typeName.length > 0) {
		buf.append(VAR_TYPE_SEPARATOR);
		buf.append(typeName);
	}
	char[] declaration= proposal.getDeclarationSignature();
	if (declaration != null) {
		declaration= Signature.getSignatureSimpleName(declaration);
		if (declaration.length > 0) {
			buf.append(QUALIFIER_SEPARATOR, StyledString.QUALIFIER_STYLER);
			if (proposal.getRequiredProposals() != null) {
				String declaringType= extractDeclaringTypeFQN(proposal);
				String qualifier= Signature.getQualifier(declaringType);
				if (qualifier.length() > 0) {
					buf.append(qualifier, StyledString.QUALIFIER_STYLER);
					buf.append('.', StyledString.QUALIFIER_STYLER);
				}
			}
			buf.append(declaration, StyledString.QUALIFIER_STYLER);
		}
	}

	return Strings.markJavaElementLabelLTR(buf);
}
 
Example #19
Source File: ParameterStyledLabelProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void update(ViewerCell cell) {
    if (cell.getElement() instanceof Parameter) {
        Parameter p = (Parameter) cell.getElement();
        StyledString styledString = new StyledString();

        String decoration = " -- " +typeProvider.getText(p);
        styledString.append(p.getName(), null);

        styledString.append(decoration, StyledString.DECORATIONS_STYLER);
        cell.setText(styledString.getString());
        cell.setImage(getImage(p)) ;
        cell.setStyleRanges(styledString.getStyleRanges());
    }
}
 
Example #20
Source File: SARLLabelProvider.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the text for the given element.
 *
 * @param element the element.
 * @return the text.
 */
protected StyledString text(SarlAction element) {
	final JvmIdentifiableElement jvmElement = this.jvmModelAssociations.getDirectlyInferredOperation(element);
	final String simpleName = element.getName();
	if (simpleName != null) {
		final QualifiedName qnName = QualifiedName.create(simpleName);
		final QualifiedName operator = this.operatorMapping.getOperator(qnName);
		if (operator != null) {
			final StyledString result = signature(operator.getFirstSegment(), jvmElement);
			result.append(" (" + simpleName + ")", StyledString.COUNTER_STYLER); //$NON-NLS-1$//$NON-NLS-2$
			return result;
		}
	}
	return signature(element.getName(), jvmElement);
}
 
Example #21
Source File: TypeLabelProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private StyledString getStyledString(Object element) {
    StyledString styledString = new StyledString();
    if (element instanceof SimpleField) {
        appendTypeLabel(((SimpleField) element).getType(), styledString);
    } else if (element instanceof FieldType) {
        appendTypeLabel((FieldType) element, styledString);
    } else if (element instanceof RelationField && ((RelationField) element).getReference() != null) {
        styledString.append(((RelationField) element).getReference().getSimpleName());
    } else if (element instanceof BusinessObject) {
        styledString.append(((BusinessObject) element).getSimpleName());
    }
    return styledString;
}
 
Example #22
Source File: HierarchyLabelProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public StyledString getStyledText(Object element) {
	if (element instanceof PendingUpdateAdapter) {
		return new StyledString(getPendingText());
	}
	return globalDescriptionProvider.getStyledText(getDescription(element));
}
 
Example #23
Source File: ApplicationFileStoreLabelProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void contentValidation(IRepositoryFileStore fileStore, StyledString styledString, ViewerCell cell) {
    if (fileStore instanceof ApplicationFileStore) {
        try {
            ApplicationFileStore applicationFileStore = (ApplicationFileStore) fileStore;
            if (!applicationFileStore.getContent().getApplications().isEmpty()) {
                cell.setText(appendAppTokens(applicationFileStore, styledString));
            }
        } catch (ReadFileStoreException e) {
            //Do not display app descriptors
            applyUnparsableFileStyle(cell);
        }
    }
}
 
Example #24
Source File: DualExpressionPreconditionViolation.java    From JDeodorant with MIT License 5 votes vote down vote up
public StyledString getStyledViolation() {
	StyledString styledString = new StyledString();
	BoldStyler boldStyler = new BoldStyler();
	NormalStyler normalStyler = new NormalStyler();
	if(type.equals(PreconditionViolationType.INFEASIBLE_UNIFICATION_DUE_TO_VARIABLE_TYPE_MISMATCH)) {
		Expression expression1 = this.expression1.getExpression();
		Expression expression2 = this.expression2.getExpression();
		if(expression1 instanceof Name && ((Name)expression1).resolveBinding().getKind() == IBinding.TYPE &&
				expression2 instanceof Name && ((Name)expression2).resolveBinding().getKind() == IBinding.TYPE) {
			styledString.append("Type ", normalStyler);
			styledString.append(expression1.resolveTypeBinding().getQualifiedName(), boldStyler);
			styledString.append(" does not match with ", normalStyler);
			styledString.append("type ", normalStyler);
			styledString.append(expression2.resolveTypeBinding().getQualifiedName(), boldStyler);
		}
		else {
			expression1 = ASTNodeDifference.getParentExpressionOfMethodNameOrTypeName(expression1);
			expression2 = ASTNodeDifference.getParentExpressionOfMethodNameOrTypeName(expression2);
			styledString.append("Type ", normalStyler);
			styledString.append(expression1.resolveTypeBinding().getQualifiedName(), boldStyler);
			styledString.append(" of variable ", normalStyler);
			styledString.append(expression1.toString(), boldStyler);
			styledString.append(" does not match with ", normalStyler);
			styledString.append("type ", normalStyler);
			styledString.append(expression2.resolveTypeBinding().getQualifiedName(), boldStyler);
			styledString.append(" of variable ", normalStyler);
			styledString.append(expression2.toString(), boldStyler);
		}
	}
	return styledString;
}
 
Example #25
Source File: UncommonSuperclassPreconditionViolation.java    From JDeodorant with MIT License 5 votes vote down vote up
@Override
public StyledString getStyledViolation() {
	StyledString styledString = new StyledString();
	NormalStyler normalStyler = new NormalStyler();
	BoldStyler boldStyler = new BoldStyler();
	styledString.append("The refactoring of the clones is infeasible, because classes ", normalStyler);
	styledString.append(qualifiedType1, boldStyler);
	styledString.append(" and ", normalStyler);
	styledString.append(qualifiedType2, boldStyler);
	styledString.append(" do not have a common superclass", normalStyler);
	return styledString;
}
 
Example #26
Source File: JsonTreeLabelProvider.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void update(ViewerCell cell) {
	Object element = cell.getElement();
	if (!(element instanceof JsonNode))
		return;
	JsonNode node = (JsonNode) element;
	StyledString styledString = getStyledText(node);
	cell.setText(styledString.toString());
	cell.setStyleRanges(styledString.getStyleRanges());
	cell.setImage(nodeLabelProvider.getImage(node, site));
	super.update(cell);
}
 
Example #27
Source File: SessionHeaderElement.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public StyledString getStyledText() {
  StyledString styledString = new StyledString();
  if (sessionInput == null || sessionInput.getSession() == null) {
    styledString.append(Messages.SessionHeaderElement_no_session_running, boldStyler);
  } else {
    styledString.append(Messages.SessionHeaderElement_session, boldStyler);
  }
  return styledString;
}
 
Example #28
Source File: SARLOutlineTreeProvider.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Compute the text for the given JVM constructor, which is usually a inherited constructor.
 *
 * @param modelElement the model
 * @return the text.
 */
protected CharSequence _text(JvmConstructor modelElement) {
	if (this.labelProvider instanceof IStyledLabelProvider) {
		final StyledString str = ((IStyledLabelProvider) this.labelProvider).getStyledText(modelElement);
		str.setStyle(0, str.length(), ColoringLabelProvider.INHERITED_STYLER);
		return str;
	}
	return this.labelProvider.getText(modelElement);
}
 
Example #29
Source File: UiToIdeContentProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected StyledString getDisplayString(ContentAssistEntry entry) {
	StyledString result = new StyledString(entry.getLabel() != null ? entry.getLabel() : entry.getProposal());
	if (!Strings.isNullOrEmpty(entry.getDescription())) {
		result.append(new StyledString(" \u2013 " + entry.getDescription(), StyledString.QUALIFIER_STYLER));
	}
	return result;
}
 
Example #30
Source File: QuickAssistProcessor1.java    From codeexamples-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IJavaCompletionProposal[] getAssists(IInvocationContext context, IProblemLocation[] locations)
		throws CoreException {
	return new IJavaCompletionProposal[] { new AbstractJavaCompletionProposal() {
		public org.eclipse.jface.viewers.StyledString getStyledDisplayString() {
			ICompilationUnit compilationUnit = context.getCompilationUnit();
			return new StyledString(
					"Generate Getter and setter for " + compilationUnit.findPrimaryType().getElementName());
		}
		
		protected int getPatternMatchRule(String pattern, String string) {
			// override the match rule since we do not work with a pattern, but just want to open the "Generate Getters and Setters..." dialog
			return -1;
		};
		
		public void apply(org.eclipse.jface.text.ITextViewer viewer, char trigger, int stateMask, int offset) {
			
			if(context instanceof AssistContext) {
				AssistContext assistContext = (AssistContext) context;
				AddGetterSetterAction addGetterSetterAction = new AddGetterSetterAction((CompilationUnitEditor)assistContext.getEditor());
				
				addGetterSetterAction.run();
			}
			
		}
	} };
}