HSAdmin Backend Domains, E-Mail, Datenbanken
Peter Hormanns
2012-11-02 f002ef41f26a1b4141eb610da046b6d66c5079e4
refactorings on run-as feature
4 files modified
1 files added
97 ■■■■ changed files
hsarweb/src/de/hsadmin/web/AbstractModule.java 49 ●●●● patch | view | raw | blame | history
hsarweb/src/de/hsadmin/web/ItemsReader.java 25 ●●●●● patch | view | raw | blame | history
hsarweb/src/de/hsadmin/web/MainApplication.java 19 ●●●●● patch | view | raw | blame | history
hsarweb/src/texts/main.properties 2 ●●● patch | view | raw | blame | history
hsarweb/src/texts/main_de.properties 2 ●●● patch | view | raw | blame | history
hsarweb/src/de/hsadmin/web/AbstractModule.java
@@ -9,6 +9,7 @@
import com.vaadin.terminal.Sizeable;
import com.vaadin.terminal.ThemeResource;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Component;
import com.vaadin.ui.Form;
import com.vaadin.ui.HorizontalLayout;
@@ -16,7 +17,6 @@
import com.vaadin.ui.Select;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.vaadin.ui.Button.ClickEvent;
import de.hsadmin.web.config.ComponentFactory;
import de.hsadmin.web.config.LocaleConfig;
@@ -55,15 +55,7 @@
        if (this instanceof SearchAble || this instanceof InsertAble ||
                !("USER".equals(application.getLoginUserRole()) || "NONE".equals(application.getLoginUserRole()))) {
            HorizontalLayout toolbar = new HorizontalLayout();
            if ("HOSTMASTER".equals(application.getLoginUserRole())) {
                createRunAsSelect(toolbar, new SearchForSelector("member", "membercode"), new SearchForSelector("pac", "name"));
            }
            if ("CUSTOMER".equals(application.getLoginUserRole())) {
                createRunAsSelect(toolbar, new SearchForSelector("pac", "name"));
            }
            if (application.getLoginUserRole().startsWith("PAC")) {
                createRunAsSelect(toolbar, new SearchForSelector("user", "name"));
            }
            createRunAsSelect(toolbar);
            if (this instanceof InsertAble) {
                Button btNew = new Button(moduleConfig.getLabel("new"));
                ThemeResource icon = new ThemeResource("../runo/icons/16/document-add.png");
@@ -122,24 +114,15 @@
        layout.setExpandRatio(component, 1.0f);
    }
    private void createRunAsSelect(HorizontalLayout toolbar, SearchForSelector... searchSelector) throws HsarwebException {
    private void createRunAsSelect(HorizontalLayout toolbar) throws UnsupportedOperationException, HsarwebException {
        selRunAs = new Select();
        selRunAs.setWidth(100.0f, Sizeable.UNITS_PIXELS);
        selRunAs.setImmediate(true);
        selRunAs.setNewItemsAllowed(false);
        selRunAs.setNewItemsAllowed(true);
        selRunAs.setNullSelectionAllowed(false);
        selRunAs.addItem(application.getLogin());
        for (SearchForSelector sel : searchSelector) {
            Object custListObj = application.getRemote().callSearch(sel.getModuleName(), new HashMap<String, String>());
            if (custListObj instanceof Object[]) {
                Object[] custList = (Object[]) custListObj;
                for (Object custObj : custList) {
                    if (custObj instanceof Map<?, ?>) {
                        Map<?, ?> custHash = (Map<?, ?>)custObj;
                        selRunAs.addItem(custHash.get(sel.getPropertyName()));
                    }
                }
            }
        for (Object item : application.readSelectRunAsItems()) {
            selRunAs.addItem(item);
        }
        selRunAs.select(application.getRunAs());
        selRunAs.setScrollToSelectedItem(true);
@@ -151,12 +134,9 @@
                application.setRunAs(property.getValue().toString());
            }
        });
        Label lbl = new Label("&nbsp;" + application.getLocaleConfig().getText("runas") + "&nbsp;", Label.CONTENT_XHTML);
        lbl.setSizeFull();
        toolbar.addComponent(lbl);
        selRunAs.setDescription(application.getLocaleConfig().getText("runas"));
        toolbar.addComponent(selRunAs);
    }
    public void setApplication(MainApplication app) throws HsarwebException {
        application = app;
@@ -180,20 +160,5 @@
    @Override
    public abstract ModuleConfig getModuleConfig();
    private class SearchForSelector {
        private final String moduleName;
        private final String propertyName;
        public SearchForSelector(String module, String property) {
            moduleName = module;
            propertyName = property;
        }
        public String getModuleName() {
            return moduleName;
        }
        public String getPropertyName() {
            return propertyName;
        }
    }
}
hsarweb/src/de/hsadmin/web/ItemsReader.java
New file
@@ -0,0 +1,25 @@
package de.hsadmin.web;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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>());
        if (custListObj instanceof Object[]) {
            Object[] custList = (Object[]) custListObj;
            for (Object custObj : custList) {
                if (custObj instanceof Map<?, ?>) {
                    Map<?, ?> custHash = (Map<?, ?>)custObj;
                    itemsList.add(custHash.get(property));
                }
            }
        }
        return itemsList;
    }
}
hsarweb/src/de/hsadmin/web/MainApplication.java
@@ -1,6 +1,8 @@
package de.hsadmin.web;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -50,6 +52,7 @@
    private String runAs = null;
    private TabSheet tabSheet;
    private Window mainWindow;
    private List<Object> runAsList = null;
    @Override
@@ -224,4 +227,20 @@
        }
    }
    public List<Object> readSelectRunAsItems() throws HsarwebException {
        if (runAsList == null) {
            runAsList = new ArrayList<Object>();
            if ("HOSTMASTER".equals(loginUserRole)) {
                runAsList = ItemsReader.readItemList(this, "member", "membercode");
            }
            if ("CUSTOMER".equals(loginUserRole)) {
                runAsList = ItemsReader.readItemList(this, "pac", "name");
            }
            if (loginUserRole.startsWith("PAC")) {
                runAsList = ItemsReader.readItemList(this, "user", "name");
            }
        }
        return runAsList;
    }
}
hsarweb/src/texts/main.properties
@@ -5,7 +5,7 @@
save=save
abort=abort
new=new
runas=run as
runas=<strong>select</strong><br />change user perspective
modules.NONE=de.hsadmin.web.HomeModule
modules.USER=de.hsadmin.web.HomeModule
modules.DOM_ADMIN=de.hsadmin.web.DomainReadonlyModule,de.hsadmin.web.EMailAddressModule,de.hsadmin.web.HomeModule
hsarweb/src/texts/main_de.properties
@@ -5,4 +5,4 @@
save=speichern
abort=abbrechen
new=Eintrag anlegen
runas=als Benutzer
runas=<strong>Auswahl/Eingabe:</strong><br />zur Ansicht eines anderen<br />Benutzers wechseln