added saving with loading

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/reports@74581 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2013-05-06 15:38:24 +00:00
parent ebbbdcfee3
commit beffd67076
10 changed files with 190 additions and 222 deletions

View File

@ -23,6 +23,7 @@ import org.gcube.portlets.user.reportgenerator.client.WorkspacePanel;
import org.gcube.portlets.user.reportgenerator.client.dialog.AddBiblioEntryDialog;
import org.gcube.portlets.user.reportgenerator.client.dialog.DeleteCitationsDialog;
import org.gcube.portlets.user.reportgenerator.client.dialog.ReportStructureDialog;
import org.gcube.portlets.user.reportgenerator.client.dialog.SavingDialog;
import org.gcube.portlets.user.reportgenerator.client.events.AddBiblioEvent;
import org.gcube.portlets.user.reportgenerator.client.events.AddBiblioEventHandler;
import org.gcube.portlets.user.reportgenerator.client.events.AddCommentEvent;
@ -89,9 +90,11 @@ public class Presenter {
private ToolboxPanel toolBoxPanel;
private TitleBar titleBar;
private HorizontalPanel exportsPanel;
private final SavingDialog dlg = new SavingDialog();
private UserBean currentUser;
private String currentScope;
/**
@ -99,6 +102,8 @@ public class Presenter {
*/
private TemplateModel model;
private String location;
private int currFocus;
RichTextToolbar currentSelectedToolbar;
@ -122,14 +127,14 @@ public class Presenter {
private void handleEvents() {
eventBus.addHandler(ExportingCompletedEvent.TYPE, new ExportingCompletedEventHandler() {
@Override
public void onExportFinished(ExportingCompletedEvent event) {
showExportSaveOptions(event.getFilePath(), event.getItemName(), event.getType());
}
});
eventBus.addHandler(AddBiblioEvent.TYPE, new AddBiblioEventHandler() {
public void onAddCitation(AddBiblioEvent event) {
addCitation(event.getCitekey(), event.getCitetext());
@ -148,10 +153,10 @@ public class Presenter {
});
eventBus.addHandler(ReportExporterEvent.TYPE, new ReportExporterEventHandler() {
@Override
public void onCompletedExport(ReportExporterEvent event) {
switch (event.getOperationResult()) {
case SAVED:
refreshWorkspace();
@ -163,7 +168,7 @@ public class Presenter {
default:
break;
}
}
});
@ -179,14 +184,14 @@ public class Presenter {
}
});
// eventBus.addHandler(ImportFinishedEvent.TYPE, new ImportFinishedEventHandler(){
// public void onFinishedImport(ImportFinishedEvent event) {
// importDlg.hide();
// openImportedFimesXML(event.getPathFile());
// }
//
// });
// eventBus.addHandler(ImportFinishedEvent.TYPE, new ImportFinishedEventHandler(){
// public void onFinishedImport(ImportFinishedEvent event) {
// importDlg.hide();
// openImportedFimesXML(event.getPathFile());
// }
//
// });
eventBus.addHandler(ItemSelectionEvent.TYPE, new ItemSelectionEventHandler() {
@SuppressWarnings("unchecked")
public void onItemSelected(ItemSelectionEvent event) {
@ -204,7 +209,7 @@ public class Presenter {
ReportGenerator.get().getScrollerPanel().setVerticalScrollPosition(top);
}
}
}
});
}
@ -256,15 +261,15 @@ public class Presenter {
commonCommands = new CommonCommands(this);
//importDlg = new FimesFileUploadWindow(eventBus);
}
public void showOpenOptions() {
wp.showOpenOptions();
}
public void showLoading() {
wp.showLoading();
}
/**
* load the template to edit in the MODEL and in the VIEW
* @param templateToOpen the name of the template to open without extension nor path
@ -322,7 +327,7 @@ public class Presenter {
}
return toReturn;
}
/**
* look if a section with a specific metadata (that indicate sit is a biblio section)
* exists in the current report model:
@ -470,7 +475,7 @@ public class Presenter {
wp.getMainLayout().clear();
ReportGenerator.get().getScrollerPanel().setScrollPosition(0);
}
/**
* Save the current report
@ -478,8 +483,21 @@ public class Presenter {
*
*/
public void saveReport(String folderid, String name) {
model.storeInSession();
model.saveReport(folderid, name);
dlg.center();
dlg.show();
Model toSave = model.getSerializableModel();
reportService.saveReport(toSave, folderid, name, new AsyncCallback<Void>() {
public void onFailure(Throwable caught) {
dlg.hide();
MessageBox.alert("Warning","Report Not Saved: " + caught.getMessage(), null);
}
public void onSuccess(Void result) {
dlg.hide();
MessageBox.info("Saving Operation","Report Saved Successfully", null);
refreshWorkspace();
}
});
}
@ -488,8 +506,20 @@ public class Presenter {
*
*/
public void saveReport() {
model.storeInSession();
model.saveReport();
dlg.center();
dlg.show();
Model toSave = model.getSerializableModel();
reportService.saveReport(toSave, new AsyncCallback<Void>() {
public void onFailure(Throwable caught) {
dlg.hide();
MessageBox.alert("Warning","Report Not Saved: " + caught.getMessage(), null);
}
public void onSuccess(Void result) {
dlg.hide();
MessageBox.info("Saving Operation","Report Saved Successfully", null);
refreshWorkspace();
}
});
}
/**
@ -497,8 +527,20 @@ public class Presenter {
*
*/
public void updateWorkflowDocument(boolean update) {
model.storeInSession();
model.updateWorkflowDocument(update);
dlg.center();
dlg.show();
Model toSave = model.getSerializableModel();
reportService.updateWorkflowDocument(toSave, update, new AsyncCallback<Void>() {
public void onFailure(Throwable caught) {
dlg.hide();
Window.alert("failed to update workflow document");
}
public void onSuccess(Void result) {
dlg.hide();
loadWorkflowLibraryApp();
}
});
}
/**
@ -510,7 +552,21 @@ public class Presenter {
titleBar.setTemplateName(templateName);
}
/**
* Redirect to VRE Deployer Portlet
*/
private void loadWorkflowLibraryApp(){
getUrl();
location += "/../my-workflow-documents";
Window.open(location, "_self", "");
}
/**
* Get URL from browser
*/
public native void getUrl()/*-{
this.@org.gcube.portlets.user.reportgenerator.client.Presenter.Presenter::location = $wnd.location.href;
}-*/;
/**
*
@ -643,7 +699,7 @@ public class Presenter {
*/
public void generateManifestation(final TemplateModel model, final ExportManifestationType type) {
GWT.runAsync(ReportExporterPopup.class, new RunAsyncCallback() {
@Override
public void onSuccess() {
ReportExporterPopup popup = new ReportExporterPopup(eventBus);
@ -663,15 +719,15 @@ public class Presenter {
break;
}
}
@Override
public void onFailure(Throwable reason) {
}
});
}
public void openAddCitationDialog() {
AddBiblioEntryDialog dlg = new AddBiblioEntryDialog(eventBus);
@ -741,7 +797,7 @@ public class Presenter {
titleBar.showPrevButton();
}
/**
* load the template to edit in the MODEL and in the VIEW
* @param serializedpath the temp file to open
@ -789,7 +845,7 @@ public class Presenter {
if (currPage > 1)
titleBar.showPrevButton();
}
/**
* just clean the page
*/
@ -848,7 +904,7 @@ public class Presenter {
List<TemplateComponent> pageElems = model.getSectionComponent(section);
for (TemplateComponent component : pageElems) {
GWT.log("Reading component.. " + component.getType(), null);
//GWT.log("Reading component.. " + component.getType(), null);
int uiX = component.getX();
int uiY= component.getY();
@ -1125,7 +1181,7 @@ public class Presenter {
public void onFailure(Throwable reason) {
}
});
}
public HorizontalPanel getExportsPanel() {
@ -1136,7 +1192,7 @@ public class Presenter {
public void setExportsPanel(HorizontalPanel exportsPanel) {
this.exportsPanel = exportsPanel;
}
/**
* when export is done this method is called
* @param filePath
@ -1162,9 +1218,9 @@ public class Presenter {
Window.alert("Error while trying exporting this report: " + caught.getMessage());
}
});
}
public void showExportPanel(final String filePath, final String itemName, final TypeExporter type, String tempFileId) {
final ExportOptions exo = new ExportOptions(this, toolBoxPanel, filePath, itemName, type, reportService, tempFileId);
exportsPanel.add(exo);
@ -1177,7 +1233,7 @@ public class Presenter {
};
t.schedule(10);
}
public void clearExportPanel() {
exportsPanel.clear();
}

View File

@ -63,16 +63,16 @@ public interface ReportService extends RemoteService{
* the report model is taken from the session
* @param folderid the basket id where to save the report
*/
void saveReport(String folderid, String newname);
void saveReport(Model toSave, String folderid, String newname);
/**
* the report model is taken from the session, the id also
*/
void saveReport();
void saveReport(Model toSave);
Model getWorkflowDocumentFromDocumentLibrary();
void updateWorkflowDocument(boolean update);
void updateWorkflowDocument(Model toSave, boolean update);
void renewLock();
/**

View File

@ -49,17 +49,10 @@ public interface ReportServiceAsync {
*/
void readTemplateFromSession( AsyncCallback<Model> callback);
/**
* @param callback .
* @param folderid .
*/
void saveReport(String folderid, String newname, AsyncCallback<Void> callback);
void saveReport(Model toSave, String folderid, String newname,
AsyncCallback<Void> callback);
/**
*
* @param callback .
*/
void saveReport(AsyncCallback<Void> callback);
void saveReport(Model toSave, AsyncCallback<Void> callback);
/**
*
* @param currentHost
@ -68,7 +61,8 @@ public interface ReportServiceAsync {
void getSessionInfo(String currentHost, AsyncCallback<SessionInfo> callback);
void getWorkflowDocumentFromDocumentLibrary(
AsyncCallback<Model> callback);
void updateWorkflowDocument(boolean update, AsyncCallback<Void> callback);
void updateWorkflowDocument(Model toSave, boolean update,
AsyncCallback<Void> callback);
void renewLock(AsyncCallback<Void> callback);
void readImportedModel(String tempPath,

View File

@ -0,0 +1,13 @@
package org.gcube.portlets.user.reportgenerator.client.dialog;
import org.gcube.portlets.user.gcubewidgets.client.popup.GCubeDialog;
import org.gcube.portlets.user.reportgenerator.client.uibinder.ShowSaving;
public class SavingDialog extends GCubeDialog {
public SavingDialog() {
super(false, true);
setText("Updating report, please wait ...");
setWidget(new ShowSaving());
}
}

View File

@ -332,10 +332,10 @@ public class TemplateComponent {
this.content = spacer;
break;
case REPEAT_SEQUENCE:
GWT.log("FOUND SEQUENCE trying getGroup");
//GWT.log("FOUND SEQUENCE trying getGroup");
RepeatableSequence repeatableSequence = (RepeatableSequence) sc.getPossibleContent();
GWT.log("getGroup: " + repeatableSequence.toString());
//GWT.log("getGroup: " + repeatableSequence.toString());
ClientRepeatableSequence rps = new ClientRepeatableSequence(presenter, repeatableSequence);
this.content = rps;
@ -386,7 +386,6 @@ public class TemplateComponent {
case DYNA_IMAGE:
ClientImage da = (ClientImage) this.content;
content = da.getDroppedImage().getElement().getAttribute("src");
GWT.log("Poss Content=" + content);
id = da.getIdInBasket();
idInBasket = id;
if (((String) content).compareTo("") == 0)

View File

@ -354,11 +354,11 @@ public class TemplateModel {
else {
int insertIn = (isAdded) ? (i-1): i;
newSections.put(""+i, sections.get(""+insertIn));
GWT.log("Inserting " + insertIn + " into section " + i + " isAdded =" + (isAdded) , null);
//GWT.log("Inserting " + insertIn + " into section " + i + " isAdded =" + (isAdded) , null);
}
}
this.sections = newSections;
GWT.log("NEW SECTION SIZE"+sections.size(), null);
//GWT.log("NEW SECTION SIZE"+sections.size(), null);
}
totalPages++;
@ -415,42 +415,21 @@ public class TemplateModel {
return toReturn;
}
/**
*
* @param folderid .
* @param name .
*/
public void saveReport (String folderid, String name) {
modelService.saveReport(folderid, name, new AsyncCallback<Void>() {
public void onFailure(Throwable caught) {
MessageBox.alert("Warning","Report Not Saved: " + caught.getMessage(), null);
}
public void onSuccess(Void result) {
MessageBox.info("Saving Operation","Report Saved Successfully", null);
presenter.refreshWorkspace();
}
});
public void saveReport (Model toSave, String folderid, String name) {
}
/**
*
*
*/
public void saveReport () {
modelService.saveReport(new AsyncCallback<Void>() {
public void onFailure(Throwable caught) {
MessageBox.alert("Warning","Report Not Saved: " + caught.getMessage(), null);
}
public void onSuccess(Void result) {
MessageBox.info("Saving Operation","Report Saved Successfully", null);
presenter.refreshWorkspace();
}
});
public void saveReport (Model toSave) {
}
@ -461,7 +440,7 @@ public class TemplateModel {
* @param newHeight .
*/
public void resizeModelComponent(Widget toResize, int newWidth, int newHeight) {
GWT.log("LOOKING CORRESPONDANCE", null);
//GWT.log("LOOKING CORRESPONDANCE", null);
String tcPage = ""+currentPage;
TemplateSection singleSection = sections.get(tcPage);
@ -506,19 +485,21 @@ public class TemplateModel {
}
/**
* stores the current model in the session
* stores the current model in the session, not to be used anymore as images could have high payload
*/
@Deprecated
public void storeInSession() {
AsyncCallback callback = new AsyncCallback() {
public void onFailure(Throwable caught) { }
public void onSuccess(Object result) { }
};
Model modelToSend = getSerializableModel();
GWT.log("Storing in session: currpage = " + modelToSend.getCurrPage(), null);
modelService.storeTemplateInSession(modelToSend, callback);
// Model modelToSend = getSerializableModel();
//
// GWT.log("Storing in session: currpage = " + modelToSend.getCurrPage(), null);
//
// modelService.storeTemplateInSession(modelToSend, new AsyncCallback<Void>() {
// @Override
// public void onFailure(Throwable caught) { }
// @Override
// public void onSuccess(Void result) {
// }
// });
}
//****** GETTERS n SETTERS
@ -675,34 +656,11 @@ public class TemplateModel {
return false;
}
public void updateWorkflowDocument(boolean update) {
modelService.updateWorkflowDocument(update, new AsyncCallback<Void>() {
public void onFailure(Throwable caught) {
Window.alert("failed to update workflow document");
}
public void onSuccess(Void result) {
loadWorkflowLibraryApp();
}
});
public void updateWorkflowDocument(Model toSave, boolean update) {
}
private String location;
/**
* Redirect to VRE Deployer Portlet
*/
private void loadWorkflowLibraryApp(){
getUrl();
location += "/../my-workflow-documents";
Window.open(location, "_self", "");
}
/**
* Get URL from browser
*/
public native void getUrl()/*-{
this.@org.gcube.portlets.user.reportgenerator.client.model.TemplateModel::location = $wnd.location.href;
}-*/;
}

View File

@ -0,0 +1,27 @@
package org.gcube.portlets.user.reportgenerator.client.uibinder;
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;
public class ShowSaving extends Composite {
public static final String LOADING = GWT.getModuleBaseURL() + "../images/reports-saving.gif";
private static ShowoadingUiBinder uiBinder = GWT
.create(ShowoadingUiBinder.class);
interface ShowoadingUiBinder extends UiBinder<Widget, ShowSaving> {
}
@UiField Image loadingReport;
public ShowSaving() {
initWidget(uiBinder.createAndBindUi(this));
loadingReport.setUrl(LOADING);
}
}

View File

@ -0,0 +1,13 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:HTMLPanel ui:field="myPanel">
<table style="width: 100%; text-align: center;">
<tr>
<td>
<g:Image ui:field="loadingReport" />
</td>
</tr>
</table>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -704,6 +704,7 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
public void storeTemplateInSession(Model model) {
ASLSession d4Session = getASLSession();
d4Session.setAttribute(CURRENT_REPORT_INSTANCE, model);
_log.trace("Saved in Session");
}
@ -785,98 +786,6 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
}
}
/**
*
* @param imageName the generated image name
* @param templateName the curr template name
* @return the url to the image
*/
private String getImageURL(String imageName, String templateName) {
StringBuilder sb = new StringBuilder("/usersArea/")
.append( getVreName())
.append("/templates/")
.append(getUsername())
.append("/CURRENT_OPEN/images/")
.append(imageName);
_log.info("getImageURL" + sb.toString());
return sb.toString();
}
/**
*
* @param imageIDinBasket .
* @param pathToFile the directory where to save the file
* @param filename the filename to give to the newly created file
* @return the file imagename with its extension
*/
private String copyImageFromBasket(String imageIDinBasket, String pathToFile, String filename) {
Workspace root = null;
try {
root = getWorkspaceArea();
} catch (WorkspaceFolderNotFoundException e) {e.printStackTrace();
} catch (InternalErrorException e) { e.printStackTrace();
} catch (HomeNotFoundException e) { e.printStackTrace();
}
WorkspaceItem item = null;
try {
item = root.getItem(imageIDinBasket);
} catch (ItemNotFoundException e) {
e.printStackTrace();
}
_log.debug("pathToFile: " + pathToFile);
File f = null;
String toReturn ="";
if (item.getType() == WorkspaceItemType.FOLDER_ITEM) {
_log.debug("\nItem is a BASKET_ITEM");
FolderItem bi = (FolderItem) item;
try {
File dir = new File(pathToFile);
_log.debug("DIR: " + pathToFile);
if (! dir.exists() )
dir.mkdirs();
InputStream data = null;
if (bi.getFolderItemType()==FolderItemType.EXTERNAL_IMAGE){
_log.debug("EXTERNAL_IMAGE -|- " + item.getType());
ExternalImage image = (ExternalImage)item;
data = image.getData();
}
if (bi.getFolderItemType()==FolderItemType.IMAGE_DOCUMENT){
ImageDocument image = (ImageDocument)item;
if (image.getMimeType().equals("image/tiff"))
data = image.getThumbnail();
else
data = image.getData();
}
toReturn = filename + "." + getImageExtension(bi);
f = new File(pathToFile+toReturn);
OutputStream out = new FileOutputStream(f);
byte buf[] = new byte[1024];
int len;
while((len = data.read(buf))>0)
out.write(buf,0,len);
out.close();
data.close();
}
catch (IOException e){
e.printStackTrace();
} catch (InternalErrorException e) {
e.printStackTrace();
}
}
_log.info("RETURNING: " + f.getAbsolutePath());
return toReturn;
}
/**
* return a string for the file extension given a mimetype
*
@ -964,7 +873,7 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
/**
* used to save the report in the same folder *
*/
public void saveReport() {
public void saveReport(Model toSave) {
Workspace root = null;
try {
root = getWorkspaceArea();
@ -988,7 +897,7 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
} catch (InternalErrorException e) {
e.printStackTrace();
}
saveReport(folderid, itemName);
saveReport(toSave, folderid, itemName);
}
@ -996,9 +905,10 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
* @param save a report in another folder .
*
*/
public void saveReport(String folderid, String newname) {
public void saveReport(Model toSave, String folderid, String newname) {
Model model = readTemplateFromSession();
Model model = toSave;
storeTemplateInSession(toSave);
_log.info("Serializing Model in folder: " + folderid );
_log.info("Trying to convert dynamic images ... ");
convertDynamicImagesFromHL(model);
@ -1457,7 +1367,7 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
/**
* update the Workflow Document in session
*/
public void updateWorkflowDocument(boolean update) {
public void updateWorkflowDocument(Model toSave, boolean update) {
ASLSession session = getASLSession();
ServiceUtil myUtil = new ServiceUtil(session);
@ -1468,12 +1378,10 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
if (update) {
_log.debug("SAVING in WorkflowDocument Library ");
model = (Model) session.getAttribute(CURRENT_REPORT_INSTANCE);
model = (Model) toSave;
_log.debug("Trying to convert dynamic images ... ");
convertDynamicImagesFromHL(model);
boolean result = myUtil.writeModel(model, "CURRENT_OPEN", getVreName(), getUsername());
if (!result) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB