Java Code Examples for org.eclipse.jface.viewers.StyledString#setStyle()

The following examples show how to use org.eclipse.jface.viewers.StyledString#setStyle() . 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: FilteredTypesSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void markMatchingRegions(StyledString string, int index, int[] matchingRegions, Styler styler) {
	if (matchingRegions != null) {
		int offset= -1;
		int length= 0;
		for (int i= 0; i + 1 < matchingRegions.length; i= i + 2) {
			if (offset == -1)
				offset= index + matchingRegions[i];
			
			// Concatenate adjacent regions
			if (i + 2 < matchingRegions.length && matchingRegions[i] + matchingRegions[i + 1] == matchingRegions[i + 2]) {
				length= length + matchingRegions[i + 1];
			} else {
				string.setStyle(offset, length + matchingRegions[i + 1], styler);
				offset= -1;
				length= 0;
			}
		}
	}
}
 
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: ImportModelLabelProvider.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public StyledString getStyledText(Object element) {
    String name = getText(element);
    StyledString styledString = new StyledString(name);
    if (hasStatus(element, ConflictStatus.CONFLICTING)) {
        styledString.setStyle(START_OFFSET, name.length(), conflictStyler);
    }
    if (hasStatus(element, ConflictStatus.SAME_CONTENT)) {
        styledString.append(String.format(" (%s)", Messages.skipped));
        styledString.setStyle(START_OFFSET, styledString.length(), sameContentStyler);
    }
    if (element instanceof LegacyStoreModel) {
        styledString.setStyle(START_OFFSET, styledString.length(), notImportedStyle);
        styledString.append(String.format(" (%s)", Messages.legacyFormsNotImported));
    }
    return styledString;
}
 
Example 4
Source File: OpenTypeSelectionDialog.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public StyledString getStyledText(final Object element) {
	if (element instanceof IEObjectDescription) {
		final String text = getText(element);
		final StyledString string = new StyledString(text);

		final int[] matchingRegion = getMatchingRegions(text);
		if (null != matchingRegion) {
			for (int i = 0; i < matchingRegion.length; i = i + 2) {
				string.setStyle(matchingRegion[i], matchingRegion[i + 1], boldStyler);
			}
		}

		final int indexOf = text.indexOf(NAME_SEPARATOR);
		if (-1 < indexOf) {
			string.setStyle(indexOf, text.length() - indexOf, qualifierStyler);
		}
		return string;
	}
	return new StyledString();
}
 
Example 5
Source File: TypeScriptCompletionProposalWithExtension7.java    From typescript.java with MIT License 6 votes vote down vote up
@Override
public StyledString getStyledDisplayString(IDocument document, int offset, BoldStylerProvider boldStylerProvider) {
	// Highlight matched prefix
	StyledString styledDisplayString = new StyledString();
	styledDisplayString.append(getStyledDisplayString());

	String pattern = getPatternToEmphasizeMatch(document, offset);
	if (pattern != null && pattern.length() > 0) {
		String displayString = styledDisplayString.getString();
		int[] bestSequence = getMatcher().bestSubsequence(displayString, pattern);
		int highlightAdjustment = 0;
		for (int index : bestSequence) {
			styledDisplayString.setStyle(index + highlightAdjustment, 1, boldStylerProvider.getBoldStyler());
		}
	}
	return styledDisplayString;
}
 
Example 6
Source File: TLAFilteredItemsSelectionDialog.java    From tlaplus with MIT License 6 votes vote down vote up
public StyledString getStyledText(Object element) {
	final String text = getText(element);
	if (text == null || EMPTY_STRING.equals(text)) {
		return new StyledString();
	}
	
	final StyledString string = new StyledString(text);
	
	if (element instanceof Spec) {
		string.setStyle(0, string.length(), StyledString.QUALIFIER_STYLER);
	} else if (element instanceof Model && text.indexOf(DELIM) != -1) {
		final int index = text.indexOf(DELIM);
		string.setStyle(index, text.length() - index, StyledString.DECORATIONS_STYLER);
	} else if (element instanceof ItemsListSeparator) {
		string.setStyle(0, string.length(), StyledString.QUALIFIER_STYLER);
	}
	return string;
}
 
Example 7
Source File: SelectModulaSourceFileDialog.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
private void markMatchingRegions(StyledString string, ArrayList<Integer> intervals, Styler styler) {
    if (intervals != null) {
        int offset= -1;
        int length= 0;
        for (int i= 0; i + 1 < intervals.size(); i= i + 2) {
            int beg = intervals.get(i); 
            int len = intervals.get(i+1) - beg; 

            if (offset == -1) {
                offset = beg;
            }
            // Concatenate adjacent regions
            if (i + 2 < intervals.size() && beg+len == intervals.get(i + 2)) {
                length= length + len;
            } else {
                string.setStyle(offset, length + len, styler);
                offset= -1;
                length= 0;
            }
        }
    }
}
 
Example 8
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 9
Source File: DotEditorUtils.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
public static StyledString style(String format, Object... args) {
	String text = String.format(format, args);
	StyledString styled = new StyledString(text);
	int offset = text.indexOf(':');
	styled.setStyle(offset, text.length() - offset,
			StyledString.DECORATIONS_STYLER);
	return styled;
}
 
Example 10
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 11
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 12
Source File: StyledFilterLabelProvider.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 ActorFilter) {
        ActorFilter filter = (ActorFilter) cell.getElement();
        ConnectorDefinition def = defStore.getDefinition(filter.getDefinitionId(),filter.getDefinitionVersion()) ;
        StyledString styledString = new StyledString();

        styledString.append(getText(filter), null);
        styledString.append(" -- ",StyledString.QUALIFIER_STYLER) ;
        String connectorType = filter.getDefinitionId() +" ("+filter.getDefinitionVersion()+")";
        styledString.append(connectorType, StyledString.DECORATIONS_STYLER);
        if(filter.getEvent() != null && !filter.getEvent().isEmpty()){
            styledString.append(" -- ",StyledString.QUALIFIER_STYLER) ;
            styledString.append(filter.getEvent(), StyledString.COUNTER_STYLER);
        }
        if(def == null){
            styledString.setStyle(0, styledString.length(), new org.eclipse.jface.viewers.StyledString.Styler() {

                @Override
                public void applyStyles(TextStyle textStyle) {
                    textStyle.strikeout = true ;
                }
            }) ;
            styledString.append(" ");
            styledString.append(Messages.bind(Messages.filterDefinitionNotFound,filter.getDefinitionId() + " ("+filter.getDefinitionVersion()+")")) ;
        }

        cell.setText(styledString.getString());
        cell.setImage(getImage(filter)) ;
        cell.setStyleRanges(styledString.getStyleRanges());
    }
}
 
Example 13
Source File: StyledFilterLabelProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getText(Object element) {
    ActorFilter filter = (ActorFilter) element;
    ConnectorDefinition def = defStore.getDefinition(filter.getDefinitionId(),filter.getDefinitionVersion()) ;
    StyledString styledString = new StyledString();

    styledString.append(filter.getName(), null);
    styledString.append(" -- ",StyledString.QUALIFIER_STYLER) ;
    String connectorType = messageProvider.getConnectorDefinitionLabel(def) ;
    if(connectorType==null && def != null) {
        connectorType = def.getId();
    }
    if(connectorType!=null){
    	 styledString.append(connectorType, StyledString.DECORATIONS_STYLER);
    }
   
    if(filter.getEvent() != null && !filter.getEvent().isEmpty()){
        styledString.append(" -- ",StyledString.QUALIFIER_STYLER) ;
        styledString.append(filter.getEvent(), StyledString.COUNTER_STYLER);
    }
    if(def == null){
        styledString.setStyle(0, styledString.length(), new org.eclipse.jface.viewers.StyledString.Styler() {

            @Override
            public void applyStyles(TextStyle textStyle) {
                textStyle.strikeout = true ;
            }
        }) ;
        styledString.append(" ");
        styledString.append(Messages.bind(Messages.filterDefinitionNotFound,filter.getDefinitionId() + " ("+filter.getDefinitionVersion()+")")) ;
    }
    return styledString.toString() ;
}
 
Example 14
Source File: StyledConnectorLabelProvider.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 Connector) {
		Connector connector = (Connector) cell.getElement();
		ConnectorDefinition def = connectorDefStore.getDefinition(connector.getDefinitionId(),connector.getDefinitionVersion()) ;
		if(def == null){
			def = connectorDefStore.getDefinition(connector.getDefinitionId(),connector.getDefinitionVersion()) ;
		}
		StyledString styledString = new StyledString();

		styledString.append(getText(connector), null);
		styledString.append(" -- ",StyledString.QUALIFIER_STYLER) ;
		String connectorType = connector.getDefinitionId() +" ("+connector.getDefinitionVersion()+")";
		styledString.append(connectorType, StyledString.DECORATIONS_STYLER);
		EObject parent = connector.eContainer();
           if (!(parent instanceof Expression)) {
			if(connector.getEvent() != null && !connector.getEvent().isEmpty()){
				styledString.append(" -- ",StyledString.QUALIFIER_STYLER) ;
				styledString.append(connector.getEvent(), StyledString.COUNTER_STYLER);
			}
		}
		if(def == null){
			styledString.setStyle(0, styledString.length(), new org.eclipse.jface.viewers.StyledString.Styler() {

				@Override
				public void applyStyles(TextStyle textStyle) {
					textStyle.strikeout = true ;
				}
			}) ;
			styledString.append(" ");
			styledString.append(Messages.bind(Messages.connectorDefinitionNotFound,connector.getDefinitionId() + " ("+connector.getDefinitionVersion()+")")) ;
		}

		cell.setText(styledString.getString());
		cell.setImage(getImage(connector)) ;
		cell.setStyleRanges(styledString.getStyleRanges());
	}
}
 
Example 15
Source File: BusinessObjectDataStyledLabelProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected StyledString createStrikethroughStyle(final String initialText,
        final String businessObjectId) {
    final StyledString styledString = new StyledString(initialText);
    styledString.setStyle(0, styledString.length(), new org.eclipse.jface.viewers.StyledString.Styler() {

        @Override
        public void applyStyles(final TextStyle textStyle) {
            textStyle.strikeout = true;
        }
    });
    styledString.append(" ");
    styledString.append(Messages.bind(Messages.businessObjectNotFound, businessObjectId));
    return styledString;
}
 
Example 16
Source File: LabelStyle.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private void apply(StyledString styled, ColorStyler styler, int start, int length) {
	String s = styled.getString();
	if (start >= s.length())
		return;
	if (length < 1) {
		length = s.length();
	} else if (length > s.length() - start)
		length = s.length() - start;
	styled.setStyle(start, length, styler);
}
 
Example 17
Source File: DomainmodelLabelProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private StyledString style(String text) {
	StyledString styled = new StyledString(text);
	int offset = text.indexOf(":");
	if (offset == -1) {
		offset = text.indexOf("extends");
	}
	if (offset != -1) {
		int length = text.length();
		styled.setStyle(offset, length - offset, StyledString.DECORATIONS_STYLER);
	}
	return styled;
}