Author: DartPeng
Date: 2009-03-05 22:25:26 -0500 (Thu, 05 Mar 2009)
New Revision: 14064
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/util/GraphicalInformationSaver.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/commandprocessor/JavaBeanModelCommandProcessor.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/model/JavaBeanModel.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/AbstractJavaBeanBuilder.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/JavaBeanSourceBuilder.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/JavaBeanTargetBuilder.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/action/AddJavaBeanModelAction.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/action/JavaBeanModelAction.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/action/RemoveJavaBeanAction.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksNormalContentEditFormPage.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/modelparser/SmooksConfigurationFileGenerateContext.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/popup/SmooksAction.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/xml/model/AbstractXMLObject.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/xml/model/ITransformTreeNode.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/xml/model/XMLObjectAnalyzer.java
Log:
JBIDE-3855
Add new feature to load Array Pojo,Collection Pojo from .graph file
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/util/GraphicalInformationSaver.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/util/GraphicalInformationSaver.java 2009-03-06
01:15:19 UTC (rev 14063)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/util/GraphicalInformationSaver.java 2009-03-06
03:25:26 UTC (rev 14064)
@@ -14,6 +14,8 @@
import java.io.IOException;
import java.util.Collections;
import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
import java.util.Properties;
import org.eclipse.core.resources.IContainer;
@@ -131,8 +133,12 @@
}
if (graph != null) {
initMappingTypes(graph, sourceid, targetid);
- Params params = GraphicalFactory.eINSTANCE.createParams();
- graph.setParams(params);
+
+ Params params = graph.getParams();
+ if(params == null){
+ params = GraphicalFactory.eINSTANCE.createParams();
+ graph.setParams(params);
+ }
initParams(params, properties);
}
graphicalFileResource.save(Collections.EMPTY_MAP);
@@ -156,10 +162,22 @@
Enumeration<Object> keys = properties.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
- Param param = GraphicalFactory.eINSTANCE.createParam();
- param.setName(key);
+ List list = params.getParam();
+ Param param = null;
+ for (Iterator iterator = list.iterator(); iterator.hasNext();) {
+ Param para = (Param) iterator.next();
+ if(para.getName().equals(key)){
+ param = para;
+ break;
+ }
+ }
+ if(param == null){
+ param = GraphicalFactory.eINSTANCE.createParam();
+ params.getParam().add(param);
+ param.setName(key);
+ }
param.setValue(properties.getProperty(key));
- params.getParam().add(param);
+
}
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/commandprocessor/JavaBeanModelCommandProcessor.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/commandprocessor/JavaBeanModelCommandProcessor.java 2009-03-06
01:15:19 UTC (rev 14063)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/commandprocessor/JavaBeanModelCommandProcessor.java 2009-03-06
03:25:26 UTC (rev 14064)
@@ -15,7 +15,6 @@
import java.util.List;
import org.eclipse.emf.common.command.Command;
-import org.eclipse.gef.DefaultEditDomain;
import org.eclipse.gef.EditDomain;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.gef.commands.CompoundCommand;
@@ -117,14 +116,25 @@
return false;
}
}
-
- if(source instanceof IXMLStructuredObject && t instanceof JavaBeanModel
&& !(source instanceof JavaBeanModel)){
- boolean isattribute = ((IXMLStructuredObject)source).isAttribute();
+
+ if (source instanceof IXMLStructuredObject
+ && t instanceof JavaBeanModel
+ && !(source instanceof JavaBeanModel)) {
+ boolean isattribute = ((IXMLStructuredObject) source).isAttribute();
JavaBeanModel targetModel = (JavaBeanModel) t;
boolean isprimitive = targetModel.isPrimitive();
- if(isattribute && !isprimitive) return false;
+ if (isattribute && !isprimitive)
+ return false;
+ boolean canlink = hasBeanCreationParentLink(targetGraphModel,
+ context);
+ if (isprimitive) {
+ if (!canlink){
+ linkBeanCreateionParentLink(sourceGraphModel,
+ targetGraphModel, context);
+ }
+ }
}
-
+
if (source instanceof JavaBeanModel && t instanceof JavaBeanModel
&& sourceGraphModel instanceof SourceModel) {
@@ -136,6 +146,16 @@
return false;
}
+ boolean canlink = hasBeanCreationParentLink(targetGraphModel,
+ context);
+
+ if (tis) {
+ if (!canlink) {
+ linkBeanCreateionParentLink(sourceGraphModel,
+ targetGraphModel, context);
+ }
+ }
+
Class sourceClass = sourceModel.getBeanClass();
Class targetClass = targetModel.getBeanClass();
boolean isCompositeSource = sourceClass.isArray()
@@ -148,6 +168,74 @@
return true;
}
+ private void linkBeanCreateionParentLink(
+ AbstractStructuredDataModel sourceGraphModel,
+ AbstractStructuredDataModel targetGraphModel,
+ SmooksConfigurationFileGenerateContext context) {
+ Object obj = sourceGraphModel.getReferenceEntityModel();
+ AbstractStructuredDataModel sourceParentGraph = null;
+ AbstractStructuredDataModel targetParentGraph = null;
+ if (obj instanceof IXMLStructuredObject) {
+ IXMLStructuredObject sourceParent = ((IXMLStructuredObject) obj)
+ .getParent();
+ sourceParentGraph = UIUtils.findGraphModel(context
+ .getGraphicalRootModel(), sourceParent);
+ }
+ Object obj1 = targetGraphModel.getReferenceEntityModel();
+ if (obj1 instanceof IXMLStructuredObject) {
+ IXMLStructuredObject targetParent = ((IXMLStructuredObject) obj1)
+ .getParent();
+ targetParentGraph = UIUtils.findGraphModel(context
+ .getGraphicalRootModel(), targetParent);
+ }
+ if (sourceParentGraph != null && targetParentGraph != null) {
+ PropertyModel propertyModel = new PropertyModel();
+ propertyModel.setName(BeanPopulatorMappingAnalyzer.PRO_BINDING_TYPE);
+ propertyModel.setValue(BeanPopulatorMappingAnalyzer.BEAN_CREATION);
+ CreateConnectionCommand command = new CreateConnectionCommand();
+ command.addPropertyModel(propertyModel);
+ command.setSource((IConnectableModel) sourceParentGraph);
+ command.setTarget((IConnectableModel) targetParentGraph);
+ context.getGefDomain().getCommandStack().execute(command);
+ }
+
+ }
+
+ private boolean hasBeanCreationParentLink(
+ AbstractStructuredDataModel sourceGraphModel,
+ SmooksConfigurationFileGenerateContext context) {
+ Object sourceNode = sourceGraphModel.getReferenceEntityModel();
+ if (!(sourceNode instanceof JavaBeanModel)) {
+ return false;
+ }
+ JavaBeanModel sourceParent = ((JavaBeanModel) sourceNode).getParent();
+ if (sourceParent == null) {
+ return false;
+ }
+ if (sourceParent instanceof JavaBeanList) {
+ return false;
+ }
+ IConnectableModel sourceParentGraph = (IConnectableModel) UIUtils
+ .findGraphModel(context.getGraphicalRootModel(), sourceParent);
+ // If the source's parent node haven't any associated resource-config ,
+ // refuse the connect request.
+ List parentConnections = sourceParentGraph.getModelTargetConnections();
+ if (parentConnections.size() == 0)
+ return false;
+ for (Iterator iterator = parentConnections.iterator(); iterator
+ .hasNext();) {
+ LineConnectionModel object = (LineConnectionModel) iterator.next();
+ if (Java2JavaAnalyzer.BEAN_CREATION.equals(object
+ .getProperty(Java2JavaAnalyzer.PRO_BINDING_TYPE))) {
+ if (object
+ .getProperty(Java2JavaAnalyzer.PRO_REFERENCE_RESOURCE_CONFIG) != null) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
private boolean checkTargetToTarget(
AbstractStructuredDataModel sourceGraphModel,
AbstractStructuredDataModel targetGraphModel,
@@ -156,14 +244,14 @@
return true;
}
Object sourceParent = sourceGraphModel.getReferenceEntityModel();
- if(!(sourceParent instanceof JavaBeanModel)){
+ if (!(sourceParent instanceof JavaBeanModel)) {
return false;
}
- sourceParent = ((JavaBeanModel)sourceParent).getParent();
- if(sourceParent == null){
+ sourceParent = ((JavaBeanModel) sourceParent).getParent();
+ if (sourceParent == null) {
return false;
}
- if(sourceParent instanceof JavaBeanList){
+ if (sourceParent instanceof JavaBeanList) {
return false;
}
IConnectableModel sourceParentGraph = (IConnectableModel) UIUtils
@@ -180,7 +268,8 @@
for (Iterator iterator = parentConnections.iterator(); iterator
.hasNext();) {
LineConnectionModel object = (LineConnectionModel) iterator.next();
- if (object.getProperty(Java2JavaAnalyzer.PRO_REFERENCE_RESOURCE_CONFIG) == null) {
+ if (object
+ .getProperty(Java2JavaAnalyzer.PRO_REFERENCE_RESOURCE_CONFIG) == null) {
return false;
}
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/model/JavaBeanModel.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/model/JavaBeanModel.java 2009-03-06
01:15:19 UTC (rev 14063)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/model/JavaBeanModel.java 2009-03-06
03:25:26 UTC (rev 14064)
@@ -34,8 +34,8 @@
*
*/
public class JavaBeanModel implements IValidatable, IXMLStructuredObject,
- Cloneable , ITransformTreeNode{
-
+ Cloneable, ITransformTreeNode {
+
private Properties extendProperties = new Properties();
protected PropertyChangeSupport support = new PropertyChangeSupport(this);
@@ -94,7 +94,8 @@
public void addNodePropetyChangeListener(PropertyChangeListener listener) {
PropertyChangeListener[] array = support.getPropertyChangeListeners();
for (int i = 0; i < array.length; i++) {
- if(listener == array[i]) return;
+ if (listener == array[i])
+ return;
}
support.addPropertyChangeListener(listener);
}
@@ -103,6 +104,14 @@
support.removePropertyChangeListener(listener);
}
+ public void cleanAllNodePropertyChangeListeners() {
+ PropertyChangeListener[] ps = support.getPropertyChangeListeners();
+ for (int i = 0; i < ps.length; i++) {
+ PropertyChangeListener p = ps[i];
+ support.removePropertyChangeListener(p);
+ }
+ }
+
// /**
// * @return the isRoot
// */
@@ -126,6 +135,16 @@
return clazz.getName();
}
+ public String getBeanClassStringWithList() {
+ String s = getBeanClassString();
+ if (this.isList()) {
+ Class genericType = getGenericType();
+ if (genericType != null)
+ s += "<" + genericType.getName() + ">";
+ }
+ return s;
+ }
+
/**
* @param isRoot
* the isRoot to set
@@ -168,7 +187,6 @@
public PropertyDescriptor getPropertyDescriptor() {
return propertyDescriptor;
}
-
public void setPropertyDescriptor(PropertyDescriptor propertyDescriptor) {
this.propertyDescriptor = propertyDescriptor;
@@ -308,6 +326,22 @@
}
}
+ protected void createArrayChildren(Class<Object> clazz, String name,
+ PropertyDescriptor pd, Class<? extends Object> parentClass,
+ boolean lazyLoad) {
+ JavaBeanModel proxyModel = newChildJavaBean(clazz, name, pd,
+ parentClass, lazyLoad);
+ addProperty(proxyModel);
+ }
+
+ protected void createListChildren(Class<Object> clazz, String name,
+ PropertyDescriptor pd, Class<? extends Object> parentClass,
+ boolean lazyLoad) {
+ JavaBeanModel proxyModel = newChildJavaBean(clazz, name, pd,
+ parentClass, lazyLoad);
+ addProperty(proxyModel);
+ }
+
private List properties;
public List getProperties() {
@@ -320,17 +354,14 @@
Class beanType = beanClass;
if (isArray() || isList()) {
if (componentClass != null) {
- JavaBeanModel proxyModel = new JavaBeanModel(
- componentClass, componentClass.getSimpleName(),
- null, beanClass, this.lazyLoadProperties);
+ createArrayChildren(componentClass, componentClass
+ .getSimpleName(), null, beanClass,
+ this.lazyLoadProperties);
beanType = componentClass;
- addProperty(proxyModel);
-
} else {
- JavaBeanModel proxyModel = new JavaBeanModel(Object.class,
- "object", null, beanClass, this.lazyLoadProperties);
+ createListChildren(Object.class, "object", null, beanClass,
+ this.lazyLoadProperties);
beanType = componentClass;
- addProperty(proxyModel);
}
return properties;
}
@@ -342,7 +373,8 @@
PropertyDescriptor pd = pds[i];
if ("class".equals(pd.getName())) //$NON-NLS-1$
continue;
- if(pd.getPropertyType() == null) continue;
+ if (pd.getPropertyType() == null)
+ continue;
if (Collection.class.isAssignableFrom(pd.getPropertyType())) {
Method rmethod = pd.getReadMethod();
if (rmethod != null) {
@@ -358,7 +390,7 @@
}
}
}
- JavaBeanModel jbm = new JavaBeanModel(pd.getPropertyType(), pd
+ JavaBeanModel jbm = newChildJavaBean(pd.getPropertyType(), pd
.getName(), pd, beanClass, this.lazyLoadProperties);
addProperty(jbm);
}
@@ -366,6 +398,12 @@
return properties;
}
+ protected JavaBeanModel newChildJavaBean(Class clazz, String name,
+ PropertyDescriptor pd, Class parentClass, boolean lazyLoading) {
+ return new JavaBeanModel(clazz, name, pd, parentClass,
+ lazyLoading);
+ }
+
public void setProperties(List properties) {
this.properties = properties;
}
@@ -441,7 +479,7 @@
}
public String getSelectorString() {
- if(parent == null) {
+ if (parent == null) {
return getBeanClassString();
}
if (parent.getClass() == JavaBeanList.class) {
@@ -487,26 +525,27 @@
// TODO Auto-generated method stub
return false;
}
-
- public void setComponentClass(Class clazz){
+
+ public void setComponentClass(Class clazz) {
componentClass = clazz;
}
public Class getComponentClass() {
return componentClass;
}
-
- public void addExtendProperty(String name,String value){
+
+ public void addExtendProperty(String name, String value) {
extendProperties.setProperty(name, value);
}
-
- public String getExtendProperty(String name){
+
+ public String getExtendProperty(String name) {
return extendProperties.getProperty(name);
}
public Object clone() {
- if(isList()){
- JavaBeanModel model =
JavaBeanModelFactory.getJavaBeanModelWithLazyLoad(ArrayList.class);
+ if (isList()) {
+ JavaBeanModel model = JavaBeanModelFactory
+ .getJavaBeanModelWithLazyLoad(ArrayList.class);
model.setComponentClass(componentClass);
return model;
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/AbstractJavaBeanBuilder.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/AbstractJavaBeanBuilder.java 2009-03-06
01:15:19 UTC (rev 14063)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/AbstractJavaBeanBuilder.java 2009-03-06
03:25:26 UTC (rev 14064)
@@ -3,11 +3,13 @@
*/
package org.jboss.tools.smooks.javabean.ui;
+import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.jboss.tools.smooks.graphical.GraphInformations;
+import org.jboss.tools.smooks.graphical.GraphicalFactory;
import org.jboss.tools.smooks.graphical.Param;
import org.jboss.tools.smooks.graphical.Params;
import org.jboss.tools.smooks.javabean.model.JavaBeanList;
@@ -19,9 +21,11 @@
*
*/
public class AbstractJavaBeanBuilder {
+
+ private ClassLoader classLoader = null;
+
public static final int SOURCE_DATA = 0;
public static final int TARGET_DATA = 1;
- private ClassLoader classLoader = null;
public ClassLoader getClassLoader() {
return classLoader;
@@ -46,12 +50,129 @@
public void mergeJavaBeans(JavaBeanList beanList, List javabeans) {
for (Iterator iterator = javabeans.iterator(); iterator.hasNext();) {
JavaBeanModel javaBean = (JavaBeanModel) iterator.next();
- if (!hasSameNameBean(beanList, javaBean)) {
- beanList.addJavaBean(javaBean);
+ // if (!hasSameNameBean(beanList, javaBean)) {
+ beanList.addJavaBean(javaBean);
+ // }
+ }
+ }
+
+ public static String getDataSourceClassArray(GraphInformations info,
+ int dataMode) {
+ String key = "sourceDataPath"; //$NON-NLS-1$
+ if (dataMode == SOURCE_DATA) {
+ key = "sourceDataPath"; //$NON-NLS-1$
+ }
+ if (dataMode == TARGET_DATA) {
+ key = "targetDataPath"; //$NON-NLS-1$
+ }
+ if (info != null) {
+ Params params = info.getParams();
+ if (params != null) {
+ List paramList = params.getParam();
+ for (Iterator iterator = paramList.iterator(); iterator
+ .hasNext();) {
+ Param param = (Param) iterator.next();
+ if (key.equals(param.getName())) {
+ return param.getValue();
+ }
+ }
}
}
+ return null;
}
+ public static void appendClassToGraph(JavaBeanModel clazz,
+ GraphInformations info, int dataMode) {
+ String classArray = getDataSourceClassArray(info, dataMode);
+ if (classArray == null) {
+ classArray = "";
+ }
+ if (!classArray.endsWith(";") && classArray.length() != 0) {
+ classArray += ";";
+ }
+ String newClassString = clazz.getBeanClassStringWithList();
+ if (newClassString != null) {
+ classArray += newClassString;
+ }
+ classArray = classArray.replace("<", "[");
+ classArray = classArray.replace(">", "]");
+ if (info != null) {
+ Params params = info.getParams();
+ if (params == null) {
+ params = GraphicalFactory.eINSTANCE.createParams();
+ info.setParams(params);
+ }
+ String key = "sourceDataPath"; //$NON-NLS-1$
+ if (dataMode == SOURCE_DATA) {
+ key = "sourceDataPath"; //$NON-NLS-1$
+ }
+ if (dataMode == TARGET_DATA) {
+ key = "targetDataPath"; //$NON-NLS-1$
+ }
+ Param targetParam = null;
+ ;
+ List paramList = params.getParam();
+ for (Iterator iterator = paramList.iterator(); iterator.hasNext();) {
+ Param param = (Param) iterator.next();
+ if (key.equals(param.getName())) {
+ targetParam = param;
+ break;
+ }
+ }
+ if (targetParam == null) {
+ targetParam = GraphicalFactory.eINSTANCE.createParam();
+ params.getParam().add(targetParam);
+ targetParam.setName(key);
+ }
+ targetParam.setValue(classArray);
+ }
+ }
+
+ public static void removeClassFromGraph(JavaBeanModel model,
+ GraphInformations info, int dataMode) {
+ String classArray = getDataSourceClassArray(info, dataMode);
+ String removeClass = model.getBeanClassStringWithList();
+ if (removeClass == null)
+ return;
+ removeClass = removeClass.replace("<", "[");
+ removeClass = removeClass.replace(">", "]");
+ int startIndex1 = classArray.indexOf(removeClass);
+ if (startIndex1 == -1)
+ return;
+ int endIndex = startIndex1 + removeClass.length();
+ endIndex++;
+ if (classArray.length() <= endIndex) {
+ endIndex --;
+ if (classArray.charAt(endIndex - 1) != ';') {
+ endIndex = startIndex1 + removeClass.length();
+ }
+ }
+ classArray = classArray.substring(0, startIndex1)
+ + classArray.substring(endIndex, classArray.length());
+ if (info != null && classArray != null) {
+ Params params = info.getParams();
+ if (params == null) {
+ params = GraphicalFactory.eINSTANCE.createParams();
+ info.setParams(params);
+ }
+ String key = "sourceDataPath"; //$NON-NLS-1$
+ if (dataMode == SOURCE_DATA) {
+ key = "sourceDataPath"; //$NON-NLS-1$
+ }
+ if (dataMode == TARGET_DATA) {
+ key = "targetDataPath"; //$NON-NLS-1$
+ }
+ List paramList = params.getParam();
+ for (Iterator iterator = paramList.iterator(); iterator.hasNext();) {
+ Param param = (Param) iterator.next();
+ if (key.equals(param.getName())) {
+ param.setValue(classArray);
+ break;
+ }
+ }
+ }
+ }
+
public List getTheJavaBeanFromGraphFile(ClassLoader classLoader,
GraphInformations graphInfo, int dataMode) {
String array = getDataSourceClassArray(graphInfo, dataMode);
@@ -66,9 +187,37 @@
if (className.length() == 0)
continue;
try {
- Class clazz = classLoader.loadClass(className);
- JavaBeanModel javaBean = JavaBeanModelFactory
- .getJavaBeanModelWithLazyLoad(clazz);
+ JavaBeanModel javaBean = null;
+ if (className.indexOf("[") != -1) {
+ int start = className.indexOf("[");
+ int end = className.indexOf("]");
+ String genericType = className.substring(start + 1, end);
+ if (genericType != null) {
+ genericType = genericType.trim();
+ }
+ String newClassName = className.substring(0, start);
+ Class realClass = classLoader.loadClass(newClassName);
+ if (genericType.length() == 0) {
+ javaBean = JavaBeanModelFactory
+ .getJavaBeanModelWithLazyLoad(Array
+ .newInstance(realClass, 0).getClass());
+ } else {
+ Class genericClass = null;
+ try {
+ genericClass = classLoader.loadClass(genericType);
+ } catch (Throwable t1) {
+
+ }
+ javaBean = JavaBeanModelFactory
+ .getJavaBeanModelWithLazyLoad(realClass);
+ if (genericClass != null)
+ javaBean.setComponentClass(genericClass);
+ }
+ } else {
+ Class clazz = classLoader.loadClass(className);
+ javaBean = JavaBeanModelFactory
+ .getJavaBeanModelWithLazyLoad(clazz);
+ }
if (javaBean != null) {
list.add(javaBean);
}
@@ -78,29 +227,4 @@
}
return list;
}
-
- private String getDataSourceClassArray(GraphInformations info, int dataMode) {
- String key = "sourceDataPath"; //$NON-NLS-1$
- if (dataMode == SOURCE_DATA) {
- key = "sourceDataPath"; //$NON-NLS-1$
- }
- if (dataMode == TARGET_DATA) {
- key = "targetDataPath"; //$NON-NLS-1$
- }
- if (info != null) {
- Params params = info.getParams();
- if (params != null) {
- List paramList = params.getParam();
- for (Iterator iterator = paramList.iterator(); iterator
- .hasNext();) {
- Param param = (Param) iterator.next();
- if (key.equals(param.getName())) {
- return param.getValue();
- }
- }
- }
- }
- return null;
- }
-
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/JavaBeanSourceBuilder.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/JavaBeanSourceBuilder.java 2009-03-06
01:15:19 UTC (rev 14063)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/JavaBeanSourceBuilder.java 2009-03-06
03:25:26 UTC (rev 14064)
@@ -112,7 +112,9 @@
selector = selector.substring(0, selector.length() - 2);
Class arrayClass = loader.loadClass(selector);
Object arrayInstance = Array.newInstance(arrayClass, 0);
- return arrayInstance.getClass();
+ Class arrayClasss = arrayInstance.getClass();
+ arrayInstance = null;
+ return arrayClass;
}
return loader.loadClass(selector);
} catch (ClassNotFoundException e) {
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/JavaBeanTargetBuilder.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/JavaBeanTargetBuilder.java 2009-03-06
01:15:19 UTC (rev 14063)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/JavaBeanTargetBuilder.java 2009-03-06
03:25:26 UTC (rev 14064)
@@ -3,6 +3,7 @@
*/
package org.jboss.tools.smooks.javabean.ui;
+import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
@@ -24,6 +25,8 @@
import org.jboss.tools.smooks.model.SmooksResourceListType;
import org.jboss.tools.smooks.model.util.SmooksModelConstants;
import org.jboss.tools.smooks.model.util.SmooksModelUtils;
+import org.jboss.tools.smooks.ui.editors.SmooksGraphicalFormPage;
+import org.jboss.tools.smooks.ui.editors.TransformDataTreeViewer;
import org.jboss.tools.smooks.utils.ProjectClassLoader;
/**
@@ -31,11 +34,13 @@
*
*/
public class JavaBeanTargetBuilder extends AbstractJavaBeanBuilder implements
- ITargetModelAnalyzer {
+ ITargetModelAnalyzer, PropertyChangeListener {
+ private GraphInformations graphInfo;
public Object buildTargetInputObjects(GraphInformations graphInfo,
SmooksResourceListType listType, IFile sourceFile, Object viewer)
throws InvocationTargetException {
+ this.graphInfo = graphInfo;
ClassLoader classLoader = getClassLoader();
if (classLoader == null) {
IProject project = sourceFile.getProject();
@@ -45,9 +50,18 @@
throw new InvocationTargetException(e);
}
}
- JavaBeanList beanList = (JavaBeanList) buildTargetInputObjects(graphInfo, listType,
sourceFile, viewer,
- getClassLoader());
- mergeJavaBeans(beanList, getTheJavaBeanFromGraphFile(classLoader, graphInfo,
TARGET_DATA));
+ JavaBeanList beanList = (JavaBeanList) buildTargetInputObjects(
+ graphInfo, listType, sourceFile, viewer, getClassLoader());
+ mergeJavaBeans(beanList, getTheJavaBeanFromGraphFile(classLoader,
+ graphInfo, TARGET_DATA));
+ if (viewer instanceof PropertyChangeListener) {
+ registeListener((PropertyChangeListener) viewer, beanList);
+ List list = beanList.getChildren();
+ for (Iterator iterator = list.iterator(); iterator.hasNext();) {
+ JavaBeanModel beanModel = (JavaBeanModel) iterator.next();
+ registeListener((PropertyChangeListener) viewer, beanModel);
+ }
+ }
return beanList;
}
@@ -93,12 +107,12 @@
continue;
JavaBeanModel javaBean = JavaBeanModelFactory
.getJavaBeanModelWithLazyLoad(clazz);
- registeListener(viewer, javaBean);
+ // registeListener(viewer, javaBean);
beanList.addJavaBean(javaBean);
}
}
}
- registeListener(viewer, beanList);
+ // registeListener(viewer, beanList);
return beanList;
}
@@ -106,6 +120,7 @@
if (listener instanceof PropertyChangeListener) {
javaBean
.addNodePropetyChangeListener((PropertyChangeListener) listener);
+ javaBean.addNodePropetyChangeListener(this);
}
}
@@ -129,4 +144,31 @@
return null;
}
+ public void propertyChange(PropertyChangeEvent evt) {
+ if (graphInfo != null) {
+ String type = evt.getPropertyName();
+ Object node = evt.getNewValue();
+ if(TransformDataTreeViewer.REMOVE_CHILDREN_EVENT
+ .equals(type)){
+ node = evt.getOldValue();
+ }
+ if (node instanceof JavaBeanModel) {
+ if (!((JavaBeanModel) node).isPrimitive()) {
+ if (TransformDataTreeViewer.NODE_PROPERTY_EVENT
+ .equals(type)
+ || TransformDataTreeViewer.ADD_CHILDREN_EVENT
+ .equals(type)) {
+ appendClassToGraph((JavaBeanModel) node, graphInfo,
+ TARGET_DATA);
+ }
+ if (TransformDataTreeViewer.REMOVE_CHILDREN_EVENT
+ .equals(type)) {
+ removeClassFromGraph((JavaBeanModel) node, graphInfo,
+ TARGET_DATA);
+ }
+ }
+ }
+ }
+ }
+
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/action/AddJavaBeanModelAction.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/action/AddJavaBeanModelAction.java 2009-03-06
01:15:19 UTC (rev 14063)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/action/AddJavaBeanModelAction.java 2009-03-06
03:25:26 UTC (rev 14064)
@@ -80,6 +80,8 @@
}
}
}
+
+ super.run();
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/action/JavaBeanModelAction.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/action/JavaBeanModelAction.java 2009-03-06
01:15:19 UTC (rev 14063)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/action/JavaBeanModelAction.java 2009-03-06
03:25:26 UTC (rev 14064)
@@ -7,6 +7,7 @@
import org.eclipse.jface.viewers.IStructuredSelection;
import org.jboss.tools.smooks.javabean.model.JavaBeanModel;
+import org.jboss.tools.smooks.ui.editors.SmooksFormEditor;
import org.jboss.tools.smooks.ui.popup.SmooksAction;
/**
@@ -25,4 +26,16 @@
}
return null;
}
+
+ protected void fireEditorIsDirty(){
+ ((SmooksFormEditor)context.getSmooksGraphcalPage().getEditor()).fireEditorDirty(true);
+ }
+
+ @Override
+ public void run() {
+ super.run();
+ fireEditorIsDirty();
+ }
+
+
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/action/RemoveJavaBeanAction.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/action/RemoveJavaBeanAction.java 2009-03-06
01:15:19 UTC (rev 14063)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/action/RemoveJavaBeanAction.java 2009-03-06
03:25:26 UTC (rev 14064)
@@ -43,10 +43,11 @@
// disConnectAllConnections(graphModel);
}
if(viewer instanceof PropertyChangeListener){
- model.removeNodePropetyChangeListener((PropertyChangeListener)viewer);
+ model.cleanAllNodePropertyChangeListeners();
}
beanList.removeJavaBean(model);
}
+ super.run();
}
protected void disConnectAllConnections(IConnectableModel model){
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java 2009-03-06
01:15:19 UTC (rev 14063)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java 2009-03-06
03:25:26 UTC (rev 14064)
@@ -60,7 +60,6 @@
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
@@ -119,6 +118,7 @@
import org.jboss.tools.smooks.analyzer.SmooksAnalyzerException;
import org.jboss.tools.smooks.analyzer.SmooksFileBuilder;
import org.jboss.tools.smooks.graphical.GraphInformations;
+import org.jboss.tools.smooks.graphical.GraphicalFactory;
import org.jboss.tools.smooks.graphical.MappingDataType;
import org.jboss.tools.smooks.graphical.Param;
import org.jboss.tools.smooks.graphical.Params;
@@ -190,6 +190,7 @@
protected Hyperlink sourceLink = null;
protected Hyperlink targetLink = null;
protected String sourceDataTypeID = null;
+ protected GraphInformations graphinformations = null;
public String getSourceDataTypeID() {
return sourceDataTypeID;
@@ -470,9 +471,16 @@
targetViewer));
}
}
+
+
+
toolkit.paintBordersFor(rootMainControl);
form.pack();
+ /*
+ * below is init GUIs
+ */
+
Throwable throwable = null;
try {
this.initTransformViewerModel((IEditorSite) getSite(),
@@ -633,11 +641,12 @@
protected void initTargetTreeViewer() {
if (this.targetTreeViewerInputModel != null) {
-// if (targetTreeViewerInputModel instanceof ITransformTreeNode
-// && targetViewer instanceof PropertyChangeListener) {
-// ((ITransformTreeNode) targetTreeViewerInputModel)
-// .addNodePropetyChangeListener((PropertyChangeListener) targetViewer);
-// }
+ // if (targetTreeViewerInputModel instanceof ITransformTreeNode
+ // && targetViewer instanceof PropertyChangeListener) {
+ // ((ITransformTreeNode) targetTreeViewerInputModel)
+ // .addNodePropetyChangeListener((PropertyChangeListener)
+ // targetViewer);
+ // }
targetViewer.setInput(targetTreeViewerInputModel);
}
}
@@ -1001,8 +1010,10 @@
// save graphical informations
if (this.graphicalInformationSaver != null) {
- graphicalInformationSaver.doSave(monitor,
- getSmooksConfigurationFileGenerateContext());
+ SmooksConfigurationFileGenerateContext context = new
SmooksConfigurationFileGenerateContext();
+ initSmooksConfigurationFileGenerateContext(context);
+ context.getProperties().clear();
+ graphicalInformationSaver.doSave(monitor, context);
}
} catch (CoreException e) {
exp = e;
@@ -1043,6 +1054,7 @@
context.setSourceDataTypeID(this.sourceDataTypeID);
context.setTargetDataTypeID(this.targetDataTypeID);
context.setSmooksType(SmooksModelConstants.SAX);
+ context.setGraphInformations(graphinformations);
context.setDataMappingRootModel(this.rootModel);
context.setSmooksConfigFile(((IFileEditorInput) getEditorInput())
.getFile());
@@ -1277,11 +1289,12 @@
throws Throwable {
graphicalInformationSaver = new GraphicalInformationSaver(input);
- GraphInformations graph = null;
try {
- graph = graphicalInformationSaver.doLoad();
- initFormEditorWithGraphInfo(graph);
- initSmooksContext(graph, this
+ if (graphinformations == null) {
+ graphinformations = graphicalInformationSaver.doLoad();
+ }
+ initFormEditorWithGraphInfo(graphinformations);
+ initSmooksContext(graphinformations, this
.getSmooksConfigurationFileGenerateContext());
} catch (Throwable t) {
// ignore
@@ -1315,7 +1328,7 @@
return;
SmooksResourceListType listType = ((DocumentRoot) smooksResource
.getContents().get(0)).getSmooksResourceList();
- this.analyzeGraphicalModel(listType, graph, file);
+ this.analyzeGraphicalModel(listType, graphinformations, file);
}
}
@@ -1330,10 +1343,10 @@
smooksResource.getContents().clear();
smooksResource.getContents().add(listType.eContainer());
}
- GraphInformations graph = null;
- if (graphicalInformationSaver != null)
- graph = graphicalInformationSaver.doLoad();
- this.analyzeGraphicalModel(listType, graph,
+ // GraphInformations graph = null;
+ // if (graphicalInformationSaver != null)
+ // graph = graphicalInformationSaver.doLoad();
+ this.analyzeGraphicalModel(listType, graphinformations,
((IFileEditorInput) getEditorInput()).getFile());
}
@@ -1450,6 +1463,30 @@
}
}
+ public void replaceInputDataPathData(String pathName, String value) {
+ if (graphinformations != null) {
+ Params params = graphinformations.getParams();
+ if (params == null) {
+ return;
+ }
+ Param param = null;
+ List list = params.getParam();
+ for (Iterator iterator = list.iterator(); iterator.hasNext();) {
+ Param p = (Param) iterator.next();
+ if (pathName.equals(p.getName())) {
+ param = p;
+ break;
+ }
+ }
+ if (param == null) {
+ param = GraphicalFactory.eINSTANCE.createParam();
+ params.getParam().add(param);
+ param.setName(pathName);
+ }
+ param.setValue(value);
+ }
+ }
+
/**
* It's a very important method
* <p>
@@ -1490,23 +1527,17 @@
try {
if (viewer == this.sourceViewer) {
this.createSourceGraphModels();
- this
- .getSmooksConfigurationFileGenerateContext()
- .getProperties()
- .setProperty(
- SmooksConfigFileNewWizard.PRO_SOURCE_DATA_PATH,
- cw.getStructuredDataSourcePath());
+ replaceInputDataPathData(
+ SmooksConfigFileNewWizard.PRO_SOURCE_DATA_PATH,
+ cw.getStructuredDataSourcePath());
sourceDataTypeID = typeID;
}
if (viewer == this.targetViewer) {
this.createTargetGraphModels();
targetDataTypeID = typeID;
- this
- .getSmooksConfigurationFileGenerateContext()
- .getProperties()
- .setProperty(
- SmooksConfigFileNewWizard.PRO_TARGET_DATA_PATH,
- cw.getStructuredDataSourcePath());
+ replaceInputDataPathData(
+ SmooksConfigFileNewWizard.PRO_TARGET_DATA_PATH,
+ cw.getStructuredDataSourcePath());
}
commandStackChanged = true;
firePropertyChange(PROP_DIRTY);
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksNormalContentEditFormPage.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksNormalContentEditFormPage.java 2009-03-06
01:15:19 UTC (rev 14063)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksNormalContentEditFormPage.java 2009-03-06
03:25:26 UTC (rev 14064)
@@ -1,643 +1,644 @@
-/*******************************************************************************
- * Copyright (c) 2008 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:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.smooks.ui.editors;
-
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.ui.dialogs.WorkspaceResourceDialog;
-import org.eclipse.emf.edit.command.AddCommand;
-import org.eclipse.emf.edit.command.MoveCommand;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerFilter;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.forms.IManagedForm;
-import org.eclipse.ui.forms.editor.FormEditor;
-import org.eclipse.ui.forms.editor.FormPage;
-import org.eclipse.ui.forms.widgets.FormToolkit;
-import org.eclipse.ui.forms.widgets.ScrolledForm;
-import org.eclipse.ui.forms.widgets.Section;
-import org.eclipse.ui.ide.IDE;
-import org.jboss.tools.smooks.analyzer.MappingResourceConfigList;
-import org.jboss.tools.smooks.analyzer.NormalSmooksModelPackage;
-import org.jboss.tools.smooks.model.ImportType;
-import org.jboss.tools.smooks.model.ParamType;
-import org.jboss.tools.smooks.model.ResourceConfigType;
-import org.jboss.tools.smooks.model.SmooksFactory;
-import org.jboss.tools.smooks.model.SmooksPackage;
-import org.jboss.tools.smooks.model.SmooksResourceListType;
-import org.jboss.tools.smooks.model.util.SmooksModelConstants;
-import org.jboss.tools.smooks.model.util.SmooksModelUtils;
-import org.jboss.tools.smooks.ui.AnalyzeResult;
-import org.jboss.tools.smooks.ui.IAnalyzeListener;
-import org.jboss.tools.smooks.ui.SmooksUIActivator;
-import org.jboss.tools.smooks.ui.gef.util.GraphicsConstants;
-import org.jboss.tools.smooks.utils.SmooksGraphConstants;
-import org.jboss.tools.smooks.utils.UIUtils;
-
-/**
- * @author Dart Peng Date : 2008-9-9
- */
-public class SmooksNormalContentEditFormPage extends FormPage implements
- IAnalyzeListener {
-
- protected NormalSmooksModelPackage modelPackage = null;
-
- protected SmooksResourceConfigFormBlock resourceBlock = null;
-
- protected ResourceConfigType transformType = null;
-
- private Button saxButton;
-
- private Button domButton;
-
- private Button saxdomButton;
-
- private EditingDomain domain;
-
- private List hidenResourceConfigs;
-
- private boolean disableGUI = false;
-
- public boolean isDisableGUI() {
- return disableGUI;
- }
-
- public void setDisableGUI(boolean disableGUI) {
- this.disableGUI = disableGUI;
- setGUIStates();
- }
-
- private Section parseTypeSection;
-
- private Button addFileButton;
-
- private Button removeFileButton;
-
- private Button editFileButton;
-
- private TableViewer fileViewer;
-
- public SmooksNormalContentEditFormPage(FormEditor editor, String id,
- String title, NormalSmooksModelPackage modelPacakge) {
- super(editor, id, title);
- domain = ((SmooksFormEditor) editor).getEditingDomain();
- this.createResourceConfigFormBlock();
- this.setModelPackage(modelPacakge);
- }
-
- public SmooksNormalContentEditFormPage(String id, String title,
- NormalSmooksModelPackage modelPacakge) {
- super(id, title);
- this.createResourceConfigFormBlock();
- this.setModelPackage(modelPacakge);
- }
-
- protected void createResourceConfigFormBlock() {
- resourceBlock = new SmooksResourceConfigFormBlock();
- resourceBlock.setDomain(getEditingDomain());
- resourceBlock.setParentEditor((SmooksFormEditor) this.getEditor());
- }
-
- protected EditingDomain getEditingDomain() {
- return ((SmooksFormEditor) getEditor()).getEditingDomain();
- }
-
- @Override
- protected void createFormContent(IManagedForm managedForm) {
- final ScrolledForm form = managedForm.getForm();
- FormToolkit tool = managedForm.getToolkit();
- tool.decorateFormHeading(form.getForm());
- GridLayout gridLayout = UIUtils.createGeneralFormEditorLayout(1);
- resourceBlock.createContent(managedForm);
- Composite rootMainControl = form.getBody();
- form
- .setText(Messages
- .getString("SmooksNormalContentEditFormPage.ConfigurationPageText"));
//$NON-NLS-1$
- createSmooksTypeGUI(rootMainControl, tool);
- form.getBody().setLayout(gridLayout);
- form.pack();
- this.initOtherConfigurationsGUI();
- resourceBlock.initViewers(transformType);
-
- setGUIStates();
- }
-
- @Override
- public boolean isDirty() {
- return false;
- }
-
- public void setGUIStates() {
- if (resourceBlock != null) {
- resourceBlock.setSectionStates(!disableGUI);
- }
-
- if (this.parseTypeSection != null && !parseTypeSection.isDisposed()) {
- parseTypeSection.setEnabled(!disableGUI);
- }
- }
-
- private ResourceConfigType createTransformType() {
- ResourceConfigType transformType = SmooksFactory.eINSTANCE
- .createResourceConfigType();
- AddCommand.create(
- domain,
- modelPackage.getSmooksResourceList(),
- SmooksPackage.eINSTANCE
- .getSmooksResourceListType_AbstractResourceConfig(),
- transformType).execute();
- MoveCommand.create(domain, modelPackage.getSmooksResourceList(),
- SmooksPackage.eINSTANCE
- .getSmooksResourceListType_AbstractResourceConfig(),
- transformType, 0);
- transformType.setSelector(SmooksModelConstants.GLOBAL_PARAMETERS);
- ParamType typeParam = SmooksFactory.eINSTANCE.createParamType();
- typeParam.setName(SmooksModelConstants.STREAM_FILTER_TYPE);
- transformType.getParam().add(typeParam);
-
- return transformType;
- }
-
- protected void initOtherConfigurationsGUI() {
- if (saxButton != null)
- saxButton.setSelection(false);
- if (domButton != null)
- domButton.setSelection(false);
- if (saxdomButton != null)
- saxdomButton.setSelection(false);
- if (this.getModelPackage() != null) {
- List list = modelPackage.getSmooksResourceList()
- .getAbstractResourceConfig();
- if (fileViewer != null) {
- fileViewer.setInput(list);
- }
- for (Iterator iterator = list.iterator(); iterator.hasNext();) {
- Object sr = iterator.next();
- if (sr instanceof ResourceConfigType) {
- if (SmooksModelUtils
- .isTransformTypeResourceConfig((ResourceConfigType) sr)) {
- this.transformType = (ResourceConfigType) sr;
- break;
- }
- }
- }
- if (transformType == null) {
- transformType = createTransformType();
- }
- if (transformType != null) {
- String type = SmooksModelUtils.getTransformType(transformType);
- if (SmooksModelConstants.SAX.equals(type)) {
- if (saxButton != null)
- saxButton.setSelection(true);
- }
- if (SmooksModelConstants.DOM.equals(type)) {
- if (domButton != null)
- domButton.setSelection(true);
- }
- if ("SAX/DOM".equals(type)) { //$NON-NLS-1$
- if (saxdomButton != null)
- saxdomButton.setSelection(true);
- }
- }
- }
- }
-
- protected void createSmooksTypeGUI(Composite mainComposite, FormToolkit tool) {
- GridData gd = new GridData(GridData.FILL_HORIZONTAL);
- parseTypeSection = tool.createSection(mainComposite, Section.TITLE_BAR
- | Section.TWISTIE);
- parseTypeSection.setLayoutData(gd);
- Composite otherConfigurationComposite = tool
- .createComposite(parseTypeSection);
- parseTypeSection.setClient(otherConfigurationComposite);
- parseTypeSection.setText(Messages
- .getString("SmooksNormalContentEditFormPage.SmooksParseType"));
//$NON-NLS-1$
- GridLayout layout1 = new GridLayout();
- otherConfigurationComposite.setLayout(layout1);
-
- gd = new GridData(GridData.FILL_HORIZONTAL);
- gd.horizontalSpan = 2;
- otherConfigurationComposite.setLayoutData(gd);
- GridLayout layout = new GridLayout();
- otherConfigurationComposite.setLayout(layout);
-
- Composite buttonComposite = tool
- .createComposite(otherConfigurationComposite);
- GridLayout buttonAreaLayout = new GridLayout();
- buttonAreaLayout.numColumns = 4;
- buttonComposite.setLayout(buttonAreaLayout);
-
- gd = new GridData(GridData.FILL_HORIZONTAL);
- buttonComposite.setLayoutData(gd);
-
- tool.createLabel(buttonComposite, "Parse Type : ");
- saxButton = createTypeSelectRadioButton(buttonComposite, tool,
- SmooksModelConstants.SAX);
- domButton = createTypeSelectRadioButton(buttonComposite, tool,
- SmooksModelConstants.DOM);
- saxdomButton = createTypeSelectRadioButton(buttonComposite, tool,
- SmooksModelConstants.SAX_DOM);
-
- gd = new GridData(GridData.FILL_HORIZONTAL);
- gd.horizontalSpan = 2;
- tool.createSeparator(otherConfigurationComposite, SWT.HORIZONTAL)
- .setLayoutData(gd);
-
- Composite importFileComposite = tool
- .createComposite(otherConfigurationComposite);
- gd = new GridData(GridData.FILL_HORIZONTAL);
- GridLayout fileLayout = new GridLayout();
- fileLayout.numColumns = 2;
- importFileComposite.setLayoutData(gd);
- importFileComposite.setLayout(fileLayout);
- // importFileComposite.setBackground(ColorConstants.black);
-
- Label fileListLabel = tool.createLabel(importFileComposite,
- "Import Files :");
- gd = new GridData(GridData.FILL_HORIZONTAL);
- gd.horizontalSpan = 2;
- fileListLabel.setLayoutData(gd);
-
- Composite viewerComposite = tool.createComposite(importFileComposite);
- FillLayout viewerLayout = new FillLayout();
- viewerLayout.marginHeight = 1;
- viewerLayout.marginWidth = 1;
- viewerComposite.setLayout(viewerLayout);
- fileViewer = new TableViewer(viewerComposite, SWT.NONE);
- fileViewer.setContentProvider(new FileImportContentProvider());
- fileViewer.setLabelProvider(new FileImportLabelProvider());
- if (getModelPackage() != null) {
- SmooksResourceListType listType = getModelPackage()
- .getSmooksResourceList();
- if (listType != null && listType.getAbstractResourceConfig() != null) {
- fileViewer.setInput(listType.getAbstractResourceConfig());
- }
- }
- fileViewer.addDoubleClickListener(new IDoubleClickListener() {
- public void doubleClick(DoubleClickEvent event) {
- openFile(fileViewer.getSelection());
- }
- });
- fileViewer.addFilter(new ViewerFilter() {
-
- @Override
- public boolean select(Viewer viewer, Object parentElement,
- Object element) {
- if (element instanceof ImportType)
- return true;
- return false;
- }
-
- });
- gd = new GridData(GridData.FILL_BOTH);
- viewerComposite.setLayoutData(gd);
- viewerComposite.setBackground(GraphicsConstants.groupBorderColor);
- tool.paintBordersFor(viewerComposite);
-
- Composite fileActionComposite = tool
- .createComposite(importFileComposite);
- gd = new GridData(GridData.FILL_VERTICAL);
- fileActionComposite.setLayoutData(gd);
-
- GridLayout fileActionLayout = new GridLayout();
- fileActionComposite.setLayout(fileActionLayout);
-
- addFileButton = createFileActionButton(fileActionComposite, tool, "Add");
- removeFileButton = createFileActionButton(fileActionComposite, tool,
- "Remove");
- editFileButton = createFileActionButton(fileActionComposite, tool,
- "Edit");
-
- tool.paintBordersFor(fileActionComposite);
-
- hookButtons();
- }
-
- protected void openFile(ISelection selection) {
- Object obj = ((IStructuredSelection) selection).getFirstElement();
- if (obj != null && obj instanceof ImportType) {
- String filePath = ((ImportType) obj).getFile();
- IFile input = createEditorInput(filePath);
- if (input != null) {
- try {
- IDE.openEditor(SmooksUIActivator.getDefault()
- .getWorkbench().getActiveWorkbenchWindow()
- .getActivePage(), input);
- } catch (PartInitException e) {
- UIUtils.showErrorDialog(getSite().getShell(), UIUtils
- .createErrorStatus(e));
- }
- }
- }
- }
-
- private IProject getCurrentProject() {
- IFile file = ((IFileEditorInput) getEditor().getEditorInput())
- .getFile();
- if (file != null) {
- IProject project = file.getProject();
- return project;
- }
- return null;
- }
-
- protected IFile createEditorInput(String filePath) {
- String workspacePath = this.getWorkspaceFilePath(filePath);
- IProject project = getCurrentProject();
- if (project != null) {
- IResource resource = project.findMember(new Path(workspacePath));
- if (resource instanceof IFile) {
- return (IFile) resource;
- }
- }
- return null;
- }
-
- private Button createFileActionButton(Composite parent, FormToolkit tool,
- String text) {
- Button button = tool.createButton(parent, text, SWT.NONE);
- GridData gd = new GridData(GridData.FILL_HORIZONTAL);
- button.setLayoutData(gd);
- return button;
- }
-
- private void setTransformType(String type) {
- if (this.transformType != null) {
- SmooksModelUtils.setTransformType(transformType, type);
- ((SmooksFormEditor) getEditor()).fireEditorDirty(true);
- }
- }
-
- protected void hookButtons() {
- saxButton.addSelectionListener(new SelectionAdapter() {
-
- public void widgetSelected(SelectionEvent e) {
- setTransformType(SmooksModelConstants.SAX);
- }
-
- });
-
- domButton.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- setTransformType(SmooksModelConstants.DOM);
- }
- });
-
- saxdomButton.addSelectionListener(new SelectionAdapter() {
-
- public void widgetSelected(SelectionEvent e) {
- setTransformType(SmooksModelConstants.SAX_DOM);
- }
-
- });
-
- addFileButton.addSelectionListener(new SelectionAdapter() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- addFileImport();
- }
-
- });
-
- removeFileButton.addSelectionListener(new SelectionAdapter() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- removeFileImport();
- }
-
- });
-
- editFileButton.addSelectionListener(new SelectionAdapter() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- editFileImport();
- }
-
- });
- }
-
- protected void editFileImport() {
- IStructuredSelection selection = (IStructuredSelection) fileViewer
- .getSelection();
- Object obj = selection.getFirstElement();
- if (obj instanceof ImportType) {
- String filePath = getWorkspaceFilePath(((ImportType) obj).getFile());
- IProject project = getCurrentProject();
- if (project != null) {
- IResource resource = project.findMember(new Path(filePath));
- IFile[] files = WorkspaceResourceDialog.openFileSelection(
- getSite().getShell(), "Select Files", "", false,
- new Object[] { resource }, Collections.EMPTY_LIST);
- if (files != null) {
- IPath path1 = files[0].getFullPath().removeFirstSegments(1);
- String s = path1.toString();
- if (s.startsWith("/") || s.startsWith("\\")) {
-
- } else {
- s = "/" + s;
- }
- ((ImportType) obj).setFile("classpath:" + s);
- fileViewer.refresh();
- ((SmooksFormEditor) getEditor()).fireEditorDirty(true);
- }
- }
-
- }
- }
-
- protected void removeFileImport() {
- IStructuredSelection selection = (IStructuredSelection) fileViewer
- .getSelection();
- NormalSmooksModelPackage modelPackage = getModelPackage();
- if (modelPackage != null) {
- modelPackage.getSmooksResourceList().getAbstractResourceConfig()
- .removeAll(selection.toList());
- fileViewer.refresh();
- ((SmooksFormEditor) getEditor()).fireEditorDirty(true);
- }
- }
-
- protected void addFileImport() {
- IFile[] files = WorkspaceResourceDialog.openFileSelection(getSite()
- .getShell(), "Select Files", "", false, null,
- Collections.EMPTY_LIST);
- if (files != null && files.length > 0) {
- ImportType fileImport = SmooksFactory.eINSTANCE.createImportType();
- IPath path1 = files[0].getFullPath().removeFirstSegments(1);
- String s = path1.toString();
- if (s.startsWith("/") || s.startsWith("\\")) {
-
- } else {
- s = "/" + s;
- }
- fileImport.setFile("classpath:" + s);
- NormalSmooksModelPackage modelPackage = getModelPackage();
- if (modelPackage != null) {
- Command command = AddCommand
- .create(
- ((SmooksFormEditor) getEditor())
- .getEditingDomain(),
- modelPackage.getSmooksResourceList(),
- SmooksPackage.eINSTANCE
- .getSmooksResourceListType_AbstractResourceConfig(),
- fileImport);
- ((SmooksFormEditor) getEditor()).getEditingDomain()
- .getCommandStack().execute(command);
- fileViewer.refresh();
- ((SmooksFormEditor) getEditor()).fireEditorDirty(true);
- }
- }
- }
-
- private Button createTypeSelectRadioButton(Composite parent,
- FormToolkit tool, String labelName) {
- Button button = tool.createButton(parent, labelName, SWT.RADIO);
- return button;
- }
-
- private String getWorkspaceFilePath(String filePath) {
- if (filePath == null)
- return "";
- if (filePath.indexOf(":") != -1) {
- int index = filePath.indexOf(":");
- return filePath.substring(index + 1, filePath.length());
- }
- return filePath;
- }
-
- /**
- * @return the modelPackage
- */
- public NormalSmooksModelPackage getModelPackage() {
- return modelPackage;
- }
-
- /**
- * @param modelPackage
- * the modelPackage to set
- */
- public void setModelPackage(NormalSmooksModelPackage modelPackage) {
- if (modelPackage == this.modelPackage)
- return;
- this.modelPackage = modelPackage;
- if (resourceBlock != null)
- this.resourceBlock.setModelPackage(this.modelPackage);
- }
-
- public void endAnalyze(AnalyzeResult result) {
- if (result.getError() == null) {
- disableGUI = false;
- SmooksFormEditor parentEditor = (SmooksFormEditor) getEditor();
- NormalSmooksModelPackage pa = parentEditor
- .createNewSmooksModelPackage();
- SmooksGraphicalFormPage graphicalEditor = (SmooksGraphicalFormPage) result
- .getSourceEdtior();
- MappingResourceConfigList rclist = graphicalEditor
- .getMappingResourceConfigList();
- // for make sure that the SmooksResourceConfig model was the same :
- if (rclist != null) {
- List<ResourceConfigType> renderList = rclist
- .getGraphRenderResourceConfigList();
- if (renderList != null && renderList.size() > 0) {
- ResourceConfigType resourceConfig = renderList.get(0);
- SmooksResourceListType rootList = (SmooksResourceListType) resourceConfig
- .eContainer();
- if (!(rootList == pa.getSmooksResourceList())) {
- pa.setSmooksResourceList(rootList);
- }
- }
- pa.setHidenSmooksElements(renderList);
- }
- setModelPackage(pa);
- } else {
- setModelPackage(null);
- disableGUI = true;
- }
- initOtherConfigurationsGUI();
- if (resourceBlock != null)
- this.resourceBlock.initViewers(transformType);
- setGUIStates();
- }
-
- private class FileImportContentProvider implements
- IStructuredContentProvider {
-
- public Object[] getElements(Object inputElement) {
- if (inputElement instanceof List) {
- return ((List) inputElement).toArray();
- }
- return new Object[] {};
- }
-
- public void dispose() {
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
- }
-
- private class FileImportLabelProvider extends LabelProvider {
-
- @Override
- public Image getImage(Object element) {
- if (element instanceof ImportType) {
- String path = getWorkspaceFilePath(((ImportType) element)
- .getFile());
- IProject project = getCurrentProject();
- IResource resource = project.findMember(new Path(path));
- if (resource == null || !resource.exists())
- return SmooksUIActivator.getDefault().getImageRegistry()
- .get(SmooksGraphConstants.IMAGE_ERROR);
- }
- return super.getImage(element);
- }
-
- @Override
- public String getText(Object element) {
- if (element instanceof ImportType) {
- return getWorkspaceFilePath(((ImportType) element).getFile());
- }
- return super.getText(element);
- }
-
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.smooks.ui.editors;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.ui.dialogs.WorkspaceResourceDialog;
+import org.eclipse.emf.edit.command.AddCommand;
+import org.eclipse.emf.edit.command.MoveCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.forms.editor.FormPage;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+import org.eclipse.ui.forms.widgets.Section;
+import org.eclipse.ui.ide.IDE;
+import org.jboss.tools.smooks.analyzer.MappingResourceConfigList;
+import org.jboss.tools.smooks.analyzer.NormalSmooksModelPackage;
+import org.jboss.tools.smooks.model.ImportType;
+import org.jboss.tools.smooks.model.ParamType;
+import org.jboss.tools.smooks.model.ResourceConfigType;
+import org.jboss.tools.smooks.model.SmooksFactory;
+import org.jboss.tools.smooks.model.SmooksPackage;
+import org.jboss.tools.smooks.model.SmooksResourceListType;
+import org.jboss.tools.smooks.model.util.SmooksModelConstants;
+import org.jboss.tools.smooks.model.util.SmooksModelUtils;
+import org.jboss.tools.smooks.ui.AnalyzeResult;
+import org.jboss.tools.smooks.ui.IAnalyzeListener;
+import org.jboss.tools.smooks.ui.SmooksUIActivator;
+import org.jboss.tools.smooks.ui.gef.util.GraphicsConstants;
+import org.jboss.tools.smooks.utils.SmooksGraphConstants;
+import org.jboss.tools.smooks.utils.UIUtils;
+
+/**
+ * @author Dart Peng Date : 2008-9-9
+ */
+public class SmooksNormalContentEditFormPage extends FormPage implements
+ IAnalyzeListener {
+
+ protected NormalSmooksModelPackage modelPackage = null;
+
+ protected SmooksResourceConfigFormBlock resourceBlock = null;
+
+ protected ResourceConfigType transformType = null;
+
+ private Button saxButton;
+
+ private Button domButton;
+
+ private Button saxdomButton;
+
+ private EditingDomain domain;
+
+ private List hidenResourceConfigs;
+
+ private boolean disableGUI = false;
+
+ public boolean isDisableGUI() {
+ return disableGUI;
+ }
+
+ public void setDisableGUI(boolean disableGUI) {
+ this.disableGUI = disableGUI;
+ setGUIStates();
+ }
+
+ private Section parseTypeSection;
+
+ private Button addFileButton;
+
+ private Button removeFileButton;
+
+ private Button editFileButton;
+
+ private TableViewer fileViewer;
+
+ public SmooksNormalContentEditFormPage(FormEditor editor, String id,
+ String title, NormalSmooksModelPackage modelPacakge) {
+ super(editor, id, title);
+ domain = ((SmooksFormEditor) editor).getEditingDomain();
+ this.createResourceConfigFormBlock();
+ this.setModelPackage(modelPacakge);
+ }
+
+ public SmooksNormalContentEditFormPage(String id, String title,
+ NormalSmooksModelPackage modelPacakge) {
+ super(id, title);
+ this.createResourceConfigFormBlock();
+ this.setModelPackage(modelPacakge);
+ }
+
+ protected void createResourceConfigFormBlock() {
+ resourceBlock = new SmooksResourceConfigFormBlock();
+ resourceBlock.setDomain(getEditingDomain());
+ resourceBlock.setParentEditor((SmooksFormEditor) this.getEditor());
+ }
+
+ protected EditingDomain getEditingDomain() {
+ return ((SmooksFormEditor) getEditor()).getEditingDomain();
+ }
+
+ @Override
+ protected void createFormContent(IManagedForm managedForm) {
+ final ScrolledForm form = managedForm.getForm();
+ FormToolkit tool = managedForm.getToolkit();
+ tool.decorateFormHeading(form.getForm());
+ GridLayout gridLayout = UIUtils.createGeneralFormEditorLayout(1);
+ resourceBlock.createContent(managedForm);
+ Composite rootMainControl = form.getBody();
+ form
+ .setText(Messages
+ .getString("SmooksNormalContentEditFormPage.ConfigurationPageText"));
//$NON-NLS-1$
+ createSmooksTypeGUI(rootMainControl, tool);
+ form.getBody().setLayout(gridLayout);
+ form.pack();
+ this.initOtherConfigurationsGUI();
+ resourceBlock.initViewers(transformType);
+
+ setGUIStates();
+ }
+
+ @Override
+ public boolean isDirty() {
+ return false;
+ }
+
+ public void setGUIStates() {
+ if (resourceBlock != null) {
+ resourceBlock.setSectionStates(!disableGUI);
+ }
+
+ if (this.parseTypeSection != null && !parseTypeSection.isDisposed()) {
+ parseTypeSection.setEnabled(!disableGUI);
+ }
+ }
+
+ private ResourceConfigType createTransformType() {
+ ResourceConfigType transformType = SmooksFactory.eINSTANCE
+ .createResourceConfigType();
+ AddCommand.create(
+ domain,
+ modelPackage.getSmooksResourceList(),
+ SmooksPackage.eINSTANCE
+ .getSmooksResourceListType_AbstractResourceConfig(),
+ transformType).execute();
+ MoveCommand.create(domain, modelPackage.getSmooksResourceList(),
+ SmooksPackage.eINSTANCE
+ .getSmooksResourceListType_AbstractResourceConfig(),
+ transformType, 0);
+ transformType.setSelector(SmooksModelConstants.GLOBAL_PARAMETERS);
+ ParamType typeParam = SmooksFactory.eINSTANCE.createParamType();
+ typeParam.setName(SmooksModelConstants.STREAM_FILTER_TYPE);
+ transformType.getParam().add(typeParam);
+
+ return transformType;
+ }
+
+ protected void initOtherConfigurationsGUI() {
+ if (saxButton != null)
+ saxButton.setSelection(false);
+ if (domButton != null)
+ domButton.setSelection(false);
+ if (saxdomButton != null)
+ saxdomButton.setSelection(false);
+ if (this.getModelPackage() != null) {
+ List list = modelPackage.getSmooksResourceList()
+ .getAbstractResourceConfig();
+ if (fileViewer != null) {
+ fileViewer.setInput(list);
+ }
+ for (Iterator iterator = list.iterator(); iterator.hasNext();) {
+ Object sr = iterator.next();
+ if (sr instanceof ResourceConfigType) {
+ if (SmooksModelUtils
+ .isTransformTypeResourceConfig((ResourceConfigType) sr)) {
+ this.transformType = (ResourceConfigType) sr;
+ break;
+ }
+ }
+ }
+ if (transformType == null) {
+ transformType = createTransformType();
+ }
+ if (transformType != null) {
+ String type = SmooksModelUtils.getTransformType(transformType);
+ if (SmooksModelConstants.SAX.equals(type)) {
+ if (saxButton != null)
+ saxButton.setSelection(true);
+ }
+ if (SmooksModelConstants.DOM.equals(type)) {
+ if (domButton != null)
+ domButton.setSelection(true);
+ }
+ if ("SAX/DOM".equals(type)) { //$NON-NLS-1$
+ if (saxdomButton != null)
+ saxdomButton.setSelection(true);
+ }
+ }
+ }
+ }
+
+ protected void createSmooksTypeGUI(Composite mainComposite, FormToolkit tool) {
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ parseTypeSection = tool.createSection(mainComposite, Section.TITLE_BAR
+ | Section.TWISTIE);
+ parseTypeSection.setLayoutData(gd);
+ Composite otherConfigurationComposite = tool
+ .createComposite(parseTypeSection);
+ parseTypeSection.setClient(otherConfigurationComposite);
+ parseTypeSection.setText(Messages
+ .getString("SmooksNormalContentEditFormPage.SmooksParseType"));
//$NON-NLS-1$
+ GridLayout layout1 = new GridLayout();
+ otherConfigurationComposite.setLayout(layout1);
+
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan = 2;
+ otherConfigurationComposite.setLayoutData(gd);
+ GridLayout layout = new GridLayout();
+ otherConfigurationComposite.setLayout(layout);
+
+ Composite buttonComposite = tool
+ .createComposite(otherConfigurationComposite);
+ GridLayout buttonAreaLayout = new GridLayout();
+ buttonAreaLayout.numColumns = 4;
+ buttonComposite.setLayout(buttonAreaLayout);
+
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ buttonComposite.setLayoutData(gd);
+
+ tool.createLabel(buttonComposite, "Parse Type : ");
+ saxButton = createTypeSelectRadioButton(buttonComposite, tool,
+ SmooksModelConstants.SAX);
+ domButton = createTypeSelectRadioButton(buttonComposite, tool,
+ SmooksModelConstants.DOM);
+ saxdomButton = createTypeSelectRadioButton(buttonComposite, tool,
+ SmooksModelConstants.SAX_DOM);
+
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan = 2;
+// tool.createSeparator(otherConfigurationComposite, SWT.HORIZONTAL)
+// .setLayoutData(gd);
+
+ // below is for creating import files GUI.
+ Composite importFileComposite = tool
+ .createComposite(otherConfigurationComposite);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ GridLayout fileLayout = new GridLayout();
+ fileLayout.numColumns = 2;
+ importFileComposite.setLayoutData(gd);
+ importFileComposite.setLayout(fileLayout);
+ // importFileComposite.setBackground(ColorConstants.black);
+
+ Label fileListLabel = tool.createLabel(importFileComposite,
+ "Import Files :");
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan = 2;
+ fileListLabel.setLayoutData(gd);
+
+ Composite viewerComposite = tool.createComposite(importFileComposite);
+ FillLayout viewerLayout = new FillLayout();
+ viewerLayout.marginHeight = 1;
+ viewerLayout.marginWidth = 1;
+ viewerComposite.setLayout(viewerLayout);
+ fileViewer = new TableViewer(viewerComposite, SWT.NONE);
+ fileViewer.setContentProvider(new FileImportContentProvider());
+ fileViewer.setLabelProvider(new FileImportLabelProvider());
+ if (getModelPackage() != null) {
+ SmooksResourceListType listType = getModelPackage()
+ .getSmooksResourceList();
+ if (listType != null && listType.getAbstractResourceConfig() != null) {
+ fileViewer.setInput(listType.getAbstractResourceConfig());
+ }
+ }
+ fileViewer.addDoubleClickListener(new IDoubleClickListener() {
+ public void doubleClick(DoubleClickEvent event) {
+ openFile(fileViewer.getSelection());
+ }
+ });
+ fileViewer.addFilter(new ViewerFilter() {
+
+ @Override
+ public boolean select(Viewer viewer, Object parentElement,
+ Object element) {
+ if (element instanceof ImportType)
+ return true;
+ return false;
+ }
+
+ });
+ gd = new GridData(GridData.FILL_BOTH);
+ viewerComposite.setLayoutData(gd);
+ viewerComposite.setBackground(GraphicsConstants.groupBorderColor);
+ tool.paintBordersFor(viewerComposite);
+
+ Composite fileActionComposite = tool
+ .createComposite(importFileComposite);
+ gd = new GridData(GridData.FILL_VERTICAL);
+ fileActionComposite.setLayoutData(gd);
+
+ GridLayout fileActionLayout = new GridLayout();
+ fileActionComposite.setLayout(fileActionLayout);
+
+ addFileButton = createFileActionButton(fileActionComposite, tool, "Add");
+ removeFileButton = createFileActionButton(fileActionComposite, tool,
+ "Remove");
+ editFileButton = createFileActionButton(fileActionComposite, tool,
+ "Edit");
+
+ tool.paintBordersFor(fileActionComposite);
+
+ hookButtons();
+ }
+
+ protected void openFile(ISelection selection) {
+ Object obj = ((IStructuredSelection) selection).getFirstElement();
+ if (obj != null && obj instanceof ImportType) {
+ String filePath = ((ImportType) obj).getFile();
+ IFile input = createEditorInput(filePath);
+ if (input != null) {
+ try {
+ IDE.openEditor(SmooksUIActivator.getDefault()
+ .getWorkbench().getActiveWorkbenchWindow()
+ .getActivePage(), input);
+ } catch (PartInitException e) {
+ UIUtils.showErrorDialog(getSite().getShell(), UIUtils
+ .createErrorStatus(e));
+ }
+ }
+ }
+ }
+
+ private IProject getCurrentProject() {
+ IFile file = ((IFileEditorInput) getEditor().getEditorInput())
+ .getFile();
+ if (file != null) {
+ IProject project = file.getProject();
+ return project;
+ }
+ return null;
+ }
+
+ protected IFile createEditorInput(String filePath) {
+ String workspacePath = this.getWorkspaceFilePath(filePath);
+ IProject project = getCurrentProject();
+ if (project != null) {
+ IResource resource = project.findMember(new Path(workspacePath));
+ if (resource instanceof IFile) {
+ return (IFile) resource;
+ }
+ }
+ return null;
+ }
+
+ private Button createFileActionButton(Composite parent, FormToolkit tool,
+ String text) {
+ Button button = tool.createButton(parent, text, SWT.NONE);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ button.setLayoutData(gd);
+ return button;
+ }
+
+ private void setTransformType(String type) {
+ if (this.transformType != null) {
+ SmooksModelUtils.setTransformType(transformType, type);
+ ((SmooksFormEditor) getEditor()).fireEditorDirty(true);
+ }
+ }
+
+ protected void hookButtons() {
+ saxButton.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent e) {
+ setTransformType(SmooksModelConstants.SAX);
+ }
+
+ });
+
+ domButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ setTransformType(SmooksModelConstants.DOM);
+ }
+ });
+
+ saxdomButton.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent e) {
+ setTransformType(SmooksModelConstants.SAX_DOM);
+ }
+
+ });
+
+ addFileButton.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ addFileImport();
+ }
+
+ });
+
+ removeFileButton.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ removeFileImport();
+ }
+
+ });
+
+ editFileButton.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ editFileImport();
+ }
+
+ });
+ }
+
+ protected void editFileImport() {
+ IStructuredSelection selection = (IStructuredSelection) fileViewer
+ .getSelection();
+ Object obj = selection.getFirstElement();
+ if (obj instanceof ImportType) {
+ String filePath = getWorkspaceFilePath(((ImportType) obj).getFile());
+ IProject project = getCurrentProject();
+ if (project != null) {
+ IResource resource = project.findMember(new Path(filePath));
+ IFile[] files = WorkspaceResourceDialog.openFileSelection(
+ getSite().getShell(), "Select Files", "", false,
+ new Object[] { resource }, Collections.EMPTY_LIST);
+ if (files != null) {
+ IPath path1 = files[0].getFullPath().removeFirstSegments(1);
+ String s = path1.toString();
+ if (s.startsWith("/") || s.startsWith("\\")) {
+
+ } else {
+ s = "/" + s;
+ }
+ ((ImportType) obj).setFile("classpath:" + s);
+ fileViewer.refresh();
+ ((SmooksFormEditor) getEditor()).fireEditorDirty(true);
+ }
+ }
+
+ }
+ }
+
+ protected void removeFileImport() {
+ IStructuredSelection selection = (IStructuredSelection) fileViewer
+ .getSelection();
+ NormalSmooksModelPackage modelPackage = getModelPackage();
+ if (modelPackage != null) {
+ modelPackage.getSmooksResourceList().getAbstractResourceConfig()
+ .removeAll(selection.toList());
+ fileViewer.refresh();
+ ((SmooksFormEditor) getEditor()).fireEditorDirty(true);
+ }
+ }
+
+ protected void addFileImport() {
+ IFile[] files = WorkspaceResourceDialog.openFileSelection(getSite()
+ .getShell(), "Select Files", "", false, null,
+ Collections.EMPTY_LIST);
+ if (files != null && files.length > 0) {
+ ImportType fileImport = SmooksFactory.eINSTANCE.createImportType();
+ IPath path1 = files[0].getFullPath().removeFirstSegments(1);
+ String s = path1.toString();
+ if (s.startsWith("/") || s.startsWith("\\")) {
+
+ } else {
+ s = "/" + s;
+ }
+ fileImport.setFile("classpath:" + s);
+ NormalSmooksModelPackage modelPackage = getModelPackage();
+ if (modelPackage != null) {
+ Command command = AddCommand
+ .create(
+ ((SmooksFormEditor) getEditor())
+ .getEditingDomain(),
+ modelPackage.getSmooksResourceList(),
+ SmooksPackage.eINSTANCE
+ .getSmooksResourceListType_AbstractResourceConfig(),
+ fileImport);
+ ((SmooksFormEditor) getEditor()).getEditingDomain()
+ .getCommandStack().execute(command);
+ fileViewer.refresh();
+ ((SmooksFormEditor) getEditor()).fireEditorDirty(true);
+ }
+ }
+ }
+
+ private Button createTypeSelectRadioButton(Composite parent,
+ FormToolkit tool, String labelName) {
+ Button button = tool.createButton(parent, labelName, SWT.RADIO);
+ return button;
+ }
+
+ private String getWorkspaceFilePath(String filePath) {
+ if (filePath == null)
+ return "";
+ if (filePath.indexOf(":") != -1) {
+ int index = filePath.indexOf(":");
+ return filePath.substring(index + 1, filePath.length());
+ }
+ return filePath;
+ }
+
+ /**
+ * @return the modelPackage
+ */
+ public NormalSmooksModelPackage getModelPackage() {
+ return modelPackage;
+ }
+
+ /**
+ * @param modelPackage
+ * the modelPackage to set
+ */
+ public void setModelPackage(NormalSmooksModelPackage modelPackage) {
+ if (modelPackage == this.modelPackage)
+ return;
+ this.modelPackage = modelPackage;
+ if (resourceBlock != null)
+ this.resourceBlock.setModelPackage(this.modelPackage);
+ }
+
+ public void endAnalyze(AnalyzeResult result) {
+ if (result.getError() == null) {
+ disableGUI = false;
+ SmooksFormEditor parentEditor = (SmooksFormEditor) getEditor();
+ NormalSmooksModelPackage pa = parentEditor
+ .createNewSmooksModelPackage();
+ SmooksGraphicalFormPage graphicalEditor = (SmooksGraphicalFormPage) result
+ .getSourceEdtior();
+ MappingResourceConfigList rclist = graphicalEditor
+ .getMappingResourceConfigList();
+ // for make sure that the SmooksResourceConfig model was the same :
+ if (rclist != null) {
+ List<ResourceConfigType> renderList = rclist
+ .getGraphRenderResourceConfigList();
+ if (renderList != null && renderList.size() > 0) {
+ ResourceConfigType resourceConfig = renderList.get(0);
+ SmooksResourceListType rootList = (SmooksResourceListType) resourceConfig
+ .eContainer();
+ if (!(rootList == pa.getSmooksResourceList())) {
+ pa.setSmooksResourceList(rootList);
+ }
+ }
+ pa.setHidenSmooksElements(renderList);
+ }
+ setModelPackage(pa);
+ } else {
+ setModelPackage(null);
+ disableGUI = true;
+ }
+ initOtherConfigurationsGUI();
+ if (resourceBlock != null)
+ this.resourceBlock.initViewers(transformType);
+ setGUIStates();
+ }
+
+ private class FileImportContentProvider implements
+ IStructuredContentProvider {
+
+ public Object[] getElements(Object inputElement) {
+ if (inputElement instanceof List) {
+ return ((List) inputElement).toArray();
+ }
+ return new Object[] {};
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ }
+
+ private class FileImportLabelProvider extends LabelProvider {
+
+ @Override
+ public Image getImage(Object element) {
+ if (element instanceof ImportType) {
+ String path = getWorkspaceFilePath(((ImportType) element)
+ .getFile());
+ IProject project = getCurrentProject();
+ IResource resource = project.findMember(new Path(path));
+ if (resource == null || !resource.exists())
+ return SmooksUIActivator.getDefault().getImageRegistry()
+ .get(SmooksGraphConstants.IMAGE_ERROR);
+ }
+ return super.getImage(element);
+ }
+
+ @Override
+ public String getText(Object element) {
+ if (element instanceof ImportType) {
+ return getWorkspaceFilePath(((ImportType) element).getFile());
+ }
+ return super.getText(element);
+ }
+
+ }
+}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/modelparser/SmooksConfigurationFileGenerateContext.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/modelparser/SmooksConfigurationFileGenerateContext.java 2009-03-06
01:15:19 UTC (rev 14063)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/modelparser/SmooksConfigurationFileGenerateContext.java 2009-03-06
03:25:26 UTC (rev 14064)
@@ -22,6 +22,7 @@
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.widgets.Shell;
+import org.jboss.tools.smooks.graphical.GraphInformations;
import org.jboss.tools.smooks.graphical.Param;
import org.jboss.tools.smooks.model.SmooksResourceListType;
import org.jboss.tools.smooks.ui.editors.SmooksGraphicalFormPage;
@@ -43,7 +44,16 @@
protected EditingDomain domain;
protected SmooksGraphicalFormPage smooksGraphcalPage = null;
protected EditDomain gefDomain;
+ protected GraphInformations graphInformations = null;
+ public GraphInformations getGraphInformations() {
+ return graphInformations;
+ }
+
+ public void setGraphInformations(GraphInformations graphInformations) {
+ this.graphInformations = graphInformations;
+ }
+
public SmooksGraphicalFormPage getSmooksGraphcalPage() {
return smooksGraphcalPage;
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/popup/SmooksAction.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/popup/SmooksAction.java 2009-03-06
01:15:19 UTC (rev 14063)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/popup/SmooksAction.java 2009-03-06
03:25:26 UTC (rev 14064)
@@ -56,7 +56,6 @@
}
public void run(){
-
}
public void selectionChanged(ISelection selection) {
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/xml/model/AbstractXMLObject.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/xml/model/AbstractXMLObject.java 2009-03-06
01:15:19 UTC (rev 14063)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/xml/model/AbstractXMLObject.java 2009-03-06
03:25:26 UTC (rev 14064)
@@ -16,6 +16,7 @@
import java.util.List;
import org.dom4j.Element;
+import org.dom4j.QName;
import org.jboss.tools.smooks.ui.IXMLStructuredObject;
import org.jboss.tools.smooks.ui.editors.TransformDataTreeViewer;
@@ -72,7 +73,7 @@
this.name = name;
Element element = this.getReferenceElement();
if(element != null){
- element.setName(name);
+ element.setQName(new QName(name,element.getNamespace()));
}
support.firePropertyChange(TransformDataTreeViewer.NODE_PROPERTY_EVENT, oldName,
this.name);
}
@@ -115,6 +116,14 @@
support.removePropertyChangeListener(listener);
}
+ public void cleanAllNodePropertyChangeListeners() {
+ PropertyChangeListener[] ps = support.getPropertyChangeListeners();
+ for (int i = 0; i < ps.length; i++) {
+ PropertyChangeListener p = ps[i];
+ support.removePropertyChangeListener(p);
+ }
+ }
+
public List<IXMLStructuredObject> getChildren() {
List children = getXMLNodeChildren();
return children;
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/xml/model/ITransformTreeNode.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/xml/model/ITransformTreeNode.java 2009-03-06
01:15:19 UTC (rev 14063)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/xml/model/ITransformTreeNode.java 2009-03-06
03:25:26 UTC (rev 14064)
@@ -14,4 +14,6 @@
public void addNodePropetyChangeListener(PropertyChangeListener listener);
public void removeNodePropetyChangeListener(PropertyChangeListener listener);
+
+ public void cleanAllNodePropertyChangeListeners();
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/xml/model/XMLObjectAnalyzer.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/xml/model/XMLObjectAnalyzer.java 2009-03-06
01:15:19 UTC (rev 14063)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/xml/model/XMLObjectAnalyzer.java 2009-03-06
03:25:26 UTC (rev 14064)
@@ -81,6 +81,7 @@
}
protected TagObject parseElement(Element element, TagObject parentTag , String[]
ignoreNodeNames) {
+
if(isIgnoreNode(element, ignoreNodeNames))
return null;
boolean canAdd = false;