Updated Union

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-unionwizard-widget@98730 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-07-17 09:36:52 +00:00 committed by Giancarlo Panichi
parent c8c7b40cf9
commit 635b633eb9
9 changed files with 149 additions and 449 deletions

View File

@ -1,12 +1,9 @@
package org.gcube.portlets.user.td.unionwizardwidget.client;
import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource;
import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionSession;
import org.gcube.portlets.user.td.wizardwidget.client.WizardCard;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.Command;
public class ColumnMappingCard extends WizardCard {
@ -20,19 +17,20 @@ public class ColumnMappingCard extends WizardCard {
this.unionSession = unionSession;
thisCard = this;
columnMappingPanel = new ColumnMappingPanel(thisCard,res);
columnMappingPanel = new ColumnMappingPanel(thisCard,unionSession,res);
/*
columnMappingPanel
.addSelectionHandler(new SelectionHandler<TabResource>() {
public void onSelection(SelectionEvent<TabResource> event) {
/*codelistMappingSession.setConnectedTR(tabResourcesSelectionPanel
codelistMappingSession.setConnectedTR(tabResourcesSelectionPanel
.getSelectedItem());
getWizardWindow().setEnableNextButton(true);*/
getWizardWindow().setEnableNextButton(true);
}
});
*/
setContent(columnMappingPanel);
}
@ -82,10 +80,6 @@ public class ColumnMappingCard extends WizardCard {
}
protected void goNext() {
try {
Log.info("NextCard ColumnSelectionCard");

View File

@ -1,110 +1,49 @@
package org.gcube.portlets.user.td.unionwizardwidget.client;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
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.TabResource;
import org.gcube.portlets.user.td.unionwizardwidget.client.utils.UtilsGXT3;
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.widgetcommonevent.shared.TRId;
import org.gcube.portlets.user.td.wizardwidget.client.WizardCard;
import org.gcube.portlets.user.td.wizardwidget.client.dataresource.ResourceBundle;
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.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.event.logical.shared.HasSelectionHandlers;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.sencha.gxt.core.client.IdentityValueProvider;
import com.sencha.gxt.core.client.Style.SelectionMode;
import com.sencha.gxt.data.client.loader.RpcProxy;
import com.sencha.gxt.data.shared.ListStore;
import com.sencha.gxt.data.shared.ModelKeyProvider;
import com.sencha.gxt.data.shared.Store;
import com.sencha.gxt.data.shared.Store.StoreFilter;
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.cell.core.client.ButtonCell.IconAlign;
import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode;
import com.sencha.gxt.core.client.util.Margins;
import com.sencha.gxt.widget.core.client.ContentPanel;
import com.sencha.gxt.widget.core.client.Resizable;
import com.sencha.gxt.widget.core.client.Dialog.PredefinedButton;
import com.sencha.gxt.widget.core.client.Resizable.Dir;
import com.sencha.gxt.widget.core.client.box.AlertMessageBox;
import com.sencha.gxt.widget.core.client.box.ConfirmMessageBox;
import com.sencha.gxt.widget.core.client.button.TextButton;
import com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer;
import com.sencha.gxt.widget.core.client.container.SimpleContainer;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
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.HBoxLayoutAlign;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
import com.sencha.gxt.widget.core.client.event.HideEvent;
import com.sencha.gxt.widget.core.client.event.SelectEvent;
import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler;
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
import com.sencha.gxt.widget.core.client.form.TextField;
import com.sencha.gxt.widget.core.client.grid.CheckBoxSelectionModel;
import com.sencha.gxt.widget.core.client.grid.ColumnConfig;
import com.sencha.gxt.widget.core.client.grid.ColumnModel;
import com.sencha.gxt.widget.core.client.grid.Grid;
import com.sencha.gxt.widget.core.client.menu.Item;
import com.sencha.gxt.widget.core.client.menu.Menu;
import com.sencha.gxt.widget.core.client.menu.MenuItem;
import com.sencha.gxt.widget.core.client.toolbar.LabelToolItem;
import com.sencha.gxt.widget.core.client.toolbar.ToolBar;
import com.sencha.gxt.widget.core.client.form.FieldLabel;
public class ColumnMappingPanel extends ContentPanel implements
HasSelectionHandlers<TabResource> {
public class ColumnMappingPanel extends ContentPanel {
private static final TabResourcesProperties properties = GWT
.create(TabResourcesProperties.class);
protected static final ColumnConfig<TabResource, String> nameColumn = new ColumnConfig<TabResource, String>(
properties.name(), 90, "Name");
protected static final ColumnConfig<TabResource, String> typeColumn = new ColumnConfig<TabResource, String>(
properties.tabularResourceType(), 30, "Type");
protected static final ColumnConfig<TabResource, String> agencyColumn = new ColumnConfig<TabResource, String>(
properties.agency(), 60, "Agency");
protected static final ColumnConfig<TabResource, String> ownerColumn = new ColumnConfig<TabResource, String>(
properties.ownerLogin(), 70, "Owner");
protected static final ColumnConfig<TabResource, String> dateColumn = new ColumnConfig<TabResource, String>(
properties.date(), 40, "Date");
protected Grid<TabResource> grid;
protected ResourceBundle res;
protected Menu contextMenu;
private ColumnMappingCard parent;
private TabResource removableTR;
private WizardCard parent;
public ColumnMappingPanel(WizardCard parent, ResourceBundle res) {
public ColumnMappingPanel(ColumnMappingCard parent,ResourceBundle res) {
this.res = res;
this.parent = parent;
Log.debug("TabResourcesSelectionPanel");
Log.debug("ColumnMappingPanel");
init();
try {
createContextMenu();
} catch (Throwable e) {
Log.debug("Error In CreateContextMenu:" + e.getMessage());
e.printStackTrace();
}
try {
buildPanel(properties.id(),
Arrays.<ColumnConfig<TabResource, ?>> asList(nameColumn,
typeColumn, ownerColumn, agencyColumn, dateColumn),
nameColumn);
} catch (Throwable e) {
Log.debug("Error building panel:" + e.getMessage());
e.printStackTrace();
}
retrieveColumns();
}
protected void init() {
@ -113,156 +52,42 @@ public class ColumnMappingPanel extends ContentPanel implements
}
protected void buildPanel(ModelKeyProvider<TabResource> keyProvider,
List<ColumnConfig<TabResource, ?>> columns,
ColumnConfig<TabResource, ?> autoexpandColumn) {
protected void create() {
/*
itemIdSourceValueArg = "SourceArg" + selectedColumn.getName();
itemIdTargetValueArg = "TargetArg" + selectedColumn.getName();
ToolBar toolBar = new ToolBar();
toolBar.add(new LabelToolItem("Search: "));
final TextField searchField = new TextField();
toolBar.add(searchField);
SimpleContainer container = new SimpleContainer();
container.setHeight(CONTAINERHEIGHT);
container.setWidth(CONTAINERWIDTH);
TextButton btnReload = new TextButton();
// btnReload.setText("Reload");
btnReload.setIcon(res.refresh16());
btnReload.setToolTip("Reload");
toolBar.add(btnReload);
vert = new VerticalLayoutContainer();
vert.setScrollMode(ScrollMode.AUTO);
vert.setAdjustForScroll(true);
IdentityValueProvider<TabResource> identity = new IdentityValueProvider<TabResource>();
final CheckBoxSelectionModel<TabResource> sm = new CheckBoxSelectionModel<TabResource>(
identity);
setColumnMappingData();
ColumnModel<TabResource> cm = new ColumnModel<TabResource>(columns);
container.add(vert);
container.forceLayout();
final ExtendedListStore<TabResource> store = new ExtendedListStore<TabResource>(
keyProvider);
FieldLabel rowsLabel = new FieldLabel(null, "Select columns");
rowsLabel.getElement().applyStyles("font-weight:bold");
searchField.addKeyUpHandler(new KeyUpHandler() {
VerticalLayoutContainer vPanel = new VerticalLayoutContainer();
vPanel.add(rowsLabel, new VerticalLayoutData(1, -1, new Margins(1)));
vPanel.add(container, new VerticalLayoutData(1, -1));
public void onKeyUp(KeyUpEvent event) {
Log.trace("searchTerm: " + searchField.getCurrentValue());
store.applyFilters();
}
});
store.addFilter(new StoreFilter<TabResource>() {
public boolean select(Store<TabResource> store, TabResource parent,
TabResource item) {
String searchTerm = searchField.getCurrentValue();
if (searchTerm == null)
return true;
return ColumnMappingPanel.this.select(item, searchTerm);
}
});
store.setEnableFilters(true);
RpcProxy<ListLoadConfig, ListLoadResult<TabResource>> proxy = new RpcProxy<ListLoadConfig, ListLoadResult<TabResource>>() {
public void load(ListLoadConfig loadConfig,
final AsyncCallback<ListLoadResult<TabResource>> callback) {
loadData(loadConfig, callback);
}
};
final ListLoader<ListLoadConfig, ListLoadResult<TabResource>> loader = new ListLoader<ListLoadConfig, ListLoadResult<TabResource>>(
proxy);
loader.setRemoteSort(false);
loader.addLoadHandler(new LoadResultListStoreBinding<ListLoadConfig, TabResource, ListLoadResult<TabResource>>(
store));
grid = new Grid<TabResource>(store, cm) {
@Override
protected void onAfterFirstAttach() {
super.onAfterFirstAttach();
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
public void execute() {
loader.load();
}
});
}
};
sm.setSelectionMode(SelectionMode.SINGLE);
grid.setLoader(loader);
grid.setSelectionModel(sm);
grid.getView().setAutoExpandColumn(autoexpandColumn);
grid.getView().setStripeRows(true);
grid.getView().setColumnLines(true);
grid.getView().setAutoFill(true);
grid.setBorders(false);
grid.setLoadMask(true);
grid.setColumnReordering(true);
SelectHandler sh = new SelectHandler() {
public void onSelect(SelectEvent event) {
loader.load();
}
};
btnReload.addSelectHandler(sh);
if (contextMenu != null) {
grid.setContextMenu(contextMenu);
} else
grid.setContextMenu(null);
VerticalLayoutContainer con = new VerticalLayoutContainer();
con.add(toolBar, new VerticalLayoutData(1, -1));
con.add(grid, new VerticalLayoutData(1, 1));
setWidget(con);
add(vPanel);
forceLayout();
*/
}
protected void createContextMenu() {
contextMenu = new Menu();
MenuItem deleteTRItem = new MenuItem("Delete");
deleteTRItem.setId("DeleteTR");
deleteTRItem.setIcon(org.gcube.portlets.user.td.unionwizardwidget.client.dataresource.ResourceBundle.INSTANCE.delete());
deleteTRItem.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
if (grid != null) {
TabResource tabResource = getSelectedItem();
deleteTR(tabResource);
}
}
});
contextMenu.add(deleteTRItem);
}
protected boolean select(TabResource item, String searchTerm) {
if (item.getName() != null
&& item.getName().toLowerCase()
.contains(searchTerm.toLowerCase()))
return true;
if (item.getTabularResourceType() != null
&& item.getTabularResourceType().toLowerCase()
.contains(searchTerm.toLowerCase()))
return true;
if (item.getAgency() != null
&& item.getAgency().toLowerCase()
.contains(searchTerm.toLowerCase()))
return true;
if (item.getDate() != null
&& item.getDate().toLowerCase()
.contains(searchTerm.toLowerCase()))
return true;
if (item.getOwnerLogin() != null
&& item.getOwnerLogin().toLowerCase()
.contains(searchTerm.toLowerCase()))
return true;
return false;
}
protected void loadData(ListLoadConfig loadConfig,
final AsyncCallback<ListLoadResult<TabResource>> callback) {
TDGWTServiceAsync.INSTANCE
.getTabularResources(new AsyncCallback<ArrayList<TabResource>>() {
private void retrieveColumns() {
TRId trId=parent.unionSession.getTrId();
TDGWTServiceAsync.INSTANCE.getColumns(trId,
new AsyncCallback<ArrayList<ColumnData>>() {
@Override
public void onFailure(Throwable caught) {
if (caught instanceof TDGWTSessionExpiredException) {
parent.getEventBus()
@ -270,102 +95,26 @@ public class ColumnMappingPanel extends ContentPanel implements
new SessionExpiredEvent(
SessionExpiredType.EXPIREDONSERVER));
} else {
Log.debug("Error retrieving tabular resource: "
Log.debug("Error retrieving columns: "
+ caught.getLocalizedMessage());
AlertMessageBox d = new AlertMessageBox("Error!",
"Error retrieving tabular resources on server!");
d.addHideHandler(new HideHandler() {
public void onHide(HideEvent event) {
//
}
});
d.show();
UtilsGXT3.alert("Error retrieving columns",
"Error retrieving columns on server!");
}
callback.onFailure(caught);
}
public void onSuccess(ArrayList<TabResource> result) {
Log.debug("loaded " + result.size()
+ " TabularResources");
callback.onSuccess(new ListLoadResultBean<TabResource>(
result));
@Override
public void onSuccess(ArrayList<ColumnData> result) {
/*
* comboColumnReferenceType.reset();
* storeComboColumnReferenceType.clear();
* storeComboColumnReferenceType.addAll(result);
* storeComboColumnReferenceType.commitChanges();
* comboColumnReferenceTypeLabel.setVisible(true);
* forceLayout();
*/
}
});
}
public HandlerRegistration addSelectionHandler(
SelectionHandler<TabResource> handler) {
return grid.getSelectionModel().addSelectionHandler(handler);
}
public TabResource getSelectedItem() {
return grid.getSelectionModel().getSelectedItem();
}
protected class ExtendedListStore<M> extends ListStore<M> {
public ExtendedListStore(ModelKeyProvider<? super M> keyProvider) {
super(keyProvider);
}
public void applyFilters() {
super.applyFilters();
}
}
public void gridReload() {
grid.getLoader().load();
}
protected void deleteTR(TabResource tabResource) {
removableTR = tabResource;
final ConfirmMessageBox mb = new ConfirmMessageBox("Delete",
"Would you like to delete this tabular resource?");
mb.addHideHandler(new HideHandler() {
public void onHide(HideEvent event) {
if (mb.getHideButton() == mb.getButtonById(PredefinedButton.YES
.name())) {
callDeleteTabularResource();
} else if (mb.getHideButton() == mb
.getButtonById(PredefinedButton.NO.name())) {
// perform NO action
}
}
});
mb.setWidth(300);
mb.show();
}
protected void callDeleteTabularResource() {
Log.debug("Delete TR:" + removableTR);
TDGWTServiceAsync.INSTANCE.removeTabularResource(removableTR.getTrId(),
new AsyncCallback<Void>() {
public void onFailure(Throwable caught) {
AlertMessageBox d = new AlertMessageBox("Error",
"Error on delete TabResource: "
+ caught.getLocalizedMessage());
d.addHideHandler(new HideHandler() {
public void onHide(HideEvent event) {
}
});
d.show();
}
public void onSuccess(Void result) {
gridReload();
}
});
}
}

View File

@ -90,7 +90,9 @@ public class UnionOperationInProgressCard extends WizardCard implements
}
/**
*
*/
public void startUnion() {
TDGWTServiceAsync.INSTANCE.startUnion(unionSession,
new AsyncCallback<Void>() {

View File

@ -10,6 +10,7 @@ import com.google.web.bindery.event.shared.EventBus;
/**
*
* @author "Giancarlo Panichi"
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class UnionWizardTD extends WizardWindow {
@ -19,10 +20,11 @@ public class UnionWizardTD extends WizardWindow {
protected UnionSession unionSession;
/**
* The id of the {@link CSVTarget} to use.
* @param targetId
*
* @param trId
* @param title
* @param eventBus
*/
public UnionWizardTD(TRId trId, String title, EventBus eventBus) {
super(title,eventBus);
Log.debug("UnionWizardTD: "+trId);

View File

@ -1,67 +0,0 @@
/**
*
*/
package org.gcube.portlets.user.td.unionwizardwidget.client.util;
import com.google.gwt.core.client.Callback;
import com.google.gwt.user.client.ui.Label;
import com.sencha.gxt.widget.core.client.Dialog;
import com.sencha.gxt.widget.core.client.Dialog.PredefinedButton;
import com.sencha.gxt.widget.core.client.box.MessageBox;
import com.sencha.gxt.widget.core.client.event.HideEvent;
import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class ErrorMessageBox {
private static final String DETAILS = "Details";
public static void showError(String title, String failureReason, final String failureDetails)
{
showError(title, failureReason, failureDetails, new NOPCallBack<Dialog, Void>());
}
public static void showError(String title, String failureReason, final String failureDetails, final Callback<Dialog, Void> callback)
{
final MessageBox box = new MessageBox(title);
box.setMessage(failureReason);
box.addHideHandler(new HideHandler() {
public void onHide(HideEvent event) {
Dialog dialog = (Dialog) event.getSource();
if (dialog.getHideButton().getText().equals(DETAILS)){
//box.close();
showErrorDetails("Error details", failureDetails);
} else callback.onSuccess(dialog);
}
});
box.show();
}
public static void showErrorDetails(String title, String failureDetails)
{
final Dialog simple = new Dialog();
simple.setHeadingText(title);
simple.setPredefinedButtons(PredefinedButton.OK);
simple.setBodyStyleName("pad-text");
simple.add(new Label("<PRE>"+failureDetails+"</PRE>"));
simple.setHideOnButtonClick(true);
simple.setWidth(400);
simple.setHeight(400);
simple.show();
}
}

View File

@ -1,37 +0,0 @@
/**
*
*/
package org.gcube.portlets.user.td.unionwizardwidget.client.util;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class Format {
/**
* Converts a file size into a {@link String} representation adding the misure unit.
* @param size the file size.
* @return the textual representation.
*/
public static String fileSize(long size) {
StringBuilder text = new StringBuilder();
if (size < 1024) {
text.append(size);
text.append(" bytes");
} else if (size < 1048576) {
text.append(Math.round(((size * 10) / 1024)) / 10);
text.append(" KB");
} else if (size < 1073741824) {
text.append(Math.round(((size * 10) / 1048576)) / 10);
text.append(" MB");
} else {
text.append(Math.round(((size * 10) / 1073741824)) / 10);
text.append(" GB");
}
return text.toString();
}
}

View File

@ -1,22 +0,0 @@
/**
*
*/
package org.gcube.portlets.user.td.unionwizardwidget.client.util;
import com.google.gwt.core.client.Callback;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
* @param <T>
* @param <F>
*/
public class NOPCallBack<T,F> implements Callback<T, F> {
public void onFailure(F reason) {}
public void onSuccess(T result) {}
}

View File

@ -0,0 +1,28 @@
package org.gcube.portlets.user.td.unionwizardwidget.client.utils;
import com.sencha.gxt.widget.core.client.box.MessageBox;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class InfoMessageBox extends MessageBox {
/**
* Creates a message box with an info icon and the specified title and
* message.
*
* @param title
* the message box title
* @param message
* the message displayed in the message box
*/
public InfoMessageBox(String title, String message) {
super(title, message);
setIcon(ICONS.info());
}
}

View File

@ -0,0 +1,51 @@
package org.gcube.portlets.user.td.unionwizardwidget.client.utils;
import com.google.gwt.user.client.Element;
import com.sencha.gxt.core.client.dom.XElement;
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;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class UtilsGXT3 {
public static void mask(Element element) {
XElement el = element.<XElement> cast();
el.mask("Loading...");
}
public static void umask(Element element) {
element.<XElement> cast().unmask();
}
public static void alert(String title, String message) {
final AlertMessageBox d = new AlertMessageBox(title, message);
d.addHideHandler(new HideHandler() {
public void onHide(HideEvent event) {
}
});
d.show();
}
public static void info(String title, String message) {
final InfoMessageBox d = new InfoMessageBox(title, message);
d.addHideHandler(new HideHandler() {
public void onHide(HideEvent event) {
}
});
d.show();
}
}