Author: scabanovich
Date: 2009-04-22 11:59:03 -0400 (Wed, 22 Apr 2009)
New Revision: 14852
Added:
trunk/seam/plugins/org.jboss.tools.seam.xml/src/org/jboss/tools/seam/xml/components/model/SeamPromptingProvider.java
trunk/seam/plugins/org.jboss.tools.seam.xml/src/org/jboss/tools/seam/xml/components/model/helpers/
trunk/seam/plugins/org.jboss.tools.seam.xml/src/org/jboss/tools/seam/xml/components/model/helpers/OpenRuleHelper.java
Modified:
trunk/seam/plugins/org.jboss.tools.seam.xml/plugin.xml
Log:
https://jira.jboss.org/jira/browse/JBIDE-3804
Modified: trunk/seam/plugins/org.jboss.tools.seam.xml/plugin.xml
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.xml/plugin.xml 2009-04-22 15:58:01 UTC (rev
14851)
+++ trunk/seam/plugins/org.jboss.tools.seam.xml/plugin.xml 2009-04-22 15:59:03 UTC (rev
14852)
@@ -53,6 +53,9 @@
<xclass
id="org.jboss.tools.seam.xml.components.model.constraint.ListIntELConstraint"
class="org.jboss.tools.seam.xml.components.model.constraint.ListIntELConstraint"/>
+ <xclass
id="org.jboss.tools.seam.xml.components.model.SeamPromptingProvider"
+ class="org.jboss.tools.seam.xml.components.model.SeamPromptingProvider"/>
+
</extension>
<extension point="org.eclipse.wst.xml.core.catalogContributions">
Added:
trunk/seam/plugins/org.jboss.tools.seam.xml/src/org/jboss/tools/seam/xml/components/model/SeamPromptingProvider.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.xml/src/org/jboss/tools/seam/xml/components/model/SeamPromptingProvider.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.xml/src/org/jboss/tools/seam/xml/components/model/SeamPromptingProvider.java 2009-04-22
15:59:03 UTC (rev 14852)
@@ -0,0 +1,53 @@
+package org.jboss.tools.seam.xml.components.model;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.jboss.tools.common.model.XModel;
+import org.jboss.tools.common.model.XModelException;
+import org.jboss.tools.jst.web.project.list.IWebPromptingProvider;
+import org.jboss.tools.seam.xml.components.model.helpers.OpenRuleHelper;
+
+public class SeamPromptingProvider implements IWebPromptingProvider {
+
+ static Set<String> SUPPORTED_IDS = new HashSet<String>();
+ static {
+ SUPPORTED_IDS.add(JSF_OPEN_ACTION);
+ }
+ public boolean isSupporting(String id) {
+ return id != null && SUPPORTED_IDS.contains(id);
+ }
+
+ public List<Object> getList(XModel model, String id, String prefix,
+ Properties properties) {
+ try {
+ return getListInternal(model, id, prefix, properties);
+ } catch (CoreException e) {
+ if(properties != null) {
+ String message = e.getMessage();
+ if(message==null) {
+ message = e.getClass().getName();
+ }
+ properties.setProperty(ERROR, message);
+ }
+ return EMPTY_LIST;
+ }
+ }
+
+ private List<Object> getListInternal(XModel model, String id, String prefix,
Properties properties) throws CoreException {
+ String error = null;
+ if(JSF_OPEN_ACTION.equals(id)) {
+ IFile file = (IFile)properties.get(FILE);
+ String action = prefix;
+ OpenRuleHelper helper = new OpenRuleHelper();
+ error = helper.run(model, file, action);
+ }
+ if(error != null) throw new XModelException(error);
+ return EMPTY_LIST;
+ }
+
+}
Property changes on:
trunk/seam/plugins/org.jboss.tools.seam.xml/src/org/jboss/tools/seam/xml/components/model/SeamPromptingProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/seam/plugins/org.jboss.tools.seam.xml/src/org/jboss/tools/seam/xml/components/model/helpers/OpenRuleHelper.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.xml/src/org/jboss/tools/seam/xml/components/model/helpers/OpenRuleHelper.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.xml/src/org/jboss/tools/seam/xml/components/model/helpers/OpenRuleHelper.java 2009-04-22
15:59:03 UTC (rev 14852)
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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.seam.xml.components.model.helpers;
+
+import java.util.*;
+import org.eclipse.core.resources.IFile;
+//import org.eclipse.osgi.util.NLS;
+
+import org.jboss.tools.common.meta.action.XAction;
+import org.jboss.tools.common.meta.action.XActionInvoker;
+import org.jboss.tools.common.model.*;
+import org.jboss.tools.common.model.filesystems.FileSystemsHelper;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.jst.web.project.WebProject;
+
+//see OpenCaseHelper
+public class OpenRuleHelper {
+
+ public String run(XModel model, IFile jsp, String action) {
+ if(model == null || jsp == null || action == null) return null;
+ XModelObject jspObject = EclipseResourceUtil.getObjectByResource(jsp);
+ if(jspObject == null) return null;
+ WebProject p = WebProject.getInstance(model);
+ String jspLocation = jsp.getLocation().toString().replace('\\', '/');
+ String webRoot = p.getWebRootLocation().replace('\\', '/');
+ if(webRoot.endsWith("/")) webRoot = webRoot.substring(0, webRoot.length() -
1);
+ if(!jspLocation.startsWith(webRoot)) return null;
+ String viewPath = jspLocation.substring(webRoot.length());
+ XModelObject result = findRule(model, viewPath, action);
+ if(result == null) //return NLS.bind(JSFUIMessages.CANNOT_FIND_MATCHING_RULE_FOR_PATH,
viewPath);
+ return "JSFUIMessages.CANNOT_FIND_MATCHING_RULE_FOR_PATH " + viewPath;
+ XModelObject object = result;
+
+ XAction xaction = XActionInvoker.getAction("Select", object);
+ if(xaction != null && xaction.isEnabled(object)) {
+ XActionInvoker.invoke("Select", object, new Properties());
+ }
+
+ return null;
+ }
+
+ private XModelObject findRule(XModel model, String viewPath, String action) {
+ XModelObject webinf = FileSystemsHelper.getWebInf(model);
+ if(webinf == null) return null;
+ XModelObject pagesXML = webinf.getChildByPath("pages.xml");
+ if(pagesXML == null) return null;
+ XModelObject pagesFolder = pagesXML.getChildByPath("Pages");
+ XModelObject[] ps = pagesFolder.getChildren();
+
+ for (int i = 0; i < ps.length; i++) {
+ String viewId = ps[i].getAttributeValue("view id");
+ if(!isPatternMatches(viewId, viewPath)) continue;
+ XModelObject[] ns = ps[i].getChildren();
+ for (int j = 0; j < ns.length; j++) {
+ String entity = ns[j].getModelEntity().getName();
+ if(!entity.startsWith("SeamPageNavigation")) continue;
+ if(entity.startsWith("SeamPageNavigationRule")) continue;
+ XModelObject[] rs = ns[j].getChildren();
+ for (int k = 0; k < rs.length; k++) {
+ String a = rs[k].getAttributeValue("if outcome");
+ if(a != null && a.equals(action)) {
+ //TODO compare match length
+ return rs[k];
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ public static boolean isPatternMatches(String pattern, String fromViewId) {
+ if(pattern.length() == 0 || "*".equals(pattern)) return true;
+ pattern = pattern.toLowerCase().replace('\\', '/');
+ fromViewId = fromViewId.toLowerCase().replace('\\', '/');
+ if(pattern.indexOf('*') < 0) return pattern.equals(fromViewId);
+ StringTokenizer st = new StringTokenizer(pattern, "*", true);
+ boolean f = true;
+ while(st.hasMoreTokens()) {
+ String t = st.nextToken();
+ if("*".equals(t)) {
+ f = false;
+ } else {
+ int i = fromViewId.indexOf(t);
+ if(i < 0 || (f && i > 0)) return false;
+ fromViewId = fromViewId.substring(i);
+ }
+ }
+ return true;
+ }
+
+}
Property changes on:
trunk/seam/plugins/org.jboss.tools.seam.xml/src/org/jboss/tools/seam/xml/components/model/helpers/OpenRuleHelper.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain