diff --git a/drools-wb-screens/drools-wb-scenario-simulation-editor/drools-wb-scenario-simulation-editor-client/src/main/java/org/drools/workbench/screens/scenariosimulation/client/collectioneditor/CollectionPresenter.java b/drools-wb-screens/drools-wb-scenario-simulation-editor/drools-wb-scenario-simulation-editor-client/src/main/java/org/drools/workbench/screens/scenariosimulation/client/collectioneditor/CollectionPresenter.java index d59283652f5..29e0ae57986 100644 --- a/drools-wb-screens/drools-wb-scenario-simulation-editor/drools-wb-scenario-simulation-editor-client/src/main/java/org/drools/workbench/screens/scenariosimulation/client/collectioneditor/CollectionPresenter.java +++ b/drools-wb-screens/drools-wb-scenario-simulation-editor/drools-wb-scenario-simulation-editor-client/src/main/java/org/drools/workbench/screens/scenariosimulation/client/collectioneditor/CollectionPresenter.java @@ -22,7 +22,6 @@ import javax.inject.Inject; import com.google.gwt.dom.client.LIElement; -import com.google.gwt.dom.client.Style; import com.google.gwt.dom.client.UListElement; import com.google.gwt.json.client.JSONArray; import com.google.gwt.json.client.JSONObject; @@ -73,8 +72,6 @@ public class CollectionPresenter implements CollectionView.Presenter { protected CollectionView collectionView; - protected LIElement objectSeparatorLI; - @Override public void initListStructure(String key, Map simplePropertiesMap, Map> expandablePropertiesMap, CollectionView collectionView) { commonInit(key, collectionView); @@ -101,10 +98,22 @@ public void setValue(String jsonString) { return; } JSONValue jsonValue = getJSONValue(jsonString); + if (jsonValue instanceof JSONString) { + populateExpression(jsonValue); + } else { + populateCreateCollection(jsonValue); + } + } + + /** + * It populates the guided "Create Collection" editor + * @param value + */ + protected void populateCreateCollection(JSONValue value) { if (collectionView.isListWidget()) { - populateList(jsonValue); + populateList(value); } else { - populateMap(jsonValue); + populateMap(value); } } @@ -160,10 +169,10 @@ public void addMapItem(Map keyPropertiesValues, Map> simpleItemsProperties = listElementPresenter.getSimpleItemsProperties(); Map>> nestedItemsProperties = listElementPresenter.getExpandableItemsProperties(); @@ -317,8 +344,7 @@ protected Map> getExpandablePropertiesValues(JSONObj jsonObject.keySet().forEach(propertyName -> { final JSONValue jsonValue = jsonObject.get(propertyName); if (jsonValue.isObject() != null) { - final Map simplePropertiesMap = getSimplePropertiesMap(jsonValue.isObject()); - toReturn.put(propertyName, simplePropertiesMap); + toReturn.put(propertyName, getSimplePropertiesMap(jsonValue.isObject())); } }); return toReturn; @@ -327,7 +353,7 @@ protected Map> getExpandablePropertiesValues(JSONObj /** * @return */ - protected String getMapValue() throws IllegalStateException { + protected String getMapValue() { Map, Map> itemsProperties = mapElementPresenter.getItemsProperties(); JSONObject toReturnModel = new JSONObject(); itemsProperties.forEach((keyPropertiesValues, valuePropertiesMap) -> { diff --git a/drools-wb-screens/drools-wb-scenario-simulation-editor/drools-wb-scenario-simulation-editor-client/src/main/java/org/drools/workbench/screens/scenariosimulation/client/collectioneditor/CollectionView.java b/drools-wb-screens/drools-wb-scenario-simulation-editor/drools-wb-scenario-simulation-editor-client/src/main/java/org/drools/workbench/screens/scenariosimulation/client/collectioneditor/CollectionView.java index 4db69ae2253..402889562df 100644 --- a/drools-wb-screens/drools-wb-scenario-simulation-editor/drools-wb-scenario-simulation-editor-client/src/main/java/org/drools/workbench/screens/scenariosimulation/client/collectioneditor/CollectionView.java +++ b/drools-wb-screens/drools-wb-scenario-simulation-editor/drools-wb-scenario-simulation-editor-client/src/main/java/org/drools/workbench/screens/scenariosimulation/client/collectioneditor/CollectionView.java @@ -19,10 +19,10 @@ import com.google.gwt.dom.client.ButtonElement; import com.google.gwt.dom.client.HeadingElement; -import com.google.gwt.dom.client.LIElement; import com.google.gwt.dom.client.SpanElement; import com.google.gwt.dom.client.Style; import com.google.gwt.dom.client.UListElement; +import org.drools.scenariosimulation.api.model.ScenarioSimulationModel; /** * Interface defining the contract for actual implementations @@ -130,10 +130,9 @@ interface Presenter { String getValue(); /** - * @param listWidget set to true if the current instance will manage a List, - * false for a Map. + * Returns true if the current instance is managing an user defined expression. */ - void setListWidget(boolean listWidget); + boolean isExpressionWidget(); /** * Returns true if the current instance will manage a List, @@ -144,8 +143,6 @@ interface Presenter { UListElement getElementsContainer(); - LIElement getObjectSeparator(); - HeadingElement getEditorTitle(); SpanElement getPropertyTitle(); @@ -158,6 +155,10 @@ interface Presenter { ButtonElement getSaveButton(); + String getExpression(); + + void setExpression(String expressionValue); + void toggleRowExpansion(); /** @@ -183,10 +184,11 @@ interface Presenter { * Set the name of the property and the Map to be used to create the skeleton of the current CollectionViewImpl editor * showing a List of elements * @param key The key representing the property, i.e Classname#propertyname (e.g Author#books) - * @param instancePropertyMap + * @param simplePropertiesMap * @param expandablePropertiesMap + * @param type */ - void initListStructure(String key, Map instancePropertyMap, Map> expandablePropertiesMap); + void initListStructure(String key, Map simplePropertiesMap, Map> expandablePropertiesMap, ScenarioSimulationModel.Type type); /** * Set the name of the property and the Maps to be used to create the skeleton of the current CollectionViewImpl editor @@ -194,8 +196,9 @@ interface Presenter { * @param key The key representing the property, i.e Classname#propertyname (e.g Author#books) * @param keyPropertyMap * @param valuePropertyMap + * @param type */ - void initMapStructure(String key, Map keyPropertyMap, Map valuePropertyMap); + void initMapStructure(String key, Map keyPropertyMap, Map valuePropertyMap, ScenarioSimulationModel.Type type); void setFixedHeight(double value, Style.Unit px); diff --git a/drools-wb-screens/drools-wb-scenario-simulation-editor/drools-wb-scenario-simulation-editor-client/src/main/java/org/drools/workbench/screens/scenariosimulation/client/collectioneditor/CollectionViewImpl.html b/drools-wb-screens/drools-wb-scenario-simulation-editor/drools-wb-scenario-simulation-editor-client/src/main/java/org/drools/workbench/screens/scenariosimulation/client/collectioneditor/CollectionViewImpl.html index 525ff888040..0903de6ba37 100644 --- a/drools-wb-screens/drools-wb-scenario-simulation-editor/drools-wb-scenario-simulation-editor-client/src/main/java/org/drools/workbench/screens/scenariosimulation/client/collectioneditor/CollectionViewImpl.html +++ b/drools-wb-screens/drools-wb-scenario-simulation-editor/drools-wb-scenario-simulation-editor-client/src/main/java/org/drools/workbench/screens/scenariosimulation/client/collectioneditor/CollectionViewImpl.html @@ -9,32 +9,58 @@