diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 2dc054b..0dde3da 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -5,6 +5,9 @@ + + uses + diff --git a/src/main/java/org/gcube/portlets/user/reportgenerator/client/Presenter/Presenter.java b/src/main/java/org/gcube/portlets/user/reportgenerator/client/Presenter/Presenter.java index 49b4c61..9257f01 100644 --- a/src/main/java/org/gcube/portlets/user/reportgenerator/client/Presenter/Presenter.java +++ b/src/main/java/org/gcube/portlets/user/reportgenerator/client/Presenter/Presenter.java @@ -8,11 +8,16 @@ import org.gcube.portlets.d4sreporting.common.shared.ComponentType; import org.gcube.portlets.d4sreporting.common.shared.Metadata; import org.gcube.portlets.d4sreporting.common.shared.Model; import org.gcube.portlets.user.exporter.client.ReportExporterPopup; +import org.gcube.portlets.user.exporter.client.ReportExporterServiceAsync; +import org.gcube.portlets.user.exporter.client.event.ExportingCompletedEvent; +import org.gcube.portlets.user.exporter.client.event.ExportingCompletedEventHandler; import org.gcube.portlets.user.exporter.client.event.ReportExporterEvent; import org.gcube.portlets.user.exporter.client.event.ReportExporterEventHandler; import org.gcube.portlets.user.exporter.shared.TypeExporter; import org.gcube.portlets.user.reportgenerator.client.Headerbar; import org.gcube.portlets.user.reportgenerator.client.ReportGenerator; +import org.gcube.portlets.user.reportgenerator.client.ReportService; +import org.gcube.portlets.user.reportgenerator.client.ReportServiceAsync; import org.gcube.portlets.user.reportgenerator.client.TitleBar; import org.gcube.portlets.user.reportgenerator.client.ToolboxPanel; import org.gcube.portlets.user.reportgenerator.client.WorkspacePanel; @@ -46,6 +51,7 @@ import org.gcube.portlets.user.reportgenerator.client.targets.HeadingTextArea; import org.gcube.portlets.user.reportgenerator.client.targets.ReportTextArea; import org.gcube.portlets.user.reportgenerator.client.targets.TSArea; import org.gcube.portlets.user.reportgenerator.client.targets.TextTableImage; +import org.gcube.portlets.user.reportgenerator.client.uibinder.ExportOptions; import org.gcube.portlets.user.reportgenerator.shared.SessionInfo; import org.gcube.portlets.user.reportgenerator.shared.UserBean; @@ -53,14 +59,13 @@ import com.extjs.gxt.ui.client.widget.MessageBox; import com.extjs.gxt.ui.client.widget.layout.FitLayout; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.RunAsyncCallback; -import com.google.gwt.event.shared.EventBus; import com.google.gwt.event.shared.HandlerManager; -import com.google.gwt.event.shared.SimpleEventBus; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.RichTextArea; import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; @@ -74,6 +79,7 @@ import com.google.gwt.user.client.ui.Widget; */ public class Presenter { + private ReportServiceAsync reportService = (ReportServiceAsync) GWT.create(ReportService.class); /** * View part */ @@ -83,10 +89,9 @@ public class Presenter { private ToolboxPanel toolBoxPanel; -// private FimesFileUploadWindow importDlg; - private TitleBar titleBar; - + + private HorizontalPanel exportsPanel; private UserBean currentUser; private String currentScope; @@ -118,6 +123,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()); @@ -135,11 +148,6 @@ public class Presenter { } }); -// eventBus.addHandler(ExportFinishedEvent.TYPE, new EsportFinishedEventHandler() { -// public void onFinishedExport(ExportFinishedEvent event) { -// refreshWorkspace(); -// } -// }); eventBus.addHandler(ReportExporterEvent.TYPE, new ReportExporterEventHandler() { @Override @@ -432,15 +440,7 @@ public class Presenter { //persists the change in the session model.storeInSession(); } - /** - * when export is done this method is called - * @param filePath - * @param itemName - * @param type - */ - public void showExportSaveOptions(final String filePath, final String itemName, final TypeExporter type) { - - } + /** * just clean the page */ @@ -1131,5 +1131,27 @@ public class Presenter { } + public HorizontalPanel getExportsPanel() { + return exportsPanel; + } + + public void setExportsPanel(HorizontalPanel exportsPanel) { + this.exportsPanel = exportsPanel; + } + + /** + * when export is done this method is called + * @param filePath + * @param itemName + * @param type + */ + public void showExportSaveOptions(final String filePath, final String itemName, final TypeExporter type) { + ExportOptions exo = new ExportOptions(this, toolBoxPanel, filePath, itemName, type, reportService); + exportsPanel.add(exo); + } + + public void clearExportPanel() { + exportsPanel.clear(); + } } diff --git a/src/main/java/org/gcube/portlets/user/reportgenerator/client/ReportGenerator.java b/src/main/java/org/gcube/portlets/user/reportgenerator/client/ReportGenerator.java index 2b0481f..62506cf 100644 --- a/src/main/java/org/gcube/portlets/user/reportgenerator/client/ReportGenerator.java +++ b/src/main/java/org/gcube/portlets/user/reportgenerator/client/ReportGenerator.java @@ -1,5 +1,6 @@ package org.gcube.portlets.user.reportgenerator.client; +import org.gcube.portlets.user.exporter.shared.TypeExporter; import org.gcube.portlets.user.guidedtour.client.GCUBEGuidedTour; import org.gcube.portlets.user.guidedtour.client.steps.GCUBETemplate1Text1Image; import org.gcube.portlets.user.guidedtour.client.steps.GCUBETemplate2Text2Image; @@ -34,11 +35,10 @@ import com.google.gwt.user.client.ui.VerticalPanel; * Entry point classes define onModuleLoad(). * * - * ReportGen class is the Entry point class, defines the main layout of the UI + * ReportGeneretor class is the Entry point class, defines the main layout of the UI * * @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it - * - * @version June 2011 (3.0) + */ public class ReportGenerator implements EntryPoint { @@ -86,6 +86,8 @@ public class ReportGenerator implements EntryPoint { private TitleBar titlebar; + private HorizontalPanel exportResultsPanel = new HorizontalPanel(); + private WorkspacePanel workSpacePanel; private VerticalPanel eastPanel = new VerticalPanel(); @@ -116,6 +118,7 @@ public class ReportGenerator implements EntryPoint { presenter.setTitleBar(titlebar); presenter.setWp(workSpacePanel); presenter.setToolBoxPanel(toolBoxPanel); + presenter.setExportsPanel(exportResultsPanel); mainLayout.add(titlebar); mainLayout.add(header); @@ -140,6 +143,7 @@ public class ReportGenerator implements EntryPoint { divHidden.addStyleName("hasRichTextToolbar"); divHidden.addStyleName("setVisibilityOff"); + eastPanel.add(exportResultsPanel); eastPanel.add(workSpacePanel); eastPanel.add(divHidden); bottomScrollerPanel.add(eastPanel); @@ -174,6 +178,7 @@ public class ReportGenerator implements EntryPoint { }); //showGuidedTour() ; + //presenter.showExportSaveOptions("", "", TypeExporter.DOCX, null); } private void showGuidedTour() { diff --git a/src/main/java/org/gcube/portlets/user/reportgenerator/client/ReportService.java b/src/main/java/org/gcube/portlets/user/reportgenerator/client/ReportService.java index fdf91ff..4cb8f2f 100644 --- a/src/main/java/org/gcube/portlets/user/reportgenerator/client/ReportService.java +++ b/src/main/java/org/gcube/portlets/user/reportgenerator/client/ReportService.java @@ -1,19 +1,24 @@ package org.gcube.portlets.user.reportgenerator.client; import org.gcube.portlets.d4sreporting.common.shared.Model; -import org.gcube.portlets.d4sreporting.common.shared.Table; import org.gcube.portlets.d4sreporting.common.shared.RepTimeSeries; -import org.gcube.portlets.user.reportgenerator.client.model.ExportManifestationType; +import org.gcube.portlets.d4sreporting.common.shared.Table; +import org.gcube.portlets.user.exporter.shared.SaveReportFileException; +import org.gcube.portlets.user.exporter.shared.SaveReportFileExistException; +import org.gcube.portlets.user.exporter.shared.TypeExporter; import org.gcube.portlets.user.reportgenerator.shared.SessionInfo; import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; /** * Service interface for server communication * @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it - * @version november 2008 (0.1) */ - +@RemoteServiceRelativePath("ReportServiceImpl") public interface ReportService extends RemoteService{ + String save(String filePath, String workspaceFolderId, String ItemName, + TypeExporter type, boolean overwrite) + throws SaveReportFileException, SaveReportFileExistException; /** * return the first ten records of the timeseries having id as param * @param sTS . diff --git a/src/main/java/org/gcube/portlets/user/reportgenerator/client/ReportServiceAsync.java b/src/main/java/org/gcube/portlets/user/reportgenerator/client/ReportServiceAsync.java index acea9bd..b51b6fc 100644 --- a/src/main/java/org/gcube/portlets/user/reportgenerator/client/ReportServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/reportgenerator/client/ReportServiceAsync.java @@ -1,9 +1,9 @@ package org.gcube.portlets.user.reportgenerator.client; import org.gcube.portlets.d4sreporting.common.shared.Model; -import org.gcube.portlets.d4sreporting.common.shared.Table; import org.gcube.portlets.d4sreporting.common.shared.RepTimeSeries; -import org.gcube.portlets.user.reportgenerator.client.model.ExportManifestationType; +import org.gcube.portlets.d4sreporting.common.shared.Table; +import org.gcube.portlets.user.exporter.shared.TypeExporter; import org.gcube.portlets.user.reportgenerator.shared.SessionInfo; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -11,7 +11,6 @@ import com.google.gwt.user.client.rpc.AsyncCallback; * * Service interface for server Async communication * @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it * - * @version november 2011 (3.0) */ public interface ReportServiceAsync { @@ -74,4 +73,6 @@ public interface ReportServiceAsync { void readImportedModel(String tempPath, AsyncCallback callback); + void save(String filePath, String workspaceFolderId, String ItemName, + TypeExporter type, boolean overwrite, AsyncCallback callback); } diff --git a/src/main/java/org/gcube/portlets/user/reportgenerator/client/WorkspacePanel.java b/src/main/java/org/gcube/portlets/user/reportgenerator/client/WorkspacePanel.java index d08ccd0..036d4aa 100644 --- a/src/main/java/org/gcube/portlets/user/reportgenerator/client/WorkspacePanel.java +++ b/src/main/java/org/gcube/portlets/user/reportgenerator/client/WorkspacePanel.java @@ -8,6 +8,7 @@ import org.gcube.portlets.user.reportgenerator.client.targets.DoubleColumnPanel; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.FlowPanel; +import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.Widget; @@ -49,7 +50,6 @@ public class WorkspacePanel extends Composite { public static WorkspacePanel get() { return singleton; } - /** * the panel for the layout of the working space */ diff --git a/src/main/java/org/gcube/portlets/user/reportgenerator/client/uibinder/ExportOptions.java b/src/main/java/org/gcube/portlets/user/reportgenerator/client/uibinder/ExportOptions.java new file mode 100644 index 0000000..8da0fb0 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/reportgenerator/client/uibinder/ExportOptions.java @@ -0,0 +1,84 @@ +package org.gcube.portlets.user.reportgenerator.client.uibinder; + +import org.gcube.portlets.user.exporter.shared.TypeExporter; +import org.gcube.portlets.user.reportgenerator.client.ReportServiceAsync; +import org.gcube.portlets.user.reportgenerator.client.ToolboxPanel; +import org.gcube.portlets.user.reportgenerator.client.Presenter.Presenter; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.uibinder.client.UiHandler; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.Widget; + +public class ExportOptions extends Composite { + + private static ExportOptionsUiBinder uiBinder = GWT + .create(ExportOptionsUiBinder.class); + + interface ExportOptionsUiBinder extends UiBinder { + } + enum ExportMode {SAVE_OPEN, SAVE, SAVE_AS } + + ToolboxPanel tbp; + @UiField HTML saveOpen; + @UiField HTML save; + @UiField HTML saveAs; + + + private String filePath; + private String itemName; + private String workspaceFolderId; + private TypeExporter type; + private ReportServiceAsync rpc; + private Presenter p; + + public ExportOptions(Presenter p, ToolboxPanel tbp, final String filePath, final String itemName, final TypeExporter type, ReportServiceAsync rpc) { + initWidget(uiBinder.createAndBindUi(this)); + this.tbp = tbp; + this.filePath = filePath; + this.itemName = itemName; + this.type= type; + this.rpc = rpc; + this.p = p; + workspaceFolderId = null; + } + + @UiHandler("saveOpen") + void onSaveOpenClick(ClickEvent e) { + GWT.log("SaveOPen"); + doCallBack(ExportMode.SAVE_OPEN); + } + + @UiHandler("save") + void onSaveClick(ClickEvent e) { + doCallBack(ExportMode.SAVE); + } + + @UiHandler("saveAs") + void onSaveAs(ClickEvent e) { + doCallBack(ExportMode.SAVE_AS); + } + + + private void doCallBack(ExportMode mode) { + rpc.save(filePath, workspaceFolderId, itemName, type, true, new AsyncCallback() { + @Override + public void onSuccess(String createdItemId) { + p.clearExportPanel(); + tbp.showExportedVersion(createdItemId, itemName); + Window.alert("Success "); + } + + @Override + public void onFailure(Throwable caught) { + Window.alert("Error: " + caught.getMessage()); + } + }); + } +} diff --git a/src/main/java/org/gcube/portlets/user/reportgenerator/client/uibinder/ExportOptions.ui.xml b/src/main/java/org/gcube/portlets/user/reportgenerator/client/uibinder/ExportOptions.ui.xml new file mode 100644 index 0000000..7af02a9 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/reportgenerator/client/uibinder/ExportOptions.ui.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + +
+
+ Exporting Completed Succesfully
+
+ Save & Open + + Save + + Save As +
+
+
\ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/reportgenerator/server/servlet/ReportServiceImpl.java b/src/main/java/org/gcube/portlets/user/reportgenerator/server/servlet/ReportServiceImpl.java index fd3c2b1..26ec672 100644 --- a/src/main/java/org/gcube/portlets/user/reportgenerator/server/servlet/ReportServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/reportgenerator/server/servlet/ReportServiceImpl.java @@ -47,6 +47,9 @@ import org.gcube.portlets.d4sreporting.common.shared.RepTimeSeries; import org.gcube.portlets.d4sreporting.common.shared.RepeatableSequence; import org.gcube.portlets.d4sreporting.common.shared.Table; import org.gcube.portlets.d4sreporting.common.shared.TableCell; +import org.gcube.portlets.user.exporter.shared.SaveReportFileException; +import org.gcube.portlets.user.exporter.shared.SaveReportFileExistException; +import org.gcube.portlets.user.exporter.shared.TypeExporter; import org.gcube.portlets.user.homelibrary.home.HomeLibrary; import org.gcube.portlets.user.homelibrary.home.exceptions.HomeNotFoundException; import org.gcube.portlets.user.homelibrary.home.exceptions.InternalErrorException; @@ -1651,6 +1654,47 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe } + @Override + public String save(String filePath, String workspaceFolderId, String itemName, TypeExporter type, boolean overwrite) throws SaveReportFileException, SaveReportFileExistException { + try { + File file = new File(filePath); + + Workspace workspace = HomeLibrary.getUserWorkspace(getASLSession()); + _log.info("Saving in Workspace of " + workspace.getOwner().getPortalLogin()); + WorkspaceFolder folder = (workspaceFolderId != null)? + (WorkspaceFolder)workspace.getItem(workspaceFolderId):workspace.getRoot(); + + if (workspace.exists(itemName, folder.getId())) { + if (overwrite) + workspace.remove(itemName, folder.getId()); + else + throw new SaveReportFileException("The item " + itemName + " already exists"); + } + + switch (type) { + case PDF: + return folder.createExternalPDFFileItem(itemName + "." + type.toString().toLowerCase(), + "", null, new FileInputStream(file)).getId(); + + case HTML: + return folder.createExternalFileItem(itemName + "." + type.toString().toLowerCase(), + "", "text/html", new FileInputStream(file)).getId(); + case DOCX: + return folder.createExternalFileItem(itemName + "." + type.toString().toLowerCase(), + "", "application/msword", new FileInputStream(file)).getId(); + + case XML: + return folder.createExternalFileItem(itemName + "." + type.toString().toLowerCase(), + "", "application/xml", new FileInputStream(file)).getId(); + } + throw new SaveReportFileException("Unknown file type"); + } catch (ItemAlreadyExistException e) { + throw new SaveReportFileExistException(e.getMessage()); + } catch (Exception e) { + throw new SaveReportFileException(e.getMessage()); + } + } + diff --git a/src/main/java/org/gcube/portlets/user/reportgenerator/shared/ReportExporterException.java b/src/main/java/org/gcube/portlets/user/reportgenerator/shared/ReportExporterException.java new file mode 100644 index 0000000..602a2a5 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/reportgenerator/shared/ReportExporterException.java @@ -0,0 +1,25 @@ +package org.gcube.portlets.user.reportgenerator.shared; + +import java.io.Serializable; + +public class ReportExporterException extends Exception implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -1020757346366625622L; + private String error; + + public ReportExporterException() { + + } + + public ReportExporterException(String error) { + this.error = error; + } + + @Override + public String getMessage() { + return error; + } +} diff --git a/src/main/java/org/gcube/portlets/user/reportgenerator/shared/SaveReportFileException.java b/src/main/java/org/gcube/portlets/user/reportgenerator/shared/SaveReportFileException.java new file mode 100644 index 0000000..2b13610 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/reportgenerator/shared/SaveReportFileException.java @@ -0,0 +1,16 @@ +package org.gcube.portlets.user.reportgenerator.shared; + + + +public class SaveReportFileException extends ReportExporterException { + + private static final long serialVersionUID = -6674611825830219782L; + + public SaveReportFileException() { + + } + + public SaveReportFileException(String error) { + super(error); + } +} diff --git a/src/main/java/org/gcube/portlets/user/reportgenerator/shared/SaveReportFileExistException.java b/src/main/java/org/gcube/portlets/user/reportgenerator/shared/SaveReportFileExistException.java new file mode 100644 index 0000000..a88e523 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/reportgenerator/shared/SaveReportFileExistException.java @@ -0,0 +1,18 @@ +package org.gcube.portlets.user.reportgenerator.shared; + +public class SaveReportFileExistException extends ReportExporterException { + + /** + * + */ + private static final long serialVersionUID = 7241356056474394295L; + + public SaveReportFileExistException() { + + } + + public SaveReportFileExistException(String error) { + super(error); + } + +} diff --git a/src/main/webapp/ReportGenerator.css b/src/main/webapp/ReportGenerator.css index d2c2536..c5506f3 100644 --- a/src/main/webapp/ReportGenerator.css +++ b/src/main/webapp/ReportGenerator.css @@ -1,5 +1,51 @@ @import url('reports/old-dialog.css'); +.exportPanel { + margin: 10px 5px 5px 20px; + border: 1px solid #e3e8f3; + padding: 10px; + background-color: #FFFFBF; + -webkit-border-radius: 5px; + -moz-border-radius: 5px; + border-radius: 5px; + width: 775px; +} +.exportResult { + font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; + font-size: 18px; + color: #444; + margin-bottom: 20px; +} +.exportOption { + display: block; + height: 148px; + width: 250px; + opacity: 0.8; + text-align: center; + font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; + font-size: 18px; + color: #444; +} + +.exportOption:hover { + cursor: pointer; + cursor: hand; + opacity: 1.0; +} + +.optionSave { + background: url('images/save.png') 55% 25px no-repeat; +} + +.optionSaveAs { + background: url('images/save_as.png') 60% 25px no-repeat; +} + +.optionSaveOpen { + background: url('images/save_open.png') 55% 25px no-repeat; +} + + .closeImage { background: url(images/close.png) 0px 0px no-repeat; height: 15px; diff --git a/src/main/webapp/images/save.png b/src/main/webapp/images/save.png new file mode 100644 index 0000000..fbb8d7e Binary files /dev/null and b/src/main/webapp/images/save.png differ diff --git a/src/main/webapp/images/save_as.png b/src/main/webapp/images/save_as.png new file mode 100644 index 0000000..8f5fb2e Binary files /dev/null and b/src/main/webapp/images/save_as.png differ diff --git a/src/main/webapp/images/save_open.png b/src/main/webapp/images/save_open.png new file mode 100644 index 0000000..995717f Binary files /dev/null and b/src/main/webapp/images/save_open.png differ