Mercurial > dive4elements > river
changeset 848:9ecd58f619a4
Moved datacage into a separated widget.
flys-client/trunk@2586 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 25 Aug 2011 16:03:26 +0000 |
parents | 25a4bf390757 |
children | d0098fc8c40b |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/event/DatacageHandler.java flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageButton.java flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacagePanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWidget.java flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartToolbar.java |
diffstat | 7 files changed, 352 insertions(+), 244 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Thu Aug 25 13:36:06 2011 +0000 +++ b/flys-client/ChangeLog Thu Aug 25 16:03:26 2011 +0000 @@ -1,4 +1,21 @@ -2011-08-24 Sascha L. Teichmann <sascha.teichmann@intevation.de> +2011-08-25 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/client/client/ui/DatacageWidget.java: + Moved datacage specific stuff into a VLayout. + * src/main/java/de/intevation/flys/client/client/event/DatacageHandler.java: + New. Event handler used by DatacageWidget to broadcast toLoad events. + + * src/main/java/de/intevation/flys/client/client/ui/DatacagePanel.java, + src/main/java/de/intevation/flys/client/client/ui/DatacageButton.java: + Adjusted calls. TODO: We need the user and the collection view. + + * src/main/java/de/intevation/flys/client/client/ui/chart/ChartToolbar.java: + Forward collection view to DatacageWindow. + + * src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java: + Moved stuff out to DatacageWidget. Send recommendations to CollectionView. + +2011-08-25 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/client/client/ui/CollectionView.java: Ugly workaraound: If no reference artifact is given use current
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/event/DatacageHandler.java Thu Aug 25 16:03:26 2011 +0000 @@ -0,0 +1,9 @@ +package de.intevation.flys.client.client.event; + +import de.intevation.flys.client.shared.model.ToLoad; + +public interface DatacageHandler +{ + void toLoad(ToLoad toLoad); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageButton.java Thu Aug 25 13:36:06 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageButton.java Thu Aug 25 16:03:26 2011 +0000 @@ -14,19 +14,30 @@ protected Artifact artifact; protected User user; + protected CollectionView view; - public DatacageButton(String title, Artifact artifact, User user) { + public DatacageButton( + String title, + Artifact artifact, + User user, + CollectionView view + ) { super(title); this.artifact = artifact; this.user = user; + this.view = view; addClickHandler(this); } public void onClick(ClickEvent event) { - final DatacageWindow dc = new DatacageWindow(artifact, user); + // TODO: fetch outs! + String outs = ""; + + final DatacageWindow dc = new DatacageWindow( + artifact, user, outs, view); dc.addCloseClickHandler(new CloseClickHandler() { public void onCloseClick(CloseClientEvent event) { dc.destroy();
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacagePanel.java Thu Aug 25 13:36:06 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacagePanel.java Thu Aug 25 16:03:26 2011 +0000 @@ -53,8 +53,10 @@ layout.addMember(createForm()); // TODO: fetch current user! + // TODO: fetch collection view! layout.addMember( - new DatacageButton(MSG.databasket(), artifact, null)); + new DatacageButton( + MSG.databasket(), artifact, null, null)); return layout; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWidget.java Thu Aug 25 16:03:26 2011 +0000 @@ -0,0 +1,278 @@ +package de.intevation.flys.client.client.ui; + +import de.intevation.flys.client.client.event.DatacageHandler; + +import com.google.gwt.core.client.GWT; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.util.SC; + +import com.smartgwt.client.widgets.Button; + +import com.smartgwt.client.widgets.tree.Tree; +import com.smartgwt.client.widgets.tree.TreeGrid; +import com.smartgwt.client.widgets.tree.TreeNode; + +import com.smartgwt.client.types.TreeModelType; + +import com.smartgwt.client.widgets.layout.VLayout; + +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.events.ClickEvent; + +import com.smartgwt.client.widgets.grid.ListGridRecord; + +import com.smartgwt.client.widgets.grid.events.RecordDoubleClickEvent; +import com.smartgwt.client.widgets.grid.events.RecordDoubleClickHandler; + +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.User; +import de.intevation.flys.client.shared.model.ToLoad; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.Config; + +import de.intevation.flys.client.client.services.MetaDataService; +import de.intevation.flys.client.client.services.MetaDataServiceAsync; + +import de.intevation.flys.client.shared.model.DataCageTree; +import de.intevation.flys.client.shared.model.DataCageNode; +import de.intevation.flys.client.shared.model.AttrList; + +import java.util.ArrayList; +import java.util.List; +import java.util.Stack; + +public class DatacageWidget +extends VLayout +{ + protected MetaDataServiceAsync metaDataService = + GWT.create(MetaDataService.class); + + protected FLYSConstants messages = + GWT.create(FLYSConstants.class); + + protected Artifact artifact; + protected User user; + protected String outs; + + protected TreeGrid treeGrid; + protected Tree tree; + + protected ToLoad toLoad; + + protected List<DatacageHandler> handlers; + + public DatacageWidget() { + handlers = new ArrayList<DatacageHandler>(); + } + + public DatacageWidget(Artifact artifact, User user) { + this(artifact, user, null); + } + + public DatacageWidget(Artifact artifact, User user, String outs) { + this(); + + this.artifact = artifact; + this.user = user; + this.outs = outs; + + toLoad = new ToLoad(); + + setWidth100(); + + tree = new Tree(); + tree.setModelType(TreeModelType.PARENT); + tree.setNameProperty("name"); + tree.setIdField("id"); + tree.setParentIdField("parent-id"); + + treeGrid = new TreeGrid(); + treeGrid.setLoadDataOnDemand(false); + treeGrid.setWidth100(); + treeGrid.setHeight100(); + treeGrid.setShowRoot(false); + + treeGrid.addRecordDoubleClickHandler(new RecordDoubleClickHandler() { + @Override + public void onRecordDoubleClick(RecordDoubleClickEvent event) { + doubleClickedOnTree(event); + } + }); + + addMember(treeGrid); + + // TODO: i18n + icon + Button plusBtn = new Button("+"); + plusBtn.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + plusClicked(); + } + }); + + addMember(plusBtn); + + triggerTreeBuilding(); + } + + public void addDatacageHandler(DatacageHandler handler) { + if (handlers.contains(handler)) { + handlers.add(handler); + } + } + + public void removeDatacageHandler(DatacageHandler handler) { + handlers.remove(handler); + } + + public ToLoad getToLoad() { + return toLoad; + } + + public void plusClicked() { + if (treeGrid == null) { + return; + } + + ListGridRecord [] selection = treeGrid.getSelection(); + + if (selection != null) { + for (ListGridRecord record: selection) { + if (record instanceof TreeNode) { + collectToLoads((TreeNode)record); + } + } + } + + if (!toLoad.isEmpty()) { + fireToLoad(); + } + } + + protected void fireToLoad() { + for (DatacageHandler handler: handlers) { + handler.toLoad(toLoad); + } + } + + protected void doubleClickedOnTree(RecordDoubleClickEvent event) { + + TreeNode node = (TreeNode)event.getRecord(); + collectToLoads(node); + destroy(); + } + + protected void collectToLoads(TreeNode node) { + Stack<TreeNode> stack = new Stack<TreeNode>(); + + stack.push(node); + + while (!stack.isEmpty()) { + node = stack.pop(); + String factory = node.getAttribute("factory"); + if (factory != null) { // we need at least a factory + String artifact = node.getAttribute("artifact-id"); + String out = node.getAttribute("out"); + String name = node.getName(); + String ids = node.getAttribute("ids"); + + toLoad.add(artifact, factory, out, name, ids); + } + TreeNode [] children = tree.getChildren(node); + if (children != null) { + for (TreeNode child: children) { + stack.push(child); + } + } + } + } + + + protected void triggerTreeBuilding() { + Config config = Config.getInstance(); + String url = config.getServerUrl(); + String locale = config.getLocale(); + + String artifactId = artifact.getUuid(); + String userId = user != null ? user.identifier() : null; + + metaDataService.getMetaData( + url, locale, + artifactId, + userId, + outs, + new AsyncCallback<DataCageTree>() { + public void onFailure(Throwable caught) { + GWT.log("Could not load meta data."); + SC.warn(caught.getMessage()); + } + + public void onSuccess(DataCageTree dcTree) { + GWT.log("Successfully loaded meta data."); + tree.setData(treeToData(dcTree)); + treeGrid.setData(tree); + } + }); + } + + private static class IdGenerator { + protected int current; + + public IdGenerator() { + } + + public IdGenerator(int start) { + current = start; + } + + public int next() { + return current++; + } + } // class IdGenerator + + protected static void buildRecursive( + DataCageNode node, + int parentId, + IdGenerator idGenerator, + List<TreeNode> nodes + ) { + TreeNode tn = new TreeNode(); + int id = idGenerator.next(); + tn.setAttribute("parent-id", parentId); + tn.setAttribute("id", id); + // TODO: i18n + tn.setAttribute("name", node.getName()); + nodes.add(tn); + AttrList attrs = node.getAttributes(); + if (attrs != null) { + for (int i = 0, N = attrs.size(); i < N; ++i) { + String key = attrs.getKey(i); + String value = attrs.getValue(i); + tn.setAttribute(key, value); + } + } + List<DataCageNode> children = node.getChildren(); + if (children != null) { + for (DataCageNode child: children) { + buildRecursive(child, id, idGenerator, nodes); + } + } + } + + + protected static TreeNode [] treeToData(DataCageTree tree) { + List<TreeNode> nodes = new ArrayList<TreeNode>(); + + DataCageNode root = tree.getRoot(); + + IdGenerator idGenerator = new IdGenerator(); + + buildRecursive(root, idGenerator.next(), idGenerator, nodes); + + return nodes.toArray(new TreeNode[nodes.size()]); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java Thu Aug 25 13:36:06 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java Thu Aug 25 16:03:26 2011 +0000 @@ -2,124 +2,49 @@ import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.util.SC; - import com.smartgwt.client.widgets.Window; -import com.smartgwt.client.widgets.Button; - -import com.smartgwt.client.widgets.tree.Tree; -import com.smartgwt.client.widgets.tree.TreeGrid; -import com.smartgwt.client.widgets.tree.TreeNode; -import com.smartgwt.client.types.TreeModelType; - -import com.smartgwt.client.widgets.layout.Layout; -import com.smartgwt.client.widgets.layout.VLayout; +import de.intevation.flys.client.client.FLYSConstants; -import com.smartgwt.client.widgets.events.ClickHandler; -import com.smartgwt.client.widgets.events.ClickEvent; - -import com.smartgwt.client.widgets.grid.ListGridRecord; - -import com.smartgwt.client.widgets.grid.events.RecordDoubleClickEvent; -import com.smartgwt.client.widgets.grid.events.RecordDoubleClickHandler; +import de.intevation.flys.client.client.event.DatacageHandler; import de.intevation.flys.client.shared.model.Artifact; import de.intevation.flys.client.shared.model.ArtifactDescription; import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; import de.intevation.flys.client.shared.model.DataList; -import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.ToLoad; import de.intevation.flys.client.shared.model.User; -import de.intevation.flys.client.shared.model.ToLoad; - -import de.intevation.flys.client.client.FLYSConstants; -import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.shared.model.Recommendation; -import de.intevation.flys.client.client.services.MetaDataService; -import de.intevation.flys.client.client.services.MetaDataServiceAsync; +import java.util.List; -import de.intevation.flys.client.shared.model.DataCageTree; -import de.intevation.flys.client.shared.model.DataCageNode; -import de.intevation.flys.client.shared.model.AttrList; - -import java.util.ArrayList; -import java.util.List; -import java.util.Stack; public class DatacageWindow extends Window +implements DatacageHandler { - protected MetaDataServiceAsync metaDataService = - GWT.create(MetaDataService.class); - protected FLYSConstants messages = GWT.create(FLYSConstants.class); - - protected Artifact artifact; - protected User user; - protected String outs; - - protected TreeGrid treeGrid; - protected Tree tree; - - protected Layout layout; + protected CollectionView view; - protected ToLoad toLoad; - - - public DatacageWindow(Artifact artifact, User user) { - this(artifact, user, null); - } - - public DatacageWindow(Artifact artifact, User user, String outs) { - this.artifact = artifact; - this.user = user; - this.outs = outs; - - setWidth(300); + public DatacageWindow( + Artifact artifact, + User user, + String outs, + CollectionView view + ) { + this.view = view; + setWidth(400); setHeight(500); - layout = new VLayout(); - layout.setWidth100(); - - addItem(layout); - - tree = new Tree(); - tree.setModelType(TreeModelType.PARENT); - tree.setNameProperty("name"); - tree.setIdField("id"); - tree.setParentIdField("parent-id"); - - treeGrid = new TreeGrid(); - treeGrid.setLoadDataOnDemand(false); - treeGrid.setWidth100(); - treeGrid.setHeight100(); - treeGrid.setShowRoot(false); + DatacageWidget dw = new DatacageWidget(artifact, user, outs); + dw.addDatacageHandler(this); - treeGrid.addRecordDoubleClickHandler(new RecordDoubleClickHandler() { - @Override - public void onRecordDoubleClick(RecordDoubleClickEvent event) { - doubleClickedOnTree(event); - } - }); - - layout.addMember(treeGrid); + addItem(dw); - // TODO: i18n + icon - Button plusBtn = new Button("+"); - plusBtn.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - plusClicked(); - } - }); - - layout.addMember(plusBtn); - - String river = findRiver(); + String river = findRiver(artifact); // TODO: i18n setTitle("Datenkorb: " + river); setShowMinimizeButton(false); @@ -128,154 +53,17 @@ setCanDragResize(true); centerInPage(); - - toLoad = new ToLoad(); - - triggerTreeBuilding(); - } - - public ToLoad getToLoad() { - return toLoad; - } - - public void plusClicked() { - if (treeGrid == null) { - return; - } - - ListGridRecord [] selection = treeGrid.getSelection(); - - if (selection != null) { - for (ListGridRecord record: selection) { - if (record instanceof TreeNode) { - collectToLoads((TreeNode)record); - } - } - } - - if (!toLoad.isEmpty()) { - destroy(); - } - } - - protected void doubleClickedOnTree(RecordDoubleClickEvent event) { - - TreeNode node = (TreeNode)event.getRecord(); - collectToLoads(node); - destroy(); - } - - protected void collectToLoads(TreeNode node) { - Stack<TreeNode> stack = new Stack<TreeNode>(); - - stack.push(node); - - while (!stack.isEmpty()) { - node = stack.pop(); - String factory = node.getAttribute("factory"); - if (factory != null) { // we need at least a factory - String artifact = node.getAttribute("artifact-id"); - String out = node.getAttribute("out"); - String name = node.getName(); - String ids = node.getAttribute("ids"); - - toLoad.add(artifact, factory, out, name, ids); - } - TreeNode [] children = tree.getChildren(node); - if (children != null) { - for (TreeNode child: children) { - stack.push(child); - } - } - } } - - protected void triggerTreeBuilding() { - Config config = Config.getInstance(); - String url = config.getServerUrl(); - String locale = config.getLocale(); - - String artifactId = artifact.getUuid(); - String userId = user != null ? user.identifier() : null; - - metaDataService.getMetaData( - url, locale, - artifactId, - userId, - outs, - new AsyncCallback<DataCageTree>() { - public void onFailure(Throwable caught) { - GWT.log("Could not load meta data."); - SC.warn(caught.getMessage()); - } - - public void onSuccess(DataCageTree dcTree) { - GWT.log("Successfully loaded meta data."); - tree.setData(treeToData(dcTree)); - treeGrid.setData(tree); - } - }); + @Override + public void toLoad(ToLoad toLoad) { + destroy(); + List<Recommendation> recs = toLoad.toRecommendations(); + view.loadRecommendedArtifacts( + recs.toArray(new Recommendation[recs.size()])); } - private static class IdGenerator { - protected int current; - - public IdGenerator() { - } - - public IdGenerator(int start) { - current = start; - } - - public int next() { - return current++; - } - } // class IdGenerator - - protected static void buildRecursive( - DataCageNode node, - int parentId, - IdGenerator idGenerator, - List<TreeNode> nodes - ) { - TreeNode tn = new TreeNode(); - int id = idGenerator.next(); - tn.setAttribute("parent-id", parentId); - tn.setAttribute("id", id); - // TODO: i18n - tn.setAttribute("name", node.getName()); - nodes.add(tn); - AttrList attrs = node.getAttributes(); - if (attrs != null) { - for (int i = 0, N = attrs.size(); i < N; ++i) { - String key = attrs.getKey(i); - String value = attrs.getValue(i); - tn.setAttribute(key, value); - } - } - List<DataCageNode> children = node.getChildren(); - if (children != null) { - for (DataCageNode child: children) { - buildRecursive(child, id, idGenerator, nodes); - } - } - } - - - protected static TreeNode [] treeToData(DataCageTree tree) { - List<TreeNode> nodes = new ArrayList<TreeNode>(); - - DataCageNode root = tree.getRoot(); - - IdGenerator idGenerator = new IdGenerator(); - - buildRecursive(root, idGenerator.next(), idGenerator, nodes); - - return nodes.toArray(new TreeNode[nodes.size()]); - } - - protected String findRiver() { + protected String findRiver(Artifact artifact) { ArtifactDescription adescr = artifact.getArtifactDescription(); DataList [] data = adescr.getOldData();
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartToolbar.java Thu Aug 25 13:36:06 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartToolbar.java Thu Aug 25 16:03:26 2011 +0000 @@ -158,7 +158,10 @@ Artifact artifact = getArtifact(); User user = getUser(); - final DatacageWindow dc = new DatacageWindow(artifact, user); + String outs = ""; // TODO: fetch outs + + final DatacageWindow dc = new DatacageWindow( + artifact, user, outs, view); dc.addCloseClickHandler(new CloseClickHandler() { public void onCloseClick(CloseClientEvent event) { dc.destroy();