264 lines
7.8 KiB
Java
264 lines
7.8 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.portlets.user.td.codelistmappingimportwidget.client;
|
|
|
|
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
|
|
import org.gcube.portlets.user.td.gwtservice.shared.codelisthelper.CodelistMappingSession;
|
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsFinalException;
|
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsLockedException;
|
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
|
|
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDDescriptor;
|
|
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.TRId;
|
|
import org.gcube.portlets.user.td.wizardwidget.client.WizardCard;
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
import com.google.gwt.user.client.Command;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
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.FieldLabel;
|
|
import com.sencha.gxt.widget.core.client.form.TextArea;
|
|
import com.sencha.gxt.widget.core.client.form.TextField;
|
|
|
|
/**
|
|
*
|
|
* @author "Giancarlo Panichi" <a
|
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
*
|
|
*/
|
|
public class CodelistMappingTableDetailCard extends WizardCard implements
|
|
MonitorDialogListener {
|
|
|
|
protected CodelistMappingSession codelistMappingSession;
|
|
protected CodelistMappingTableDetailCard thisCard;
|
|
|
|
protected VerticalLayoutContainer p;
|
|
|
|
protected TextField name;
|
|
protected TextArea description;
|
|
|
|
protected ResourceTDDescriptor resourceDetails = new ResourceTDDescriptor();
|
|
|
|
public CodelistMappingTableDetailCard(
|
|
final CodelistMappingSession codelistMappingSession) {
|
|
super("Codelist Mapping Detail", "");
|
|
|
|
this.codelistMappingSession = codelistMappingSession;
|
|
thisCard = this;
|
|
FramedPanel form = new FramedPanel();
|
|
|
|
form.setHeadingText("Details");
|
|
|
|
p = new VerticalLayoutContainer();
|
|
form.add(p);
|
|
|
|
name = new TextField();
|
|
name.setAllowBlank(false);
|
|
name.setEmptyText("Enter a name...");
|
|
if (codelistMappingSession.getLocalFileName() != null
|
|
&& !codelistMappingSession.getLocalFileName().isEmpty()) {
|
|
name.setValue(codelistMappingSession.getLocalFileName());
|
|
} else {
|
|
|
|
}
|
|
name.setAllowBlank(false);
|
|
p.add(new FieldLabel(name, "Name"), new VerticalLayoutData(1, -1));
|
|
|
|
description = new TextArea();
|
|
description.setAllowBlank(false);
|
|
description.setEmptyText("Enter a description...");
|
|
description.setValue("XML map");
|
|
description.setAllowBlank(false);
|
|
p.add(new FieldLabel(description, "Description"),
|
|
new VerticalLayoutData(1, -1));
|
|
|
|
setContent(form);
|
|
|
|
}
|
|
|
|
@Override
|
|
public void setup() {
|
|
Command sayNextCard = new Command() {
|
|
|
|
public void execute() {
|
|
checkData();
|
|
}
|
|
|
|
};
|
|
|
|
getWizardWindow().setNextButtonCommand(sayNextCard);
|
|
|
|
Command sayPreviousCard = new Command() {
|
|
public void execute() {
|
|
try {
|
|
getWizardWindow().previousCard();
|
|
getWizardWindow().removeCard(thisCard);
|
|
Log.info("Remove CodelistMappingTableDetailCard");
|
|
} catch (Exception e) {
|
|
Log.error("sayPreviousCard :" + e.getLocalizedMessage());
|
|
}
|
|
}
|
|
};
|
|
|
|
getWizardWindow().setPreviousButtonCommand(sayPreviousCard);
|
|
getWizardWindow().setEnableNextButton(true);
|
|
|
|
}
|
|
|
|
protected void checkData() {
|
|
Log.debug("checkData()");
|
|
getWizardWindow().setEnableNextButton(false);
|
|
getWizardWindow().setEnableBackButton(false);
|
|
AlertMessageBox d;
|
|
HideHandler hideHandler = new HideHandler() {
|
|
|
|
public void onHide(HideEvent event) {
|
|
getWizardWindow().setEnableNextButton(true);
|
|
getWizardWindow().setEnableBackButton(true);
|
|
|
|
}
|
|
};
|
|
|
|
if (name.getValue() == null || name.getValue().isEmpty()
|
|
|| !name.isValid() || description.getValue() == null
|
|
|| description.getValue().isEmpty() || !description.isValid()) {
|
|
d = new AlertMessageBox("Attention!", "Fill in all fields");
|
|
d.addHideHandler(hideHandler);
|
|
d.show();
|
|
} else {
|
|
name.setReadOnly(true);
|
|
description.setReadOnly(true);
|
|
goNext();
|
|
}
|
|
}
|
|
|
|
protected void goNext() {
|
|
Log.debug("goNext()");
|
|
try {
|
|
resourceDetails.setName(name.getCurrentValue());
|
|
resourceDetails.setDescription(description.getCurrentValue());
|
|
|
|
codelistMappingSession.setResourceTDDescriptor(resourceDetails);
|
|
|
|
/*
|
|
* CodelistMappingOperationInProgressCard
|
|
* codelistMappingOperationInProgressCard = new
|
|
* CodelistMappingOperationInProgressCard( codelistMappingSession);
|
|
* getWizardWindow
|
|
* ().addCard(codelistMappingOperationInProgressCard);
|
|
* Log.info("NextCard CodelistMappingOperationInProgressCard");
|
|
* getWizardWindow().nextCard();
|
|
*/
|
|
importCodelistMapping();
|
|
|
|
} catch (Throwable e) {
|
|
Log.error("sayNextCard :" + e.getLocalizedMessage());
|
|
}
|
|
}
|
|
|
|
protected void importCodelistMapping() {
|
|
TDGWTServiceAsync.INSTANCE.startCodelistMappingImport(
|
|
codelistMappingSession, new AsyncCallback<String>() {
|
|
|
|
public void onSuccess(String taskId) {
|
|
openMonitorDialog(taskId);
|
|
}
|
|
|
|
public void onFailure(Throwable caught) {
|
|
if (caught instanceof TDGWTSessionExpiredException) {
|
|
getEventBus()
|
|
.fireEvent(
|
|
new SessionExpiredEvent(
|
|
SessionExpiredType.EXPIREDONSERVER));
|
|
} else {
|
|
if (caught instanceof TDGWTIsLockedException) {
|
|
Log.error(caught.getLocalizedMessage());
|
|
showErrorAndHide("Error Locked",
|
|
caught.getLocalizedMessage(), caught);
|
|
} else {
|
|
if (caught instanceof TDGWTIsFinalException) {
|
|
Log.error(caught.getLocalizedMessage());
|
|
showErrorAndHide("Error Final",
|
|
caught.getLocalizedMessage(),
|
|
caught);
|
|
} else {
|
|
showErrorAndHide(
|
|
"Error in import codelist mapping",
|
|
"An error occured in import codelist mapping: "
|
|
+ caught.getLocalizedMessage(),
|
|
caught);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
protected void openMonitorDialog(String taskId) {
|
|
MonitorDialog monitorDialog = new MonitorDialog(taskId, getEventBus());
|
|
monitorDialog.add(thisCard);
|
|
monitorDialog.show();
|
|
}
|
|
|
|
@Override
|
|
public void operationComplete(TRId trId) {
|
|
getWizardWindow().fireCompleted(trId);
|
|
|
|
}
|
|
|
|
@Override
|
|
public void operationFailed(Throwable caught, String reason, String details) {
|
|
if (caught instanceof TDGWTSessionExpiredException) {
|
|
getEventBus()
|
|
.fireEvent(
|
|
new SessionExpiredEvent(
|
|
SessionExpiredType.EXPIREDONSERVER));
|
|
} else {
|
|
if (caught instanceof TDGWTIsLockedException) {
|
|
Log.error(caught.getLocalizedMessage());
|
|
showErrorAndHide("Error Locked", caught.getLocalizedMessage(),
|
|
caught);
|
|
} else {
|
|
if (caught instanceof TDGWTIsFinalException) {
|
|
Log.error(caught.getLocalizedMessage());
|
|
showErrorAndHide("Error Final",
|
|
caught.getLocalizedMessage(), caught);
|
|
} else {
|
|
getWizardWindow().fireFailed("Error",
|
|
"Error in Codelist Mapping Import", caught);
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public void operationStopped(TRId trId, String reason, String details) {
|
|
getWizardWindow().fireCompleted(trId);
|
|
|
|
}
|
|
|
|
@Override
|
|
public void operationAborted() {
|
|
getWizardWindow().fireAborted();
|
|
|
|
}
|
|
|
|
@Override
|
|
public void operationPutInBackground() {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
}
|