Author: vrubezhny
Date: 2009-11-24 09:01:57 -0500 (Tue, 24 Nov 2009)
New Revision: 18798
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/AbstractHyperlink.java
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext.richfaces/src/org/jboss/tools/jsf/text/ext/richfaces/hyperlink/RichfacesCSSClassHyperlink.java
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext.richfaces/src/org/jboss/tools/jsf/text/ext/richfaces/hyperlink/RichfacesCSSClassHyperlinkPartitioner.java
trunk/jst/plugins/org.jboss.tools.jst.text.ext/META-INF/MANIFEST.MF
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/CSSClassHyperlink.java
Log:
JBIDE-5237: Update existing CSS Class Hyperlink for "class" attribute of
HTML-tags to search thru CSS Stylesheets loaded using JSF tags like <a:loadStyle />
JBIDE-5149: Make OpenOn work for styleClass="|"
Issues are fixed
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/AbstractHyperlink.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/AbstractHyperlink.java 2009-11-24
13:56:15 UTC (rev 18797)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/AbstractHyperlink.java 2009-11-24
14:01:57 UTC (rev 18798)
@@ -46,6 +46,7 @@
/**
*
*/
+@SuppressWarnings("restriction")
abstract public class AbstractHyperlink extends AbstractBaseHyperlink implements
IHyperlink {
public static final String DOLLAR_PREFIX = "${"; //$NON-NLS-1$
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext.richfaces/src/org/jboss/tools/jsf/text/ext/richfaces/hyperlink/RichfacesCSSClassHyperlink.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext.richfaces/src/org/jboss/tools/jsf/text/ext/richfaces/hyperlink/RichfacesCSSClassHyperlink.java 2009-11-24
13:56:15 UTC (rev 18797)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext.richfaces/src/org/jboss/tools/jsf/text/ext/richfaces/hyperlink/RichfacesCSSClassHyperlink.java 2009-11-24
14:01:57 UTC (rev 18798)
@@ -1,3 +1,14 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
package org.jboss.tools.jsf.text.ext.richfaces.hyperlink;
import java.text.MessageFormat;
@@ -3,49 +14,23 @@
import java.util.List;
-import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Region;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.jboss.tools.common.el.core.resolver.ELContext;
import org.jboss.tools.common.text.ext.hyperlink.xpl.Messages;
import org.jboss.tools.jst.text.ext.hyperlink.CSSClassHyperlink;
import org.jboss.tools.jst.web.kb.ICSSContainerSupport;
-import org.jboss.tools.jst.web.kb.IPageContext;
import org.jboss.tools.jst.web.kb.PageContextFactory;
import org.jboss.tools.jst.web.kb.PageContextFactory.CSSStyleSheetDescriptor;
import org.w3c.dom.css.CSSRule;
import org.w3c.dom.css.CSSRuleList;
+/**
+ *
+ * @author Victor Rubezhny
+ *
+ */
+@SuppressWarnings("restriction")
public class RichfacesCSSClassHyperlink extends CSSClassHyperlink {
-
- @Override
- protected void doHyperlink(IRegion region) {
- ICSSContainerSupport cssContainerSupport = null;
- IPageContext context = PageContextFactory.createPageContext(getFile(),
region.getOffset(), getContentType(getDocument()));
- if (!(context instanceof ICSSContainerSupport)) {
- openFileFailed();
- return;
- }
- cssContainerSupport = (ICSSContainerSupport)context;
- List<CSSStyleSheetDescriptor> descrs =
cssContainerSupport.getCSSStyleSheetDescriptors();
-
- for (int i = (descrs == null) ? -1 : descrs.size() - 1; descrs != null && i
>= 0; i--) {
- CSSStyleSheetDescriptor descr = descrs.get(i);
- CSSRuleList rules = descr.sheet.getCssRules();
- for (int r = 0; rules != null && r < rules.getLength(); r++) {
- if (isRuleMatch(rules.item(r), getStyleName(region))) {
- CSSRule rule = rules.item(r);
- System.out.println();
- showRegion(
- PageContextFactory.getFileFromProject(descr.source, getFile()),
- new Region(((IndexedRegion)rule).getStartOffset(),
((IndexedRegion)rule).getLength()));
- return;
- }
- }
- }
- }
-
/*
* (non-Javadoc)
@@ -60,31 +45,4 @@
return MessageFormat.format(Messages.OpenCSSStyle, styleName);
}
-
-
- /**
- * Returns the content type of document
- *
- * @param document -
- * assumes document is not null
- * @return String content type of given document
- */
- @SuppressWarnings("restriction")
- private String getContentType(IDocument document) {
- String type = null;
-
- IModelManager mgr = StructuredModelManager.getModelManager();
- IStructuredModel model = null;
- try {
- model = mgr.getExistingModelForRead(document);
- if (model != null) {
- type = model.getContentTypeIdentifier();
- }
- } finally {
- if (model != null) {
- model.releaseFromRead();
- }
- }
- return type;
- }
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext.richfaces/src/org/jboss/tools/jsf/text/ext/richfaces/hyperlink/RichfacesCSSClassHyperlinkPartitioner.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext.richfaces/src/org/jboss/tools/jsf/text/ext/richfaces/hyperlink/RichfacesCSSClassHyperlinkPartitioner.java 2009-11-24
13:56:15 UTC (rev 18797)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext.richfaces/src/org/jboss/tools/jsf/text/ext/richfaces/hyperlink/RichfacesCSSClassHyperlinkPartitioner.java 2009-11-24
14:01:57 UTC (rev 18798)
@@ -1,3 +1,14 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
package org.jboss.tools.jsf.text.ext.richfaces.hyperlink;
import org.eclipse.jface.text.IDocument;
@@ -4,6 +15,11 @@
import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkRegion;
import org.jboss.tools.jst.text.ext.hyperlink.CSSClassHyperlinkPartitioner;
+/**
+ *
+ * @author Victor Rubezhny
+ *
+ */
public class RichfacesCSSClassHyperlinkPartitioner extends CSSClassHyperlinkPartitioner
{
public static final String RICHFACES_CSS_CLASS_PARTITION =
"org.jboss.tools.common.text.ext.RICHFACES_CSS_CLASS"; //$NON-NLS-1$
private static final String RICHFACES_CSS_CLASS_TOKEN = "/styleClass/";
//$NON-NLS-1$
Modified: trunk/jst/plugins/org.jboss.tools.jst.text.ext/META-INF/MANIFEST.MF
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.text.ext/META-INF/MANIFEST.MF 2009-11-24
13:56:15 UTC (rev 18797)
+++ trunk/jst/plugins/org.jboss.tools.jst.text.ext/META-INF/MANIFEST.MF 2009-11-24
14:01:57 UTC (rev 18798)
@@ -28,5 +28,6 @@
org.jboss.tools.common.el.core;bundle-version="2.0.0",
org.eclipse.emf.ecore;bundle-version="2.5.0",
org.eclipse.wst.css.core,
- org.eclipse.wst.html.core
+ org.eclipse.wst.html.core,
+ org.jboss.tools.jst.web.kb
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Modified:
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/CSSClassHyperlink.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/CSSClassHyperlink.java 2009-11-24
13:56:15 UTC (rev 18797)
+++
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/CSSClassHyperlink.java 2009-11-24
14:01:57 UTC (rev 18798)
@@ -10,12 +10,8 @@
******************************************************************************/
package org.jboss.tools.jst.text.ext.hyperlink;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
import java.text.MessageFormat;
-import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Matcher;
@@ -29,200 +25,69 @@
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.ide.IDE;
-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.ICSSDocument;
import org.eclipse.wst.css.core.internal.provisional.document.ICSSModel;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule;
import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet;
-import org.eclipse.wst.html.core.internal.htmlcss.LinkElementAdapter;
-import org.eclipse.wst.html.core.internal.htmlcss.URLModelProvider;
-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.xml.core.internal.provisional.document.IDOMDocument;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.jboss.tools.common.el.core.resolver.ELContext;
import org.jboss.tools.common.text.ext.ExtensionsPlugin;
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
import org.jboss.tools.common.text.ext.hyperlink.xpl.Messages;
-import org.jboss.tools.common.text.ext.util.RegionHolder;
import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
import org.jboss.tools.common.text.ext.util.StructuredSelectionHelper;
import org.jboss.tools.common.text.ext.util.Utils;
+import org.jboss.tools.jst.web.kb.ICSSContainerSupport;
+import org.jboss.tools.jst.web.kb.PageContextFactory;
+import org.jboss.tools.jst.web.kb.PageContextFactory.CSSStyleSheetDescriptor;
import org.w3c.dom.Attr;
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;
/**
* @author Jeremy
*/
+@SuppressWarnings("restriction")
public class CSSClassHyperlink extends AbstractHyperlink {
public static final String[] STYLE_TAGS = new String[] { "style",
"link" }; //$NON-NLS-1$//$NON-NLS-2$
public static final String LINK_TAG = "link"; //$NON-NLS-1$
public static final String HREF_ATTRIBUTE = "href"; //$NON-NLS-1$
- public static final String COMPARE_CLASS_REGEX_PREFIX = "[\\.]?";
//$NON-NLS-1$
+ public static final String COMPARE_CLASS_REGEX_PREFIX =
"([A-Za-z_][A-Za-z_0-9\\-]*)*[\\.]?"; //$NON-NLS-1$
public static final String CONTEXT_PATH_EXPRESSION =
"^\\s*(\\#|\\$)\\{facesContext.externalContext.requestContextPath\\}";
//$NON-NLS-1$
-
- /**
- *
- */
+
+ @Override
protected void doHyperlink(IRegion region) {
-
- IDOMModel model = (IDOMModel) getModelManager()
- .getExistingModelForRead(getDocument());
-
- // get name of looked for style
- String styleName = getStyleName(region);
-
- // get elements which copntans information about styles (style and link
- // tags)
- List<Node> styleElementList = getStyleContainerList(model);
-
- // sort nodes by position in inverse order - from larger position to
- // smaller
- Collections.sort(styleElementList, new Comparator<Node>() {
-
- public int compare(Node o1, Node o2) {
- return ((IDOMNode) o2).getStartOffset()
- - ((IDOMNode) o1).getStartOffset();
- }
-
- });
-
- RegionHolder styleRegion = null;
- // look for style in each Style element
- for (Node styleContainer : styleElementList) {
-
- styleRegion = findStyleRegion(styleContainer, styleName);
-
- if (styleRegion != null) {
- showRegion(styleRegion);
- break;
- }
-
+ ICSSContainerSupport cssContainerSupport = null;
+ ELContext context = PageContextFactory.createPageContext(getFile());
+ if (!(context instanceof ICSSContainerSupport)) {
+ openFileFailed();
+ return;
}
+ cssContainerSupport = (ICSSContainerSupport)context;
+ List<CSSStyleSheetDescriptor> descrs =
cssContainerSupport.getCSSStyleSheetDescriptors();
- model.releaseFromRead();
- }
-
- /**
- *
- * @param model
- * @return
- */
- private List<Node> getStyleContainerList(IDOMModel model) {
-
- // get model of current page
- IDOMDocument document = model.getDocument();
-
- List<Node> getStyleContainerList = new ArrayList<Node>();
-
- // get all tags which contains style ( link, style)
- for (String tagName : STYLE_TAGS) {
- getStyleContainerList.addAll(getList(document
- .getElementsByTagName(tagName)));
- }
-
- return getStyleContainerList;
- }
-
- /**
- * move nodes from NodeList to List
- *
- * @param nodeList
- * @return
- */
- List<Node> getList(NodeList nodeList) {
-
- List<Node> newContainerList = new ArrayList<Node>();
- for (int i = 0; i < nodeList.getLength(); i++) {
- newContainerList.add(nodeList.item(i));
- }
- return newContainerList;
- }
-
- /**
- *
- * @param stylesContainer
- * @param styleName
- * @return
- */
- public RegionHolder findStyleRegion(Node stylesContainer, String styleName) {
-
- // get style sheet
- CSSStyleSheet sheet = getSheet(stylesContainer);
-
- if (sheet != null) {
-
- CSSRuleList ruleList = sheet.getCssRules();
-
- // for each cssRule
- for (int i = 0; i < ruleList.getLength(); i++) {
-
- CSSRule cssRule = ruleList.item(i);
-
- // if cssRule describe looked for style
- if (isRuleMatch(cssRule, styleName)) {
-
- return new RegionHolder(getFile((ICSSNode) cssRule),
- getRegion(cssRule));
-
+ for (int i = (descrs == null) ? -1 : descrs.size() - 1; descrs != null && i
>= 0; i--) {
+ CSSStyleSheetDescriptor descr = descrs.get(i);
+ CSSRuleList rules = descr.sheet.getCssRules();
+ for (int r = 0; rules != null && r < rules.getLength(); r++) {
+ if (isRuleMatch(rules.item(r), getStyleName(region))) {
+ CSSRule rule = rules.item(r);
+ System.out.println();
+ showRegion(
+ PageContextFactory.getFileFromProject(descr.source, getFile()),
+ new Region(((IndexedRegion)rule).getStartOffset(),
((IndexedRegion)rule).getLength()));
+ return;
}
}
-
}
- return null;
+ openFileFailed();
}
/**
*
- * @param stylesContainer
- * @return
- */
- private CSSStyleSheet getSheet(final Node stylesContainer) {
-
- INodeNotifier notifier = (INodeNotifier) stylesContainer;
-
- IStyleSheetAdapter adapter = (IStyleSheetAdapter) notifier
- .getAdapterFor(IStyleSheetAdapter.class);
-
- if (LINK_TAG.equalsIgnoreCase(stylesContainer.getNodeName())
- && !(adapter instanceof ExtendedLinkElementAdapter)) {
-
- notifier.removeAdapter(adapter);
- adapter = new ExtendedLinkElementAdapter(
- (Element) stylesContainer);
- notifier.addAdapter(adapter);
-
- }
-
- CSSStyleSheet sheet = null;
-
- if (adapter != null) {
- sheet = (CSSStyleSheet) adapter.getSheet();
-
- }
-
- return sheet;
-
- }
-
- protected String processURL(String href) {
- // TODO Auto-generated method stub
- return null;
- }
-
- /**
- *
* @param cssRule
* @param styleName
* @return
@@ -237,19 +102,20 @@
for (String styleText : styles) {
String[] styleWords = styleText.trim().split(" "); //$NON-NLS-1$
if (styleWords != null) {
- int searchIndex = Arrays.binarySearch(styleWords, styleName,
- new Comparator<String>() {
-
- public int compare(String o1, String o2) {
- Matcher matcher = Pattern.compile(
- COMPARE_CLASS_REGEX_PREFIX + o2)
- .matcher(o1);
- return matcher.matches() ? 0 : 1;
- }
-
- });
- if (searchIndex >= 0)
- return true;
+ int searchIndex = Arrays.binarySearch(styleWords, styleName,
+ new Comparator<String>() {
+
+ public int compare(String o1, String o2) {
+ Matcher matcher = Pattern.compile(
+ COMPARE_CLASS_REGEX_PREFIX + o2)
+ .matcher(o1);
+
+ return matcher.matches() ? 0 : 1;
+ }
+
+ });
+ if (searchIndex >= 0)
+ return true;
}
}
}
@@ -258,18 +124,6 @@
/**
*
- * @param node
- * @return
- */
- private IFile getFile(ICSSNode node) {
-
- ICSSDocument sheet = node.getOwnerDocument();
-
- return AbstractHyperlink.getFile(sheet.getModel());
- }
-
- /**
- *
* @param cssRule
* @return
*/
@@ -299,30 +153,6 @@
*
* @param styleRegion
*/
- protected void showRegion(RegionHolder styleRegion) {
-
- IWorkbenchPage workbenchPage = ExtensionsPlugin.getDefault()
- .getWorkbench().getActiveWorkbenchWindow().getActivePage();
- IEditorPart part = null;
- if (styleRegion.file != null) {
- try {
- part = IDE.openEditor(workbenchPage, styleRegion.file, true);
- } catch (PartInitException e) {
- e.printStackTrace();
- }
- if (part == null) {
- openFileFailed();
- return;
- }
- }
- StructuredSelectionHelper.setSelectionAndReveal(part,
- styleRegion.region);
- }
-
- /**
- *
- * @param styleRegion
- */
protected void showRegion(IFile file, IRegion region) {
IWorkbenchPage workbenchPage = ExtensionsPlugin.getDefault()
@@ -343,7 +173,6 @@
region);
}
-
/**
*
* @param region
@@ -447,91 +276,8 @@
@Override
protected String findAndReplaceElVariable(String fileName) {
if (fileName != null)
- fileName = fileName
- .replaceFirst(
- "^\\s*(\\#|\\$)\\{facesContext.externalContext.requestContextPath\\}",
- "");
+ fileName = fileName.replaceFirst(CONTEXT_PATH_EXPRESSION,""); //$NON-NLS-1$
+
return super.findAndReplaceElVariable(fileName);
}
-
- public class ExtendedLinkElementAdapter extends LinkElementAdapter {
-
- private Element element;
-
- public ExtendedLinkElementAdapter(Element element) {
- this.element = element;
- }
-
- @Override
- public Element getElement() {
- return element;
- }
-
- @Override
- protected boolean isValidAttribute() {
- String href = getElement().getAttribute(HREF_ATTRIBUTE);
- 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(HREF_ATTRIBUTE));
-
- 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