2014-04-11 16:12:21 +02:00
|
|
|
package org.gcube.portlets.user.td.columnwidget.client.dimension;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2014-05-06 10:36:32 +02:00
|
|
|
import org.gcube.portlets.user.td.columnwidget.client.properties.ColumnDataPropertiesCombo;
|
2014-04-11 16:12:21 +02:00
|
|
|
import org.gcube.portlets.user.td.columnwidget.client.properties.TabResourceProperties;
|
|
|
|
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;
|
2014-09-26 12:20:11 +02:00
|
|
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsFinalException;
|
|
|
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsLockedException;
|
2014-05-16 12:24:29 +02:00
|
|
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
|
2014-04-11 16:12:21 +02:00
|
|
|
import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource;
|
2014-05-16 12:24:29 +02:00
|
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent;
|
|
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType;
|
2015-04-13 12:57:30 +02:00
|
|
|
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnData;
|
2014-04-11 16:12:21 +02:00
|
|
|
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
|
|
import com.google.gwt.core.client.GWT;
|
|
|
|
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.shared.LabelProvider;
|
|
|
|
import com.sencha.gxt.data.shared.ListStore;
|
|
|
|
import com.sencha.gxt.widget.core.client.FramedPanel;
|
|
|
|
import com.sencha.gxt.widget.core.client.Window;
|
|
|
|
import com.sencha.gxt.widget.core.client.button.TextButton;
|
|
|
|
import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutData;
|
|
|
|
import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutPack;
|
|
|
|
import com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer;
|
|
|
|
import com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer.HBoxLayoutAlign;
|
|
|
|
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.event.TriggerClickEvent;
|
|
|
|
import com.sencha.gxt.widget.core.client.event.TriggerClickEvent.TriggerClickHandler;
|
|
|
|
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.info.Info;
|
|
|
|
|
2014-05-13 17:33:14 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author "Giancarlo Panichi"
|
2014-05-16 12:24:29 +02:00
|
|
|
*
|
2014-05-13 17:33:14 +02:00
|
|
|
*/
|
2014-04-11 16:12:21 +02:00
|
|
|
public class ConnectCodelistDialog extends Window implements
|
|
|
|
CodelistSelectionListener {
|
|
|
|
protected String WIDTH = "500px";
|
|
|
|
protected String HEIGHT = "150px";
|
|
|
|
protected ArrayList<ConnectCodelistListener> listeners;
|
|
|
|
|
|
|
|
protected ComboBox<TabResource> comboDimensionType = null;
|
|
|
|
protected FieldLabel comboDimensionTypeLabel;
|
|
|
|
protected ListStore<TabResource> storeComboDimensionType;
|
|
|
|
|
|
|
|
protected ComboBox<ColumnData> comboColumnReferenceType = null;
|
|
|
|
protected FieldLabel comboColumnReferenceTypeLabel;
|
|
|
|
protected ListStore<ColumnData> storeComboColumnReferenceType;
|
2014-05-16 12:24:29 +02:00
|
|
|
|
2014-04-11 16:12:21 +02:00
|
|
|
protected EventBus eventBus;
|
2014-05-16 12:24:29 +02:00
|
|
|
|
2014-04-11 16:12:21 +02:00
|
|
|
private TextButton btnApply;
|
|
|
|
private TextButton btnClose;
|
|
|
|
|
|
|
|
public ConnectCodelistDialog(EventBus eventBus) {
|
|
|
|
listeners = new ArrayList<ConnectCodelistListener>();
|
|
|
|
this.eventBus = eventBus;
|
|
|
|
initWindow();
|
|
|
|
create();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void create() {
|
|
|
|
final FramedPanel panel = new FramedPanel();
|
|
|
|
panel.setHeaderVisible(false);
|
|
|
|
panel.setBodyBorder(false);
|
|
|
|
|
|
|
|
// Attach Codelist
|
|
|
|
// comboDimensionType
|
|
|
|
TabResourceProperties propsDimensionType = GWT
|
|
|
|
.create(TabResourceProperties.class);
|
|
|
|
storeComboDimensionType = new ListStore<TabResource>(
|
|
|
|
propsDimensionType.id());
|
|
|
|
|
|
|
|
comboDimensionType = new ComboBox<TabResource>(storeComboDimensionType,
|
|
|
|
propsDimensionType.label());
|
|
|
|
Log.trace("ComboDimensionType created");
|
|
|
|
|
|
|
|
addHandlersForComboDimensionType(propsDimensionType.label());
|
|
|
|
|
|
|
|
comboDimensionType.setEmptyText("Select a Codelist...");
|
|
|
|
comboDimensionType.setWidth(191);
|
|
|
|
comboDimensionType.setEditable(false);
|
|
|
|
comboDimensionType.setTriggerAction(TriggerAction.ALL);
|
|
|
|
|
|
|
|
comboDimensionTypeLabel = new FieldLabel(comboDimensionType, "Codelist");
|
|
|
|
|
|
|
|
// ColumnReferenceType
|
2014-05-06 10:36:32 +02:00
|
|
|
ColumnDataPropertiesCombo propsColumnReferenceType = GWT
|
|
|
|
.create(ColumnDataPropertiesCombo.class);
|
2014-04-11 16:12:21 +02:00
|
|
|
storeComboColumnReferenceType = new ListStore<ColumnData>(
|
|
|
|
propsColumnReferenceType.id());
|
|
|
|
|
|
|
|
comboColumnReferenceType = new ComboBox<ColumnData>(
|
|
|
|
storeComboColumnReferenceType, propsColumnReferenceType.label());
|
|
|
|
Log.trace("ComboColumnReferenceType created");
|
|
|
|
|
|
|
|
addHandlersForComboColumnReferenceType(propsColumnReferenceType.label());
|
|
|
|
|
|
|
|
comboColumnReferenceType.setEmptyText("Select a Column Reference...");
|
|
|
|
comboColumnReferenceType.setWidth(191);
|
|
|
|
comboColumnReferenceType.setEditable(false);
|
|
|
|
comboColumnReferenceType.setTriggerAction(TriggerAction.ALL);
|
|
|
|
|
|
|
|
comboColumnReferenceTypeLabel = new FieldLabel(
|
|
|
|
comboColumnReferenceType, "Column");
|
|
|
|
|
|
|
|
// Buttons
|
|
|
|
btnApply = new TextButton("Connect");
|
|
|
|
btnApply.setIcon(ResourceBundle.INSTANCE.codelistLink());
|
|
|
|
btnApply.setIconAlign(IconAlign.RIGHT);
|
2015-04-01 12:56:23 +02:00
|
|
|
btnApply.setToolTip("Connect");
|
2014-04-11 16:12:21 +02:00
|
|
|
btnApply.addSelectHandler(new SelectHandler() {
|
|
|
|
|
|
|
|
public void onSelect(SelectEvent event) {
|
|
|
|
Log.debug("Pressed Connect");
|
|
|
|
connectCodelist();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
btnClose = new TextButton("Close");
|
|
|
|
btnClose.setIcon(ResourceBundle.INSTANCE.close());
|
|
|
|
btnClose.setIconAlign(IconAlign.RIGHT);
|
2015-04-01 12:56:23 +02:00
|
|
|
btnClose.setToolTip("Close");
|
2014-04-11 16:12:21 +02:00
|
|
|
btnClose.addSelectHandler(new SelectHandler() {
|
|
|
|
|
|
|
|
public void onSelect(SelectEvent event) {
|
|
|
|
Log.debug("Pressed Close");
|
|
|
|
close();
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
HBoxLayoutContainer flowButton = new HBoxLayoutContainer();
|
|
|
|
flowButton.setHBoxLayoutAlign(HBoxLayoutAlign.MIDDLE);
|
|
|
|
flowButton.setPack(BoxLayoutPack.CENTER);
|
|
|
|
|
2014-12-05 17:48:51 +01:00
|
|
|
BoxLayoutData boxLayoutData=new BoxLayoutData(new Margins(2, 4, 2, 4));
|
|
|
|
flowButton.add(btnApply, boxLayoutData);
|
|
|
|
flowButton.add(btnClose, boxLayoutData);
|
2014-04-11 16:12:21 +02:00
|
|
|
|
|
|
|
VerticalLayoutContainer v = new VerticalLayoutContainer();
|
|
|
|
v.add(comboDimensionTypeLabel, new VerticalLayoutData(1, -1));
|
|
|
|
v.add(comboColumnReferenceTypeLabel, new VerticalLayoutData(1, -1));
|
2014-12-05 17:48:51 +01:00
|
|
|
v.add(flowButton, new VerticalLayoutData(1, 36,
|
2014-04-11 16:12:21 +02:00
|
|
|
new Margins(5, 2, 5, 2)));
|
|
|
|
|
|
|
|
panel.add(v);
|
|
|
|
|
|
|
|
add(panel);
|
|
|
|
|
|
|
|
comboColumnReferenceTypeLabel.setVisible(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void addHandlersForComboDimensionType(
|
|
|
|
final LabelProvider<TabResource> labelProvider) {
|
|
|
|
|
|
|
|
comboDimensionType.addTriggerClickHandler(new TriggerClickHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTriggerClick(TriggerClickEvent event) {
|
|
|
|
Log.debug("ComboDimension TriggerClickEvent");
|
|
|
|
callDialogCodelistSelection();
|
|
|
|
comboDimensionType.collapse();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void addHandlersForComboColumnReferenceType(
|
|
|
|
final LabelProvider<ColumnData> labelProvider) {
|
|
|
|
|
|
|
|
comboColumnReferenceType
|
|
|
|
.addSelectionHandler(new SelectionHandler<ColumnData>() {
|
|
|
|
public void onSelection(SelectionEvent<ColumnData> event) {
|
|
|
|
Info.display(
|
|
|
|
"Column Reference Selected",
|
|
|
|
"You selected "
|
|
|
|
+ (event.getSelectedItem() == null ? "nothing"
|
|
|
|
: labelProvider.getLabel(event
|
|
|
|
.getSelectedItem())
|
|
|
|
+ "!"));
|
|
|
|
Log.debug("ComboColumnReferenceType selected: "
|
|
|
|
+ event.getSelectedItem());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void connectCodelist() {
|
|
|
|
TabResource codelist = comboDimensionType.getCurrentValue();
|
|
|
|
if (codelist == null) {
|
|
|
|
Log.debug("No codelist selected");
|
|
|
|
UtilsGXT3.alert("Attention", "Select a valid codelist");
|
|
|
|
} else {
|
|
|
|
ColumnData connection = comboColumnReferenceType.getCurrentValue();
|
|
|
|
if (connection == null) {
|
|
|
|
Log.debug("No connection selected");
|
|
|
|
UtilsGXT3.alert("Attention", "Select a valid column");
|
|
|
|
} else {
|
|
|
|
fireCompleted(connection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void callDialogCodelistSelection() {
|
|
|
|
CodelistSelectionDialog dialogCodelistSelection = new CodelistSelectionDialog(
|
|
|
|
eventBus);
|
|
|
|
dialogCodelistSelection.addListener(this);
|
|
|
|
dialogCodelistSelection.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void selected(TabResource tabResource) {
|
|
|
|
Log.debug("Selected Codelist: " + tabResource);
|
|
|
|
storeComboDimensionType.clear();
|
|
|
|
storeComboDimensionType.add(tabResource);
|
|
|
|
storeComboDimensionType.commitChanges();
|
|
|
|
comboDimensionType.setValue(tabResource);
|
|
|
|
retrieveConnectedColumnData(tabResource);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void aborted() {
|
|
|
|
Log.debug("Select Codelist Aborted");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void failed(String reason, String detail) {
|
|
|
|
Log.error("Select Codelist Failed[reason: " + reason + " , detail:"
|
|
|
|
+ detail + "]");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void retrieveConnectedColumnData(TabResource tabResource) {
|
|
|
|
TDGWTServiceAsync.INSTANCE.getColumnsForDimension(
|
|
|
|
tabResource.getTrId(),
|
|
|
|
new AsyncCallback<ArrayList<ColumnData>>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2014-05-16 12:24:29 +02:00
|
|
|
if (caught instanceof TDGWTSessionExpiredException) {
|
|
|
|
eventBus.fireEvent(new SessionExpiredEvent(
|
|
|
|
SessionExpiredType.EXPIREDONSERVER));
|
|
|
|
} else {
|
2014-09-26 12:20:11 +02:00
|
|
|
if (caught instanceof TDGWTIsLockedException) {
|
|
|
|
Log.error(caught.getLocalizedMessage());
|
|
|
|
UtilsGXT3.alert("Error Locked",
|
|
|
|
caught.getLocalizedMessage());
|
|
|
|
} else {
|
|
|
|
if (caught instanceof TDGWTIsFinalException) {
|
|
|
|
Log.error(caught.getLocalizedMessage());
|
|
|
|
UtilsGXT3.alert("Error Final",
|
|
|
|
caught.getLocalizedMessage());
|
|
|
|
} else {
|
|
|
|
Log.debug("Error retrieving columns: "
|
|
|
|
+ caught.getLocalizedMessage());
|
|
|
|
UtilsGXT3
|
|
|
|
.alert("Error retrieving columns",
|
|
|
|
"Error retrieving columns on server!");
|
|
|
|
}
|
|
|
|
}
|
2014-05-16 12:24:29 +02:00
|
|
|
}
|
2014-04-11 16:12:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(ArrayList<ColumnData> result) {
|
|
|
|
storeComboColumnReferenceType.clear();
|
|
|
|
storeComboColumnReferenceType.addAll(result);
|
|
|
|
storeComboColumnReferenceType.commitChanges();
|
2014-12-05 17:48:51 +01:00
|
|
|
|
2014-04-11 16:12:21 +02:00
|
|
|
comboColumnReferenceTypeLabel.setVisible(true);
|
|
|
|
comboColumnReferenceType.setMinListWidth(191);
|
2014-12-05 17:48:51 +01:00
|
|
|
comboColumnReferenceTypeLabel.forceLayout();
|
|
|
|
|
2014-04-11 16:12:21 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void initWindow() {
|
|
|
|
setWidth(WIDTH);
|
|
|
|
setHeight(HEIGHT);
|
|
|
|
setBodyBorder(false);
|
|
|
|
setResizable(false);
|
|
|
|
setHeadingText("Connect");
|
|
|
|
setModal(true);
|
|
|
|
setClosable(true);
|
|
|
|
getHeader().setIcon(ResourceBundle.INSTANCE.codelistLink());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void initTools() {
|
|
|
|
super.initTools();
|
|
|
|
|
|
|
|
closeBtn.addSelectHandler(new SelectHandler() {
|
|
|
|
|
|
|
|
public void onSelect(SelectEvent event) {
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void close() {
|
|
|
|
fireAborted();
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addListener(ConnectCodelistListener listener) {
|
|
|
|
listeners.add(listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removeListener(ConnectCodelistListener listener) {
|
|
|
|
listeners.remove(listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void fireCompleted(ColumnData connection) {
|
|
|
|
for (ConnectCodelistListener listener : listeners)
|
|
|
|
listener.selectedConnectCodelist(connection);
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void fireAborted() {
|
|
|
|
for (ConnectCodelistListener listener : listeners)
|
|
|
|
listener.abortedConnectCodelist();
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void fireFailed(String reason, String details) {
|
|
|
|
for (ConnectCodelistListener listener : listeners)
|
|
|
|
listener.failedConnectCodelist(reason, details);
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|