# HG changeset patch
# User gernotbelger
# Date 1518001153 -3600
# Node ID c26fb37899ca3e8777e53816fe6cc0aa80d15cb0
# Parent 20b85ea3b524cff197a30cf4f79813a2ac0609ef
Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui.
Also using now the localization info from the server instead of localizing the modules again on the client side.
diff -r 20b85ea3b524 -r c26fb37899ca artifacts/doc/conf/modules.xml
--- a/artifacts/doc/conf/modules.xml Wed Feb 07 11:52:04 2018 +0100
+++ b/artifacts/doc/conf/modules.xml Wed Feb 07 11:59:13 2018 +0100
@@ -3,19 +3,19 @@
-
-
-
-
+
-
+
-
+
-
+
+
+
+
\ No newline at end of file
diff -r 20b85ea3b524 -r c26fb37899ca artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java Wed Feb 07 11:52:04 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java Wed Feb 07 11:59:13 2018 +0100
@@ -617,30 +617,34 @@
NodeList modulenodes = (NodeList) XMLUtils.xpath(
cfg, XPATH_MODULES, XPathConstants.NODESET);
- int num = modulenodes != null ? modulenodes.getLength() : 0;
- ArrayList modules = new ArrayList(num);
+ final int num = modulenodes != null ? modulenodes.getLength() : 0;
+
+ final List modules = new ArrayList<>(num);
for (int i = 0; i < num; i++) {
- Element e = (Element) modulenodes.item(i);
- String modulename = e.getAttribute("name");
- String attrselected = e.getAttribute("selected");
- boolean selected = attrselected == null ? false :
- attrselected.equalsIgnoreCase("true");
+ final Element e = (Element) modulenodes.item(i);
+ final String modulename = e.getAttribute("name");
+ final String attrselected = e.getAttribute("selected");
+ final boolean selected = Boolean.parseBoolean(attrselected);
+ final String group = e.getAttribute("group");
+
log.debug("Loaded module " + modulename);
- NodeList children = e.getChildNodes();
- List rivers = new ArrayList(children.getLength());
+
+ final NodeList children = e.getChildNodes();
+ final List rivers = new ArrayList<>(children.getLength());
for (int j = 0; j < children.getLength(); j++) {
if (children.item(j).getNodeType() != Node.ELEMENT_NODE) {
continue;
}
- Element ce = (Element)children.item(j);
+
+ final Element ce = (Element)children.item(j);
if (ce.hasAttribute("uuid")) {
rivers.add(ce.getAttribute("uuid"));
}
else if (ce.hasAttribute("name")) {
- List allRivers = RiverFactory.getRivers();
- String name = ce.getAttribute("name");
- for (River r: allRivers) {
+ final List allRivers = RiverFactory.getRivers();
+ final String name = ce.getAttribute("name");
+ for (final River r: allRivers) {
if (name.equals(r.getName())) {
rivers.add(r.getModelUuid());
break;
@@ -648,7 +652,7 @@
}
}
}
- modules.add(new Module(modulename, selected, rivers));
+ modules.add(new Module(modulename, selected, group, rivers));
}
context.put(RiverContext.MODULES, modules);
}
diff -r 20b85ea3b524 -r c26fb37899ca artifacts/src/main/java/org/dive4elements/river/artifacts/model/Module.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/Module.java Wed Feb 07 11:52:04 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/Module.java Wed Feb 07 11:59:13 2018 +0100
@@ -15,12 +15,21 @@
*/
public class Module {
- private String name;
- List rivers;
- private boolean selected;
+ private final String name;
- public Module(String name, boolean selected, List rivers) {
+ /**
+ * Defines an (optional) group name for a module. Modules with the same group name are considered to be in the same group
+ * This can be uised to group modules in the front-end
+ */
+ private final String group;
+
+ private final boolean selected;
+
+ private final List rivers;
+
+ public Module(final String name, final boolean selected, final String group, final List rivers) {
this.name = name;
+ this.group = group;
this.rivers = rivers;
this.selected = selected;
}
@@ -32,6 +41,10 @@
public boolean isSelected() {
return this.selected;
}
+
+ public String getGroup() {
+ return this.group;
+ }
public List getRivers() {
return this.rivers;
diff -r 20b85ea3b524 -r c26fb37899ca artifacts/src/main/java/org/dive4elements/river/artifacts/services/ModuleService.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/services/ModuleService.java Wed Feb 07 11:52:04 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/services/ModuleService.java Wed Feb 07 11:59:13 2018 +0100
@@ -30,6 +30,7 @@
private static Logger log = Logger.getLogger(ModuleService.class);
+ @Override
protected Document doProcess(
Document data,
GlobalContext globalContext,
@@ -37,26 +38,25 @@
) {
log.debug("ModuleService.process");
- Document result = XMLUtils.newDocument();
+ final Document result = XMLUtils.newDocument();
- XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
+ final XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
result,
ArtifactNamespaceContext.NAMESPACE_URI,
ArtifactNamespaceContext.NAMESPACE_PREFIX);
- Element em = ec.create("modules");
- List modules = (List)globalContext.get(
- RiverContext.MODULES);
+ final Element em = ec.create("modules");
+ final List modules = (List)globalContext.get( RiverContext.MODULES);
- for (Module module : modules) {
- Element m = ec.create("module");
+ for (final Module module : modules) {
+ final Element m = ec.create("module");
ec.addAttr(m, "name", module.getName(), true);
- String localname = Resources.getMsg(callMeta,
- MODULE + "." + module.getName(), module.getName());
+
+ final String localname = Resources.getMsg(callMeta, MODULE + "." + module.getName(), module.getName());
ec.addAttr(m, "localname", localname, true);
- for (String river : module.getRivers()) {
- Element r = ec.create("river");
+ for (final String river : module.getRivers()) {
+ final Element r = ec.create("river");
r.setAttribute("uuid", river);
m.appendChild(r);
}
@@ -64,6 +64,13 @@
ec.addAttr(m, "selected", "true", true);
}
+ final String group = module.getGroup();
+ if( group != null ) {
+ final String groupLabel = Resources.getMsg(callMeta, group);
+ ec.addAttr(m, "groupId", group, true);
+ ec.addAttr(m, "groupLabel", groupLabel, true);
+ }
+
em.appendChild(m);
}
diff -r 20b85ea3b524 -r c26fb37899ca artifacts/src/main/resources/messages.properties
--- a/artifacts/src/main/resources/messages.properties Wed Feb 07 11:52:04 2018 +0100
+++ b/artifacts/src/main/resources/messages.properties Wed Feb 07 11:59:13 2018 +0100
@@ -762,6 +762,10 @@
help.state.fix.vollmer.qs=${help.url}/OnlineHilfe/Fixierungsanalyse#help.state.fix.vollmer.qs
help.state.fix.vollmer.compute=${help.url}/OnlineHilfe/Fixierungsanalyse#help.state.fix.vollmer.compute
+module.group.ingwerds = INGwerDs
+# empty label, so it does not get a group-frame in the ui
+module.group.bottom =
+
state.sinfo.river = River
state.sinfo.calculation_mode=Calculation Mode
diff -r 20b85ea3b524 -r c26fb37899ca artifacts/src/main/resources/messages_de.properties
--- a/artifacts/src/main/resources/messages_de.properties Wed Feb 07 11:52:04 2018 +0100
+++ b/artifacts/src/main/resources/messages_de.properties Wed Feb 07 11:59:13 2018 +0100
@@ -768,6 +768,10 @@
help.state.fix.vollmer.qs=${help.url}/OnlineHilfe/Fixierungsanalyse#help.state.fix.vollmer.qs
help.state.fix.vollmer.compute=${help.url}/OnlineHilfe/Fixierungsanalyse#help.state.fix.vollmer.compute
+module.group.ingwerds = INGwerDs
+# empty label, so it does not get a group-frame in the ui
+module.group.bottom =
+
state.sinfo.river = Gew\u00e4sser
state.sinfo.calculation_mode=Berechnungsart
diff -r 20b85ea3b524 -r c26fb37899ca artifacts/src/main/resources/messages_de_DE.properties
--- a/artifacts/src/main/resources/messages_de_DE.properties Wed Feb 07 11:52:04 2018 +0100
+++ b/artifacts/src/main/resources/messages_de_DE.properties Wed Feb 07 11:59:13 2018 +0100
@@ -764,6 +764,10 @@
help.state.fix.vollmer.qs=${help.url}/OnlineHilfe/Fixierungsanalyse#help.state.fix.vollmer.qs
help.state.fix.vollmer.compute=${help.url}/OnlineHilfe/Fixierungsanalyse#help.state.fix.vollmer.compute
+module.group.ingwerds = INGwerDs
+# empty label, so it does not get a group-frame in the ui
+module.group.bottom =
+
state.sinfo.river = Gew\u00e4sser
state.sinfo.calculation_mode=Berechnungsart
diff -r 20b85ea3b524 -r c26fb37899ca artifacts/src/main/resources/messages_en.properties
--- a/artifacts/src/main/resources/messages_en.properties Wed Feb 07 11:52:04 2018 +0100
+++ b/artifacts/src/main/resources/messages_en.properties Wed Feb 07 11:59:13 2018 +0100
@@ -763,6 +763,10 @@
help.state.fix.vollmer.qs=${help.url}/OnlineHilfe/Fixierungsanalyse#help.state.fix.vollmer.qs
help.state.fix.vollmer.compute=${help.url}/OnlineHilfe/Fixierungsanalyse#help.state.fix.vollmer.compute
+module.group.ingwerds = INGwerDs
+# empty label, so it does not get a group-frame in the ui
+module.group.bottom =
+
state.sinfo.river = River
state.sinfo.calculation_mode=Calculation Mode
diff -r 20b85ea3b524 -r c26fb37899ca gwt-client/src/main/java/org/dive4elements/river/client/client/ui/MapSelection.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/MapSelection.java Wed Feb 07 11:52:04 2018 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/MapSelection.java Wed Feb 07 11:59:13 2018 +0100
@@ -29,7 +29,7 @@
private static final long serialVersionUID = 1261822454641198692L;
- protected ModuleSelection moduleSelection;
+ private ModuleSelection moduleSelection;
public MapSelection() {
}
diff -r 20b85ea3b524 -r c26fb37899ca gwt-client/src/main/java/org/dive4elements/river/client/client/ui/ModuleSelection.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/ModuleSelection.java Wed Feb 07 11:52:04 2018 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/ModuleSelection.java Wed Feb 07 11:59:13 2018 +0100
@@ -8,19 +8,13 @@
package org.dive4elements.river.client.client.ui;
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.user.client.rpc.AsyncCallback;
-
-import com.smartgwt.client.types.VerticalAlignment;
-import com.smartgwt.client.util.SC;
-import com.smartgwt.client.widgets.Canvas;
-import com.smartgwt.client.widgets.Label;
-import com.smartgwt.client.widgets.form.DynamicForm;
-import com.smartgwt.client.widgets.form.fields.RadioGroupItem;
-import com.smartgwt.client.widgets.form.fields.events.ChangeEvent;
-import com.smartgwt.client.widgets.form.fields.events.ChangeHandler;
-import com.smartgwt.client.widgets.layout.HLayout;
-import com.smartgwt.client.widgets.layout.VLayout;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import org.dive4elements.river.client.client.Config;
import org.dive4elements.river.client.client.FLYSConstants;
@@ -32,10 +26,21 @@
import org.dive4elements.river.client.shared.model.DefaultData;
import org.dive4elements.river.client.shared.model.DefaultDataItem;
import org.dive4elements.river.client.shared.model.Module;
+import org.dive4elements.river.client.shared.model.ModuleGroup;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.smartgwt.client.types.VerticalAlignment;
+import com.smartgwt.client.util.SC;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.Label;
+import com.smartgwt.client.widgets.form.DynamicForm;
+import com.smartgwt.client.widgets.form.fields.RadioGroupItem;
+import com.smartgwt.client.widgets.form.fields.events.ChangeEvent;
+import com.smartgwt.client.widgets.form.fields.events.ChangeHandler;
+import com.smartgwt.client.widgets.layout.HLayout;
+import com.smartgwt.client.widgets.layout.LayoutSpacer;
+import com.smartgwt.client.widgets.layout.VLayout;
/**
* The ModuleSelection combines the river selection and the module selection in
@@ -50,32 +55,34 @@
private static final long serialVersionUID = -5634831815175543328L;
/** The message class that provides i18n strings.*/
- protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class);
-
- /** The module checkboxes.*/
- protected static RadioGroupItem radio;
-
- /** */
- protected Module[] modules;
+ private FLYSConstants MESSAGES = GWT.create(FLYSConstants.class);
/** The ModuleService used to retrieve the available modules of a user.*/
- protected ModuleServiceAsync moduleService = GWT.create(
- ModuleService.class);
-
- private Map > modulesRiverMap;
- protected Map rivers;
+ private ModuleServiceAsync moduleService = GWT.create(ModuleService.class);
- /**
- * The default constructor.
- */
+ private Map > modulesRiverMap = new LinkedHashMap >();
+
+ private Map modulesByName = new HashMap();
+
+ private Map> modulesByGroup = new LinkedHashMap>();
+
+ private Map groupToRadios = new LinkedHashMap();
+
+ private Map groupToCanvas = new LinkedHashMap();
+
+ private Map rivers = null;
+
+ private VLayout radioPanel;
+
+ /* TODO: seems that it needs to be static for the callback, is this really necessary?
+ * TODO: what happens if we have several 'new project' windows open in parallel?
+ * */
+ private static Module selectedModule = null;
+
public ModuleSelection() {
- rivers = null;
- modulesRiverMap = new LinkedHashMap >();
-
readModules();
}
-
/**
* This method returns a widget that renders the checkboxes for each module
* and the MapSelection that lets the user choose the river.
@@ -114,59 +121,54 @@
@Override
public void onSuccess(Module[] newmodules) {
GWT.log("Retrieved " + newmodules.length + " modules.");
- modules = newmodules;
- setModules();
+ setModules(newmodules);
+ updateRadioPanels();
}
});
}
+ // TODO: bad. Too much knowledge spread over the application.
+ // TODO: instead, e.g. use a controller that knows both (ModuleSelection and LinkSelection) and let him do this kind of things
private void checkRivers(String selected) {
- if (selected == null) {
- selected = getSelectedModule();
- }
- if (rivers != null
- && !rivers.isEmpty()
- && modules != null
- && selected != null
- ) {
- List allowedRivers = modulesRiverMap.get(selected);
- if ( allowedRivers == null ) {
- GWT.log("No configured rivers for module: " + selected);
- }
- for (Map.Entry s: rivers.entrySet()) {
- if ( allowedRivers == null ) {
- s.getValue().hide();
- continue;
- }
- if (!allowedRivers.contains(s.getKey())) {
- s.getValue().hide();
- } else {
- s.getValue().show();
- }
+ if (rivers == null || rivers.isEmpty() || /*modules == null || */ selected == null )
+ return;
+
+ final List allowedRivers = modulesRiverMap.get(selected);
+ if ( allowedRivers == null )
+ GWT.log("No configured rivers for module: " + selected);
+
+ for (final Map.Entry s: rivers.entrySet()) {
+ if (allowedRivers == null || !allowedRivers.contains(s.getKey())) {
+ s.getValue().hide();
+ } else {
+ s.getValue().show();
}
}
}
-
- private void setModules() {
- LinkedHashMap values =
- new LinkedHashMap();
+
+ protected final void setModules(Module[] newmodules) {
+ modulesRiverMap.clear();
+
+ if( newmodules == null )
+ return;
+
+ for(final Module module : newmodules) {
+ final String name = module.getName();
+
+ /* remember rivers per module */
+ modulesRiverMap.put(name, module.getRivers());
- if (this.modules!= null) {
- for(Module module : this.modules) {
- values.put(module.getName(), module.getLocalizedName());
- if (module.isSelected()) {
- GWT.log("Module " + module.getName() + " is selected.");
- if (radio != null) {
- radio.setDefaultValue(module.getName());
- }
- }
- modulesRiverMap.put(module.getName(), module.getRivers());
- }
+ /* hash by name */
+ modulesByName.put(name, module);
+
+ /* hash by group */
+ final ModuleGroup group = module.getGroup();
+ if( !modulesByGroup.containsKey( group ) )
+ modulesByGroup.put(group, new LinkedList());
+
+ final List modulesGroup = modulesByGroup.get(group);
+ modulesGroup.add(module);
}
- if (radio != null) {
- radio.setValueMap(values);
- }
- checkRivers(null);
}
/**
@@ -175,36 +177,119 @@
* @return a widget with checkboxes.
*/
protected Canvas createWidget() {
- HLayout layout = new HLayout();
-
- Label label = new Label(MESSAGES.module_selection());
- DynamicForm form = new DynamicForm();
+
+ final HLayout layout = new HLayout();
+
+ radioPanel = new VLayout();
- radio = new RadioGroupItem("plugin");
- radio.addChangeHandler(new ChangeHandler() {
- @Override
- public void onChange(ChangeEvent event) {
- checkRivers((String)event.getValue());
- }
- });
-
+ final Label label = new Label(MESSAGES.module_selection());
label.setWidth(50);
label.setHeight(25);
-
- radio.setShowTitle(false);
- radio.setVertical(true);
-
- setModules();
-
- form.setFields(radio);
-
layout.addMember(label);
- layout.addMember(form);
-
+ layout.addMember(radioPanel);
+
+ updateRadioPanels();
+
return layout;
}
+ protected final void updateRadioPanels() {
+
+ /* first clear existing panels, if any exist */
+ final Collection