Added Licences

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-csv-import-widget@99404 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-09-02 16:31:31 +00:00
parent 5b5e688fa1
commit bfa092d0e4
2 changed files with 137 additions and 3 deletions

View File

@ -3,22 +3,43 @@
*/
package org.gcube.portlets.user.td.csvimportwidget.client;
import java.util.ArrayList;
import java.util.Date;
import org.gcube.portlets.user.td.csvimportwidget.client.licence.LicenceDataPropertiesCombo;
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
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;
@ -52,6 +73,10 @@ public class CSVTableDetailCard extends WizardCard {
protected TabResource detail = new TabResource();
private ListLoader<ListLoadConfig, ListLoadResult<LicenceData>> loader;
private ComboBox<LicenceData> comboLicences;
public CSVTableDetailCard(final CSVImportSession importSession) {
super("Tabular Resource Detail", "");
@ -103,12 +128,88 @@ public class CSVTableDetailCard extends WizardCard {
p.add(new FieldLabel(validUntilTo, "Valid Until To"),
new VerticalLayoutData(1, -1));
// Combo Licences
LicenceDataPropertiesCombo propsLicenceData = GWT
.create(LicenceDataPropertiesCombo.class);
ListStore<LicenceData> storeCombo = new ListStore<LicenceData>(
propsLicenceData.id());
Log.debug("StoreCombo created");
RpcProxy<ListLoadConfig, ListLoadResult<LicenceData>> proxy = new RpcProxy<ListLoadConfig, ListLoadResult<LicenceData>>() {
public void load(ListLoadConfig loadConfig,
final AsyncCallback<ListLoadResult<LicenceData>> callback) {
loadData(loadConfig, callback);
}
};
loader = new ListLoader<ListLoadConfig, ListLoadResult<LicenceData>>(
proxy) {
@Override
protected ListLoadConfig newLoadConfig() {
return (ListLoadConfig) new ListLoadConfigBean();
}
};
loader.addLoadHandler(new LoadResultListStoreBinding<ListLoadConfig, LicenceData, ListLoadResult<LicenceData>>(
storeCombo));
Log.trace("LoaderCombo created");
comboLicences = new ComboBox<LicenceData>(storeCombo,
propsLicenceData.licence()) {
protected void onAfterFirstAttach() {
super.onAfterFirstAttach();
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
public void execute() {
loader.load();
}
});
}
};
Log.trace("Combo Licence created");
// /
tableDetailPanel.add(form);
setContent(tableDetailPanel);
}
protected void loadData(ListLoadConfig loadConfig,
final AsyncCallback<ListLoadResult<LicenceData>> callback) {
TDGWTServiceAsync.INSTANCE
.getLicences(new AsyncCallback<ArrayList<LicenceData>>() {
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<LicenceData> result) {
Log.trace("loaded " + result.size() + " ColumnData");
callback.onSuccess(new ListLoadResultBean<LicenceData>(
result));
}
});
}
@Override
public void setup() {
Command sayNextCard = new Command() {
@ -160,13 +261,15 @@ public class CSVTableDetailCard extends WizardCard {
if (description.getValue() == null
|| description.getValue().isEmpty()
|| !description.isValid()) {
d = new AlertMessageBox("Attention!", "Fill in description field");
d = new AlertMessageBox("Attention!",
"Fill in description field");
d.addHideHandler(hideHandler);
d.show();
} else {
if (rights.getValue() == null || rights.getValue().isEmpty()
|| !rights.isValid()) {
d = new AlertMessageBox("Attention!", "Fill in rights field");
d = new AlertMessageBox("Attention!",
"Fill in rights field");
d.addHideHandler(hideHandler);
d.show();
} else {
@ -184,7 +287,7 @@ public class CSVTableDetailCard 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");
@ -208,6 +311,11 @@ public class CSVTableDetailCard extends WizardCard {
+ e.getLocalizedMessage());
}
}
if(comboLicences.getCurrentValue()!=null&& comboLicences.getCurrentValue().getLicence()!=null){
detail.setLicence(comboLicences.getCurrentValue().getLicence());
}
importSession.setTabResource(detail);
CSVOperationInProgressCard csvOperationInProgressCard = new CSVOperationInProgressCard(

View File

@ -0,0 +1,26 @@
package org.gcube.portlets.user.td.csvimportwidget.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"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public interface LicenceDataPropertiesCombo extends
PropertyAccess<LicenceData> {
@Path("id")
ModelKeyProvider<LicenceData> id();
LabelProvider<LicenceData> licence();
}