Author: vrubezhny
Date: 2008-12-03 14:16:20 -0500 (Wed, 03 Dec 2008)
New Revision: 12262
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/META-INF/MANIFEST.MF
trunk/seam/plugins/org.jboss.tools.seam.core/build.properties
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCorePlugin.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java
Log:
JBIDE-3133 New icons for proposals in JSF/Seam Code Assist.
The icons support and a set of common icons are added to the Seam CA.
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/META-INF/MANIFEST.MF 2008-12-03 19:15:48
UTC (rev 12261)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/META-INF/MANIFEST.MF 2008-12-03 19:16:20
UTC (rev 12262)
@@ -50,7 +50,8 @@
org.eclipse.emf.ecore,
org.eclipse.jst.j2ee.core,
org.eclipse.jst.jsf.facesconfig,
- org.eclipse.jst.common.frameworks
+ org.eclipse.jst.common.frameworks,
+ org.jboss.tools.common.kb;bundle-version="2.0.0"
Bundle-Version: 2.0.0
Export-Package:
org.jboss.tools.seam.core,
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/build.properties
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/build.properties 2008-12-03 19:15:48 UTC
(rev 12261)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/build.properties 2008-12-03 19:16:20 UTC
(rev 12262)
@@ -8,7 +8,8 @@
about.ini,\
about.mappings,\
about.properties,\
- seam_icon.png
+ seam_icon.png,\
+ images/
jars.compile.order = seam-core.jar
src.includes = templates/,\
src/,\
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCorePlugin.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCorePlugin.java 2008-12-03
19:15:48 UTC (rev 12261)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCorePlugin.java 2008-12-03
19:16:20 UTC (rev 12262)
@@ -12,6 +12,7 @@
import java.io.File;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import org.eclipse.core.resources.IProject;
@@ -27,6 +28,8 @@
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.jboss.tools.common.log.BaseUIPlugin;
import org.jboss.tools.common.log.IPluginLog;
import org.jboss.tools.seam.core.event.ISeamProjectChangeListener;
@@ -45,6 +48,12 @@
// The shared instance
private static SeamCorePlugin plugin;
+ // A Map to save a descriptor for each image
+ private HashMap fImageDescRegistry = null;
+
+
+ public static final String CA_SEAM_EL_IMAGE_PATH =
"images/ca/icons_Seam_EL.gif";
+ public static final String CA_SEAM_MESSAGES_IMAGE_PATH =
"images/ca/icons_Message_Bundles.gif";
/**
* The constructor
*/
@@ -216,4 +225,104 @@
}
}
+ /**
+ * Creates an image from the given resource and adds the image to the
+ * image registry.
+ *
+ * @param resource
+ * @return Image
+ */
+ private Image createImage(String resource) {
+ ImageDescriptor desc = getImageDescriptorFromRegistry(resource);
+ Image image = null;
+
+ if (desc != null) {
+ image = desc.createImage();
+ // dont add the missing image descriptor image to the image
+ // registry
+ if (!desc.equals(ImageDescriptor.getMissingImageDescriptor())) {
+ getImageRegistry().put(resource, image);
+ }
+ }
+ return image;
+ }
+
+ /**
+ * Creates an image descriptor from the given imageFilePath and adds the
+ * image descriptor to the image descriptor registry. If an image
+ * descriptor could not be created, the default "missing" image descriptor
+ * is returned but not added to the image descriptor registry.
+ *
+ * @param imageFilePath
+ * @return ImageDescriptor image descriptor for imageFilePath or default
+ * "missing" image descriptor if resource could not be found
+ */
+ private ImageDescriptor createImageDescriptor(String imageFilePath) {
+ ImageDescriptor imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID,
imageFilePath);
+ if (imageDescriptor != null) {
+ getImageDescriptorRegistry().put(imageFilePath, imageDescriptor);
+ }
+ else {
+ imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
+ }
+
+ return imageDescriptor;
+ }
+
+ /**
+ * Retrieves the image associated with resource from the image registry.
+ * If the image cannot be retrieved, attempt to find and load the image at
+ * the location specified in resource.
+ *
+ * @param resource
+ * the image to retrieve
+ * @return Image the image associated with resource or null if one could
+ * not be found
+ */
+ public Image getImage(String resource) {
+ Image image = getImageRegistry().get(resource);
+ if (image == null) {
+ // create an image
+ image = createImage(resource);
+ }
+ return image;
+ }
+
+ /**
+ * Retrieves the image descriptor associated with resource from the image
+ * descriptor registry. If the image descriptor cannot be retrieved,
+ * attempt to find and load the image descriptor at the location specified
+ * in resource.
+ *
+ * @param resource
+ * the image descriptor to retrieve
+ * @return ImageDescriptor the image descriptor assocated with resource or
+ * the default "missing" image descriptor if one could not be
+ * found
+ */
+ public ImageDescriptor getImageDescriptorFromRegistry(String resource) {
+ ImageDescriptor imageDescriptor = null;
+ Object o = getImageDescriptorRegistry().get(resource);
+ if (o == null) {
+ // create a descriptor
+ imageDescriptor = createImageDescriptor(resource);
+ }
+ else {
+ imageDescriptor = (ImageDescriptor) o;
+ }
+ return imageDescriptor;
+ }
+
+ /**
+ * Returns the image descriptor registry for this plugin.
+ *
+ * @return HashMap - image descriptor registry for this plugin
+ */
+ private HashMap getImageDescriptorRegistry() {
+ if (fImageDescRegistry == null) {
+ fImageDescRegistry = new HashMap();
+ }
+ return fImageDescRegistry;
+ }
+
}
\ No newline at end of file
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java 2008-12-03
19:15:48 UTC (rev 12261)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java 2008-12-03
19:16:20 UTC (rev 12262)
@@ -27,6 +27,7 @@
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.swt.graphics.Image;
import org.jboss.tools.common.el.core.model.ELExpression;
import org.jboss.tools.common.el.core.model.ELInstance;
import org.jboss.tools.common.el.core.model.ELInvocationExpression;
@@ -45,11 +46,15 @@
import org.jboss.tools.common.el.core.resolver.TypeInfoCollector;
import org.jboss.tools.common.el.core.resolver.Var;
import org.jboss.tools.common.el.core.resolver.TypeInfoCollector.MemberInfo;
+import org.jboss.tools.common.kb.KbProposal;
import org.jboss.tools.seam.core.ISeamComponent;
import org.jboss.tools.seam.core.ISeamContextVariable;
+import org.jboss.tools.seam.core.ISeamElement;
import org.jboss.tools.seam.core.ISeamProject;
+import org.jboss.tools.seam.core.ISeamXmlFactory;
import org.jboss.tools.seam.core.ScopeType;
import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.internal.core.SeamMessagesComponent;
import org.jboss.tools.seam.internal.core.el.SeamExpressionResolver.MessagesInfo;
/**
@@ -59,6 +64,11 @@
*/
public final class SeamELCompletionEngine implements ELCompletionEngine {
+ private static final Image SEAM_EL_PROPOSAL_IMAGE =
+ SeamCorePlugin.getDefault().getImage(SeamCorePlugin.CA_SEAM_EL_IMAGE_PATH);
+ private static final Image SEAM_MESSAGES_PROPOSAL_IMAGE =
+ SeamCorePlugin.getDefault().getImage(SeamCorePlugin.CA_SEAM_MESSAGES_IMAGE_PATH);
+
ISeamProject project;
ELParserFactory factory = ELParserUtil.getJbossFactory();
/**
@@ -72,8 +82,9 @@
return factory;
}
+
/**
- * Create the array of suggestions.
+ * Create the list of suggestions.
* @param seamProject Seam project
* @param file File
* @param documentContent
@@ -96,9 +107,9 @@
* @throws BadLocationException if accessing the current document fails
* @throws StringIndexOutOfBoundsException
*/
- public List<String> getCompletions(IFile file, IDocument document, CharSequence
prefix,
+ public List<KbProposal> getCompletions(IFile file, IDocument document,
CharSequence prefix,
int position, boolean returnEqualedVariablesOnly, List<Var> vars, int start, int
end) throws BadLocationException, StringIndexOutOfBoundsException {
- List<String> completions = new ArrayList<String>();
+ List<KbProposal> completions = new ArrayList<KbProposal>();
ELOperandResolveStatus status = resolveELOperand(file, parseOperand("" +
prefix), returnEqualedVariablesOnly, vars, new ElVarSearcher(file, this));
if (status.isOK()) {
@@ -107,7 +118,6 @@
return completions;
}
-
private static final String collectionAdditionForCollectionDataModel =
".iterator().next()";
private static final String collectionAdditionForMapDataModel =
".entrySet().iterator().next()";
@@ -194,7 +204,15 @@
}
if(!returnEqualedVariablesOnly && vars!=null) {
- status.getProposals().addAll(getVarNameProposals(vars, operand.toString()));
+ List<String> varNameProposals = getVarNameProposals(vars, operand.toString());
+ if (varNameProposals != null) {
+ for (String varNameProposal : varNameProposals) {
+ KbProposal proposal = new KbProposal();
+ proposal.setReplacementString(varNameProposal);
+ proposal.setImage(SEAM_EL_PROPOSAL_IMAGE);
+ status.getProposals().add(proposal);
+ }
+ }
}
return status;
}
@@ -326,11 +344,18 @@
// no vars are resolved
// the tokens are the part of var name ended with a separator (.)
resolvedVariables = resolveVariables(scope, expr, true,
returnEqualedVariablesOnly);
- Set<String> proposals = new
TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
+ Set<KbProposal> proposals = new
TreeSet<KbProposal>(KbProposal.KB_PROPOSAL_ORDER);
for (ISeamContextVariable var : resolvedVariables) {
String varName = var.getName();
if(varName.startsWith(operand.getText())) {
- proposals.add(varName.substring(operand.getLength()));
+ KbProposal proposal = new KbProposal();
+ proposal.setReplacementString(varName.substring(operand.getLength()));
+ if (isSeamMessagesComponentVariable(var)) {
+ proposal.setImage(SEAM_MESSAGES_PROPOSAL_IMAGE);
+ } else {
+ proposal.setImage(SEAM_EL_PROPOSAL_IMAGE);
+ }
+ proposals.add(proposal);
}
}
status.setProposals(proposals);
@@ -341,13 +366,27 @@
// OK. we'll proceed with members of these vars
if (status.getResolvedTokens() == status.getTokens()) {
// First segment is the last one
- Set<String> proposals = new
TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
+ Set<KbProposal> proposals = new
TreeSet<KbProposal>(KbProposal.KB_PROPOSAL_ORDER);
for (ISeamContextVariable var : resolvedVariables) {
String varName = var.getName();
if(operand.getLength()<=varName.length()) {
- proposals.add(varName.substring(operand.getLength()));
+ KbProposal proposal = new KbProposal();
+ proposal.setReplacementString(varName.substring(operand.getLength()));
+ if (isSeamMessagesComponentVariable(var)) {
+ proposal.setImage(SEAM_MESSAGES_PROPOSAL_IMAGE);
+ } else {
+ proposal.setImage(SEAM_EL_PROPOSAL_IMAGE);
+ }
+ proposals.add(proposal);
} else if(returnEqualedVariablesOnly) {
- proposals.add(varName);
+ KbProposal proposal = new KbProposal();
+ proposal.setReplacementString(varName);
+ if (isSeamMessagesComponentVariable(var)) {
+ proposal.setImage(SEAM_MESSAGES_PROPOSAL_IMAGE);
+ } else {
+ proposal.setImage(SEAM_EL_PROPOSAL_IMAGE);
+ }
+ proposals.add(proposal);
}
status.setMemberOfResolvedOperand(SeamExpressionResolver.getMemberInfoByVariable(var,
true));
}
@@ -444,7 +483,8 @@
List<TypeInfoCollector.MemberInfo> members,
ELOperandResolveStatus status,
boolean returnEqualedVariablesOnly, boolean varIsUsed) {
- Set<String> proposals = new
TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
+ Set<KbProposal> kbProposals = new
TreeSet<KbProposal>(KbProposal.KB_PROPOSAL_ORDER);
+
if (expr.getType() == ELObjectType.EL_PROPERTY_INVOCATION &&
((ELPropertyInvocation)expr).getName() == null) {
// return all the methods + properties
for (TypeInfoCollector.MemberInfo mbr : members) {
@@ -458,9 +498,17 @@
if (key == null || key.length() == 0)
continue;
if (key.indexOf('.') != -1) {
- proposals.add("['" + key + "']");
+ KbProposal proposal = new KbProposal();
+ proposal.setReplacementString("['" + key + "']");
+ proposal.setImage(SEAM_MESSAGES_PROPOSAL_IMAGE);
+
+ kbProposals.add(proposal);
} else {
- proposals.add(key);
+ KbProposal proposal = new KbProposal();
+ proposal.setReplacementString(key);
+ proposal.setImage(SEAM_MESSAGES_PROPOSAL_IMAGE);
+
+ kbProposals.add(proposal);
}
}
continue;
@@ -472,8 +520,29 @@
if (TypeInfoCollector.isNotParameterizedCollection(mbr) ||
TypeInfoCollector.isResourceBundle(mbr.getMemberType())) {
status.setMapOrCollectionOrBundleAmoungTheTokens();
}
- proposals.addAll(infos.getMethodPresentationStrings());
- proposals.addAll(infos.getPropertyPresentationStrings(status.getUnpairedGettersOrSetters()));
+
+ Set<String> methodPresentations =
+ infos.getMethodPresentationStrings();
+ if (methodPresentations != null) {
+ for (String presentation : methodPresentations) {
+ KbProposal proposal = new KbProposal();
+ proposal.setReplacementString(presentation);
+ proposal.setImage(SEAM_EL_PROPOSAL_IMAGE);
+
+ kbProposals.add(proposal);
+ }
+ }
+ Set<String> propertyPresentations =
+ infos.getPropertyPresentationStrings(status.getUnpairedGettersOrSetters());
+ if (propertyPresentations != null) {
+ for (String presentation : propertyPresentations) {
+ KbProposal proposal = new KbProposal();
+ proposal.setReplacementString(presentation);
+ proposal.setImage(SEAM_EL_PROPOSAL_IMAGE);
+
+ kbProposals.add(proposal);
+ }
+ }
}
} else
if(expr.getType() != ELObjectType.EL_ARGUMENT_INVOCATION)
@@ -508,7 +577,17 @@
if(returnEqualedVariablesOnly) {
// This is used for validation.
if (proposal.getPresentation().equals(filter)) {
- proposals.add(proposal.getPresentation());
+ KbProposal kbProposal = new KbProposal();
+ kbProposal.setReplacementString(proposal.getPresentation());
+
+ if (proposal.getMember() instanceof MessagesInfo) {
+ kbProposal.setImage(SEAM_MESSAGES_PROPOSAL_IMAGE);
+ } else {
+ kbProposal.setImage(SEAM_EL_PROPOSAL_IMAGE);
+ }
+
+ kbProposals.add(kbProposal);
+
status.setMemberOfResolvedOperand(proposal.getMember());
if(status.getUnpairedGettersOrSetters()!=null) {
TypeInfoCollector.MethodInfo unpirMethod =
status.getUnpairedGettersOrSetters().get(filter);
@@ -521,11 +600,15 @@
}
} else if (proposal.getPresentation().startsWith(filter)) {
// This is used for CA.
- proposals.add(proposal.getPresentation().substring(filter.length()));
+ KbProposal kbProposal = new KbProposal();
+ kbProposal.setReplacementString(proposal.getPresentation().substring(filter.length()));
+ kbProposal.setImage(SEAM_EL_PROPOSAL_IMAGE);
+
+ kbProposals.add(kbProposal);
}
}
}
- status.setProposals(proposals);
+ status.setProposals(kbProposals);
if (status.isOK()){
status.setLastResolvedToken(expr);
}
@@ -616,16 +699,16 @@
* @param suggestions a list of suggestions ({@link String}).
* @return a list of unique completion suggestions.
*/
- public List<String> makeUnique(List<String> suggestions) {
+ public List<KbProposal> makeKbUnique(List<KbProposal> suggestions) {
HashSet<String> present = new HashSet<String>();
- ArrayList<String> unique= new ArrayList<String>();
+ ArrayList<KbProposal> unique= new ArrayList<KbProposal>();
if (suggestions == null)
return unique;
- for (String item : suggestions) {
- if (!present.contains(item)) {
- present.add(item);
+ for (KbProposal item : suggestions) {
+ if (!present.contains(item.getReplacementString())) {
+ present.add(item.getReplacementString());
unique.add(item);
}
}
@@ -843,4 +926,33 @@
return content.length();
}
+ public static boolean isSeamMessagesComponentVariable(ISeamContextVariable variable) {
+ if (variable instanceof SeamMessagesComponent) {
+ return true;
+ } else if (variable instanceof ISeamXmlFactory) {
+ ISeamXmlFactory factory = (ISeamXmlFactory)variable;
+ String value = factory.getValue();
+ if (value != null && value.length() > 0) {
+ if (value.startsWith("#{") || value.startsWith("${"))
//$NON-NLS-1$ //$NON-NLS-2$
+ value = value.substring(2);
+ if (value.endsWith("}")) //$NON-NLS-1$
+ value = value.substring(0, value.length() - 1);
+ }
+ if (value != null && value.length() > 0) {
+ ISeamProject p = ((ISeamElement)factory).getSeamProject();
+ if (p != null) {
+ List<ISeamContextVariable> resolvedValues =
SeamExpressionResolver.resolveVariables(p, null, value, true);
+ for (ISeamContextVariable var : resolvedValues) {
+ if (var.getName().equals(value)) {
+ if (var instanceof SeamMessagesComponent) {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
}