162 lines
5.1 KiB
Java
162 lines
5.1 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.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.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 {
|
|
|
|
protected RuleOnTableNewOperationInProgressCard thisCard;
|
|
protected RuleDescriptionData ruleDescriptionData;
|
|
protected HtmlLayoutContainer resultField;
|
|
|
|
public RuleOnTableNewOperationInProgressCard(
|
|
RuleDescriptionData ruleDescriptionData) {
|
|
super("Save", "");
|
|
|
|
this.ruleDescriptionData = ruleDescriptionData;
|
|
thisCard = this;
|
|
|
|
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;\";>Rule Name: </span>");
|
|
description.setText(0, 1, ruleDescriptionData.getName());
|
|
description.setHTML(1, 0,
|
|
"<span style=\"font-weight:bold;\";>Rule Description: </span>");
|
|
description.setText(1, 1, ruleDescriptionData.getDescription());
|
|
|
|
FramedPanel summary = new FramedPanel();
|
|
summary.setHeadingText("Rule On Table");
|
|
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);
|
|
|
|
}
|
|
|
|
public void saveRuleOnTable() {
|
|
ExpressionServiceAsync.INSTANCE.saveRule(ruleDescriptionData,
|
|
new AsyncCallback<String>() {
|
|
|
|
@Override
|
|
public void onSuccess(String ruleId) {
|
|
Log.debug("Saved Rule: " + ruleId);
|
|
operationComplete();
|
|
|
|
UtilsGXT3.info("Save Rule", "The rule is saved!");
|
|
|
|
}
|
|
|
|
@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("Error",
|
|
"Error saving rule on table",
|
|
caught.getLocalizedMessage(), caught);
|
|
} else {
|
|
showErrorAndHide("Error",
|
|
"Error saving rule on table: ",
|
|
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;'>Operation Completed</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();
|
|
|
|
}
|
|
|
|
|
|
}
|