Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/BedHeightsDatacagePanel.java @ 8852:8f6d6d26e96f
Refaktored the DatacageTwinPanel so it is reusable.
author | gernotbelger |
---|---|
date | Thu, 18 Jan 2018 18:32:30 +0100 |
parents | 22169da49f9b |
children | 28df64078f27 |
comparison
equal
deleted
inserted
replaced
8851:13650d8a2373 | 8852:8f6d6d26e96f |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.client.client.ui.minfo; | 9 package org.dive4elements.river.client.client.ui.minfo; |
10 | 10 |
11 import java.util.List; | |
12 | |
13 import org.dive4elements.river.client.client.ui.AbstractPairRecommendationPanel; | |
14 import org.dive4elements.river.client.client.ui.DatacageWidget; | |
15 import org.dive4elements.river.client.client.ui.DefaultDatacageTwinPanelInfo; | |
16 import org.dive4elements.river.client.client.ui.RecommendationPairRecord; | |
17 import org.dive4elements.river.client.client.ui.WaterlevelTwinPanelValidator; | |
18 import org.dive4elements.river.client.shared.model.DataList; | |
19 import org.dive4elements.river.client.shared.model.ToLoad; | |
20 import org.dive4elements.river.client.shared.model.User; | |
21 | |
11 import com.google.gwt.core.client.GWT; | 22 import com.google.gwt.core.client.GWT; |
12 | |
13 import com.smartgwt.client.util.SC; | 23 import com.smartgwt.client.util.SC; |
14 import com.smartgwt.client.widgets.Button; | 24 import com.smartgwt.client.widgets.Button; |
15 import com.smartgwt.client.widgets.Canvas; | 25 import com.smartgwt.client.widgets.Canvas; |
16 | |
17 import com.smartgwt.client.widgets.events.ClickEvent; | 26 import com.smartgwt.client.widgets.events.ClickEvent; |
18 import com.smartgwt.client.widgets.events.ClickHandler; | 27 import com.smartgwt.client.widgets.events.ClickHandler; |
19 | 28 import com.smartgwt.client.widgets.grid.ListGrid; |
20 import com.smartgwt.client.widgets.layout.VLayout; | 29 import com.smartgwt.client.widgets.layout.VLayout; |
21 import com.smartgwt.client.widgets.tree.TreeNode; | 30 import com.smartgwt.client.widgets.tree.TreeNode; |
22 | 31 |
23 import org.dive4elements.river.client.client.FLYSConstants; | |
24 | |
25 import org.dive4elements.river.client.client.services.LoadArtifactServiceAsync; | |
26 import org.dive4elements.river.client.client.services.RemoveArtifactServiceAsync; | |
27 | |
28 import org.dive4elements.river.client.client.ui.DatacageTwinPanel; | |
29 import org.dive4elements.river.client.client.ui.DatacageWidget; | |
30 import org.dive4elements.river.client.client.ui.RecommendationPairRecord; | |
31 | |
32 import org.dive4elements.river.client.shared.model.DataList; | |
33 import org.dive4elements.river.client.shared.model.ToLoad; | |
34 | |
35 import org.dive4elements.river.client.shared.model.Recommendation; | |
36 import org.dive4elements.river.client.shared.model.User; | |
37 | |
38 import java.util.ArrayList; | |
39 import java.util.List; | |
40 | |
41 // TODO Probably better to branch off AbstractUIProvider. | |
42 public class BedHeightsDatacagePanel | 32 public class BedHeightsDatacagePanel |
43 extends DatacageTwinPanel { | 33 extends AbstractPairRecommendationPanel { |
44 | |
45 protected static FLYSConstants MSG = GWT.create(FLYSConstants.class); | |
46 | |
47 /** | |
48 * List to track previously selected but now removed pairs. (Needed to | |
49 * be able to identify artifacts that can be removed from the collection. | |
50 */ | |
51 protected List<RecommendationPairRecord> removedPairs = | |
52 new ArrayList<RecommendationPairRecord>(); | |
53 | |
54 /** Service handle to clone and add artifacts to collection. */ | |
55 LoadArtifactServiceAsync loadArtifactService = GWT.create( | |
56 org.dive4elements.river.client.client.services.LoadArtifactService.class); | |
57 | |
58 /** Service to remove artifacts from collection. */ | |
59 RemoveArtifactServiceAsync removeArtifactService = GWT.create( | |
60 org.dive4elements.river.client.client.services.RemoveArtifactService.class); | |
61 | |
62 protected DatacageWidget datacage; | |
63 | 34 |
64 public BedHeightsDatacagePanel(User user) { | 35 public BedHeightsDatacagePanel(User user) { |
65 super(user); | 36 // FIXME: This will lead to a bad error message in English (i.e. contains something about waterlevels), for M-Info/Bed-Differences calculation |
37 // BUT: this is the behavior of 3.2.1 (because of sloppy derivation), so we do not change it now | |
38 super(user, new WaterlevelTwinPanelValidator(), new DefaultDatacageTwinPanelInfo("bedheight", null), new DefaultDatacageTwinPanelInfo("bedheight", null) ); | |
66 } | 39 } |
67 | 40 |
68 /** | |
69 * Creates the graphical representation and interaction widgets for the data. | |
70 * @param dataList the data. | |
71 * @return graphical representation and interaction widgets for data. | |
72 */ | |
73 @Override | 41 @Override |
74 public Canvas create(DataList dataList) { | 42 protected Canvas createChooserWidgets(final Canvas widget, final DataList dataList, final User user, final ListGrid differencesList) { |
75 GWT.log("createData()"); | 43 GWT.log("createData()"); |
76 | 44 |
77 Canvas widget = createWidget(); | |
78 Canvas submit = getNextButton(); | 45 Canvas submit = getNextButton(); |
79 datacage = new DatacageWidget( | 46 |
47 final DatacageWidget datacage = new DatacageWidget( | |
80 this.artifact, user, "minfo_diff_panel", "load-system:true", false); | 48 this.artifact, user, "minfo_diff_panel", "load-system:true", false); |
81 | 49 |
82 Button plusBtn = new Button(MSG.datacage_add_pair()); | 50 Button plusBtn = new Button(msg().datacage_add_pair()); |
83 plusBtn.setAutoFit(true); | 51 plusBtn.setAutoFit(true); |
84 plusBtn.addClickHandler(new ClickHandler() { | 52 plusBtn.addClickHandler(new ClickHandler() { |
85 @Override | 53 @Override |
86 public void onClick(ClickEvent event) { | 54 public void onClick(ClickEvent event) { |
87 plusClicked(); | 55 plusClicked(datacage, differencesList); |
88 } | 56 } |
89 }); | 57 }); |
90 | 58 |
91 VLayout layout = new VLayout(); | 59 VLayout layout = new VLayout(); |
92 VLayout helperLayout = new VLayout(); | 60 VLayout helperLayout = new VLayout(); |
96 layout.addMember(widget); | 64 layout.addMember(widget); |
97 layout.addMember(submit); | 65 layout.addMember(submit); |
98 layout.setMembersMargin(10); | 66 layout.setMembersMargin(10); |
99 this.helperContainer.addMember(helperLayout); | 67 this.helperContainer.addMember(helperLayout); |
100 | 68 |
101 populateGrid(dataList, "bedheight"); | |
102 | |
103 return layout; | 69 return layout; |
104 } | |
105 | |
106 public void adjustRecommendation(Recommendation recommendation) { | |
107 recommendation.setFactory("bedheight"); | |
108 } | |
109 | |
110 @Override | |
111 protected String createDataString(String artifact, Recommendation recommendation) { | |
112 return createDataString(artifact, recommendation, "bedheight"); | |
113 } | 70 } |
114 | 71 |
115 /** | 72 /** |
116 * Callback for add-button. | 73 * Callback for add-button. |
117 * Fires to load for every selected element and handler. | 74 * Fires to load for every selected element and handler. |
75 * @param differencesList | |
118 */ | 76 */ |
119 public void plusClicked() { | 77 protected final static void plusClicked( final DatacageWidget datacage, ListGrid differencesList ) { |
120 List<TreeNode> selection = datacage.getPlainSelection(); | 78 List<TreeNode> selection = datacage.getPlainSelection(); |
121 | 79 |
122 if (selection == null || selection.isEmpty()) { | 80 if (selection == null || selection.isEmpty()) { |
123 SC.say(MSG.warning()); | 81 SC.say(msg().warning()); |
124 return; | 82 return; |
125 } | 83 } |
126 | 84 |
127 for (TreeNode node : selection) { | 85 for (TreeNode node : selection) { |
128 ToLoad toLoad1 = new ToLoad(); | 86 ToLoad toLoad1 = new ToLoad(); |