Author: akazakov
Date: 2011-05-24 20:07:18 -0400 (Tue, 24 May 2011)
New Revision: 31466
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/proposal/ResourcePathProposalType.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/taglibs/Ajax4jsf.xml
trunk/jst/plugins/org.jboss.tools.jst.web.kb/taglibs/FaceletsHtml.xml
trunk/jst/plugins/org.jboss.tools.jst.web.kb/taglibs/JsfHtmlBasic.xml
trunk/jst/tests/org.jboss.tools.jst.web.kb.test/src/org/jboss/tools/jst/web/kb/test/WebKbTest.java
Log:
https://issues.jboss.org/browse/JBIDE-8953
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/proposal/ResourcePathProposalType.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/proposal/ResourcePathProposalType.java 2011-05-24
22:40:51 UTC (rev 31465)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/proposal/ResourcePathProposalType.java 2011-05-25
00:07:18 UTC (rev 31466)
@@ -41,6 +41,7 @@
private static Image ICON;
private static Set<String> GRAPHIC_FILE_EXTENSIONS = new HashSet<String>();
private static Set<String> PAGE_FILE_EXTENSIONS = new HashSet<String>();
+ private static Set<String> CSS_FILE_EXTENSIONS = new HashSet<String>();
static {
String[] images = {"gif", "jpeg", "jpg", "png",
"wbmp", "bmp"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
for (int i = 0; i < images.length; i++) {
@@ -50,11 +51,16 @@
for (int i = 0; i < pages.length; i++) {
PAGE_FILE_EXTENSIONS.add(pages[i]);
}
+ String[] css = {"css", "xcss"}; //$NON-NLS-1$ //$NON-NLS-2$
+ for (int i = 0; i < css.length; i++) {
+ CSS_FILE_EXTENSIONS.add(css[i]);
+ }
}
private static String PATH_ADDITION = "pathAddition"; //$NON-NLS-1$
private IContainer webRootResource;
- private Set<String> extensions;
+ private Set<String> extensions = new HashSet<String>();
+ private String optionalPrefix;
private List<String> enumeration;
/* (non-Javadoc)
@@ -71,9 +77,9 @@
webRootResource = (IContainer)EclipseResourceUtil.getResource(webRoot);
}
}
- if(extensions==null) {
+// if(extensions==null) {
initExtensions();
- }
+// }
if(enumeration==null) {
enumeration = new ArrayList<String>();
if(params!=null) {
@@ -95,12 +101,27 @@
return EMPTY_PROPOSAL_LIST;
}
List<TextProposal> proposals = new ArrayList<TextProposal>();
- ImagePathDescriptor[] images = getImagesFilesPathes(query.getValue());
- for(int i=0; i<images.length; i++) {
+ String newValue = null;
+ String value = query.getValue();
+ if(optionalPrefix!=null) {
+ char[] optionalPrefixArray = optionalPrefix.toCharArray();
+ StringBuffer prefix = new StringBuffer();
+ for (char c : optionalPrefixArray) {
+ prefix.append(c);
+ if(value.startsWith(prefix.toString())) {
+ newValue = value.substring(prefix.length());
+ }
+ }
+ }
+ if(newValue==null) {
+ newValue = value;
+ }
+ ResourcePathDescriptor[] resources = getResourcePathes(newValue);
+ for(int i=0; i<resources.length; i++) {
TextProposal proposal = new TextProposal();
- proposal.setLabel(images[i].getQueryPath());
- String replacementString = images[i].getQueryPath();
- if(images[i].getResource() instanceof IFolder) {
+ proposal.setLabel(resources[i].getQueryPath());
+ String replacementString = resources[i].getQueryPath();
+ if(resources[i].getResource() instanceof IFolder) {
replacementString = replacementString + "/"; //$NON-NLS-1$
proposal.setAutoActivationContentAssistantAfterApplication(true);
}
@@ -110,7 +131,20 @@
ICON = ImageDescriptor.createFromFile(WebKbPlugin.class, IMAGE_NAME).createImage();
}
proposal.setImage(ICON);
- proposals.add(proposal);
+ if(newValue == value) {
+ proposals.add(proposal);
+ }
+ if(optionalPrefix!=null) {
+ try {
+ TextProposal clone = proposal.clone();
+ clone.setLabel(optionalPrefix + proposal.getLabel());
+ clone.setReplacementString(optionalPrefix + proposal.getReplacementString());
+ clone.setPosition(clone.getReplacementString().length());
+ proposals.add(clone);
+ } catch (CloneNotSupportedException e) {
+ WebKbPlugin.getDefault().logError(e);
+ }
+ }
}
for (String path : enumeration) {
TextProposal proposal = new TextProposal();
@@ -131,18 +165,22 @@
private static final String EXTENSIONS_PARAM_NAME = "extensions";
//$NON-NLS-1$
private static final String IMAGE_PARAM_TYPE = "%image%"; //$NON-NLS-1$
private static final String PAGE_PARAM_TYPE = "%page%"; //$NON-NLS-1$
+ private static final String CSS_PARAM_TYPE = "%css%"; //$NON-NLS-1$
+ private static final String OPTIONAL_PREFIX = "optionalPrefix"; //$NON-NLS-1$
private void initExtensions() {
+ extensions.clear();
String value = getParamValue(EXTENSIONS_PARAM_NAME);
if(value != null && !value.equals("*")) { //$NON-NLS-1$
if(IMAGE_PARAM_TYPE.equals(value)) {
- this.extensions = GRAPHIC_FILE_EXTENSIONS;
- } else if("%page%".equals(value)) { //$NON-NLS-1$
- this.extensions = PAGE_FILE_EXTENSIONS;
+ this.extensions.addAll(GRAPHIC_FILE_EXTENSIONS);
+ } else if(PAGE_PARAM_TYPE.equals(value)) {
+ this.extensions.addAll(PAGE_FILE_EXTENSIONS);
+ } else if(CSS_PARAM_TYPE.equals(value)) {
+ this.extensions.addAll(CSS_FILE_EXTENSIONS);
} else {
StringTokenizer st = new StringTokenizer(value, ",;"); //$NON-NLS-1$
if(st.countTokens() > 0) {
- extensions = new HashSet<String>();
while(st.hasMoreTokens()) {
String t = st.nextToken().trim();
if(t.length() == 0) {
@@ -152,6 +190,8 @@
extensions.addAll(GRAPHIC_FILE_EXTENSIONS);
} else if(PAGE_PARAM_TYPE.equals(t)) {
extensions.addAll(PAGE_FILE_EXTENSIONS);
+ } else if(CSS_PARAM_TYPE.equals(t)) {
+ extensions.addAll(CSS_FILE_EXTENSIONS);
} else {
extensions.add(t);
}
@@ -159,6 +199,10 @@
}
}
}
+ optionalPrefix = getParamValue(OPTIONAL_PREFIX);
+ if(optionalPrefix!=null && optionalPrefix.trim().length()==0) {
+ optionalPrefix = null;
+ }
}
/*
@@ -169,10 +213,10 @@
return webRootResource!=null;
}
- private ImagePathDescriptor[] getImagesFilesPathes(String query) {
+ private ResourcePathDescriptor[] getResourcePathes(String query) {
query = query.trim();
if(query.indexOf('\\')>-1) {
- return new ImagePathDescriptor[0];
+ return new ResourcePathDescriptor[0];
}
if(query.length()==0) {
query = "/"; //$NON-NLS-1$
@@ -203,9 +247,6 @@
}
name = ""; //$NON-NLS-1$
}
- if(name==null) {
- name = ""; //$NON-NLS-1$
- }
IResource resource;
String startPath = pathWithoutLastSegment;
if(pathWithoutLastSegment.startsWith("/")) { //$NON-NLS-1$
@@ -223,27 +264,27 @@
List<IResource> resources = new ArrayList<IResource>();
try {
- if(resource != null) resource.accept(new ImagesFinder(resources, name, extensions));
+ if(resource != null) resource.accept(new ResourceFinder(resources, name,
extensions));
} catch (CoreException e) {
WebKbPlugin.getDefault().logError(e);
}
- ImagePathDescriptor[] filesPathes = new ImagePathDescriptor[resources.size()];
+ ResourcePathDescriptor[] filesPathes = new ResourcePathDescriptor[resources.size()];
for(int i=0; i<filesPathes.length; i++) {
String prefix = pathWithoutLastSegment.toString();
if(!prefix.endsWith("/")) { //$NON-NLS-1$
prefix = prefix + '/';
}
IResource r = (IResource)resources.get(i);
- filesPathes[i] = new ImagePathDescriptor(prefix + r.getName(), r);
+ filesPathes[i] = new ResourcePathDescriptor(prefix + r.getName(), r);
}
return filesPathes;
}
- private static class ImagePathDescriptor {
+ private static class ResourcePathDescriptor {
private String queryPath;
private IResource resource;
- public ImagePathDescriptor(String queryPath, IResource resource) {
+ public ResourcePathDescriptor(String queryPath, IResource resource) {
this.queryPath = queryPath;
this.resource = resource;
}
@@ -257,18 +298,18 @@
}
}
- private static class ImagesFinder implements IResourceVisitor {
+ private static class ResourceFinder implements IResourceVisitor {
private List<IResource> resources;
private int count = 0;
private String name;
- Set<String> extensions = null;
+ Set<String> extensions;
/**
* @param resources
* @param name
* @param extensions
*/
- public ImagesFinder(List<IResource> resources, String name, Set<String>
extensions) {
+ public ResourceFinder(List<IResource> resources, String name, Set<String>
extensions) {
this.resources = resources;
this.name = name;
this.extensions = extensions;
@@ -278,7 +319,7 @@
if(ext != null) {
ext = ext.toLowerCase();
}
- return (extensions == null || extensions.contains(ext));
+ return extensions == null || extensions.isEmpty() || extensions.contains(ext);
}
public boolean visit(IResource resource) throws CoreException {
Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/taglibs/Ajax4jsf.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/taglibs/Ajax4jsf.xml 2011-05-24 22:40:51
UTC (rev 31465)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/taglibs/Ajax4jsf.xml 2011-05-25 00:07:18
UTC (rev 31466)
@@ -162,7 +162,12 @@
<param value="speech" />
</proposal>
</attribute>
- <attribute name="src" required="true" />
+ <attribute name="src" required="true" >
+ <proposal type="file">
+ <param name="extensions" value="%css%"/>
+ <param name="optionalPrefix" value="resource://"/>
+ </proposal>
+ </attribute>
</component>
<component name="log">
<attribute name="level">
Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/taglibs/FaceletsHtml.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/taglibs/FaceletsHtml.xml 2011-05-24
22:40:51 UTC (rev 31465)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/taglibs/FaceletsHtml.xml 2011-05-25
00:07:18 UTC (rev 31466)
@@ -2038,7 +2038,9 @@
<param value="rtl" />
</proposal>
</attribute>
- <attribute extended="false" name="href" />
+ <attribute extended="false" name="href" >
+ <proposal type="file"/>
+ </attribute>
<attribute extended="false" name="onkeyup" />
<attribute extended="false" name="style" />
<attribute extended="false" name="rev" />
Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/taglibs/JsfHtmlBasic.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/taglibs/JsfHtmlBasic.xml 2011-05-24
22:40:51 UTC (rev 31465)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/taglibs/JsfHtmlBasic.xml 2011-05-25
00:07:18 UTC (rev 31466)
@@ -20,6 +20,12 @@
</attribute>
</component>
+ <component closeTag="true" name="link">
+ <attribute name="value" >
+ <proposal type="file"/>
+ </attribute>
+ </component>
+
<component closeTag="true" name="commandLink">
<attribute name="action" required="true" />
<attribute name="value" required="true" />
Modified:
trunk/jst/tests/org.jboss.tools.jst.web.kb.test/src/org/jboss/tools/jst/web/kb/test/WebKbTest.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.web.kb.test/src/org/jboss/tools/jst/web/kb/test/WebKbTest.java 2011-05-24
22:40:51 UTC (rev 31465)
+++
trunk/jst/tests/org.jboss.tools.jst.web.kb.test/src/org/jboss/tools/jst/web/kb/test/WebKbTest.java 2011-05-25
00:07:18 UTC (rev 31466)
@@ -18,8 +18,11 @@
import org.jboss.tools.common.el.core.resolver.ELContext;
import org.jboss.tools.jst.web.kb.IPageContext;
import org.jboss.tools.jst.web.kb.PageContextFactory;
+import org.jboss.tools.jst.web.kb.internal.proposal.CustomProposalType;
import org.jboss.tools.jst.web.kb.internal.taglib.CustomTagLibAttribute;
import org.jboss.tools.jst.web.kb.taglib.CustomTagLibManager;
+import org.jboss.tools.jst.web.kb.taglib.IAttribute;
+import org.jboss.tools.jst.web.kb.taglib.IComponent;
import org.jboss.tools.jst.web.kb.taglib.ICustomTagLibrary;
import org.jboss.tools.jst.web.kb.taglib.ITagLibrary;
@@ -59,6 +62,67 @@
}
/**
+ *
https://issues.jboss.org/browse/JBIDE-8953
+ */
+ public void testLinksComponents() {
+ ICustomTagLibrary[] libs = CustomTagLibManager.getInstance().getLibraries();
+ ICustomTagLibrary facelets = null;
+ ICustomTagLibrary h = null;
+ ICustomTagLibrary a4j = null;
+ for (ICustomTagLibrary lib : libs) {
+
if("http://www.w3.org/1999/xhtml/facelets".equals(lib.getURI())) {
+ facelets = lib;
+ } else
if("http://java.sun.com/jsf/html".equals(lib.getURI())) {
+ h = lib;
+ } else
if("http://richfaces.org/a4j".equals(lib.getURI())) {
+ a4j = lib;
+ }
+ }
+ assertNotNull(facelets);
+ assertNotNull(h);
+ assertNotNull(a4j);
+
+ IComponent link = facelets.getComponent("link");
+ assertNotNull(link);
+
+ IAttribute href = link.getAttribute("href");
+ assertNotNull(href);
+
+ CustomProposalType[] proposals = ((CustomTagLibAttribute)href).getProposals();
+ boolean found = false;
+ for (CustomProposalType proposalType : proposals) {
+ found = found || "file".equals(proposalType.getType());
+ }
+ assertTrue(found);
+
+ IComponent hLink = h.getComponent("link");
+ assertNotNull(hLink);
+
+ IAttribute value = hLink.getAttribute("value");
+ assertNotNull(value);
+
+ proposals = ((CustomTagLibAttribute)value).getProposals();
+ found = false;
+ for (CustomProposalType proposalType : proposals) {
+ found = found || "file".equals(proposalType.getType());
+ }
+ assertTrue(found);
+
+ IComponent aLoadStyle = a4j.getComponent("loadStyle");
+ assertNotNull(aLoadStyle);
+
+ IAttribute src = aLoadStyle.getAttribute("src");
+ assertNotNull(src);
+
+ proposals = ((CustomTagLibAttribute)src).getProposals();
+ found = false;
+ for (CustomProposalType proposalType : proposals) {
+ found = found || "file".equals(proposalType.getType());
+ }
+ assertTrue(found);
+ }
+
+ /**
* JBIDE-8926
*/
public void testDuplicateLibs() {