package com.framsticks.framclipse.ui.contentassist; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import org.eclipse.jface.viewers.StyledString; import org.eclipse.jface.viewers.StyledString.Styler; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.TextStyle; import org.eclipse.swt.widgets.Display; public class HTMLDescriptorProvider implements DescriptorProvider { private static final Styler LEFT_STYLER = new ColorStyler(SWT.COLOR_BLACK); private static final Styler RIGHT_STYLER = new ColorStyler(SWT.COLOR_DARK_GRAY); private static final String INDENT = "
			
"; @Override public StyledString display(String string) { int pointcut = string.indexOf(':'); if (pointcut < 0) { return new StyledString(string, LEFT_STYLER); } else { StyledString display = new StyledString(string.substring(0, pointcut), LEFT_STYLER); display.append(string.substring(pointcut, string.length()), RIGHT_STYLER); return display; } } @Override public String description(Map description) { StringBuilder builder = new StringBuilder(); Set> set = description.entrySet(); for (Entry entry : set) { builder.append(wrap(entry.getKey(), entry.getValue())); } return builder.toString(); } private String wrap(String name, String content) { if (name != null && content != null && content.length() > 0) { String[] split = content.split("\n"); return "" + name + ":
" + indent(split); } else { return ""; } } private String indent(String... content) { StringBuilder builder = new StringBuilder(); for (String string : content) { builder.append(INDENT).append(string).append("
"); } return builder.toString(); } private static class ColorStyler extends Styler { private final int color; public ColorStyler(int color) { this.color = color; } @Override public void applyStyles(TextStyle textStyle) { textStyle.foreground = Display.getCurrent().getSystemColor(color); } } }