Author: vrubezhny
Date: 2009-09-17 10:57:48 -0400 (Thu, 17 Sep 2009)
New Revision: 17635
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AutoContentAssistantProposal.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditor.java
Log:
JBIDE-512 context variable code completion dropdown should show their "source"
JBIDE-2541 Show java-doc for EL content assist item
The values of type, sourceType and JavaDoc are gathered to be displayed in CA
CA shows proposals for EL in a Java-like manner
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AutoContentAssistantProposal.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AutoContentAssistantProposal.java 2009-09-17
14:37:38 UTC (rev 17634)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AutoContentAssistantProposal.java 2009-09-17
14:57:48 UTC (rev 17635)
@@ -12,8 +12,10 @@
import org.eclipse.jface.text.ITextOperationTarget;
import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.ICompletionProposalExtension6;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.viewers.StyledString;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal;
@@ -22,8 +24,10 @@
/**
* @author Igels
*/
-public class AutoContentAssistantProposal extends CustomCompletionProposal {
+public class AutoContentAssistantProposal extends CustomCompletionProposal implements
ICompletionProposalExtension6
+{
+
private boolean autoContentAssistant = false;
public AutoContentAssistantProposal(String replacementString, int replacementOffset, int
replacementLength, int cursorPosition, Image image, String displayString,
IContextInformation contextInformation, String additionalProposalInfo) {
@@ -72,4 +76,55 @@
}
return cursorPosition>-1?cursorPosition:super.getCursorPosition();
}
+
+
+ StyledString fStyledDisplayString;
+
+ public String getDisplayString() {
+ if (super.getDisplayString() != null)
+ return super.getDisplayString();
+ else {
+ if (super.getReplacementString() != null) {
+ setDisplayString(super.getReplacementString());
+ return super.getDisplayString();
+ }
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ public void setDisplayString(String string) {
+ super.setDisplayString(string);
+
+ boolean isJavaWordPart = string.length() > 0 &&
Character.isJavaIdentifierPart(string.charAt(0));
+ boolean hasRetType = isJavaWordPart && string.indexOf(':') > 0;
+ boolean hasDeclType = isJavaWordPart && string.lastIndexOf('-') >
0;
+
+ int p1i = string.indexOf(':');
+ int p2i = string.lastIndexOf('-');
+
+ String p1 = hasRetType && hasDeclType ? string.substring(0, p2i) : string;
+ String p2 = string.substring(p1.length());
+
+ StyledString styledString = new StyledString();
+
+ // name, attrs, type
+ styledString.append(p1);
+
+ // decl type
+ if (p2 != null && p2.length() > 0)
+ styledString.append(p2, StyledString.QUALIFIER_STYLER);
+ fStyledDisplayString = styledString;
+ }
+
+ public StyledString getStyledDisplayString() {
+ if (fStyledDisplayString == null) {
+ setDisplayString(super.getDisplayString()); // This re-creates Styled Display String
+ }
+ return fStyledDisplayString;
+ }
+
+ public void setStyledDisplayString(StyledString text) {
+ fStyledDisplayString = text;
+ super.setDisplayString(fStyledDisplayString == null ? "" :
fStyledDisplayString.getString());
+ }
}
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditor.java 2009-09-17
14:37:38 UTC (rev 17634)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditor.java 2009-09-17
14:57:48 UTC (rev 17635)
@@ -27,6 +27,8 @@
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.TextEvent;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
+import org.eclipse.jface.text.contentassist.IContentAssistant;
import org.eclipse.jface.text.formatter.IContentFormatter;
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
import org.eclipse.jface.text.source.IAnnotationModel;
@@ -411,6 +413,10 @@
IVerticalRuler ruler, int styles) {
ISourceViewer sv = super.createSourceViewer(parent, ruler, styles);
sv.getTextWidget().addFocusListener(new TextFocusListener());
+ IContentAssistant ca = getSourceViewerConfiguration().getContentAssistant(sv);
+ if (ca instanceof ContentAssistant) {
+ ((ContentAssistant)ca).enableColoredLabels(true);
+ }
return sv;
}