Java Code Examples for org.eclipse.jface.viewers.StyledString.Styler

The following examples show how to use org.eclipse.jface.viewers.StyledString.Styler. These examples are extracted from open source projects. 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 Project: n4js   Source File: N4JSProjectExplorerHelper.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @return a styled string for a given external project. Respects name, type, version, and information about
 *         shadowing and whether it is available in the xtext index
 */
public StyledString getStyledTextForExternalProject(final IN4JSProject project,
		N4JSProjectName overrideProjectName) {
	N4JSProjectName name = (overrideProjectName == null) ? project.getProjectName() : overrideProjectName;
	ProjectType type = project.getProjectType();
	// for better visual representation MyProject @1.2.3 -> MyProject v1.2.3
	String version = SemverSerializer.serialize(project.getVersion()).replaceFirst("@", "v");
	String typeLabel = getProjectTypeLabel(type);
	boolean inIndex = project.isExternal()
			&& indexSynchronizer.isInIndex((FileURI) project.getProjectDescriptionLocation());
	String rootLocationName = getRootLocationName(project);

	Styler stylerName = inIndex ? null : StyledString.QUALIFIER_STYLER;
	Styler stylerType = inIndex ? StyledString.DECORATIONS_STYLER : StyledString.QUALIFIER_STYLER;
	StyledString string = new StyledString(name + " " + version, stylerName);
	string.append(typeLabel, stylerType);
	if (rootLocationName != null) {
		string.append(rootLocationName, StyledString.COUNTER_STYLER);
	}
	return string;
}
 
Example 2
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 3
@Override
public StyledString getStyledText(Object element) {
	if (isNormalMethodWrapper(element)) {
		MethodWrapper wrapper= (MethodWrapper)element;
		String decorated= getElementLabel(wrapper);
		
		StyledString styledLabel= super.getStyledText(wrapper.getMember());
		StyledString styledDecorated= StyledCellLabelProvider.styleDecoratedString(decorated, StyledString.COUNTER_STYLER, styledLabel);
		if (isSpecialConstructorNode(wrapper)) {
			decorated= Messages.format(CallHierarchyMessages.CallHierarchyLabelProvider_constructor_label, decorated);
			styledDecorated= StyledCellLabelProvider.styleDecoratedString(decorated, ColoringLabelProvider.INHERITED_STYLER, styledDecorated);
		}
		return styledDecorated;
	}
	
	String specialLabel= getSpecialLabel(element);
	Styler styler= element instanceof RealCallers ? ColoringLabelProvider.INHERITED_STYLER : null;
	return new StyledString(specialLabel, styler);
}
 
Example 4
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 5
/**
 * The default implementation of this returns the styled text label for the given element.
 * @param element
 *            the element to evaluate the styled string for
 * @return the styled string.
 * @since 3.7
 */
public StyledString getStyledText(Object element) {
	IWorkbenchAdapter3 adapter = getAdapter3(element);
	if (adapter == null) {
		// If adapter class doesn't implement IWorkbenchAdapter3 than use
		// StyledString with text of element. Since the output of getText is
		// already decorated, so we don't need to call decorateText again
		// here.
		return new StyledString(getText(element));
	}
	StyledString styledString = adapter.getStyledText(element);
	// Now, re-use any existing decorateText implementation, to decorate
	// this styledString.
	String decorated = decorateText(styledString.getString(), element);
	Styler styler = getDecorationStyle(element);
	return StyledCellLabelProvider.styleDecoratedString(decorated, styler, styledString);
}
 
Example 6
/**
 * The default implementation of this returns the styled text label for the given element.
 * @param element
 *            the element to evaluate the styled string for
 * @return the styled string.
 * @since 3.7
 */
public StyledString getStyledText(Object element) {
	IWorkbenchAdapter3 adapter = getAdapter3(element);
	if (adapter == null) {
		// If adapter class doesn't implement IWorkbenchAdapter3 than use
		// StyledString with text of element. Since the output of getText is
		// already decorated, so we don't need to call decorateText again
		// here.
		return new StyledString(getText(element));
	}
	StyledString styledString = adapter.getStyledText(element);
	// Now, re-use any existing decorateText implementation, to decorate
	// this styledString.
	String decorated = decorateText(styledString.getString(), element);
	Styler styler = getDecorationStyle(element);
	return StyledCellLabelProvider.styleDecoratedString(decorated, styler, styledString);
}
 
Example 7
Source Project: Pydev   Source File: HierarchyLabelProvider.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public StyledString getStyledText(Object element) {
    if (element instanceof DataAndImageTreeNode) {
        @SuppressWarnings("rawtypes")
        DataAndImageTreeNode treeNode = (DataAndImageTreeNode) element;
        Object data = treeNode.data;
        if (data instanceof HierarchyNodeModel) {
            HierarchyNodeModel model = (HierarchyNodeModel) data;
            String spaces = "     ";
            StyledString styledString = new StyledString(model.name + spaces);
            if (model.moduleName != null && model.moduleName.trim().length() > 0) {
                Styler styler = StyledString.createColorRegistryStyler(JFacePreferences.DECORATIONS_COLOR, null);
                styledString.append("(" + model.moduleName + ")", styler);
            }
            return styledString;
        }
        return new StyledString(data.toString());
    }
    return new StyledString(element == null ? "" : element.toString());
}
 
Example 8
@Override
public StyledString getStyledText(final Object element) {
	if (element instanceof WorkingSet) {
		return WorkingSetLabelProvider.INSTANCE.getStyledText(element);
	}

	if (element instanceof IFolder) {
		IFolder folder = (IFolder) element;
		N4JSExternalProject npmProject = helper.getNodeModulesNpmProjectOrNull(folder);
		if (npmProject != null) {
			IN4JSProject iNpmProject = npmProject.getIProject();
			return helper.getStyledTextForExternalProject(iNpmProject, new N4JSProjectName(folder.getName()));

		} else if (Files.isSymbolicLink(folder.getLocation().toFile().toPath())) {
			// might be a project from workspace
			N4JSProjectName n4jsProjectName = new PlatformResourceURI(folder).getProjectName();
			String eclipseProjectName = n4jsProjectName.toEclipseProjectName().getRawName();

			IProject iProject = ResourcesPlugin.getWorkspace().getRoot().getProject(eclipseProjectName);
			if (iProject != null && iProject.exists()) {

				Styler stylerName = StyledString.QUALIFIER_STYLER;
				if (iProject.isAccessible()) {
					IN4JSEclipseProject n4jsProject = n4jsCore.create(iProject).orNull();
					if (n4jsProject.isExternal()) {
						stylerName = null;
					}
				}
				StyledString string = new StyledString(folder.getName(), stylerName);
				return string;
			}
		}

		return new StyledString(folder.getName());
	}

	return workbenchLabelProvider.getStyledText(element);

}
 
Example 9
Source Project: neoscada   Source File: BlockControlImage.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public BlockControlImage ( final ControlImage controlImage, final int style, final RegistrationManager registrationManager )
{
    super ( controlImage.getClientSpace (), style );

    this.controlImage = controlImage;

    this.registrationManager = registrationManager;

    setLayout ( new FillLayout () );

    this.icon = new Label ( this, SWT.NONE );
    this.icon.setImage ( getEmptyImage () );
    this.icon.addMouseListener ( new MouseAdapter () {
        @Override
        public void mouseUp ( final MouseEvent e )
        {
            toggleBlock ();
        }
    } );

    this.registrationManager.addListener ( this );

    final LocalResourceManager resources = new LocalResourceManager ( JFaceResources.getResources (), this.icon );

    this.boldFont = resources.createFont ( JFaceResources.getDefaultFontDescriptor ().withStyle ( SWT.BOLD ) );
    this.boldStyler = new Styler () {

        @Override
        public void applyStyles ( final TextStyle textStyle )
        {
            textStyle.font = BlockControlImage.this.boldFont;
        }
    };
}
 
Example 10
Source Project: xtext-eclipse   Source File: XtextLabelProvider.java    License: Eclipse Public License 2.0 5 votes vote down vote up
StyledString text(ParserRule parserRule) {
	if (GrammarUtil.isDatatypeRule(parserRule)) {
		Styler xtextStyleAdapterStyler = stylerFactory.createXtextStyleAdapterStyler(semanticHighlightingConfiguration
				.dataTypeRule());
		return new StyledString(parserRule.getName(), xtextStyleAdapterStyler);
	}
	return convertToStyledString(parserRule.getName());
}
 
Example 11
Source Project: xds-ide   Source File: ModulaSearchLabelProvider.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public M2LabelProvider(ModulaSearchResultPage resultPage, ResourceRegistry resourceRegistry) {
    this.resultPage = resultPage;
    this.resourceRegistry = resourceRegistry;
    this.dlgFont = resultPage.getControl().getFont();
    fLabelProvider= new WorkbenchLabelProvider();
    positionStyler = new Styler() {
        @Override
        public void applyStyles(TextStyle textStyle) {
            textStyle.foreground = JFaceResources.getColorRegistry().get(JFacePreferences.QUALIFIER_COLOR);
            textStyle.font= getItalicFont(dlgFont);
        }
    };
}
 
Example 12
public StyledDecoratingLabelProvider(ILabelProvider provider, ILabelDecorator decorator) {
    super(provider, decorator);
    boldStyler = new Styler() {
        @Override
        public void applyStyles(TextStyle textStyle) {
            textStyle.font= getBoldFont();
        }
    };
}
 
Example 13
Source Project: tracecompass   Source File: TmfAnalysisElement.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Styler getStyler() {
    if (!canExecute()) {
        return ANALYSIS_CANT_EXECUTE_STYLER;
    }
    return null;
}
 
Example 14
@Override
public @Nullable Styler getStyler() {
    if (!fCanRun) {
        return STRIKED_OUT_STYLER;
    }
    return null;
}
 
Example 15
private Styler getStyler()
{
	if (textFontStyler == null)
	{
		textFontStyler = new TextFontStyler();
	}
	return textFontStyler;
}
 
Example 16
private Styler createBoldStyler() {
	return new Styler() {
		@Override
		public void applyStyles(TextStyle textStyle) {
			textStyle.font= getBoldFont();
		}
	};
}
 
Example 17
private Styler createBoldQualifierStyler() {
	return new Styler() {
		@Override
		public void applyStyles(TextStyle textStyle) {
			StyledString.QUALIFIER_STYLER.applyStyles(textStyle);
			textStyle.font= getBoldFont();
		}
	};
}
 
Example 18
Source Project: sarl   Source File: SARLUIStrings.java    License: Apache License 2.0 5 votes vote down vote up
/** Format the parameters.
 *
 * @param elements the list of the formal parameters.
 * @param isVarArgs indicates if the function has var args.
 * @param includeName indicates if the names are included in the replied valued.
 * @param keywords the keyword provider.
 * @param annotationFinder the finder of attached annotations.
 * @param utils the utility.
 * @return the string representation of the parameters.
 * @since 0.6
 */
public static StyledString getParameterStyledString(Iterable<? extends JvmFormalParameter> elements, boolean isVarArgs,
		boolean includeName, SARLGrammarKeywordAccess keywords, AnnotationLookup annotationFinder, UIStrings utils) {
	final StyledString result = new StyledString();
	boolean needsSeparator = false;
	final Iterator<? extends JvmFormalParameter> iterator = elements.iterator();
	while (iterator.hasNext()) {
		final JvmFormalParameter parameter = iterator.next();
		if (needsSeparator) {
			result.append(keywords.getCommaKeyword()).append(" "); //$NON-NLS-1$
		}
		needsSeparator = true;
		final boolean isDefaultValued = annotationFinder.findAnnotation(parameter, DefaultValue.class) != null;
		final Styler styler;
		if (isDefaultValued) {
			styler = OPTIONAL_ELEMENT_STYLER;
			result.append(keywords.getLeftSquareBracketKeyword(), styler);
		} else {
			styler = null;
		}
		if (includeName) {
			result.append(parameter.getName(), styler).append(" ", styler);  //$NON-NLS-1$
			result.append(keywords.getColonKeyword(), styler).append(" ", styler); //$NON-NLS-1$
		}
		JvmTypeReference typeRef = parameter.getParameterType();
		if (isVarArgs && !iterator.hasNext() && typeRef instanceof JvmGenericArrayTypeReference) {
			typeRef = ((JvmGenericArrayTypeReference) typeRef).getComponentType();
			result.append(utils.referenceToString(typeRef, NULL_TYPE), styler);
			result.append(keywords.getWildcardAsteriskKeyword(), styler);
		} else {
			result.append(utils.referenceToString(typeRef, NULL_TYPE), styler);
		}
		if (isDefaultValued) {
			result.append(keywords.getRightSquareBracketKeyword(), styler);
		}
	}
	return result;
}
 
Example 19
Source Project: bonita-studio   Source File: StylerBuilder.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Styler create() {
    return new Styler() {

        @Override
        public void applyStyles(TextStyle textStyle) {
            color.ifPresent(c -> textStyle.foreground = c);
            font.ifPresent(f -> textStyle.font = f);
        }
    };
}
 
Example 20
public DatabaseDriversLabelProvider(){
	super();
	boldgreen = new StyledString.Styler(){

		@Override
		public void applyStyles(TextStyle textStyle) {
			textStyle.font = BonitaStudioFontRegistry.getActiveFont();
			textStyle.foreground = Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GREEN);
		}
	};
}
 
Example 21
private void initStyle() {
	imageProvider = new AdapterFactoryLabelProvider(new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE)) ;
	italicGrey = new StyledString.Styler() {
		@Override
		public void applyStyles(TextStyle textStyle) {
			textStyle.font = BonitaStudioFontRegistry.getTransientDataFont();
			textStyle.foreground = JFaceResources.getColorRegistry().get(JFacePreferences.QUALIFIER_COLOR);
		}
	};
}
 
Example 22
Source Project: xtext-eclipse   Source File: StylerFactory.java    License: Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @return {@link DefaultFontStyler}
 */
public Styler createStyler(String foregroundColorName, String backgroundColorName) {
	return new DefaultFontStyler(null, foregroundColorName, backgroundColorName);
}
 
Example 23
protected Styler getStyleForQualifiedNamePart(Type type) {
	return new GreyoutStyler();
}
 
Example 24
protected Styler getStyleForSimpleNamePart(Type type) {
	if (isUnknownType(type)) {
		return new StrikeThroughStyler();
	}
	return null;
}
 
Example 25
public Styler getTagStyler() {
    return TAG_STYLER;
}
 
Example 26
public Styler getTextStyler() {
    return TEXT_STYLER;
}
 
Example 27
void setStyler(Styler styler)
{
	this.styler = styler;
}
 
Example 28
@Override
public void setStyle(int offset, int length, Styler styler) {
	// no style
}
 
Example 29
@Override
public void setStyle(int offset, int length, Styler styler) {
	fStyledString.setStyle(offset, length, styler);
}
 
Example 30
Source Project: goclipse   Source File: StylerHelpers.java    License: Eclipse Public License 1.0 4 votes vote down vote up
public FontStyler(Styler parentStyler) {
	this.parentStyler = parentStyler;
}