184 lines
6.2 KiB
Java
184 lines
6.2 KiB
Java
package org.gcube.portlets.user.td.columnwidget.client;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import org.gcube.portlets.user.td.columnwidget.client.properties.ColumnDataProperties;
|
|
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
|
|
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnTypeCode;
|
|
|
|
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.event.logical.shared.ValueChangeEvent;
|
|
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
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.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.ContentPanel;
|
|
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.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;
|
|
|
|
public class ChangeColumnTypePanel extends FramedPanel {
|
|
protected String WIDTH = "640px";
|
|
protected String HEIGHT = "520px";
|
|
|
|
protected ChangeColumnTypeDialog parent;
|
|
protected TextField label = null;
|
|
protected TRId trId;
|
|
protected String columnName;
|
|
protected ColumnData column;
|
|
protected ComboBox<ColumnData> comboColumn = null;
|
|
protected ComboBox<ColumnTypeCode> comboTypeColumn = null;
|
|
|
|
|
|
|
|
public ChangeColumnTypePanel(TRId trId, String columnName){
|
|
setWidth(WIDTH);
|
|
setHeight(HEIGHT);
|
|
setHeaderVisible(false);
|
|
setBodyBorder(false);
|
|
this.trId=trId;
|
|
this.columnName=columnName;
|
|
|
|
VerticalLayoutContainer basicLayout = new VerticalLayoutContainer();
|
|
|
|
ContentPanel panel = new ContentPanel();
|
|
panel.setHeaderVisible(false);
|
|
|
|
ColumnDataProperties props = GWT.create(ColumnDataProperties.class);
|
|
ListStore<ColumnData> store = new ListStore<ColumnData>(props.id());
|
|
|
|
Log.trace("Store created");
|
|
RpcProxy<ListLoadConfig, ListLoadResult<ColumnData>> proxy = new RpcProxy<ListLoadConfig, ListLoadResult<ColumnData>>() {
|
|
|
|
public void load(ListLoadConfig loadConfig, final AsyncCallback<ListLoadResult<ColumnData>> callback) {
|
|
loadData(loadConfig, callback);
|
|
}
|
|
};
|
|
final ListLoader<ListLoadConfig, ListLoadResult<ColumnData>> loader = new ListLoader<ListLoadConfig, ListLoadResult<ColumnData>>(proxy);
|
|
loader.setRemoteSort(false);
|
|
loader.addLoadHandler(new LoadResultListStoreBinding<ListLoadConfig, ColumnData, ListLoadResult<ColumnData>>(store));
|
|
Log.trace("Loader created");
|
|
|
|
|
|
comboColumn = new ComboBox<ColumnData>(store, props.label()){
|
|
|
|
protected void onAfterFirstAttach() {
|
|
super.onAfterFirstAttach();
|
|
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
|
public void execute() {
|
|
loader.load();
|
|
}
|
|
});
|
|
}
|
|
};
|
|
Log.trace("Combo created");
|
|
|
|
addHandlersForEventObservation(comboColumn, props.label());
|
|
|
|
comboColumn.setEmptyText("Select a column...");
|
|
comboColumn.setWidth(150);
|
|
comboColumn.setTypeAhead(true);
|
|
comboColumn.setTriggerAction(TriggerAction.ALL);
|
|
comboColumn.setLoader(loader);
|
|
|
|
FramedPanel form = new FramedPanel();
|
|
form.setHeaderVisible(false);
|
|
//form.setWidth(350);
|
|
form.setBodyStyle("background: none;");
|
|
|
|
TextField labelColumn=new TextField();
|
|
|
|
|
|
|
|
|
|
VerticalLayoutContainer v = new VerticalLayoutContainer();
|
|
v.add(new FieldLabel(comboColumn, "Column"), new VerticalLayoutData(1, -1));
|
|
v.add(new FieldLabel(labelColumn, "Label"), new VerticalLayoutData(1, -1));
|
|
|
|
form.add(v);
|
|
form.addButton(new TextButton("Change"));
|
|
|
|
|
|
panel.add(form);
|
|
basicLayout.add(panel, new VerticalLayoutData(-1, -1, new Margins()));
|
|
add(basicLayout);
|
|
|
|
}
|
|
|
|
private <T> void addHandlersForEventObservation(ComboBox<T> combo,
|
|
final LabelProvider<T> labelProvider) {
|
|
combo.addValueChangeHandler(new ValueChangeHandler<T>() {
|
|
|
|
public void onValueChange(ValueChangeEvent<T> event) {
|
|
Info.display(
|
|
"Value Changed",
|
|
"New value: "
|
|
+ (event.getValue() == null ? "nothing"
|
|
: labelProvider.getLabel(event
|
|
.getValue()) + "!"));
|
|
|
|
}
|
|
});
|
|
combo.addSelectionHandler(new SelectionHandler<T>() {
|
|
public void onSelection(SelectionEvent<T> event) {
|
|
Info.display(
|
|
"State Selected",
|
|
"You selected "
|
|
+ (event.getSelectedItem() == null ? "nothing"
|
|
: labelProvider.getLabel(event
|
|
.getSelectedItem()) + "!"));
|
|
}
|
|
});
|
|
}
|
|
|
|
protected void loadData(ListLoadConfig loadConfig,
|
|
final AsyncCallback<ListLoadResult<ColumnData>> callback) {
|
|
TDGWTServiceAsync.INSTANCE.getColumns(trId,
|
|
new AsyncCallback<ArrayList<ColumnData>>() {
|
|
|
|
public void onFailure(Throwable caught) {
|
|
Log.error("load combo failure:"
|
|
+ caught.getLocalizedMessage());
|
|
callback.onFailure(caught);
|
|
}
|
|
|
|
public void onSuccess(ArrayList<ColumnData> result) {
|
|
Log.trace("loaded " + result.size() + " ColumnData");
|
|
if (columnName != null) {
|
|
for (ColumnData cd : result) {
|
|
if (cd.getName().compareTo(columnName) == 0) {
|
|
comboColumn.setValue(cd);
|
|
}
|
|
}
|
|
}
|
|
callback.onSuccess(new ListLoadResultBean<ColumnData>(
|
|
result));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|