170 lines
5.4 KiB
Java
170 lines
5.4 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.portlets.user.td.rulewidget.client.multicolumn;
|
|
|
|
import org.gcube.portlets.user.td.expressionwidget.client.rpc.ExpressionServiceAsync;
|
|
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.rule.description.RuleDescriptionData;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.CommonMessages;
|
|
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 org.gcube.portlets.user.td.wizardwidget.client.util.UtilsGXT3;
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
import com.google.gwt.core.client.GWT;
|
|
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
|
import com.google.gwt.user.client.Command;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
import com.google.gwt.user.client.ui.FlexTable;
|
|
import com.sencha.gxt.core.client.util.Margins;
|
|
import com.sencha.gxt.widget.core.client.FramedPanel;
|
|
import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutData;
|
|
import com.sencha.gxt.widget.core.client.container.HtmlLayoutContainer;
|
|
import com.sencha.gxt.widget.core.client.container.MarginData;
|
|
import com.sencha.gxt.widget.core.client.container.VBoxLayoutContainer;
|
|
import com.sencha.gxt.widget.core.client.container.VBoxLayoutContainer.VBoxLayoutAlign;
|
|
|
|
/**
|
|
*
|
|
* @author "Giancarlo Panichi" <a
|
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
*
|
|
*/
|
|
public class RuleOnTableNewOperationInProgressCard extends WizardCard {
|
|
private static RuleOnTableNewMessages msgs = GWT
|
|
.create(RuleOnTableNewMessages.class);
|
|
|
|
private RuleDescriptionData ruleDescriptionData;
|
|
private HtmlLayoutContainer resultField;
|
|
|
|
private CommonMessages msgsCommon;
|
|
|
|
public RuleOnTableNewOperationInProgressCard(
|
|
RuleDescriptionData ruleDescriptionData) {
|
|
super(msgs.save(), "");
|
|
this.ruleDescriptionData = ruleDescriptionData;
|
|
initMessages();
|
|
|
|
VBoxLayoutContainer operationInProgressPanel = new VBoxLayoutContainer();
|
|
operationInProgressPanel.setVBoxLayoutAlign(VBoxLayoutAlign.CENTER);
|
|
|
|
final FlexTable description = new FlexTable();
|
|
// FlexCellFormatter cellFormatter = description.getFlexCellFormatter();
|
|
description.setCellSpacing(10);
|
|
description.setCellPadding(4);
|
|
description.setBorderWidth(0);
|
|
|
|
// display:block;vertical-align:text-top;
|
|
description.setHTML(0, 0,
|
|
"<span style=\"font-weight:bold;\";>"+msgs.ruleNameLabel()+"</span>");
|
|
description.setText(0, 1, ruleDescriptionData.getName());
|
|
description.setHTML(1, 0,
|
|
"<span style=\"font-weight:bold;\";>"+msgs.ruleDescriptionLabel()+"</span>");
|
|
description.setText(1, 1, ruleDescriptionData.getDescription());
|
|
|
|
FramedPanel summary = new FramedPanel();
|
|
summary.setHeadingText(msgs.summaryHead());
|
|
summary.setWidth(400);
|
|
summary.add(description);
|
|
operationInProgressPanel.add(summary, new BoxLayoutData(new Margins(20,
|
|
5, 10, 5)));
|
|
|
|
resultField = new HtmlLayoutContainer("<div></div>");
|
|
|
|
operationInProgressPanel.add(resultField, new BoxLayoutData(
|
|
new Margins(10, 5, 10, 5)));
|
|
|
|
setCenterWidget(operationInProgressPanel, new MarginData(0));
|
|
resultField.setVisible(false);
|
|
|
|
}
|
|
|
|
protected void initMessages(){
|
|
msgsCommon=GWT.create(CommonMessages.class);
|
|
}
|
|
|
|
public void saveRuleOnTable() {
|
|
ExpressionServiceAsync.INSTANCE.saveRule(ruleDescriptionData,
|
|
new AsyncCallback<String>() {
|
|
|
|
@Override
|
|
public void onSuccess(String ruleId) {
|
|
Log.debug("Saved Rule: " + ruleId);
|
|
operationComplete();
|
|
|
|
UtilsGXT3.info(msgs.ruleSavedHead(), msgs.ruleSaved());
|
|
|
|
}
|
|
|
|
@Override
|
|
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(msgsCommon.error(),
|
|
msgs.errorSavingRuleOnTable(),
|
|
caught.getLocalizedMessage(), caught);
|
|
} else {
|
|
showErrorAndHide(msgsCommon.error(),
|
|
msgs.errorSavingRuleOnTable(),
|
|
caught.getLocalizedMessage(), caught);
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
@Override
|
|
public void setup() {
|
|
getWizardWindow().setEnableBackButton(false);
|
|
setBackButtonVisible(false);
|
|
getWizardWindow().setEnableNextButton(false);
|
|
getWizardWindow().setNextButtonToFinish();
|
|
saveRuleOnTable();
|
|
}
|
|
|
|
|
|
|
|
public void operationComplete() {
|
|
SafeHtmlBuilder safeHtmlBuilder = new SafeHtmlBuilder();
|
|
safeHtmlBuilder
|
|
.appendHtmlConstant("<div style='text-align:center;font-size:large;font-weight:bold; color:#009900;'>"+msgsCommon.operationCompleted()+"</div>");
|
|
resultField.setHTML(safeHtmlBuilder.toSafeHtml());
|
|
resultField.setVisible(true);
|
|
|
|
Command sayComplete = new Command() {
|
|
public void execute() {
|
|
try {
|
|
getWizardWindow().close(false);
|
|
|
|
getWizardWindow().fireCompleted(null);
|
|
|
|
} catch (Exception e) {
|
|
Log.error("fire Complete :" + e.getLocalizedMessage());
|
|
}
|
|
}
|
|
};
|
|
|
|
getWizardWindow().setNextButtonCommand(sayComplete);
|
|
|
|
setNextButtonVisible(true);
|
|
getWizardWindow().setEnableNextButton(true);
|
|
|
|
forceLayout();
|
|
|
|
}
|
|
|
|
|
|
}
|