Author: vrubezhny
Date: 2009-10-19 09:18:23 -0400 (Mon, 19 Oct 2009)
New Revision: 18155
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/ICSSContainerSupport.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/CSSClassProposalType.java
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/FaceletPageContectAssistProcessor.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JspContentAssistProcessor.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/META-INF/MANIFEST.MF
trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.xml
trunk/jst/plugins/org.jboss.tools.jst.web.kb/schema/include.exsd
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/IIncludedContextSupport.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/IncludeContextBuilder.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/IncludeContextDefinition.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/JspContextImpl.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/CustomProposalTypeFactory.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/taglibs/componentExtension.xml
Log:
JBIDE-3563: Code assist for "class" and "styleClass" attributes for
html and jsf tags.
The schema for included pages is updated to support the style class definitions loading
tags
The included pages context are updated to be the information holder for the CSS Style
Sheets loaded
The new Proposal Type is added for CSS classes.
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/FaceletPageContectAssistProcessor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/FaceletPageContectAssistProcessor.java 2009-10-19
12:55:43 UTC (rev 18154)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/FaceletPageContectAssistProcessor.java 2009-10-19
13:18:23 UTC (rev 18155)
@@ -77,7 +77,7 @@
context.setLibraries(getTagLibraries(context));
context.setResourceBundles(super.getResourceBundles(context));
- PageContextFactory.createIncludedContexts(context);
+ PageContextFactory.collectIncludedAdditionalInfo(context);
return context;
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JspContentAssistProcessor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JspContentAssistProcessor.java 2009-10-19
12:55:43 UTC (rev 18154)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JspContentAssistProcessor.java 2009-10-19
13:18:23 UTC (rev 18155)
@@ -97,7 +97,7 @@
@Override
protected IPageContext createContext() {
IPageContext context = super.createContext();
- PageContextFactory.createIncludedContexts(context);
+ PageContextFactory.collectIncludedAdditionalInfo(context);
return context;
}
Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/META-INF/MANIFEST.MF
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/META-INF/MANIFEST.MF 2009-10-19 12:55:43
UTC (rev 18154)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/META-INF/MANIFEST.MF 2009-10-19 13:18:23
UTC (rev 18155)
@@ -22,7 +22,9 @@
org.eclipse.jdt.ui,
org.eclipse.wst.validation,
org.eclipse.ui.editors,
- org.eclipse.ui.ide
+ org.eclipse.ui.ide,
+ org.eclipse.wst.css.core;bundle-version="1.1.300",
+ org.eclipse.wst.html.core;bundle-version="1.1.300"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-Vendor: %providerName
Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.xml 2009-10-19 12:55:43 UTC (rev
18154)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.xml 2009-10-19 13:18:23 UTC (rev
18155)
@@ -88,6 +88,15 @@
<contexttype id="FACELETS_PAGE_CONTEXT_TYPE">
<contenttype id="org.eclipse.wst.html.core.htmlsource" />
</contexttype>
+
+ <cssholder uri="">
+ <tag name="style" caseinsensitive="true" />
+ <tag name="link" caseinsensitive="true">
+ <attribute
+ name="href">
+ </attribute>
+ </tag>
+ </cssholder>
</extension>
<extension id="kbproblemmarker" name="%KBProblemName"
point="org.eclipse.core.resources.markers">
@@ -103,4 +112,4 @@
class="org.jboss.tools.jst.web.kb.action.KBProblemMarkerResolutionGenerator">
</markerResolutionGenerator>
</extension>
-</plugin>
\ No newline at end of file
+</plugin>
Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/schema/include.exsd
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/schema/include.exsd 2009-10-19 12:55:43
UTC (rev 18154)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/schema/include.exsd 2009-10-19 13:18:23
UTC (rev 18155)
@@ -25,6 +25,7 @@
<complexType>
<sequence>
<element ref="include" minOccurs="0"
maxOccurs="unbounded"/>
+ <element ref="cssholder" minOccurs="0"
maxOccurs="unbounded"/>
<element ref="contexttype" minOccurs="0"
maxOccurs="unbounded"/>
</sequence>
<attribute name="point" type="string"
use="required">
@@ -146,6 +147,26 @@
</complexType>
</element>
+ <element name="cssholder">
+ <annotation>
+ <documentation>
+ Defines a CSS holder item.
+ </documentation>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="tag" minOccurs="0"
maxOccurs="unbounded"/>
+ <element ref="attribute" minOccurs="0"
maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="uri" type="string"
use="required">
+ <annotation>
+ <documentation>
+ An URI for this element.
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
<annotation>
<appInfo>
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/ICSSContainerSupport.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/ICSSContainerSupport.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/ICSSContainerSupport.java 2009-10-19
13:18:23 UTC (rev 18155)
@@ -0,0 +1,29 @@
+package org.jboss.tools.jst.web.kb;
+
+import java.util.List;
+
+import org.w3c.dom.css.CSSStyleSheet;
+
+/**
+ * The interface defines the methods to collect
+ * CSS Stylesheets used within the page.
+ *
+ * @author Victor Rubezhny
+ *
+ */
+public interface ICSSContainerSupport {
+
+ /**
+ * Adds the CSS StyleSheet object found within the page
+ *
+ * @param includedContext
+ */
+ void addCSSStyleSheet(CSSStyleSheet cssStyleSheet);
+
+ /**
+ * Returns the list of all the collected CSS StyleSheet objects
+ *
+ * @return
+ */
+ List<CSSStyleSheet> getCSSStyleSheets();
+}
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/ICSSContainerSupport.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/IIncludedContextSupport.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/IIncludedContextSupport.java 2009-10-19
12:55:43 UTC (rev 18154)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/IIncludedContextSupport.java 2009-10-19
13:18:23 UTC (rev 18155)
@@ -6,8 +6,27 @@
import org.eclipse.core.resources.IFile;
import org.jboss.tools.jst.web.kb.taglib.INameSpace;
+/**
+ * The interface defines the methods to collect
+ * contexts for the included pages.
+ *
+ * @author Victor Rubezhny
+ *
+ */
public interface IIncludedContextSupport {
+
+ /**
+ * Adds the context created for the included page
+ *
+ * @param includedContext
+ */
void addIncludedContext(IPageContext includedContext);
+
+ /**
+ * Returns the list of all the collected contexts
+ *
+ * @return
+ */
List<IPageContext> getIncludedContexts();
/**
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java 2009-10-19
12:55:43 UTC (rev 18154)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java 2009-10-19
13:18:23 UTC (rev 18155)
@@ -11,6 +11,7 @@
package org.jboss.tools.jst.web.kb;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
@@ -34,15 +35,21 @@
import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager;
import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker;
import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.texteditor.DocumentProviderRegistry;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.wst.common.componentcore.internal.ComponentResource;
import org.eclipse.wst.common.componentcore.internal.StructureEdit;
import org.eclipse.wst.common.componentcore.internal.WorkbenchComponent;
+import org.eclipse.wst.css.core.internal.provisional.adapters.IModelProvideAdapter;
+import org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetAdapter;
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSModel;
+import org.eclipse.wst.html.core.internal.htmlcss.LinkElementAdapter;
+import org.eclipse.wst.html.core.internal.htmlcss.URLModelProvider;
import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
import org.eclipse.wst.xml.core.internal.document.NodeContainer;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
@@ -68,7 +75,7 @@
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import org.eclipse.ui.part.FileEditorInput;
+import org.w3c.dom.css.CSSStyleSheet;
/**
* @author Alexey Kazakov
@@ -114,7 +121,8 @@
setJSPNameSpaces(context, offset);
context.setLibraries(getTagLibraries(context, offset));
context.setResourceBundles(getResourceBundles(context));
- createIncludedContexts(context);
+
+ collectIncludedAdditionalInfo(context);
} finally {
releaseConnectedDocument(input);
context.setDocument(null);
@@ -143,7 +151,7 @@
context.setLibraries(getTagLibraries(context, offset));
context.setResourceBundles(getResourceBundles(context));
- PageContextFactory.createIncludedContexts(context);
+ collectIncludedAdditionalInfo(context);
} finally {
releaseConnectedDocument(input);
context.setDocument(null);
@@ -154,8 +162,9 @@
/* Utility functions */
- public static void createIncludedContexts(IPageContext context) {
- if (!(context instanceof IIncludedContextSupport))
+ public static void collectIncludedAdditionalInfo(IPageContext context) {
+ if (!(context instanceof IIncludedContextSupport) &&
+ !(context instanceof ICSSContainerSupport))
return;
IStructuredModel sModel = StructuredModelManager.getModelManager()
@@ -173,7 +182,7 @@
return;
if (xmlDocument instanceof IDOMNode) {
- createIncludedContextForNode((IDOMNode)xmlDocument,
(IIncludedContextSupport)context);
+ createIncludedAdditionalInfoForNode((IDOMNode)xmlDocument, context);
}
} finally {
if (sModel != null) {
@@ -182,8 +191,8 @@
}
}
-
- private static void createIncludedContextForNode(IDOMNode node, IIncludedContextSupport
context) {
+
+ private static void createIncludedAdditionalInfoForNode(IDOMNode node, IPageContext
context) {
String prefix = node.getPrefix() == null ? "" : node.getPrefix();
//$NON-NLS-1$
String tagName = node.getLocalName();
if (node instanceof IDOMElement) {
@@ -192,12 +201,26 @@
if (uris != null) {
for (String uri : uris) {
- String[] includeAttributes = IncludeContextBuilder.getIncludeAttributes(uri,
tagName);
- if (includeAttributes != null) {
- for (String attr : includeAttributes) {
- createIncludedContextFromAttribute((IDOMElement)node, attr, context);
+ if (context instanceof IIncludedContextSupport) {
+ String[] includeAttributes = IncludeContextBuilder.getIncludeAttributes(uri,
tagName);
+ if (includeAttributes != null) {
+ for (String attr : includeAttributes) {
+ createIncludedContextFromAttribute((IDOMElement)node, attr, context);
+ }
}
}
+ if (context instanceof ICSSContainerSupport) {
+ if(IncludeContextBuilder.isCSSStyleSheetContainer(uri, tagName)) {
+ createCSSStyleSheetFromElement((IDOMElement)node, (ICSSContainerSupport)context);
+ } else {
+ String[] cssAttributes = IncludeContextBuilder.getCSSStyleSheetAttributes(uri,
tagName);
+ if (cssAttributes != null) {
+ for (String attr : cssAttributes) {
+ createCSSStyleSheetFromAttribute((IDOMElement)node, attr,
(ICSSContainerSupport)context);
+ }
+ }
+ }
+ }
}
}
}
@@ -205,11 +228,78 @@
NodeList children = node.getChildNodes();
for (int i = 0; children != null && i < children.getLength(); i++) {
if (children.item(i) instanceof IDOMElement) {
- createIncludedContextForNode((IDOMElement)children.item(i), context);
+ createIncludedAdditionalInfoForNode((IDOMElement)children.item(i), context);
}
}
}
+ private static void createCSSStyleSheetFromAttribute(IDOMElement node,
+ String attribute, ICSSContainerSupport context) {
+ CSSStyleSheet sheet = getSheetForTagAttribute(node, attribute);
+ if (sheet != null)
+ context.addCSSStyleSheet(sheet);
+ }
+
+ private static void createCSSStyleSheetFromElement(IDOMElement node,
+ ICSSContainerSupport context) {
+ CSSStyleSheet sheet = getSheetForTag(node);
+ if (sheet != null)
+ context.addCSSStyleSheet(sheet);
+ }
+
+
+ /**
+ *
+ * @param stylesContainer
+ * @return
+ */
+ private static CSSStyleSheet getSheetForTagAttribute(final Node stylesContainer, String
attribute) {
+
+ INodeNotifier notifier = (INodeNotifier) stylesContainer;
+
+ IStyleSheetAdapter adapter = (IStyleSheetAdapter) notifier
+ .getAdapterFor(IStyleSheetAdapter.class);
+
+ if (!(adapter instanceof ExtendedLinkElementAdapter)) {
+
+ notifier.removeAdapter(adapter);
+ adapter = new ExtendedLinkElementAdapter(
+ (Element) stylesContainer, attribute);
+ notifier.addAdapter(adapter);
+
+ }
+
+ CSSStyleSheet sheet = null;
+
+ if (adapter != null) {
+ sheet = (CSSStyleSheet) adapter.getSheet();
+
+ }
+
+ return sheet;
+ }
+
+ /**
+ *
+ * @param stylesContainer
+ * @return
+ */
+ private static CSSStyleSheet getSheetForTag(final Node stylesContainer) {
+
+ INodeNotifier notifier = (INodeNotifier) stylesContainer;
+
+ IStyleSheetAdapter adapter = (IStyleSheetAdapter) notifier
+ .getAdapterFor(IStyleSheetAdapter.class);
+
+ CSSStyleSheet sheet = null;
+
+ if (adapter != null) {
+ sheet = (CSSStyleSheet) adapter.getSheet();
+ }
+
+ return sheet;
+ }
+
private static void createIncludedContextFromAttribute(IDOMElement node, String
attribute, IIncludedContextSupport context) {
String fileName = node.getAttribute(attribute);
if (fileName == null || fileName.trim().length() == 0)
@@ -243,7 +333,8 @@
if (xmlDocument instanceof IDOMNode) {
String contentType = sModel.getContentTypeIdentifier();
IPageContext includedContext = PageContextFactory.createPageContext(file, ((IDOMNode)
xmlDocument).getEndOffset() - 1, contentType);
- context.addIncludedContext(includedContext);
+ if (includedContext != null)
+ context.addIncludedContext(includedContext);
}
} finally {
if (sModel != null) {
@@ -251,7 +342,6 @@
}
}
}
-
static Node findNodeForOffset(IDOMNode node, int offset) {
if(node == null) return null;
@@ -566,11 +656,9 @@
try {
sModel =
StructuredModelManager.getModelManager().getModelForRead(context.getResource());
} catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ // Ignore. The sModel will be set to null
} catch (CoreException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ // Ignore. The sModel will be set to null
}
if (sModel == null)
@@ -815,4 +903,86 @@
return sortedReferences;
}
+
+ public static class ExtendedLinkElementAdapter extends LinkElementAdapter {
+
+ private Element element;
+ private String hrefAttrName;
+
+ public ExtendedLinkElementAdapter(Element element, String hrefAttrName) {
+ this.element = element;
+ this.hrefAttrName = hrefAttrName;
+ }
+
+ @Override
+ public Element getElement() {
+ return element;
+ }
+
+ @Override
+ protected boolean isValidAttribute() {
+ String href = getElement().getAttribute(hrefAttrName);
+ if (href == null || href.length() == 0)
+ return false;
+ return true;
+ }
+
+ /**
+ */
+ public ICSSModel getModel() {
+ ICSSModel model = super.getModel();
+ if (model == null) {
+ model = retrieveModel();
+ setModel(model);
+ }
+ return model;
+ }
+
+ /**
+ */
+ private ICSSModel retrieveModel() {
+ if (!isValidAttribute()) {
+ return null;
+ }
+
+ // null,attr check is done in isValidAttribute()
+ Element element = getElement();
+ String href = findAndReplaceElVariable(element
+ .getAttribute(hrefAttrName));
+
+ IDOMModel baseModel = ((IDOMNode) element).getModel();
+ if (baseModel == null)
+ return null;
+ Object id = baseModel.getId();
+ if (!(id instanceof String))
+ return null;
+ // String base = (String)id;
+
+ // get ModelProvideAdapter
+ IModelProvideAdapter adapter = (IModelProvideAdapter) ((INodeNotifier) getElement())
+ .getAdapterFor(IModelProvideAdapter.class);
+
+ URLModelProvider provider = new URLModelProvider();
+ try {
+ IStructuredModel newModel = provider.getModelForRead(baseModel,
+ href);
+ if (newModel == null)
+ return null;
+ if (!(newModel instanceof ICSSModel)) {
+ newModel.releaseFromRead();
+ return null;
+ }
+
+ // notify adapter
+ if (adapter != null)
+ adapter.modelProvided(newModel);
+
+ return (ICSSModel) newModel;
+ } catch (UnsupportedEncodingException e) {
+ } catch (IOException e) {
+ }
+
+ return null;
+ }
+ }
}
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/IncludeContextBuilder.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/IncludeContextBuilder.java 2009-10-19
12:55:43 UTC (rev 18154)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/IncludeContextBuilder.java 2009-10-19
13:18:23 UTC (rev 18155)
@@ -19,7 +19,8 @@
public static final String TAG_ATTRIBUTE = "attribute"; //$NON-NLS-1$
public static final String TAG_CONTEXTTYPE = "contexttype"; //$NON-NLS-1$
public static final String TAG_CONTENTTYPE = "contenttype"; //$NON-NLS-1$
-
+ public static final String TAG_CSSHOLDER = "cssholder"; //$NON-NLS-1$
+
public static final String ATT_ID = "id"; //$NON-NLS-1$
public static final String ATT_URI = "uri"; //$NON-NLS-1$
public static final String ATT_NAME = "name"; //$NON-NLS-1$
@@ -70,30 +71,47 @@
* open on object. Creates a new open on definition object and adds it to the
* list of open on definition objects
*
- * @param element hyperlink configuration element
+ * @param element configuration element
*/
- private void processIncludeElement(IConfigurationElement element) {
+ private void processIncludeContextElement(IConfigurationElement element) {
String theUri = getUri(element);
-// String theResolver = getIncludeResolver(element);
theUri = theUri == null ? "" : theUri; //$NON-NLS-1$
- // start building new HyperlinkDefinition
- fCurrentIncludeDefinition = new IncludeContextDefinition(theUri, element);
-
- // create a new list of open on definitions if it hasnt been created yet
+ // create a new list of open on definitions if it hasn't been created yet
if (fIncludeContextDefs == null) {
fIncludeContextDefs = new ArrayList<IncludeContextDefinition>();
}
- fIncludeContextDefs.add(fCurrentIncludeDefinition);
+
+ fCurrentIncludeDefinition = getIncludeContextDefinition(theUri);
+ if (fCurrentIncludeDefinition == null) {
+ // start building new IncludeDefinition
+ fCurrentIncludeDefinition = new IncludeContextDefinition(theUri);
+ fIncludeContextDefs.add(fCurrentIncludeDefinition);
+ }
}
- private void processTagElement(IConfigurationElement element) {
+ IncludeContextDefinition getIncludeContextDefinition(String uri) {
+ if (fIncludeContextDefs == null || uri == null)
+ return null;
+
+ for (IncludeContextDefinition def : fIncludeContextDefs) {
+ if (uri.equals(def.getUri())) {
+ return def;
+ }
+ }
+
+ return null;
+ }
+
+ private boolean processTagElement(IConfigurationElement element) {
String theName = getName(element);
if (fCurrentIncludeDefinition != null && theName != null) {
- fCurrentIncludeDefinition.addTag(theName, element);
+ return fCurrentIncludeDefinition.addTag(theName, element);
}
+
+ return false;
}
private void processAttributeElement(IConfigurationElement element) {
@@ -127,9 +145,9 @@
protected boolean readElement(IConfigurationElement element) {
String tag = element.getName();
- if (tag.equals(fTargetContributionElement)) {
- processIncludeElement(element);
-
+ if (tag.equals(TAG_INCLUDE) || tag.equals(TAG_CSSHOLDER)) {
+ processIncludeContextElement(element);
+
// make sure processing of current open on tag resulted in a current open on
definition
// before continue reading the children
if (fCurrentIncludeDefinition != null) {
@@ -190,7 +208,7 @@
return fIncludeContextDefs;
}
- public static String[] getIncludeAttributes(String uri, String tag) {
+ public static String[] getIncludeAttributes(String uri, String tagName) {
if (uri == null)
return null;
@@ -198,13 +216,18 @@
if (defs == null)
return null;
+ List<String> attrs = new ArrayList<String>();
+
for (IncludeContextDefinition def : defs) {
if (uri.equals(def.getUri())) {
- return def.getTagAttributes(tag);
+ String[] defAttrs = def.getIncludeTagAttributes(tagName);
+ if (defAttrs != null) {
+ for (String attr : defAttrs) attrs.add(attr);
+ }
}
}
- return null;
+ return attrs.size() == 0 ? null : attrs.toArray(new String[attrs.size()]);
}
public static String getContextType(String contentType) {
@@ -223,4 +246,57 @@
return null;
}
+
+ public static boolean isCSSStyleSheetContainer(String uri, String tagName) {
+ if (uri == null)
+ return false;
+
+ List<IncludeContextDefinition> defs =
IncludeContextBuilder.getInstance().getIncludeContextDefinitions();
+ if (defs == null)
+ return false;
+
+ boolean isHolder = false;
+ for (IncludeContextDefinition def : defs) {
+ if (uri.equals(def.getUri())) {
+ String[] defTags = def.getCSSTags();
+ if (defTags != null) {
+ for (String tag : defTags) {
+ if (tagName.equals(tag)) {
+ isHolder = true;
+ // Check that the tag have no attributes defined
+ // If so - the tag itself is used to define the CSS
+ // But if the tag has at least one attribute defined - it's not the holder
+ String[] attrs = def.getCSSTagAttributes(tagName);
+ isHolder ^= (attrs != null && attrs.length > 0);
+ }
+ }
+ }
+ }
+ }
+
+ return isHolder;
+ }
+
+ public static String[] getCSSStyleSheetAttributes(String uri, String tagName) {
+ if (uri == null)
+ return null;
+
+ List<IncludeContextDefinition> defs =
IncludeContextBuilder.getInstance().getIncludeContextDefinitions();
+ if (defs == null)
+ return null;
+
+ List<String> attrs = new ArrayList<String>();
+
+ for (IncludeContextDefinition def : defs) {
+ if (uri.equals(def.getUri())) {
+ String[] defAttrs = def.getCSSTagAttributes(tagName);
+ if (defAttrs != null) {
+ for (String attr : defAttrs) attrs.add(attr);
+ }
+ }
+ }
+
+ return attrs.size() == 0 ? null : attrs.toArray(new String[attrs.size()]);
+
+ }
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/IncludeContextDefinition.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/IncludeContextDefinition.java 2009-10-19
12:55:43 UTC (rev 18154)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/IncludeContextDefinition.java 2009-10-19
13:18:23 UTC (rev 18155)
@@ -11,20 +11,13 @@
import org.eclipse.ui.internal.EarlyStartupRunnable;
public class IncludeContextDefinition {
- private IConfigurationElement fElement;
private String fUri;
- private Map<String, Set<String>> fTags; // Map<TagName,
Set<AttributeName>>
- private Map<IConfigurationElement, String> fTagConfigurationElements;
+ private Map<String, Set<String>> fIncludeTags; // Map<TagName,
Set<AttributeName>>
+ private Map<String, Set<String>> fCSSTags; // Map<TagName,
Set<AttributeName>>
private Map<String, Set<String>> fContexts; // Map<ContextType,
Set<ContentType>>
- private Map<IConfigurationElement, String> fContextConfigurationElements;
- public IncludeContextDefinition(IConfigurationElement element) {
- this.fElement = element;
- }
-
- public IncludeContextDefinition(String uri, IConfigurationElement element) {
+ public IncludeContextDefinition(String uri) {
this.fUri = uri;
- this.fElement = element;
}
public String getUri() {
@@ -35,21 +28,37 @@
this.fUri = uri;
}
- public void addTag(String tagName, IConfigurationElement element) {
- if (fTags == null) {
- fTags = new HashMap<String, Set<String>>();
+ public boolean addTag(String tagName, IConfigurationElement element) {
+ if (isInParentElements(element, IncludeContextBuilder.TAG_INCLUDE)) {
+ addIncludeTag(tagName, element);
+ return true;
+ } else if (isInParentElements(element, IncludeContextBuilder.TAG_CSSHOLDER)) {
+ addCSSTag(tagName, element);
+ return true;
}
- Set<String> tagSet = fTags.get(tagName);
+ return false;
+ }
+
+ public void addIncludeTag(String tagName, IConfigurationElement element) {
+ if (fIncludeTags == null) {
+ fIncludeTags = new HashMap<String, Set<String>>();
+ }
+ Set<String> tagSet = fIncludeTags.get(tagName);
if (tagSet == null) {
tagSet = new HashSet<String>();
- fTags.put(tagName, tagSet);
+ fIncludeTags.put(tagName, tagSet);
}
-
- if (fTagConfigurationElements == null) {
- fTagConfigurationElements = new HashMap<IConfigurationElement, String>();
+ }
+
+ public void addCSSTag(String tagName, IConfigurationElement element) {
+ if (fCSSTags == null) {
+ fCSSTags = new HashMap<String, Set<String>>();
}
-
- fTagConfigurationElements.put(element, tagName);
+ Set<String> tagSet = fCSSTags.get(tagName);
+ if (tagSet == null) {
+ tagSet = new HashSet<String>();
+ fCSSTags.put(tagName, tagSet);
+ }
}
public void addTagAttribute(String attributeName, IConfigurationElement element) {
@@ -67,13 +76,33 @@
}
parentTagName = parentTagName == null ? "" : parentTagName; //$NON-NLS-1$
- if (fTags.get(parentTagName) == null) {
- addTag(parentTagName, parentTagElement);
+ if (isInParentElements(element, IncludeContextBuilder.TAG_INCLUDE)) {
+ if (fIncludeTags.get(parentTagName) == null) {
+ addIncludeTag(parentTagName, parentTagElement);
+ }
+
+ fIncludeTags.get(parentTagName).add(attributeName);
+ } else if (isInParentElements(element, IncludeContextBuilder.TAG_CSSHOLDER)) {
+ if (fCSSTags.get(parentTagName) == null) {
+ addCSSTag(parentTagName, parentTagElement);
+ }
+
+ fCSSTags.get(parentTagName).add(attributeName);
}
-
- fTags.get(parentTagName).add(attributeName);
}
+ private boolean isInParentElements(IConfigurationElement element, String elementName) {
+ Object parent = element.getParent();
+ while (parent instanceof IConfigurationElement) {
+ IConfigurationElement parentElement = (IConfigurationElement)parent;
+ if (elementName.equals(parentElement.getName())) {
+ return true;
+ }
+ parent = parentElement.getParent();
+ }
+ return false;
+ }
+
public void addContextType(String id, IConfigurationElement element) {
if (fContexts == null) {
fContexts = new HashMap<String, Set<String>>();
@@ -84,11 +113,6 @@
fContexts.put(id, contextSet);
}
- if (fContextConfigurationElements == null) {
- fContextConfigurationElements = new HashMap<IConfigurationElement, String>();
- }
-
- fContextConfigurationElements.put(element, id);
}
public boolean addContentType(String id, IConfigurationElement element) {
@@ -115,18 +139,29 @@
private static final String[] EMPTY_CHILDREN = new String[0];
- public String[] getTags() {
- return fTags == null ? EMPTY_CHILDREN :
- (String[])fTags.keySet().toArray(new String[fTags.size()]);
+ public String[] getIncludeTags() {
+ return fIncludeTags == null ? EMPTY_CHILDREN :
+ (String[])fIncludeTags.keySet().toArray(new String[fIncludeTags.size()]);
+ }
+
+ public String[] getCSSTags() {
+ return fCSSTags == null ? EMPTY_CHILDREN :
+ (String[])fCSSTags.keySet().toArray(new String[fCSSTags.size()]);
}
- public String[] getTagAttributes(String tagName) {
- Set<String> attrSet = fTags.get(tagName);
+ public String[] getIncludeTagAttributes(String tagName) {
+ Set<String> attrSet = fIncludeTags == null ? null : fIncludeTags.get(tagName);
return attrSet == null ? EMPTY_CHILDREN :
(String[])attrSet.toArray(new String[attrSet.size()]);
}
-
+
+ public String[] getCSSTagAttributes(String tagName) {
+ Set<String> attrSet = fCSSTags == null ? null : fCSSTags.get(tagName);
+
+ return attrSet == null ? EMPTY_CHILDREN :
+ (String[])attrSet.toArray(new String[attrSet.size()]);
+ }
public String getContextType(String contentType) {
if (fContexts == null)
return null;
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/JspContextImpl.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/JspContextImpl.java 2009-10-19
12:55:43 UTC (rev 18154)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/JspContextImpl.java 2009-10-19
13:18:23 UTC (rev 18155)
@@ -16,19 +16,21 @@
import java.util.Map;
import java.util.Set;
+import org.jboss.tools.jst.web.kb.ICSSContainerSupport;
import org.jboss.tools.jst.web.kb.IIncludedContextSupport;
import org.jboss.tools.jst.web.kb.IPageContext;
import org.jboss.tools.jst.web.kb.IResourceBundle;
import org.jboss.tools.jst.web.kb.internal.taglib.NameSpace;
import org.jboss.tools.jst.web.kb.taglib.INameSpace;
+import org.w3c.dom.css.CSSStyleSheet;
/**
* JSP page context
* @author Alexey Kazakov
*/
-public class JspContextImpl extends XmlContextImpl {
+public class JspContextImpl extends XmlContextImpl implements ICSSContainerSupport {
protected List<IPageContext> fIncludedContexts = null;
-
+ protected List<CSSStyleSheet> fCSSStyleSheets = null;
@Override
@@ -54,5 +56,37 @@
return superNameSpaces;
}
+
+ public void addCSSStyleSheet(CSSStyleSheet cssStyleSheet) {
+ if (fCSSStyleSheets == null) {
+ fCSSStyleSheets = new ArrayList<CSSStyleSheet>();
+ }
+ fCSSStyleSheets.add(cssStyleSheet);
+ }
+
+ public List<CSSStyleSheet> getCSSStyleSheets() {
+ List<CSSStyleSheet> sheets = new ArrayList<CSSStyleSheet>();
+
+ if (fCSSStyleSheets != null) {
+ for (CSSStyleSheet sheet : fCSSStyleSheets) {
+ sheets.add(sheet);
+ }
+ }
+
+ List<IPageContext> includedContexts = getIncludedContexts();
+ if (includedContexts != null) {
+ for (IPageContext includedContext : includedContexts) {
+ if (includedContext instanceof ICSSContainerSupport) {
+ List<CSSStyleSheet> includedSheets =
((ICSSContainerSupport)includedContext).getCSSStyleSheets();
+ if (includedSheets != null) {
+ sheets.addAll(includedSheets);
+ }
+ }
+ }
+ }
+
+ return sheets;
+
+ }
}
\ No newline at end of file
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/CSSClassProposalType.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/CSSClassProposalType.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/CSSClassProposalType.java 2009-10-19
13:18:23 UTC (rev 18155)
@@ -0,0 +1,133 @@
+package org.jboss.tools.jst.web.kb.internal.taglib;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+import org.jboss.tools.common.text.TextProposal;
+import org.jboss.tools.jst.web.kb.ICSSContainerSupport;
+import org.jboss.tools.jst.web.kb.IPageContext;
+import org.jboss.tools.jst.web.kb.KbQuery;
+import org.jboss.tools.jst.web.kb.WebKbPlugin;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.css.CSSRule;
+import org.w3c.dom.css.CSSRuleList;
+import org.w3c.dom.css.CSSStyleSheet;
+
+public class CSSClassProposalType extends CustomProposalType {
+ private static final String IMAGE_NAME = "EnumerationProposal.gif";
//$NON-NLS-1$
+ private static Image ICON;
+
+ static String ID = "cssclass"; //$NON-NLS-1$
+ static String QUOTE_1 = "'"; //$NON-NLS-1$
+ static String QUOTE_2 = "\""; //$NON-NLS-1$
+ Set<String> idList = new TreeSet<String>();
+
+ @Override
+ protected void init(IPageContext context) {
+ idList.clear();
+ if (context instanceof ICSSContainerSupport) {
+ ICSSContainerSupport cssSource = (ICSSContainerSupport)context;
+
+ List<CSSStyleSheet> sheets = cssSource.getCSSStyleSheets();
+ if (sheets != null) {
+ for (CSSStyleSheet sheet : sheets) {
+ CSSRuleList rules = sheet.getCssRules();
+ for (int i = 0; rules != null && i < rules.getLength(); i++) {
+ CSSRule rule = rules.item(i);
+ idList.addAll(getNamesFromCSSRule(rule));
+ }
+ }
+ }
+
+ }
+ }
+
+ /**
+ *
+ * @param cssRule
+ * @param styleName
+ * @return
+ */
+ private Set<String> getNamesFromCSSRule(CSSRule cssRule) {
+ Set<String> styleNames = new
TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
+
+ // get selector text
+ String selectorText = ((ICSSStyleRule) cssRule).getSelectorText();
+
+ if (selectorText != null) {
+ String styles[] = selectorText.trim().split(","); //$NON-NLS-1$
+ for (String styleText : styles) {
+ String[] styleWords = styleText.trim().split(" "); //$NON-NLS-1$
+ if (styleWords != null) {
+ for (String name : styleWords) {
+ if (name.startsWith(".")) //$NON-NLS-1$
+ continue;
+
+ if (name.indexOf("[") >= 0) { //$NON-NLS-1$
+ name = name.substring(0, name.indexOf("[")); //$NON-NLS-1$
+ }
+ if (name.indexOf(".") >= 0) { //$NON-NLS-1$
+ name = name.substring(0, name.indexOf(".")); //$NON-NLS-1$
+ }
+ if (name.indexOf(":") >= 0) { //$NON-NLS-1$
+ name = name.substring(0, name.indexOf(":")); //$NON-NLS-1$
+ }
+
+ // Use the first word as a style name
+ styleNames.add(name);
+ }
+ }
+ }
+ }
+ return styleNames;
+ }
+
+ @Override
+ public TextProposal[] getProposals(KbQuery query) {
+ String v = query.getValue();
+ int offset = v.length();
+ int b = v.lastIndexOf(',');
+ if(b < 0) b = 0; else b += 1;
+ String tail = v.substring(offset);
+ int e = tail.indexOf(',');
+ if(e < 0) e = v.length(); else e += offset;
+ String prefix = v.substring(b).trim();
+
+ List<TextProposal> proposals = new ArrayList<TextProposal>();
+ for (String text: idList) {
+ if(text.startsWith(prefix)) {
+ TextProposal proposal = new TextProposal();
+ proposal.setLabel(text);
+ proposal.setReplacementString(text);
+ proposal.setPosition(b + text.length());
+ proposal.setStart(b);
+ proposal.setEnd(e);
+ if(ICON==null) {
+ ICON = ImageDescriptor.createFromFile(WebKbPlugin.class, IMAGE_NAME).createImage();
+ }
+ proposal.setImage(ICON);
+
+ proposals.add(proposal);
+ }
+ }
+
+ return proposals.toArray(new TextProposal[0]);
+ }
+
+}
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/CSSClassProposalType.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/CustomProposalTypeFactory.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/CustomProposalTypeFactory.java 2009-10-19
12:55:43 UTC (rev 18154)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/CustomProposalTypeFactory.java 2009-10-19
13:18:23 UTC (rev 18155)
@@ -28,6 +28,7 @@
public static final String ID_TYPE = "id"; //$NON-NLS-1$
public static final String CONVERTER_ID_TYPE = "converterID"; //$NON-NLS-1$
public static final String VALIDATOR_ID_TYPE = "validatorID"; //$NON-NLS-1$
+ public static final String CSSCLASS_TYPE = "cssclass"; //$NON-NLS-1$
private CustomProposalTypeFactory() {
}
@@ -72,6 +73,9 @@
if(VALIDATOR_ID_TYPE.equals(type)) {
return new ValidatorIDProposalType();
}
+ if(CSSCLASS_TYPE.equals(type)) {
+ return new CSSClassProposalType();
+ }
//WebKbPlugin.getDefault().logError("Unknown proposal type: " + type);
//$NON-NLS-1$
//ExtendedProposalType will report if necessary
Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/taglibs/componentExtension.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/taglibs/componentExtension.xml 2009-10-19
12:55:43 UTC (rev 18154)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/taglibs/componentExtension.xml 2009-10-19
13:18:23 UTC (rev 18155)
@@ -64,4 +64,28 @@
<attribute name="converter">
<proposal type="converterID"/>
</attribute>
+ <attribute name="class">
+ <proposal type="cssclass"/>
+ </attribute>
+ <attribute name="styleClass">
+ <proposal type="cssclass"/>
+ </attribute>
+ <attribute name="captionClass">
+ <proposal type="cssclass"/>
+ </attribute>
+ <attribute name="columnClasses">
+ <proposal type="cssclass"/>
+ </attribute>
+ <attribute name="rowClasses">
+ <proposal type="cssclass"/>
+ </attribute>
+ <attribute name="bodyClass">
+ <proposal type="cssclass"/>
+ </attribute>
+ <attribute name="headerClass">
+ <proposal type="cssclass"/>
+ </attribute>
+ <attribute name="footerClass">
+ <proposal type="cssclass"/>
+ </attribute>
</component-extension>
\ No newline at end of file