From jbosstools-commits at lists.jboss.org Sat Jan 30 09:37:31 2010 Content-Type: multipart/mixed; boundary="===============7018137050055895498==" MIME-Version: 1.0 From: jbosstools-commits at lists.jboss.org To: jbosstools-commits at lists.jboss.org Subject: [jbosstools-commits] JBoss Tools SVN: r20034 - in trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks: graphical/editors/model/javamapping and 1 other directory. Date: Sat, 30 Jan 2010 09:37:31 -0500 Message-ID: <201001301437.o0UEbVG5014575@svn01.web.mwc.hst.phx2.redhat.com> --===============7018137050055895498== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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/smook= s/editor/propertySections/DecodeParamMetaData.java trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smook= s/editor/propertySections/DecodeParamMetaDataFactory.java trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smook= s/graphical/editors/model/javamapping/JavaNode.java Modified: trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smook= s/editor/propertySections/Messages.java trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smook= s/editor/propertySections/ValueDecodeParamSection.java trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smook= s/editor/propertySections/messages.properties trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smook= s/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/s= mooks/editor/propertySections/DecodeParamMetaData.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smoo= ks/editor/propertySections/DecodeParamMetaData.java = (rev 0) +++ trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smoo= ks/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 WIT= HOUT A + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNE= SS 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 Licens= e, + * 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 tom.fennelly(a)jbos= s.com + */ +public class DecodeParamMetaData { + + private String name; + private String defaultVal; + private boolean requiresConfiguration; + = + public DecodeParamMetaData(String name, String defaultVal) { + this.name =3D name; + this.defaultVal =3D defaultVal; + } + = + public DecodeParamMetaData(String name, String defaultVal, boolean requir= esConfiguration) { + this(name, defaultVal); + this.requiresConfiguration =3D 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/s= mooks/editor/propertySections/DecodeParamMetaDataFactory.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smoo= ks/editor/propertySections/DecodeParamMetaDataFactory.java = (rev 0) +++ trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smoo= ks/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 WIT= HOUT A + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNE= SS 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 Licens= e, + * 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 tom.fennelly(a)jbos= s.com + */ +public class DecodeParamMetaDataFactory { + + private static Map, DecodeParamMetaData[]> c= onfigMap =3D new HashMap, DecodeParamMetaData[= ]>(); + = + static { + DecodeParamMetaData[] dateDecodeMD =3D new DecodeParamMetaData[] { + new DecodeParamMetaData(LocaleAwareDateDecoder.FORMAT, LocaleAwareDate= Decoder.DEFAULT_DATE_FORMAT), + new DecodeParamMetaData(LocaleAwareDateDecoder.LOCALE_COUNTRY_CODE, nu= ll), + new DecodeParamMetaData(LocaleAwareDateDecoder.LOCALE_LANGUAGE_CODE, n= ull) + }; + + // 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 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/tool= s/smooks/editor/propertySections/Messages.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smoo= ks/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/smoo= ks/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/tool= s/smooks/editor/propertySections/ValueDecodeParamSection.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smoo= ks/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/smoo= ks/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.TabbedPropertySheetWidgetFac= tory; -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.ProjectClassLoad= er; -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.JavaBean= ChildGraphModel; 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 DECODERS =3D new ArrayList(); = @@ -189,74 +189,6 @@ } } = - private String[] getDecoderParametersName(String decoder) { - if (decoder !=3D null) { - if ("Date".equals(decoder)) { - return new String[] { "format", "locale-language", "locale-country" }; - } - - if ("Enum".equals(decoder)) { - TreeNodeConnection lineModel =3D (TreeNodeConnection) getPresentSelect= edGraphModel(); - Object model =3D lineModel.getTargetNode().getData(); - model =3D AdapterFactoryEditingDomain.unwrap(model); - if (model !=3D null && model instanceof ValueType) { - String[] enumFieldsString =3D null; - List inputs =3D SelectorCreationDialog.generateInputData(Smoo= ksUIUtils - .getSmooks11ResourceListType(getSmooksModelProvider().getSmooksMode= l())); - if (inputs !=3D null && !inputs.isEmpty()) { - Object input =3D inputs.get(0); - if (input instanceof JavaBeanModel) { - String path =3D ((ValueType) model).getData(); - JavaBeanModel beanModel =3D (JavaBeanModel) SmooksUIUtils.localXMLN= odeWithPath(path, - (JavaBeanModel) input); - if (beanModel !=3D null) { - String clazz =3D beanModel.getBeanClassString(); - if (clazz !=3D null) { - clazz =3D clazz.trim(); - IProject project =3D ((IFileEditorInput) getEditorPart().getEdito= rInput()).getFile() - .getProject(); - try { - ProjectClassLoader classLoader =3D new ProjectClassLoader(JavaCo= re - .create(project)); - Class enumType =3D classLoader.loadClass(clazz); - if (enumType.isEnum()) { - Field[] fields =3D enumType.getDeclaredFields(); - if (fields !=3D null) { - List enumList =3D new ArrayList(); - enumFieldsString =3D new String[fields.length + 1]; - for (int i =3D 0; i < fields.length; i++) { - Field enumField =3D fields[i]; - if (enumField.isEnumConstant()) { - enumList.add(enumField.getName()); - } - } - enumFieldsString =3D 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 =3D new String[] { "enumType" }; - if (enumFieldsString !=3D null) { - enumFieldsString[0] =3D result[0]; - return enumFieldsString; - } else { - return result; - } - } - } - } - return null; - } - private void createDecodeParamViewer(TabbedPropertySheetWidgetFactory fac= tory, Composite sashForm) { GridData gd =3D new GridData(GridData.FILL_BOTH); = @@ -279,6 +211,7 @@ = = FillLayout layout =3D new FillLayout(); + = layout.marginHeight =3D 1; layout.marginWidth =3D 1; viewerComposite.setLayout(layout); @@ -289,84 +222,18 @@ = paramterViewer.setFilters(new ViewerFilter[] { new DecodeParamTypeFilter= () }); = - TableColumn nameColumn =3D new TableColumn(paramterViewer.getTable(), SW= T.NONE); + nameColumn =3D new TableColumn(paramterViewer.getTable(), SWT.NONE); + valueColumn =3D new TableColumn(paramterViewer.getTable(), SWT.NONE); + nameColumn.setText(Messages.ValueDecodeParamSection_ParamNameColumnText); + valueColumn.setText(Messages.ValueDecodeParamSection_ParamValueColumnTex= t); nameColumn.setWidth(150); - nameColumn.setText(Messages.ValueDecodeParamSection_ParamNameColumnText); - TableColumn valueColumn =3D new TableColumn(paramterViewer.getTable(), S= WT.NONE); valueColumn.setWidth(150); - valueColumn.setText(Messages.ValueDecodeParamSection_ParamValueColumnTex= t); = - paramterViewer.setCellEditors(new CellEditor[] { new TextCellEditor(para= mterViewer.getTable()), - new TextCellEditor(paramterViewer.getTable()) }); + paramterViewer.setCellEditors(new CellEditor[] { new TextCellEditor(para= mterViewer.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 =3D ((TableItem) element).getData(); - TreeNodeConnection lineModel =3D (TreeNodeConnection) getPresentSelec= tedGraphModel(); - Object model =3D lineModel.getTargetNode().getData(); - model =3D AdapterFactoryEditingDomain.unwrap(model); - if (model !=3D null && model instanceof ValueType && currentElement i= nstanceof DecodeParam) { - String pname =3D ((DecodeParam) currentElement).getName(); - DecodeParamType paramType =3D findDecodeParamType(pname, (ValueType)= model); - Command command =3D null; - EditingDomain editingDomain =3D getSmooksModelProvider().getEditingD= omain(); - if (property.equals("value")) { - if (value !=3D null) { - String svalue =3D ((String) value).trim(); - if ("".equals(svalue)) { - if (paramType !=3D null) { - command =3D RemoveCommand.create(editingDomain, paramType); - } - } else { - // if param is empty , add it - if (paramType =3D=3D null) { - paramType =3D Javabean12Factory.eINSTANCE.createDecodeParamType(= ); - paramType.setName(pname); - paramType.setValue((String) value); - command =3D AddCommand.create(editingDomain, (ValueType) model, - Javabean12Package.Literals.VALUE_TYPE__DECODE_PARAM, paramType= ); - } else { - command =3D SetCommand.create(editingDomain, paramType, - Javabean12Package.Literals.DECODE_PARAM_TYPE__VALUE, value); - } - } - } - } - if (command !=3D null) { - editingDomain.getCommandStack().execute(command); - ((DecodeParam) currentElement).setValue((String) value); - paramterViewer.update(currentElement, new String[] { property }); - } - } - } - } - - public Object getValue(Object element, String property) { - element =3D AdapterFactoryEditingDomain.unwrap(element); - if (property.equals("value")) { //$NON-NLS-1$ - if (element instanceof DecodeParam) { - String name =3D ((DecodeParam) element).getValue(); - if (name =3D=3D null) - name =3D ""; //$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 =3D (TreeNodeConnection) getPresentSelected= GraphModel(); - Object model =3D lineModel.getTargetNode().getData(); - model =3D AdapterFactoryEditingDomain.unwrap(model); - if (model !=3D null && model instanceof ValueType) { - String decoder =3D ((ValueType) model).getDecoder(); - if (decoder !=3D null) { - decoder =3D decoder.trim(); - int index =3D DECODERS.indexOf(decoder); - decoderCombo.select(index); + AbstractSmooksGraphicalModel targetNode =3D lineModel.getTargetNode(); + = + if(targetNode instanceof JavaBeanChildGraphModel) { + JavaBeanChildGraphModel javaBeanChildGraphModel =3D (JavaBeanChildGraph= Model)targetNode; + Object bindingTypeObj =3D javaBeanChildGraphModel.getBindingTypeObj(); + = + if (bindingTypeObj !=3D null && bindingTypeObj instanceof ValueType) { + Class targetPropertyType =3D javaBeanChildGraphModel.getJavaType(); + String decoderAlias =3D ((ValueType) bindingTypeObj).getDecoder(); + = + if(decoderAlias !=3D null) { + // The decoder is configured... + int index =3D DECODERS.indexOf(decoderAlias.trim()); + decoderCombo.select(index); + } else { + // Try work out the decoder based on the target property type... + DataDecoder decoder =3D DataDecoder.Factory.create(targetPropertyType= ); + if(decoder.getClass().getPackage() =3D=3D IntegerDecoder.class.getPac= kage()) { + String decoderName =3D decoder.getClass().getSimpleName(); + if(decoderName.endsWith("Decoder")) { + decoderAlias =3D decoderName.substring(0, decoderName.length() - "D= ecoder".length()); + int index =3D DECODERS.indexOf(decoderAlias); + decoderCombo.select(index); + } + } + } } } } @@ -390,17 +275,106 @@ private void initDecodeParamViewer() { paramterViewer.setInput("NULL"); TreeNodeConnection lineModel =3D (TreeNodeConnection) getPresentSelected= GraphModel(); - Object model =3D lineModel.getTargetNode().getData(); - model =3D AdapterFactoryEditingDomain.unwrap(model); - if (model !=3D null && model instanceof ValueType) { - String decoder =3D ((ValueType) model).getDecoder(); - String[] params =3D getDecoderParametersName(decoder); - if (params !=3D null) { - paramterViewer.setInput(newDecodeParam(params, ((ValueType) model))); + AbstractSmooksGraphicalModel targetNode =3D lineModel.getTargetNode(); + = + if(targetNode instanceof JavaBeanChildGraphModel) { + JavaBeanChildGraphModel javaBeanChildGraphModel =3D (JavaBeanChildGraph= Model)targetNode; + Object bindingTypeObj =3D javaBeanChildGraphModel.getBindingTypeObj(); + = + if (bindingTypeObj !=3D null && bindingTypeObj instanceof ValueType) { + Class targetPropertyType =3D javaBeanChildGraphModel.getJavaType(); + String decoderAlias =3D ((ValueType) bindingTypeObj).getDecoder(); + DataDecoder decoder; + DecodeParamMetaData[] decodeParamMetaData; + = + if(decoderAlias !=3D null) { + // The decoder is configured... + decoder =3D DataDecoder.Factory.create(decoderAlias); + } else { + // Try work out the decoder based on the target property type... + decoder =3D DataDecoder.Factory.create(targetPropertyType); + } + = + if(decoder instanceof EnumDecoder) { + // Get the enum values based on the targetPropertyType enum etc... + isEnumTarget =3D true; + paramterViewer.setInput(newEnumDecodeParamSet(targetPropertyType, (Va= lueType) bindingTypeObj, javaBeanChildGraphModel)); + nameColumn.setText(Messages.ValueDecodeParamSection_EnumParamNameColu= mnText); + valueColumn.setText(Messages.ValueDecodeParamSection_EnumParamValueCo= lumnText); + } else { + isEnumTarget =3D false; + nameColumn.setText(Messages.ValueDecodeParamSection_ParamNameColumnTe= xt); + valueColumn.setText(Messages.ValueDecodeParamSection_ParamValueColumn= Text); + decodeParamMetaData =3D DecodeParamMetaDataFactory.getDecodeParamMeta= Data(decoder.getClass()); = + if(decodeParamMetaData !=3D null) { + paramterViewer.setInput(newDecodeParam(decodeParamMetaData, ((ValueT= ype) bindingTypeObj))); + } + } } } } = + private List newDecodeParam(DecodeParamMetaData[] decodePara= mMetaData, ValueType valueType) { + List list =3D new ArrayList(); + for (int i =3D 0; i < decodeParamMetaData.length; i++) { + DecodeParamMetaData decodeParamMD =3D decodeParamMetaData[i]; + DecodeParam p =3D new DecodeParam(); + DecodeParamType dp =3D findDecodeParamType(decodeParamMD.getName(), val= ueType); + + p.setName(decodeParamMD.getName()); + if (dp !=3D null) { + String dpv =3D dp.getValue(); + if (dpv !=3D null) { + dpv =3D dpv.trim(); + } + p.setValue(dpv); = + } else if(decodeParamMD.getDefaultVal() !=3D null) { + p.setValue(decodeParamMD.getDefaultVal()); + } else if(decodeParamMD.isRequiresConfiguration()) { + // TODO: We need to raise a warning... + } + = + list.add(p); + } + return list; + } + + private List newEnumDecodeParamSet(Class enumType, ValueT= ype valueType, JavaBeanChildGraphModel enumValueModelNode) { + List list =3D new ArrayList(); + Properties configuredParams =3D JavaBeanChildGraphModel.getDecoderParams= (valueType); + + if(!configuredParams.isEmpty()) { + // Already configured... + Set> paramSet =3D configuredParams.entrySet(); + for(Entry param : paramSet) { + String paramName =3D param.getKey().toString(); + = + if(!paramName.equals("enumType")) { + DecodeParam p =3D new DecodeParam(); + p.setName(paramName); + p.setValue(param.getValue().toString()); + list.add(p); + } + } = + } else { + Field[] enumFields =3D enumType.getDeclaredFields(); + + for(Field enumField : enumFields) { + if(enumField.isEnumConstant()) { + DecodeParam p =3D 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 valueT= ype) { List ps =3D valueType.getDecodeParam(); for (Iterator iterator =3D ps.iterator(); iterator.hasNext();) { @@ -416,24 +390,6 @@ return null; } = - private List newDecodeParam(String[] params, ValueType value= Type) { - List list =3D new ArrayList(); - for (int i =3D 0; i < params.length; i++) { - String name =3D params[i]; - DecodeParam p =3D new DecodeParam(); - p.setName(name); - DecodeParamType dp =3D findDecodeParamType(name, valueType); - if (dp !=3D null) { - String dpv =3D dp.getValue(); - if (dpv !=3D null) - dpv =3D dpv.trim(); - p.setValue(dpv); - } - list.add(p); - } - return list; - } - protected void createDecodeParamGUIContents(Object model, ISmooksModelPro= vider provider, IEditorPart part, FormToolkit factory, Composite controlComposite) { // ModelPanelCreator creator =3D 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 =3D ((TableItem) element).getData(); + TreeNodeConnection lineModel =3D (TreeNodeConnection) getPresentSelect= edGraphModel(); + EditingDomain editingDomain =3D getSmooksModelProvider().getEditingDom= ain(); + Object model =3D lineModel.getTargetNode().getData(); + + model =3D AdapterFactoryEditingDomain.unwrap(model); + if (model !=3D null && model instanceof ValueType && currentElement in= stanceof DecodeParam) { + String pname =3D ((DecodeParam) currentElement).getName(); + DecodeParamType paramType =3D findDecodeParamType(pname, (ValueType) = model); + Command command =3D null; + if (!isEnumTarget && property.equals("value")) { + if (value !=3D null) { + String svalue =3D ((String) value).trim(); + if ("".equals(svalue)) { + if (paramType !=3D null) { + command =3D RemoveCommand.create(editingDomain, paramType); + } + } else { + // if param is empty , add it + if (paramType =3D=3D null) { + AbstractSmooksGraphicalModel targetNode =3D lineModel.getTargetNo= de(); = + if(targetNode instanceof JavaBeanChildGraphModel) { + command =3D ((JavaBeanChildGraphModel)targetNode).addDecodeParam= (pname, (String) value, (ValueType) model); + } + } else { + command =3D SetCommand.create(editingDomain, paramType, + Javabean12Package.Literals.DECODE_PARAM_TYPE__VALUE, value); + } + } + } + if (command !=3D null) { + editingDomain.getCommandStack().execute(command); + ((DecodeParam) currentElement).setValue((String) value); + paramterViewer.update(currentElement, new String[] { property }); + } + } else if (isEnumTarget && property.equals("name")) { + if (value !=3D null) { + String svalue =3D ((String) value).trim(); + if ("".equals(svalue)) { + // Can't blank it for an enum... ignore... + } else { + command =3D 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 =3D AdapterFactoryEditingDomain.unwrap(element); + if (!isEnumTarget && property.equals("value")) { //$NON-NLS-1$ + if (element instanceof DecodeParam) { + String name =3D ((DecodeParam) element).getValue(); + if (name =3D=3D null) + name =3D ""; //$NON-NLS-1$ + return name; + } + } else if (isEnumTarget && property.equals("name")) { //$NON-NLS-1$ + if (element instanceof DecodeParam) { + String name =3D ((DecodeParam) element).getName(); + if (name =3D=3D null) + name =3D ""; //$NON-NLS-1$ + return name; + } + } + return null; + } + + public boolean canModify(Object element, String property) { + if (property.equals(isEnumTarget?"name":"value")) { //$NON-NLS-1$ //$NO= N-NLS-2$ + if (element instanceof DecodeParam) { + return true; + } + } + return false; + } + } = } Modified: trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tool= s/smooks/editor/propertySections/messages.properties =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smoo= ks/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/smoo= ks/editor/propertySections/messages.properties 2010-01-30 14:37:31 UTC (rev= 20034) @@ -16,4 +16,6 @@ ValueDecodeParamSection_NullText=3D ValueDecodeParamSection_ParamNameColumnText=3DName ValueDecodeParamSection_ParamValueColumnText=3DValue +ValueDecodeParamSection_EnumParamNameColumnText=3DFrom Data Value +ValueDecodeParamSection_EnumParamValueColumnText=3DTo Enum Value ValueDecodeParamSection_SectionTitle=3DDecode Configuration Modified: trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tool= s/smooks/graphical/editors/model/javamapping/JavaBeanChildGraphModel.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smoo= ks/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/smoo= ks/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.SmooksFreemarkerT= emplateGraphicalEditor; 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 AbstractResourceConfigChildNo= deGraphModel { +public class JavaBeanChildGraphModel extends AbstractResourceConfigChildNo= deGraphModel implements JavaNode { = private IGraphicalEditorPart editorPart; = @@ -278,6 +282,15 @@ Command addParamsCommand =3D AddCommand.create(domainProvider.getEdit= ingDomain(), 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 par= ameters... + Class targetType =3D getJavaType(); + if(targetType.isEnum()) { + if(dataDecoder =3D=3D null) { + dataDecoder =3D "Enum"; + } + compoundCommand.append(_newEnumDecodeParamSet(targetType, (ValueType= ) model)); + } } = if (dataDecoder !=3D null) { @@ -298,6 +311,34 @@ } } = + public void newEnumDecodeParamSet(Class enumType, ValueType valueType)= { + Command compoundCommand =3D _newEnumDecodeParamSet(enumType, valueType); + domainProvider.getEditingDomain().getCommandStack().execute(compoundComm= and); + } + = + private Command _newEnumDecodeParamSet(Class enumType, ValueType value= Type) { + CompoundCommand compoundCommand =3D new CompoundCommand(); + Field[] enumFields =3D enumType.getDeclaredFields(); + + compoundCommand.append(addDecodeParam("enumType", enumType.getName(), va= lueType)); + for(Field enumField : enumFields) { + if(enumField.isEnumConstant()) { + compoundCommand.append(addDecodeParam(enumField.getName(), enumField.g= etName(), valueType)); + } + } + = + return compoundCommand; + } + + public Command addDecodeParam(String paramName, String paramValue, ValueT= ype valueType) { = + DecodeParamType paramType =3D Javabean12Factory.eINSTANCE.createDecodePa= ramType(); + = + paramType.setName(paramName); + paramType.setValue(paramValue); + = + return AddCommand.create(domainProvider.getEditingDomain(), valueType, J= avabean12Package.Literals.VALUE_TYPE__DECODE_PARAM, paramType); + } + protected String getDataDecoder(TreeNodeConnection connection) { Object data =3D getData(); data =3D AdapterFactoryEditingDomain.unwrap(data); @@ -398,7 +439,42 @@ } = } + = + public Class getJavaType() { + if(getData() instanceof WrapperItemProvider) { + WrapperItemProvider sourceData =3D (WrapperItemProvider) getData(); + Object binding =3D ((ContainmentUpdatingFeatureMapEntry)sourceData.getV= alue()).getValue(); + = + if(binding instanceof ValueType) { = + return getPropertyType(getParentBean(), ((ValueType)binding).getProper= ty()); + } else if(binding instanceof WiringType) { = + return getPropertyType(getParentBean(), ((WiringType)binding).getPrope= rty()); + } else if(binding instanceof ExpressionType) { = + return getPropertyType(getParentBean(), ((ExpressionType)binding).getP= roperty()); + } + } = = + throw new IllegalStateException("Unexpected error. GraphModel data expe= cted to implement WrapperItemProvider."); + } + = + public BeanType getParentBean() { + if(getData() instanceof WrapperItemProvider) { + WrapperItemProvider sourceData =3D (WrapperItemProvider) getData(); + return (BeanType) sourceData.getOwner(); = + } + = + throw new IllegalStateException("Unexpected error. GraphModel data expe= cted to implement WrapperItemProvider."); + } + = + public Object getBindingTypeObj() { + if(getData() instanceof WrapperItemProvider) { + WrapperItemProvider sourceData =3D (WrapperItemProvider) getData(); + return ((ContainmentUpdatingFeatureMapEntry) sourceData.getValue()).get= Value(); + } + = + throw new IllegalStateException("Unexpected error. GraphModel data expe= cted to implement WrapperItemProvider."); + } + /* (non-Javadoc) * @see org.jboss.tools.smooks.graphical.editors.model.AbstractResourceCo= nfigGraphModel#addMappingTypeInfo(org.jboss.tools.smooks.templating.templat= e.ValueMapping) */ @@ -406,22 +482,22 @@ public void addMappingTypeInfo(ValueMapping mapping) { if(getData() instanceof WrapperItemProvider) { WrapperItemProvider sourceData =3D (WrapperItemProvider) getData(); - BeanType bean =3D (BeanType) sourceData.getOwner(); - ValueType valueBinding =3D (ValueType) ((ContainmentUpdatingFeatureMapE= ntry)sourceData.getValue()).getValue(); + Object binding =3D ((ContainmentUpdatingFeatureMapEntry)sourceData.getV= alue()).getValue(); = - mapping.setValueType(getPropertyType(bean, valueBinding)); - if(mapping.getEncodeProperties() =3D=3D null) { - mapping.setEncodeProperties(getDecoderParams(valueBinding)); + if(binding instanceof ValueType) { = + mapping.setValueType(getJavaType()); + if(mapping.getEncodeProperties() =3D=3D null) { + mapping.setEncodeProperties(getDecoderParams((ValueType) binding)); + } } } = } = - private Class getPropertyType(BeanType bean, ValueType valueBinding) { + private Class getPropertyType(BeanType bean, String targetProperty) { try { IJavaProject project =3D SmooksUIUtils.getJavaProject(bean); ProjectClassLoader classLoader =3D new ProjectClassLoader(project); Class beanClass =3D classLoader.loadClass(bean.getClass_()); - String targetProperty =3D valueBinding.getProperty(); = if(targetProperty !=3D null && !targetProperty.trim().equals("")) { StringBuilder getterNameBuilder =3D new StringBuilder(); @@ -446,7 +522,7 @@ return null; } = - private Properties getDecoderParams(ValueType valueBinding) { + public static Properties getDecoderParams(ValueType valueBinding) { Properties decodeParams =3D new Properties(); EList decodeParamsList =3D valueBinding.getDecodeParam(); = Added: trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/s= mooks/graphical/editors/model/javamapping/JavaNode.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smoo= ks/graphical/editors/model/javamapping/JavaNode.java = (rev 0) +++ trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smoo= ks/graphical/editors/model/javamapping/JavaNode.java 2010-01-30 14:37:31 UT= C (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 WIT= HOUT A + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNE= SS 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 Licens= e, + * 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 tom.fennelly(a)jbos= s.com + */ +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 --===============7018137050055895498==--