Mercurial > dive4elements > river
diff gwt-client/src/main/java/org/dive4elements/river/client/client/ui/AbstractPairRecommendationPanel.java @ 9227:84397da33d17
Allow to control specific behaviour in TwinDatacagePanel
Implemented client logic of 'intelligent datacage filtering' for SINFO
author | gernotbelger |
---|---|
date | Wed, 04 Jul 2018 18:28:08 +0200 |
parents | 8d1df8639563 |
children | 839b2aa84dd0 |
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/AbstractPairRecommendationPanel.java Wed Jul 04 17:14:16 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/AbstractPairRecommendationPanel.java Wed Jul 04 18:28:08 2018 +0200 @@ -52,39 +52,36 @@ public abstract class AbstractPairRecommendationPanel extends TextProvider { - /** - * Allows for abstraction on how to handle/serialize the recommendation and the used factories. - * Basically this allows to tweak the factory that is delivered from the datacage to be replaced by a specific one... - * - * @author Gernot Belger - */ - public static interface IRecommendationInfo { - - String getFactory(String originalFactory); + /** + * Allows for abstraction on how to handle/serialize the recommendation and the used factories. + * Basically this allows to tweak the factory that is delivered from the datacage to be replaced by a specific one... + * + * @author Gernot Belger + */ + public static interface IRecommendationInfo { - /** - * Separate factory for the 'createDataString' method, because in the case of waterlevels. See HOTFIX/FIXME there. - * @param recommendation - */ - String getDataStringFactory(Recommendation recommendation); + String getFactory(String originalFactory); - /** - * Set factory of recommendation such that the correct artifacts will - * be cloned for difference calculations. - */ - void adjustRecommendation(Recommendation recommendation); - } - - public static interface IValidator - { - List<String> validate(ListGrid differencesList, FLYSConstants msgProvider); - } + /** + * Separate factory for the 'createDataString' method, because in the case of waterlevels. See HOTFIX/FIXME there. + * @param recommendation + */ + String getDataStringFactory(Recommendation recommendation); + + /** + * Set factory of recommendation such that the correct artifacts will + * be cloned for difference calculations. + */ + void adjustRecommendation(Recommendation recommendation); + } + + public static interface IValidator + { + List<String> validate(ListGrid differencesList, FLYSConstants msgProvider); + } private static final long serialVersionUID = 8906629596491827857L; - // FIXME: why? we hide the field of the super class with exactly the same thing... - private static FLYSConstants MSG_PROVIDER = GWT.create(FLYSConstants.class); - private String dataName; private final User user; @@ -97,7 +94,7 @@ * be able to identify artifacts that can be removed from the collection. */ private final List<RecommendationPairRecord> removedPairs = - new ArrayList<RecommendationPairRecord>(); + new ArrayList<RecommendationPairRecord>(); /** Service handle to clone and add artifacts to collection. */ private final LoadArtifactServiceAsync loadArtifactService = GWT.create( @@ -107,28 +104,28 @@ private final RemoveArtifactServiceAsync removeArtifactService = GWT.create( org.dive4elements.river.client.client.services.RemoveArtifactService.class); - private final IRecommendationInfo leftInfo; - - private final IRecommendationInfo rightInfo; + private final IRecommendationInfo leftInfo; - private final IValidator validator; + private final IRecommendationInfo rightInfo; - /** - * @param Validates the content of this form when the user clicks 'apply' - * @param leftInfo Delegate for handling the left part of the recommendation-pair - * @param rightInfo Delegate for handling the right part of the recommendation-pair - */ + private final IValidator validator; + + /** + * @param Validates the content of this form when the user clicks 'apply' + * @param leftInfo Delegate for handling the left part of the recommendation-pair + * @param rightInfo Delegate for handling the right part of the recommendation-pair + */ public AbstractPairRecommendationPanel(final User user, final IValidator validator, final IRecommendationInfo leftInfo, final IRecommendationInfo rightInfo ) { this.user = user; - this.validator = validator; - this.leftInfo = leftInfo; - this.rightInfo = rightInfo; + this.validator = validator; + this.leftInfo = leftInfo; + this.rightInfo = rightInfo; } - + // FIXME: better than copy/pasting the MSG field into every sub-class but not really nice yet. protected final static FLYSConstants msg() { - return MSG_PROVIDER; - } + return MSG; + } /** * Remove first occurrence of "[" and "]" (if both do occur). @@ -155,7 +152,7 @@ /** * Create a recommendation from a string representation of it. * @param from string in format as shown above. - * @param leftInfo2 + * @param leftInfo2 * @return recommendation from input string. */ private Recommendation createRecommendationFromString(final String from, final IRecommendationInfo info) { @@ -169,7 +166,7 @@ final List<Recommendation.Facet> facets = new ArrayList<Recommendation.Facet>(); facets.add(facet); filter.add("longitudinal_section", facets); - + final String factory = info.getFactory( parts[1] ); final Recommendation r = new Recommendation(factory, parts[0], this.artifact.getUuid(), filter); @@ -188,12 +185,12 @@ if (recs.length % 2 != 0) return; for (int i = 0; i < recs.length; i+=2) { final Recommendation minuend = - createRecommendationFromString(recs[i+0], this.leftInfo); + createRecommendationFromString(recs[i+0], this.leftInfo); final Recommendation subtrahend = - createRecommendationFromString(recs[i+1], this.rightInfo); + createRecommendationFromString(recs[i+1], this.rightInfo); final RecommendationPairRecord pr = new RecommendationPairRecord( - minuend, subtrahend); + minuend, subtrahend); // This Recommendation Pair comes from the data string and was thus // already cloned. pr.setIsAlreadyLoaded(true); @@ -208,13 +205,13 @@ */ @Override public final Canvas create(final DataList dataList) { - + final Canvas widget = createWidget(); - - final Canvas canvas = createChooserWidgets(widget, dataList, this.user, this.differencesList); - + + final Canvas canvas = createChooserWidgets(widget, dataList, this.user, this.differencesList); + populateGrid(dataList); - + return canvas; } @@ -223,14 +220,14 @@ */ protected abstract Canvas createChooserWidgets(final Canvas widget, final DataList dataList, final User auser, final ListGrid diffList); - private void populateGrid(final DataList dataList) { + private void populateGrid(final DataList dataList) { final Data data = dataList.get(0); this.dataName = data.getLabel(); for (int i = 0; i < dataList.size(); i++) { if (dataList.get(i) != null && dataList.get(i).getItems() != null) { if (dataList.get(i).getItems() != null) { populateGridFromString( - dataList.get(i).getItems()[0].getStringValue()); + dataList.get(i).getItems()[0].getStringValue()); } } } @@ -238,7 +235,7 @@ @Override public final List<String> validate() { - return this.validator.validate(this.differencesList, MSG_PROVIDER); + return this.validator.validate(this.differencesList, msg()); } /** @@ -259,34 +256,34 @@ // Track removed rows, therefore more or less reimplement // setCanRecomeRecords. final ListGridField removeField = - new ListGridField("_removeRecord", "Remove Record"){{ - setType(ListGridFieldType.ICON); - setIcon(GWT.getHostPageBaseURL() + msg().removeFeature()); - setCanEdit(false); - setCanFilter(false); - setCanSort(false); - setCanGroupBy(false); - setCanFreeze(false); - setWidth(25); - }}; - - this.differencesList.setFields(new ListGridField[] {nameField, - capitalField, removeField}); + new ListGridField("_removeRecord", "Remove Record"){{ + setType(ListGridFieldType.ICON); + setIcon(GWT.getHostPageBaseURL() + msg().removeFeature()); + setCanEdit(false); + setCanFilter(false); + setCanSort(false); + setCanGroupBy(false); + setCanFreeze(false); + setWidth(25); + }}; - this.differencesList.addRecordClickHandler(new RecordClickHandler() { - @Override - public void onRecordClick(final RecordClickEvent event) { - // Just handle remove-clicks - if(!event.getField().getName().equals(removeField.getName())) { - return; + this.differencesList.setFields(new ListGridField[] {nameField, + capitalField, removeField}); + + this.differencesList.addRecordClickHandler(new RecordClickHandler() { + @Override + public void onRecordClick(final RecordClickEvent event) { + // Just handle remove-clicks + if(!event.getField().getName().equals(removeField.getName())) { + return; + } + trackRemoved(event.getRecord()); + event.getViewer().removeData(event.getRecord()); } - trackRemoved(event.getRecord()); - event.getViewer().removeData(event.getRecord()); - } - }); - layout.addMember(this.differencesList); + }); + layout.addMember(this.differencesList); - return layout; + return layout; } @@ -322,7 +319,7 @@ for (final ListGridRecord record : records) { final RecommendationPairRecord r = - (RecommendationPairRecord) record; + (RecommendationPairRecord) record; // Do not add "old" recommendations. if (!r.isAlreadyLoaded()) { // Check whether one of those is a dike or similar. @@ -374,47 +371,47 @@ // feedback. for(final String uuid: artifactIdsToRemove) { this.removeArtifactService.remove(this.collection, - uuid, - locale, - new AsyncCallback<Collection>() { - @Override - public void onFailure(final Throwable caught) { - GWT.log("RemoveArtifact (" + uuid + ") failed."); - } - @Override - public void onSuccess(final Collection coll) { - GWT.log("RemoveArtifact succeeded"); - } - }); + uuid, + locale, + new AsyncCallback<Collection>() { + @Override + public void onFailure(final Throwable caught) { + GWT.log("RemoveArtifact (" + uuid + ") failed."); + } + @Override + public void onSuccess(final Collection coll) { + GWT.log("RemoveArtifact succeeded"); + } + }); } // Clone new ones (and spawn statics), go forward. this.parameterList.lockUI(); this.loadArtifactService.loadMany( - this.collection, - toClone, - //"staticwkms" and "waterlevel" - null, - locale, - new AsyncCallback<Artifact[]>() { - @Override - public void onFailure(final Throwable caught) { - caught.printStackTrace(); - GWT.log("Failure of cloning with factories!"); - AbstractPairRecommendationPanel.this.parameterList.unlockUI(); - } - @Override - public void onSuccess(final Artifact[] artifacts) { - GWT.log("Successfully cloned " + toClone.length + - " with factories."); + this.collection, + toClone, + //"staticwkms" and "waterlevel" + null, + locale, + new AsyncCallback<Artifact[]>() { + @Override + public void onFailure(final Throwable caught) { + caught.printStackTrace(); + GWT.log("Failure of cloning with factories!"); + AbstractPairRecommendationPanel.this.parameterList.unlockUI(); + } + @Override + public void onSuccess(final Artifact[] artifacts) { + GWT.log("Successfully cloned " + toClone.length + + " with factories."); - fireStepForwardEvent(new StepForwardEvent( - getData(toClone, artifacts, toUse))); - AbstractPairRecommendationPanel.this.parameterList.unlockUI(); - } - }); + fireStepForwardEvent(new StepForwardEvent( + getData(toClone, artifacts, toUse))); + AbstractPairRecommendationPanel.this.parameterList.unlockUI(); + } + }); } - + /** * Create Data and DataItem from selection (a long string with identifiers * to construct diff-pairs). @@ -440,21 +437,21 @@ final String uuid = newArtifact.getUuid(); r.setMasterArtifact(uuid); - if (i>0) - dataItemString += "#"; + if (i>0) + dataItemString += "#"; // REMARK: ugly, but we know that the recommandations comes in left/right pairs. final IRecommendationInfo info = i % 2 == 0 ? this.leftInfo : this.rightInfo; - + dataItemString += createDataString(uuid, r, info); } for (int i = 0; i < oldRecommendations.length; i++) { final Recommendation r = oldRecommendations[i]; final String uuid = r.getIDs(); - - if (dataItemString.length() > 0) - dataItemString += "#"; + + if (dataItemString.length() > 0) + dataItemString += "#"; // REMARK: ugly, but we know that the recommandations comes in left/right pairs. final IRecommendationInfo info = i % 2 == 0 ? this.leftInfo : this.rightInfo; @@ -466,7 +463,7 @@ // (e.g. one per pair). final DataItem item = new DefaultDataItem(this.dataName, this.dataName, dataItemString); return new Data[] { new DefaultData( - this.dataName, null, null, new DataItem[] {item}) }; + this.dataName, null, null, new DataItem[] {item}) }; } /** @@ -475,35 +472,35 @@ * @param info Provides the factory to encode. */ protected static final String createDataString(final String artifactUuid, final Recommendation recommendation, final IRecommendationInfo info) { - final String factory = info.getDataStringFactory( recommendation ); - - final Filter filter = recommendation.getFilter(); - Facet f = null; - - if(filter != null) { - final Map<String, List<Facet>> outs = filter.getOuts(); - final Set<Map.Entry<String, List<Facet>>> entries = outs.entrySet(); - - for (final Map.Entry<String, List<Facet>> entry: entries) { - final List<Facet> fs = entry.getValue(); - - f = fs.get(0); - if (f != null) { - break; - } - } - - return "[" + artifactUuid + ";" - + f.getName() - + ";" - + f.getIndex() - + ";" - + recommendation.getDisplayName() + "]"; - } - - return "[" - + artifactUuid - + ";" + factory + ";0;" - + recommendation.getDisplayName() + "]"; + final String factory = info.getDataStringFactory( recommendation ); + + final Filter filter = recommendation.getFilter(); + Facet f = null; + + if(filter != null) { + final Map<String, List<Facet>> outs = filter.getOuts(); + final Set<Map.Entry<String, List<Facet>>> entries = outs.entrySet(); + + for (final Map.Entry<String, List<Facet>> entry: entries) { + final List<Facet> fs = entry.getValue(); + + f = fs.get(0); + if (f != null) { + break; + } + } + + return "[" + artifactUuid + ";" + + f.getName() + + ";" + + f.getIndex() + + ";" + + recommendation.getDisplayName() + "]"; + } + + return "[" + + artifactUuid + + ";" + factory + ";0;" + + recommendation.getDisplayName() + "]"; } } \ No newline at end of file