Added colors to the 'Outline View' labels for Properties and Literals.
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/labeling/Labels.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/labeling/Labels.java index 90ccad9..db89fd2 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/labeling/Labels.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/labeling/Labels.java
@@ -9,11 +9,13 @@ package com.google.eclipse.protobuf.ui.labeling; import static com.google.eclipse.protobuf.scoping.ImportUriFixerAndResolver.URI_PREFIX; +import static org.eclipse.jface.viewers.StyledString.DECORATIONS_STYLER; + +import org.eclipse.jface.viewers.StyledString; import com.google.eclipse.protobuf.protobuf.*; import com.google.eclipse.protobuf.ui.util.Properties; -import com.google.inject.Inject; -import com.google.inject.Singleton; +import com.google.inject.*; /** * Registry of commonly used text in the 'Protocol Buffer' editor. @@ -25,10 +27,7 @@ @Inject private Properties properties; - private static final String LITERAL_FORMAT = "%s [%d]"; - private static final String PROPERTY_FORMAT = "%s [%d] : %s"; - - public String labelFor(Object o) { + public Object labelFor(Object o) { if (o instanceof Import) { Import i = (Import) o; return labelFor(i); @@ -48,21 +47,27 @@ return null; } - private String labelFor(Import i) { + private Object labelFor(Import i) { String uri = i.getImportURI(); if (uri == null || !uri.startsWith(URI_PREFIX)) return uri; return uri.substring(URI_PREFIX.length()); } - private String labelFor(Literal l) { - return String.format(LITERAL_FORMAT, l.getName(), l.getIndex()); + private Object labelFor(Literal l) { + StyledString text = new StyledString(l.getName()); + String index = String.format(" [%d]", l.getIndex()); + text.append(index, DECORATIONS_STYLER); + return text; } - private String labelFor(Property p) { - return String.format(PROPERTY_FORMAT, p.getName(), p.getIndex(), properties.typeNameOf(p)); + private Object labelFor(Property p) { + StyledString text = new StyledString(p.getName()); + String indexAndType = String.format(" [%d] : %s", p.getIndex(), properties.typeNameOf(p)); + text.append(indexAndType, DECORATIONS_STYLER); + return text; } - private String labelFor(Protobuf p) { + private Object labelFor(Protobuf p) { // TODO show this text till I figure out how to hide 'Protobuf' node in outline view return "Protocol Buffer"; }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/labeling/ProtobufLabelProvider.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/labeling/ProtobufLabelProvider.java index 71423d3..9ae89f9 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/labeling/ProtobufLabelProvider.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/labeling/ProtobufLabelProvider.java
@@ -30,7 +30,7 @@ } @Override public Object text(Object o) { - String text = labels.labelFor(o); + Object text = labels.labelFor(o); return (text != null) ? text : super.text(o); }