Mercurial > dive4elements > river
changeset 1298:b0ed67cb5197
Minor refactoring, improved displayed Strings in W-Diff branch.
flys-client/trunk@2920 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Mon, 10 Oct 2011 10:02:16 +0000 |
parents | 887eb0cd7dfc |
children | f4f30d758550 |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacagePairWidget.java flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageTwinPanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/RecommendationPairRecord.java |
diffstat | 4 files changed, 194 insertions(+), 54 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Mon Oct 10 09:31:08 2011 +0000 +++ b/flys-client/ChangeLog Mon Oct 10 10:02:16 2011 +0000 @@ -1,3 +1,11 @@ +2011-10-10 Felix Wolfsteller <felix.wolfsteller@intevation.de> + + * src/main/java/de/intevation/flys/client/client/ui/RecommendationPairRecord.java: + New file. Extracted from DatacagePairWidget. + + * src/main/java/de/intevation/flys/client/client/ui/DatacagePairWidget.java: + Extracted RecommendationPairRecord implementation and constats. + 2011-10-10 Ingo Weinzierl <ingo@intevation.de> flys/issue375 (ÜSK, Streckemessung)
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacagePairWidget.java Mon Oct 10 09:31:08 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacagePairWidget.java Mon Oct 10 10:02:16 2011 +0000 @@ -35,61 +35,12 @@ /** The "remote" ListGrid to insert data to when add-button is clicked. */ protected ListGrid grid; - /** First attribute-name for StringPairRecord. */ - protected static final String ATTRIBUTE_FIRST = "first"; - - /** Second attribute-name for StringPairRecord. */ - protected static final String ATTRIBUTE_SECOND = "second"; - /** First (upper) DataCage Grid. */ protected DatacageWidget firstDatacageWidget; /** Second (lower) DataCage Grid. */ protected DatacageWidget secondDatacageWidget; - - - /** - * Two strings to be displayed in a GridList, derived from two - * Recommendations. - */ - protected class RecommendationPairRecord extends ListGridRecord { - Recommendation first; - Recommendation second; - String firstName; - String secondName; - - public RecommendationPairRecord() { - } - - public RecommendationPairRecord(String firstName, - Recommendation first, - String secondName, - Recommendation second) - { - setFirst(first, firstName); - setSecond(second, secondName); - } - - - public void setFirst(Recommendation first, String name) { - this.first = first; - this.firstName = name; - setAttribute(ATTRIBUTE_FIRST, name); - } - - - public void setSecond(Recommendation second, String name) { - this.second = second; - this.secondName = name; - setAttribute(ATTRIBUTE_SECOND, name); - } - - public Recommendation getFirst() {return first;} - public Recommendation getSecond() {return second;} - public String getFirstName() {return firstName;} - public String getSecondName() {return secondName;} - } - + /** *
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageTwinPanel.java Mon Oct 10 09:31:08 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageTwinPanel.java Mon Oct 10 10:02:16 2011 +0000 @@ -68,11 +68,76 @@ } + /** + * Remove first occurrence of "[" and "]" (if both do occur). + * @param value String to be stripped of [] (might be null). + * @return input string but with [ and ] removed, or input string if no + * brackets were found. + * @see StringUtil.unbracket + */ + public static final String unbracket(String value) { + // null- guard. + if (value == null) return value; + + int start = value.indexOf("["); + int end = value.indexOf("]"); + + if (start < 0 || end < 0) { + return value; + } + + value = value.substring(start + 1, end); + + return value; + } + + + /** + * Create a recommendation from a string representation of it. + * @TODO describe format of input string + * @param from string in format as shown above. + * @return recommendation from input string. + */ + public Recommendation createRecommendationFromString(String from) { + // TODO Construct "real" filter. + String[] parts = unbracket(from).split(";"); + Recommendation.Filter filter = new Recommendation.Filter(); + Recommendation.Facet facet = new Recommendation.Facet( + parts[1], + parts[2]); + + List<Recommendation.Facet> facets = new ArrayList<Recommendation.Facet> + (); + facets.add(facet); + filter.add("longitudinal_section", facets); + Recommendation r = new Recommendation("waterlevel", parts[0], + this.artifact.getUuid(), filter); + return r; + } + + + /** + * Add RecomendationPairRecords from input String to the ListGrid. + */ + public void populateGridFromString(String from){ + // Split this string. + // Create according recommendations and display strings. + String[] recs = from.split("#"); + // TODO real name + if (recs.length % 2 != 0) return; + for (int i = 0; i < recs.length; i+=2) { + Recommendation minuend = createRecommendationFromString(recs[i+0]); + Recommendation subtrahend = createRecommendationFromString(recs[i+1]); + RecommendationPairRecord pr = new RecommendationPairRecord( + "A", minuend, "B", subtrahend); + this.differencesList.addData(pr); + } + } + + @Override public Canvas create(DataList dataList) { GWT.log("createData()"); - Data data = dataList.get(0); - this.dataName = data.getLabel(); // TODO use i18n of data. Canvas label = new Label("Subtrahend/Minuend");//data.getDescription()); @@ -91,6 +156,24 @@ layout.setMembersMargin(10); this.helperContainer.addMember(helperLayout); + // Find old data, if any. + Data data = dataList.get(0); + // "diffids" data handling. + this.dataName = data.getLabel(); + for (int i = 0; i < dataList.size(); i++) { + if (dataList.get(i) != null) { + if (dataList.get(i).getItems() != null) { + populateGridFromString(dataList.get(i).getItems()[0].getStringValue()); + } + else{ + System.out.println("DatacageTwinPanel: Datalist for item is null"); + } + } + else{ + System.out.println("DatacageTwinPanel: Data " + i + " is null (not displayable)."); + } + } + return layout; } @@ -146,8 +229,8 @@ Set<Recommendation> ar = new HashSet<Recommendation>(); for (ListGridRecord record : records) { - DatacagePairWidget.RecommendationPairRecord r = - (DatacagePairWidget.RecommendationPairRecord) record; + RecommendationPairRecord r = + (RecommendationPairRecord) record; ar.add(r.getFirst()); ar.add(r.getSecond()); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/RecommendationPairRecord.java Mon Oct 10 10:02:16 2011 +0000 @@ -0,0 +1,98 @@ +package de.intevation.flys.client.client.ui; + +import com.smartgwt.client.widgets.grid.ListGridRecord; +import de.intevation.flys.client.shared.model.Recommendation; + + +/** + * Two strings to be displayed in a GridList, derived from two + * Recommendations. + */ +public class RecommendationPairRecord extends ListGridRecord { + + /** First attribute-name for StringPairRecord. */ + protected static final String ATTRIBUTE_FIRST = "first"; + + /** Second attribute-name for StringPairRecord. */ + protected static final String ATTRIBUTE_SECOND = "second"; + + Recommendation first; + Recommendation second; + String firstName; + String secondName; + + + public RecommendationPairRecord() { + } + + + public RecommendationPairRecord(String firstName, + Recommendation first, + String secondName, + Recommendation second) + { + setFirst(first, firstName); + setSecond(second, secondName); + } + + + public void setFirst(Recommendation first, String name) { + this.first = first; + this.firstName = name; + setAttribute(ATTRIBUTE_FIRST, name); + } + + + public void setSecond(Recommendation second, String name) { + this.second = second; + this.secondName = name; + setAttribute(ATTRIBUTE_SECOND, name); + } + + + public Recommendation getFirst() { + return first; + } + + + public Recommendation getSecond() { + return second; + } + + + public String getFirstName() { + return firstName; + } + + + public String getSecondName() { + return secondName; + } + +/* + * public static Recommmendation recommendationfromString(String from, + String factory, String masterArtifactId) + { + String parts = StringUtil.unbracket(from).split(";"); + // TODO proper filter instead of null. + Recommendation r = new Recommendation(factory, parts[0], + masterArtifactId, null); + return r; + } + + public static RecommendationPairRecord[] fromString(String from, + String masterArtifactId) + { + if (from == null) { + return new RecommendationPairRecord[] {}; + } + + //List<RecommendationPairRecord> + String recs = from.split("#"); + for (int i = 0; i < recs.length; i+=2) { + Recommendation minuend = recommendationfromString(recs[i+0], "waterlevel", masterArtifactId); + Recommendation subtrahend = recommendationfromString(recs[i+0], "waterlevel", masterArtifactId); + } + return new RecommendationPairRecord[] {}; + }*/ +}