HSAdmin Backend Domains, E-Mail, Datenbanken
Peter Hormanns
2012-12-18 7449f9f6f6af965bb5a1b7abcceaf5d72bc3127f
new edit widget pacprefixed-name
8 files modified
1 files added
161 ■■■■ changed files
hsarweb/src/de/hsadmin/web/UnixUserModule.java 35 ●●●● patch | view | raw | blame | history
hsarweb/src/de/hsadmin/web/config/LocaleConfig.java 7 ●●●● patch | view | raw | blame | history
hsarweb/src/de/hsadmin/web/config/PropertyConfig.java 2 ●●● patch | view | raw | blame | history
hsarweb/src/de/hsadmin/web/vaadin/GenericForm.java 5 ●●●●● patch | view | raw | blame | history
hsarweb/src/de/hsadmin/web/vaadin/PacPrefixedNamePropertyFieldFactory.java 100 ●●●●● patch | view | raw | blame | history
hsarweb/src/de/hsadmin/web/vaadin/PasswordPropertyFieldFactory.java 3 ●●●● patch | view | raw | blame | history
hsarweb/src/texts/home_de.properties 1 ●●●● patch | view | raw | blame | history
hsarweb/src/texts/user.properties 3 ●●●●● patch | view | raw | blame | history
hsarweb/src/texts/user_de.properties 5 ●●●● patch | view | raw | blame | history
hsarweb/src/de/hsadmin/web/UnixUserModule.java
@@ -9,6 +9,7 @@
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;
@@ -22,10 +23,12 @@
    protected void initModule() {
        MainApplication application = getApplication();
        moduleConfig = new ModuleConfig("user", application.getLocale());
        String login = application.getRunAs();
        final String pac = login.length() >= 5 ? login.substring(0, 5) : "";
        PropertyConfig pacProp = new PropertyConfig(moduleConfig, "pac", String.class, PropertyTableColumn.HIDDEN, new SelectPropertyFieldFactory());
        pacProp.setSelectValues(new PropertySelectValues() {
        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, new PacPrefixedNamePropertyFieldFactory(this));
        nameProp.setSelectValues(new PropertySelectValues() {
            @Override
            public boolean newItemsAllowed() {
                return false;
@@ -34,6 +37,7 @@
            public boolean hasSelectList() {
                return true;
            }
            @Override
            public Map<String, String> getSelectValues() {
                List<String> list = getPackets();
@@ -44,28 +48,7 @@
                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.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 commentProp = new PropertyConfig(moduleConfig, "comment", String.class);
        commentProp.setExpandRatio(0.7f);
@@ -116,10 +99,8 @@
                return "0";
            }
        });
        pacProp.setShowInForm(false);
        idProp.setShowInForm(false);
        useridProp.setShowInForm(false);
        moduleConfig.addProperty(pacProp);
        moduleConfig.addProperty(idProp);
        moduleConfig.addProperty(useridProp);
        moduleConfig.addProperty(nameProp);
hsarweb/src/de/hsadmin/web/config/LocaleConfig.java
@@ -1,11 +1,14 @@
package de.hsadmin.web.config;
import java.io.Serializable;
import java.util.Locale;
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) {
        bundle = ResourceBundle.getBundle("texts." + moduleName, locale);
hsarweb/src/de/hsadmin/web/config/PropertyConfig.java
@@ -147,5 +147,5 @@
    public void setExpandRatio(float expandRatio) {
        this.expandRatio = expandRatio;
    }
}
hsarweb/src/de/hsadmin/web/vaadin/GenericForm.java
@@ -89,8 +89,9 @@
                f.setData(entityId);
                Layout layout = f.getLayout();
                for (PropertyConfig prop : config.getPropertyList()) {
                    if (prop.getPropFieldFactory().getClass().equals(DefaultPropertyFieldFactory.class)
                            && prop.getPropTableColumn().equals(PropertyTableColumn.DISPLAY)) {
                    if (( DefaultPropertyFieldFactory.class.equals(prop.getPropFieldFactory().getClass()) ||
                            PacPrefixedNamePropertyFieldFactory.class.equals(prop.getPropFieldFactory().getClass()))
                                && prop.getPropTableColumn().equals(PropertyTableColumn.DISPLAY)) {
                        PropertyFieldFactory propFieldFactory = prop.getPropFieldFactory();
                        Object value = row.get(prop.getId());
                        Component component = (Component) propFieldFactory.createFieldComponent(prop, value);
hsarweb/src/de/hsadmin/web/vaadin/PacPrefixedNamePropertyFieldFactory.java
New 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;
    }
}
hsarweb/src/de/hsadmin/web/vaadin/PasswordPropertyFieldFactory.java
@@ -12,7 +12,8 @@
public class PasswordPropertyFieldFactory implements PropertyFieldFactory {
    private Module module;
    final private Module module;
    private boolean readOnly = false;
    private boolean writeOnce = false;
hsarweb/src/texts/home_de.properties
@@ -11,7 +11,6 @@
moduletitle=Passwort
moduleicon=../runo/icons/16/lock.png
change_password_icon=../runo/icons/16/lock.png
hello=Hallo Welt!
change_password=Passwort ändern
update=Passwort ändern
save=Passwort speichern
hsarweb/src/texts/user.properties
@@ -1,5 +1,8 @@
id=identifier
name=username
name.pacprefix=packet
name.separator=-
name.postfix=userpart
password=password
password1=new password
password2=repeat password
hsarweb/src/texts/user_de.properties
@@ -1,5 +1,8 @@
id=Schlüssel
name=Benutzername
name=Benutzer
name.pacprefix=Paket
name.separator=-
name.postfix=Benutzer-Postfix
password=Passwort
password1=neues Passwort
password2=Passwort-Wiederholung