refactorings on run-as feature

This commit is contained in:
Peter Hormanns 2012-11-02 14:05:41 +01:00
parent 417cfc680f
commit f002ef41f2
5 changed files with 53 additions and 44 deletions

View File

@ -9,6 +9,7 @@ import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.terminal.Sizeable; import com.vaadin.terminal.Sizeable;
import com.vaadin.terminal.ThemeResource; import com.vaadin.terminal.ThemeResource;
import com.vaadin.ui.Button; import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Component; import com.vaadin.ui.Component;
import com.vaadin.ui.Form; import com.vaadin.ui.Form;
import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.HorizontalLayout;
@ -16,7 +17,6 @@ import com.vaadin.ui.Label;
import com.vaadin.ui.Select; import com.vaadin.ui.Select;
import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window; import com.vaadin.ui.Window;
import com.vaadin.ui.Button.ClickEvent;
import de.hsadmin.web.config.ComponentFactory; import de.hsadmin.web.config.ComponentFactory;
import de.hsadmin.web.config.LocaleConfig; import de.hsadmin.web.config.LocaleConfig;
@ -55,15 +55,7 @@ public abstract class AbstractModule implements Module, Serializable {
if (this instanceof SearchAble || this instanceof InsertAble || if (this instanceof SearchAble || this instanceof InsertAble ||
!("USER".equals(application.getLoginUserRole()) || "NONE".equals(application.getLoginUserRole()))) { !("USER".equals(application.getLoginUserRole()) || "NONE".equals(application.getLoginUserRole()))) {
HorizontalLayout toolbar = new HorizontalLayout(); HorizontalLayout toolbar = new HorizontalLayout();
if ("HOSTMASTER".equals(application.getLoginUserRole())) { createRunAsSelect(toolbar);
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"));
}
if (this instanceof InsertAble) { if (this instanceof InsertAble) {
Button btNew = new Button(moduleConfig.getLabel("new")); Button btNew = new Button(moduleConfig.getLabel("new"));
ThemeResource icon = new ThemeResource("../runo/icons/16/document-add.png"); ThemeResource icon = new ThemeResource("../runo/icons/16/document-add.png");
@ -122,24 +114,15 @@ public abstract class AbstractModule implements Module, Serializable {
layout.setExpandRatio(component, 1.0f); 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 = new Select();
selRunAs.setWidth(100.0f, Sizeable.UNITS_PIXELS); selRunAs.setWidth(100.0f, Sizeable.UNITS_PIXELS);
selRunAs.setImmediate(true); selRunAs.setImmediate(true);
selRunAs.setNewItemsAllowed(false); selRunAs.setNewItemsAllowed(true);
selRunAs.setNullSelectionAllowed(false); selRunAs.setNullSelectionAllowed(false);
selRunAs.addItem(application.getLogin()); selRunAs.addItem(application.getLogin());
for (SearchForSelector sel : searchSelector) { for (Object item : application.readSelectRunAsItems()) {
Object custListObj = application.getRemote().callSearch(sel.getModuleName(), new HashMap<String, String>()); selRunAs.addItem(item);
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()));
}
}
}
} }
selRunAs.select(application.getRunAs()); selRunAs.select(application.getRunAs());
selRunAs.setScrollToSelectedItem(true); selRunAs.setScrollToSelectedItem(true);
@ -151,13 +134,10 @@ public abstract class AbstractModule implements Module, Serializable {
application.setRunAs(property.getValue().toString()); application.setRunAs(property.getValue().toString());
} }
}); });
Label lbl = new Label("&nbsp;" + application.getLocaleConfig().getText("runas") + "&nbsp;", Label.CONTENT_XHTML); selRunAs.setDescription(application.getLocaleConfig().getText("runas"));
lbl.setSizeFull();
toolbar.addComponent(lbl);
toolbar.addComponent(selRunAs); toolbar.addComponent(selRunAs);
} }
public void setApplication(MainApplication app) throws HsarwebException { public void setApplication(MainApplication app) throws HsarwebException {
application = app; application = app;
initModule(); initModule();
@ -181,19 +161,4 @@ public abstract class AbstractModule implements Module, Serializable {
@Override @Override
public abstract ModuleConfig getModuleConfig(); 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;
}
}
} }

View 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;
}
}

View File

@ -1,6 +1,8 @@
package de.hsadmin.web; package de.hsadmin.web;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
@ -50,6 +52,7 @@ public class MainApplication extends Application implements HttpServletRequestLi
private String runAs = null; private String runAs = null;
private TabSheet tabSheet; private TabSheet tabSheet;
private Window mainWindow; private Window mainWindow;
private List<Object> runAsList = null;
@Override @Override
@ -224,4 +227,20 @@ public class MainApplication extends Application implements HttpServletRequestLi
} }
} }
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;
}
} }

View File

@ -5,7 +5,7 @@ confirmdelete=confirm delete
save=save save=save
abort=abort abort=abort
new=new new=new
runas=run as runas=<strong>select</strong><br />change user perspective
modules.NONE=de.hsadmin.web.HomeModule modules.NONE=de.hsadmin.web.HomeModule
modules.USER=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 modules.DOM_ADMIN=de.hsadmin.web.DomainReadonlyModule,de.hsadmin.web.EMailAddressModule,de.hsadmin.web.HomeModule

View File

@ -5,4 +5,4 @@ confirmdelete=Diesen Eintrag l
save=speichern save=speichern
abort=abbrechen abort=abbrechen
new=Eintrag anlegen new=Eintrag anlegen
runas=als Benutzer runas=<strong>Auswahl/Eingabe:</strong><br />zur Ansicht eines anderen<br />Benutzers wechseln