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

@ -136,6 +136,7 @@
</dependency>
<!-- LOGGING -->
<dependency>
<groupId>com.allen-sauer.gwt.log</groupId>

View File

@ -1,5 +1,6 @@
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 com.google.web.bindery.event.shared.EventBus;
@ -18,15 +19,10 @@ public class ResourcesDialog extends Window {
protected String WIDTH = "320px";
protected String HEIGHT = "540px";
protected TRId trId;
protected EventBus eventBus;
protected UserInfo userInfo;
public ResourcesDialog(TRId trId, EventBus eventBus) {
create(trId, eventBus);
}
protected void create(TRId trId, EventBus eventBus) {
this.trId = trId;
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.StringResourceTD;
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.resources.ResourceBundle;
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.type.SessionExpiredType;
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.google.gwt.cell.client.AbstractCell;
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.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.web.bindery.event.shared.EventBus;
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.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.ColumnModel;
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.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 ResourcesDialog parent;
protected UserInfo userInfo;
protected TRId trId;
protected TableData table;
protected String headingTitle;
@ -73,14 +86,17 @@ public class ResourcesPanel extends FramedPanel {
protected RollBackSession rollBackSession;
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();
this.parent = parent;
this.trId = trId;
this.eventBus = eventBus;
forceLayoutOnResize = true;
draw();
retrieveUserInfo();
}
public ResourcesPanel(TRId trId, EventBus eventBus) {
@ -88,7 +104,33 @@ public class ResourcesPanel extends FramedPanel {
this.trId = trId;
this.eventBus = eventBus;
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() {
@ -111,81 +153,103 @@ public class ResourcesPanel extends FramedPanel {
.create(ResourceTDDescriptorProperties.class);
IdentityValueProvider<ResourceTDDescriptor> identityProvider = new IdentityValueProvider<ResourceTDDescriptor>();
final GridSelectionModel<ResourceTDDescriptor> sm = new GridSelectionModel<ResourceTDDescriptor>();
sm.setSelectionMode(SelectionMode.SINGLE);
RowExpander<ResourceTDDescriptor> expander = new RowExpander<ResourceTDDescriptor>(
identityProvider, new AbstractCell<ResourceTDDescriptor>() {
@Override
public void render(Context context,
ResourceTDDescriptor value, SafeHtmlBuilder sb) {
sb.appendHtmlConstant("<table style='font-family: tahoma, arial, verdana, sans-serif;"
+ "width: 100%; border: none;"
+ "font-size: 12px; margin:2px; text-align: left;'>"
+ "<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Name: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"
+ value.getName()
+ "</td>"
+ "</tr>"
+ "<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Description: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"
+ value.getDescription()
+ "</td>"
+ "</tr>"
+ "<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Creation Date: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"
+ value.getCreationDate()
+ "</td>"
+ "</tr>"
+ "<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Creator Id: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"
+ value.getCreatorId()
+ "</td>"
+ "</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;'>"
+ value.getResourceType().toString()
+ "</td>"
+ "</tr>");
sb.appendHtmlConstant(
"<table style='font-family: tahoma, arial, verdana, sans-serif;"
+ "width: 100%; border: none;"
+ "font-size: 12px; margin:2px; text-align: left;'>"
+ "<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Name: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>")
.appendEscaped(value.getName())
.appendHtmlConstant(
"</td>"
+ "</tr>"
+ "<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Description: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>")
.appendEscaped(value.getDescription())
.appendHtmlConstant(
"</td>"
+ "</tr>"
+ "<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Creation Date: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>")
.appendEscaped(value.getCreationDate())
.appendHtmlConstant(
"</td>"
+ "</tr>"
+ "<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Creator Id: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>")
.append(value.getCreatorId())
.appendHtmlConstant(
"</td>"
+ "</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();
if (resource instanceof InternalURITD) {
InternalURITD internalURITD = (InternalURITD) resource;
sb.appendHtmlConstant("<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>File Id: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"
+ internalURITD.getFileId()
+ "</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='"+ internalURITD.getUri()+"' title='"+internalURITD.getUri()+"'>link</a>"
+ "</td>"
+ "</tr>");
sb.appendHtmlConstant(
"<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>File Id: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>")
.appendEscaped(internalURITD.getFileId())
.appendHtmlConstant("</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 {
if (resource instanceof StringResourceTD) {
StringResourceTD stringResourceTD = (StringResourceTD) resource;
sb.appendHtmlConstant("<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Value: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"
+ stringResourceTD.getStringValue()
+ "</td>" + "</tr>");
sb.appendHtmlConstant(
"<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Value: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>")
.appendEscaped(
stringResourceTD
.getStringValue())
.appendHtmlConstant("</td>" + "</tr>");
} else {
if (resource instanceof TableResourceTD) {
TableResourceTD tableResourceTD = (TableResourceTD) resource;
sb.appendHtmlConstant("<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Table Id: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"
+ tableResourceTD.getTableId()
+ "</td>" + "</tr>");
sb.appendHtmlConstant(
"<tr>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>Table Id: </b></td>"
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>")
.append(tableResourceTD
.getTableId())
.appendHtmlConstant(
"</td>" + "</tr>");
} else {
@ -205,8 +269,9 @@ public class ResourcesPanel extends FramedPanel {
@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {
sb.appendHtmlConstant("<span title='" + value + "'>" + value
+ "</span>");
sb.appendHtmlConstant("<span title='").appendEscaped(value)
.appendHtmlConstant("'>").appendEscaped(value)
.appendHtmlConstant("</span>");
}
@ -214,18 +279,7 @@ public class ResourcesPanel extends FramedPanel {
ColumnConfig<ResourceTDDescriptor, ResourceTDType> typeColumn = new ColumnConfig<ResourceTDDescriptor, ResourceTDType>(
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, ?>>();
l.add(expander);
l.add(nameCol);
@ -268,8 +322,8 @@ public class ResourcesPanel extends FramedPanel {
};
grid.setLoader(loader);
grid.setSelectionModel(sm);
grid.setSize("200px", "300px");
grid.getView().setStripeRows(true);
grid.getView().setColumnLines(true);
grid.getView().setAutoFill(true);
@ -279,57 +333,100 @@ public class ResourcesPanel extends FramedPanel {
grid.setColumnResize(true);
grid.getView().setAutoExpandColumn(nameCol);
grid.getView().setEmptyText("Empty");
expander.initPlugin(grid);
/*
* VerticalLayoutContainer v = new VerticalLayoutContainer();
* v.setScrollMode(ScrollMode.AUTO); v.add(grid, new
* VerticalLayoutData(1, 1, new Margins(0))); v.forceLayout();
*/
createContextMenu();
add(grid, new MarginData(0));
onResize();
}
protected void startSearchRollBackId(int rowIndex) {
currentRowIndex = rowIndex;
currentTDDescriptor = store.get(rowIndex - 1);
Log.debug(currentTDDescriptor.toString() + " was clicked.[rowIndex="
+ currentRowIndex + " ]");
callRollBack();
protected void createContextMenu() {
contextMenu = new Menu();
openItem = new MenuItem();
openItem.setText("Open");
openItem.setIcon(ResourceBundle.INSTANCE.codelistLink());
openItem.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
ResourceTDDescriptor selected = grid.getSelectionModel().getSelectedItem();
Log.debug("selected: "+selected);
requestOpen(selected);
}
});
contextMenu.add(openItem);
grid.setContextMenu(contextMenu);
}
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 callRollBack() {
/*
* rollBackSession = new RollBackSession(trId,
*
* currentTDDescriptor.getHistoryId());
* TDGWTServiceAsync.INSTANCE.startRollBack(rollBackSession, new
* AsyncCallback<String>() {
*
* public void onFailure(Throwable caught) { if (caught instanceof
* TDGWTSessionExpiredException) { eventBus.fireEvent(new
* SessionExpiredEvent( SessionExpiredType.EXPIREDONSERVER)); } else {
* 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 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,
final AsyncCallback<ListLoadResult<ResourceTDDescriptor>> callback) {
@ -404,6 +501,8 @@ public class ResourcesPanel extends FramedPanel {
});
}
protected void close() {
if (parent != null) {

View File

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