use of org.jaffa.presentation.portlet.widgets.controller.usergriddomain.UserGridColumnSettings in project jaffa-framework by jaffa-projects.
the class GridController method updateModel.
/**
* Updates the model with the input value.
* This will throw the XmlStructureRuntimeException, in case the input is not well-formed.
* @param value The new value for the model.
* @param model The model to be updated.
*/
public static void updateModel(String value, GridModel model) {
try {
String user = null;
String gridId = null;
String tableWidth = null;
List listSettings = new ArrayList();
// get the root element for the input XML
Element root = getRootElement(value);
// iterate through each element in the Grid, and update there model
for (Iterator it = root.getChildren(XML_WIDGET).iterator(); it.hasNext(); ) {
Element element = (Element) it.next();
int rowId = Integer.parseInt(element.getAttribute(XML_ROW).getValue());
String field = element.getAttribute(XML_FIELD).getValue();
String contents = getContents(element);
GridModelRow row = model.getRowById(rowId);
Object innerModel = row.get(field);
if (innerModel != null) {
interpretAndUpdateModel(contents, innerModel);
}
}
// Gets the Setting info posted from the JSP
// This is only posted when the Grid's Layout is being modified
Element element = root.getChild(XML_SETTINGS);
if (element != null) {
// no longer expect the user to be passed as this could be spoofed, get it from the security manager
if (SecurityManager.getPrincipal() != null) {
user = SecurityManager.getPrincipal().getName();
} else {
// Error can't save settings if no user is set
log.error(" Can't save user settings: User unknown or not set by SecurityManager.");
model.setErrorInSavingUserSettings(true);
return;
}
gridId = element.getChildText(XML_GRIDID);
log.debug("Grid id=" + gridId + " for user=" + user + " is being modified");
// This means delete there customized version
if (element.getChild(XML_RESTORE) != null) {
// Delete custom settings
model.setErrorInSavingUserSettings(!UserGridManager.restore(user, gridId));
log.debug("Grid id=" + gridId + " for user=" + user + " has been reset to the default");
} else {
tableWidth = element.getChildText(XML_TABLEWIDTH);
// create an ObjectFactory instance.
ObjectFactory objFactory = new ObjectFactory();
UserGridSettings thing = objFactory.createUserGridSettings();
List cols = thing.getUserGridColumnSettings();
// And passes that list to the UserGridManager setColSettings()
if (log.isDebugEnabled()) {
log.debug("Saving Grid Column Listing for User=" + user + ", GridId=" + gridId);
}
for (Iterator it = element.getChildren(XML_COLUMN).iterator(); it.hasNext(); ) {
Element column = (Element) it.next();
String name = column.getAttribute(XML_NAME).getValue();
String width = column.getAttribute(XML_WIDTH).getValue();
UserGridColumnSettings thing2 = objFactory.createUserGridColumnSettings();
thing2.setName(name);
thing2.setWidth(width);
cols.add(thing2);
if (log.isDebugEnabled()) {
log.debug(" show column = " + name + ", width=" + width);
}
}
// Sets the value of the Outer Table Width
thing.setGridWidth(tableWidth);
// Save settings to xml file
// Raise the error flag in the model, in case the 'save' fails
// The UserGridTag will raise an Error, in case the error-flag is set, and then reset the error-flag
model.setErrorInSavingUserSettings(!UserGridManager.setColSettings(user, gridId, thing));
}
// See if the user whats to toggle the popup hints.
String hints = element.getChildText(XML_HINTS);
if (hints != null) {
try {
log.debug("Current Rule " + GridTag.RULE_USERGRID_POPUP + " = " + ContextManagerFactory.instance().getProperty(GridTag.RULE_USERGRID_POPUP));
ContextManagerFactory.instance().setUserPreference(GridTag.RULE_USERGRID_POPUP, hints);
log.debug("New Rule " + GridTag.RULE_USERGRID_POPUP + " = " + ContextManagerFactory.instance().getProperty(GridTag.RULE_USERGRID_POPUP));
} catch (IOException e) {
log.error("Failed to changed user preferences for " + GridTag.RULE_USERGRID_POPUP, e);
}
}
}
// Process any state related to the Tree Widget
for (Iterator it = root.getChildren(XML_DISPLAY).iterator(); it.hasNext(); ) {
Element data = (Element) it.next();
int rowId = Integer.parseInt(data.getAttribute(XML_ROW).getValue());
Boolean expanded = new Boolean(data.getAttribute(XML_EXPANDED).getValue());
String contents = getContents(data);
GridModelRow row = model.getRow(rowId);
row.addElement("isDisplayed", new Boolean(contents));
row.addElement("isExpanded", expanded);
}
} catch (Exception e) {
log.error("Failed to create Java content objects for marshalling into XML", e);
model.setErrorInSavingUserSettings(true);
}
}
use of org.jaffa.presentation.portlet.widgets.controller.usergriddomain.UserGridColumnSettings in project jaffa-framework by jaffa-projects.
the class UserGridManager method getColSettings.
/**
* Unmarshalls any user grid settings file (stored in XML) for the current user
* configuration of this grid. Returns a null value if no file found.
* <p>
* In the event that the xml file is not found a default UserGrid file will
* be loaded form a property configuration file like...
* <@properties>/user/UGW_(uniqueID).xml
* or default file
* <@properties>/DEFAULT/UGW_(uniqueID).xml
* @param userId user ID
* @param userGridId unique ID of the grid
* @return All the coumn names in an ordered list for display on the screen
*/
public List getColSettings(String userId, String userGridId) {
// load xml if not loaded
if (m_settings == null) {
loadXML(userId, userGridId);
if (m_settings == null) {
return null;
}
}
// We now have the user settings object, build the LinkedHash Of UserSettings to return...
List l = m_settings.getUserGridColumnSettings();
if (l == null || l.size() == 0) {
return null;
}
List userSettings = new ArrayList();
if (log.isDebugEnabled()) {
log.debug("Loading Grid Column Listing for User=" + userId + ", GridId=" + userGridId);
}
for (Iterator itr = l.iterator(); itr.hasNext(); ) {
UserGridColumnSettings columnSetting = (UserGridColumnSettings) itr.next();
userSettings.add(columnSetting.getName());
if (log.isDebugEnabled()) {
log.debug(" show column = " + columnSetting.getName());
}
}
return userSettings;
}
Aggregations