From e7bfcb4deda0effc4f6dd63d7c695a1287a1deaa Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Wed, 3 Sep 2014 10:01:01 +0000 Subject: [PATCH] Added Licences git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-extractcodelist-widget@99416 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/ExtractCodelistDetailsCard.java | 151 ++++++++++++++++++ .../licence/LicenceDataPropertiesCombo.java | 26 +++ 2 files changed, 177 insertions(+) create mode 100644 src/main/java/org/gcube/portlets/user/td/extractcodelistwidget/client/licence/LicenceDataPropertiesCombo.java diff --git a/src/main/java/org/gcube/portlets/user/td/extractcodelistwidget/client/ExtractCodelistDetailsCard.java b/src/main/java/org/gcube/portlets/user/td/extractcodelistwidget/client/ExtractCodelistDetailsCard.java index a9c79ce..85d3865 100644 --- a/src/main/java/org/gcube/portlets/user/td/extractcodelistwidget/client/ExtractCodelistDetailsCard.java +++ b/src/main/java/org/gcube/portlets/user/td/extractcodelistwidget/client/ExtractCodelistDetailsCard.java @@ -1,18 +1,43 @@ package org.gcube.portlets.user.td.extractcodelistwidget.client; +import java.util.ArrayList; +import java.util.Date; + +import org.gcube.portlets.user.td.extractcodelistwidget.client.licence.LicenceDataPropertiesCombo; +import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; +import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException; import org.gcube.portlets.user.td.gwtservice.shared.extract.ExtractCodelistSession; +import org.gcube.portlets.user.td.gwtservice.shared.licenses.LicenceData; import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource; +import org.gcube.portlets.user.td.monitorwidget.client.utils.UtilsGXT3; +import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent; +import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType; import org.gcube.portlets.user.td.wizardwidget.client.WizardCard; import com.allen_sauer.gwt.log.client.Log; +import com.google.gwt.core.client.GWT; +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.user.client.Command; +import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.VerticalPanel; +import com.sencha.gxt.data.client.loader.RpcProxy; +import com.sencha.gxt.data.shared.ListStore; +import com.sencha.gxt.data.shared.loader.ListLoadConfig; +import com.sencha.gxt.data.shared.loader.ListLoadConfigBean; +import com.sencha.gxt.data.shared.loader.ListLoadResult; +import com.sencha.gxt.data.shared.loader.ListLoadResultBean; +import com.sencha.gxt.data.shared.loader.ListLoader; +import com.sencha.gxt.data.shared.loader.LoadResultListStoreBinding; import com.sencha.gxt.widget.core.client.FramedPanel; import com.sencha.gxt.widget.core.client.box.AlertMessageBox; import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer; import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData; import com.sencha.gxt.widget.core.client.event.HideEvent; import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler; +import com.sencha.gxt.widget.core.client.form.ComboBox; +import com.sencha.gxt.widget.core.client.form.DateField; import com.sencha.gxt.widget.core.client.form.FieldLabel; import com.sencha.gxt.widget.core.client.form.FieldSet; import com.sencha.gxt.widget.core.client.form.TextArea; @@ -25,7 +50,9 @@ import com.sencha.gxt.widget.core.client.form.TextField; * */ public class ExtractCodelistDetailsCard extends WizardCard { + protected DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd"); + protected final String TABLEDETAILPANELWIDTH = "100%"; protected final String TABLEDETAILPANELHEIGHT = "100%"; protected final String FORMWIDTH = "538px"; @@ -39,8 +66,15 @@ public class ExtractCodelistDetailsCard extends WizardCard { protected TextField name; protected TextArea description; protected TextArea rights; + protected DateField validFrom; + protected DateField validUntilTo; + + protected ListLoader> loader; + protected ComboBox comboLicences; + protected TabResource detail = new TabResource(); + public ExtractCodelistDetailsCard(final ExtractCodelistSession extractCodelistSession) { super("Codelist Detail", ""); @@ -84,6 +118,62 @@ public class ExtractCodelistDetailsCard extends WizardCard { rights.setEmptyText("Enter rights..."); rights.setAllowBlank(false); p.add(new FieldLabel(rights, "Rights"), new VerticalLayoutData(1, -1)); + + validFrom = new DateField(); + validFrom.setValue(new Date()); + p.add(new FieldLabel(validFrom, "Valid From"), new VerticalLayoutData( + 1, -1)); + + validUntilTo = new DateField(); + p.add(new FieldLabel(validUntilTo, "Valid Until To"), + new VerticalLayoutData(1, -1)); + + // Combo Licences + LicenceDataPropertiesCombo propsLicenceData = GWT + .create(LicenceDataPropertiesCombo.class); + ListStore storeCombo = new ListStore( + propsLicenceData.id()); + + Log.debug("StoreCombo created"); + + RpcProxy> proxy = new RpcProxy>() { + + public void load(ListLoadConfig loadConfig, + final AsyncCallback> callback) { + loadData(loadConfig, callback); + } + }; + + loader = new ListLoader>( + proxy) { + @Override + protected ListLoadConfig newLoadConfig() { + return (ListLoadConfig) new ListLoadConfigBean(); + } + + }; + + loader.addLoadHandler(new LoadResultListStoreBinding>( + storeCombo)); + Log.trace("LoaderCombo created"); + + comboLicences = new ComboBox(storeCombo, + propsLicenceData.licence()) { + + protected void onAfterFirstAttach() { + super.onAfterFirstAttach(); + Scheduler.get().scheduleDeferred(new ScheduledCommand() { + public void execute() { + loader.load(); + } + }); + } + }; + Log.trace("Combo Licence created"); + + // / + p.add(new FieldLabel(comboLicences, "Licence"), + new VerticalLayoutData(1, -1)); tableDetailPanel.add(form); @@ -92,6 +182,38 @@ public class ExtractCodelistDetailsCard extends WizardCard { } + protected void loadData(ListLoadConfig loadConfig, + final AsyncCallback> callback) { + TDGWTServiceAsync.INSTANCE + .getLicences(new AsyncCallback>() { + + public void onFailure(Throwable caught) { + if (caught instanceof TDGWTSessionExpiredException) { + getEventBus() + .fireEvent( + new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); + } else { + Log.error("load combo failure:" + + caught.getLocalizedMessage()); + UtilsGXT3.alert("Error", + "Error retrieving licences."); + } + callback.onFailure(caught); + } + + public void onSuccess(ArrayList result) { + Log.trace("loaded " + result.size() + " ColumnData"); + callback.onSuccess(new ListLoadResultBean( + result)); + + } + + }); + + } + + @Override public void setup() { Command sayNextCard = new Command() { @@ -158,7 +280,36 @@ public class ExtractCodelistDetailsCard extends WizardCard { detail.setName(name.getCurrentValue()); detail.setDescription(description.getCurrentValue()); detail.setRight(rights.getCurrentValue()); + + Date vFrom = validFrom.getCurrentValue(); + if (vFrom == null) { + Log.debug("Valid From is null"); + } else { + try { + detail.setValidFrom(sdf.format(vFrom)); + } catch (Throwable e) { + Log.error("Error parsing Valid From " + + e.getLocalizedMessage()); + } + } + Date vUntilTo = validUntilTo.getCurrentValue(); + if (vUntilTo == null) { + Log.debug("Valid Until To is null"); + } else { + try { + detail.setValidUntilTo(sdf.format(vUntilTo)); + } catch (Throwable e) { + Log.error("Error parsing Valid Until To " + + e.getLocalizedMessage()); + } + } + + if(comboLicences.getCurrentValue()!=null&& comboLicences.getCurrentValue().getLicence()!=null){ + detail.setLicence(comboLicences.getCurrentValue().getLicence()); + } + + extractCodelistSession.setTabResource(detail); ExtractCodelistOperationInProgressCard csvOperationInProgressCard = new ExtractCodelistOperationInProgressCard( diff --git a/src/main/java/org/gcube/portlets/user/td/extractcodelistwidget/client/licence/LicenceDataPropertiesCombo.java b/src/main/java/org/gcube/portlets/user/td/extractcodelistwidget/client/licence/LicenceDataPropertiesCombo.java new file mode 100644 index 0000000..ec76b20 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/extractcodelistwidget/client/licence/LicenceDataPropertiesCombo.java @@ -0,0 +1,26 @@ +package org.gcube.portlets.user.td.extractcodelistwidget.client.licence; + +import org.gcube.portlets.user.td.gwtservice.shared.licenses.LicenceData; + +import com.google.gwt.editor.client.Editor.Path; +import com.sencha.gxt.data.shared.LabelProvider; +import com.sencha.gxt.data.shared.ModelKeyProvider; +import com.sencha.gxt.data.shared.PropertyAccess; + + +/** + * + * @author "Giancarlo Panichi" + * g.panichi@isti.cnr.it + * + */ +public interface LicenceDataPropertiesCombo extends + PropertyAccess { + + @Path("id") + ModelKeyProvider id(); + + LabelProvider licence(); + + +} \ No newline at end of file