Author: tfennelly
Date: 2010-01-30 09:37:31 -0500 (Sat, 30 Jan 2010)
New Revision: 20034
Added:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/propertySections/DecodeParamMetaData.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/propertySections/DecodeParamMetaDataFactory.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/javamapping/JavaNode.java
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/propertySections/Messages.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/propertySections/ValueDecodeParamSection.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/propertySections/messages.properties
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/javamapping/JavaBeanChildGraphModel.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5687
Improve Decode Param support
Added:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/propertySections/DecodeParamMetaData.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/propertySections/DecodeParamMetaData.java
(rev 0)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/propertySections/DecodeParamMetaData.java 2010-01-30
14:37:31 UTC (rev 20034)
@@ -0,0 +1,54 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2009, JBoss Inc.
+ */
+package org.jboss.tools.smooks.editor.propertySections;
+
+/**
+ * Java value binding data decode parameter metadata.
+ *
+ * @author <a
href="mailto:tom.fennelly@jboss.com">tom.fennelly@jboss.com</a>
+ */
+public class DecodeParamMetaData {
+
+ private String name;
+ private String defaultVal;
+ private boolean requiresConfiguration;
+
+ public DecodeParamMetaData(String name, String defaultVal) {
+ this.name = name;
+ this.defaultVal = defaultVal;
+ }
+
+ public DecodeParamMetaData(String name, String defaultVal, boolean
requiresConfiguration) {
+ this(name, defaultVal);
+ this.requiresConfiguration = requiresConfiguration;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getDefaultVal() {
+ return defaultVal;
+ }
+
+ public boolean isRequiresConfiguration() {
+ return requiresConfiguration;
+ }
+}
Property changes on:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/propertySections/DecodeParamMetaData.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/propertySections/DecodeParamMetaDataFactory.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/propertySections/DecodeParamMetaDataFactory.java
(rev 0)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/propertySections/DecodeParamMetaDataFactory.java 2010-01-30
14:37:31 UTC (rev 20034)
@@ -0,0 +1,58 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2009, JBoss Inc.
+ */
+package org.jboss.tools.smooks.editor.propertySections;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.milyn.javabean.DataDecoder;
+import org.milyn.javabean.decoders.CalendarDecoder;
+import org.milyn.javabean.decoders.DateDecoder;
+import org.milyn.javabean.decoders.LocaleAwareDateDecoder;
+import org.milyn.javabean.decoders.SqlDateDecoder;
+import org.milyn.javabean.decoders.SqlTimeDecoder;
+
+/**
+ * Factory class for storing decode parameter metadata..
+ *
+ * @author <a
href="mailto:tom.fennelly@jboss.com">tom.fennelly@jboss.com</a>
+ */
+public class DecodeParamMetaDataFactory {
+
+ private static Map<Class<? extends DataDecoder>, DecodeParamMetaData[]>
configMap = new HashMap<Class<? extends DataDecoder>,
DecodeParamMetaData[]>();
+
+ static {
+ DecodeParamMetaData[] dateDecodeMD = new DecodeParamMetaData[] {
+ new DecodeParamMetaData(LocaleAwareDateDecoder.FORMAT,
LocaleAwareDateDecoder.DEFAULT_DATE_FORMAT),
+ new DecodeParamMetaData(LocaleAwareDateDecoder.LOCALE_COUNTRY_CODE, null),
+ new DecodeParamMetaData(LocaleAwareDateDecoder.LOCALE_LANGUAGE_CODE, null)
+ };
+
+ // The date decoders all have the same basic configuration...
+ configMap.put(DateDecoder.class, dateDecodeMD);
+ configMap.put(CalendarDecoder.class, dateDecodeMD);
+ configMap.put(SqlDateDecoder.class, dateDecodeMD);
+ configMap.put(SqlTimeDecoder.class, dateDecodeMD);
+ }
+
+ public static DecodeParamMetaData[] getDecodeParamMetaData(Class<? extends
DataDecoder> decoder) {
+ return configMap.get(decoder);
+ }
+}
Property changes on:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/propertySections/DecodeParamMetaDataFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/propertySections/Messages.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/propertySections/Messages.java 2010-01-29
23:30:31 UTC (rev 20033)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/propertySections/Messages.java 2010-01-30
14:37:31 UTC (rev 20034)
@@ -22,6 +22,8 @@
public static String ValueDecodeParamSection_NullText;
public static String ValueDecodeParamSection_ParamNameColumnText;
public static String ValueDecodeParamSection_ParamValueColumnText;
+ public static String ValueDecodeParamSection_EnumParamNameColumnText;
+ public static String ValueDecodeParamSection_EnumParamValueColumnText;
public static String ValueDecodeParamSection_SectionTitle;
static {
// initialize resource bundle
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/propertySections/ValueDecodeParamSection.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/propertySections/ValueDecodeParamSection.java 2010-01-29
23:30:31 UTC (rev 20033)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/propertySections/ValueDecodeParamSection.java 2010-01-30
14:37:31 UTC (rev 20034)
@@ -17,17 +17,16 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.Map.Entry;
-import org.eclipse.core.resources.IProject;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CompoundCommand;
-import org.eclipse.emf.edit.command.AddCommand;
import org.eclipse.emf.edit.command.RemoveCommand;
import org.eclipse.emf.edit.command.SetCommand;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.IStructuredContentProvider;
@@ -50,23 +49,21 @@
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.forms.IFormColors;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
-import org.jboss.tools.smooks.configuration.editors.SelectorCreationDialog;
-import org.jboss.tools.smooks.configuration.editors.javabean.JavaBeanModel;
-import org.jboss.tools.smooks.configuration.editors.uitls.ProjectClassLoader;
-import org.jboss.tools.smooks.configuration.editors.uitls.SmooksUIUtils;
import org.jboss.tools.smooks.editor.ISmooksModelProvider;
+import org.jboss.tools.smooks.gef.model.AbstractSmooksGraphicalModel;
import org.jboss.tools.smooks.gef.tree.model.TreeNodeConnection;
+import
org.jboss.tools.smooks.graphical.editors.model.javamapping.JavaBeanChildGraphModel;
import org.jboss.tools.smooks.model.javabean12.DecodeParamType;
-import org.jboss.tools.smooks.model.javabean12.Javabean12Factory;
import org.jboss.tools.smooks.model.javabean12.Javabean12Package;
import org.jboss.tools.smooks.model.javabean12.ValueType;
import org.milyn.javabean.DataDecoder;
+import org.milyn.javabean.decoders.EnumDecoder;
+import org.milyn.javabean.decoders.IntegerDecoder;
/**
* @author Dart
@@ -77,6 +74,9 @@
private Composite controlComposite;
private TableViewer paramterViewer;
private CCombo decoderCombo;
+ boolean isEnumTarget;
+ private TableColumn nameColumn;
+ private TableColumn valueColumn;
private static List<String> DECODERS = new ArrayList<String>();
@@ -189,74 +189,6 @@
}
}
- private String[] getDecoderParametersName(String decoder) {
- if (decoder != null) {
- if ("Date".equals(decoder)) {
- return new String[] { "format", "locale-language",
"locale-country" };
- }
-
- if ("Enum".equals(decoder)) {
- TreeNodeConnection lineModel = (TreeNodeConnection) getPresentSelectedGraphModel();
- Object model = lineModel.getTargetNode().getData();
- model = AdapterFactoryEditingDomain.unwrap(model);
- if (model != null && model instanceof ValueType) {
- String[] enumFieldsString = null;
- List<Object> inputs = SelectorCreationDialog.generateInputData(SmooksUIUtils
- .getSmooks11ResourceListType(getSmooksModelProvider().getSmooksModel()));
- if (inputs != null && !inputs.isEmpty()) {
- Object input = inputs.get(0);
- if (input instanceof JavaBeanModel) {
- String path = ((ValueType) model).getData();
- JavaBeanModel beanModel = (JavaBeanModel)
SmooksUIUtils.localXMLNodeWithPath(path,
- (JavaBeanModel) input);
- if (beanModel != null) {
- String clazz = beanModel.getBeanClassString();
- if (clazz != null) {
- clazz = clazz.trim();
- IProject project = ((IFileEditorInput)
getEditorPart().getEditorInput()).getFile()
- .getProject();
- try {
- ProjectClassLoader classLoader = new ProjectClassLoader(JavaCore
- .create(project));
- Class<?> enumType = classLoader.loadClass(clazz);
- if (enumType.isEnum()) {
- Field[] fields = enumType.getDeclaredFields();
- if (fields != null) {
- List<String> enumList = new ArrayList<String>();
- enumFieldsString = new String[fields.length + 1];
- for (int i = 0; i < fields.length; i++) {
- Field enumField = fields[i];
- if (enumField.isEnumConstant()) {
- enumList.add(enumField.getName());
- }
- }
- enumFieldsString = new String[enumList.size() + 1];
- System.arraycopy(enumList.toArray(new String[] {}), 0,
- enumFieldsString, 1, enumList.size());
- enumList.clear();
- }
- }
- } catch (JavaModelException e) {
- } catch (ClassNotFoundException e) {
- } catch (SecurityException e) {
- }
- }
- }
- }
- }
- String[] result = new String[] { "enumType" };
- if (enumFieldsString != null) {
- enumFieldsString[0] = result[0];
- return enumFieldsString;
- } else {
- return result;
- }
- }
- }
- }
- return null;
- }
-
private void createDecodeParamViewer(TabbedPropertySheetWidgetFactory factory, Composite
sashForm) {
GridData gd = new GridData(GridData.FILL_BOTH);
@@ -279,6 +211,7 @@
FillLayout layout = new FillLayout();
+
layout.marginHeight = 1;
layout.marginWidth = 1;
viewerComposite.setLayout(layout);
@@ -289,84 +222,18 @@
paramterViewer.setFilters(new ViewerFilter[] { new DecodeParamTypeFilter() });
- TableColumn nameColumn = new TableColumn(paramterViewer.getTable(), SWT.NONE);
+ nameColumn = new TableColumn(paramterViewer.getTable(), SWT.NONE);
+ valueColumn = new TableColumn(paramterViewer.getTable(), SWT.NONE);
+ nameColumn.setText(Messages.ValueDecodeParamSection_ParamNameColumnText);
+ valueColumn.setText(Messages.ValueDecodeParamSection_ParamValueColumnText);
nameColumn.setWidth(150);
- nameColumn.setText(Messages.ValueDecodeParamSection_ParamNameColumnText);
- TableColumn valueColumn = new TableColumn(paramterViewer.getTable(), SWT.NONE);
valueColumn.setWidth(150);
- valueColumn.setText(Messages.ValueDecodeParamSection_ParamValueColumnText);
- paramterViewer.setCellEditors(new CellEditor[] { new
TextCellEditor(paramterViewer.getTable()),
- new TextCellEditor(paramterViewer.getTable()) });
+ paramterViewer.setCellEditors(new CellEditor[] { new
TextCellEditor(paramterViewer.getTable()), new TextCellEditor(paramterViewer.getTable())
});
paramterViewer.setColumnProperties(new String[] { "name", "value"
}); //$NON-NLS-1$ //$NON-NLS-2$
- paramterViewer.setCellModifier(new ICellModifier() {
+ paramterViewer.setCellModifier(new DecodeParamCellModifier());
- public void modify(Object element, String property, Object value) {
- if (element instanceof TableItem) {
- Object currentElement = ((TableItem) element).getData();
- TreeNodeConnection lineModel = (TreeNodeConnection) getPresentSelectedGraphModel();
- Object model = lineModel.getTargetNode().getData();
- model = AdapterFactoryEditingDomain.unwrap(model);
- if (model != null && model instanceof ValueType && currentElement
instanceof DecodeParam) {
- String pname = ((DecodeParam) currentElement).getName();
- DecodeParamType paramType = findDecodeParamType(pname, (ValueType) model);
- Command command = null;
- EditingDomain editingDomain = getSmooksModelProvider().getEditingDomain();
- if (property.equals("value")) {
- if (value != null) {
- String svalue = ((String) value).trim();
- if ("".equals(svalue)) {
- if (paramType != null) {
- command = RemoveCommand.create(editingDomain, paramType);
- }
- } else {
- // if param is empty , add it
- if (paramType == null) {
- paramType = Javabean12Factory.eINSTANCE.createDecodeParamType();
- paramType.setName(pname);
- paramType.setValue((String) value);
- command = AddCommand.create(editingDomain, (ValueType) model,
- Javabean12Package.Literals.VALUE_TYPE__DECODE_PARAM, paramType);
- } else {
- command = SetCommand.create(editingDomain, paramType,
- Javabean12Package.Literals.DECODE_PARAM_TYPE__VALUE, value);
- }
- }
- }
- }
- if (command != null) {
- editingDomain.getCommandStack().execute(command);
- ((DecodeParam) currentElement).setValue((String) value);
- paramterViewer.update(currentElement, new String[] { property });
- }
- }
- }
- }
-
- public Object getValue(Object element, String property) {
- element = AdapterFactoryEditingDomain.unwrap(element);
- if (property.equals("value")) { //$NON-NLS-1$
- if (element instanceof DecodeParam) {
- String name = ((DecodeParam) element).getValue();
- if (name == null)
- name = ""; //$NON-NLS-1$
- return name;
- }
- }
- return null;
- }
-
- public boolean canModify(Object element, String property) {
- if (property.equals("value")) { //$NON-NLS-1$
- if (element instanceof DecodeParam) {
- return true;
- }
- }
- return false;
- }
- });
-
paramterViewer.getTable().setHeaderVisible(true);
paramterViewer.getTable().setLinesVisible(true);
@@ -375,14 +242,32 @@
private void initDecoderCombo() {
decoderCombo.select(-1);
TreeNodeConnection lineModel = (TreeNodeConnection) getPresentSelectedGraphModel();
- Object model = lineModel.getTargetNode().getData();
- model = AdapterFactoryEditingDomain.unwrap(model);
- if (model != null && model instanceof ValueType) {
- String decoder = ((ValueType) model).getDecoder();
- if (decoder != null) {
- decoder = decoder.trim();
- int index = DECODERS.indexOf(decoder);
- decoderCombo.select(index);
+ AbstractSmooksGraphicalModel targetNode = lineModel.getTargetNode();
+
+ if(targetNode instanceof JavaBeanChildGraphModel) {
+ JavaBeanChildGraphModel javaBeanChildGraphModel =
(JavaBeanChildGraphModel)targetNode;
+ Object bindingTypeObj = javaBeanChildGraphModel.getBindingTypeObj();
+
+ if (bindingTypeObj != null && bindingTypeObj instanceof ValueType) {
+ Class<?> targetPropertyType = javaBeanChildGraphModel.getJavaType();
+ String decoderAlias = ((ValueType) bindingTypeObj).getDecoder();
+
+ if(decoderAlias != null) {
+ // The decoder is configured...
+ int index = DECODERS.indexOf(decoderAlias.trim());
+ decoderCombo.select(index);
+ } else {
+ // Try work out the decoder based on the target property type...
+ DataDecoder decoder = DataDecoder.Factory.create(targetPropertyType);
+ if(decoder.getClass().getPackage() == IntegerDecoder.class.getPackage()) {
+ String decoderName = decoder.getClass().getSimpleName();
+ if(decoderName.endsWith("Decoder")) {
+ decoderAlias = decoderName.substring(0, decoderName.length() -
"Decoder".length());
+ int index = DECODERS.indexOf(decoderAlias);
+ decoderCombo.select(index);
+ }
+ }
+ }
}
}
}
@@ -390,17 +275,106 @@
private void initDecodeParamViewer() {
paramterViewer.setInput("NULL");
TreeNodeConnection lineModel = (TreeNodeConnection) getPresentSelectedGraphModel();
- Object model = lineModel.getTargetNode().getData();
- model = AdapterFactoryEditingDomain.unwrap(model);
- if (model != null && model instanceof ValueType) {
- String decoder = ((ValueType) model).getDecoder();
- String[] params = getDecoderParametersName(decoder);
- if (params != null) {
- paramterViewer.setInput(newDecodeParam(params, ((ValueType) model)));
+ AbstractSmooksGraphicalModel targetNode = lineModel.getTargetNode();
+
+ if(targetNode instanceof JavaBeanChildGraphModel) {
+ JavaBeanChildGraphModel javaBeanChildGraphModel =
(JavaBeanChildGraphModel)targetNode;
+ Object bindingTypeObj = javaBeanChildGraphModel.getBindingTypeObj();
+
+ if (bindingTypeObj != null && bindingTypeObj instanceof ValueType) {
+ Class<?> targetPropertyType = javaBeanChildGraphModel.getJavaType();
+ String decoderAlias = ((ValueType) bindingTypeObj).getDecoder();
+ DataDecoder decoder;
+ DecodeParamMetaData[] decodeParamMetaData;
+
+ if(decoderAlias != null) {
+ // The decoder is configured...
+ decoder = DataDecoder.Factory.create(decoderAlias);
+ } else {
+ // Try work out the decoder based on the target property type...
+ decoder = DataDecoder.Factory.create(targetPropertyType);
+ }
+
+ if(decoder instanceof EnumDecoder) {
+ // Get the enum values based on the targetPropertyType enum etc...
+ isEnumTarget = true;
+ paramterViewer.setInput(newEnumDecodeParamSet(targetPropertyType, (ValueType)
bindingTypeObj, javaBeanChildGraphModel));
+ nameColumn.setText(Messages.ValueDecodeParamSection_EnumParamNameColumnText);
+ valueColumn.setText(Messages.ValueDecodeParamSection_EnumParamValueColumnText);
+ } else {
+ isEnumTarget = false;
+ nameColumn.setText(Messages.ValueDecodeParamSection_ParamNameColumnText);
+ valueColumn.setText(Messages.ValueDecodeParamSection_ParamValueColumnText);
+ decodeParamMetaData =
DecodeParamMetaDataFactory.getDecodeParamMetaData(decoder.getClass());
+ if(decodeParamMetaData != null) {
+ paramterViewer.setInput(newDecodeParam(decodeParamMetaData, ((ValueType)
bindingTypeObj)));
+ }
+ }
}
}
}
+ private List<DecodeParam> newDecodeParam(DecodeParamMetaData[]
decodeParamMetaData, ValueType valueType) {
+ List<DecodeParam> list = new ArrayList<DecodeParam>();
+ for (int i = 0; i < decodeParamMetaData.length; i++) {
+ DecodeParamMetaData decodeParamMD = decodeParamMetaData[i];
+ DecodeParam p = new DecodeParam();
+ DecodeParamType dp = findDecodeParamType(decodeParamMD.getName(), valueType);
+
+ p.setName(decodeParamMD.getName());
+ if (dp != null) {
+ String dpv = dp.getValue();
+ if (dpv != null) {
+ dpv = dpv.trim();
+ }
+ p.setValue(dpv);
+ } else if(decodeParamMD.getDefaultVal() != null) {
+ p.setValue(decodeParamMD.getDefaultVal());
+ } else if(decodeParamMD.isRequiresConfiguration()) {
+ // TODO: We need to raise a warning...
+ }
+
+ list.add(p);
+ }
+ return list;
+ }
+
+ private List<DecodeParam> newEnumDecodeParamSet(Class<?> enumType, ValueType
valueType, JavaBeanChildGraphModel enumValueModelNode) {
+ List<DecodeParam> list = new ArrayList<DecodeParam>();
+ Properties configuredParams = JavaBeanChildGraphModel.getDecoderParams(valueType);
+
+ if(!configuredParams.isEmpty()) {
+ // Already configured...
+ Set<Entry<Object, Object>> paramSet = configuredParams.entrySet();
+ for(Entry<Object, Object> param : paramSet) {
+ String paramName = param.getKey().toString();
+
+ if(!paramName.equals("enumType")) {
+ DecodeParam p = new DecodeParam();
+ p.setName(paramName);
+ p.setValue(param.getValue().toString());
+ list.add(p);
+ }
+ }
+ } else {
+ Field[] enumFields = enumType.getDeclaredFields();
+
+ for(Field enumField : enumFields) {
+ if(enumField.isEnumConstant()) {
+ DecodeParam p = new DecodeParam();
+ p.setName(enumField.getName());
+ p.setValue(enumField.getName());
+ list.add(p);
+ }
+ }
+
+ // And add them to the model...
+ enumValueModelNode.newEnumDecodeParamSet(enumType, valueType);
+ }
+
+ return list;
+ }
+
private DecodeParamType findDecodeParamType(String name, ValueType valueType) {
List<?> ps = valueType.getDecodeParam();
for (Iterator<?> iterator = ps.iterator(); iterator.hasNext();) {
@@ -416,24 +390,6 @@
return null;
}
- private List<DecodeParam> newDecodeParam(String[] params, ValueType valueType) {
- List<DecodeParam> list = new ArrayList<DecodeParam>();
- for (int i = 0; i < params.length; i++) {
- String name = params[i];
- DecodeParam p = new DecodeParam();
- p.setName(name);
- DecodeParamType dp = findDecodeParamType(name, valueType);
- if (dp != null) {
- String dpv = dp.getValue();
- if (dpv != null)
- dpv = dpv.trim();
- p.setValue(dpv);
- }
- list.add(p);
- }
- return list;
- }
-
protected void createDecodeParamGUIContents(Object model, ISmooksModelProvider provider,
IEditorPart part,
FormToolkit factory, Composite controlComposite) {
// ModelPanelCreator creator = new ModelPanelCreator();
@@ -594,4 +550,91 @@
}
}
+
+ private class DecodeParamCellModifier implements ICellModifier {
+
+ public void modify(Object element, String property, Object value) {
+ if (element instanceof TableItem) {
+ Object currentElement = ((TableItem) element).getData();
+ TreeNodeConnection lineModel = (TreeNodeConnection) getPresentSelectedGraphModel();
+ EditingDomain editingDomain = getSmooksModelProvider().getEditingDomain();
+ Object model = lineModel.getTargetNode().getData();
+
+ model = AdapterFactoryEditingDomain.unwrap(model);
+ if (model != null && model instanceof ValueType && currentElement
instanceof DecodeParam) {
+ String pname = ((DecodeParam) currentElement).getName();
+ DecodeParamType paramType = findDecodeParamType(pname, (ValueType) model);
+ Command command = null;
+ if (!isEnumTarget && property.equals("value")) {
+ if (value != null) {
+ String svalue = ((String) value).trim();
+ if ("".equals(svalue)) {
+ if (paramType != null) {
+ command = RemoveCommand.create(editingDomain, paramType);
+ }
+ } else {
+ // if param is empty , add it
+ if (paramType == null) {
+ AbstractSmooksGraphicalModel targetNode = lineModel.getTargetNode();
+ if(targetNode instanceof JavaBeanChildGraphModel) {
+ command = ((JavaBeanChildGraphModel)targetNode).addDecodeParam(pname, (String)
value, (ValueType) model);
+ }
+ } else {
+ command = SetCommand.create(editingDomain, paramType,
+ Javabean12Package.Literals.DECODE_PARAM_TYPE__VALUE, value);
+ }
+ }
+ }
+ if (command != null) {
+ editingDomain.getCommandStack().execute(command);
+ ((DecodeParam) currentElement).setValue((String) value);
+ paramterViewer.update(currentElement, new String[] { property });
+ }
+ } else if (isEnumTarget && property.equals("name")) {
+ if (value != null) {
+ String svalue = ((String) value).trim();
+ if ("".equals(svalue)) {
+ // Can't blank it for an enum... ignore...
+ } else {
+ command = SetCommand.create(editingDomain, paramType,
+ Javabean12Package.Literals.DECODE_PARAM_TYPE__NAME, value);
+ editingDomain.getCommandStack().execute(command);
+ ((DecodeParam) currentElement).setName((String) value);
+ paramterViewer.update(currentElement, new String[] { property });
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public Object getValue(Object element, String property) {
+ element = AdapterFactoryEditingDomain.unwrap(element);
+ if (!isEnumTarget && property.equals("value")) { //$NON-NLS-1$
+ if (element instanceof DecodeParam) {
+ String name = ((DecodeParam) element).getValue();
+ if (name == null)
+ name = ""; //$NON-NLS-1$
+ return name;
+ }
+ } else if (isEnumTarget && property.equals("name")) { //$NON-NLS-1$
+ if (element instanceof DecodeParam) {
+ String name = ((DecodeParam) element).getName();
+ if (name == null)
+ name = ""; //$NON-NLS-1$
+ return name;
+ }
+ }
+ return null;
+ }
+
+ public boolean canModify(Object element, String property) {
+ if (property.equals(isEnumTarget?"name":"value")) { //$NON-NLS-1$
//$NON-NLS-2$
+ if (element instanceof DecodeParam) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/propertySections/messages.properties
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/propertySections/messages.properties 2010-01-29
23:30:31 UTC (rev 20033)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/propertySections/messages.properties 2010-01-30
14:37:31 UTC (rev 20034)
@@ -16,4 +16,6 @@
ValueDecodeParamSection_NullText=<null>
ValueDecodeParamSection_ParamNameColumnText=Name
ValueDecodeParamSection_ParamValueColumnText=Value
+ValueDecodeParamSection_EnumParamNameColumnText=From Data Value
+ValueDecodeParamSection_EnumParamValueColumnText=To Enum Value
ValueDecodeParamSection_SectionTitle=Decode Configuration
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/javamapping/JavaBeanChildGraphModel.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/javamapping/JavaBeanChildGraphModel.java 2010-01-29
23:30:31 UTC (rev 20033)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/javamapping/JavaBeanChildGraphModel.java 2010-01-30
14:37:31 UTC (rev 20034)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.smooks.graphical.editors.model.javamapping;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
@@ -50,8 +51,11 @@
import
org.jboss.tools.smooks.graphical.editors.template.SmooksFreemarkerTemplateGraphicalEditor;
import org.jboss.tools.smooks.model.javabean12.BeanType;
import org.jboss.tools.smooks.model.javabean12.DecodeParamType;
+import org.jboss.tools.smooks.model.javabean12.ExpressionType;
+import org.jboss.tools.smooks.model.javabean12.Javabean12Factory;
import org.jboss.tools.smooks.model.javabean12.Javabean12Package;
import org.jboss.tools.smooks.model.javabean12.ValueType;
+import org.jboss.tools.smooks.model.javabean12.WiringType;
import org.jboss.tools.smooks.templating.model.ModelBuilder;
import org.jboss.tools.smooks.templating.template.TemplateBuilder;
import org.jboss.tools.smooks.templating.template.ValueMapping;
@@ -62,7 +66,7 @@
* @author Dart
*
*/
-public class JavaBeanChildGraphModel extends AbstractResourceConfigChildNodeGraphModel {
+public class JavaBeanChildGraphModel extends AbstractResourceConfigChildNodeGraphModel
implements JavaNode {
private IGraphicalEditorPart editorPart;
@@ -278,6 +282,15 @@
Command addParamsCommand = AddCommand.create(domainProvider.getEditingDomain(),
owner,
Javabean12Package.Literals.VALUE_TYPE__DECODE_PARAM, oldParameters);
compoundCommand.append(addParamsCommand);
+ } else {
+ // If the target is an Enum type, we want to configure the decode parameters...
+ Class<?> targetType = getJavaType();
+ if(targetType.isEnum()) {
+ if(dataDecoder == null) {
+ dataDecoder = "Enum";
+ }
+ compoundCommand.append(_newEnumDecodeParamSet(targetType, (ValueType) model));
+ }
}
if (dataDecoder != null) {
@@ -298,6 +311,34 @@
}
}
+ public void newEnumDecodeParamSet(Class<?> enumType, ValueType valueType) {
+ Command compoundCommand = _newEnumDecodeParamSet(enumType, valueType);
+ domainProvider.getEditingDomain().getCommandStack().execute(compoundCommand);
+ }
+
+ private Command _newEnumDecodeParamSet(Class<?> enumType, ValueType valueType) {
+ CompoundCommand compoundCommand = new CompoundCommand();
+ Field[] enumFields = enumType.getDeclaredFields();
+
+ compoundCommand.append(addDecodeParam("enumType", enumType.getName(),
valueType));
+ for(Field enumField : enumFields) {
+ if(enumField.isEnumConstant()) {
+ compoundCommand.append(addDecodeParam(enumField.getName(), enumField.getName(),
valueType));
+ }
+ }
+
+ return compoundCommand;
+ }
+
+ public Command addDecodeParam(String paramName, String paramValue, ValueType valueType)
{
+ DecodeParamType paramType = Javabean12Factory.eINSTANCE.createDecodeParamType();
+
+ paramType.setName(paramName);
+ paramType.setValue(paramValue);
+
+ return AddCommand.create(domainProvider.getEditingDomain(), valueType,
Javabean12Package.Literals.VALUE_TYPE__DECODE_PARAM, paramType);
+ }
+
protected String getDataDecoder(TreeNodeConnection connection) {
Object data = getData();
data = AdapterFactoryEditingDomain.unwrap(data);
@@ -398,7 +439,42 @@
}
}
+
+ public Class<?> getJavaType() {
+ if(getData() instanceof WrapperItemProvider) {
+ WrapperItemProvider sourceData = (WrapperItemProvider) getData();
+ Object binding =
((ContainmentUpdatingFeatureMapEntry)sourceData.getValue()).getValue();
+
+ if(binding instanceof ValueType) {
+ return getPropertyType(getParentBean(), ((ValueType)binding).getProperty());
+ } else if(binding instanceof WiringType) {
+ return getPropertyType(getParentBean(), ((WiringType)binding).getProperty());
+ } else if(binding instanceof ExpressionType) {
+ return getPropertyType(getParentBean(), ((ExpressionType)binding).getProperty());
+ }
+ }
+ throw new IllegalStateException("Unexpected error. GraphModel data expected to
implement WrapperItemProvider.");
+ }
+
+ public BeanType getParentBean() {
+ if(getData() instanceof WrapperItemProvider) {
+ WrapperItemProvider sourceData = (WrapperItemProvider) getData();
+ return (BeanType) sourceData.getOwner();
+ }
+
+ throw new IllegalStateException("Unexpected error. GraphModel data expected to
implement WrapperItemProvider.");
+ }
+
+ public Object getBindingTypeObj() {
+ if(getData() instanceof WrapperItemProvider) {
+ WrapperItemProvider sourceData = (WrapperItemProvider) getData();
+ return ((ContainmentUpdatingFeatureMapEntry) sourceData.getValue()).getValue();
+ }
+
+ throw new IllegalStateException("Unexpected error. GraphModel data expected to
implement WrapperItemProvider.");
+ }
+
/* (non-Javadoc)
* @see
org.jboss.tools.smooks.graphical.editors.model.AbstractResourceConfigGraphModel#addMappingTypeInfo(org.jboss.tools.smooks.templating.template.ValueMapping)
*/
@@ -406,22 +482,22 @@
public void addMappingTypeInfo(ValueMapping mapping) {
if(getData() instanceof WrapperItemProvider) {
WrapperItemProvider sourceData = (WrapperItemProvider) getData();
- BeanType bean = (BeanType) sourceData.getOwner();
- ValueType valueBinding = (ValueType)
((ContainmentUpdatingFeatureMapEntry)sourceData.getValue()).getValue();
+ Object binding =
((ContainmentUpdatingFeatureMapEntry)sourceData.getValue()).getValue();
- mapping.setValueType(getPropertyType(bean, valueBinding));
- if(mapping.getEncodeProperties() == null) {
- mapping.setEncodeProperties(getDecoderParams(valueBinding));
+ if(binding instanceof ValueType) {
+ mapping.setValueType(getJavaType());
+ if(mapping.getEncodeProperties() == null) {
+ mapping.setEncodeProperties(getDecoderParams((ValueType) binding));
+ }
}
}
}
- private Class<?> getPropertyType(BeanType bean, ValueType valueBinding) {
+ private Class<?> getPropertyType(BeanType bean, String targetProperty) {
try {
IJavaProject project = SmooksUIUtils.getJavaProject(bean);
ProjectClassLoader classLoader = new ProjectClassLoader(project);
Class<?> beanClass = classLoader.loadClass(bean.getClass_());
- String targetProperty = valueBinding.getProperty();
if(targetProperty != null && !targetProperty.trim().equals("")) {
StringBuilder getterNameBuilder = new StringBuilder();
@@ -446,7 +522,7 @@
return null;
}
- private Properties getDecoderParams(ValueType valueBinding) {
+ public static Properties getDecoderParams(ValueType valueBinding) {
Properties decodeParams = new Properties();
EList decodeParamsList = valueBinding.getDecodeParam();
Added:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/javamapping/JavaNode.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/javamapping/JavaNode.java
(rev 0)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/javamapping/JavaNode.java 2010-01-30
14:37:31 UTC (rev 20034)
@@ -0,0 +1,30 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2009, JBoss Inc.
+ */
+package org.jboss.tools.smooks.graphical.editors.model.javamapping;
+
+/**
+ * Java Node type.
+ *
+ * @author <a
href="mailto:tom.fennelly@jboss.com">tom.fennelly@jboss.com</a>
+ */
+public interface JavaNode {
+
+ Class<?> getJavaType();
+}
Property changes on:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/javamapping/JavaNode.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain