Author: tfennelly
Date: 2010-08-20 17:27:49 -0400 (Fri, 20 Aug 2010)
New Revision: 24355
Added:
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/AbstractContributor.java
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/JavaConfigurationContributorFactory.java
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/Messages.java
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/messages.properties
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/util/
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/util/TextFieldChangeListener.java
Modified:
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/InputSourceType.java
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/Messages.java
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/SampleDataConfigurationContributorFactory.java
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/XSDConfigurationContributorFactory.java
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/messages.properties
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/model/JavaInputModelFactory.java
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/uitls/SmooksUIUtils.java
Log:
https://jira.jboss.org/browse/JBIDE-6868
Re-add Java Input support.
Modified:
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/InputSourceType.java
===================================================================
---
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/InputSourceType.java 2010-08-20
20:17:37 UTC (rev 24354)
+++
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/InputSourceType.java 2010-08-20
21:27:49 UTC (rev 24355)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.smooks.configuration.editors.input;
+import
org.jboss.tools.smooks.configuration.editors.input.contributors.JavaConfigurationContributorFactory;
import
org.jboss.tools.smooks.configuration.editors.input.contributors.SampleDataConfigurationContributorFactory;
import
org.jboss.tools.smooks.configuration.editors.input.contributors.SimpleMessageContributorFactory;
import
org.jboss.tools.smooks.configuration.editors.input.contributors.XSDConfigurationContributorFactory;
@@ -28,7 +29,7 @@
NONE(0, new
SimpleMessageContributorFactory(Messages.InputSourceType_Warning_Specify_Input_Type),
null),
XML(1, new SampleDataConfigurationContributorFactory(), new XMLInputModelFactory()),
XSD(2, new XSDConfigurationContributorFactory(), new XSDInputModelFactory()),
- JAVA(3, new
SimpleMessageContributorFactory(Messages.InputSourceType_Warning_Specify_Sample_Data), new
JavaInputModelFactory());
+ JAVA(3, new JavaConfigurationContributorFactory(), new JavaInputModelFactory());
private int typeIndex;
private InputTaskPanelContributorFactory taskPanelContributorFactory;
Modified:
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/Messages.java
===================================================================
---
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/Messages.java 2010-08-20
20:17:37 UTC (rev 24354)
+++
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/Messages.java 2010-08-20
21:27:49 UTC (rev 24355)
@@ -8,8 +8,6 @@
public static String InputSourceType_Warning_Specify_Sample_Data;
public static String InputSourceType_Unknown_Input_Type_Name;
public static String InputSourceType_Unknown_Input_Type_Index;
- public static String XSDConfigurationContributor_XML_Schema_File;
- public static String XSDConfigurationContributor_Root_Element_Name;
static {
// initialize resource bundle
Added:
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/AbstractContributor.java
===================================================================
---
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/AbstractContributor.java
(rev 0)
+++
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/AbstractContributor.java 2010-08-20
21:27:49 UTC (rev 24355)
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.configuration.editors.input.contributors;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.edit.command.DeleteCommand;
+import org.eclipse.emf.edit.command.SetCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.ui.part.EditorPart;
+import org.jboss.tools.smooks.configuration.editors.input.InputTaskPanelContributor;
+import org.jboss.tools.smooks.configuration.editors.uitls.SmooksUIUtils;
+import org.jboss.tools.smooks.model.SmooksModel;
+import org.jboss.tools.smooks.model.core.ICorePackage;
+import org.jboss.tools.smooks.model.core.IParam;
+import org.milyn.javabean.dynamic.Model;
+
+/**
+ * Abstract Contributor.
+ * @author <a
href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
+ */
+public abstract class AbstractContributor implements InputTaskPanelContributor {
+
+ private EditorPart editorPart;
+ private Model<SmooksModel> configModel;
+ private SmooksModel modelRoot;
+ private EditingDomain editingDomain;
+
+ public AbstractContributor(EditorPart editorPart, Model<SmooksModel> configModel)
{
+ this.editorPart = editorPart;
+ this.configModel = configModel;
+ this.modelRoot = configModel.getModelRoot();
+ this.editingDomain = modelRoot.getModelProvider().getEditingDomain();
+ }
+
+ public EditorPart getEditorPart() {
+ return editorPart;
+ }
+
+ public Model<SmooksModel> getConfigModel() {
+ return configModel;
+ }
+
+ public SmooksModel getModelRoot() {
+ return modelRoot;
+ }
+
+ public EditingDomain getEditingDomain() {
+ return editingDomain;
+ }
+
+ protected IParam setInputParam(String inputType, String value, CompoundCommand
compoundCommand) {
+ IParam inputParam = getInputParam(inputType);
+
+ if(inputParam == null) {
+ inputParam = SmooksUIUtils.recordInputDataInfomation(editingDomain,
modelRoot.getParams(), inputType, value, null, compoundCommand);
+ } else {
+ setParamValue(inputParam, value, compoundCommand);
+ }
+
+ return inputParam;
+ }
+
+ protected void removeInputParam(String inputType, CompoundCommand compoundCommand) {
+ IParam inputParam = getInputParam(inputType);
+ removeParam(inputParam, compoundCommand);
+ }
+
+ protected void removeParam(IParam param, CompoundCommand compoundCommand) {
+ if(param != null) {
+ modelRoot.getParams().getParams().remove(param);
+ Command command = DeleteCommand.create(editingDomain, param);
+ addOrExecute(compoundCommand, command);
+ }
+ }
+
+ protected IParam getInputParam(String inputType) {
+ return modelRoot.getParams().getParam(inputType);
+ }
+
+ protected void setParamValue(IParam param, String value, CompoundCommand
compoundCommand) {
+ Command command = SetCommand.create(editingDomain, param,
ICorePackage.Literals.PARAM__VALUE, value);
+ addOrExecute(compoundCommand, command);
+ }
+
+ protected void setParamType(IParam param, String typeValue, CompoundCommand
compoundCommand) {
+ Command command = SetCommand.create(editingDomain, param,
ICorePackage.Literals.PARAM__TYPE, typeValue);
+ addOrExecute(compoundCommand, command);
+ }
+
+ private void addOrExecute(CompoundCommand compoundCommand, Command command) {
+ if (command.canExecute()) {
+ if(compoundCommand == null) {
+ editingDomain.getCommandStack().execute(command);
+ } else {
+ compoundCommand.append(command);
+ }
+ }
+ }
+}
Property changes on:
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/AbstractContributor.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/JavaConfigurationContributorFactory.java
===================================================================
---
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/JavaConfigurationContributorFactory.java
(rev 0)
+++
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/JavaConfigurationContributorFactory.java 2010-08-20
21:27:49 UTC (rev 24355)
@@ -0,0 +1,120 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.configuration.editors.input.contributors;
+
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+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.swt.widgets.Text;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.part.EditorPart;
+import org.jboss.tools.smooks.configuration.SmooksModelUtils;
+import org.jboss.tools.smooks.configuration.editors.input.InputSourceType;
+import org.jboss.tools.smooks.configuration.editors.input.InputTaskPanelContributor;
+import
org.jboss.tools.smooks.configuration.editors.input.InputTaskPanelContributorFactory;
+import org.jboss.tools.smooks.configuration.editors.uitls.JavaTypeFieldDialog;
+import org.jboss.tools.smooks.model.SmooksModel;
+import org.jboss.tools.smooks.model.core.IParam;
+import org.jboss.tools.smooks.util.TextFieldChangeListener;
+import org.milyn.javabean.dynamic.Model;
+
+/**
+ * Java Source configuration contributor factory.
+ * @author <a
href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
+ */
+public class JavaConfigurationContributorFactory implements
InputTaskPanelContributorFactory {
+
+ public InputTaskPanelContributor newInstance(FormToolkit toolkit, EditorPart editorPart,
Model<SmooksModel> configModel) {
+ return new PanelContributor(toolkit, editorPart, configModel);
+ }
+
+ public void setInputSourceType(InputSourceType inputSourceType) {
+ }
+
+ private class PanelContributor extends AbstractContributor {
+
+ private Composite inputSourceConfigComposite;
+ private Text classTextField;
+
+ public PanelContributor(FormToolkit toolkit, EditorPart editorPart,
Model<SmooksModel> configModel) {
+ super(editorPart, configModel);
+ }
+
+ public void setInputSourceConfigComposite(Composite inputSourceConfigComposite) {
+ this.inputSourceConfigComposite = inputSourceConfigComposite;
+ }
+
+ public void addInputSourceTypeConfigControls() {
+ Composite javaClassSelectionSection = new Composite(inputSourceConfigComposite,
SWT.NONE);
+ GridLayout layout = new GridLayout();
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+
+ layout.numColumns = 3;
+ javaClassSelectionSection.setLayout(layout);
+ javaClassSelectionSection.setLayoutData(gd);
+
+ new Label(javaClassSelectionSection,
SWT.NONE).setText(Messages.JavaConfigurationContributorFactory_Class_Name);
+
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ classTextField = new Text(javaClassSelectionSection, SWT.BORDER);
+ IParam inputParam = getInputParam(SmooksModelUtils.INPUT_TYPE_JAVA);
+ if(inputParam != null) {
+ classTextField.setText(inputParam.getValue());
+ }
+ new TextFieldChangeListener(classTextField) {
+ public void fieldChanged(String newValue) {
+ setInputClass();
+ }
+ };
+ classTextField.setLayoutData(gd);
+
+ Button browseButton = new Button(javaClassSelectionSection, SWT.NONE);
+ browseButton.setText(Messages.ConfigurationContributorFactory_Browse_Button);
+ browseButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ browseForClass();
+ }
+ });
+
+ inputSourceConfigComposite.setBackgroundMode(SWT.TRANSPARENT);
+ inputSourceConfigComposite.layout();
+ }
+
+ protected void browseForClass() {
+ IJavaProject javaProject =
JavaCore.create(((IFileEditorInput)getEditorPart().getEditorInput()).getFile().getProject());
+ String classString =
JavaTypeFieldDialog.openJavaTypeDialog(getEditorPart().getEditorSite().getShell(),
javaProject);
+
+ if(classString != null) {
+ classTextField.setText(classString);
+ setInputClass();
+ }
+ }
+
+ protected void setInputClass() {
+ CompoundCommand compoundCommand = new CompoundCommand();
+
+ setInputParam(SmooksModelUtils.INPUT_TYPE_JAVA, classTextField.getText(),
compoundCommand);
+ if(!compoundCommand.isEmpty()) {
+ getEditingDomain().getCommandStack().execute(compoundCommand);
+ }
+ }
+ }
+}
Property changes on:
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/JavaConfigurationContributorFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/Messages.java
===================================================================
---
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/Messages.java
(rev 0)
+++
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/Messages.java 2010-08-20
21:27:49 UTC (rev 24355)
@@ -0,0 +1,19 @@
+package org.jboss.tools.smooks.configuration.editors.input.contributors;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ public static String ConfigurationContributorFactory_Browse_Button;
+ public static String XSDConfigurationContributorFactory_XML_Schema_File;
+ public static String XSDConfigurationContributorFactory_Root_Element_Name;
+ public static String JavaConfigurationContributorFactory_Class_Name;
+
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(Messages.class.getPackage().getName() + ".messages",
Messages.class); //$NON-NLS-1$
+ }
+
+ private Messages() {
+ }
+}
Property changes on:
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/Messages.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified:
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/SampleDataConfigurationContributorFactory.java
===================================================================
---
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/SampleDataConfigurationContributorFactory.java 2010-08-20
20:17:37 UTC (rev 24354)
+++
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/SampleDataConfigurationContributorFactory.java 2010-08-20
21:27:49 UTC (rev 24355)
@@ -91,7 +91,7 @@
return new PanelContributor(toolkit, editorPart, configModel);
}
- private class PanelContributor implements InputTaskPanelContributor {
+ private class PanelContributor extends AbstractContributor {
private EditorPart editorPart;
private Model<SmooksModel> configModel;
@@ -105,6 +105,7 @@
private Button removeInputDataButton;
public PanelContributor(FormToolkit toolkit, EditorPart editorPart,
Model<SmooksModel> configModel) {
+ super(editorPart, configModel);
this.editorPart = editorPart;
this.configModel = configModel;
this.modelProvider = configModel.getModelRoot().getModelProvider();
@@ -291,7 +292,7 @@
}
if(!compoundCommand.isEmpty()) {
- compoundCommand.execute();
+ editingDomain.getCommandStack().execute(compoundCommand);
}
if (!inputs.isEmpty()) {
@@ -311,24 +312,6 @@
inputSourceConfigComposite.setBackgroundMode(SWT.TRANSPARENT);
inputSourceConfigComposite.layout();
}
-
- private void setParamType(IParam param, String typeValue, CompoundCommand
compoundCommand) {
- Command c = SetCommand.create(editingDomain, param, ICorePackage.Literals.PARAM__TYPE,
typeValue);
- if (c.canExecute()) {
- compoundCommand.append(c);
- }
- }
-
- private void removeParam(IParam param, CompoundCommand compoundCommand) {
- List<IParam> removingList = new ArrayList<IParam>();
-
- removingList.add(param);
-
- Command removeCommand = RemoveCommand.create(editingDomain, removingList);
- if (removeCommand.canExecute()) {
- compoundCommand.append(removeCommand);
- }
- }
protected void showInputDataWizard() {
String inputType = modelProvider.getInputType();
Modified:
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/XSDConfigurationContributorFactory.java
===================================================================
---
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/XSDConfigurationContributorFactory.java 2010-08-20
20:17:37 UTC (rev 24354)
+++
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/XSDConfigurationContributorFactory.java 2010-08-20
21:27:49 UTC (rev 24355)
@@ -34,7 +34,7 @@
import org.jboss.tools.smooks.configuration.editors.input.InputSourceType;
import org.jboss.tools.smooks.configuration.editors.input.InputTaskPanelContributor;
import
org.jboss.tools.smooks.configuration.editors.input.InputTaskPanelContributorFactory;
-import org.jboss.tools.smooks.configuration.editors.input.Messages;
+import org.jboss.tools.smooks.configuration.editors.input.contributors.Messages;
import org.jboss.tools.smooks.configuration.editors.uitls.SmooksUIUtils;
import org.jboss.tools.smooks.model.SmooksModel;
import org.jboss.tools.smooks.model.core.ICorePackage;
@@ -80,7 +80,7 @@
Composite xsdFileSelectionSection = new Composite(inputSourceConfigComposite,
SWT.NONE);
pageSelectionComponent = new
FileSelectionPageComponent(editorPart.getEditorSite().getShell(), new String[]
{"xsd"});
- pageSelectionComponent.setLabel(Messages.XSDConfigurationContributor_XML_Schema_File);
+ pageSelectionComponent.setLabel(Messages.XSDConfigurationContributorFactory_XML_Schema_File);
pageSelectionComponent.createControl(xsdFileSelectionSection);
pageSelectionComponent.addFileSelectionListener(new FileSelectionListener() {
public void fileSelected(String fileName) {
@@ -151,7 +151,7 @@
gd = new GridData(GridData.BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING);
Label rootElementsLabel = new Label(xsdRootElementSelectionSection, SWT.NONE);
rootElementsLabel.setLayoutData(gd);
- rootElementsLabel.setText(Messages.XSDConfigurationContributor_Root_Element_Name);
+ rootElementsLabel.setText(Messages.XSDConfigurationContributorFactory_Root_Element_Name);
gd = new GridData(GridData.FILL_HORIZONTAL);
rootElementsDropDown = new Combo(xsdRootElementSelectionSection, SWT.DROP_DOWN |
SWT.READ_ONLY | SWT.RESIZE);
Added:
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/messages.properties
===================================================================
---
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/messages.properties
(rev 0)
+++
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/contributors/messages.properties 2010-08-20
21:27:49 UTC (rev 24355)
@@ -0,0 +1,5 @@
+ConfigurationContributorFactory_Browse_Button=Browse...
+XSDConfigurationContributorFactory_Root_Element_Name=Root Element Name:
+XSDConfigurationContributorFactory_XML_Schema_File=XML Schema File:
+XSDConfigurationContributorFactory_Root_Element_Name=Root Element Name:
+JavaConfigurationContributorFactory_Class_Name=Class:
\ No newline at end of file
Modified:
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/messages.properties
===================================================================
---
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/messages.properties 2010-08-20
20:17:37 UTC (rev 24354)
+++
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/messages.properties 2010-08-20
21:27:49 UTC (rev 24355)
@@ -2,5 +2,3 @@
InputSourceType_Warning_Specify_Sample_Data=Specify sample data in the Input Data
section.
InputSourceType_Unknown_Input_Type_Name=Unknown Input Type Name:
InputSourceType_Unknown_Input_Type_Index=Unknown Input Type Index:
-XSDConfigurationContributor_XML_Schema_File=XML Schema File:
-XSDConfigurationContributor_Root_Element_Name=Root Element Name:
\ No newline at end of file
Modified:
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/model/JavaInputModelFactory.java
===================================================================
---
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/model/JavaInputModelFactory.java 2010-08-20
20:17:37 UTC (rev 24354)
+++
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/input/model/JavaInputModelFactory.java 2010-08-20
21:27:49 UTC (rev 24355)
@@ -10,12 +10,31 @@
******************************************************************************/
package org.jboss.tools.smooks.configuration.editors.input.model;
+import java.lang.reflect.Array;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.transform.dom.DOMResult;
+
import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaModelException;
import org.jboss.tools.smooks.configuration.SmooksModelUtils;
+import org.jboss.tools.smooks.configuration.editors.uitls.ProjectClassLoader;
import org.jboss.tools.smooks.model.SmooksModel;
import org.jboss.tools.smooks.model.core.IParam;
+import org.jboss.tools.smooks.templating.model.ModelBuilderException;
+import org.milyn.Smooks;
+import org.milyn.payload.JavaSource;
import org.w3c.dom.Document;
-import org.w3c.dom.Element;
/**
* Java Source Input Model Factory.
@@ -24,12 +43,128 @@
*/
public class JavaInputModelFactory extends AbstractInputModelFactory {
- public Document getModel(SmooksModel smooksConfigModel, IJavaProject project) {
+ private Smooks smooksRuntime = new Smooks();
+ private JavaGraphBuilder graphBuilder = new JavaGraphBuilder();
+
+ public Document getModel(SmooksModel smooksConfigModel, IJavaProject project) throws
ModelBuilderException {
IParam inputSourceParam = getInputSourceParam(SmooksModelUtils.INPUT_TYPE_JAVA,
smooksConfigModel);
-
-
-
- return null;
+
+ try {
+ ProjectClassLoader classLoader = new ProjectClassLoader(project);
+ Class theModelClass = classLoader.loadClass(inputSourceParam.getValue().trim());
+ Object objectGraph = graphBuilder.buildGraph(theModelClass);
+ DOMResult domResult = new DOMResult();
+
+ // Filter a populated object model through an actual smooks runtime instance.
+ // this ensures that the generated model will be exactly the same as that seen
+ // by the smooks instance at runtime...
+ smooksRuntime.filterSource(new JavaSource(objectGraph), domResult);
+
+ return (Document) domResult.getNode();
+ } catch (JavaModelException e) {
+ throw new ModelBuilderException("Error build project classpath.", e);
//$NON-NLS-1$
+ } catch (ClassNotFoundException e) {
+ throw new ModelBuilderException("Java Class '" +
inputSourceParam.getValue().trim() + "' not found on project classpath.",
e); //$NON-NLS-1$ //$NON-NLS-2$
+ }
}
+ public static class JavaGraphBuilder {
+
+ public <T> T buildGraph(Class<T> messageType) {
+ try {
+ return buildObject(messageType);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new IllegalArgumentException("Unable to construct an instance of
'" + messageType.getName() + "'", e);
+ }
+ }
+
+ private <T> T buildObject(Class<T> objectType) throws
IllegalAccessException, InstantiationException, InvocationTargetException,
NoSuchMethodException {
+
+ if(String.class.isAssignableFrom(objectType)) {
+ return objectType.cast("x");
+ } else if(Number.class.isAssignableFrom(objectType)) {
+ return objectType.getConstructor(String.class).newInstance("1");
+ } else if(objectType.isPrimitive()) {
+ return (T) primitiveToObjectMap.get(objectType);
+ } else if(objectType == Object.class) {
+ // don't construct raw Object types... leave them and just return
null...
+ return null;
+ }
+
+ T messageInstance = objectType.newInstance();
+
+ // populate all the fields...
+ Method[] methods = objectType.getMethods();
+ for(Method method : methods) {
+ if(method.getName().startsWith("set") &&
method.getParameterTypes().length == 1) {
+ Class<?> propertyType = method.getParameterTypes()[0];
+ Object propertyInstance = null;
+
+ if(Collection.class.isAssignableFrom(propertyType)) {
+ propertyInstance = buildCollection(method, propertyType);
+ } else if(propertyType.isArray()) {
+ propertyInstance = buildArray(method, propertyType);
+ } else {
+ propertyInstance = buildObject(propertyType);
+ }
+
+ if(propertyInstance != null) {
+ method.invoke(messageInstance, propertyInstance);
+ }
+ }
+ }
+
+ return messageInstance;
+ }
+
+ private Object buildArray(Method method, Class<?> propertyType) throws
ArrayIndexOutOfBoundsException, IllegalArgumentException, IllegalAccessException,
InstantiationException, InvocationTargetException, NoSuchMethodException {
+ Class<?> arrayType = propertyType.getComponentType();
+ Object[] arrayObj = (Object[]) Array.newInstance(arrayType, 1);
+
+ Array.set(arrayObj, 0, buildObject(arrayType));
+
+ return arrayObj;
+ }
+
+ private Object buildCollection(Method method, Class<?> propertyType) throws
IllegalAccessException, InstantiationException, InvocationTargetException,
NoSuchMethodException {
+ Type genericType = method.getGenericParameterTypes()[0];
+
+ if(genericType instanceof ParameterizedType) {
+ ParameterizedType genericTypeClass = (ParameterizedType) genericType;
+ Collection collection = null;
+
+ if(!propertyType.isInterface()) {
+ // It's a concrete Collection type... just create an instance...
+ collection = (Collection) propertyType.newInstance();
+ }else if(List.class.isAssignableFrom(propertyType)) {
+ collection = new ArrayList();
+ } else if(Set.class.isAssignableFrom(propertyType)) {
+ collection = new LinkedHashSet();
+ }
+
+ if(collection != null) {
+ collection.add(buildObject((Class<Object>)
genericTypeClass.getActualTypeArguments()[0]));
+ return collection;
+ }
+ }
+
+ return null;
+ }
+
+ private static final Map<Class, Object> primitiveToObjectMap;
+
+ static {
+ primitiveToObjectMap = new HashMap<Class, Object>();
+ primitiveToObjectMap.put(int.class, 1);
+ primitiveToObjectMap.put(long.class, 1L);
+ primitiveToObjectMap.put(boolean.class, true);
+ primitiveToObjectMap.put(float.class, 1f);
+ primitiveToObjectMap.put(double.class, 1d);
+ primitiveToObjectMap.put(char.class, '1');
+ primitiveToObjectMap.put(byte.class, Byte.parseByte("1"));
+ primitiveToObjectMap.put(short.class, 1);
+ }
+
+ }
}
Modified:
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/uitls/SmooksUIUtils.java
===================================================================
---
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/uitls/SmooksUIUtils.java 2010-08-20
20:17:37 UTC (rev 24354)
+++
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/uitls/SmooksUIUtils.java 2010-08-20
21:27:49 UTC (rev 24355)
@@ -157,7 +157,7 @@
}
public static IParam recordInputDataInfomation(
- EditingDomain domain, GlobalParams paramsType, String type,
+ EditingDomain domain, GlobalParams globalParams, String type,
String path, Properties properties, CompoundCommand compoundCommand) {
if (type != null && path != null && domain != null) {
@@ -176,7 +176,7 @@
Command command = null;
try {
- command = AddCommand.create(domain, paramsType,
ICorePackage.Literals.PARAMS__PARAMS, params);
+ command = AddCommand.create(domain, globalParams,
ICorePackage.Literals.PARAMS__PARAMS, params);
} catch (Throwable t) {
t.printStackTrace();
}
Added:
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/util/TextFieldChangeListener.java
===================================================================
---
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/util/TextFieldChangeListener.java
(rev 0)
+++
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/util/TextFieldChangeListener.java 2010-08-20
21:27:49 UTC (rev 24355)
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.util;
+
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Text Field change listener.
+ * <p/>
+ * Forwards a field value change event if the {@link #fieldChanged} method
+ * implementation if the carriage return is pressed, or the field looses
+ * focus.
+ *
+ * @author <a
href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
+ */
+public abstract class TextFieldChangeListener implements KeyListener, FocusListener {
+
+ private Text textField;
+ private String lastValue;
+
+ public TextFieldChangeListener(Text textField) {
+ this.textField = textField;
+ textField.addKeyListener(this);
+ textField.addFocusListener(this);
+ lastValue = textField.getText();
+ }
+
+ public void focusGained(FocusEvent event) {
+ lastValue = textField.getText();
+ }
+
+ public void focusLost(FocusEvent event) {
+ String currentValue = textField.getText();
+ if(!lastValue.equals(currentValue)) {
+ lastValue = currentValue;
+ fieldChanged(currentValue);
+ }
+ }
+
+ public void keyPressed(KeyEvent event) {
+ String currentValue = textField.getText();
+ if(event.character == '\r' && !lastValue.equals(currentValue)) {
+ lastValue = currentValue;
+ fieldChanged(currentValue);
+ }
+ }
+
+ public void keyReleased(KeyEvent event) {
+ }
+
+ public abstract void fieldChanged(String newValue);
+}
Property changes on:
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/util/TextFieldChangeListener.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF