Added Uri Resolver

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-resources-widget@100793 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-10-17 16:41:23 +00:00
parent e44da1723a
commit 907e9c51eb
4 changed files with 218 additions and 121 deletions

View File

@ -135,6 +135,7 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- LOGGING --> <!-- LOGGING -->
<dependency> <dependency>

View File

@ -1,5 +1,6 @@
package org.gcube.portlets.user.td.resourceswidget.client; package org.gcube.portlets.user.td.resourceswidget.client;
import org.gcube.portlets.user.td.gwtservice.shared.user.UserInfo;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import com.google.web.bindery.event.shared.EventBus; import com.google.web.bindery.event.shared.EventBus;
@ -18,15 +19,10 @@ public class ResourcesDialog extends Window {
protected String WIDTH = "320px"; protected String WIDTH = "320px";
protected String HEIGHT = "540px"; protected String HEIGHT = "540px";
protected TRId trId; protected TRId trId;
protected EventBus eventBus; protected EventBus eventBus;
protected UserInfo userInfo;
public ResourcesDialog(TRId trId, EventBus eventBus) { public ResourcesDialog(TRId trId, EventBus eventBus) {
create(trId, eventBus);
}
protected void create(TRId trId, EventBus eventBus) {
this.trId = trId; this.trId = trId;
this.eventBus=eventBus; this.eventBus=eventBus;

View File

@ -14,21 +14,29 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDDescr
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDType; import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDType;
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.StringResourceTD; import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.StringResourceTD;
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.TableResourceTD; import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.TableResourceTD;
import org.gcube.portlets.user.td.gwtservice.shared.uriresolver.UriResolverSession;
import org.gcube.portlets.user.td.gwtservice.shared.user.UserInfo;
import org.gcube.portlets.user.td.resourceswidget.client.properties.ResourceTDDescriptorProperties; import org.gcube.portlets.user.td.resourceswidget.client.properties.ResourceTDDescriptorProperties;
import org.gcube.portlets.user.td.resourceswidget.client.resources.ResourceBundle;
import org.gcube.portlets.user.td.resourceswidget.client.utils.UtilsGXT3; import org.gcube.portlets.user.td.resourceswidget.client.utils.UtilsGXT3;
import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent; 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.client.type.SessionExpiredType;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import org.gcube.portlets.user.td.widgetcommonevent.shared.uriresolver.ApplicationType;
import com.allen_sauer.gwt.log.client.Log; import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.cell.client.AbstractCell; import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand; 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.safehtml.shared.SafeHtmlBuilder; import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.web.bindery.event.shared.EventBus; import com.google.web.bindery.event.shared.EventBus;
import com.sencha.gxt.core.client.IdentityValueProvider; 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.client.loader.RpcProxy;
import com.sencha.gxt.data.shared.ListStore; import com.sencha.gxt.data.shared.ListStore;
import com.sencha.gxt.data.shared.loader.ListLoadConfig; import com.sencha.gxt.data.shared.loader.ListLoadConfig;
@ -42,7 +50,11 @@ import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
import com.sencha.gxt.widget.core.client.grid.ColumnConfig; 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.ColumnModel;
import com.sencha.gxt.widget.core.client.grid.Grid; import com.sencha.gxt.widget.core.client.grid.Grid;
import com.sencha.gxt.widget.core.client.grid.GridSelectionModel;
import com.sencha.gxt.widget.core.client.grid.RowExpander; import com.sencha.gxt.widget.core.client.grid.RowExpander;
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;
/** /**
* *
@ -58,6 +70,7 @@ public class ResourcesPanel extends FramedPanel {
protected String HEIGHT = "520px"; protected String HEIGHT = "520px";
protected ResourcesDialog parent; protected ResourcesDialog parent;
protected UserInfo userInfo;
protected TRId trId; protected TRId trId;
protected TableData table; protected TableData table;
protected String headingTitle; protected String headingTitle;
@ -73,14 +86,17 @@ public class ResourcesPanel extends FramedPanel {
protected RollBackSession rollBackSession; protected RollBackSession rollBackSession;
private boolean drawed = false; private boolean drawed = false;
private Menu contextMenu;
private MenuItem openItem;
public ResourcesPanel(ResourcesDialog parent, TRId trId, EventBus eventBus) { public ResourcesPanel(ResourcesDialog parent, TRId trId,
EventBus eventBus) {
super(); super();
this.parent = parent; this.parent = parent;
this.trId = trId; this.trId = trId;
this.eventBus = eventBus; this.eventBus = eventBus;
forceLayoutOnResize = true; forceLayoutOnResize = true;
draw(); retrieveUserInfo();
} }
public ResourcesPanel(TRId trId, EventBus eventBus) { public ResourcesPanel(TRId trId, EventBus eventBus) {
@ -88,7 +104,33 @@ public class ResourcesPanel extends FramedPanel {
this.trId = trId; this.trId = trId;
this.eventBus = eventBus; this.eventBus = eventBus;
forceLayoutOnResize = true; forceLayoutOnResize = true;
draw(); retrieveUserInfo();
}
protected void retrieveUserInfo(){
TDGWTServiceAsync.INSTANCE.hello(
new AsyncCallback<UserInfo>() {
public void onFailure(Throwable caught) {
if (caught instanceof TDGWTSessionExpiredException) {
eventBus.fireEvent(new SessionExpiredEvent(
SessionExpiredType.EXPIREDONSERVER));
} else {
Log.error("Error Retrieving User Info: "
+ caught.getLocalizedMessage());
UtilsGXT3.alert("Error",
"Error retrieving User Info");
}
}
public void onSuccess(UserInfo userInfo) {
Log.debug("User Info: " + userInfo);
draw();
}
});
} }
protected void draw() { protected void draw() {
@ -111,81 +153,103 @@ public class ResourcesPanel extends FramedPanel {
.create(ResourceTDDescriptorProperties.class); .create(ResourceTDDescriptorProperties.class);
IdentityValueProvider<ResourceTDDescriptor> identityProvider = new IdentityValueProvider<ResourceTDDescriptor>(); IdentityValueProvider<ResourceTDDescriptor> identityProvider = new IdentityValueProvider<ResourceTDDescriptor>();
final GridSelectionModel<ResourceTDDescriptor> sm = new GridSelectionModel<ResourceTDDescriptor>();
sm.setSelectionMode(SelectionMode.SINGLE);
RowExpander<ResourceTDDescriptor> expander = new RowExpander<ResourceTDDescriptor>( RowExpander<ResourceTDDescriptor> expander = new RowExpander<ResourceTDDescriptor>(
identityProvider, new AbstractCell<ResourceTDDescriptor>() { identityProvider, new AbstractCell<ResourceTDDescriptor>() {
@Override @Override
public void render(Context context, public void render(Context context,
ResourceTDDescriptor value, SafeHtmlBuilder sb) { ResourceTDDescriptor value, SafeHtmlBuilder sb) {
sb.appendHtmlConstant("<table style='font-family: tahoma, arial, verdana, sans-serif;" sb.appendHtmlConstant(
+ "width: 100%; border: none;" "<table style='font-family: tahoma, arial, verdana, sans-serif;"
+ "font-size: 12px; margin:2px; text-align: left;'>" + "width: 100%; border: none;"
+ "<tr>" + "font-size: 12px; margin:2px; text-align: left;'>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Name: </b></td>" + "<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>" + "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Name: </b></td>"
+ value.getName() + "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>")
+ "</td>" .appendEscaped(value.getName())
+ "</tr>" .appendHtmlConstant(
+ "<tr>" "</td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Description: </b></td>" + "</tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>" + "<tr>"
+ value.getDescription() + "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Description: </b></td>"
+ "</td>" + "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>")
+ "</tr>" .appendEscaped(value.getDescription())
+ "<tr>" .appendHtmlConstant(
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Creation Date: </b></td>" "</td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>" + "</tr>"
+ value.getCreationDate() + "<tr>"
+ "</td>" + "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Creation Date: </b></td>"
+ "</tr>" + "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>")
+ "<tr>" .appendEscaped(value.getCreationDate())
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Creator Id: </b></td>" .appendHtmlConstant(
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>" "</td>"
+ value.getCreatorId() + "</tr>"
+ "</td>" + "<tr>"
+ "</tr>" + "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Creator Id: </b></td>"
+ "<tr>" + "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>")
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Type: </b></td>" .append(value.getCreatorId())
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>" .appendHtmlConstant(
+ value.getResourceType().toString() "</td>"
+ "</td>" + "</tr>"
+ "</tr>"); + "<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Type: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>")
.appendEscaped(
value.getResourceType().toString())
.appendHtmlConstant("</td>" + "</tr>");
ResourceTD resource = value.getResourceTD(); ResourceTD resource = value.getResourceTD();
if (resource instanceof InternalURITD) { if (resource instanceof InternalURITD) {
InternalURITD internalURITD = (InternalURITD) resource; InternalURITD internalURITD = (InternalURITD) resource;
sb.appendHtmlConstant("<tr>" sb.appendHtmlConstant(
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>File Id: </b></td>" "<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>" + "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>File Id: </b></td>"
+ internalURITD.getFileId() + "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>")
+ "</td>" + "</tr>"); .appendEscaped(internalURITD.getFileId())
sb.appendHtmlConstant("<tr>" .appendHtmlConstant("</td>" + "</tr>");
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>URI: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"
+ "<a href='"+ internalURITD.getUri()+"' title='"+internalURITD.getUri()+"'>link</a>"
+ "</td>" /*
+ "</tr>"); sb.appendHtmlConstant(
"<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>URI: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"
+ "<a href='")
.appendEscaped(internalURITD.getUri())
.appendHtmlConstant("' title='")
.appendEscaped(internalURITD.getUri())
.appendHtmlConstant(
"'>link</a>" + "</td>" + "</tr>");*/
} else { } else {
if (resource instanceof StringResourceTD) { if (resource instanceof StringResourceTD) {
StringResourceTD stringResourceTD = (StringResourceTD) resource; StringResourceTD stringResourceTD = (StringResourceTD) resource;
sb.appendHtmlConstant("<tr>" sb.appendHtmlConstant(
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Value: </b></td>" "<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>" + "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Value: </b></td>"
+ stringResourceTD.getStringValue() + "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>")
+ "</td>" + "</tr>"); .appendEscaped(
stringResourceTD
.getStringValue())
.appendHtmlConstant("</td>" + "</tr>");
} else { } else {
if (resource instanceof TableResourceTD) { if (resource instanceof TableResourceTD) {
TableResourceTD tableResourceTD = (TableResourceTD) resource; TableResourceTD tableResourceTD = (TableResourceTD) resource;
sb.appendHtmlConstant("<tr>" sb.appendHtmlConstant(
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Table Id: </b></td>" "<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>" + "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Table Id: </b></td>"
+ tableResourceTD.getTableId() + "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>")
+ "</td>" + "</tr>"); .append(tableResourceTD
.getTableId())
.appendHtmlConstant(
"</td>" + "</tr>");
} else { } else {
@ -205,8 +269,9 @@ public class ResourcesPanel extends FramedPanel {
@Override @Override
public void render(Context context, String value, SafeHtmlBuilder sb) { public void render(Context context, String value, SafeHtmlBuilder sb) {
sb.appendHtmlConstant("<span title='" + value + "'>" + value sb.appendHtmlConstant("<span title='").appendEscaped(value)
+ "</span>"); .appendHtmlConstant("'>").appendEscaped(value)
.appendHtmlConstant("</span>");
} }
@ -214,18 +279,7 @@ public class ResourcesPanel extends FramedPanel {
ColumnConfig<ResourceTDDescriptor, ResourceTDType> typeColumn = new ColumnConfig<ResourceTDDescriptor, ResourceTDType>( ColumnConfig<ResourceTDDescriptor, ResourceTDType> typeColumn = new ColumnConfig<ResourceTDDescriptor, ResourceTDType>(
props.resourceType(), 40, "Type"); props.resourceType(), 40, "Type");
/*
* ActionButtonCellNoFirst button = new ActionButtonCellNoFirst();
* button.setIcon(ResourceBundle.INSTANCE.undo());
* button.setTitle("Undo"); button.addSelectHandler(new SelectHandler()
* {
*
* @Override public void onSelect(SelectEvent event) {
* Log.debug("Button Undo Pressed"); Context c = event.getContext(); int
* rowIndex = c.getIndex(); startSearchRollBackId(rowIndex); } });
*
* typeColumn.setCell(button);
*/
List<ColumnConfig<ResourceTDDescriptor, ?>> l = new ArrayList<ColumnConfig<ResourceTDDescriptor, ?>>(); List<ColumnConfig<ResourceTDDescriptor, ?>> l = new ArrayList<ColumnConfig<ResourceTDDescriptor, ?>>();
l.add(expander); l.add(expander);
l.add(nameCol); l.add(nameCol);
@ -268,8 +322,8 @@ public class ResourcesPanel extends FramedPanel {
}; };
grid.setLoader(loader); grid.setLoader(loader);
grid.setSelectionModel(sm);
grid.setSize("200px", "300px"); grid.setSize("200px", "300px");
grid.getView().setStripeRows(true); grid.getView().setStripeRows(true);
grid.getView().setColumnLines(true); grid.getView().setColumnLines(true);
grid.getView().setAutoFill(true); grid.getView().setAutoFill(true);
@ -279,56 +333,99 @@ public class ResourcesPanel extends FramedPanel {
grid.setColumnResize(true); grid.setColumnResize(true);
grid.getView().setAutoExpandColumn(nameCol); grid.getView().setAutoExpandColumn(nameCol);
grid.getView().setEmptyText("Empty"); grid.getView().setEmptyText("Empty");
expander.initPlugin(grid); expander.initPlugin(grid);
createContextMenu();
/*
* VerticalLayoutContainer v = new VerticalLayoutContainer();
* v.setScrollMode(ScrollMode.AUTO); v.add(grid, new
* VerticalLayoutData(1, 1, new Margins(0))); v.forceLayout();
*/
add(grid, new MarginData(0)); add(grid, new MarginData(0));
onResize(); onResize();
} }
protected void startSearchRollBackId(int rowIndex) { protected void createContextMenu() {
currentRowIndex = rowIndex; contextMenu = new Menu();
currentTDDescriptor = store.get(rowIndex - 1);
Log.debug(currentTDDescriptor.toString() + " was clicked.[rowIndex="
+ currentRowIndex + " ]");
callRollBack();
} openItem = new MenuItem();
openItem.setText("Open");
openItem.setIcon(ResourceBundle.INSTANCE.codelistLink());
openItem.addSelectionHandler(new SelectionHandler<Item>() {
protected void callRollBack() { @Override
/* public void onSelection(SelectionEvent<Item> event) {
* rollBackSession = new RollBackSession(trId, ResourceTDDescriptor selected = grid.getSelectionModel().getSelectedItem();
* Log.debug("selected: "+selected);
* currentTDDescriptor.getHistoryId()); requestOpen(selected);
* TDGWTServiceAsync.INSTANCE.startRollBack(rollBackSession, new }
* AsyncCallback<String>() {
*
* public void onFailure(Throwable caught) { if (caught instanceof });
* TDGWTSessionExpiredException) { eventBus.fireEvent(new contextMenu.add(openItem);
* SessionExpiredEvent( SessionExpiredType.EXPIREDONSERVER)); } else { grid.setContextMenu(contextMenu);
* 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.error("Error in rollback: " + caught.getLocalizedMessage());
* UtilsGXT3 .alert("Error in rollback", "Error: " +
* caught.getLocalizedMessage()); } } } }
*
* public void onSuccess(String taskId) { Log.debug("Rollback started");
* //openMonitorDialog(taskId);
*
* }
*
* });
*/
} }
protected void requestOpen(ResourceTDDescriptor resourceTDDescriptor) {
switch (resourceTDDescriptor.getResourceType()){
case CHART:
break;
case CODELIST:
break;
case CSV:
break;
case GUESSER:
break;
case JSON:
break;
case MAP:
requestOpenMap(resourceTDDescriptor);
break;
case SDMX:
break;
default:
break;
}
}
protected void requestOpenMap(final ResourceTDDescriptor resourceTDDescriptor){
ResourceTD resource=resourceTDDescriptor.getResourceTD();
if (resource instanceof InternalURITD) {
InternalURITD internalURITD = (InternalURITD) resource;
UriResolverSession uriResolverSession=new UriResolverSession(internalURITD.getUri(), ApplicationType.GIS);
TDGWTServiceAsync.INSTANCE.getUriFromResolver(uriResolverSession, new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
if (caught instanceof TDGWTSessionExpiredException) {
eventBus.fireEvent(new SessionExpiredEvent(
SessionExpiredType.EXPIREDONSERVER));
} else {
Log.error("Error with uri resolver: "
+ caught.getLocalizedMessage());
UtilsGXT3.alert("Error",
"Error retrieving uri from resolver");
}
}
public void onSuccess(String link) {
Log.debug("Retrieved link: " + link);
Window.open(link, resourceTDDescriptor.getName(), "");
}
});
} else {
Log.error("Error with resource: no valid InternalUri");
UtilsGXT3.alert("Error with resource",
"Error no valid InternalUri");
}
}
protected void loadData(ListLoadConfig loadConfig, protected void loadData(ListLoadConfig loadConfig,
final AsyncCallback<ListLoadResult<ResourceTDDescriptor>> callback) { final AsyncCallback<ListLoadResult<ResourceTDDescriptor>> callback) {
@ -404,6 +501,8 @@ public class ResourcesPanel extends FramedPanel {
}); });
} }
protected void close() { protected void close() {
if (parent != null) { if (parent != null) {

View File

@ -20,6 +20,7 @@ public class ResourcesWidgetEntry implements EntryPoint {
public void onModuleLoad() { public void onModuleLoad() {
EventBus eventBus= new SimpleEventBus(); EventBus eventBus= new SimpleEventBus();
TRId trId=new TRId(); TRId trId=new TRId();
//For example Tabular Resource 7 and table 402 //For example Tabular Resource 7 and table 402