Minor Update

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-information-widget@99151 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-07-31 11:04:18 +00:00
parent e148d1ac2c
commit 8ac3028fd0
1 changed files with 103 additions and 53 deletions

View File

@ -1,6 +1,7 @@
package org.gcube.portlets.user.td.informationwidget.client;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
@ -27,6 +28,7 @@ import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.web.bindery.event.shared.EventBus;
import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign;
@ -41,12 +43,15 @@ 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.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;
import com.sencha.gxt.widget.core.client.form.TextField;
public class TabularResourceProperties extends FramedPanel {
private DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd");
protected String headingTitle;
protected HashMap<String, String> tabularResourcePropertiesMap;
protected VerticalLayoutContainer vl;
@ -62,15 +67,14 @@ public class TabularResourceProperties extends FramedPanel {
protected TextField agencyField;
protected TextField dateField;
protected TextArea rightField;
protected TextField validFromField;
protected TextField validUntilToField;
protected DateField validFromField;
protected DateField validUntilToField;
protected TextField ownerField;
protected CheckBox validField;
protected CheckBox finalizedField;
protected TextField typeField;
protected IconButton btnShare;
protected FieldLabel shareLabel;
@ -142,26 +146,21 @@ public class TabularResourceProperties extends FramedPanel {
rightField.setValue("");
layoutTabularResource.add(new FieldLabel(rightField, "Rights"),
new VerticalLayoutData(1, -1));
validFromField = new TextField();
validFromField.setReadOnly(true);
validFromField.setValue("");
validFromField = new DateField();
layoutTabularResource.add(new FieldLabel(validFromField, "Valid From"),
new VerticalLayoutData(1, -1));
validUntilToField = new TextField();
validUntilToField.setReadOnly(true);
validUntilToField.setValue("");
layoutTabularResource.add(new FieldLabel(validUntilToField, "Valid Until To"),
new VerticalLayoutData(1, -1));
validUntilToField = new DateField();
layoutTabularResource.add(new FieldLabel(validUntilToField,
"Valid Until To"), new VerticalLayoutData(1, -1));
ownerField = new TextField();
ownerField.setReadOnly(true);
ownerField.setValue("");
layoutTabularResource.add(new FieldLabel(ownerField, "Owner"),
new VerticalLayoutData(1, -1));
btnShare = new IconButton();
btnShare.setIcon(ResourceBundle.INSTANCE.share());
btnShare.addClickHandler(new ClickHandler() {
@ -174,17 +173,14 @@ public class TabularResourceProperties extends FramedPanel {
});
shareLabel = new FieldLabel(btnShare, "Share");
shareLabel.setVisible(false);
layoutTabularResource.add(shareLabel,
new VerticalLayoutData(1, -1));
layoutTabularResource.add(shareLabel, new VerticalLayoutData(1, -1));
validField = new CheckBox();
validField.setValue(false);
validField.setReadOnly(true);
layoutTabularResource.add(new FieldLabel(validField, "Valid"),
new VerticalLayoutData(1, -1));
finalizedField = new CheckBox();
// finalizedField.setBoxLabel("");
@ -194,8 +190,9 @@ public class TabularResourceProperties extends FramedPanel {
@Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
if (event.getValue()) {
UtilsGXT3.info("Warning",
"A TabularResource set to final can't be modified anymore!");
UtilsGXT3
.info("Warning",
"A TabularResource set to final can't be modified anymore!");
}
}
});
@ -251,8 +248,37 @@ public class TabularResourceProperties extends FramedPanel {
dateField.setValue(tabResource.getDate());
typeField.setValue(tabResource.getTrId().getTabularResourceType());
rightField.setValue(tabResource.getRight());
validFromField.setValue(tabResource.getValidFrom());
validUntilToField.setValue(tabResource.getValidUntilTo());
if (tabResource.getValidFrom() == null
|| tabResource.getValidFrom().isEmpty()) {
Log.debug("ValidFrom null or empty");
} else {
Date vFrom;
try {
vFrom = sdf.parse(tabResource.getValidFrom());
validFromField.setValue(vFrom);
} catch (IllegalArgumentException e) {
Log.error("Error Parsing Valid From for Tabular Resource: "
+ tabResource);
e.printStackTrace();
}
}
if (tabResource.getValidUntilTo() == null
|| tabResource.getValidUntilTo().isEmpty()) {
Log.debug("ValidUntilTo null or empty");
} else {
Date vUntilTo;
try {
vUntilTo = sdf.parse(tabResource.getValidFrom());
validUntilToField.setValue(vUntilTo);
} catch (IllegalArgumentException e) {
Log.error("Error Parsing Valid Until To for Tabular Resource: "
+ tabResource);
e.printStackTrace();
}
}
ownerField.setValue(tabResource.getOwner().getLogin());
validField.setValue(tabResource.isValid());
if (tabResource.isFinalized()) {
@ -262,19 +288,18 @@ public class TabularResourceProperties extends FramedPanel {
finalizedField.setReadOnly(false);
finalizedField.setValue(false);
}
}
protected void updateShareInfo(ShareInfo result){
ArrayList<Contacts> contacts=result.getContacts();
if(contacts!=null&& contacts.size()>0){
protected void updateShareInfo(ShareInfo result) {
ArrayList<Contacts> contacts = result.getContacts();
if (contacts != null && contacts.size() > 0) {
shareLabel.setVisible(true);
} else {
shareLabel.setVisible(false);
}
}
public void addTable() {
tableFieldSet = new FieldSet();
tableFieldSet.setHeadingText("Table");
@ -318,10 +343,10 @@ public class TabularResourceProperties extends FramedPanel {
"TableInformation", trId, eventBus);
layoutTable.add(tableMetadataPanel, new VerticalLayoutData(-1, -1));
tableFieldSet.add(layoutTable);
forceLayout();
}
public void update() {
TDGWTServiceAsync.INSTANCE
.getTabResourceInformation(new AsyncCallback<TabResource>() {
@ -338,8 +363,9 @@ public class TabularResourceProperties extends FramedPanel {
SessionExpiredType.EXPIREDONSERVER));
} else {
Log.error("Error retrienving properties: "
+ caught.getLocalizedMessage());
UtilsGXT3.alert("Error",
+ caught.getLocalizedMessage());
UtilsGXT3.alert(
"Error",
"Error retrienving properties: "
+ caught.getLocalizedMessage());
}
@ -348,14 +374,14 @@ public class TabularResourceProperties extends FramedPanel {
});
}
protected void getShareInformation(TRId trId){
protected void getShareInformation(TRId trId) {
TDGWTServiceAsync.INSTANCE.getShareInfo(trId,
new AsyncCallback<ShareInfo>() {
public void onSuccess(ShareInfo result) {
Log.debug("Retrived share info:" + result);
updateShareInfo(result);
//getLastTable(tabResource.getTrId());
// getLastTable(tabResource.getTrId());
}
@ -374,7 +400,7 @@ public class TabularResourceProperties extends FramedPanel {
});
}
protected void getLastTable(TRId trId) {
TDGWTServiceAsync.INSTANCE.getLastTable(trId,
new AsyncCallback<TableData>() {
@ -382,7 +408,7 @@ public class TabularResourceProperties extends FramedPanel {
public void onSuccess(TableData result) {
Log.debug("Retrived LastTable:" + result);
updateTable(result);
}
public void onFailure(Throwable caught) {
@ -392,7 +418,8 @@ public class TabularResourceProperties extends FramedPanel {
} else {
Log.error("Error retrienving Last Table: "
+ caught.getLocalizedMessage());
UtilsGXT3.alert("Error",
UtilsGXT3.alert(
"Error",
"Error retrienving Last Table: "
+ caught.getLocalizedMessage());
}
@ -403,23 +430,48 @@ public class TabularResourceProperties extends FramedPanel {
public void initInformation() {
addTabularResource();
//addTable();
// addTable();
update();
}
protected void onSave() {
if (nameField.getValue() == null || nameField.getValue().isEmpty()) {
Log.debug("Attention Fill name field");
if (nameField.getValue() == null || nameField.getValue().isEmpty()) {
Log.debug("Attention Fill name field");
UtilsGXT3.info("Attention", "Fill name field");
return;
return;
}
tabResource.setName(nameField.getValue());
tabResource.setDescription(descriptionField.getValue());
tabResource.setAgency(agencyField.getValue());
tabResource.setRight(rightField.getValue());
tabResource.setValidFrom(validFromField.getValue());
tabResource.setValidUntilTo(validUntilToField.getValue());
Date vFrom = validFromField.getValue();
if (vFrom == null) {
Log.debug("No valid from set");
} else {
try {
String vFr = sdf.format(vFrom);
tabResource.setValidFrom(vFr);
} catch (Throwable e) {
Log.error("No valid from field: " + vFrom);
e.printStackTrace();
}
}
Date vUntilTo = validUntilToField.getValue();
if (vUntilTo == null) {
Log.debug("No valid until to set");
} else {
try {
String vUTo = sdf.format(vUntilTo);
tabResource.setValidUntilTo(vUTo);
} catch (Throwable e) {
Log.error("No valid until to field: " + vUntilTo);
e.printStackTrace();
}
}
tabResource.setValid(validField.getValue());
tabResource.setFinalized(finalizedField.getValue());
@ -434,7 +486,8 @@ public class TabularResourceProperties extends FramedPanel {
Log.error("Error Setting Tabular Resoruce Properties: "
+ caught.getLocalizedMessage());
UtilsGXT3.alert("Error",
"Error setting tabular resource properties: "+caught.getLocalizedMessage());
"Error setting tabular resource properties: "
+ caught.getLocalizedMessage());
}
}
@ -443,7 +496,7 @@ public class TabularResourceProperties extends FramedPanel {
+ tabResource);
UtilsGXT3.info("Proprerties",
"Tabular Resource properties are set");
if(finalizedField.getValue()){
if (finalizedField.getValue()) {
finalizedField.setReadOnly(true);
finalizedField.setValue(true);
}
@ -454,7 +507,4 @@ public class TabularResourceProperties extends FramedPanel {
}
}