From f0acf25178e53a7880f9086c170e6b2c661a7a15 Mon Sep 17 00:00:00 2001 From: Nuwan Chamara Pallewela Date: Sat, 6 Aug 2016 04:31:49 +0530 Subject: [PATCH] Adding drop down list for data mapper element edit dialog for interrelated input element --- .../custom/action/AddNewArrayAction.java | 2 +- .../custom/action/AddNewAttributeAction.java | 2 +- .../custom/action/AddNewFieldAction.java | 2 +- .../custom/action/AddNewObjectAction.java | 2 +- .../custom/action/AddNewRootAction.java | 2 +- .../custom/action/EditArrayAction.java | 2 +- .../custom/action/EditAttributeAction.java | 2 +- .../custom/action/EditFieldAction.java | 2 +- .../custom/action/EditObjectAction.java | 2 +- ...erentLevelArrayMappingConfigGenerator.java | 2 +- .../custom/model/DataMapperDiagramModel.java | 15 +- .../custom/util/AddNewObjectDialog.java | 278 +++++++++++------- .../custom/util/ScriptGenerationUtil.java | 2 +- 13 files changed, 193 insertions(+), 122 deletions(-) diff --git a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/AddNewArrayAction.java b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/AddNewArrayAction.java index 1c199ec4f..56a3bca93 100644 --- a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/AddNewArrayAction.java +++ b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/AddNewArrayAction.java @@ -98,7 +98,7 @@ public AddNewArrayAction(IWorkbenchPart workbenchPart) { protected void doRun(IProgressMonitor progressMonitor) { selectedEP = getSelectedEditPart(); AddNewObjectDialog objectDialog = new AddNewObjectDialog(Display.getCurrent().getActiveShell(), - new Class[] { IRegistryFile.class }); + new Class[] { IRegistryFile.class }, selectedEP); //Check if the edit part is an output edit part isOutputEditPart = checkContainer(selectedEP); objectDialog.create(); diff --git a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/AddNewAttributeAction.java b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/AddNewAttributeAction.java index d61351d91..922f989f8 100644 --- a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/AddNewAttributeAction.java +++ b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/AddNewAttributeAction.java @@ -89,7 +89,7 @@ protected void doRun(IProgressMonitor progressMonitor) { selectedEP = getSelectedEditPart(); AddNewObjectDialog objectDialog = new AddNewObjectDialog(Display.getCurrent().getActiveShell(), - new Class[] { IRegistryFile.class }); + new Class[] { IRegistryFile.class }, selectedEP); objectDialog.create(); objectDialog.setTitle(DIALOG_TITLE); objectDialog.setVisibility(DIALOG_TITLE,false); diff --git a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/AddNewFieldAction.java b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/AddNewFieldAction.java index 3be7a3116..996e618d8 100644 --- a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/AddNewFieldAction.java +++ b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/AddNewFieldAction.java @@ -86,7 +86,7 @@ public AddNewFieldAction(IWorkbenchPart workbenchPart) { protected void doRun(IProgressMonitor progressMonitor) { selectedEP = getSelectedEditPart(); AddNewObjectDialog objectDialog = new AddNewObjectDialog(Display.getCurrent().getActiveShell(), - new Class[] { IRegistryFile.class }); + new Class[] { IRegistryFile.class }, selectedEP); objectDialog.create(); objectDialog.setTitle(DIALOG_TITLE); objectDialog.setVisibility(DIALOG_TITLE,false); diff --git a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/AddNewObjectAction.java b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/AddNewObjectAction.java index aa7be75e9..cc4129afe 100644 --- a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/AddNewObjectAction.java +++ b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/AddNewObjectAction.java @@ -98,7 +98,7 @@ protected void doRun(IProgressMonitor progressMonitor) { selectedEP = getSelectedEditPart(); AddNewObjectDialog objectDialog = new AddNewObjectDialog(Display.getCurrent().getActiveShell(), - new Class[] { IRegistryFile.class }); + new Class[] { IRegistryFile.class }, selectedEP); objectDialog.create(); objectDialog.setTitle(DIALOG_TITLE); objectDialog.setVisibility(DIALOG_TITLE,false); diff --git a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/AddNewRootAction.java b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/AddNewRootAction.java index 224f4a1b7..f241e9dc9 100644 --- a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/AddNewRootAction.java +++ b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/AddNewRootAction.java @@ -106,7 +106,7 @@ protected void doRun(IProgressMonitor progressMonitor) { } else { AddNewObjectDialog rootElementDialog = new AddNewObjectDialog(Display.getCurrent().getActiveShell(), - new Class[] { IRegistryFile.class }); + new Class[] { IRegistryFile.class }, selectedEP); rootElementDialog.create(); rootElementDialog.setTitle(DIALOG_TITLE); rootElementDialog.setVisibility(DIALOG_TITLE,false); diff --git a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/EditArrayAction.java b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/EditArrayAction.java index 12a010cfc..09b68dc12 100644 --- a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/EditArrayAction.java +++ b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/EditArrayAction.java @@ -538,7 +538,7 @@ private void openEditRecordDialog(TreeNode selectedNode, String title, String sc String required, String schemaValue, String namespaces, String value, String identifierType, String identifierValue, String identifierURL, boolean isNullable, String interrelatedElement, boolean isOutputEditPart, boolean isRootElement, String rootInterrelatedElement) { Shell shell = Display.getDefault().getActiveShell(); - AddNewObjectDialog editTypeDialog = new AddNewObjectDialog(shell, new Class[] { IRegistryFile.class }); + AddNewObjectDialog editTypeDialog = new AddNewObjectDialog(shell, new Class[] { IRegistryFile.class }, selectedEP); editTypeDialog.create(); editTypeDialog.setTypeWhenEditing(schemaType); diff --git a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/EditAttributeAction.java b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/EditAttributeAction.java index f775151fd..6a35bb64f 100644 --- a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/EditAttributeAction.java +++ b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/EditAttributeAction.java @@ -309,7 +309,7 @@ private void openEditFieldDialog(TreeNode selectedNode, String title, String sch String schemaValue, String namespaces, boolean isNullable) { Shell shell = Display.getDefault().getActiveShell(); - AddNewObjectDialog editTypeDialog = new AddNewObjectDialog(shell, new Class[] { IRegistryFile.class }); + AddNewObjectDialog editTypeDialog = new AddNewObjectDialog(shell, new Class[] { IRegistryFile.class }, selectedEP); editTypeDialog.create(); editTypeDialog.setTypeWhenEditing(schemaType); diff --git a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/EditFieldAction.java b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/EditFieldAction.java index 5c135c4fc..eb0ff9743 100644 --- a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/EditFieldAction.java +++ b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/EditFieldAction.java @@ -303,7 +303,7 @@ private void executeCommand(TreeNode selectedNode, EStructuralFeature feature, S private void openEditRecordDialog(TreeNode selectedNode, String title, String schemaType, String id, String required, String schemaValue, String namespaces, boolean isNullable) { Shell shell = Display.getDefault().getActiveShell(); - AddNewObjectDialog editTypeDialog = new AddNewObjectDialog(shell, new Class[] { IRegistryFile.class }); + AddNewObjectDialog editTypeDialog = new AddNewObjectDialog(shell, new Class[] { IRegistryFile.class }, selectedEP); editTypeDialog.create(); editTypeDialog.setTypeWhenEditing(schemaType); diff --git a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/EditObjectAction.java b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/EditObjectAction.java index df3b42f3e..4399b36e1 100644 --- a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/EditObjectAction.java +++ b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/action/EditObjectAction.java @@ -462,7 +462,7 @@ private void openEditRecordDialog(TreeNode selectedNode, String title, String sc String required, String schemaValue, String namespaces, String value, String identifierType, String identifierValue, String identifierURL, boolean isNullable,String interrelatedElement, boolean isOutputEditPart, boolean isRootElement, String rootInterrelatedElement) { Shell shell = Display.getDefault().getActiveShell(); - AddNewObjectDialog editTypeDialog = new AddNewObjectDialog(shell, new Class[] { IRegistryFile.class }); + AddNewObjectDialog editTypeDialog = new AddNewObjectDialog(shell, new Class[] { IRegistryFile.class }, selectedEP); editTypeDialog.create(); editTypeDialog.setTypeWhenEditing(schemaType); diff --git a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/generator/DifferentLevelArrayMappingConfigGenerator.java b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/generator/DifferentLevelArrayMappingConfigGenerator.java index 9bfcb0f62..5baeef2ce 100644 --- a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/generator/DifferentLevelArrayMappingConfigGenerator.java +++ b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/generator/DifferentLevelArrayMappingConfigGenerator.java @@ -97,7 +97,7 @@ private void populateOutputArrayRootVariableMap(DataMapperDiagramModel model) { if (outputVariable.getMappedInputVariableRootArrayElement() != null) { if (forLoopBeanMap.containsKey(ScriptGenerationUtil .removeInvalidCharaters(outputVariable.getMappedInputVariableRootArrayElement()))) { - int rootArrayVariableForLoopIndex = outputArrayVariableForLoopMap + int rootArrayVariableForLoopIndex = forLoopBeanMap .get(outputVariable.getMappedInputVariableRootArrayElement()); outputArrayRootVariableForLoop.put(outputVariable.getName(), rootArrayVariableForLoopIndex); } else { diff --git a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/model/DataMapperDiagramModel.java b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/model/DataMapperDiagramModel.java index ae0dcfaa7..d3d25fb4a 100644 --- a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/model/DataMapperDiagramModel.java +++ b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/model/DataMapperDiagramModel.java @@ -16,6 +16,8 @@ package org.wso2.developerstudio.datamapper.diagram.custom.model; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -954,7 +956,18 @@ private String getMappedRootArrayInputElement(TreeNodeImpl currentTreeNode) { private String getMappedInputArrayFromMap(Map outputInputElementMapping, String variableName) { Set outputArrayVariables = outputInputElementMapping.keySet(); - for (String arrayName : outputArrayVariables) { + List outputArrayVariablesList = new ArrayList<>(); + for (String string : outputArrayVariables) { + outputArrayVariablesList.add(string); + } + Collections.sort(outputArrayVariablesList, new Comparator() { + + @Override + public int compare(String str1, String str2) { + return -str1.length() + str2.length(); + } + }); + for (String arrayName : outputArrayVariablesList) { if(variableName.startsWith(arrayName)){ return outputInputElementMapping.get(arrayName); } diff --git a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/util/AddNewObjectDialog.java b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/util/AddNewObjectDialog.java index 281a2aeb9..020515152 100644 --- a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/util/AddNewObjectDialog.java +++ b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/util/AddNewObjectDialog.java @@ -16,7 +16,19 @@ package org.wso2.developerstudio.datamapper.diagram.custom.util; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Stack; + import org.apache.commons.lang.StringUtils; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.edit.tree.impl.TreeNodeImpl; +import org.eclipse.gef.EditPart; +import org.eclipse.gmf.runtime.notation.Node; +import org.eclipse.gmf.runtime.notation.impl.DiagramImpl; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.swt.SWT; @@ -35,6 +47,18 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; +import org.wso2.developerstudio.datamapper.Input; +import org.wso2.developerstudio.datamapper.PropertyKeyValuePair; +import org.wso2.developerstudio.datamapper.SchemaDataType; +import org.wso2.developerstudio.datamapper.TreeNode; +import org.wso2.developerstudio.datamapper.diagram.custom.model.DMVariable; +import org.wso2.developerstudio.datamapper.diagram.custom.model.DMVariableType; +import org.wso2.developerstudio.datamapper.diagram.edit.parts.DataMapperRootEditPart; +import org.wso2.developerstudio.datamapper.diagram.edit.parts.InputEditPart; +import org.wso2.developerstudio.datamapper.diagram.edit.parts.OutputEditPart; +import org.wso2.developerstudio.datamapper.diagram.edit.parts.TreeNodeEditPart; +import org.wso2.developerstudio.datamapper.impl.DataMapperRootImpl; +import org.wso2.developerstudio.datamapper.impl.ElementImpl; public class AddNewObjectDialog extends Dialog { @@ -53,8 +77,8 @@ public class AddNewObjectDialog extends Dialog { private Button checkBoxForIdentifiers; private Button btnNamespaces; private Button checkBoxForNullables; - private Text textInterrelatedElement; - private Text textRootInterrelatedElement; + private Combo textInterrelatedCombo; + private Combo textRootInterrelatedCombo; private Label lblTitleLabel; @@ -132,15 +156,38 @@ public class AddNewObjectDialog extends Dialog { private boolean okPressed = false; private Label lblRootInterrelatedElement; + private InputEditPart inputRootElement; + private boolean isElementInOutput; + private EditPart selectedEP; /** * Create the dialog. * * @param parentShell + * @param selectedEP TODO */ - public AddNewObjectDialog(Shell parentShell, Class[] type) { + public AddNewObjectDialog(Shell parentShell, Class[] type, EditPart selectedEP) { super(parentShell); setShellStyle(SWT.CLOSE | SWT.TITLE | SWT.BORDER | SWT.OK | SWT.APPLICATION_MODAL); + this.selectedEP = selectedEP; + inputRootElement = getInputRootElement(selectedEP); + } + + private InputEditPart getInputRootElement(EditPart selectedEP) { + while(!(selectedEP instanceof OutputEditPart)){ + selectedEP=selectedEP.getParent(); + if(selectedEP instanceof DataMapperRootEditPart){ + return null; + } + } + @SuppressWarnings("unchecked") + List diagramElements = selectedEP.getParent().getChildren(); + for (EditPart editPart : diagramElements) { + if(editPart instanceof InputEditPart){ + return (InputEditPart) editPart; + } + } + return null; } /** @@ -192,10 +239,6 @@ public void setVisibility(String title, boolean isOutputEditPart) { textIdentifierURL.setVisible(false); checkBoxForNullables.setVisible(true); lblNullables.setVisible(true); - lblInterrelatedElement.setVisible(false); - lblRootInterrelatedElement.setVisible(false); - textInterrelatedElement.setVisible(false); - textRootInterrelatedElement.setVisible(false); isRootElementNode = true; } if (title.equals(DIALOG_TITLE_OBJECT)) { @@ -217,10 +260,6 @@ public void setVisibility(String title, boolean isOutputEditPart) { textIdentifierURL.setVisible(false); checkBoxForNullables.setVisible(true); lblNullables.setVisible(true); - lblInterrelatedElement.setVisible(false); - lblRootInterrelatedElement.setVisible(false); - textInterrelatedElement.setVisible(false); - textRootInterrelatedElement.setVisible(false); }if(title.equals(DIALOG_TITLE_ARRAY)){ lblSchemaValue.setVisible(false); textSchemaValue.setVisible(false); @@ -241,15 +280,10 @@ public void setVisibility(String title, boolean isOutputEditPart) { checkBoxForNullables.setVisible(true); lblNullables.setVisible(true); if(isOutputEditPart){ - lblInterrelatedElement.setVisible(true); - lblRootInterrelatedElement.setVisible(true); - textInterrelatedElement.setVisible(true); - textRootInterrelatedElement.setVisible(true); - }else{ - lblInterrelatedElement.setVisible(false); - lblRootInterrelatedElement.setVisible(false); - textInterrelatedElement.setVisible(false); - textRootInterrelatedElement.setVisible(false); + lblInterrelatedElement.setVisible(true && isElementInOutput); + lblRootInterrelatedElement.setVisible(true && isElementInOutput); + textInterrelatedCombo.setVisible(true && isElementInOutput); + textRootInterrelatedCombo.setVisible(true && isElementInOutput); } } if (title.equals(DIALOG_TITLE_FIELD)) { @@ -267,10 +301,6 @@ public void setVisibility(String title, boolean isOutputEditPart) { textIdentifierURL.setVisible(false); checkBoxForNullables.setVisible(true); lblNullables.setVisible(true); - lblInterrelatedElement.setVisible(false); - lblRootInterrelatedElement.setVisible(false); - textInterrelatedElement.setVisible(false); - textRootInterrelatedElement.setVisible(false); lblSchemaValue.setVisible(false); textSchemaValue.setVisible(false); }if(title.equals(DIALOG_TITLE_ATTRIBUTE)){ @@ -288,10 +318,6 @@ public void setVisibility(String title, boolean isOutputEditPart) { textIdentifierURL.setVisible(false); checkBoxForNullables.setVisible(true); lblNullables.setVisible(true); - lblInterrelatedElement.setVisible(false); - lblRootInterrelatedElement.setVisible(false); - textInterrelatedElement.setVisible(false); - textRootInterrelatedElement.setVisible(false); lblSchemaValue.setVisible(false); textSchemaValue.setVisible(false); } @@ -373,10 +399,6 @@ public void setValues(String title, String schemaType, String id, String require textNamespaces.setVisible(true); checkBoxForNullables.setVisible(true); lblNullables.setVisible(true); - lblInterrelatedElement.setVisible(false); - lblRootInterrelatedElement.setVisible(false); - textInterrelatedElement.setVisible(false); - textRootInterrelatedElement.setVisible(false); if(isRootElement){ checkBoxForIdentifiers.setVisible(false); lblCheckBoxForIdentifiers.setVisible(false); @@ -421,19 +443,14 @@ public void setValues(String title, String schemaType, String id, String require if(isOutputEditPart){ lblInterrelatedElement.setVisible(true); lblRootInterrelatedElement.setVisible(true); - textInterrelatedElement.setVisible(true); - textRootInterrelatedElement.setVisible(true); + textInterrelatedCombo.setVisible(true); + textRootInterrelatedCombo.setVisible(true); if(StringUtils.isNotEmpty(interrelatedElement)){ - textInterrelatedElement.setText(interrelatedElement); + textInterrelatedCombo.setText(interrelatedElement); } if(StringUtils.isNotEmpty(rootInterrelatedElement)){ - textRootInterrelatedElement.setText(rootInterrelatedElement); + textRootInterrelatedCombo.setText(rootInterrelatedElement); } - }else{ - lblInterrelatedElement.setVisible(false); - lblRootInterrelatedElement.setVisible(false); - textInterrelatedElement.setVisible(false); - textRootInterrelatedElement.setVisible(false); } if(isRootElement){ checkBoxForIdentifiers.setVisible(false); @@ -489,10 +506,6 @@ public void setValues(String title, String schemaType, String id, String require textIdentifierURL.setVisible(false); checkBoxForNullables.setVisible(true); lblNullables.setVisible(true); - lblInterrelatedElement.setVisible(false); - lblRootInterrelatedElement.setVisible(false); - textInterrelatedElement.setVisible(false); - textRootInterrelatedElement.setVisible(false); break; case "number": comboSchemaType.select(1); @@ -518,10 +531,6 @@ public void setValues(String title, String schemaType, String id, String require textIdentifierURL.setVisible(false); checkBoxForNullables.setVisible(true); lblNullables.setVisible(true); - lblInterrelatedElement.setVisible(false); - lblRootInterrelatedElement.setVisible(false); - textInterrelatedElement.setVisible(false); - textRootInterrelatedElement.setVisible(false); break; case "boolean": comboSchemaType.select(2); @@ -545,10 +554,6 @@ public void setValues(String title, String schemaType, String id, String require textIdentifierURL.setVisible(false); checkBoxForNullables.setVisible(true); lblNullables.setVisible(true); - lblInterrelatedElement.setVisible(false); - lblRootInterrelatedElement.setVisible(false); - textInterrelatedElement.setVisible(false); - textRootInterrelatedElement.setVisible(false); break; case "bytes": comboSchemaType.select(3); @@ -572,10 +577,6 @@ public void setValues(String title, String schemaType, String id, String require textIdentifierURL.setVisible(false); checkBoxForNullables.setVisible(true); lblNullables.setVisible(true); - lblInterrelatedElement.setVisible(false); - lblRootInterrelatedElement.setVisible(false); - textInterrelatedElement.setVisible(false); - textRootInterrelatedElement.setVisible(false); break; case "double": comboSchemaType.select(4); @@ -599,10 +600,6 @@ public void setValues(String title, String schemaType, String id, String require textIdentifierURL.setVisible(false); checkBoxForNullables.setVisible(true); lblNullables.setVisible(true); - lblInterrelatedElement.setVisible(false); - lblRootInterrelatedElement.setVisible(false); - textInterrelatedElement.setVisible(false); - textRootInterrelatedElement.setVisible(false); break; case "enum": comboSchemaType.select(5); @@ -626,10 +623,6 @@ public void setValues(String title, String schemaType, String id, String require textIdentifierURL.setVisible(false); checkBoxForNullables.setVisible(true); lblNullables.setVisible(true); - lblInterrelatedElement.setVisible(false); - lblRootInterrelatedElement.setVisible(false); - textInterrelatedElement.setVisible(false); - textRootInterrelatedElement.setVisible(false); break; case "fixed": comboSchemaType.select(6); @@ -653,10 +646,6 @@ public void setValues(String title, String schemaType, String id, String require textIdentifierURL.setVisible(false); checkBoxForNullables.setVisible(true); lblNullables.setVisible(true); - lblInterrelatedElement.setVisible(false); - lblRootInterrelatedElement.setVisible(false); - textInterrelatedElement.setVisible(false); - textRootInterrelatedElement.setVisible(false); break; case "float": comboSchemaType.select(7); @@ -680,10 +669,6 @@ public void setValues(String title, String schemaType, String id, String require textIdentifierURL.setVisible(false); checkBoxForNullables.setVisible(true); lblNullables.setVisible(true); - lblInterrelatedElement.setVisible(false); - lblRootInterrelatedElement.setVisible(false); - textInterrelatedElement.setVisible(false); - textRootInterrelatedElement.setVisible(false); break; case "long": comboSchemaType.select(8); @@ -707,10 +692,6 @@ public void setValues(String title, String schemaType, String id, String require textIdentifierURL.setVisible(false); checkBoxForNullables.setVisible(true); lblNullables.setVisible(true); - lblInterrelatedElement.setVisible(false); - lblRootInterrelatedElement.setVisible(false); - textInterrelatedElement.setVisible(false); - textRootInterrelatedElement.setVisible(false); break; case "map": comboSchemaType.select(9); @@ -734,10 +715,6 @@ public void setValues(String title, String schemaType, String id, String require textIdentifierURL.setVisible(false); checkBoxForNullables.setVisible(true); lblNullables.setVisible(true); - lblInterrelatedElement.setVisible(false); - lblRootInterrelatedElement.setVisible(false); - textInterrelatedElement.setVisible(false); - textRootInterrelatedElement.setVisible(false); break; case "union": comboSchemaType.select(10); @@ -761,10 +738,6 @@ public void setValues(String title, String schemaType, String id, String require textIdentifierURL.setVisible(false); checkBoxForNullables.setVisible(true); lblNullables.setVisible(true); - lblInterrelatedElement.setVisible(false); - lblRootInterrelatedElement.setVisible(false); - textInterrelatedElement.setVisible(false); - textRootInterrelatedElement.setVisible(false); break; default: break; @@ -910,15 +883,11 @@ public void widgetSelected(SelectionEvent e) { textIdentifierURL.setVisible(false); checkBoxForNullables.setVisible(true); lblNullables.setVisible(true); - lblInterrelatedElement.setVisible(false); - lblRootInterrelatedElement.setVisible(false); - textInterrelatedElement.setVisible(false); - textRootInterrelatedElement.setVisible(false); if(comboSchemaType.getText().equals("array") && isOutputEditpartContainer){ lblInterrelatedElement.setVisible(true); lblRootInterrelatedElement.setVisible(true); - textInterrelatedElement.setVisible(true); - textRootInterrelatedElement.setVisible(true); + textInterrelatedCombo.setVisible(true); + textRootInterrelatedCombo.setVisible(true); } if(isRootElementNode){ checkBoxForValue.setVisible(false); @@ -1049,25 +1018,34 @@ public void modifyText(ModifyEvent arg0) { }); textSchemaValue.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 5, 1)); + TreeNode node = (TreeNode) ((Node) selectedEP.getModel()).getElement(); - lblInterrelatedElement = new Label(compositeType, SWT.NONE); - lblInterrelatedElement.setText(LABEL_INTERRELATED_ELEMENT); - - textInterrelatedElement = new Text(compositeType, SWT.BORDER); - - textInterrelatedElement.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent arg0) { - + if(inputRootElement != null && isArrayElement(node)){ + GridData dataPropertyConfigText = new GridData(); + dataPropertyConfigText.grabExcessHorizontalSpace = true; + dataPropertyConfigText.horizontalAlignment = GridData.FILL; + List arrayInputElements = getArrayElements(inputRootElement); + isElementInOutput = true; + lblInterrelatedElement = new Label(compositeType, SWT.NONE); + lblInterrelatedElement.setText(LABEL_INTERRELATED_ELEMENT); + + textInterrelatedCombo = new Combo(compositeType, SWT.DROP_DOWN | SWT.BORDER); + textInterrelatedCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 5, 1)); + for (String element : arrayInputElements) { + textInterrelatedCombo.add(element); } - }); - - textInterrelatedElement.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 5, 1)); - - lblRootInterrelatedElement = new Label(compositeType, SWT.NONE); - lblRootInterrelatedElement.setText(LABEL_ROOT_INTERRELATED_ELEMENT); - - textRootInterrelatedElement= new Text(compositeType, SWT.BORDER); - textRootInterrelatedElement.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 5, 1)); + + lblRootInterrelatedElement = new Label(compositeType, SWT.NONE); + lblRootInterrelatedElement.setText(LABEL_ROOT_INTERRELATED_ELEMENT); + + textRootInterrelatedCombo= new Combo(compositeType, SWT.DROP_DOWN | SWT.BORDER); + textRootInterrelatedCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 5, 1)); + for (String element : arrayInputElements) { + textRootInterrelatedCombo.add(element); + } + } else{ + isElementInOutput = false; + } checkBoxForIdentifiers = new Button(compositeType,SWT.CHECK); lblCheckBoxForIdentifiers = new Label(compositeType, SWT.NONE); @@ -1201,6 +1179,86 @@ public void widgetDefaultSelected(SelectionEvent arg0) { return container; } + private List getArrayElements(InputEditPart inputRootElement) { + List elementArray = new ArrayList<>(); + DiagramImpl diagram = (DiagramImpl) inputRootElement.getParent().getModel(); + DataMapperRootImpl element = (DataMapperRootImpl) diagram.getElement(); + Input input = element.getInput(); + Stack nodeStack = new Stack<>(); + nodeStack.addAll(input.getTreeNode()); + Stack parentVariableStack = new Stack(); + List tempNodeArray = new ArrayList<>(); + while (!nodeStack.isEmpty()) { + EObject currentNode = nodeStack.pop(); + if (currentNode instanceof TreeNode) { + TreeNode currentTreeNode = (TreeNode) currentNode; + if (currentTreeNode.getLevel() <= parentVariableStack.size()) { + while (parentVariableStack.size() >= currentTreeNode.getLevel()) { + parentVariableStack.pop(); + } + } else if (currentTreeNode.getLevel() > (parentVariableStack.size() + 1)) { + throw new IllegalArgumentException("Illegal element level detected : element level- " + + currentTreeNode.getLevel() + " , parents level- " + parentVariableStack.size()); + } + String variableName = getVariableName(parentVariableStack, currentTreeNode.getName()); + String variableType = getTreeNodeType(currentTreeNode); + if("array".equals(variableType)){ + elementArray.add(variableName); + } + if (currentTreeNode.getLevel() == parentVariableStack.size()) { + parentVariableStack.pop(); + parentVariableStack.push(currentTreeNode); + } else if (currentTreeNode.getLevel() > parentVariableStack.size()) { + parentVariableStack.push(currentTreeNode); + } else { + while (parentVariableStack.size() >= currentTreeNode.getLevel()) { + parentVariableStack.pop(); + } + parentVariableStack.push(currentTreeNode); + } + } + nodeStack.addAll(((TreeNode) currentNode).getNode()); + } + // diagram.get + return elementArray; + } + + private String getVariableName(Stack parentVariableStack, String name) { + String variableName = "input"; + for (EObject eObject : parentVariableStack) { + if (eObject instanceof TreeNode) { + variableName = variableName + + ScriptGenerationUtil.removeInvalidCharaters(((TreeNode) eObject).getName()) + "."; + } else if (eObject instanceof ElementImpl) { + variableName = variableName + + ScriptGenerationUtil.removeInvalidCharaters(((ElementImpl) eObject).getName()) + "."; + } else { + throw new IllegalArgumentException("Illegal element type found : " + eObject.toString()); + } + } + return variableName + ScriptGenerationUtil.removeInvalidCharaters(name); + } + + private String getTreeNodeType(TreeNode currentTreeNode) { + EList propertyList = currentTreeNode.getProperties(); + for (PropertyKeyValuePair propertyKeyValuePair : propertyList) { + if ("type".equals(propertyKeyValuePair.getKey())) { + return propertyKeyValuePair.getValue(); + } + } + throw new IllegalArgumentException("Type field not found in treeNode"); + } + + private boolean isArrayElement(TreeNode tempElement) { + EList properties = tempElement.getProperties(); + for (PropertyKeyValuePair propertyKeyValuePair : properties) { + if ("type".equals(propertyKeyValuePair.getKey()) && "array".equals(propertyKeyValuePair.getValue())) { + return true; + } + } + return false; + } + /** * Get namespaces as a string * @param namespaces @@ -1247,8 +1305,8 @@ protected void okPressed() { setIdentifierValue(textIdentifierValue.getText()); setIdentifierURL(textIdentifierURL.getText()); setNullable(isNullable); - setInterrelatedElement(textInterrelatedElement.getText()); - setRootInterrelatedElement(textRootInterrelatedElement.getText()); + setInterrelatedElement(textInterrelatedCombo.getText()); + setRootInterrelatedElement(textRootInterrelatedCombo.getText()); super.okPressed(); } diff --git a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/util/ScriptGenerationUtil.java b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/util/ScriptGenerationUtil.java index 1395a30c9..ba4e310b6 100644 --- a/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/util/ScriptGenerationUtil.java +++ b/plugins/org.wso2.developerstudio.visualdatamapper.diagram/src/org/wso2/developerstudio/datamapper/diagram/custom/util/ScriptGenerationUtil.java @@ -254,7 +254,7 @@ && getArrayElementCount(variable.getName(), map) == 1) { public static ForLoopBean getForLoopFromMappedVariableArrayName(String mappedInputVariableArrayElement, List forLoopBeanList) { for (ForLoopBean forLoopBean : forLoopBeanList) { - if(forLoopBean.getVariableName().equals("input"+removeInvalidCharaters(mappedInputVariableArrayElement))){ + if(forLoopBean.getVariableName().equals(removeInvalidCharaters(mappedInputVariableArrayElement))){ return forLoopBean; } }