Added Licences

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-information-widget@99417 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-09-03 10:01:10 +00:00
parent f8cef8f658
commit 7069895801
2 changed files with 151 additions and 15 deletions

View File

@ -3,14 +3,17 @@ package org.gcube.portlets.user.td.informationwidget.client;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
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.licenses.LicenceData;
import org.gcube.portlets.user.td.gwtservice.shared.share.Contacts;
import org.gcube.portlets.user.td.gwtservice.shared.share.ShareInfo;
import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource;
import org.gcube.portlets.user.td.gwtservice.shared.tr.TableData;
import org.gcube.portlets.user.td.informationwidget.client.custom.IconButton;
import org.gcube.portlets.user.td.informationwidget.client.licence.LicenceDataPropertiesCombo;
import org.gcube.portlets.user.td.informationwidget.client.resources.ResourceBundle;
import org.gcube.portlets.user.td.informationwidget.client.util.UtilsGXT3;
import org.gcube.portlets.user.td.metadatawidget.client.TRMetadataAccordionPanel;
@ -24,6 +27,9 @@ import org.gcube.portlets.user.td.widgetcommonevent.client.type.WidgetRequestTyp
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
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.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
@ -34,6 +40,14 @@ import com.google.web.bindery.event.shared.EventBus;
import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign;
import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode;
import com.sencha.gxt.core.client.util.Margins;
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.button.TextButton;
import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutData;
@ -43,6 +57,7 @@ import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.Verti
import com.sencha.gxt.widget.core.client.event.SelectEvent;
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
import com.sencha.gxt.widget.core.client.form.CheckBox;
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;
@ -50,8 +65,9 @@ import com.sencha.gxt.widget.core.client.form.TextArea;
import com.sencha.gxt.widget.core.client.form.TextField;
public class TabularResourceProperties extends FramedPanel {
private static final String LISTVIEWWIDTH="250px";
private DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd");
protected String headingTitle;
protected HashMap<String, String> tabularResourcePropertiesMap;
protected VerticalLayoutContainer vl;
@ -73,6 +89,10 @@ public class TabularResourceProperties extends FramedPanel {
protected CheckBox validField;
protected CheckBox finalizedField;
protected ListLoader<ListLoadConfig, ListLoadResult<LicenceData>> loader;
protected ComboBox<LicenceData> comboLicences;
protected ListStore<LicenceData> storeCombo;
protected TextField typeField;
protected IconButton btnShare;
@ -155,6 +175,54 @@ public class TabularResourceProperties extends FramedPanel {
layoutTabularResource.add(new FieldLabel(validUntilToField,
"Valid Until To"), new VerticalLayoutData(1, -1));
// //
// Combo Licences
LicenceDataPropertiesCombo propsLicenceData = GWT
.create(LicenceDataPropertiesCombo.class);
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();
}
});
}
};
comboLicences.getListView().setWidth(LISTVIEWWIDTH);
Log.trace("Combo Licence created");
// /
layoutTabularResource.add(new FieldLabel(comboLicences, "Licence"),
new VerticalLayoutData(1, -1));
// /
ownerField = new TextField();
ownerField.setReadOnly(true);
ownerField.setValue("");
@ -239,6 +307,35 @@ public class TabularResourceProperties extends FramedPanel {
}
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) {
eventBus.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));
}
});
}
protected void updateTabularResource(TabResource tabResource) {
this.tabResource = tabResource;
Log.debug(tabResource.toString());
@ -279,6 +376,19 @@ public class TabularResourceProperties extends FramedPanel {
}
}
if (tabResource.getLicence() != null
&& !tabResource.getLicence().isEmpty()) {
List<LicenceData> listLicence = storeCombo.getAll();
for (int i=0; i<listLicence.size(); i++) {
if (tabResource.getLicence().compareTo(listLicence.get(i).getLicence()) == 0) {
comboLicences.setValue(listLicence.get(i),true);
}
}
}
ownerField.setValue(tabResource.getOwner().getLogin());
validField.setValue(tabResource.isValid());
if (tabResource.isFinalized()) {
@ -288,7 +398,7 @@ public class TabularResourceProperties extends FramedPanel {
finalizedField.setReadOnly(false);
finalizedField.setValue(false);
}
}
protected void updateShareInfo(ShareInfo result) {
@ -334,18 +444,16 @@ public class TabularResourceProperties extends FramedPanel {
protected void updateTable(TableData tableData) {
trId = tableData.getTrId();
/*
tableTypeNameField.setValue(tableData.getTypeName());
if (tableMetadataPanel != null) {
tableFieldSet.remove(layoutTable);
layoutTable.remove(tableMetadataPanel);
}
tableMetadataPanel = new TableMetadataAccordionPanel(
"TableInformation", trId, eventBus);
layoutTable.add(tableMetadataPanel, new VerticalLayoutData(-1, -1));
tableFieldSet.add(layoutTable);
*/
* tableTypeNameField.setValue(tableData.getTypeName()); if
* (tableMetadataPanel != null) { tableFieldSet.remove(layoutTable);
* layoutTable.remove(tableMetadataPanel); }
*
*
* tableMetadataPanel = new TableMetadataAccordionPanel(
* "TableInformation", trId, eventBus);
* layoutTable.add(tableMetadataPanel, new VerticalLayoutData(-1, -1));
* tableFieldSet.add(layoutTable);
*/
forceLayout();
}
@ -460,7 +568,7 @@ public class TabularResourceProperties extends FramedPanel {
e.printStackTrace();
}
}
Date vUntilTo = validUntilToField.getValue();
if (vUntilTo == null) {
Log.debug("No valid until to set");
@ -472,8 +580,10 @@ public class TabularResourceProperties extends FramedPanel {
Log.error("No valid until to field: " + vUntilTo);
e.printStackTrace();
}
}
tabResource.setLicence(comboLicences.getCurrentValue().getLicence());
tabResource.setValid(validField.getValue());
tabResource.setFinalized(finalizedField.getValue());

View File

@ -0,0 +1,26 @@
package org.gcube.portlets.user.td.informationwidget.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();
}