Mercurial > dive4elements > river
diff flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java @ 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 | 29966a53cfeb |
children | c0e13cf826d7 |
line wrap: on
line diff
--- 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();