merged ArstractProperty, pac-prefix editor everywhere

This commit is contained in:
Peter Hormanns 2012-12-18 16:44:00 +01:00
parent fa9cd9865b
commit d9afe25155
19 changed files with 90 additions and 75 deletions

View File

@ -1,5 +1,7 @@
package de.hsadmin.web;
public class AbstractProperty {
public abstract class AbstractProperty {
public abstract Object toXmlrpcParam();
}

View File

@ -11,6 +11,7 @@ import de.hsadmin.web.config.PropertyConfig;
import de.hsadmin.web.config.PropertyDefaultValue;
import de.hsadmin.web.config.PropertySelectValues;
import de.hsadmin.web.config.PropertyTableColumn;
import de.hsadmin.web.vaadin.PacPrefixedNamePropertyFieldFactory;
import de.hsadmin.web.vaadin.SelectPropertyFieldFactory;
public abstract class DatabaseModule extends GenericModule {
@ -29,29 +30,10 @@ public abstract class DatabaseModule extends GenericModule {
protected void initModule() {
MainApplication application = getApplication();
moduleConfig = new ModuleConfig(getModuleIdent(), application.getLocale());
String login = application.getRunAs();
final String pac = login.length() >= 5 ? login.substring(0, 5) : "";
PropertyConfig idProp = new PropertyConfig(moduleConfig, "id", Long.class, PropertyTableColumn.INTERNAL_KEY);
idProp.setReadOnly(true);
PropertyConfig nameProp = new PropertyConfig(moduleConfig, "name", String.class);
nameProp.setDefaultValue(new PropertyDefaultValue() {
@Override
public String getDefaultValue() {
if (pac.length() >= 5) {
return pac + "_";
}
return "";
}
});
nameProp.setWriteOnce(true);
PropertyConfig pacProp = new PropertyConfig(moduleConfig, "pac", String.class, PropertyTableColumn.HIDDEN, new SelectPropertyFieldFactory());
pacProp.setDefaultValue(new PropertyDefaultValue() {
@Override
public String getDefaultValue() {
return pac;
}
});
pacProp.setSelectValues(new PropertySelectValues() {
PropertyConfig nameProp = new PropertyConfig(moduleConfig, "name", String.class, new PacPrefixedNamePropertyFieldFactory(this));
nameProp.setSelectValues(new PropertySelectValues() {
@Override
public boolean newItemsAllowed() {
return false;
@ -70,7 +52,7 @@ public abstract class DatabaseModule extends GenericModule {
return map;
}
});
pacProp.setWriteOnce(true);
nameProp.setWriteOnce(true);
PropertyConfig encodingProp = new PropertyConfig(moduleConfig, "encoding", String.class, new SelectPropertyFieldFactory());
encodingProp.setDefaultValue(new PropertyDefaultValue() {
@Override
@ -125,10 +107,8 @@ public abstract class DatabaseModule extends GenericModule {
}
});
idProp.setShowInForm(false);
pacProp.setShowInForm(false);
encodingProp.setShowInForm(false);
moduleConfig.addProperty(idProp);
moduleConfig.addProperty(pacProp);
moduleConfig.addProperty(nameProp);
moduleConfig.addProperty(encodingProp);
moduleConfig.addProperty(ownerProp);

View File

@ -6,11 +6,10 @@ import java.util.TreeMap;
import de.hsadmin.web.config.ModuleConfig;
import de.hsadmin.web.config.PropertyConfig;
import de.hsadmin.web.config.PropertyDefaultValue;
import de.hsadmin.web.config.PropertySelectValues;
import de.hsadmin.web.config.PropertyTableColumn;
import de.hsadmin.web.vaadin.PacPrefixedNamePropertyFieldFactory;
import de.hsadmin.web.vaadin.PasswordPropertyFieldFactory;
import de.hsadmin.web.vaadin.SelectPropertyFieldFactory;
public abstract class DatabaseUserModule extends GenericModule {
@ -24,29 +23,10 @@ public abstract class DatabaseUserModule extends GenericModule {
protected void initModule() {
MainApplication application = getApplication();
moduleConfig = new ModuleConfig(getModuleIdent(), application.getLocale());
String login = application.getRunAs();
final String pac = login.length() >= 5 ? login.substring(0, 5) : "";
PropertyConfig idProp = new PropertyConfig(moduleConfig, "id", Long.class, PropertyTableColumn.INTERNAL_KEY);
idProp.setReadOnly(true);
PropertyConfig nameProp = new PropertyConfig(moduleConfig, "name", String.class);
nameProp.setDefaultValue(new PropertyDefaultValue() {
@Override
public String getDefaultValue() {
if (pac.length() >= 5) {
return pac + "_";
}
return "";
}
});
nameProp.setWriteOnce(true);
PropertyConfig pacProp = new PropertyConfig(moduleConfig, "pac", String.class, PropertyTableColumn.HIDDEN, new SelectPropertyFieldFactory());
pacProp.setDefaultValue(new PropertyDefaultValue() {
@Override
public String getDefaultValue() {
return pac;
}
});
pacProp.setSelectValues(new PropertySelectValues() {
PropertyConfig nameProp = new PropertyConfig(moduleConfig, "name", String.class, new PacPrefixedNamePropertyFieldFactory(this));
nameProp.setSelectValues(new PropertySelectValues() {
@Override
public boolean newItemsAllowed() {
return false;
@ -65,12 +45,10 @@ public abstract class DatabaseUserModule extends GenericModule {
return map;
}
});
pacProp.setWriteOnce(true);
nameProp.setWriteOnce(true);
PropertyConfig passwordProp = new PropertyConfig(moduleConfig, "password", String.class, PropertyTableColumn.NONE, new PasswordPropertyFieldFactory(this));
idProp.setShowInForm(false);
pacProp.setShowInForm(false);
moduleConfig.addProperty(idProp);
moduleConfig.addProperty(pacProp);
moduleConfig.addProperty(nameProp);
moduleConfig.addProperty(passwordProp);
}

View File

@ -35,8 +35,8 @@ public class HomeModule extends AbstractModule implements ComponentFactory, Upda
setComponentFactory(this);
}
public void updateRow(Map<String, String> paramHash) throws HsarwebException {
Map<String, String> whereHash = new HashMap<String, String>();
public void updateRow(Map<String, AbstractProperty> paramHash) throws HsarwebException {
Map<String, AbstractProperty> whereHash = new HashMap<String, AbstractProperty>();
String idKey = findIdKey();
whereHash.put(idKey, paramHash.get(idKey));
paramHash.remove(idKey);
@ -94,8 +94,8 @@ public class HomeModule extends AbstractModule implements ComponentFactory, Upda
Button button = new Button(moduleConfig.getLabel("change_password"));
ThemeResource icon = new ThemeResource(moduleConfig.getLabel("change_password_icon"));
button.setIcon(icon);
Map<String, String> whereHash = new HashMap<String, String>();
whereHash.put("name", application.getRunAs());
Map<String, AbstractProperty> whereHash = new HashMap<String, AbstractProperty>();
whereHash.put("name", new StringProperty(application.getRunAs()));
Long key = -1L;
try {
Object object = application.getRemote().callSearch(moduleConfig.getRemoteName(), whereHash);
@ -130,8 +130,8 @@ public class HomeModule extends AbstractModule implements ComponentFactory, Upda
public void buttonClick(ClickEvent event) {
application.getMainWindow().removeWindow(childWindow);
try {
Map<String, String> map = new HashMap<String, String>();
map.put("id", ((Long) event.getButton().getData()).toString());
Map<String, AbstractProperty> map = new HashMap<String, AbstractProperty>();
map.put("id", new StringProperty(((Long) event.getButton().getData()).toString()));
Iterator<Component> componentIterator = form.getLayout().getComponentIterator();
while (componentIterator.hasNext()) {
Component component = (Component) componentIterator.next();

View File

@ -9,7 +9,7 @@ public class ItemsReader {
public static List<Object> readItemList(MainApplication app, String module, String property) throws HsarwebException {
final List<Object> itemsList = new ArrayList<Object>();
Object custListObj = app.getRemote().callSearch(module, new HashMap<String, String>());
Object custListObj = app.getRemote().callSearch(module, new HashMap<String, AbstractProperty>());
if (custListObj instanceof Object[]) {
Object[] custList = (Object[]) custListObj;
for (Object custObj : custList) {

View File

@ -1,15 +1,28 @@
package de.hsadmin.web;
import java.util.ArrayList;
import java.util.List;
public class ListOfStringsProperty extends AbstractProperty {
public List<String> properties;
public final List<String> properties;
public ListOfStringsProperty(){
// ?? this.properties = new List<String>();
this.properties = new ArrayList<String>();
}
public boolean Add(String string){
public boolean add(String string){
return properties.add(string);
}
@Override
public Object toXmlrpcParam() {
String[] result = new String[properties.size()];
int idx = 0;
for (String prop : properties) {
result[idx] = prop;
idx++;
}
return result;
}
}

View File

@ -19,35 +19,46 @@ public class Remote {
}
public Object callSearch(String module, Map<String, AbstractProperty> where) throws HsarwebException {
return xmlrpcCall(module, "search", where);
return xmlrpcCall(module, "search", buildXmlrpcParam(where));
}
public void callAdd(String module, Map<String, AbstractProperty> set) throws HsarwebException {
xmlrpcCall(module, "add", set);
xmlrpcCall(module, "add", buildXmlrpcParam(set));
}
public void callUpdate(String module, Map<String, AbstractProperty> set, Map<String, AbstractProperty> where) throws HsarwebException {
xmlrpcCall(module, "update", set, where);
xmlrpcCall(module, "update", buildXmlrpcParam(set), buildXmlrpcParam(where));
}
public void callDelete(String module, Map<String, AbstractProperty> where) throws HsarwebException {
xmlrpcCall(module, "delete", where);
xmlrpcCall(module, "delete", buildXmlrpcParam(where));
}
private Object xmlrpcCall(String module, String operation, Map<String, AbstractProperty> param1) throws HsarwebException {
private Map<String, Object> buildXmlrpcParam(Map<String, AbstractProperty> paramHash) {
Map<String, Object> resultMap = new HashMap<String, Object>();
if (paramHash == null) {
return null;
}
for (String key : paramHash.keySet()) {
resultMap.put(key, paramHash.get(key).toXmlrpcParam());
}
return resultMap;
}
private Object xmlrpcCall(String module, String operation, Map<String, Object> param1) throws HsarwebException {
Object[] params = new Object[3];
params[0] = app.getRunAs();
params[1] = app.getProxyTicket();
params[2] = param1 != null ? param1 : new HashMap<String, String>();
params[2] = param1 != null ? param1 : new HashMap<String, Object>();
return xmlrpcCall(module + "." + operation, params);
}
private Object xmlrpcCall(String module, String operation, Map<String, AbstractProperty> param1, Map<String, AbstractProperty> param2) throws HsarwebException {
private Object xmlrpcCall(String module, String operation, Map<String, Object> param1, Map<String, Object> param2) throws HsarwebException {
Object[] params = new Object[4];
params[0] = app.getRunAs();
params[1] = app.getProxyTicket();
params[2] = param1 != null ? param1 : new HashMap<String, String>();
params[3] = param2 != null ? param2 : new HashMap<String, String>();
params[2] = param1 != null ? param1 : new HashMap<String, Object>();
params[3] = param2 != null ? param2 : new HashMap<String, Object>();
return xmlrpcCall(module + "." + operation, params);
}

View File

@ -1,10 +1,16 @@
package de.hsadmin.web;
public class StringProperty extends AbstractProperty {
public String property ;
public StringProperty(String property) {
this.property = property;
}
@Override
public Object toXmlrpcParam() {
return property;
}
}

View File

@ -37,7 +37,6 @@ public class UnixUserModule extends GenericModule {
public boolean hasSelectList() {
return true;
}
@Override
public Map<String, String> getSelectValues() {
List<String> list = getPackets();

View File

@ -81,8 +81,8 @@ public class GenericForm {
try {
MainApplication application = module.getApplication();
ModuleConfig config = module.getModuleConfig();
Map<String, String> where = new HashMap<String, String>();
where.put(findIdKey(), entityId.toString());
Map<String, AbstractProperty> where = new HashMap<String, AbstractProperty>();
where.put(findIdKey(), new StringProperty(entityId.toString()));
Object searchResult = application.getRemote().callSearch(config.getRemoteName(), where);
if (searchResult instanceof Object[]) {
Map<?, ?> row = (Map<?, ?>) (((Object[]) searchResult)[0]);

View File

@ -7,8 +7,10 @@ import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Select;
import com.vaadin.ui.TextField;
import de.hsadmin.web.AbstractProperty;
import de.hsadmin.web.HsarwebException;
import de.hsadmin.web.Module;
import de.hsadmin.web.StringProperty;
import de.hsadmin.web.config.ModuleConfig;
import de.hsadmin.web.config.PropertyConfig;
import de.hsadmin.web.config.PropertyFieldFactory;
@ -67,14 +69,14 @@ public class PacPrefixedNamePropertyFieldFactory implements PropertyFieldFactory
}
@Override
public String getValue(PropertyConfig prop, Object component) throws HsarwebException {
public AbstractProperty getValue(PropertyConfig prop, Object component) throws HsarwebException {
ModuleConfig config = module.getModuleConfig();
HorizontalLayout layout = (HorizontalLayout) component;
Select sel = (Select) layout.getComponent(0);
TextField tf = (TextField) layout.getComponent(2);
String pacPart = (String) sel.getValue();
String userPart = (String) tf.getValue();
return pacPart + config.getLabel(prop.getId() + ".separator") + userPart;
return new StringProperty(pacPart + config.getLabel(prop.getId() + ".separator") + userPart);
}
@Override

View File

@ -1,5 +1,8 @@
id=identifier
name=database
name.pacprefix=packet
name.separator=_
name.postfix=databasepart
pac=packet
encoding=encoding
owner=owner

View File

@ -1,5 +1,8 @@
id=Schlüssel
name=MySQL Datenbank
name.pacprefix=Paket
name.separator=_
name.postfix=Datenbank-Postfix
pac=Paket
encoding=Zeichensatz
owner=Verwalter

View File

@ -1,5 +1,8 @@
id=identifier
name=database username
name.pacprefix=packet
name.separator=_
name.postfix=userpart
password=password
password1=new password
password2=repeat password

View File

@ -1,5 +1,8 @@
id=Schlüssel
name=MySQL User
name.pacprefix=Paket
name.separator=_
name.postfix=Benutzer-Postfix
password=Passwort
password1=neues Passwort
password2=Passwort-Wiederholung

View File

@ -1,5 +1,8 @@
id=identifier
name=database
name.pacprefix=packet
name.separator=_
name.postfix=databasepart
pac=packet
encoding=encoding
owner=owner

View File

@ -1,5 +1,8 @@
id=Schlüssel
name=Datenbank
name.pacprefix=Paket
name.separator=_
name.postfix=Datenbank-Postfix
pac=Paket
encoding=Zeichensatz
owner=Verwalter

View File

@ -1,5 +1,8 @@
id=identifier
name=postgres username
name.pacprefix=packet
name.separator=_
name.postfix=userpart
password=password
password1=new password
password2=repeat password

View File

@ -1,5 +1,8 @@
id=Schlüssel
name=PostgreSQL User
name.pacprefix=Paket
name.separator=_
name.postfix=Benutzer-Postfix
password=Passwort
password1=neues Passwort
password2=Passwort-Wiederholung