Skip to content

Commit

Permalink
- support List model type conversions
Browse files Browse the repository at this point in the history
- roundtrip generic form to dmr and back
  • Loading branch information
heiko-braun committed Aug 7, 2012
1 parent bc23396 commit b2e2d1d
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,15 @@ public void closeDialogue() {
public void onCreateTemplate(FXTemplate template) {

closeDialogue();
System.out.println(template.asModelNode());
System.out.println("Create: "+template.asModelNode());
storage.storeTemplate(template);
getView().setTemplates(storage.loadTemplates());
}

@Override
public void onUpdateTemplate(FXTemplate template) {

System.out.println("Update: "+template.asModelNode());
storage.storeTemplate(template);
getView().setTemplates(storage.loadTemplates());
}
Expand All @@ -233,4 +241,6 @@ public void launchNewModelStepWizard(FXTemplate template) {
public void onRemoveModelStep(FXTemplate currentTemplate, String stepId) {

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,15 @@ public ModelNode asModelNode() {

return modelNode;
}

public void removeModel(String id) {
for(FXModel model : models)
{
if(model.getId().equals(id))
{
models.remove(model);
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ public interface StoragePresenter {
void launchNewModelStepWizard(FXTemplate template);

void onRemoveModelStep(FXTemplate currentTemplate, String stepId);

void onUpdateTemplate(FXTemplate template);
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,7 @@ public void onSelectionChange(SelectionChangeEvent selectionChangeEvent) {
public void setTemplates(Set<FXTemplate> fxTemplates) {
dataProvider.getList().clear();
dataProvider.getList().addAll(fxTemplates);
dataProvider.flush();
table.selectDefaultEntity();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.jboss.ballroom.client.widgets.tables.DefaultCellTable;
import org.jboss.ballroom.client.widgets.tools.ToolButton;
import org.jboss.ballroom.client.widgets.tools.ToolStrip;
import org.jboss.dmr.client.ModelNode;
import org.jboss.dmr.client.ModelType;

import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -95,8 +97,7 @@ public void onClick(ClickEvent clickEvent) {
final SimpleForm form = new SimpleForm();
form.setNumColumns(2);
final TextItem id = new TextItem("id", "ID");
final TextBoxItem desc = new TextBoxItem("desc", "Description", true);

final TextBoxItem desc = new TextBoxItem("description", "Description", true);
final TextAreaItem address = new TextAreaItem("address", "Address", true);
final ComboBoxItem type = new ComboBoxItem("execType", "ExecType")
{
Expand Down Expand Up @@ -148,6 +149,25 @@ public void onSelectionChange(SelectionChangeEvent selectionChangeEvent) {
@Override
public void onSave(Map<String, Object> changeset) {

final FXModel modelStep = selectionModel.getSelectedObject();
final ModelNode modelNode = modelStep.asModelNode();
for(String key : changeset.keySet())
{
for(String attribute : modelNode.keys())
{
if(key.equals(attribute))
{
final Object o = changeset.get(key);
final ModelType dmrType = Types.toDMR(o);
modelNode.get(attribute).set(dmrType, o);
break;
}
}
}

getCurrentTemplate().removeModel(modelStep.getId());
getCurrentTemplate().getModels().add(FXModel.fromModelNode(modelNode));
presenter.onUpdateTemplate(getCurrentTemplate());
}

@Override
Expand Down Expand Up @@ -180,5 +200,7 @@ public void setModelSteps(FXTemplate template, List<FXModel> models) {
this.currentTemplate = template;
dataProvider.getList().clear();
dataProvider.getList().addAll(models);
dataProvider.flush();
table.selectDefaultEntity();
}
}
42 changes: 42 additions & 0 deletions gui/src/main/java/org/jboss/as/console/client/tools/Types.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.jboss.as.console.client.tools;

import org.jboss.dmr.client.ModelType;

/**
* @author Heiko Braun
* @date 7/23/12
*/
public class Types {

public static ModelType toDMR(Object o) {
return resolveModelType(o.getClass().getName());
}

private static ModelType resolveModelType(String javaTypeName) {

ModelType type = null;

if("java.lang.String".equals(javaTypeName))
type = ModelType.STRING;
else if("java.lang.Integer".equals(javaTypeName))
type = ModelType.INT;
else if("java.lang.Long".equals(javaTypeName))
type = ModelType.LONG;
else if("java.lang.Boolean".equals(javaTypeName))
type = ModelType.BOOLEAN;
else if("java.lang.Double".equals(javaTypeName))
type = ModelType.DOUBLE;
else if("java.util.List".equals(javaTypeName)) {
type = ModelType.LIST;
}
else if("java.util.ArrayList".equals(javaTypeName)) {
type = ModelType.LIST;
}
else {
throw new RuntimeException("Failed to resolve ModelType for '"+ javaTypeName+"'");
}

return type;
}

}
8 changes: 8 additions & 0 deletions gui/src/main/java/org/jboss/dmr/client/ModelNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,14 @@ else if(type.equals(ModelType.BOOLEAN))
{
set((Boolean)propValue);
}
else if(type.equals(ModelType.LIST))
{
setEmptyList();
List list = (List)propValue;

for(Object item : list)
add(String.valueOf(item));
}
else
{
throw new RuntimeException("Type conversion not implemented for "+type);
Expand Down

0 comments on commit b2e2d1d

Please sign in to comment.