2014-01-21 20:51:21 +01:00
|
|
|
package org.gcube.portlets.user.td.expressionwidget.client;
|
|
|
|
|
2015-04-17 12:25:30 +02:00
|
|
|
import java.util.ArrayList;
|
2014-09-30 14:38:31 +02:00
|
|
|
|
2015-04-17 12:25:30 +02:00
|
|
|
import org.gcube.portlets.user.td.expressionwidget.client.notification.ExpressionWrapperNotification;
|
|
|
|
import org.gcube.portlets.user.td.expressionwidget.client.notification.ExpressionWrapperNotification.ExpressionWrapperNotificationListener;
|
|
|
|
import org.gcube.portlets.user.td.expressionwidget.client.notification.ExpressionWrapperNotification.HasExpressionWrapperNotificationListener;
|
2014-04-17 15:48:58 +02:00
|
|
|
import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources;
|
2014-09-30 14:38:31 +02:00
|
|
|
import org.gcube.portlets.user.td.expressionwidget.client.utils.UtilsGXT3;
|
2014-01-22 14:33:39 +01:00
|
|
|
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
|
2014-09-30 14:38:31 +02:00
|
|
|
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.widgetcommonevent.client.event.SessionExpiredEvent;
|
|
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType;
|
2014-01-21 20:51:21 +01:00
|
|
|
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
2015-04-13 12:58:22 +02:00
|
|
|
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnData;
|
|
|
|
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnMockUp;
|
2014-01-24 11:43:31 +01:00
|
|
|
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnTypeCode;
|
2014-01-21 20:51:21 +01:00
|
|
|
|
2014-01-22 14:33:39 +01:00
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
|
import com.google.gwt.user.client.ui.HTML;
|
2014-02-17 13:04:19 +01:00
|
|
|
import com.google.web.bindery.event.shared.EventBus;
|
2014-01-21 20:51:21 +01:00
|
|
|
import com.sencha.gxt.widget.core.client.Window;
|
2014-02-18 15:57:20 +01:00
|
|
|
import com.sencha.gxt.widget.core.client.box.AlertMessageBox;
|
|
|
|
import com.sencha.gxt.widget.core.client.event.HideEvent;
|
|
|
|
import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler;
|
2014-09-30 14:38:31 +02:00
|
|
|
import com.sencha.gxt.widget.core.client.event.SelectEvent;
|
2014-03-14 18:48:30 +01:00
|
|
|
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
|
2014-01-21 20:51:21 +01:00
|
|
|
|
2014-02-24 12:23:21 +01:00
|
|
|
/**
|
|
|
|
*
|
2017-05-15 12:49:43 +02:00
|
|
|
* @author Giancarlo Panichi
|
|
|
|
*
|
2014-02-24 12:23:21 +01:00
|
|
|
*
|
|
|
|
*/
|
2017-05-15 12:49:43 +02:00
|
|
|
public class TemplateColumnExpressionDialog extends Window implements HasExpressionWrapperNotificationListener {
|
2015-05-08 16:01:07 +02:00
|
|
|
private static final String WIDTH = "670px";
|
2015-03-26 20:56:41 +01:00
|
|
|
private static final String HEIGHT = "426px";
|
2015-04-17 12:25:30 +02:00
|
|
|
private ArrayList<ExpressionWrapperNotificationListener> listeners;
|
2015-03-26 20:56:41 +01:00
|
|
|
private ColumnExpressionPanel columnExpressionPanel;
|
|
|
|
private ColumnData column = null;
|
|
|
|
private TRId trId;
|
|
|
|
private String columnId = null;
|
|
|
|
private EventBus eventBus;
|
2015-04-17 12:25:30 +02:00
|
|
|
|
2015-03-31 09:54:54 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param columnMockUp
|
2017-05-15 12:49:43 +02:00
|
|
|
* Column Mockup
|
2015-03-31 09:54:54 +02:00
|
|
|
* @param eventBus
|
2017-05-15 12:49:43 +02:00
|
|
|
* Event bus
|
2015-03-31 09:54:54 +02:00
|
|
|
*/
|
2015-04-17 12:25:30 +02:00
|
|
|
public TemplateColumnExpressionDialog(ColumnMockUp columnMockUp, EventBus eventBus) {
|
|
|
|
listeners = new ArrayList<ExpressionWrapperNotificationListener>();
|
2014-02-17 13:04:19 +01:00
|
|
|
this.eventBus = eventBus;
|
2014-01-22 14:33:39 +01:00
|
|
|
column = new ColumnData();
|
2015-03-26 20:56:41 +01:00
|
|
|
column.setColumnId(columnMockUp.getColumnId());
|
|
|
|
column.setLabel(columnMockUp.getLabel());
|
|
|
|
column.setDataTypeName(columnMockUp.getColumnDataType().toString());
|
|
|
|
column.setTypeCode(columnMockUp.getColumnType().toString());
|
2015-04-17 12:25:30 +02:00
|
|
|
initWindow();
|
2014-02-12 18:14:30 +01:00
|
|
|
create();
|
2014-02-17 13:04:19 +01:00
|
|
|
|
2014-01-21 20:51:21 +01:00
|
|
|
}
|
|
|
|
|
2015-03-31 09:54:54 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param trId
|
2017-05-15 12:49:43 +02:00
|
|
|
* Tabular Resource id
|
2015-03-31 09:54:54 +02:00
|
|
|
* @param columnId
|
2017-05-15 12:49:43 +02:00
|
|
|
* Column id
|
2015-03-31 09:54:54 +02:00
|
|
|
* @param eventBus
|
2017-05-15 12:49:43 +02:00
|
|
|
* Event bus
|
2015-03-31 09:54:54 +02:00
|
|
|
*/
|
2015-04-17 12:25:30 +02:00
|
|
|
public TemplateColumnExpressionDialog(TRId trId, String columnId, EventBus eventBus) {
|
|
|
|
listeners = new ArrayList<ExpressionWrapperNotificationListener>();
|
2014-02-17 16:22:15 +01:00
|
|
|
this.eventBus = eventBus;
|
|
|
|
this.trId = trId;
|
2015-03-25 16:19:12 +01:00
|
|
|
this.columnId = columnId;
|
2015-04-17 12:25:30 +02:00
|
|
|
initWindow();
|
2015-03-25 16:19:12 +01:00
|
|
|
load();
|
2014-02-17 16:22:15 +01:00
|
|
|
|
|
|
|
}
|
2014-02-18 15:57:20 +01:00
|
|
|
|
|
|
|
protected void initWindow() {
|
2014-01-21 20:51:21 +01:00
|
|
|
setWidth(WIDTH);
|
|
|
|
setHeight(HEIGHT);
|
2015-06-22 13:47:06 +02:00
|
|
|
setModal(true);
|
2014-01-22 14:33:39 +01:00
|
|
|
setBodyBorder(false);
|
2014-01-22 12:19:59 +01:00
|
|
|
setResizable(false);
|
2014-01-21 20:51:21 +01:00
|
|
|
setHeadingText("New Rule");
|
2014-03-14 18:48:30 +01:00
|
|
|
setClosable(true);
|
2014-03-13 19:28:27 +01:00
|
|
|
forceLayoutOnResize = true;
|
2015-05-25 19:00:04 +02:00
|
|
|
getHeader().setIcon(ExpressionResources.INSTANCE.ruleColumnAdd());
|
2014-02-17 13:04:19 +01:00
|
|
|
|
2014-01-22 14:33:39 +01:00
|
|
|
}
|
2015-04-17 12:25:30 +02:00
|
|
|
|
2014-03-14 18:48:30 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void initTools() {
|
|
|
|
super.initTools();
|
|
|
|
|
|
|
|
closeBtn.addSelectHandler(new SelectHandler() {
|
|
|
|
|
|
|
|
public void onSelect(SelectEvent event) {
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2015-04-17 12:25:30 +02:00
|
|
|
|
|
|
|
protected void close() {
|
|
|
|
fireAborted();
|
2014-03-14 18:48:30 +01:00
|
|
|
}
|
2014-02-17 13:04:19 +01:00
|
|
|
|
|
|
|
protected void create() {
|
2017-05-15 12:49:43 +02:00
|
|
|
if (column.getTypeCode().compareTo(ColumnTypeCode.ANNOTATION.toString()) == 0
|
|
|
|
|| column.getTypeCode().compareTo(ColumnTypeCode.ATTRIBUTE.toString()) == 0
|
|
|
|
|| column.getTypeCode().compareTo(ColumnTypeCode.CODE.toString()) == 0
|
|
|
|
|| column.getTypeCode().compareTo(ColumnTypeCode.CODEDESCRIPTION.toString()) == 0
|
|
|
|
|| column.getTypeCode().compareTo(ColumnTypeCode.CODENAME.toString()) == 0
|
|
|
|
|| column.getTypeCode().compareTo(ColumnTypeCode.MEASURE.toString()) == 0) {
|
|
|
|
columnExpressionPanel = new ColumnExpressionPanel(this, column, eventBus);
|
2014-01-22 14:33:39 +01:00
|
|
|
add(columnExpressionPanel);
|
|
|
|
} else {
|
2017-05-15 12:49:43 +02:00
|
|
|
HTML errorMessage = new HTML("This type of column is not supported for now!");
|
2014-01-22 14:33:39 +01:00
|
|
|
add(errorMessage);
|
2017-05-15 12:49:43 +02:00
|
|
|
AlertMessageBox d = new AlertMessageBox("Error", "This type of column is not supported for now!");
|
2014-02-18 15:57:20 +01:00
|
|
|
d.addHideHandler(new HideHandler() {
|
|
|
|
public void onHide(HideEvent event) {
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
d.show();
|
2014-01-22 14:33:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-15 12:49:43 +02:00
|
|
|
protected void onExpression(ExpressionWrapperNotification expressionWrapperNotification) {
|
2015-04-17 12:25:30 +02:00
|
|
|
fireNotification(expressionWrapperNotification);
|
2014-01-22 14:33:39 +01:00
|
|
|
}
|
2014-02-17 13:04:19 +01:00
|
|
|
|
2015-03-25 16:19:12 +01:00
|
|
|
protected void load() {
|
2017-05-15 12:49:43 +02:00
|
|
|
TDGWTServiceAsync.INSTANCE.getColumn(columnId, trId, new AsyncCallback<ColumnData>() {
|
|
|
|
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
if (caught instanceof TDGWTSessionExpiredException) {
|
|
|
|
eventBus.fireEvent(new SessionExpiredEvent(SessionExpiredType.EXPIREDONSERVER));
|
|
|
|
} else {
|
|
|
|
if (caught instanceof TDGWTIsLockedException) {
|
|
|
|
Log.error(caught.getLocalizedMessage());
|
|
|
|
UtilsGXT3.alert("Error Locked", caught.getLocalizedMessage());
|
|
|
|
} else {
|
|
|
|
Log.error("Error retrieving column: " + caught.getMessage());
|
|
|
|
UtilsGXT3.alert("Error", "Error retrieving column: " + caught.getMessage());
|
2014-01-22 14:33:39 +01:00
|
|
|
}
|
2017-05-15 12:49:43 +02:00
|
|
|
}
|
|
|
|
fireFailed(caught);
|
2014-01-22 14:33:39 +01:00
|
|
|
|
2017-05-15 12:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onSuccess(ColumnData result) {
|
|
|
|
Log.debug("Retrived column: " + result);
|
|
|
|
column = result;
|
|
|
|
create();
|
|
|
|
}
|
2014-01-22 14:33:39 +01:00
|
|
|
|
2017-05-15 12:49:43 +02:00
|
|
|
});
|
2014-01-22 14:33:39 +01:00
|
|
|
|
|
|
|
}
|
2014-02-17 13:04:19 +01:00
|
|
|
|
2015-04-17 12:25:30 +02:00
|
|
|
@Override
|
2017-05-15 12:49:43 +02:00
|
|
|
public void addExpressionWrapperNotificationListener(ExpressionWrapperNotificationListener handler) {
|
2015-04-17 12:25:30 +02:00
|
|
|
listeners.add(handler);
|
2017-05-15 12:49:43 +02:00
|
|
|
|
2015-04-17 12:25:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-05-15 12:49:43 +02:00
|
|
|
public void removeExpressionWrapperNotificationListener(ExpressionWrapperNotificationListener handler) {
|
2015-04-17 12:25:30 +02:00
|
|
|
listeners.remove(handler);
|
2017-05-15 12:49:43 +02:00
|
|
|
|
2015-04-17 12:25:30 +02:00
|
|
|
}
|
2017-05-15 12:49:43 +02:00
|
|
|
|
2015-04-17 12:25:30 +02:00
|
|
|
private void fireNotification(ExpressionWrapperNotification expressionWrapperNotification) {
|
|
|
|
if (listeners != null) {
|
|
|
|
for (ExpressionWrapperNotificationListener listener : listeners) {
|
|
|
|
listener.onExpression(expressionWrapperNotification);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fireAborted() {
|
|
|
|
if (listeners != null) {
|
|
|
|
for (ExpressionWrapperNotificationListener listener : listeners) {
|
|
|
|
listener.aborted();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fireFailed(Throwable caught) {
|
|
|
|
if (listeners != null) {
|
|
|
|
for (ExpressionWrapperNotificationListener listener : listeners) {
|
|
|
|
listener.failed(caught);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hide();
|
|
|
|
|
|
|
|
}
|
2017-05-15 12:49:43 +02:00
|
|
|
|
2014-01-21 20:51:21 +01:00
|
|
|
}
|