# HG changeset patch # User Felix Wolfsteller # Date 1316009934 0 # Node ID 2b6efb8b2301afe1cb0dbb83b31c1f9da2a865d1 # Parent fe23bbf0ea117f925ed066f9d4914e07d214afe8 Refactored DatacageWidget to allow reuse in other use-cases. flys-client/trunk@2743 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r fe23bbf0ea11 -r 2b6efb8b2301 flys-client/ChangeLog --- a/flys-client/ChangeLog Wed Sep 14 12:00:22 2011 +0000 +++ b/flys-client/ChangeLog Wed Sep 14 14:18:54 2011 +0000 @@ -1,3 +1,13 @@ +2011-09-14 Felix Wolfsteller + + Ease access to selected elements of a DatacageWidget. Make button-less + DatacageWidget possible. + + * src/main/java/de/intevation/flys/client/client/ui/DatacageWidget.java: + Refactored to allow for button-less Widget and still be able to + access current selection as ToLoad-objects from "outside"; in coo + with Ingo Weinzierl. + 2011-09-14 Raimund Renkert * src/main/java/de/intevation/flys/client/client/ui/FLYSWorkspace.java, diff -r fe23bbf0ea11 -r 2b6efb8b2301 flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWidget.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWidget.java Wed Sep 14 12:00:22 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWidget.java Wed Sep 14 14:18:54 2011 +0000 @@ -44,6 +44,7 @@ import java.util.List; import java.util.Stack; +// TODO: refactor, extract ~DataCageGrid public class DatacageWidget extends VLayout { @@ -74,8 +75,12 @@ this(artifact, user, null); } + public DatacageWidget(Artifact artifact, User user, String outs) { + this(artifact, user, outs, true); + } - public DatacageWidget(Artifact artifact, User user, String outs) { + public DatacageWidget(Artifact artifact, User user, String outs, + boolean showButton) { this(); this.artifact = artifact; @@ -107,37 +112,53 @@ addMember(treeGrid); - // TODO: i18n + icon - Button plusBtn = new Button("+"); - plusBtn.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - plusClicked(); - } - }); - - addMember(plusBtn); + if (showButton) { + addMember(createPlusButton()); + } triggerTreeBuilding(); } + + /** + * @param handler Handler to be added (notified on add-action). + */ + public DatacageWidget(Artifact artifact, User user, String outs, + DatacageHandler handler) { + this(artifact, user, outs); + this.addDatacageHandler(handler); + } + + + /** + * @param handler Handler to be added (notified on add-action). + */ public void addDatacageHandler(DatacageHandler handler) { if (!handlers.contains(handler)) { handlers.add(handler); } } + + /** + * @param handler Handler to remove from list. + */ public void removeDatacageHandler(DatacageHandler handler) { handlers.remove(handler); } + public ToLoad getToLoad() { return toLoad; } - public void plusClicked() { + + public ToLoad getSelection() { + // Reset content of toLoads. + toLoad = new ToLoad(); + if (treeGrid == null) { - return; + return toLoad; } ListGridRecord [] selection = treeGrid.getSelection(); @@ -150,17 +171,41 @@ } } - if (!toLoad.isEmpty()) { + return toLoad; + } + + + /** + * Callback for add-button. + * Fires to load for every selected element and handler. + */ + public void plusClicked() { + if (!getSelection().isEmpty()) { fireToLoad(); } } + + protected Button createPlusButton() { + // TODO: i18n + icon + Button plusBtn = new Button("+"); + plusBtn.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + plusClicked(); + } + }); + return plusBtn; + } + + protected void fireToLoad() { for (DatacageHandler handler: handlers) { handler.toLoad(toLoad); } } + protected void doubleClickedOnTree(RecordDoubleClickEvent event) { TreeNode node = (TreeNode)event.getRecord(); @@ -168,6 +213,7 @@ destroy(); } + protected void collectToLoads(TreeNode node) { Stack stack = new Stack();