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.type.SessionExpiredType;
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.wizardwidget.client.WizardListener;
@ -108,7 +109,7 @@ public class ResourcesPanel extends FramedPanel {
private MenuItem saveItem;
private MenuItem removeItem;
private RemoveResourceSession removeResourceSession;
private RemoveResourceSession removeResourceSession;
private SaveResourceSession saveResourceSession;
public ResourcesPanel(ResourcesDialog parent, TRId trId, EventBus eventBus) {
@ -232,11 +233,16 @@ public class ResourcesPanel extends FramedPanel {
String resourceData = "";
if (resource instanceof InternalURITD) {
InternalURITD internalURITD = (InternalURITD) resource;
resourceData = "<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;'>"
+ SafeHtmlUtils.htmlEscape(internalURITD
.getFileId()) + "</td>" + "</tr>";
if (internalURITD.getFileId() != null
&& !internalURITD.getFileId().isEmpty()) {
resourceData = "<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;'>"
+ SafeHtmlUtils
.htmlEscape(internalURITD
.getFileId()) + "</td>"
+ "</tr>";
}
} else {
if (resource instanceof StringResourceTD) {
@ -290,35 +296,34 @@ public class ResourcesPanel extends FramedPanel {
ColumnConfig<ResourceTDDescriptor, ResourceTDType> typeColumn = new ColumnConfig<ResourceTDDescriptor, ResourceTDType>(
props.resourceType(), 30, "Type");
ResourceTDTypeButtonCell button = new ResourceTDTypeButtonCell();
button.addSelectHandler(new SelectHandler() {
@Override
public void onSelect(SelectEvent event) {
Log.debug("Button Pressed");
Context c = event.getContext();
int rowIndex = c.getIndex();
int columnIndex=c.getColumn();
Element el=grid.getView().getCell(rowIndex, columnIndex);
NativeEvent contextEvent = Document.get().createMouseEvent(BrowserEvents.CONTEXTMENU, true, true,0, 0, 0,
el.getAbsoluteLeft(), el.getAbsoluteTop(), false, false, false, false,
NativeEvent.BUTTON_RIGHT, null);
//NativeEvent contextEvent = Document.get().createContextMenuEvent();
int columnIndex = c.getColumn();
Element el = grid.getView().getCell(rowIndex, columnIndex);
NativeEvent contextEvent = Document.get().createMouseEvent(
BrowserEvents.CONTEXTMENU, true, true, 0, 0, 0,
el.getAbsoluteLeft(), el.getAbsoluteTop(), false,
false, false, false, NativeEvent.BUTTON_RIGHT, null);
// NativeEvent contextEvent =
// Document.get().createContextMenuEvent();
el.dispatchEvent(contextEvent);
//DomEvent
// DomEvent
}
});
typeColumn.setCell(button);
List<ColumnConfig<ResourceTDDescriptor, ?>> l = new ArrayList<ColumnConfig<ResourceTDDescriptor, ?>>();
l.add(expander);
l.add(nameCol);
@ -358,9 +363,7 @@ public class ResourcesPanel extends FramedPanel {
}
});
}
};
grid.setLoader(loader);
@ -487,6 +490,19 @@ public class ResourcesPanel extends FramedPanel {
contextMenu.add(removeItem);
grid.setContextMenu(contextMenu);
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:
contextMenu.clear();
contextMenu.add(removeItem);
@ -504,23 +520,28 @@ public class ResourcesPanel extends FramedPanel {
protected void requestSave(ResourceTDDescriptor resourceTDDescriptor) {
switch (resourceTDDescriptor.getResourceType()) {
case CHART:
requestSaveResource(resourceTDDescriptor, ".jpg", "image/jpeg");
requestSaveResource(resourceTDDescriptor, MimeTypeSupport._jpg);
break;
case CODELIST:
break;
case CSV:
requestSaveResource(resourceTDDescriptor, ".csv", "text/csv");
requestSaveResource(resourceTDDescriptor, MimeTypeSupport._csv);
break;
case GUESSER:
break;
case JSON:
requestSaveResource(resourceTDDescriptor, ".json",
"application/json");
requestSaveResource(resourceTDDescriptor, MimeTypeSupport._json);
break;
case MAP:
break;
case SDMX:
break;
case GENERIC_FILE:
requestSaveResource(resourceTDDescriptor, MimeTypeSupport._unknow);
break;
case GENERIC_TABLE:
// requestSaveResource(resourceTDDescriptor, MimeTypeSupport._csv);
break;
default:
break;
@ -529,29 +550,16 @@ public class ResourcesPanel extends FramedPanel {
}
protected void requestSaveResource(
ResourceTDDescriptor resourceTDDescriptor, String extension,
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);
ResourceTDDescriptor resourceTDDescriptor, MimeTypeSupport mime) {
saveResourceSession = new SaveResourceSession();
saveResourceSession.setMimeType(mimeType);
saveResourceSession.setExtension(extension);
saveResourceSession.setFileName(resourceTDDescriptor.getName()
+ extension);
saveResourceSession.setResourceTDDescriptor(resourceTDDescriptor);
saveResourceSession.setMime(mime);
saveResourceSession.setFileName(resourceTDDescriptor.getName());
saveResourceSession.setFileDescription(resourceTDDescriptor
.getDescription());
saveResourceSession.setUri(internalURITD.getUri());
GWT.runAsync(new RunAsyncCallback() {
public void onSuccess() {
@ -561,9 +569,9 @@ public class ResourcesPanel extends FramedPanel {
saveResourceWizard.addListener(new WizardListener() {
public void failed(String title, String message, String details,
Throwable throwable) {
Log.debug(title + ", " + message+" "+details);
public void failed(String title, String message,
String details, Throwable throwable) {
Log.debug(title + ", " + message + " " + details);
}
public void completed(TRId id) {
@ -647,6 +655,11 @@ public class ResourcesPanel extends FramedPanel {
break;
case SDMX:
break;
case GENERIC_FILE:
requestOpenGenericFile(resourceTDDescriptor);
break;
case GENERIC_TABLE:
break;
default:
break;
@ -655,9 +668,10 @@ public class ResourcesPanel extends FramedPanel {
}
private void repquestOpenChart(ResourceTDDescriptor resourceTDDescriptor) {
ChartViewerDialog chartDialog=new ChartViewerDialog(resourceTDDescriptor, trId, eventBus);
ChartViewerDialog chartDialog = new ChartViewerDialog(
resourceTDDescriptor, trId, eventBus);
chartDialog.show();
}
protected void requestOpenMap(
@ -693,20 +707,10 @@ public class ResourcesPanel extends FramedPanel {
} else {
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 {
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 {
Log.error("Error with resource: no valid 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,
final AsyncCallback<ListLoadResult<ResourceTDDescriptor>> callback) {

View File

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

View File

@ -132,6 +132,12 @@ public interface ResourceBundle extends ClientBundle {
@Source("application.png")
ImageResource application();
@Source("file_32.png")
ImageResource file32();
@Source("file.png")
ImageResource file();
@Source("Resources.css")
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.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.widgets.lighttree.client.Item;
import org.gcube.portlets.widgets.lighttree.client.ItemType;
@ -56,7 +57,15 @@ public class WorkSpaceSelectionCard extends WizardCard {
fileName = new TextField();
fileName.setAllowBlank(false);
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,
-1));

Binary file not shown.

After

Width:  |  Height:  |  Size: 517 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 827 B