From 6abee84d814892339fc4f1e76e38851144608e4c Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Tue, 22 Mar 2011 22:03:07 +0000 Subject: [PATCH] Paket selektierbar --- .../src/de/hsadmin/web/EMailAliasModule.java | 54 +++++++++++++++- .../src/de/hsadmin/web/UnixUserModule.java | 61 ++++++++++++++++--- .../de/hsadmin/web/vaadin/GenericForm.java | 14 +++-- 3 files changed, 111 insertions(+), 18 deletions(-) diff --git a/hsarweb/src/de/hsadmin/web/EMailAliasModule.java b/hsarweb/src/de/hsadmin/web/EMailAliasModule.java index a7f14f9..c2708eb 100644 --- a/hsarweb/src/de/hsadmin/web/EMailAliasModule.java +++ b/hsarweb/src/de/hsadmin/web/EMailAliasModule.java @@ -1,9 +1,17 @@ package de.hsadmin.web; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +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.SelectPropertyFieldFactory; public class EMailAliasModule extends GenericModule { @@ -39,18 +47,37 @@ public class EMailAliasModule extends GenericModule { return ""; } }); - PropertyConfig pacProp = new PropertyConfig(moduleConfig, "pac", String.class, PropertyTableColumn.HIDDEN); + PropertyConfig pacProp = new PropertyConfig(moduleConfig, "pac", String.class, PropertyTableColumn.HIDDEN, new SelectPropertyFieldFactory()); pacProp.setDefaultValue(new PropertyDefaultValue() { @Override public String getDefaultValue() { return pac; } }); - pacProp.setReadOnly(true); + pacProp.setSelectValues(new PropertySelectValues() { + @Override + public boolean newItemsAllowed() { + return false; + } + @Override + public boolean hasSelectList() { + return true; + } + @Override + public Map getSelectValues() { + List list = getPackets(); + TreeMap map = new TreeMap(); + for (String pac : list) { + map.put(pac, pac); + } + return map; + } + }); + pacProp.setWriteOnce(true); moduleConfig.addProperty(idProp); + moduleConfig.addProperty(pacProp); moduleConfig.addProperty(nameProp); moduleConfig.addProperty(targetProp); - moduleConfig.addProperty(pacProp); } @Override @@ -58,4 +85,25 @@ public class EMailAliasModule extends GenericModule { return moduleConfig; } + public List getPackets() { + ArrayList list = new ArrayList(); + try { + Object callSearch = getApplication().getRemote().callSearch("pac", new HashMap()); + if (callSearch instanceof Object[]) { + for (Object row : ((Object[])callSearch)) { + if (row instanceof Map) { + Object object = ((Map) row).get("name"); + if (object instanceof String) { + list.add((String) object); + } + } + } + } + } catch (HsarwebException e) { + e.printStackTrace(); + getApplication().showSystemException(e); + } + return list; + } + } diff --git a/hsarweb/src/de/hsadmin/web/UnixUserModule.java b/hsarweb/src/de/hsadmin/web/UnixUserModule.java index f7f1d98..294bc0b 100644 --- a/hsarweb/src/de/hsadmin/web/UnixUserModule.java +++ b/hsarweb/src/de/hsadmin/web/UnixUserModule.java @@ -1,5 +1,8 @@ package de.hsadmin.web; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -22,6 +25,33 @@ public class UnixUserModule extends GenericModule { moduleConfig = new ModuleConfig("user"); String login = getApplication().getLogin(); 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() { + @Override + public boolean newItemsAllowed() { + return false; + } + @Override + public boolean hasSelectList() { + return true; + } + @Override + public Map getSelectValues() { + List list = getPackets(); + TreeMap map = new TreeMap(); + for (String pac : list) { + map.put(pac, pac); + } + 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); @@ -71,14 +101,6 @@ public class UnixUserModule extends GenericModule { }); PropertyConfig homedirProp = new PropertyConfig(moduleConfig, "homedir", String.class, PropertyTableColumn.HIDDEN); homedirProp.setReadOnly(true); - PropertyConfig pacProp = new PropertyConfig(moduleConfig, "pac", String.class, PropertyTableColumn.HIDDEN); - pacProp.setReadOnly(true); - pacProp.setDefaultValue(new PropertyDefaultValue() { - @Override - public String getDefaultValue() { - return pac; - } - }); PropertyConfig softQuotaProp = new PropertyConfig(moduleConfig, "quota_softlimit", Long.class, PropertyTableColumn.HIDDEN); softQuotaProp.setDefaultValue(new PropertyDefaultValue() { @Override @@ -93,6 +115,7 @@ public class UnixUserModule extends GenericModule { return "0"; } }); + moduleConfig.addProperty(pacProp); moduleConfig.addProperty(idProp); moduleConfig.addProperty(useridProp); moduleConfig.addProperty(nameProp); @@ -100,7 +123,6 @@ public class UnixUserModule extends GenericModule { moduleConfig.addProperty(commentProp); moduleConfig.addProperty(shellProp); moduleConfig.addProperty(homedirProp); - moduleConfig.addProperty(pacProp); moduleConfig.addProperty(softQuotaProp); moduleConfig.addProperty(hardQuotaProp); } @@ -110,4 +132,25 @@ public class UnixUserModule extends GenericModule { return moduleConfig; } + public List getPackets() { + ArrayList list = new ArrayList(); + try { + Object callSearch = getApplication().getRemote().callSearch("pac", new HashMap()); + if (callSearch instanceof Object[]) { + for (Object row : ((Object[])callSearch)) { + if (row instanceof Map) { + Object object = ((Map) row).get("name"); + if (object instanceof String) { + list.add((String) object); + } + } + } + } + } catch (HsarwebException e) { + e.printStackTrace(); + getApplication().showSystemException(e); + } + return list; + } + } diff --git a/hsarweb/src/de/hsadmin/web/vaadin/GenericForm.java b/hsarweb/src/de/hsadmin/web/vaadin/GenericForm.java index be0c8ea..cec667a 100644 --- a/hsarweb/src/de/hsadmin/web/vaadin/GenericForm.java +++ b/hsarweb/src/de/hsadmin/web/vaadin/GenericForm.java @@ -56,13 +56,15 @@ public class GenericForm { f.setData(entityId); Layout layout = f.getLayout(); for (PropertyConfig prop : config.getPropertyList()) { - PropertyFieldFactory propFieldFactory = prop.getPropFieldFactory(); - Object value = row.get(prop.getId()); - Component component = (Component) propFieldFactory.createFieldComponent(prop, value); - if (propFieldFactory.isWriteOnce()) { - component.setReadOnly(true); + if (!prop.getPropTableColumn().equals(PropertyTableColumn.INTERNAL_KEY)) { + PropertyFieldFactory propFieldFactory = prop.getPropFieldFactory(); + Object value = row.get(prop.getId()); + Component component = (Component) propFieldFactory.createFieldComponent(prop, value); + if (propFieldFactory.isWriteOnce()) { + component.setReadOnly(true); + } + layout.addComponent(component); } - layout.addComponent(component); } return f; }