new edit widget pacprefixed-name

This commit is contained in:
Peter Hormanns 2012-12-18 13:26:59 +01:00
parent 9c4eca45ce
commit 7449f9f6f6
9 changed files with 126 additions and 35 deletions

View File

@ -9,6 +9,7 @@ import de.hsadmin.web.config.PropertyConfig;
import de.hsadmin.web.config.PropertyDefaultValue; import de.hsadmin.web.config.PropertyDefaultValue;
import de.hsadmin.web.config.PropertySelectValues; import de.hsadmin.web.config.PropertySelectValues;
import de.hsadmin.web.config.PropertyTableColumn; import de.hsadmin.web.config.PropertyTableColumn;
import de.hsadmin.web.vaadin.PacPrefixedNamePropertyFieldFactory;
import de.hsadmin.web.vaadin.PasswordPropertyFieldFactory; import de.hsadmin.web.vaadin.PasswordPropertyFieldFactory;
import de.hsadmin.web.vaadin.SelectPropertyFieldFactory; import de.hsadmin.web.vaadin.SelectPropertyFieldFactory;
@ -22,10 +23,12 @@ public class UnixUserModule extends GenericModule {
protected void initModule() { protected void initModule() {
MainApplication application = getApplication(); MainApplication application = getApplication();
moduleConfig = new ModuleConfig("user", application.getLocale()); moduleConfig = new ModuleConfig("user", application.getLocale());
String login = application.getRunAs(); PropertyConfig idProp = new PropertyConfig(moduleConfig, "id", Long.class, PropertyTableColumn.INTERNAL_KEY);
final String pac = login.length() >= 5 ? login.substring(0, 5) : ""; idProp.setReadOnly(true);
PropertyConfig pacProp = new PropertyConfig(moduleConfig, "pac", String.class, PropertyTableColumn.HIDDEN, new SelectPropertyFieldFactory()); PropertyConfig useridProp = new PropertyConfig(moduleConfig, "userid", Long.class, PropertyTableColumn.HIDDEN);
pacProp.setSelectValues(new PropertySelectValues() { useridProp.setReadOnly(true);
PropertyConfig nameProp = new PropertyConfig(moduleConfig, "name", String.class, new PacPrefixedNamePropertyFieldFactory(this));
nameProp.setSelectValues(new PropertySelectValues() {
@Override @Override
public boolean newItemsAllowed() { public boolean newItemsAllowed() {
return false; return false;
@ -34,6 +37,7 @@ public class UnixUserModule extends GenericModule {
public boolean hasSelectList() { public boolean hasSelectList() {
return true; return true;
} }
@Override @Override
public Map<String, String> getSelectValues() { public Map<String, String> getSelectValues() {
List<String> list = getPackets(); List<String> list = getPackets();
@ -44,28 +48,7 @@ public class UnixUserModule extends GenericModule {
return map; return map;
} }
}); });
pacProp.setDefaultValue(new PropertyDefaultValue() {
@Override
public String getDefaultValue() {
return pac;
}
});
pacProp.setWriteOnce(true);
PropertyConfig idProp = new PropertyConfig(moduleConfig, "id", Long.class, PropertyTableColumn.INTERNAL_KEY);
idProp.setReadOnly(true);
PropertyConfig useridProp = new PropertyConfig(moduleConfig, "userid", Long.class, PropertyTableColumn.HIDDEN);
useridProp.setReadOnly(true);
PropertyConfig nameProp = new PropertyConfig(moduleConfig, "name", String.class);
nameProp.setWriteOnce(true); nameProp.setWriteOnce(true);
nameProp.setDefaultValue(new PropertyDefaultValue() {
@Override
public String getDefaultValue() {
if (pac.length() > 0) {
return pac + "-";
}
return "";
}
});
PropertyConfig passwordProp = new PropertyConfig(moduleConfig, "password", String.class, PropertyTableColumn.NONE, new PasswordPropertyFieldFactory(this)); PropertyConfig passwordProp = new PropertyConfig(moduleConfig, "password", String.class, PropertyTableColumn.NONE, new PasswordPropertyFieldFactory(this));
PropertyConfig commentProp = new PropertyConfig(moduleConfig, "comment", String.class); PropertyConfig commentProp = new PropertyConfig(moduleConfig, "comment", String.class);
commentProp.setExpandRatio(0.7f); commentProp.setExpandRatio(0.7f);
@ -116,10 +99,8 @@ public class UnixUserModule extends GenericModule {
return "0"; return "0";
} }
}); });
pacProp.setShowInForm(false);
idProp.setShowInForm(false); idProp.setShowInForm(false);
useridProp.setShowInForm(false); useridProp.setShowInForm(false);
moduleConfig.addProperty(pacProp);
moduleConfig.addProperty(idProp); moduleConfig.addProperty(idProp);
moduleConfig.addProperty(useridProp); moduleConfig.addProperty(useridProp);
moduleConfig.addProperty(nameProp); moduleConfig.addProperty(nameProp);

View File

@ -1,11 +1,14 @@
package de.hsadmin.web.config; package de.hsadmin.web.config;
import java.io.Serializable;
import java.util.Locale; import java.util.Locale;
import java.util.ResourceBundle; import java.util.ResourceBundle;
public class LocaleConfig { public class LocaleConfig implements Serializable {
private ResourceBundle bundle; private static final long serialVersionUID = 1L;
private final ResourceBundle bundle;
public LocaleConfig(Locale locale, String moduleName) { public LocaleConfig(Locale locale, String moduleName) {
bundle = ResourceBundle.getBundle("texts." + moduleName, locale); bundle = ResourceBundle.getBundle("texts." + moduleName, locale);

View File

@ -89,8 +89,9 @@ public class GenericForm {
f.setData(entityId); f.setData(entityId);
Layout layout = f.getLayout(); Layout layout = f.getLayout();
for (PropertyConfig prop : config.getPropertyList()) { for (PropertyConfig prop : config.getPropertyList()) {
if (prop.getPropFieldFactory().getClass().equals(DefaultPropertyFieldFactory.class) if (( DefaultPropertyFieldFactory.class.equals(prop.getPropFieldFactory().getClass()) ||
&& prop.getPropTableColumn().equals(PropertyTableColumn.DISPLAY)) { PacPrefixedNamePropertyFieldFactory.class.equals(prop.getPropFieldFactory().getClass()))
&& prop.getPropTableColumn().equals(PropertyTableColumn.DISPLAY)) {
PropertyFieldFactory propFieldFactory = prop.getPropFieldFactory(); PropertyFieldFactory propFieldFactory = prop.getPropFieldFactory();
Object value = row.get(prop.getId()); Object value = row.get(prop.getId());
Component component = (Component) propFieldFactory.createFieldComponent(prop, value); Component component = (Component) propFieldFactory.createFieldComponent(prop, value);

View File

@ -0,0 +1,100 @@
package de.hsadmin.web.vaadin;
import java.util.Map;
import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Select;
import com.vaadin.ui.TextField;
import de.hsadmin.web.HsarwebException;
import de.hsadmin.web.Module;
import de.hsadmin.web.config.ModuleConfig;
import de.hsadmin.web.config.PropertyConfig;
import de.hsadmin.web.config.PropertyFieldFactory;
public class PacPrefixedNamePropertyFieldFactory implements PropertyFieldFactory {
final private Module module;
private boolean readOnly = false;
private boolean writeOnce = false;
public PacPrefixedNamePropertyFieldFactory(Module module) {
this.module = module;
}
@Override
public Object createFieldComponent(PropertyConfig prop, Object value) {
ModuleConfig config = module.getModuleConfig();
HorizontalLayout layout = new HorizontalLayout();
layout.setCaption(prop.getLabel());
layout.setData(prop.getId());
Select sel = new Select(config.getLabel(prop.getId() + ".pacprefix"));
sel.setData(prop.getId());
sel.setNullSelectionAllowed(false);
sel.setNewItemsAllowed(prop.newItemsAllowed());
Map<String, String> selectValues = prop.getSelectValues();
for (Object key : selectValues.keySet()) {
sel.addItem(key);
sel.setItemCaption(key, selectValues.get(key));
}
sel.setWidth(80.0f, Sizeable.UNITS_PIXELS);
sel.setInvalidAllowed(prop.newItemsAllowed());
layout.addComponent(sel);
TextField separator = new TextField(" ", config.getLabel(prop.getId() + ".separator"));
separator.setWidth(18.0f, Sizeable.UNITS_PIXELS);
separator.setReadOnly(true);
layout.addComponent(separator);
TextField tf = new TextField(config.getLabel(prop.getId() + ".postfix"));
tf.setData(prop.getId());
tf.setWidth(384.0f, Sizeable.UNITS_PIXELS);
layout.addComponent(tf);
String valueOrDefault = (value != null && value instanceof String) ? ((String) value) : prop.getDefaultValue();
if (valueOrDefault.length() >= 5) {
sel.setValue(valueOrDefault.substring(0, 5));
tf.setValue(valueOrDefault.length() > 6 ? valueOrDefault.substring(6) : "");
sel.setReadOnly(readOnly || writeOnce);
tf.setReadOnly(readOnly || writeOnce);
} else {
sel.setReadOnly(readOnly);
tf.setReadOnly(readOnly);
}
return layout;
}
@Override
public String 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;
}
@Override
public void setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
}
@Override
public boolean isReadOnly() {
return readOnly;
}
@Override
public void setWriteOnce(boolean writeOnce) {
this.writeOnce = writeOnce;
}
@Override
public boolean isWriteOnce() {
return writeOnce;
}
}

View File

@ -12,7 +12,8 @@ import de.hsadmin.web.config.PropertyFieldFactory;
public class PasswordPropertyFieldFactory implements PropertyFieldFactory { public class PasswordPropertyFieldFactory implements PropertyFieldFactory {
private Module module; final private Module module;
private boolean readOnly = false; private boolean readOnly = false;
private boolean writeOnce = false; private boolean writeOnce = false;

View File

@ -11,7 +11,6 @@ pac=Paket
moduletitle=Passwort moduletitle=Passwort
moduleicon=../runo/icons/16/lock.png moduleicon=../runo/icons/16/lock.png
change_password_icon=../runo/icons/16/lock.png change_password_icon=../runo/icons/16/lock.png
hello=Hallo Welt!
change_password=Passwort ändern change_password=Passwort ändern
update=Passwort ändern update=Passwort ändern
save=Passwort speichern save=Passwort speichern

View File

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

View File

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