Added Generic File to ResourceType

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-resources-widget@112243 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2015-02-23 17:27:25 +00:00
parent 99b7a0bc82
commit 254871f2b3
8 changed files with 142 additions and 65 deletions

View File

@ -27,6 +27,7 @@ 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.mime.MimeTypeSupport;
import org.gcube.portlets.user.td.widgetcommonevent.shared.uriresolver.ApplicationType; import org.gcube.portlets.user.td.widgetcommonevent.shared.uriresolver.ApplicationType;
import org.gcube.portlets.user.td.wizardwidget.client.WizardListener; import org.gcube.portlets.user.td.wizardwidget.client.WizardListener;
@ -108,7 +109,7 @@ public class ResourcesPanel extends FramedPanel {
private MenuItem saveItem; private MenuItem saveItem;
private MenuItem removeItem; private MenuItem removeItem;
private RemoveResourceSession removeResourceSession; private RemoveResourceSession removeResourceSession;
private SaveResourceSession saveResourceSession; private SaveResourceSession saveResourceSession;
public ResourcesPanel(ResourcesDialog parent, TRId trId, EventBus eventBus) { public ResourcesPanel(ResourcesDialog parent, TRId trId, EventBus eventBus) {
@ -232,11 +233,16 @@ public class ResourcesPanel extends FramedPanel {
String resourceData = ""; String resourceData = "";
if (resource instanceof InternalURITD) { if (resource instanceof InternalURITD) {
InternalURITD internalURITD = (InternalURITD) resource; InternalURITD internalURITD = (InternalURITD) resource;
resourceData = "<tr>" if (internalURITD.getFileId() != null
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>File Id: </b></td>" && !internalURITD.getFileId().isEmpty()) {
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>" resourceData = "<tr>"
+ SafeHtmlUtils.htmlEscape(internalURITD + "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>File Id: </b></td>"
.getFileId()) + "</td>" + "</tr>"; + "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"
+ SafeHtmlUtils
.htmlEscape(internalURITD
.getFileId()) + "</td>"
+ "</tr>";
}
} else { } else {
if (resource instanceof StringResourceTD) { if (resource instanceof StringResourceTD) {
@ -290,35 +296,34 @@ public class ResourcesPanel extends FramedPanel {
ColumnConfig<ResourceTDDescriptor, ResourceTDType> typeColumn = new ColumnConfig<ResourceTDDescriptor, ResourceTDType>( ColumnConfig<ResourceTDDescriptor, ResourceTDType> typeColumn = new ColumnConfig<ResourceTDDescriptor, ResourceTDType>(
props.resourceType(), 30, "Type"); props.resourceType(), 30, "Type");
ResourceTDTypeButtonCell button = new ResourceTDTypeButtonCell(); ResourceTDTypeButtonCell button = new ResourceTDTypeButtonCell();
button.addSelectHandler(new SelectHandler() { button.addSelectHandler(new SelectHandler() {
@Override @Override
public void onSelect(SelectEvent event) { public void onSelect(SelectEvent event) {
Log.debug("Button Pressed"); Log.debug("Button Pressed");
Context c = event.getContext(); Context c = event.getContext();
int rowIndex = c.getIndex(); int rowIndex = c.getIndex();
int columnIndex=c.getColumn(); int columnIndex = c.getColumn();
Element el=grid.getView().getCell(rowIndex, columnIndex); Element el = grid.getView().getCell(rowIndex, columnIndex);
NativeEvent contextEvent = Document.get().createMouseEvent(BrowserEvents.CONTEXTMENU, true, true,0, 0, 0, NativeEvent contextEvent = Document.get().createMouseEvent(
el.getAbsoluteLeft(), el.getAbsoluteTop(), false, false, false, false, BrowserEvents.CONTEXTMENU, true, true, 0, 0, 0,
NativeEvent.BUTTON_RIGHT, null); el.getAbsoluteLeft(), el.getAbsoluteTop(), false,
false, false, false, NativeEvent.BUTTON_RIGHT, null);
//NativeEvent contextEvent = Document.get().createContextMenuEvent();
// NativeEvent contextEvent =
// Document.get().createContextMenuEvent();
el.dispatchEvent(contextEvent); el.dispatchEvent(contextEvent);
//DomEvent // DomEvent
} }
}); });
typeColumn.setCell(button); 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);
@ -358,9 +363,7 @@ public class ResourcesPanel extends FramedPanel {
} }
}); });
} }
}; };
grid.setLoader(loader); grid.setLoader(loader);
@ -487,6 +490,19 @@ public class ResourcesPanel extends FramedPanel {
contextMenu.add(removeItem); contextMenu.add(removeItem);
grid.setContextMenu(contextMenu); grid.setContextMenu(contextMenu);
break; break;
case GENERIC_FILE:
contextMenu.clear();
openItem.setIcon(ResourceBundle.INSTANCE.file());
contextMenu.add(openItem);
contextMenu.add(saveItem);
contextMenu.add(removeItem);
grid.setContextMenu(contextMenu);
break;
case GENERIC_TABLE:
contextMenu.clear();
contextMenu.add(removeItem);
grid.setContextMenu(contextMenu);
break;
default: default:
contextMenu.clear(); contextMenu.clear();
contextMenu.add(removeItem); contextMenu.add(removeItem);
@ -504,23 +520,28 @@ public class ResourcesPanel extends FramedPanel {
protected void requestSave(ResourceTDDescriptor resourceTDDescriptor) { protected void requestSave(ResourceTDDescriptor resourceTDDescriptor) {
switch (resourceTDDescriptor.getResourceType()) { switch (resourceTDDescriptor.getResourceType()) {
case CHART: case CHART:
requestSaveResource(resourceTDDescriptor, ".jpg", "image/jpeg"); requestSaveResource(resourceTDDescriptor, MimeTypeSupport._jpg);
break; break;
case CODELIST: case CODELIST:
break; break;
case CSV: case CSV:
requestSaveResource(resourceTDDescriptor, ".csv", "text/csv"); requestSaveResource(resourceTDDescriptor, MimeTypeSupport._csv);
break; break;
case GUESSER: case GUESSER:
break; break;
case JSON: case JSON:
requestSaveResource(resourceTDDescriptor, ".json", requestSaveResource(resourceTDDescriptor, MimeTypeSupport._json);
"application/json");
break; break;
case MAP: case MAP:
break; break;
case SDMX: case SDMX:
break; break;
case GENERIC_FILE:
requestSaveResource(resourceTDDescriptor, MimeTypeSupport._unknow);
break;
case GENERIC_TABLE:
// requestSaveResource(resourceTDDescriptor, MimeTypeSupport._csv);
break;
default: default:
break; break;
@ -529,29 +550,16 @@ public class ResourcesPanel extends FramedPanel {
} }
protected void requestSaveResource( protected void requestSaveResource(
ResourceTDDescriptor resourceTDDescriptor, String extension, ResourceTDDescriptor resourceTDDescriptor, MimeTypeSupport mime) {
String mimeType) {
InternalURITD internalURITD;
ResourceTD resource = resourceTDDescriptor.getResourceTD();
if (resource instanceof InternalURITD) {
internalURITD=(InternalURITD)resource;
} else {
UtilsGXT3.alert("Attention", "This resource does not have valid internal URI!");
Log.debug("Attention, this resource does not have valid Internal URI!");
return;
}
Log.debug("InteranlURI: "+internalURITD);
saveResourceSession = new SaveResourceSession(); saveResourceSession = new SaveResourceSession();
saveResourceSession.setMimeType(mimeType); saveResourceSession.setResourceTDDescriptor(resourceTDDescriptor);
saveResourceSession.setExtension(extension); saveResourceSession.setMime(mime);
saveResourceSession.setFileName(resourceTDDescriptor.getName() saveResourceSession.setFileName(resourceTDDescriptor.getName());
+ extension);
saveResourceSession.setFileDescription(resourceTDDescriptor saveResourceSession.setFileDescription(resourceTDDescriptor
.getDescription()); .getDescription());
saveResourceSession.setUri(internalURITD.getUri());
GWT.runAsync(new RunAsyncCallback() { GWT.runAsync(new RunAsyncCallback() {
public void onSuccess() { public void onSuccess() {
@ -561,9 +569,9 @@ public class ResourcesPanel extends FramedPanel {
saveResourceWizard.addListener(new WizardListener() { saveResourceWizard.addListener(new WizardListener() {
public void failed(String title, String message, String details, public void failed(String title, String message,
Throwable throwable) { String details, Throwable throwable) {
Log.debug(title + ", " + message+" "+details); Log.debug(title + ", " + message + " " + details);
} }
public void completed(TRId id) { public void completed(TRId id) {
@ -647,6 +655,11 @@ public class ResourcesPanel extends FramedPanel {
break; break;
case SDMX: case SDMX:
break; break;
case GENERIC_FILE:
requestOpenGenericFile(resourceTDDescriptor);
break;
case GENERIC_TABLE:
break;
default: default:
break; break;
@ -655,9 +668,10 @@ public class ResourcesPanel extends FramedPanel {
} }
private void repquestOpenChart(ResourceTDDescriptor resourceTDDescriptor) { private void repquestOpenChart(ResourceTDDescriptor resourceTDDescriptor) {
ChartViewerDialog chartDialog=new ChartViewerDialog(resourceTDDescriptor, trId, eventBus); ChartViewerDialog chartDialog = new ChartViewerDialog(
resourceTDDescriptor, trId, eventBus);
chartDialog.show(); chartDialog.show();
} }
protected void requestOpenMap( protected void requestOpenMap(
@ -693,20 +707,10 @@ public class ResourcesPanel extends FramedPanel {
} else { } else {
if (resource instanceof InternalURITD) { if (resource instanceof InternalURITD) {
/*
* Log.error(
* "Error with resource: is internal uri resource no uri present"
* ); UtilsGXT3.alert("Error with resource",
* "Error is string resource no uri present");
*/
} else { } else {
if (resource instanceof TableResourceTD) { if (resource instanceof TableResourceTD) {
/*
* Log.error(
* "Error with resource: is table resource no uri present");
* UtilsGXT3.alert("Error with resource",
* "Error is table resource no uri present");
*/
} else { } else {
Log.error("Error with resource: no valid resource"); Log.error("Error with resource: no valid resource");
UtilsGXT3.alert("Error with resource", UtilsGXT3.alert("Error with resource",
@ -717,6 +721,58 @@ public class ResourcesPanel extends FramedPanel {
} }
} }
} }
protected void requestOpenGenericFile(
final ResourceTDDescriptor resourceTDDescriptor) {
ResourceTD resource = resourceTDDescriptor.getResourceTD();
if (resource instanceof StringResourceTD) {
StringResourceTD genericFileResourceTD = (StringResourceTD) resource;
UriResolverSession uriResolverSession = new UriResolverSession(
genericFileResourceTD.getStringValue(), ApplicationType.SMP);
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 {
if (resource instanceof InternalURITD) {
} else {
if (resource instanceof TableResourceTD) {
} else {
Log.error("Error with resource: no valid resource");
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) {

View File

@ -74,6 +74,12 @@ public class ResourceTDTypeButtonCellAppearance {
case SDMX: case SDMX:
imageResource = ResourceBundle.INSTANCE.sdmx(); imageResource = ResourceBundle.INSTANCE.sdmx();
break; break;
case GENERIC_FILE:
imageResource = ResourceBundle.INSTANCE.file();
break;
case GENERIC_TABLE:
imageResource = ResourceBundle.INSTANCE.table();
break;
default: default:
imageResource = ResourceBundle.INSTANCE.resources(); imageResource = ResourceBundle.INSTANCE.resources();
break; break;

View File

@ -132,6 +132,12 @@ public interface ResourceBundle extends ClientBundle {
@Source("application.png") @Source("application.png")
ImageResource application(); ImageResource application();
@Source("file_32.png")
ImageResource file32();
@Source("file.png")
ImageResource file();
@Source("Resources.css") @Source("Resources.css")
ResourceCSS resourceCSS(); ResourceCSS resourceCSS();
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 517 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 827 B

View File

@ -8,6 +8,7 @@ import java.util.List;
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.SaveResourceSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.SaveResourceSession;
import org.gcube.portlets.user.td.resourceswidget.client.workspace.WorkspacePanel; import org.gcube.portlets.user.td.resourceswidget.client.workspace.WorkspacePanel;
import org.gcube.portlets.user.td.widgetcommonevent.shared.mime.MimeTypeSupport;
import org.gcube.portlets.user.td.wizardwidget.client.WizardCard; import org.gcube.portlets.user.td.wizardwidget.client.WizardCard;
import org.gcube.portlets.widgets.lighttree.client.Item; import org.gcube.portlets.widgets.lighttree.client.Item;
import org.gcube.portlets.widgets.lighttree.client.ItemType; import org.gcube.portlets.widgets.lighttree.client.ItemType;
@ -56,7 +57,15 @@ public class WorkSpaceSelectionCard extends WizardCard {
fileName = new TextField(); fileName = new TextField();
fileName.setAllowBlank(false); fileName.setAllowBlank(false);
fileName.setWidth("410px"); fileName.setWidth("410px");
fileName.setValue(saveResourceSession.getFileName());
MimeTypeSupport mime=saveResourceSession.getMime();
if(mime==null|| mime.compareTo(MimeTypeSupport._unknow)==0){
fileName.setValue(saveResourceSession.getFileName());
} else {
fileName.setValue(saveResourceSession.getFileName()+
mime.getExtension());
}
p.add(new FieldLabel(fileName, "File Name"), new VerticalLayoutData(-1, p.add(new FieldLabel(fileName, "File Name"), new VerticalLayoutData(-1,
-1)); -1));

Binary file not shown.

After

Width:  |  Height:  |  Size: 517 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 827 B