Skip to content

Commit

Permalink
prevent map conversion: simple forms should work on DMR directly
Browse files Browse the repository at this point in the history
  • Loading branch information
heiko-braun committed Aug 7, 2012
1 parent 9267405 commit 462dbcb
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public String toBase64() {

public ModelNode asModelNode() {
ModelNode modelNode = new ModelNode();
modelNode.get("id").set(id);
modelNode.get("execType").set(type.name());
modelNode.get("address").set(address);
modelNode.get("description").set(description);
Expand All @@ -85,6 +86,7 @@ public ModelNode asModelNode() {

public static FXModel fromModelNode(ModelNode modelNode) {

final String id = modelNode.get("id").asString();
final String type = modelNode.get("execType").asString();
final ModelNode address = modelNode.get("address").asObject();
String description = modelNode.get("description").asString();
Expand All @@ -97,7 +99,12 @@ public static FXModel fromModelNode(ModelNode modelNode) {
final FXModel fxModel = new FXModel(ExecutionType.valueOf(type), address);
fxModel.getFieldNames().addAll(values);
fxModel.setDescription(description);
fxModel.setId(id);
return fxModel;
}

private void setId(String id) {
this.id = id;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
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;
import java.util.Map;

Expand Down Expand Up @@ -60,23 +58,23 @@ public Object getKey(FXModel FXModel) {
final SingleSelectionModel<FXModel> selectionModel = new SingleSelectionModel<FXModel>();
table.setSelectionModel(selectionModel);

TextColumn<FXModel> idCol = new TextColumn<FXModel>() {

TextColumn<FXModel> descCol = new TextColumn<FXModel>() {
@Override
public String getValue(FXModel FXModel) {
return FXModel.getId();
return FXModel.getDescription();
}

};

TextColumn<FXModel> typeCol = new TextColumn<FXModel>() {
@Override
public String getValue(FXModel FXModel) {
return FXModel.getType().name();
}
};

table.addColumn(idCol, "ID");
table.addColumn(typeCol, "Execution Type");
table.addColumn(descCol, "Description");

ToolStrip toolstrip = new ToolStrip();
ToolButton addBtn = new ToolButton("Add", new ClickHandler() {
Expand Down Expand Up @@ -136,20 +134,13 @@ public void onSelectionChange(SelectionChangeEvent selectionChangeEvent) {

if(modelStep!=null)
{
Map<String,Object> payload = new HashMap<String,Object>();
payload.put("id", modelStep.getId());
payload.put("description", modelStep.getDescription());
payload.put("address", modelStep.getAddress().asString());
payload.put("execType", modelStep.getType().name());
payload.put("fieldNames", modelStep.getFieldNames());

form.edit(payload);
form.edit(modelStep.asModelNode());
}
}
});


FXFormToolStrip formTools = new FXFormToolStrip(form, new FXFormToolStrip.FormCallback() {
SimpleFormToolStrip formTools = new SimpleFormToolStrip(form, new SimpleFormToolStrip.FormCallback() {
@Override
public void onSave(Map<String, Object> changeset) {

Expand All @@ -162,8 +153,8 @@ public void onSave(Map<String, Object> changeset) {
if(key.equals(attribute))
{
final Object o = changeset.get(key);
final ModelType dmrType = Types.toDMR(o);
modelNode.get(attribute).set(dmrType, o);
final ModelNode node = Types.toDMR(o);
modelNode.get(attribute).set(node);
break;
}
}
Expand Down Expand Up @@ -200,12 +191,12 @@ private FXTemplate getCurrentTemplate()
return this.currentTemplate;
}

public void setModelSteps(FXTemplate template, List<FXModel> models) {
public void setTemplate(FXTemplate template) {
this.currentTemplate = template;

this.headline.setText("Models: Template '"+template.getName()+"'");
dataProvider.getList().clear();
dataProvider.getList().addAll(models);
dataProvider.getList().addAll(template.getModels());
dataProvider.flush();
table.selectDefaultEntity();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public List<FXModel> getModels() {
public static FXTemplate fromBase64(String encoded) {

ModelNode modelNode = ModelNode.fromBase64(encoded);
return fromModelNode(modelNode);
}

public static FXTemplate fromModelNode(ModelNode modelNode)
{
final String name = modelNode.get("name").asString();
final String id = modelNode.get("id").asString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
import org.jboss.as.console.client.shared.viewframework.builder.MultipleToOneLayout;
import org.jboss.as.console.client.widgets.pages.PagedView;
import org.jboss.as.console.client.widgets.tables.TextLinkCell;
import org.jboss.ballroom.client.widgets.forms.Form;
import org.jboss.ballroom.client.widgets.forms.TextBoxItem;
import org.jboss.ballroom.client.widgets.forms.TextAreaItem;
import org.jboss.ballroom.client.widgets.forms.TextItem;
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 java.util.Map;
import java.util.Set;

/**
Expand Down Expand Up @@ -63,13 +64,6 @@ public Object getKey(FXTemplate fxTemplate) {
final SingleSelectionModel<FXTemplate> selectionModel = new SingleSelectionModel<FXTemplate>();
table.setSelectionModel(selectionModel);

TextColumn<FXTemplate> idCol = new TextColumn<FXTemplate>() {
@Override
public String getValue(FXTemplate fxTemplate) {
return fxTemplate.getId();
}

};

TextColumn<FXTemplate> nameCol = new TextColumn<FXTemplate>() {
@Override
Expand All @@ -78,17 +72,16 @@ public String getValue(FXTemplate fxTemplate) {
}
};

table.addColumn(idCol, "ID");
table.addColumn(nameCol, "Name");

Column<FXTemplate, FXTemplate> option = new Column<FXTemplate, FXTemplate>(
new TextLinkCell<FXTemplate>(Console.CONSTANTS.common_label_view(),
new ActionCell.Delegate<FXTemplate>() {
@Override
public void execute(FXTemplate selection) {
pages.showPage(1);
}
})
@Override
public void execute(FXTemplate selection) {
pages.showPage(1);
}
})
) {

@Override
Expand Down Expand Up @@ -120,9 +113,9 @@ public void onClick(ClickEvent clickEvent) {
toolstrip.addToolButtonRight(removeBtn);


final Form<Object> form = new Form(Object.class);
final SimpleForm form = new SimpleForm();
final TextItem id = new TextItem("id", "ID");
final TextBoxItem name = new TextBoxItem("name", "Name", true);
final TextAreaItem name = new TextAreaItem("name", "Name", true);
form.setFields(id, name);

modelStepView = new FXModelsView();
Expand All @@ -135,16 +128,46 @@ public void onSelectionChange(SelectionChangeEvent selectionChangeEvent) {

if(template!=null)
{
id.setValue(template.getId());
name.setValue(template.getName());
form.edit(template.asModelNode());

// update the model step views
modelStepView.setModelSteps(template, template.getModels());
modelStepView.setTemplate(template);
}
}
});

SimpleFormToolStrip formTools = new SimpleFormToolStrip(form, new SimpleFormToolStrip.FormCallback() {
@Override
public void onSave(Map<String, Object> changeset) {

final FXTemplate template = selectionModel.getSelectedObject();
final ModelNode modelNode = template.asModelNode();
for(String key : changeset.keySet())
{
for(String attribute : modelNode.keys())
{
if(key.equals(attribute))
{
final Object o = changeset.get(key);
final ModelNode node = Types.toDMR(o);
modelNode.get(attribute).set(node);
break;
}
}
}

presenter.onUpdateTemplate(FXTemplate.fromModelNode(modelNode));
}

@Override
public void onDelete(Object entity) {

}
}) ;

VerticalPanel formLayout = new VerticalPanel();
formLayout.setStyleName("fill-layout-width");
formLayout.add(formTools.asWidget());
formLayout.add(form.asWidget());

MultipleToOneLayout layout = new MultipleToOneLayout()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ Widget asWidget() {
VerticalPanel layout = new VerticalPanel();
layout.addStyleName("window-content");

final Form<Object> form = new Form(Object.class);
final SimpleForm form = new SimpleForm();
form.setEnabled(true);

final TextBoxItem name = new TextBoxItem("name", "Name", true);
final TextAreaItem name = new TextAreaItem("name", "Name", true);
final TextAreaItem address = new TextAreaItem("address", "Address", true);
final ComboBoxItem type = new ComboBoxItem("execType", "ExecType")
{
Expand All @@ -45,7 +46,6 @@ public boolean isRequired() {
}
};


type.setValueMap(new String[] {
FXModel.ExecutionType.CREATE.name(),
FXModel.ExecutionType.UPDATE.name(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.jboss.ballroom.client.widgets.forms.GroupRenderer;
import org.jboss.ballroom.client.widgets.forms.PlainFormView;
import org.jboss.ballroom.client.widgets.forms.RenderMetaData;
import org.jboss.dmr.client.ModelNode;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -26,26 +27,28 @@ public class SimpleForm {
private int numColumns = 1;
private List<PlainFormView> plainViews = new ArrayList<PlainFormView>();
private boolean enabled;
private Map<String, Object> snapshot;
private ModelNode snapshot;

public void setFields(FormItem... fields)
{
for(FormItem item : fields)
items.add(item);
}

public void edit(Map<String, Object> values)
public void edit(ModelNode values)
{
System.out.println("Edit "+values);

this.snapshot = values;

for(String key : values.keySet())
for(String key : values.keys())
{
for(FormItem item : items)
{
if(item.getName().equals(key))
{
item.resetMetaData();
final Object value = values.get(key);
final Object value = Types.fromDmr(values.get(key));

if(value!=null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @author Heiko Braun
* @date 9/19/11
*/
public class FXFormToolStrip {
public class SimpleFormToolStrip {

private SimpleForm form = null;
private FormCallback callback;
Expand All @@ -38,12 +38,12 @@ public interface PreValidation {
}


public FXFormToolStrip(SimpleForm form, FormCallback callback) {
public SimpleFormToolStrip(SimpleForm form, FormCallback callback) {
this.form = form;
this.callback = callback;
}

public FXFormToolStrip(SimpleForm form, FormCallback callback, String deleteOpName) {
public SimpleFormToolStrip(SimpleForm form, FormCallback callback, String deleteOpName) {
this.form = form;
this.callback = callback;
this.deleteOpName = deleteOpName;
Expand Down
Loading

0 comments on commit 462dbcb

Please sign in to comment.