Updated Collateral Table

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-extractcodelist-widget@111579 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2015-01-30 17:36:19 +00:00
parent b40852f708
commit 0af85614f6
3 changed files with 329 additions and 50 deletions

View File

@ -150,14 +150,14 @@
<scope>provided</scope>
</dependency>
<!-- tabular-data-column-widget -->
<!-- tabular-data-column-widget-->
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>tabular-data-column-widget</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<!-- LOGGING -->
<dependency>
<groupId>com.allen-sauer.gwt.log</groupId>

View File

@ -1,25 +1,38 @@
package org.gcube.portlets.user.td.extractcodelistwidget.client;
import org.gcube.portlets.user.td.columnwidget.client.properties.ColumnDataPropertiesCombo;
import org.gcube.portlets.user.td.gwtservice.shared.extract.ExtractCodelistSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource;
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.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.sencha.gxt.cell.core.client.form.ComboBoxCell.TriggerAction;
import com.sencha.gxt.core.client.util.Margins;
import com.sencha.gxt.core.client.util.ToggleGroup;
import com.sencha.gxt.data.shared.LabelProvider;
import com.sencha.gxt.data.shared.ListStore;
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.FieldLabel;
import com.sencha.gxt.widget.core.client.form.FieldSet;
import com.sencha.gxt.widget.core.client.form.Radio;
import com.sencha.gxt.widget.core.client.form.TextField;
import com.sencha.gxt.widget.core.client.info.Info;
import com.sencha.gxt.widget.core.client.tips.ToolTip;
import com.sencha.gxt.widget.core.client.tips.ToolTipConfig;
@ -30,14 +43,13 @@ import com.sencha.gxt.widget.core.client.tips.ToolTipConfig;
*
*/
public class ExtractCodelistDetailsCard extends WizardCard {
//private static DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd");
// private static DateTimeFormat sdf =
// DateTimeFormat.getFormat("yyyy-MM-dd");
private static final String TABLEDETAILPANELWIDTH = "100%";
private static final String TABLEDETAILPANELHEIGHT = "100%";
private static final String FORMWIDTH = "538px";
private ExtractCodelistSession extractCodelistSession;
private ExtractCodelistDetailsCard thisCard;
@ -47,14 +59,19 @@ public class ExtractCodelistDetailsCard extends WizardCard {
private TextField name;
private Radio automaticallyAttachTrue;
private Radio automaticallyAttachFalse;
private TabResource detail;
public ExtractCodelistDetailsCard(final ExtractCodelistSession extractCodelistSession) {
private TabResource detail;
private ComboBox<ColumnData> comboAttachToColumn;
private ColumnData attachColumn;
private FieldLabel attachToColumnField;
public ExtractCodelistDetailsCard(
final ExtractCodelistSession extractCodelistSession) {
super("Codelist Detail", "");
this.extractCodelistSession = extractCodelistSession;
thisCard = this;
attachColumn = null;
tableDetailPanel = new VerticalPanel();
@ -78,10 +95,10 @@ public class ExtractCodelistDetailsCard extends WizardCard {
name.setAllowBlank(false);
name.setEmptyText("Enter a name...");
name.setAllowBlank(false);
p.add(new FieldLabel(name, "Name"), new VerticalLayoutData(1, -1,new Margins(0)));
///
p.add(new FieldLabel(name, "Name"), new VerticalLayoutData(1, -1,
new Margins(0)));
// /
automaticallyAttachTrue = new Radio();
automaticallyAttachTrue.setBoxLabel("True");
automaticallyAttachTrue.setValue(true);
@ -92,30 +109,108 @@ public class ExtractCodelistDetailsCard extends WizardCard {
ToggleGroup automticallyAttachGroup = new ToggleGroup();
automticallyAttachGroup.add(automaticallyAttachTrue);
automticallyAttachGroup.add(automaticallyAttachFalse);
automticallyAttachGroup
.addValueChangeHandler(new ValueChangeHandler<HasValue<Boolean>>() {
@Override
public void onValueChange(
ValueChangeEvent<HasValue<Boolean>> event) {
try {
if (automaticallyAttachTrue.getValue()) {
attachToColumnField.setVisible(true);
} else {
attachToColumnField.setVisible(false);
}
thisCard.forceLayout();
} catch (Exception e) {
Log.error("ToggleGroup: onValueChange "
+ e.getLocalizedMessage());
}
}
});
HorizontalPanel automaticallyAttachPanel = new HorizontalPanel();
automaticallyAttachPanel.add(automaticallyAttachTrue);
automaticallyAttachPanel.add(automaticallyAttachFalse);
new ToolTip(automaticallyAttachPanel, new ToolTipConfig(
"Automatically attach the generated codelist"));
FieldLabel fieldAttach=new FieldLabel(automaticallyAttachPanel, "Attach");
FieldLabel fieldAttach = new FieldLabel(automaticallyAttachPanel,
"Attach");
p.add(fieldAttach, new VerticalLayoutData(1, -1, new Margins(0)));
// //
// Column Data
ColumnDataPropertiesCombo propsColumnData = GWT
.create(ColumnDataPropertiesCombo.class);
ListStore<ColumnData> storeCombo = new ListStore<ColumnData>(
propsColumnData.id());
storeCombo.addAll(extractCodelistSession.getSourceColumns());
comboAttachToColumn = new ComboBox<ColumnData>(storeCombo,
propsColumnData.label());
Log.trace("Combo AttachToColumn created");
addHandlersForComboAttachToColumn(propsColumnData.label());
comboAttachToColumn.setEmptyText("Select a column...");
comboAttachToColumn.setWidth(191);
comboAttachToColumn.setTypeAhead(false);
comboAttachToColumn.setEditable(false);
comboAttachToColumn.setTriggerAction(TriggerAction.ALL);
attachToColumnField = new FieldLabel(comboAttachToColumn,
"Attach To Column");
p.add(attachToColumnField,
new VerticalLayoutData(1, -1, new Margins(0)));
// /
tableDetailPanel.add(form);
setContent(tableDetailPanel);
}
/**
*
* @param label
*/
private void addHandlersForComboAttachToColumn(
final LabelProvider<ColumnData> label) {
comboAttachToColumn
.addSelectionHandler(new SelectionHandler<ColumnData>() {
public void onSelection(SelectionEvent<ColumnData> event) {
Info.display(
"Column Selected",
"You selected "
+ (event.getSelectedItem() == null ? "nothing"
: label.getLabel(event
.getSelectedItem())
+ "!"));
Log.debug("ComboAttachToColumn selected: "
+ event.getSelectedItem());
ColumnData column = event.getSelectedItem();
updateAttachColumn(column);
}
});
}
private void updateAttachColumn(ColumnData column) {
}
@Override
public void setup() {
Command sayNextCard = new Command() {
public void execute() {
checkData();
}
@ -155,40 +250,46 @@ public class ExtractCodelistDetailsCard extends WizardCard {
};
if (name.getValue() == null || name.getValue().isEmpty()
|| !name.isValid()
/*|| description.getValue() == null
|| description.getValue().isEmpty() || !description.isValid()
|| rights.getValue() == null || rights.getValue().isEmpty()
|| !rights.isValid()*/
) {
|| !name.isValid()) {
d = new AlertMessageBox("Attention!", "Fill name fields");
d.addHideHandler(hideHandler);
d.show();
} else {
name.setReadOnly(true);
/*description.setReadOnly(true);
rights.setReadOnly(true);*/
goNext();
if (getAutomaticallyAttach()) {
attachColumn = comboAttachToColumn.getCurrentValue();
if (attachColumn == null) {
d = new AlertMessageBox("Attention!",
"Select column to attach codelist!");
d.addHideHandler(hideHandler);
d.show();
} else {
name.setReadOnly(true);
goNext();
}
} else {
name.setReadOnly(true);
goNext();
}
}
}
protected boolean getAutomaticallyAttach() {
if(automaticallyAttachTrue.getValue()){
if (automaticallyAttachTrue.getValue()) {
return true;
} else {
return false;
}
}
protected void goNext() {
try {
detail= new TabResource();
detail = new TabResource();
detail.setName(name.getCurrentValue());
extractCodelistSession.setTabResource(detail);
extractCodelistSession.setAutomaticallyAttach(getAutomaticallyAttach());
extractCodelistSession
.setAutomaticallyAttach(getAutomaticallyAttach());
extractCodelistSession.setAttachColumn(attachColumn);
ExtractCodelistOperationInProgressCard extractCodelistOperationInProgressCard = new ExtractCodelistOperationInProgressCard(
extractCodelistSession);
getWizardWindow().addCard(extractCodelistOperationInProgressCard);
@ -196,6 +297,7 @@ public class ExtractCodelistDetailsCard extends WizardCard {
getWizardWindow().nextCard();
} catch (Exception e) {
Log.error("sayNextCard :" + e.getLocalizedMessage());
name.setReadOnly(false);
}
}

View File

@ -3,15 +3,23 @@
*/
package org.gcube.portlets.user.td.extractcodelistwidget.client;
import java.util.ArrayList;
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.extract.ExtractCodelistTargetColumn;
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeSession;
import org.gcube.portlets.user.td.monitorwidget.client.MonitorDialog;
import org.gcube.portlets.user.td.monitorwidget.client.MonitorDialogListener;
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.widgetcommonevent.shared.OperationResult;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataType;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnTypeCode;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnTypeMap;
import org.gcube.portlets.user.td.wizardwidget.client.WizardCard;
import com.allen_sauer.gwt.log.client.Log;
@ -34,10 +42,13 @@ import com.sencha.gxt.widget.core.client.container.VBoxLayoutContainer.VBoxLayou
public class ExtractCodelistOperationInProgressCard extends WizardCard
implements MonitorDialogListener {
protected ExtractCodelistOperationInProgressCard thisCard;
protected ExtractCodelistSession extractCodelistSession;
protected TRId newTrId;
protected HtmlLayoutContainer resultField;
@SuppressWarnings("unused")
private ExtractCodelistOperationInProgressCard thisCard;
private ExtractCodelistSession extractCodelistSession;
private TRId newTrId;
private HtmlLayoutContainer resultField;
private boolean automaticallyAttached;
private TRId collateralTRId;
public ExtractCodelistOperationInProgressCard(
final ExtractCodelistSession extractCodelistSession) {
@ -45,6 +56,7 @@ public class ExtractCodelistOperationInProgressCard extends WizardCard
this.extractCodelistSession = extractCodelistSession;
thisCard = this;
automaticallyAttached = false;
VBoxLayoutContainer operationInProgressPanel = new VBoxLayoutContainer();
operationInProgressPanel.setVBoxLayoutAlign(VBoxLayoutAlign.CENTER);
@ -83,6 +95,158 @@ public class ExtractCodelistOperationInProgressCard extends WizardCard
});
}
public void setCollateralTRIdFinal(ArrayList<TRId> collateralIds) {
if (collateralIds == null || collateralIds.isEmpty()) {
showErrorAndHide("Error in extract codelist",
"An error occured setting collateral table final.",
"No collateral id retrieved", new Throwable(
"No collateral id retrieved"));
}
collateralTRId = collateralIds.get(0);
if (collateralTRId == null) {
showErrorAndHide("Error in extract codelist",
"An error occured setting collateral table final.",
"Collateral id is null", new Throwable(
"Collateral id is null"));
}
TDGWTServiceAsync.INSTANCE.setTabResourceToFinal(collateralTRId,
new AsyncCallback<Void>() {
@Override
public void onSuccess(Void result) {
retrieveCollateralColumn();
}
@Override
public void onFailure(Throwable caught) {
if (caught instanceof TDGWTSessionExpiredException) {
getEventBus()
.fireEvent(
new SessionExpiredEvent(
SessionExpiredType.EXPIREDONSERVER));
} else {
showErrorAndHide(
"Error in extract codelist",
"An error occured setting collateral table final.",
caught.getLocalizedMessage(), caught);
}
}
});
}
private void retrieveCollateralColumn() {
TDGWTServiceAsync.INSTANCE.getColumnsForDimension(collateralTRId,
new AsyncCallback<ArrayList<ColumnData>>() {
@Override
public void onFailure(Throwable caught) {
if (caught instanceof TDGWTSessionExpiredException) {
getEventBus()
.fireEvent(
new SessionExpiredEvent(
SessionExpiredType.EXPIREDONSERVER));
} else {
showErrorAndHide(
"Error in extract codelist",
"An error occured retrieving column on collateral table.",
caught.getLocalizedMessage(), caught);
}
}
@Override
public void onSuccess(ArrayList<ColumnData> result) {
createChangeColumnSession(result);
}
});
}
private void createChangeColumnSession(ArrayList<ColumnData> refColumns){
ColumnData orig=extractCodelistSession.getAttachColumn();
ColumnTypeCode origColumnTypeCode= ColumnTypeMap.getColumnTypeCode(orig.getTypeCode());
ColumnDataType origColumnDataType= ColumnTypeMap.getColumnDataType(orig.getDataTypeName());
String labelOfAttachColumn=null;
ColumnTypeCode typeCodeOfColumnAttach=null;
for(ExtractCodelistTargetColumn targetCol:extractCodelistSession.getTargetColumns()){
if(targetCol.getSourceColumn().getColumnId().compareTo(orig.getColumnId())==0){
if(targetCol.isNewColumn()){
labelOfAttachColumn=targetCol.getDefColumn().getLabel();
typeCodeOfColumnAttach=targetCol.getDefColumn().getColumnType();
} else {
labelOfAttachColumn=targetCol.getTargetColumn().getLabel();
typeCodeOfColumnAttach=ColumnTypeMap.getColumnTypeCode(targetCol.getTargetColumn().getTypeCode());
}
break;
}
}
ColumnData codelistColumnReference=null;
if(labelOfAttachColumn==null){
showErrorAndHide(
"Error in extract codelist",
"An error occured no label retrieved for attach column",
"No label retrieved for attach column", new Throwable("No label retrieved for attach column"));
return;
} else {
for(ColumnData refColumn:refColumns){
if(refColumn.getLabel().compareTo(labelOfAttachColumn)==0){
if(ColumnTypeMap.getColumnTypeCode(refColumn.getTypeCode()).compareTo(typeCodeOfColumnAttach)==0){
codelistColumnReference=refColumn;
break;
} else {
}
}
}
}
if(codelistColumnReference!=null){
ColumnTypeCode columnTypeCodeTarget = ColumnTypeMap.getColumnTypeCode(codelistColumnReference.getTypeCode());
ColumnDataType columnDataTypeTarget = ColumnTypeMap.getColumnDataType(codelistColumnReference.getDataTypeName());
ChangeColumnTypeSession changeColumnTypeSession=new
ChangeColumnTypeSession(orig, origColumnTypeCode, origColumnDataType, columnTypeCodeTarget, columnDataTypeTarget, codelistColumnReference);
callChangeColumnType(changeColumnTypeSession);
} else {
showErrorAndHide(
"Error in extract codelist",
"An error occured no attach column match",
"No attach column match", new Throwable("No attach column match"));
}
}
private void callChangeColumnType(
ChangeColumnTypeSession changeColumnTypeSession) {
TDGWTServiceAsync.INSTANCE.startChangeColumnType(
changeColumnTypeSession, new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
if (caught instanceof TDGWTSessionExpiredException) {
getEventBus().fireEvent(new SessionExpiredEvent(
SessionExpiredType.EXPIREDONSERVER));
} else {
showErrorAndHide(
"Error in extract codelist",
"An error occured on start change column type.",
caught.getLocalizedMessage(), caught);
}
}
public void onSuccess(String taskId) {
automaticallyAttached=true;
openMonitorDialog(taskId);
}
});
}
@Override
public void setup() {
getWizardWindow().setEnableBackButton(false);
@ -102,10 +266,22 @@ public class ExtractCodelistOperationInProgressCard extends WizardCard
@Override
public void operationComplete(OperationResult operationResult) {
newTrId = operationResult.getTrId();
if (extractCodelistSession.isAutomaticallyAttach()) {
if (automaticallyAttached) {
updateOnComplete();
} else {
setCollateralTRIdFinal(operationResult.getCollateralTRIds());
}
} else {
updateOnComplete();
}
}
protected void updateOnComplete() {
SafeHtmlBuilder safeHtmlBuilder = new SafeHtmlBuilder();
safeHtmlBuilder
.appendHtmlConstant("<div style='text-align:center;font-size:large;font-weight:bold; color:#009900;'>Operation Completed</div>"
+ "<div style=' margin-top:30px;text-align:center;font-size:medium;font-weight:bold; color:black;'>The Codelists is available in the list of yours tabular resources</div>");
.appendHtmlConstant("<div style='display:block;margin:auto;text-align:center;font-size:large;font-weight:bold; color:#009900;'>Operation Completed</div>"
+ "<div style='display:block;margin:auto; margin-top:30px;text-align:center;font-size:medium;font-weight:bold; color:black;'>The Codelists is available in the list of yours tabular resources</div>");
resultField.setHTML(safeHtmlBuilder.toSafeHtml());
resultField.setVisible(true);
Command sayComplete = new Command() {
@ -127,14 +303,13 @@ public class ExtractCodelistOperationInProgressCard extends WizardCard
setNextButtonVisible(true);
getWizardWindow().setEnableNextButton(true);
forceLayout();
}
@Override
public void operationFailed(Throwable caught, String reason, String details) {
SafeHtmlBuilder safeHtmlBuilder = new SafeHtmlBuilder();
safeHtmlBuilder
.appendHtmlConstant("<div style='text-align:center;font-size:large;font-weight:bold;color:red;'>Operation Failed</div>");
.appendHtmlConstant("<div style='display:block;margin:auto;text-align:center;font-size:large;font-weight:bold;color:red;'>Operation Failed</div>");
resultField.setHTML(safeHtmlBuilder.toSafeHtml());
resultField.setVisible(true);
if (caught instanceof TDGWTSessionExpiredException) {
@ -143,18 +318,20 @@ public class ExtractCodelistOperationInProgressCard extends WizardCard
new SessionExpiredEvent(
SessionExpiredType.EXPIREDONSERVER));
} else {
showErrorAndHide("Error in Extract Codelist", reason, details, caught);
showErrorAndHide("Error in Extract Codelist", reason, details,
caught);
}
forceLayout();
}
@Override
public void operationStopped(OperationResult operationResult, String reason, String details) {
public void operationStopped(OperationResult operationResult,
String reason, String details) {
newTrId = operationResult.getTrId();
SafeHtmlBuilder safeHtmlBuilder = new SafeHtmlBuilder();
safeHtmlBuilder
.appendHtmlConstant("<div style='text-align:center;font-size:large;font-weight:bold;color: #FF9900;'>Problems in the Operation</div>");
.appendHtmlConstant("<div style='display:block;margin:auto;text-align:center;font-size:large;font-weight:bold;color: #FF9900;'>Problems in the Operation</div>");
resultField.setHTML(safeHtmlBuilder.toSafeHtml());
resultField.setVisible(true);
@ -185,7 +362,7 @@ public class ExtractCodelistOperationInProgressCard extends WizardCard
public void operationAborted() {
SafeHtmlBuilder safeHtmlBuilder = new SafeHtmlBuilder();
safeHtmlBuilder
.appendHtmlConstant("<div style='text-align:center;font-size:large;font-weight:bold;color: #AA00AA;'>Operation Aborted</div>");
.appendHtmlConstant("<div style='diplay:block;margin:auto;text-align:center;font-size:large;font-weight:bold;color: #AA00AA;'>Operation Aborted</div>");
resultField.setHTML(safeHtmlBuilder.toSafeHtml());
resultField.setVisible(true);
@ -215,7 +392,7 @@ public class ExtractCodelistOperationInProgressCard extends WizardCard
public void operationPutInBackground() {
SafeHtmlBuilder safeHtmlBuilder = new SafeHtmlBuilder();
safeHtmlBuilder
.appendHtmlConstant("<div style='text-align:center;font-size:large;font-weight:bold;color: #00AAAA;'>Operation in Background</div>");
.appendHtmlConstant("<div style='display:block;margin:auto;text-align:center;font-size:large;font-weight:bold;color: #00AAAA;'>Operation in Background</div>");
resultField.setHTML(safeHtmlBuilder.toSafeHtml());
resultField.setVisible(true);