use of org.jaffa.presentation.portlet.widgets.model.GridModelRow in project jaffa-framework by jaffa-projects.
the class PropertyEditorHelper method getPropertiesWM.
/**
* Convert a property string into a grid model, if the model is already
* being cached on the form, it returns the cached version. If it was not cached
* it is added to the cache after it has been create.
* <p>
* <b>NOTE: if the model is cached and this method is called with a 'new' source
* string, it will only return the current cached version, not a new grid based
* on the new source string. If you want this, clear the model cache prior to calling
* this method
* </b>
* @param form the form object that will contains this model
* @param cacheName the name being used by the form to cache this model
* @param source the source string containing the property data
* @return the converted grid model
*/
public static GridModel getPropertiesWM(FormBase form, String cacheName, String source) {
GridModel model = (GridModel) form.getWidgetCache().getModel(cacheName);
if (model == null) {
model = new GridModel();
ListProperties p = new ListProperties();
try {
if (source != null)
p.load(new ByteArrayInputStream(source.getBytes()));
for (Enumeration e = p.keys(); e.hasMoreElements(); ) {
String key = (String) e.nextElement();
String value = (String) p.getProperty(key);
String comment = (String) p.getComments(key);
GridModelRow row = model.newRow();
row.addElement(KEY, new EditBoxModel(key == null ? EMPTY : key));
row.addElement(VALUE, new EditBoxModel(value == null ? EMPTY : value));
row.addElement(COMMENT, new EditBoxModel(comment == null ? EMPTY : value));
}
form.getWidgetCache().addModel(cacheName, model);
} catch (IOException e) {
log.error("Failed to Load Properties For Field : " + cacheName, e);
}
}
return model;
}
use of org.jaffa.presentation.portlet.widgets.model.GridModelRow in project jaffa-framework by jaffa-projects.
the class PropertyEditorHelper method getProperties.
/**
* Convert the user grid back to a string format
* @param model User grid model that contains the property entries
* @return the formated string, including a date time stamp.
* Returns a null string if there are no rows.
*/
public static String getProperties(GridModel model) {
if (model == null || model.getRows() == null || model.getRows().size() == 0)
return null;
ListProperties p = new ListProperties();
for (Iterator i = model.getRows().iterator(); i.hasNext(); ) {
GridModelRow row = (GridModelRow) i.next();
EditBoxModel e = (EditBoxModel) row.get(KEY);
String key = (String) (e == null ? null : e.getValue());
e = (EditBoxModel) row.get(VALUE);
String value = (String) (e == null ? null : e.getValue());
e = (EditBoxModel) row.get(COMMENT);
String comment = (String) (e == null ? null : e.getValue());
if ((key != null && key.length() > 0) || (value != null && value.length() > 0)) {
log.debug("Save Prop '" + (key == null ? "null" : key + "[" + key.length() + "]") + "=" + (value == null ? "null" : value + "[" + value.length() + "]") + "'");
p.setProperty(key, value, comment);
}
}
try {
ByteArrayOutputStream b = new ByteArrayOutputStream();
p.store(b, null);
b.close();
return b.toString();
} catch (IOException e) {
log.error("Failed to Store Field Properties", e);
return null;
}
}
use of org.jaffa.presentation.portlet.widgets.model.GridModelRow in project jaffa-framework by jaffa-projects.
the class LookupAction method do_MultiSelect_Clicked.
/**
* This will generate the MultiSelectLookupEvent object comprising the DTOs for the selected rows.
* It will then invoke the performMultiSelectLookup() method on the component.
* @return The FormKey for the calling screen.
*/
public FormKey do_MultiSelect_Clicked() {
FormKey fk = null;
LookupForm myForm = (LookupForm) form;
LookupComponent2 myComp = (LookupComponent2) myForm.getComponent();
try {
// Create a collection of 'selectedRows'
// It will assume that each row in the GridModel in the form has a CheckBoxModel keyed by LookupComponent2.MULTI_SELECT_CHECKBOX
// Additionally, it'll assume that the FinderOutDto returned by the component has the method: 'public SomeDtoClass getRows(int i)'
Collection selectedRows = new LinkedList();
GridModel model = myForm.getRowsWM();
Object finderOutDto = myComp.getFinderOutDto();
if (finderOutDto != null && model != null && model.getRows() != null) {
Class finderOutDtoClass = finderOutDto.getClass();
Method method = finderOutDtoClass.getMethod("getRows", new Class[] { Integer.TYPE });
for (Iterator itr = model.getRows().iterator(); itr.hasNext(); ) {
GridModelRow row = (GridModelRow) itr.next();
CheckBoxModel checkBoxModel = (CheckBoxModel) row.get(LookupComponent2.MULTI_SELECT_CHECKBOX);
if (checkBoxModel != null && checkBoxModel.getState()) {
Object selectedRow = method.invoke(finderOutDto, new Object[] { new Integer(row.getRowId()) });
selectedRows.add(selectedRow);
}
}
}
MultiSelectLookupEvent event = new MultiSelectLookupEvent(myComp, selectedRows.toArray());
fk = myComp.performMultiSelectLookup(request, event);
} catch (ApplicationExceptions e) {
myForm.raiseError(request, ActionMessages.GLOBAL_MESSAGE, e);
} catch (Exception e) {
log.error(null, e);
myForm.raiseError(request, ActionMessages.GLOBAL_MESSAGE, "error.framework.general");
}
if (fk == null)
fk = myComp.getResultsFormKey();
return fk;
}
use of org.jaffa.presentation.portlet.widgets.model.GridModelRow in project jaffa-framework by jaffa-projects.
the class GridComponent method getGridChildren.
public void getGridChildren(String rowNo, String field, GridForm myForm) {
GridModel w_model1 = (GridModel) myForm.getWidgetCache().getModel(field);
GridModelRow row;
System.out.println("The row number is " + rowNo);
row = w_model1.getRowById(new Integer(rowNo).intValue());
if ((row.getElement("isExpanded") != null) && (Boolean.TRUE.equals((Boolean) row.getElement("isExpanded")))) {
return;
}
row.addElement("isExpanded", new Boolean(true));
row.addElement("isDisplayed", new Boolean(true));
w_model1.setTarget(row);
row = w_model1.newRow(new Integer(rowNo).intValue() + 1);
row.addElement("isDisplayed", new Boolean(true));
row.addElement("isTarget", new Boolean(false));
row.addElement("isParent", new Boolean(false));
row.addElement("level", new Integer(4));
row.addElement("field1", new EditBoxModel("Field91Value"));
row.addElement("field2", new EditBoxModel("Field92Value"));
row.addElement("field3", new DateTimeModel(DateTime.addMonth(new DateTime(), 1)));
row.addElement("field4", new CheckBoxModel(true));
row.addElement("field5", new ImageModel(ImageComponent.getImageBytes("C:\\Sandbox\\Jaffa\\source\\httpunittest\\html\\widgets\\tests\\testimage1_up.gif")));
row.addElement("field6", new DropDownModel("Value3"));
}
use of org.jaffa.presentation.portlet.widgets.model.GridModelRow in project jaffa-framework by jaffa-projects.
the class LookupForm method createNewModel.
private GridModel createNewModel() {
GridModel model = new GridModel();
GridModelRow row;
row = model.newRow();
row.addElement("partNo", "Part1");
row.addElement("segCode", "SC1");
row.addElement("status", "S1");
row.addElement("condition", "C1");
row = model.newRow();
row.addElement("partNo", "Part2");
row.addElement("segCode", "SC2");
row.addElement("status", "S2");
row.addElement("condition", "C2");
row = model.newRow();
row.addElement("partNo", "Part3");
row.addElement("segCode", "SC3");
row.addElement("status", "S3");
row.addElement("condition", "C3");
return model;
}
Aggregations