Author: scabanovich
Date: 2009-05-30 08:46:21 -0400 (Sat, 30 May 2009)
New Revision: 15615
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/ELFunction.java
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/IProposalProcessor.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbXMLStoreConstants.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/scanner/XMLScanner.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractAttribute.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractComponent.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractTagLib.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/FaceletTagLibrary.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/FacesConfigAttribute.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/FacesConfigComponent.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/FacesConfigTagLibrary.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/Facet.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/IComponent.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/IFacesConfigTagLibrary.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-2808
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/IProposalProcessor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/IProposalProcessor.java 2009-05-30
12:01:27 UTC (rev 15614)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/IProposalProcessor.java 2009-05-30
12:46:21 UTC (rev 15615)
@@ -16,10 +16,11 @@
* @author Alexey Kazakov
*/
public interface IProposalProcessor {
+ public TextProposal[] EMPTY_PROPOSAL_LIST = new TextProposal[0];
/**
* @return proposals
*/
- TextProposal[] getProposals(KbQuery query, IPageContext context);
+ public TextProposal[] getProposals(KbQuery query, IPageContext context);
}
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbXMLStoreConstants.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbXMLStoreConstants.java 2009-05-30
12:01:27 UTC (rev 15614)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbXMLStoreConstants.java 2009-05-30
12:46:21 UTC (rev 15615)
@@ -20,6 +20,8 @@
public String TAG_LIBRARY = "library"; //$NON-NLS-1$
public String TAG_COMPONENT = "component"; //$NON-NLS-1$
public String TAG_ATTRIBUTE = "attribute"; //$NON-NLS-1$
+ public String TAG_FACET = "facet"; //$NON-NLS-1$
+ public String TAG_FUNCTION = "function"; //$NON-NLS-1$
public String CLS_TLD_LIBRARY = "tld"; //$NON-NLS-1$
public String CLS_FACELET_LIBRARY = "facelet"; //$NON-NLS-1$
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/scanner/XMLScanner.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/scanner/XMLScanner.java 2009-05-30
12:01:27 UTC (rev 15614)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/scanner/XMLScanner.java 2009-05-30
12:46:21 UTC (rev 15615)
@@ -27,6 +27,7 @@
import org.jboss.tools.jst.web.kb.internal.taglib.AbstractAttribute;
import org.jboss.tools.jst.web.kb.internal.taglib.AbstractComponent;
import org.jboss.tools.jst.web.kb.internal.taglib.AbstractTagLib;
+import org.jboss.tools.jst.web.kb.internal.taglib.ELFunction;
import org.jboss.tools.jst.web.kb.internal.taglib.FaceletTag;
import org.jboss.tools.jst.web.kb.internal.taglib.FaceletTagLibrary;
import org.jboss.tools.jst.web.kb.internal.taglib.FacesConfigAttribute;
@@ -35,6 +36,7 @@
import org.jboss.tools.jst.web.kb.internal.taglib.TLDAttribute;
import org.jboss.tools.jst.web.kb.internal.taglib.TLDLibrary;
import org.jboss.tools.jst.web.kb.internal.taglib.TLDTag;
+import org.jboss.tools.jst.web.kb.taglib.Facet;
import org.jboss.tools.jst.web.model.helpers.InnerModelHelper;
import org.jboss.tools.jst.web.model.project.ext.store.XMLValueInfo;
@@ -44,6 +46,10 @@
public class XMLScanner implements IFileScanner {
public static final String ATTR_TAGCLASS ="tagclass"; //$NON-NLS-1$
public static final String ATTR_BODY_CONTENT = "bodycontent"; //$NON-NLS-1$
+ public static final String ATTR_FACET_NAME = "facet-name"; //$NON-NLS-1$
+ public static final String ATTR_ATTRIBUTE_NAME = "attribute-name";
//$NON-NLS-1$
+ public static final String ATTR_FUNC_SIGN = "function-signature";
//$NON-NLS-1$
+ public static final String ATTR_FUNC_NAME = "function-name"; //$NON-NLS-1$
public XMLScanner() {}
@@ -192,11 +198,13 @@
FaceletTag tag = new FaceletTag();
tag.setId(t);
tag.setName(new XMLValueInfo(t, "tag-name"));
- //what else?
-
library.addComponent(tag);
} else if(entity.startsWith("FaceletTaglibFunction")) {
- //TODO
+ ELFunction f = new ELFunction();
+ f.setId(t);
+ f.setName(new XMLValueInfo(t, ATTR_FUNC_NAME));
+ f.setSignature(new XMLValueInfo(t, ATTR_FUNC_SIGN));
+ library.addFunction(f);
}
}
}
@@ -214,8 +222,8 @@
for (XModelObject c: os) {
FacesConfigComponent component = new FacesConfigComponent();
component.setId(c);
+ //what else can we take for the name? only attribute 'component-type' is
available
component.setName(new XMLValueInfo(c, "component-type"));
- //TODO what else can we take for the name? only attribute 'component-type' is
available
component.setComponentClass(new XMLValueInfo(c, "component-class"));
component.setComponentType(c.getAttributeValue("component-type"));
@@ -226,10 +234,16 @@
String entity = child.getModelEntity().getName();
if(entity.startsWith("JSFAttribute")) {
FacesConfigAttribute attr = new FacesConfigAttribute();
+ attr.setId(child);
+ attr.setName(new XMLValueInfo(child, ATTR_ATTRIBUTE_NAME));
component.addAttribute(attr);
} else if(entity.startsWith("JSFFacet")) {
- //TODO
+ Facet f = new Facet();
+ f.setId(child);
+ f.setName(new XMLValueInfo(child, ATTR_FACET_NAME));
+ f.setDescription(new XMLValueInfo(child, AbstractComponent.DESCRIPTION));
+ component.addFacet(f);
}
}
library.addComponent(component);
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractAttribute.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractAttribute.java 2009-05-30
12:01:27 UTC (rev 15614)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractAttribute.java 2009-05-30
12:46:21 UTC (rev 15615)
@@ -107,11 +107,19 @@
* @see
org.jboss.tools.jst.web.kb.IProposalProcessor#getProposals(org.jboss.tools.jst.web.kb.KbQuery,
org.jboss.tools.jst.web.kb.IPageContext)
*/
public TextProposal[] getProposals(KbQuery query, IPageContext context) {
- List<TextProposal> proposals = new ArrayList<TextProposal>();
+ List<TextProposal> proposals = null;
ELResolver[] resolvers = context.getElResolvers();
for (int i = 0; i < resolvers.length; i++) {
- proposals.addAll(resolvers[i].getCompletions(query.getValue(), false,
query.getValue().length(), context));
+ List<TextProposal> list = resolvers[i].getCompletions(query.getValue(), false,
query.getValue().length(), context);
+ if(list == null || list.isEmpty()) continue;
+ if(proposals == null) {
+ proposals = new ArrayList<TextProposal>();
+ }
+ proposals.addAll(list);
}
+ if(proposals == null || proposals.isEmpty()) {
+ return EMPTY_PROPOSAL_LIST;
+ }
return proposals.toArray(new TextProposal[proposals.size()]);
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractComponent.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractComponent.java 2009-05-30
12:01:27 UTC (rev 15614)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractComponent.java 2009-05-30
12:46:21 UTC (rev 15615)
@@ -25,6 +25,7 @@
import org.jboss.tools.jst.web.kb.KbQuery;
import org.jboss.tools.jst.web.kb.internal.KbObject;
import org.jboss.tools.jst.web.kb.internal.KbXMLStoreConstants;
+import org.jboss.tools.jst.web.kb.taglib.Facet;
import org.jboss.tools.jst.web.kb.taglib.IAttribute;
import org.jboss.tools.jst.web.kb.taglib.IComponent;
import org.w3c.dom.Element;
@@ -207,13 +208,36 @@
}
}
+ /**
+ * Facets are a feature of JSF only, they are included into
+ * the base interface and implementation
+ * for the sake of common approach.
+ */
+ public Facet getFacet(String name) {
+ return null;
+ }
+
+ public static final Facet[] EMPTY_FACET_SET = new Facet[0];
+
+ public Facet[] getFacets() {
+ return EMPTY_FACET_SET;
+ }
+
+ public Facet[] getFacets(String nameTemplate) {
+ return EMPTY_FACET_SET;
+ }
+
/* (non-Javadoc)
* @see
org.jboss.tools.jst.web.kb.IProposalProcessor#getProposals(org.jboss.tools.jst.web.kb.KbQuery,
org.jboss.tools.jst.web.kb.IPageContext)
*/
public TextProposal[] getProposals(KbQuery query, IPageContext context) {
- List<TextProposal> proposals = new ArrayList<TextProposal>();
IAttribute[] attributes = getAttributes(query, context);
+ if(attributes.length == 0) {
+ return EMPTY_PROPOSAL_LIST;
+ }
+ List<TextProposal> proposals = null;
if(query.getType() == KbQuery.Type.ATTRIBUTE_NAME) {
+ proposals = new ArrayList<TextProposal>();
for (int i = 0; i < attributes.length; i++) {
TextProposal proposal = new TextProposal();
proposal.setContextInfo(attributes[i].getDescription());
@@ -224,11 +248,17 @@
} else if(query.getType() == KbQuery.Type.ATTRIBUTE_VALUE) {
for (int i = 0; i < attributes.length; i++) {
TextProposal[] attributeProposals = attributes[i].getProposals(query, context);
+ if(attributeProposals.length > 0 && proposals == null) {
+ proposals = new ArrayList<TextProposal>();
+ }
for (int j = 0; j < attributeProposals.length; j++) {
proposals.add(attributeProposals[j]);
}
}
}
+ if(proposals == null || proposals.isEmpty()) {
+ return EMPTY_PROPOSAL_LIST;
+ }
return proposals.toArray(new TextProposal[proposals.size()]);
}
@@ -314,6 +344,9 @@
}
}
+ public AbstractComponent clone() throws CloneNotSupportedException {
+ return (AbstractComponent)super.clone();
+ }
public String getXMLName() {
return KbXMLStoreConstants.TAG_COMPONENT;
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractTagLib.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractTagLib.java 2009-05-30
12:01:27 UTC (rev 15614)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractTagLib.java 2009-05-30
12:46:21 UTC (rev 15615)
@@ -276,6 +276,9 @@
public AbstractTagLib clone() throws CloneNotSupportedException {
AbstractTagLib t = (AbstractTagLib)super.clone();
t.components = new HashMap<String, IComponent>();
+ for (IComponent c: components.values()) {
+ t.addComponent(((AbstractComponent)c).clone());
+ }
t.components.putAll(components);
return t;
}
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/ELFunction.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/ELFunction.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/ELFunction.java 2009-05-30
12:46:21 UTC (rev 15615)
@@ -0,0 +1,89 @@
+package org.jboss.tools.jst.web.kb.internal.taglib;
+
+import java.util.Properties;
+
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.project.ext.IValueInfo;
+import org.jboss.tools.common.model.project.ext.store.XMLStoreConstants;
+import org.jboss.tools.jst.web.kb.internal.KbObject;
+import org.jboss.tools.jst.web.kb.internal.KbXMLStoreConstants;
+import org.jboss.tools.jst.web.kb.internal.scanner.XMLScanner;
+import org.jboss.tools.jst.web.kb.taglib.IELFunction;
+import org.jboss.tools.jst.web.model.project.ext.store.XMLValueInfo;
+import org.w3c.dom.Element;
+
+public class ELFunction extends KbObject implements IELFunction {
+ public static final String SIGNATURE = "signature";
+ private String name;
+ private String signature;
+
+ public ELFunction() {}
+
+ public String getName() {
+ return name;
+ }
+
+ public String getFunctionSignature() {
+ return signature;
+ }
+
+ public void setName(IValueInfo s) {
+ name = s == null ? null : s.getValue();
+ attributesInfo.put(XMLStoreConstants.ATTR_NAME, s);
+ }
+
+ public void setSignature(IValueInfo s) {
+ signature = s == null ? null : s.getValue();
+ attributesInfo.put(SIGNATURE, s);
+ }
+
+ public ELFunction clone() throws CloneNotSupportedException {
+ return (ELFunction)super.clone();
+ }
+
+ public String getXMLName() {
+ return KbXMLStoreConstants.TAG_FUNCTION;
+ }
+
+ public Element toXML(Element parent, Properties context) {
+ Element element = super.toXML(parent, context);
+
+ if(attributesInfo.get(XMLStoreConstants.ATTR_NAME) == null && name != null) {
+ element.setAttribute(XMLStoreConstants.ATTR_NAME, name);
+ }
+
+ return element;
+ }
+
+ public void loadXML(Element element, Properties context) {
+ super.loadXML(element, context);
+
+ setName(attributesInfo.get(XMLStoreConstants.ATTR_NAME));
+ setSignature(attributesInfo.get(SIGNATURE));
+
+ if(name == null && element.hasAttribute(XMLStoreConstants.ATTR_NAME)) {
+ name = element.getAttribute(XMLStoreConstants.ATTR_NAME);
+ }
+ }
+
+ @Override
+ protected void saveAttributesInfo(Element element, Properties context) {
+ if(context.get(XMLStoreConstants.KEY_MODEL_OBJECT) == getId()) {
+
+ } else {
+ super.saveAttributesInfo(element, context);
+ }
+ }
+
+ @Override
+ protected void loadAttributesInfo(Element element, Properties context) {
+ if(context.get(XMLStoreConstants.KEY_MODEL_OBJECT) == getId()) {
+ XModelObject a = (XModelObject)getId();
+ attributesInfo.put(XMLStoreConstants.ATTR_NAME, new XMLValueInfo(a,
XMLScanner.ATTR_FUNC_NAME));
+ attributesInfo.put(SIGNATURE, new XMLValueInfo(a, XMLScanner.ATTR_FUNC_SIGN));
+ } else {
+ super.loadAttributesInfo(element, context);
+ }
+ }
+
+}
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/ELFunction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/FaceletTagLibrary.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/FaceletTagLibrary.java 2009-05-30
12:01:27 UTC (rev 15614)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/FaceletTagLibrary.java 2009-05-30
12:46:21 UTC (rev 15615)
@@ -10,27 +10,49 @@
******************************************************************************/
package org.jboss.tools.jst.web.kb.internal.taglib;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.jboss.tools.common.model.project.ext.event.Change;
+import org.jboss.tools.common.xml.XMLUtilities;
+import org.jboss.tools.jst.web.kb.internal.KbObject;
import org.jboss.tools.jst.web.kb.internal.KbXMLStoreConstants;
+import org.jboss.tools.jst.web.kb.taglib.Facet;
import org.jboss.tools.jst.web.kb.taglib.IELFunction;
import org.jboss.tools.jst.web.kb.taglib.IFaceletTagLibrary;
+import org.w3c.dom.Element;
/**
* @author Viacheslav Kabanovich
*/
public class FaceletTagLibrary extends AbstractTagLib implements
IFaceletTagLibrary {
+ List<ELFunction> functions = new ArrayList<ELFunction>();
+ IELFunction[] functionArray = null;
public FaceletTagLibrary() {
}
public IELFunction[] getFunctions() {
- // TODO Auto-generated method stub
- return null;
+ if(functionArray == null) {
+ functionArray = functions.toArray(new ELFunction[0]);
+ }
+ return functionArray;
}
+ public void addFunction(ELFunction f) {
+ functions.add(f);
+ functionArray = null;
+ }
+
public FaceletTagLibrary clone() throws CloneNotSupportedException {
FaceletTagLibrary copy = (FaceletTagLibrary)super.clone();
+ copy.functions = new ArrayList<ELFunction>();
+ for (IELFunction f: getFunctions()) {
+ copy.addFunction(((ELFunction)f).clone());
+ }
return copy;
}
@@ -38,4 +60,32 @@
return KbXMLStoreConstants.CLS_FACELET_LIBRARY;
}
+ public List<Change> merge(KbObject s) {
+ List<Change> changes = super.merge(s);
+ FacesConfigTagLibrary t = (FacesConfigTagLibrary)s;
+ //TODO
+ return changes;
+ }
+
+ public Element toXML(Element parent, Properties context) {
+ Element element = super.toXML(parent, context);
+
+ for (IELFunction f: getFunctions()) {
+ ((KbObject)f).toXML(element, context);
+ }
+
+ return element;
+ }
+
+ public void loadXML(Element element, Properties context) {
+ super.loadXML(element, context);
+
+ Element[] cs = XMLUtilities.getChildren(element, KbXMLStoreConstants.TAG_FUNCTION);
+ for (Element e: cs) {
+ ELFunction f = new ELFunction();
+ f.loadXML(e, context);
+ addFunction(f);
+ }
+ }
+
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/FacesConfigAttribute.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/FacesConfigAttribute.java 2009-05-30
12:01:27 UTC (rev 15614)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/FacesConfigAttribute.java 2009-05-30
12:46:21 UTC (rev 15615)
@@ -15,6 +15,7 @@
import org.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.model.project.ext.store.XMLStoreConstants;
import org.jboss.tools.jst.web.kb.internal.KbXMLStoreConstants;
+import org.jboss.tools.jst.web.kb.internal.scanner.XMLScanner;
import org.jboss.tools.jst.web.model.project.ext.store.XMLValueInfo;
import org.w3c.dom.Element;
@@ -31,9 +32,9 @@
protected void loadAttributesInfo(Element element, Properties context) {
if(context.get(XMLStoreConstants.KEY_MODEL_OBJECT) == getId()) {
XModelObject a = (XModelObject)getId();
- attributesInfo.put(XMLStoreConstants.ATTR_NAME, new XMLValueInfo(a,
"attribute-name"));
+ attributesInfo.put(XMLStoreConstants.ATTR_NAME, new XMLValueInfo(a,
XMLScanner.ATTR_ATTRIBUTE_NAME));
+ attributesInfo.put(AbstractComponent.DESCRIPTION, new XMLValueInfo(a,
AbstractComponent.DESCRIPTION));
//TODO how to define required?
- attributesInfo.put(AbstractComponent.DESCRIPTION, new XMLValueInfo(a,
AbstractComponent.DESCRIPTION));
// attributesInfo.put(REQUIRED, new XMLValueInfo(a, REQUIRED));
} else {
super.loadAttributesInfo(element, context);
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/FacesConfigComponent.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/FacesConfigComponent.java 2009-05-30
12:01:27 UTC (rev 15614)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/FacesConfigComponent.java 2009-05-30
12:46:21 UTC (rev 15615)
@@ -10,15 +10,121 @@
******************************************************************************/
package org.jboss.tools.jst.web.kb.internal.taglib;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.jboss.tools.common.model.project.ext.event.Change;
+import org.jboss.tools.common.xml.XMLUtilities;
+import org.jboss.tools.jst.web.kb.internal.KbObject;
import org.jboss.tools.jst.web.kb.internal.KbXMLStoreConstants;
+import org.jboss.tools.jst.web.kb.taglib.Facet;
+import org.w3c.dom.Element;
/**
* @author Viacheslav Kabanovich
*/
public class FacesConfigComponent extends AbstractComponent {
+ Map<String,Facet> facets = new HashMap<String, Facet>();
+ Facet[] facetArray = EMPTY_FACET_SET;
+ public Facet getFacet(String name) {
+ return facets.get(name);
+ }
+
+ public static final Facet[] EMPTY_FACET_SET = new Facet[0];
+
+ public Facet[] getFacets() {
+ if(facetArray == null) {
+ if(facets.isEmpty()) {
+ facetArray = EMPTY_FACET_SET;
+ } else {
+ facetArray = facets.values().toArray(new Facet[0]);
+ }
+ }
+ return facetArray;
+ }
+
+ public Facet[] getFacets(String nameTemplate) {
+ Facet[] fs = getFacets();
+ if(fs == null || fs.length == 0) return EMPTY_FACET_SET;
+ List<Facet> result = new ArrayList<Facet>();
+ for (Facet f: fs) {
+ String name = f.getName();
+ boolean match = false; //TODO implement
+ if(match) result.add(f);
+ }
+ return result.isEmpty() ? EMPTY_FACET_SET : result.toArray(new Facet[0]);
+ }
+
+ public void addFacet(Facet f) {
+ adopt((KbObject)f);
+ facets.put(f.getName(), f);
+ facetArray = null;
+ }
+
public String getXMLClass() {
return KbXMLStoreConstants.CLS_FACESCONFIG_LIBRARY;
}
+ public List<Change> merge(KbObject s) {
+ List<Change> changes = super.merge(s);
+ FacesConfigComponent c = (FacesConfigComponent)s;
+
+ Change children = new Change(this, null, null, null);
+ mergeFacets(c, children);
+ changes = Change.addChange(changes, children);
+
+ return changes;
+ }
+
+ public void mergeFacets(FacesConfigComponent c, Change children) {
+ Map<Object,Facet> facetMap = new HashMap<Object, Facet>();
+ for (Facet a: facets.values()) facetMap.put(((KbObject)a).getId(), a);
+ for (Facet a: c.facets.values()) {
+ Facet loaded = (Facet)a;
+ Facet current = facetMap.get(loaded.getId());
+ if(current == null) {
+ addFacet(loaded);
+ Change change = new Change(this, null, null, loaded);
+ children.addChildren(Change.addChange(null, change));
+ } else {
+ List<Change> rc = current.merge(loaded);
+ if(rc != null) children.addChildren(rc);
+ }
+ }
+ for (Facet a: facetMap.values()) {
+ Facet removed = a;
+ if(facets.get(removed.getName()) == removed) {
+ facets.remove(removed.getName());
+ facetArray = null;
+ Change change = new Change(this, null, removed, null);
+ children.addChildren(Change.addChange(null, change));
+ }
+ }
+ }
+
+ public Element toXML(Element parent, Properties context) {
+ Element element = super.toXML(parent, context);
+
+ for (Facet f: getFacets()) {
+ ((KbObject)f).toXML(element, context);
+ }
+
+ return element;
+ }
+
+ public void loadXML(Element element, Properties context) {
+ super.loadXML(element, context);
+
+ Element[] cs = XMLUtilities.getChildren(element, KbXMLStoreConstants.TAG_FACET);
+ for (Element e: cs) {
+ Facet f = new Facet();
+ f.loadXML(e, context);
+ addFacet(f);
+ }
+ }
+
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/FacesConfigTagLibrary.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/FacesConfigTagLibrary.java 2009-05-30
12:01:27 UTC (rev 15614)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/FacesConfigTagLibrary.java 2009-05-30
12:46:21 UTC (rev 15615)
@@ -38,34 +38,27 @@
return componentsByType.get(type);
}
- public Facet getFacet(String name) {
- // TODO Auto-generated method stub
- return null;
- }
-
- public Facet[] getFacets() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public Facet[] getFacets(String nameTemplate) {
- // TODO Auto-generated method stub
- return null;
- }
-
public FacesConfigTagLibrary clone() throws CloneNotSupportedException {
FacesConfigTagLibrary copy = (FacesConfigTagLibrary)super.clone();
- //TODO
+
return copy;
}
public List<Change> merge(KbObject s) {
List<Change> changes = super.merge(s);
FacesConfigTagLibrary t = (FacesConfigTagLibrary)s;
- //TODO
+
+ Change children = new Change(this, null, null, null);
+ mergeFunctions(t, children);
+ changes = Change.addChange(changes, children);
+
return changes;
}
+ public void mergeFunctions(FacesConfigTagLibrary c, Change children) {
+ //TODO
+ }
+
public String getXMLClass() {
return KbXMLStoreConstants.CLS_FACESCONFIG_LIBRARY;
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/Facet.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/Facet.java 2009-05-30
12:01:27 UTC (rev 15614)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/Facet.java 2009-05-30
12:46:21 UTC (rev 15615)
@@ -10,11 +10,23 @@
******************************************************************************/
package org.jboss.tools.jst.web.kb.taglib;
+import java.util.Properties;
+
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.project.ext.IValueInfo;
+import org.jboss.tools.common.model.project.ext.store.XMLStoreConstants;
+import org.jboss.tools.jst.web.kb.internal.KbObject;
+import org.jboss.tools.jst.web.kb.internal.KbXMLStoreConstants;
+import org.jboss.tools.jst.web.kb.internal.scanner.XMLScanner;
+import org.jboss.tools.jst.web.kb.internal.taglib.AbstractComponent;
+import org.jboss.tools.jst.web.model.project.ext.store.XMLValueInfo;
+import org.w3c.dom.Element;
+
/**
* JSF Facet Component
* @author Alexey Kazakov
*/
-public class Facet {
+public class Facet extends KbObject {
private String description;
private String name;
@@ -40,4 +52,60 @@
public void setName(String name) {
this.name = name;
}
+
+ public void setName(IValueInfo s) {
+ name = s == null ? null : s.getValue();
+ attributesInfo.put(XMLStoreConstants.ATTR_NAME, s);
+ }
+
+ public void setDescription(IValueInfo s) {
+ description = s == null ? null : s.getValue();
+ attributesInfo.put(AbstractComponent.DESCRIPTION, s);
+ }
+
+ public String getXMLName() {
+ return KbXMLStoreConstants.TAG_FACET;
+ }
+
+ public Element toXML(Element parent, Properties context) {
+ Element element = super.toXML(parent, context);
+
+ if(attributesInfo.get(XMLStoreConstants.ATTR_NAME) == null && name != null) {
+ element.setAttribute(XMLStoreConstants.ATTR_NAME, name);
+ }
+
+ return element;
+ }
+
+ public void loadXML(Element element, Properties context) {
+ super.loadXML(element, context);
+
+ setName(attributesInfo.get(XMLStoreConstants.ATTR_NAME));
+ setDescription(attributesInfo.get(AbstractComponent.DESCRIPTION));
+
+ if(name == null && element.hasAttribute(XMLStoreConstants.ATTR_NAME)) {
+ name = element.getAttribute(XMLStoreConstants.ATTR_NAME);
+ }
+ }
+
+ @Override
+ protected void saveAttributesInfo(Element element, Properties context) {
+ if(context.get(XMLStoreConstants.KEY_MODEL_OBJECT) == getId()) {
+
+ } else {
+ super.saveAttributesInfo(element, context);
+ }
+ }
+
+ @Override
+ protected void loadAttributesInfo(Element element, Properties context) {
+ if(context.get(XMLStoreConstants.KEY_MODEL_OBJECT) == getId()) {
+ XModelObject a = (XModelObject)getId();
+ attributesInfo.put(XMLStoreConstants.ATTR_NAME, new XMLValueInfo(a,
XMLScanner.ATTR_FACET_NAME));
+ attributesInfo.put(AbstractComponent.DESCRIPTION, new XMLValueInfo(a,
AbstractComponent.DESCRIPTION));
+ } else {
+ super.loadAttributesInfo(element, context);
+ }
+ }
+
}
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/IComponent.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/IComponent.java 2009-05-30
12:01:27 UTC (rev 15614)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/IComponent.java 2009-05-30
12:46:21 UTC (rev 15615)
@@ -78,4 +78,24 @@
* @return
*/
public IAttribute[] getAttributes(KbQuery query, IPageContext context);
+
+ /**
+ * Facets are a feature of JSF only, they are included into
+ * the base interface for the sake of common approach.
+ *
+ * @return all facets of this component
+ */
+ Facet[] getFacets();
+
+ /**
+ * @param nameTemplate
+ * @return facets with names which start with given template.
+ */
+ Facet[] getFacets(String nameTemplate);
+
+ /**
+ * @param name
+ * @return facet by name
+ */
+ Facet getFacet(String name);
}
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/IFacesConfigTagLibrary.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/IFacesConfigTagLibrary.java 2009-05-30
12:01:27 UTC (rev 15614)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/IFacesConfigTagLibrary.java 2009-05-30
12:46:21 UTC (rev 15615)
@@ -21,20 +21,4 @@
*/
IComponent getComponentByType(String type);
- /**
- * @return all facets of this component
- */
- Facet[] getFacets();
-
- /**
- * @param nameTemplate
- * @return facets with names which start with given template.
- */
- Facet[] getFacets(String nameTemplate);
-
- /**
- * @param name
- * @return facet by name
- */
- Facet getFacet(String name);
}
\ No newline at end of file