Paket selektierbar

This commit is contained in:
Peter Hormanns 2011-03-22 22:03:07 +00:00
parent 6ca3aac648
commit 6abee84d81
3 changed files with 111 additions and 18 deletions

View File

@ -1,9 +1,17 @@
package de.hsadmin.web; 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.ModuleConfig;
import de.hsadmin.web.config.PropertyConfig; import de.hsadmin.web.config.PropertyConfig;
import de.hsadmin.web.config.PropertyDefaultValue; import de.hsadmin.web.config.PropertyDefaultValue;
import de.hsadmin.web.config.PropertySelectValues;
import de.hsadmin.web.config.PropertyTableColumn; import de.hsadmin.web.config.PropertyTableColumn;
import de.hsadmin.web.vaadin.SelectPropertyFieldFactory;
public class EMailAliasModule extends GenericModule { public class EMailAliasModule extends GenericModule {
@ -39,18 +47,37 @@ public class EMailAliasModule extends GenericModule {
return ""; 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() { pacProp.setDefaultValue(new PropertyDefaultValue() {
@Override @Override
public String getDefaultValue() { public String getDefaultValue() {
return pac; return pac;
} }
}); });
pacProp.setReadOnly(true); pacProp.setSelectValues(new PropertySelectValues() {
@Override
public boolean newItemsAllowed() {
return false;
}
@Override
public boolean hasSelectList() {
return true;
}
@Override
public Map<String, String> getSelectValues() {
List<String> list = getPackets();
TreeMap<String,String> map = new TreeMap<String, String>();
for (String pac : list) {
map.put(pac, pac);
}
return map;
}
});
pacProp.setWriteOnce(true);
moduleConfig.addProperty(idProp); moduleConfig.addProperty(idProp);
moduleConfig.addProperty(pacProp);
moduleConfig.addProperty(nameProp); moduleConfig.addProperty(nameProp);
moduleConfig.addProperty(targetProp); moduleConfig.addProperty(targetProp);
moduleConfig.addProperty(pacProp);
} }
@Override @Override
@ -58,4 +85,25 @@ public class EMailAliasModule extends GenericModule {
return moduleConfig; return moduleConfig;
} }
public List<String> getPackets() {
ArrayList<String> list = new ArrayList<String>();
try {
Object callSearch = getApplication().getRemote().callSearch("pac", new HashMap<String, String>());
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;
}
} }

View File

@ -1,5 +1,8 @@
package de.hsadmin.web; package de.hsadmin.web;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
@ -22,6 +25,33 @@ public class UnixUserModule extends GenericModule {
moduleConfig = new ModuleConfig("user"); moduleConfig = new ModuleConfig("user");
String login = getApplication().getLogin(); String login = getApplication().getLogin();
final String pac = login.length() >= 5 ? login.substring(0, 5) : ""; 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<String, String> getSelectValues() {
List<String> list = getPackets();
TreeMap<String,String> map = new TreeMap<String, String>();
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); PropertyConfig idProp = new PropertyConfig(moduleConfig, "id", Long.class, PropertyTableColumn.INTERNAL_KEY);
idProp.setReadOnly(true); idProp.setReadOnly(true);
PropertyConfig useridProp = new PropertyConfig(moduleConfig, "userid", Long.class, PropertyTableColumn.HIDDEN); 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); PropertyConfig homedirProp = new PropertyConfig(moduleConfig, "homedir", String.class, PropertyTableColumn.HIDDEN);
homedirProp.setReadOnly(true); 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); PropertyConfig softQuotaProp = new PropertyConfig(moduleConfig, "quota_softlimit", Long.class, PropertyTableColumn.HIDDEN);
softQuotaProp.setDefaultValue(new PropertyDefaultValue() { softQuotaProp.setDefaultValue(new PropertyDefaultValue() {
@Override @Override
@ -93,6 +115,7 @@ public class UnixUserModule extends GenericModule {
return "0"; return "0";
} }
}); });
moduleConfig.addProperty(pacProp);
moduleConfig.addProperty(idProp); moduleConfig.addProperty(idProp);
moduleConfig.addProperty(useridProp); moduleConfig.addProperty(useridProp);
moduleConfig.addProperty(nameProp); moduleConfig.addProperty(nameProp);
@ -100,7 +123,6 @@ public class UnixUserModule extends GenericModule {
moduleConfig.addProperty(commentProp); moduleConfig.addProperty(commentProp);
moduleConfig.addProperty(shellProp); moduleConfig.addProperty(shellProp);
moduleConfig.addProperty(homedirProp); moduleConfig.addProperty(homedirProp);
moduleConfig.addProperty(pacProp);
moduleConfig.addProperty(softQuotaProp); moduleConfig.addProperty(softQuotaProp);
moduleConfig.addProperty(hardQuotaProp); moduleConfig.addProperty(hardQuotaProp);
} }
@ -110,4 +132,25 @@ public class UnixUserModule extends GenericModule {
return moduleConfig; return moduleConfig;
} }
public List<String> getPackets() {
ArrayList<String> list = new ArrayList<String>();
try {
Object callSearch = getApplication().getRemote().callSearch("pac", new HashMap<String, String>());
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;
}
} }

View File

@ -56,6 +56,7 @@ public class GenericForm {
f.setData(entityId); f.setData(entityId);
Layout layout = f.getLayout(); Layout layout = f.getLayout();
for (PropertyConfig prop : config.getPropertyList()) { for (PropertyConfig prop : config.getPropertyList()) {
if (!prop.getPropTableColumn().equals(PropertyTableColumn.INTERNAL_KEY)) {
PropertyFieldFactory propFieldFactory = prop.getPropFieldFactory(); PropertyFieldFactory propFieldFactory = prop.getPropFieldFactory();
Object value = row.get(prop.getId()); Object value = row.get(prop.getId());
Component component = (Component) propFieldFactory.createFieldComponent(prop, value); Component component = (Component) propFieldFactory.createFieldComponent(prop, value);
@ -64,6 +65,7 @@ public class GenericForm {
} }
layout.addComponent(component); layout.addComponent(component);
} }
}
return f; return f;
} }
} catch (HsarwebException e) { } catch (HsarwebException e) {