diff --git a/hsarweb/src/de/hsadmin/web/DomainModule.java b/hsarweb/src/de/hsadmin/web/DomainModule.java index 19089f3..4083317 100644 --- a/hsarweb/src/de/hsadmin/web/DomainModule.java +++ b/hsarweb/src/de/hsadmin/web/DomainModule.java @@ -1,8 +1,6 @@ package de.hsadmin.web; -import java.util.ArrayList; import java.util.Date; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -81,25 +79,4 @@ public class DomainModule extends GenericModule { return moduleConfig; } - public List getUsers() { - ArrayList list = new ArrayList(); - try { - Object callSearch = getApplication().getRemote().callSearch("user", 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/EMailAddressModule.java b/hsarweb/src/de/hsadmin/web/EMailAddressModule.java index 9cd100e..e52bd84 100644 --- a/hsarweb/src/de/hsadmin/web/EMailAddressModule.java +++ b/hsarweb/src/de/hsadmin/web/EMailAddressModule.java @@ -1,7 +1,5 @@ package de.hsadmin.web; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -11,6 +9,7 @@ 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.EMailTargetPropertyFieldFactory; import de.hsadmin.web.vaadin.SelectPropertyFieldFactory; public class EMailAddressModule extends GenericModule { @@ -53,7 +52,7 @@ public class EMailAddressModule extends GenericModule { } }); domainProp.setWriteOnce(true); - PropertyConfig targetProp = new PropertyConfig(moduleConfig, "target", String.class); + PropertyConfig targetProp = new PropertyConfig(moduleConfig, "target", String.class, new EMailTargetPropertyFieldFactory(this)); targetProp.setDefaultValue(new PropertyDefaultValue() { @Override public String getDefaultValue() { @@ -82,25 +81,4 @@ public class EMailAddressModule extends GenericModule { return moduleConfig; } - public List getDomains() { - ArrayList list = new ArrayList(); - try { - Object callSearch = getApplication().getRemote().callSearch("domain", 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/EMailAliasModule.java b/hsarweb/src/de/hsadmin/web/EMailAliasModule.java index c2708eb..d893e48 100644 --- a/hsarweb/src/de/hsadmin/web/EMailAliasModule.java +++ b/hsarweb/src/de/hsadmin/web/EMailAliasModule.java @@ -1,7 +1,5 @@ package de.hsadmin.web; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -11,6 +9,7 @@ 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.EMailTargetPropertyFieldFactory; import de.hsadmin.web.vaadin.SelectPropertyFieldFactory; public class EMailAliasModule extends GenericModule { @@ -37,7 +36,7 @@ public class EMailAliasModule extends GenericModule { } }); nameProp.setWriteOnce(true); - PropertyConfig targetProp = new PropertyConfig(moduleConfig, "target", String.class); + PropertyConfig targetProp = new PropertyConfig(moduleConfig, "target", String.class, new EMailTargetPropertyFieldFactory(this)); targetProp.setDefaultValue(new PropertyDefaultValue() { @Override public String getDefaultValue() { @@ -85,25 +84,4 @@ 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/GenericModule.java b/hsarweb/src/de/hsadmin/web/GenericModule.java index d236410..4b17369 100644 --- a/hsarweb/src/de/hsadmin/web/GenericModule.java +++ b/hsarweb/src/de/hsadmin/web/GenericModule.java @@ -1,5 +1,6 @@ package de.hsadmin.web; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -38,5 +39,89 @@ public abstract class GenericModule extends AbstractModule implements InsertAble } return idKey; } + + public List getUsers() { + ArrayList list = new ArrayList(); + try { + Object callSearch = getApplication().getRemote().callSearch("user", 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; + } + + public List getEMailAliases() { + ArrayList list = new ArrayList(); + try { + Object callSearch = getApplication().getRemote().callSearch("emailalias", 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; + } + + public List getDomains() { + ArrayList list = new ArrayList(); + try { + Object callSearch = getApplication().getRemote().callSearch("domain", 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; + } + + 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 294bc0b..ec66927 100644 --- a/hsarweb/src/de/hsadmin/web/UnixUserModule.java +++ b/hsarweb/src/de/hsadmin/web/UnixUserModule.java @@ -1,7 +1,5 @@ package de.hsadmin.web; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -132,25 +130,4 @@ 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/EMailTargetPropertyFieldFactory.java b/hsarweb/src/de/hsadmin/web/vaadin/EMailTargetPropertyFieldFactory.java new file mode 100644 index 0000000..c3cf10c --- /dev/null +++ b/hsarweb/src/de/hsadmin/web/vaadin/EMailTargetPropertyFieldFactory.java @@ -0,0 +1,244 @@ +package de.hsadmin.web.vaadin; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.StringTokenizer; + +import com.vaadin.data.Property; +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.terminal.Sizeable; +import com.vaadin.ui.AbstractField; +import com.vaadin.ui.Component; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Select; +import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; + +import de.hsadmin.web.GenericModule; +import de.hsadmin.web.HsarwebException; +import de.hsadmin.web.Module; +import de.hsadmin.web.config.PropertyConfig; +import de.hsadmin.web.config.PropertyFieldFactory; + +public class EMailTargetPropertyFieldFactory implements PropertyFieldFactory { + + private Module module; + private boolean readOnly; + private boolean writeOnce; + private List users; + private List mailAliases; + private Map targets; + private int lastIndex; + private VerticalLayout layout; + + public EMailTargetPropertyFieldFactory(Module module) { + this.module = module; + } + + public void removeTarget(SingleEMailTarget target) { + if (target.getIndex() < lastIndex) { + targets.remove(target.getIndex()); + repaint(); + } + } + + public void appendTarget(SingleEMailTarget lastTarget) { + if (lastTarget.getIndex() == lastIndex) { + lastIndex++; + targets.put(lastIndex, new SingleEMailTarget(this, lastIndex, "")); + repaint(); + } + } + + private void repaint() { + layout.removeAllComponents(); + for (Integer idx : targets.keySet()) { + layout.addComponent(targets.get(idx).getComponent()); + } + } + + @Override + public Object createFieldComponent(PropertyConfig prop, Object value) { + GenericModule genModule = (GenericModule) module; + users = genModule.getUsers(); + mailAliases = genModule.getEMailAliases(); + layout = new VerticalLayout(); + layout.setCaption(prop.getLabel()); + layout.setData(prop.getId()); + + targets = new HashMap(); + lastIndex = 0; + if (value instanceof String) { + StringTokenizer tokenizer = new StringTokenizer((String) value, ","); + while (tokenizer.hasMoreTokens()) { + String target = tokenizer.nextToken().trim(); + targets.put(lastIndex, new SingleEMailTarget(this, lastIndex, target)); + lastIndex++; + } + } + targets.put(lastIndex, new SingleEMailTarget(this, lastIndex, "")); + repaint(); + return layout; + } + + @Override + public String getValue(PropertyConfig prop, Object component) throws HsarwebException { + StringBuffer target = new StringBuffer(); + boolean insertKomma = false; + for (Integer key : targets.keySet()) { + SingleEMailTarget mailTarget = targets.get(key); + String value = mailTarget.getValue(); + if (value != null && value.length() > 0) { + if (insertKomma) { + target.append(","); + } + target.append(value); + insertKomma = true; + } + } + return target.toString(); + } + + @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; + } + + class SingleEMailTarget { + + private HorizontalLayout targetLine; + private Select leftPart; + private HorizontalLayout rightPart; + private int index; + private EMailTargetPropertyFieldFactory owner; + + protected SingleEMailTarget(EMailTargetPropertyFieldFactory owner, int key, String target) { + this.owner = owner; + this.index = key; + targetLine = new HorizontalLayout(); + targetLine.setWidth(480.0f, Sizeable.UNITS_PIXELS); + rightPart = new HorizontalLayout(); + rightPart.setWidth(380.0f, Sizeable.UNITS_PIXELS); + leftPart = new Select(); + leftPart.setWidth(100.0f, Sizeable.UNITS_PIXELS); + leftPart.setImmediate(true); + leftPart.setNewItemsAllowed(false); + leftPart.setNullSelectionAllowed(false); + leftPart.addItem(" "); + leftPart.addItem("User"); + leftPart.addItem("Alias"); + leftPart.addItem("EMail"); + String type = ""; + if (target != null && target.length() > 0) { + for (String alias : mailAliases) { + if (target.equals(alias)) { + type = "Alias"; + break; + } + } + if (type == null || type.length() == 0) { + for (String user : users) { + if (target.equals(user)) { + type = "User"; + break; + } + } + } + if (type == null || type.length() == 0) { + type = "EMail"; + } + } + leftPart.setValue(type); + leftPart.addListener(new Property.ValueChangeListener() { + private static final long serialVersionUID = -4319017121072808451L; + @Override + public void valueChange(ValueChangeEvent event) { + Object targetType = event.getProperty().getValue(); + if (" ".equals(targetType)) { + removeMe(); + } else { + appendTarget(); + } + changeRightPart(targetType); + } + }); + changeRightPart(type); + if (rightPart.getComponentCount() > 0) { + ((AbstractField) rightPart.getComponent(0)).setValue(target); + } + targetLine.addComponent(leftPart); + targetLine.addComponent(rightPart); + } + + public void removeMe() { + owner.removeTarget(this); + } + + public void appendTarget() { + owner.appendTarget(this); + } + + public Component getComponent() { + return targetLine; + } + + public int getIndex() { + return index; + } + + public void changeRightPart(Object targetType) { + if ("User".equals(targetType)) { + rightPart.removeAllComponents(); + Select selUsers = new Select(null, users); + selUsers.setNewItemsAllowed(false); + selUsers.setNullSelectionAllowed(false); + selUsers.setImmediate(true); + selUsers.setWidth(380.0f, Sizeable.UNITS_PIXELS); + rightPart.addComponent(selUsers); + } + if ("Alias".equals(targetType)) { + rightPart.removeAllComponents(); + Select selAliases = new Select(null, mailAliases); + selAliases.setNewItemsAllowed(false); + selAliases.setNullSelectionAllowed(false); + selAliases.setImmediate(true); + selAliases.setWidth(380.0f, Sizeable.UNITS_PIXELS); + rightPart.addComponent(selAliases); + } + if ("EMail".equals(targetType)) { + rightPart.removeAllComponents(); + TextField freeText = new TextField(); + freeText.setImmediate(true); + freeText.setWidth(380.0f, Sizeable.UNITS_PIXELS); + rightPart.addComponent(freeText); + } + } + + public String getValue() { + String value = null; + if (rightPart.getComponentCount() > 0) { + Object object = ((AbstractField) rightPart.getComponent(0)).getValue(); + if (object != null && object instanceof String) { + value = ((String) object).trim(); + } + } + return value; + } + } +} diff --git a/hsarweb/src/de/hsadmin/web/vaadin/GenericForm.java b/hsarweb/src/de/hsadmin/web/vaadin/GenericForm.java index cec667a..468cabe 100644 --- a/hsarweb/src/de/hsadmin/web/vaadin/GenericForm.java +++ b/hsarweb/src/de/hsadmin/web/vaadin/GenericForm.java @@ -90,6 +90,10 @@ public class GenericForm { public void transferToHash(Map map, Form form) throws HsarwebException { Iterator iterator = form.getLayout().getComponentIterator(); + Object formData = form.getData(); + if (formData != null && formData instanceof Long) { + map.put(findIdKey(), ((Long) formData).toString()); + } while (iterator.hasNext()) { Component component = (Component) iterator.next(); if (component instanceof AbstractComponent) {