348 lines
11 KiB
Java
348 lines
11 KiB
Java
package org.gcube.portlets.user.td.columnwidget.client;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import org.gcube.portlets.user.td.columnwidget.client.properties.ColumnDataPropertiesCombo;
|
|
import org.gcube.portlets.user.td.columnwidget.client.resources.ResourceBundle;
|
|
import org.gcube.portlets.user.td.columnwidget.client.utils.UtilsGXT3;
|
|
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.tr.ColumnData;
|
|
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.LabelColumnSession;
|
|
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.ChangeTableRequestEvent;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.type.ChangeTableRequestType;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.type.ChangeTableWhy;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
import com.google.gwt.core.client.GWT;
|
|
import com.google.gwt.core.client.Scheduler;
|
|
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
|
|
import com.google.gwt.event.logical.shared.SelectionEvent;
|
|
import com.google.gwt.event.logical.shared.SelectionHandler;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
import com.google.web.bindery.event.shared.EventBus;
|
|
import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign;
|
|
import com.sencha.gxt.cell.core.client.form.ComboBoxCell.TriggerAction;
|
|
import com.sencha.gxt.core.client.util.Margins;
|
|
import com.sencha.gxt.data.client.loader.RpcProxy;
|
|
import com.sencha.gxt.data.shared.LabelProvider;
|
|
import com.sencha.gxt.data.shared.ListStore;
|
|
import com.sencha.gxt.data.shared.loader.ListLoadConfig;
|
|
import com.sencha.gxt.data.shared.loader.ListLoadConfigBean;
|
|
import com.sencha.gxt.data.shared.loader.ListLoadResult;
|
|
import com.sencha.gxt.data.shared.loader.ListLoadResultBean;
|
|
import com.sencha.gxt.data.shared.loader.ListLoader;
|
|
import com.sencha.gxt.data.shared.loader.LoadResultListStoreBinding;
|
|
import com.sencha.gxt.widget.core.client.FramedPanel;
|
|
import com.sencha.gxt.widget.core.client.button.TextButton;
|
|
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.SelectEvent;
|
|
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
|
|
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.TextField;
|
|
import com.sencha.gxt.widget.core.client.info.Info;
|
|
|
|
/**
|
|
*
|
|
* ChangeColumnTypePanel is the panel for change column type
|
|
*
|
|
*
|
|
* @author "Giancarlo Panichi" <a
|
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
*
|
|
*/
|
|
public class LabelColumnPanel extends FramedPanel implements
|
|
MonitorDialogListener {
|
|
protected String WIDTH = "640px";
|
|
protected String HEIGHT = "520px";
|
|
protected EventBus eventBus;
|
|
protected ChangeColumnTypeDialog parent;
|
|
protected TextField label = null;
|
|
protected TRId trId;
|
|
protected String columnName;
|
|
protected ColumnData column;
|
|
protected ComboBox<ColumnData> comboColumn = null;
|
|
protected ListLoader<ListLoadConfig, ListLoadResult<ColumnData>> loader;
|
|
|
|
protected TextButton change;
|
|
|
|
protected LabelColumnSession labelColumnSession;
|
|
|
|
public LabelColumnPanel(TRId trId, String columnName, EventBus eventBus) {
|
|
setWidth(WIDTH);
|
|
setHeight(HEIGHT);
|
|
setHeaderVisible(false);
|
|
setBodyBorder(false);
|
|
this.trId = trId;
|
|
this.columnName = columnName;
|
|
this.eventBus = eventBus;
|
|
Log.debug("LabelColumnPanel(): [" + trId.toString() + " columnName: "
|
|
+ columnName + "]");
|
|
|
|
// Column Data
|
|
ColumnDataPropertiesCombo propsColumnData = GWT
|
|
.create(ColumnDataPropertiesCombo.class);
|
|
ListStore<ColumnData> storeCombo = new ListStore<ColumnData>(
|
|
propsColumnData.id());
|
|
|
|
Log.trace("StoreCombo created");
|
|
|
|
RpcProxy<ListLoadConfig, ListLoadResult<ColumnData>> proxy = new RpcProxy<ListLoadConfig, ListLoadResult<ColumnData>>() {
|
|
|
|
public void load(ListLoadConfig loadConfig,
|
|
final AsyncCallback<ListLoadResult<ColumnData>> callback) {
|
|
loadData(loadConfig, callback);
|
|
}
|
|
};
|
|
|
|
loader = new ListLoader<ListLoadConfig, ListLoadResult<ColumnData>>(
|
|
proxy) {
|
|
@Override
|
|
protected ListLoadConfig newLoadConfig() {
|
|
return (ListLoadConfig) new ListLoadConfigBean();
|
|
}
|
|
|
|
};
|
|
|
|
loader.addLoadHandler(new LoadResultListStoreBinding<ListLoadConfig, ColumnData, ListLoadResult<ColumnData>>(
|
|
storeCombo));
|
|
Log.trace("LoaderCombo created");
|
|
|
|
comboColumn = new ComboBox<ColumnData>(storeCombo,
|
|
propsColumnData.label()) {
|
|
|
|
protected void onAfterFirstAttach() {
|
|
super.onAfterFirstAttach();
|
|
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
|
public void execute() {
|
|
loader.load();
|
|
}
|
|
});
|
|
}
|
|
};
|
|
Log.trace("Combo ColumnData created");
|
|
|
|
addHandlersForComboColumn(propsColumnData.label());
|
|
|
|
comboColumn.setLoader(loader);
|
|
comboColumn.setEmptyText("Select a column...");
|
|
comboColumn.setWidth(150);
|
|
comboColumn.setTypeAhead(false);
|
|
comboColumn.setEditable(false);
|
|
comboColumn.setTriggerAction(TriggerAction.ALL);
|
|
|
|
label = new TextField();
|
|
label.setAllowBlank(false);
|
|
|
|
change = new TextButton("Change");
|
|
change.setIcon(ResourceBundle.INSTANCE.columnLabel());
|
|
change.setIconAlign(IconAlign.RIGHT);
|
|
change.setTitle("Change Column Label");
|
|
|
|
change.addSelectHandler(new SelectHandler() {
|
|
|
|
public void onSelect(SelectEvent event) {
|
|
onLabelColumn();
|
|
|
|
}
|
|
});
|
|
|
|
VerticalLayoutContainer v = new VerticalLayoutContainer();
|
|
v.add(new FieldLabel(comboColumn, "Column"), new VerticalLayoutData(1,
|
|
-1));
|
|
v.add(new FieldLabel(label, "Label"), new VerticalLayoutData(1, -1));
|
|
v.add(change, new VerticalLayoutData(-1, -1, new Margins(10, 0, 10, 0)));
|
|
add(v, new VerticalLayoutData(-1, -1, new Margins()));
|
|
|
|
}
|
|
|
|
protected void addHandlersForComboColumn(
|
|
final LabelProvider<ColumnData> labelProvider) {
|
|
comboColumn.addSelectionHandler(new SelectionHandler<ColumnData>() {
|
|
public void onSelection(SelectionEvent<ColumnData> event) {
|
|
Info.display(
|
|
"Column Selected",
|
|
"You selected "
|
|
+ (event.getSelectedItem() == null ? "nothing"
|
|
: labelProvider.getLabel(event
|
|
.getSelectedItem()) + "!"));
|
|
Log.debug("ComboColumn selected: " + event.getSelectedItem());
|
|
ColumnData columnData = event.getSelectedItem();
|
|
updateComboStatus(columnData);
|
|
}
|
|
|
|
});
|
|
}
|
|
|
|
protected void loadData(ListLoadConfig loadConfig,
|
|
final AsyncCallback<ListLoadResult<ColumnData>> callback) {
|
|
TDGWTServiceAsync.INSTANCE.getColumns(trId,
|
|
new AsyncCallback<ArrayList<ColumnData>>() {
|
|
|
|
public void onFailure(Throwable caught) {
|
|
if (caught instanceof TDGWTSessionExpiredException) {
|
|
eventBus.fireEvent(new SessionExpiredEvent(
|
|
SessionExpiredType.EXPIREDONSERVER));
|
|
} else {
|
|
Log.error("load combo failure:"
|
|
+ caught.getLocalizedMessage());
|
|
UtilsGXT3.alert("Error",
|
|
"Error retrieving columns of tabular resource:"
|
|
+ trId.getId());
|
|
}
|
|
callback.onFailure(caught);
|
|
}
|
|
|
|
public void onSuccess(ArrayList<ColumnData> result) {
|
|
Log.trace("loaded " + result.size() + " ColumnData");
|
|
ArrayList<ColumnData> removables = new ArrayList<ColumnData>();
|
|
for (ColumnData c : result) {
|
|
if (c.getTypeCode().compareTo("DIMENSION") == 0
|
|
|| c.getTypeCode().compareTo(
|
|
"TIMEDIMENSION") == 0) {
|
|
removables.add(c);
|
|
}
|
|
}
|
|
if (removables.size() > 0) {
|
|
result.removeAll(removables);
|
|
}
|
|
setComboStatus(result);
|
|
callback.onSuccess(new ListLoadResultBean<ColumnData>(
|
|
result));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
protected void setComboStatus(ArrayList<ColumnData> result) {
|
|
Log.debug("ColumnName:" + columnName);
|
|
if (columnName != null) {
|
|
for (ColumnData cd : result) {
|
|
Log.debug("ColumnData name:" + cd.getName());
|
|
if (cd.getName().compareTo(columnName) == 0) {
|
|
updateComboStatus(cd);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void updateComboStatus(ColumnData cd) {
|
|
Log.debug("ColumnData: " + cd.toString());
|
|
labelColumnSession = new LabelColumnSession();
|
|
labelColumnSession.setColumnData(cd);
|
|
labelColumnSession.setLabel(cd.getLabel());
|
|
comboColumn.setValue(cd);
|
|
label.setValue(cd.getLabel());
|
|
}
|
|
|
|
public void update(TRId trId, String columnName) {
|
|
this.trId = trId;
|
|
this.columnName = columnName;
|
|
loader.load();
|
|
}
|
|
|
|
protected void onLabelColumn() {
|
|
|
|
ColumnData columnData = comboColumn.getCurrentValue();
|
|
if (columnData != null) {
|
|
String lab = label.getCurrentValue();
|
|
if (lab != null && !lab.isEmpty()) {
|
|
labelColumnSession = new LabelColumnSession();
|
|
labelColumnSession.setColumnData(columnData);
|
|
labelColumnSession.setLabel(lab);
|
|
callLabelColumn();
|
|
} else {
|
|
UtilsGXT3.alert("Attention", "Insert a valid label!");
|
|
}
|
|
} else {
|
|
UtilsGXT3.alert("Attention", "Select a column!");
|
|
}
|
|
}
|
|
|
|
private void callLabelColumn() {
|
|
TDGWTServiceAsync.INSTANCE.startLabelColumn(labelColumnSession,
|
|
new AsyncCallback<String>() {
|
|
|
|
public void onFailure(Throwable caught) {
|
|
if (caught instanceof TDGWTSessionExpiredException) {
|
|
eventBus.fireEvent(new SessionExpiredEvent(
|
|
SessionExpiredType.EXPIREDONSERVER));
|
|
} else {
|
|
Log.debug("Change The Column Label Error: "
|
|
+ caught.getLocalizedMessage());
|
|
UtilsGXT3
|
|
.alert("Error Changing The Column Label",
|
|
"Error in invocation of Change The Column Label operation!");
|
|
}
|
|
}
|
|
|
|
public void onSuccess(String taskId) {
|
|
openMonitorDialog(taskId) ;
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
public void close() {
|
|
if (parent != null) {
|
|
parent.close();
|
|
}
|
|
}
|
|
|
|
///
|
|
protected void openMonitorDialog(String taskId) {
|
|
MonitorDialog monitorDialog = new MonitorDialog(taskId, eventBus);
|
|
monitorDialog.addProgressDialogListener(this);
|
|
monitorDialog.show();
|
|
}
|
|
|
|
@Override
|
|
public void operationComplete(TRId trId) {
|
|
ChangeTableWhy why = ChangeTableWhy.TABLEUPDATED;
|
|
ChangeTableRequestEvent changeTableRequestEvent = new ChangeTableRequestEvent(
|
|
ChangeTableRequestType.CHANGECOLUMNLABEL, trId, why);
|
|
eventBus.fireEvent(changeTableRequestEvent);
|
|
close();
|
|
}
|
|
|
|
@Override
|
|
public void operationFailed(Throwable caught, String reason, String details) {
|
|
UtilsGXT3.alert(reason, details);
|
|
close();
|
|
|
|
}
|
|
|
|
@Override
|
|
public void operationStopped(TRId trId, String reason, String details) {
|
|
ChangeTableWhy why = ChangeTableWhy.TABLECURATION;
|
|
ChangeTableRequestEvent changeTableRequestEvent = new ChangeTableRequestEvent(
|
|
ChangeTableRequestType.CHANGECOLUMNLABEL, trId, why);
|
|
eventBus.fireEvent(changeTableRequestEvent);
|
|
close();
|
|
|
|
}
|
|
|
|
@Override
|
|
public void operationAborted() {
|
|
close();
|
|
|
|
}
|
|
|
|
@Override
|
|
public void operationPutInBackground() {
|
|
close();
|
|
|
|
}
|
|
|
|
}
|