2013-02-06 23:25:43 +01:00
package org.gcube.portlets.user.reportgenerator.client.Presenter ;
import java.util.HashMap ;
import java.util.List ;
2013-11-14 16:26:26 +01:00
import org.gcube.portlets.d4sreporting.common.shared.BasicSection ;
2013-02-06 23:25:43 +01:00
import org.gcube.portlets.d4sreporting.common.shared.Metadata ;
2013-03-01 19:42:50 +01:00
import org.gcube.portlets.d4sreporting.common.shared.Model ;
2013-11-18 18:25:49 +01:00
import org.gcube.portlets.d4sreporting.common.shared.ReportReferences ;
2013-12-17 19:19:51 +01:00
import org.gcube.portlets.d4sreporting.common.shared.Tuple ;
2013-02-06 23:25:43 +01:00
import org.gcube.portlets.user.reportgenerator.client.Headerbar ;
import org.gcube.portlets.user.reportgenerator.client.ReportGenerator ;
2013-03-15 19:06:43 +01:00
import org.gcube.portlets.user.reportgenerator.client.ReportService ;
import org.gcube.portlets.user.reportgenerator.client.ReportServiceAsync ;
2013-11-22 18:28:12 +01:00
import org.gcube.portlets.user.reportgenerator.client.ReportStructurePanel ;
2013-02-06 23:25:43 +01:00
import org.gcube.portlets.user.reportgenerator.client.TitleBar ;
import org.gcube.portlets.user.reportgenerator.client.ToolboxPanel ;
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 ;
2014-01-28 17:31:13 +01:00
import org.gcube.portlets.user.reportgenerator.client.dialog.SelectVMEReportDialog ;
import org.gcube.portlets.user.reportgenerator.client.dialog.SelectVMEReportDialog.Action ;
2013-05-06 18:54:25 +02:00
import org.gcube.portlets.user.reportgenerator.client.dialog.WaitingOperationDialog ;
2013-02-06 23:25:43 +01:00
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 ;
import org.gcube.portlets.user.reportgenerator.client.events.AddCommentEventHandler ;
import org.gcube.portlets.user.reportgenerator.client.events.ItemSelectionEvent ;
import org.gcube.portlets.user.reportgenerator.client.events.ItemSelectionEventHandler ;
import org.gcube.portlets.user.reportgenerator.client.events.RemovedCitationEvent ;
import org.gcube.portlets.user.reportgenerator.client.events.RemovedCitationEventHandler ;
import org.gcube.portlets.user.reportgenerator.client.events.RemovedUserCommentEvent ;
import org.gcube.portlets.user.reportgenerator.client.events.RemovedUserCommentEventHandler ;
2013-11-25 17:12:01 +01:00
import org.gcube.portlets.user.reportgenerator.client.events.SelectedReportEvent ;
import org.gcube.portlets.user.reportgenerator.client.events.SelectedReportEventHandler ;
2013-02-06 23:25:43 +01:00
import org.gcube.portlets.user.reportgenerator.client.model.ExportManifestationType ;
import org.gcube.portlets.user.reportgenerator.client.model.TemplateComponent ;
import org.gcube.portlets.user.reportgenerator.client.model.TemplateModel ;
import org.gcube.portlets.user.reportgenerator.client.model.TemplateSection ;
2013-03-05 15:26:22 +01:00
import org.gcube.portlets.user.reportgenerator.client.targets.AttributeMultiSelection ;
import org.gcube.portlets.user.reportgenerator.client.targets.AttributeSingleSelection ;
2013-02-06 23:25:43 +01:00
import org.gcube.portlets.user.reportgenerator.client.targets.BasicTextArea ;
2013-03-07 16:03:01 +01:00
import org.gcube.portlets.user.reportgenerator.client.targets.ClientImage ;
import org.gcube.portlets.user.reportgenerator.client.targets.ClientRepeatableSequence ;
2013-11-14 17:57:40 +01:00
import org.gcube.portlets.user.reportgenerator.client.targets.ClientReportReference ;
2013-11-18 18:25:49 +01:00
import org.gcube.portlets.user.reportgenerator.client.targets.ClientSequence ;
2013-02-06 23:25:43 +01:00
import org.gcube.portlets.user.reportgenerator.client.targets.Coords ;
import org.gcube.portlets.user.reportgenerator.client.targets.D4sRichTextarea ;
import org.gcube.portlets.user.reportgenerator.client.targets.GenericTable ;
2013-02-13 18:26:22 +01:00
import org.gcube.portlets.user.reportgenerator.client.targets.GroupingDelimiterArea ;
2013-03-13 11:06:47 +01:00
import org.gcube.portlets.user.reportgenerator.client.targets.HeadingTextArea ;
2013-02-06 23:25:43 +01:00
import org.gcube.portlets.user.reportgenerator.client.targets.ReportTextArea ;
2013-03-12 18:10:16 +01:00
import org.gcube.portlets.user.reportgenerator.client.targets.TextTableImage ;
2013-12-17 19:19:51 +01:00
import org.gcube.portlets.user.reportgenerator.client.toolbar.RichTextToolbar ;
2013-03-15 19:06:43 +01:00
import org.gcube.portlets.user.reportgenerator.client.uibinder.ExportOptions ;
2014-04-28 18:26:53 +02:00
import org.gcube.portlets.user.reportgenerator.shared.ReportImage ;
2013-02-06 23:25:43 +01:00
import org.gcube.portlets.user.reportgenerator.shared.SessionInfo ;
2013-03-05 15:26:22 +01:00
import org.gcube.portlets.user.reportgenerator.shared.UserBean ;
2013-11-13 18:56:13 +01:00
import org.gcube.portlets.user.reportgenerator.shared.VMETypeIdentifier ;
2014-01-28 17:31:13 +01:00
import org.gcube.portlets.user.reportgenerator.shared.VmeExportResponse ;
import org.gcube.portlets.user.reportgenerator.shared.VmeResponseEntry ;
2013-11-07 19:00:34 +01:00
import org.gcube.portlets.widgets.exporter.client.ReportExporterPopup ;
import org.gcube.portlets.widgets.exporter.client.event.ExportingCompletedEvent ;
import org.gcube.portlets.widgets.exporter.client.event.ExportingCompletedEventHandler ;
import org.gcube.portlets.widgets.exporter.client.event.ReportExporterEvent ;
import org.gcube.portlets.widgets.exporter.client.event.ReportExporterEventHandler ;
import org.gcube.portlets.widgets.exporter.shared.TypeExporter ;
2014-04-28 18:26:53 +02:00
import org.gcube.portlets.widgets.fileupload.client.events.FileUploadCompleteEvent ;
import org.gcube.portlets.widgets.fileupload.client.events.FileUploadCompleteEventHandler ;
2014-05-15 15:27:25 +02:00
import org.gcube.portlets.widgets.fileupload.client.events.FileUploadSelectedEvent ;
import org.gcube.portlets.widgets.fileupload.client.events.FileUploadSelectedEventHandler ;
2014-04-28 18:26:53 +02:00
import org.gcube.portlets.widgets.fileupload.client.view.UploadProgressDialog ;
2013-02-06 23:25:43 +01:00
2015-12-11 16:50:04 +01:00
import com.extjs.gxt.ui.client.event.Listener ;
import com.extjs.gxt.ui.client.event.MessageBoxEvent ;
import com.extjs.gxt.ui.client.widget.Dialog ;
2013-02-06 23:25:43 +01:00
import com.extjs.gxt.ui.client.widget.MessageBox ;
import com.google.gwt.core.client.GWT ;
2013-03-15 11:37:45 +01:00
import com.google.gwt.core.client.RunAsyncCallback ;
2013-02-06 23:25:43 +01:00
import com.google.gwt.event.shared.HandlerManager ;
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 ;
2013-03-15 19:06:43 +01:00
import com.google.gwt.user.client.ui.HorizontalPanel ;
2013-02-06 23:25:43 +01:00
import com.google.gwt.user.client.ui.RichTextArea ;
import com.google.gwt.user.client.ui.SimplePanel ;
import com.google.gwt.user.client.ui.Widget ;
/ * *
*
* @author Massimiliano Assante , ISTI - CNR - massimiliano . assante @isti.cnr.it
*
* /
public class Presenter {
2013-03-15 19:06:43 +01:00
private ReportServiceAsync reportService = ( ReportServiceAsync ) GWT . create ( ReportService . class ) ;
2013-02-06 23:25:43 +01:00
/ * *
* View part
* /
private WorkspacePanel wp ;
private Headerbar header ;
private ToolboxPanel toolBoxPanel ;
private TitleBar titleBar ;
2013-05-06 17:38:24 +02:00
2013-03-15 19:06:43 +01:00
private HorizontalPanel exportsPanel ;
2013-02-06 23:25:43 +01:00
2013-05-06 18:54:25 +02:00
private final WaitingOperationDialog dlg = new WaitingOperationDialog ( ) ;
2013-05-06 17:38:24 +02:00
2014-04-28 18:26:53 +02:00
private UploadProgressDialog uploadDlg ;
2013-03-05 15:26:22 +01:00
private UserBean currentUser ;
2013-02-06 23:25:43 +01:00
private String currentScope ;
2014-05-15 15:27:25 +02:00
2014-04-28 18:26:53 +02:00
private ClientImage selectedImage ;
2014-05-15 15:27:25 +02:00
2014-04-28 18:26:53 +02:00
2013-02-06 23:25:43 +01:00
/ * *
* Model
* /
private TemplateModel model ;
2013-05-06 17:38:24 +02:00
private String location ;
2013-02-06 23:25:43 +01:00
private int currFocus ;
2013-11-14 16:26:26 +01:00
/ * *
* this is needed to know on which client sequence the user is operating
* /
private ClientSequence clientSeqSelected = null ;
2013-02-06 23:25:43 +01:00
2014-01-28 17:31:13 +01:00
private boolean isShowingStructure = false ;
2013-02-06 23:25:43 +01:00
RichTextToolbar currentSelectedToolbar ;
RichTextArea areaForBiblio ;
/ * *
*
* /
private CommonCommands commonCommands ;
private boolean menuForWorkflowDocument = false ;
2013-12-18 00:47:35 +01:00
2013-12-17 19:19:51 +01:00
private boolean isVME = false ;
2014-01-28 17:31:13 +01:00
/ * *
* by default is set to Type VME , because refs can only be imported and not opened from WorkSpace
* /
private VMETypeIdentifier currentVmeType = VMETypeIdentifier . Vme ;
2013-02-06 23:25:43 +01:00
/ * *
* eventbus events handler
* /
2014-04-28 18:26:53 +02:00
static HandlerManager eventBus = new HandlerManager ( null ) ;
2013-02-06 23:25:43 +01:00
2014-04-28 18:26:53 +02:00
public static HandlerManager getEventBus ( ) {
2013-02-06 23:25:43 +01:00
return eventBus ;
}
2013-11-14 16:26:26 +01:00
2013-02-06 23:25:43 +01:00
private void handleEvents ( ) {
2014-05-15 15:27:25 +02:00
/ * *
* get the uploaded selected file name before submitting it
* /
eventBus . addHandler ( FileUploadSelectedEvent . TYPE , new FileUploadSelectedEventHandler ( ) {
@Override
public void onFileSelected ( FileUploadSelectedEvent event ) {
String fileName = event . getSelectedFileName ( ) ;
GWT . log ( " selected file name: " + fileName ) ;
if ( fileName . endsWith ( " .jpg " ) | | fileName . endsWith ( " .jpeg " ) | | fileName . endsWith ( " .png " )
| | fileName . endsWith ( " .gif " ) | | fileName . endsWith ( " .bmp " ) | | fileName . endsWith ( " .d4sR " ) ) {
try {
uploadDlg . submitForm ( ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
}
else {
Window . alert ( " File type not allowed " ) ;
uploadDlg . hide ( ) ;
}
}
} ) ;
2014-04-28 18:26:53 +02:00
/ * *
* get the uploaded file result
* /
eventBus . addHandler ( FileUploadCompleteEvent . TYPE , new FileUploadCompleteEventHandler ( ) {
@Override
public void onUploadComplete ( FileUploadCompleteEvent event ) {
//the filename and its path on server are returned to the client
String fileName = event . getUploadedFileInfo ( ) . getFilename ( ) ;
String absolutePathOnServer = event . getUploadedFileInfo ( ) . getAbsolutePath ( ) ;
GWT . log ( fileName + " uploaded on Server here: " + absolutePathOnServer ) ;
reportService . getUploadedImageUrlById ( fileName , absolutePathOnServer , new AsyncCallback < ReportImage > ( ) {
@Override
public void onFailure ( Throwable caught ) {
Window . alert ( " An error occurred in the server: " + caught . getMessage ( ) ) ;
}
@Override
public void onSuccess ( ReportImage result ) {
uploadDlg . showRegisteringResult ( true ) ; //or false if an error occurred
selectedImage . dropImage ( result . getUrl ( ) , result . getId ( ) , result . getWidth ( ) , result . getHeight ( ) ) ;
}
} ) ;
}
} ) ;
2013-11-25 17:12:01 +01:00
eventBus . addHandler ( SelectedReportEvent . TYPE , new SelectedReportEventHandler ( ) {
2013-11-13 18:56:13 +01:00
@Override
2013-11-25 17:12:01 +01:00
public void onReportSelected ( SelectedReportEvent event ) {
2014-01-28 17:31:13 +01:00
switch ( event . getAction ( ) ) {
case SELECT :
importVMEReport ( event . getId ( ) , event . getName ( ) , event . getType ( ) ) ;
break ;
case ASSOCIATE :
2013-11-14 16:26:26 +01:00
try {
2014-01-28 17:31:13 +01:00
associateVMEReportRef ( event . getType ( ) , event . getId ( ) ) ;
2013-11-14 16:26:26 +01:00
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
2014-01-28 17:31:13 +01:00
break ;
case DELETE :
deleteVMEReport ( event . getId ( ) , event . getName ( ) , event . getType ( ) ) ;
break ;
}
2013-11-13 18:56:13 +01:00
}
} ) ;
2013-05-06 17:38:24 +02:00
2013-03-15 19:06:43 +01:00
eventBus . addHandler ( ExportingCompletedEvent . TYPE , new ExportingCompletedEventHandler ( ) {
@Override
public void onExportFinished ( ExportingCompletedEvent event ) {
2013-05-06 18:54:25 +02:00
int top = 0 ;
ReportGenerator . get ( ) . getScrollerPanel ( ) . setVerticalScrollPosition ( top ) ;
2013-03-15 19:06:43 +01:00
showExportSaveOptions ( event . getFilePath ( ) , event . getItemName ( ) , event . getType ( ) ) ;
}
} ) ;
2013-05-06 17:38:24 +02:00
2013-02-06 23:25:43 +01:00
eventBus . addHandler ( AddBiblioEvent . TYPE , new AddBiblioEventHandler ( ) {
public void onAddCitation ( AddBiblioEvent event ) {
addCitation ( event . getCitekey ( ) , event . getCitetext ( ) ) ;
String keyToAdd = " ( " + event . getCitekey ( ) + " ) " ;
String currHTML = areaForBiblio . getHTML ( ) ;
if ( currHTML . endsWith ( " <br> " ) )
currHTML = currHTML . substring ( 0 , currHTML . length ( ) - 4 ) ;
areaForBiblio . setHTML ( currHTML + keyToAdd ) ;
}
} ) ;
eventBus . addHandler ( RemovedCitationEvent . TYPE , new RemovedCitationEventHandler ( ) {
public void onRemovedCitation ( RemovedCitationEvent event ) {
removeCitation ( event . getCitekey ( ) ) ;
}
} ) ;
2013-03-07 12:00:21 +01:00
eventBus . addHandler ( ReportExporterEvent . TYPE , new ReportExporterEventHandler ( ) {
2013-05-06 17:38:24 +02:00
2013-03-07 12:00:21 +01:00
@Override
public void onCompletedExport ( ReportExporterEvent event ) {
2013-05-06 17:38:24 +02:00
2013-03-14 18:05:59 +01:00
switch ( event . getOperationResult ( ) ) {
case SAVED :
2013-11-26 18:37:13 +01:00
//refreshWorkspace();
2013-03-14 18:05:59 +01:00
break ;
case SAVED_OPEN :
2013-12-18 00:47:35 +01:00
// refreshWorkspace();
2013-03-14 18:05:59 +01:00
toolBoxPanel . showExportedVersion ( event . getItemId ( ) , event . getItemId ( ) ) ;
break ;
default :
break ;
}
2013-05-06 17:38:24 +02:00
2013-03-07 12:00:21 +01:00
}
} ) ;
2013-02-06 23:25:43 +01:00
eventBus . addHandler ( AddCommentEvent . TYPE , new AddCommentEventHandler ( ) {
public void onAddComment ( AddCommentEvent event ) {
model . addCommentToComponent ( event . getSourceComponent ( ) , event . getComment ( ) , event . getAreaHeight ( ) ) ;
}
} ) ;
eventBus . addHandler ( RemovedUserCommentEvent . TYPE , new RemovedUserCommentEventHandler ( ) {
public void onRemovedComment ( RemovedUserCommentEvent event ) {
model . removeComment ( event . getSourceComponent ( ) ) ;
}
} ) ;
eventBus . addHandler ( ItemSelectionEvent . TYPE , new ItemSelectionEventHandler ( ) {
2013-03-06 19:06:42 +01:00
@SuppressWarnings ( " unchecked " )
2013-02-06 23:25:43 +01:00
public void onItemSelected ( ItemSelectionEvent event ) {
HashMap < String , Object > map = event . getItemSelected ( ) ;
int sectionIndex = 0 , compIndex = 0 ;
if ( map ! = null ) {
if ( map . get ( " item " ) . equals ( " Section " ) ) {
sectionIndex = Integer . parseInt ( ( String ) map . get ( " index " ) ) ;
seekSection ( sectionIndex + 1 ) ;
} else {
compIndex = Integer . parseInt ( ( String ) map . get ( " index " ) ) ;
sectionIndex = Integer . parseInt ( ( String ) ( ( HashMap < String , Object > ) map . get ( " parent " ) ) . get ( " index " ) ) ;
seekSection ( sectionIndex + 1 ) ;
int top = getModel ( ) . getSectionComponent ( sectionIndex + 1 ) . get ( compIndex ) . getContent ( ) . getAbsoluteTop ( ) ;
2013-03-06 19:06:42 +01:00
ReportGenerator . get ( ) . getScrollerPanel ( ) . setVerticalScrollPosition ( top ) ;
2013-02-06 23:25:43 +01:00
}
}
2013-05-06 17:38:24 +02:00
2013-02-06 23:25:43 +01:00
}
} ) ;
2014-05-15 15:27:25 +02:00
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
/ * *
* constructor
* /
public Presenter ( ) {
model = new TemplateModel ( this ) ;
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
titleBar = ReportGenerator . get ( ) . getTitleHeader ( ) ;
dlg . center ( ) ;
dlg . show ( ) ;
handleEvents ( ) ;
AsyncCallback < SessionInfo > callback = new AsyncCallback < SessionInfo > ( ) {
public void onFailure ( Throwable caught ) { }
public void onSuccess ( final SessionInfo sessionInfo ) {
currentUser = sessionInfo . getUsername ( ) ;
currentScope = sessionInfo . getScope ( ) ;
isVME = sessionInfo . isVME ( ) ;
addTextToolBar ( true ) ;
if ( sessionInfo . isWorkflowDocument ( ) ) {
model . getModelService ( ) . getWorkflowDocumentFromDocumentLibrary ( new AsyncCallback < Model > ( ) {
public void onFailure ( Throwable caught ) {
dlg . hide ( ) ;
2013-12-18 00:47:35 +01:00
}
2014-05-15 15:27:25 +02:00
public void onSuccess ( Model wfReport ) {
dlg . hide ( ) ;
loadModel ( wfReport , true ) ;
header . setMenuForWorkflowDocument ( sessionInfo . isEditable ( ) ) ;
titleBar . addWorkflowButtons ( true ) ;
pollServiceForLockRenewal ( ) ;
2013-12-18 00:47:35 +01:00
}
2014-05-15 15:27:25 +02:00
} ) ;
}
else { //not in workflow mode check if a report was open
model . getModelService ( ) . readTemplateFromSession ( new AsyncCallback < Model > ( ) {
public void onFailure ( Throwable caught ) {
dlg . hide ( ) ;
}
public void onSuccess ( Model result ) {
if ( isVME ) {
header . setMenuForVME ( ) ;
header . enableExports ( ) ;
}
dlg . hide ( ) ;
if ( result ! = null ) { //there was one report open in session
loadModel ( result , true ) ;
header . enableExports ( ) ;
} else {
commonCommands . newTemplate . execute ( ) ;
}
}
} ) ;
}
2013-02-06 23:25:43 +01:00
}
2014-05-15 15:27:25 +02:00
} ;
2013-05-06 17:38:24 +02:00
2014-05-15 15:27:25 +02:00
model . getModelService ( ) . getSessionInfo ( getHost ( ) , callback ) ;
commonCommands = new CommonCommands ( this ) ;
//importDlg = new FimesFileUploadWindow(eventBus);
}
2013-11-14 16:26:26 +01:00
2014-05-15 15:27:25 +02:00
public void setClientSequenceSelected ( ClientSequence toSet ) {
this . clientSeqSelected = toSet ;
}
2013-05-06 17:38:24 +02:00
2014-05-15 15:27:25 +02:00
public void showOpenOptions ( ) {
wp . showOpenOptions ( isVME ) ;
}
2013-05-06 17:38:24 +02:00
2014-05-15 15:27:25 +02:00
public void showLoading ( ) {
wp . showLoading ( ) ;
}
2013-05-02 17:00:36 +02:00
2014-05-15 15:27:25 +02:00
/ * *
* 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
* @param templateObjectID the id in the folder of the template to open
* @param isTemplate true if you are opening a template false if you are opening a report
* /
public void openTemplate ( String templateToOpen , String templateObjectID , final boolean isTemplate ) {
showLoading ( ) ;
//will asyncrously return a Serializable Model instance read from disk
model . getModelService ( ) . readModel ( templateToOpen , templateObjectID , isTemplate , false , new AsyncCallback < Model > ( ) {
@Override
public void onSuccess ( Model toLoad ) {
if ( toLoad ! = null )
loadModel ( toLoad , true ) ;
else
Window . alert ( " Could not Load template, error on server: " ) ;
}
@Override
public void onFailure ( Throwable caught ) {
Window . alert ( " Could not Load template, please try again later: " + caught . getMessage ( ) ) ;
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
}
} ) ;
2013-02-06 23:25:43 +01:00
}
2014-05-15 15:27:25 +02:00
/ * *
* called when a citation is added
* @param citekey .
* @param text .
* /
public void addCitation ( String citekey , String text ) {
if ( ! hasBibliography ( ) ) {
MessageBox . alert ( " Warning " , " Bibliography will be added as last section of this report " , null ) ;
model . insertBiblioSection ( ) ;
2013-02-06 23:25:43 +01:00
}
2014-05-15 15:27:25 +02:00
model . addCitation ( citekey , text ) ;
titleBar . getSectionSwitchPanel ( ) . setPageDisplayer ( model . getCurrentPage ( ) , model . getTotalPages ( ) ) ;
2013-02-06 23:25:43 +01:00
}
2013-05-06 17:38:24 +02:00
2014-05-15 15:27:25 +02:00
public boolean removeCitation ( String citekey ) {
boolean toReturn = model . removeCitation ( citekey ) ;
if ( toReturn ) { //if has been removed from the model
if ( model . getCurrentPage ( ) = = model . getTotalPages ( ) ) { //if the view is displaying the bibliography, need to refresh it
seekSection ( model . getTotalPages ( ) ) ;
}
2013-02-06 23:25:43 +01:00
}
2014-05-15 15:27:25 +02:00
return toReturn ;
}
2013-02-06 23:25:43 +01:00
/ * *
2014-05-15 15:27:25 +02:00
* look if a section with a specific metadata ( that indicate sit is a biblio section )
* exists in the current report model :
* check whether the last section has Metadata " isBiblio " = " true " or false
* @return true if bibliography is present yet false otherwise
2013-02-06 23:25:43 +01:00
* /
2014-05-15 15:27:25 +02:00
public boolean hasBibliography ( ) {
for ( Metadata metadata : model . getSection ( model . getTotalPages ( ) ) . getAllMetadata ( ) )
if ( metadata . getAttribute ( ) . equals ( TemplateModel . BIBLIO_SECTION ) ) return true ;
return false ;
}
/ * *
* look if a comment with a specific metadata ( that indicate sit is a comment )
* exists in the current report model :
* @return true if comment is present yet false otherwise
* /
public boolean hasComments ( Widget toCheck ) {
TemplateSection currSection = model . getSection ( model . getCurrentPage ( ) ) ;
return currSection . hasComments ( toCheck ) ;
}
/ * *
* look if a comment with a specific metadata ( that indicate sit is a comment )
* exists in the current report model :
* @return true if comment is present yet false otherwise
* /
public AddCommentEvent getComponentComments ( Widget toCheck ) {
TemplateSection currSection = model . getSection ( model . getCurrentPage ( ) ) ;
return currSection . getComponentComments ( toCheck ) ;
}
/ * *
*
* /
private void pollServiceForLockRenewal ( ) {
final int fourteenMinutes = 840000 ;
final Timer t = new Timer ( ) {
public void run ( ) {
model . getModelService ( ) . renewLock ( new AsyncCallback < Void > ( ) {
public void onFailure ( Throwable caught ) {
}
public void onSuccess ( Void result ) {
schedule ( fourteenMinutes ) ;
}
} ) ;
}
} ;
t . schedule ( fourteenMinutes ) ;
}
/ * *
* put the commands in the hashmap
* /
private HashMap < String , Command > getCommands ( ) {
/ * *
* commands to pass to the toolbar
* /
HashMap < String , Command > toReturn = new HashMap < String , Command > ( ) ;
toReturn . put ( " structureView " , commonCommands . structureView ) ;
toReturn . put ( " save " , commonCommands . saveTemplate ) ;
toReturn . put ( " exportRSG " , commonCommands . exportToRSG ) ;
toReturn . put ( " newdoc " , commonCommands . newTemplate ) ;
toReturn . put ( " open_report " , commonCommands . openReport ) ;
toReturn . put ( " open_template " , commonCommands . openTemplate ) ;
toReturn . put ( " importing " , commonCommands . importTemplateCommand ) ;
toReturn . put ( " insertImage " , commonCommands . insertImage ) ;
toReturn . put ( " pickColor " , commonCommands . pickColor ) ;
return toReturn ;
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
/ * *
* to remove the current displayed section
* /
public void discardCurrentSection ( ) {
if ( model . getTotalPages ( ) = = 1 )
Window . alert ( " Cannot discard section, need ad least 2 " ) ;
else {
boolean result = Window . confirm ( " Are you sure you want to discard section number " + model . getCurrentPage ( ) + " ? " ) ;
if ( result ) {
TemplateSection removed = model . discardSection ( model . getCurrentPage ( ) ) ;
if ( removed = = null )
GWT . log ( " REMOVED NOTHING " , null ) ;
else
GWT . log ( " REMOVED " + removed . getAllComponents ( ) . size ( ) , null ) ;
loadFirstSection ( ) ;
}
2013-02-06 23:25:43 +01:00
}
}
2014-05-15 15:27:25 +02:00
/ * *
*
* @param titleBar ,
* /
public void setTitleBar ( TitleBar titleBar ) {
this . titleBar = titleBar ;
}
/ * *
*
* @return .
* /
public String getHost ( ) {
return GWT . getHostPageBaseURL ( ) + " ../../ " ;
}
2013-02-06 23:25:43 +01:00
2013-12-18 00:47:35 +01:00
2014-05-15 15:27:25 +02:00
/ * *
* remove the user - added components from the workspace , and from the model
*
* /
public void cleanAll ( ) {
// reset the model
model = new TemplateModel ( this ) ;
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
//reset the UI
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
//give the new model instance
header . setModel ( model ) ;
wp . setModel ( model ) ;
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
cleanWorkspace ( ) ;
titleBar . getSectionSwitchPanel ( ) . hideNextButton ( ) ;
titleBar . getSectionSwitchPanel ( ) . hidePrevButton ( ) ;
titleBar . setTemplateName ( model . getTemplateName ( ) ) ;
titleBar . getSectionSwitchPanel ( ) . setPageDisplayer ( model . getCurrentPage ( ) , model . getTotalPages ( ) ) ;
titleBar . getSectionSwitchPanel ( ) . setVisible ( false ) ;
resizeWorkingArea ( model . getPageWidth ( ) , model . getPageHeight ( ) ) ;
2013-11-26 18:37:13 +01:00
2014-05-15 15:27:25 +02:00
toolBoxPanel . clear ( ) ;
toolBoxPanel . collapse ( ) ;
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
}
/ * *
* remove the user - added components from the workspace ( in the current page ) but not from the model
*
* /
public void cleanWorkspace ( ) {
wp . getMainLayout ( ) . clear ( ) ;
ReportGenerator . get ( ) . getScrollerPanel ( ) . setScrollPosition ( 0 ) ;
}
2013-05-06 17:38:24 +02:00
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
/ * *
* Save the current report
* @param folderid the id where to save the report
*
* /
public void saveReport ( String folderid , String 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 ( ) ;
}
} ) ;
2013-05-06 17:38:24 +02:00
2014-05-15 15:27:25 +02:00
}
/ * *
* Save the current report in a given folder
*
* /
public void 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 ( ) ;
}
} ) ;
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
/ * *
* Save the current report in a given folder
*
* /
public void updateWorkflowDocument ( boolean update ) {
dlg . center ( ) ;
dlg . show ( ) ;
Model toSave = model . getSerializableModel ( ) ;
reportService . updateWorkflowDocument ( toSave , update , new AsyncCallback < Void > ( ) {
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
public void onFailure ( Throwable caught ) {
dlg . hide ( ) ;
Window . alert ( " failed to update workflow document " ) ;
}
public void onSuccess ( Void result ) {
dlg . hide ( ) ;
loadWorkflowLibraryApp ( ) ;
}
} ) ;
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
/ * *
*
* @param templateName .
* /
public void changeTemplateName ( String templateName ) {
//initialize the template
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 ( ) / * - {
2013-05-06 17:38:24 +02:00
this . @org.gcube.portlets.user.reportgenerator.client.Presenter.Presenter : : location = $wnd . location . href ;
} - * / ;
2014-05-15 15:27:25 +02:00
/ * *
* Import a Section in the View and in the Model
* @param toLoad the SerializableModel instance where toget the section
* @param sectionNoToimport section to import 0 - > n - 1
* @param beforeSection say where to import this section ( before )
* @param asLastSection say to import this section as last section in the curren template / report
* /
public void importSection ( Model toLoad , int sectionNoToimport , int beforeSection , boolean asLastSection ) {
model . importSectionInModel ( toLoad , sectionNoToimport , beforeSection , asLastSection ) ;
if ( asLastSection )
seekLastPage ( ) ;
else
seekSection ( beforeSection ) ;
Window . alert ( " Importing Complete " ) ;
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
/ * *
* in case someone imported a new section
* /
public void seekLastPage ( ) {
while ( ! ( model . getCurrentPage ( ) = = model . getTotalPages ( ) ) )
nextPageButtonClicked ( ) ;
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
/ * *
* in case someone imported a new section
* @param sect2Seek .
* /
public void seekSection ( int sect2Seek ) {
loadFirstSection ( ) ;
while ( ! ( model . getCurrentPage ( ) = = sect2Seek ) )
nextPageButtonClicked ( ) ;
}
/ * *
*
* /
public void addTextToolBar ( boolean enableCommands ) {
RichTextToolbar rtbar = new RichTextToolbar ( new RichTextArea ( ) , getCommands ( ) , isVME ) ;
rtbar . enableCommands ( enableCommands ) ;
currentSelectedToolbar = rtbar ;
SimplePanel deco = new SimplePanel ( ) ;
rtbar . setEnabled ( false ) ;
deco . add ( rtbar ) ;
deco . setSize ( " 100% " , " 25 " ) ;
rtbar . setWidth ( " 100% " ) ;
ReportGenerator . get ( ) . getToolbarPanel ( ) . clear ( ) ;
ReportGenerator . get ( ) . getToolbarPanel ( ) . add ( deco ) ;
}
/ * *
* enable the format text toolbar for the given Rich Textarea passed as argument
* @param d4sArea the enabled text area
* /
public void enableTextToolBar ( RichTextArea d4sArea ) {
RichTextToolbar rtbar = new RichTextToolbar ( d4sArea , getCommands ( ) , isVME ) ;
if ( menuForWorkflowDocument ) //disable open and save buttons from the toolbar
rtbar . enableCommands ( false ) ;
currentSelectedToolbar = rtbar ;
rtbar . setEnabled ( true ) ;
ReportGenerator . get ( ) . getToolbarPanel ( ) . clear ( ) ;
SimplePanel deco = new SimplePanel ( ) ;
deco . add ( rtbar ) ;
deco . setSize ( " 100% " , " 25 " ) ;
rtbar . setWidth ( " 100% " ) ;
ReportGenerator . get ( ) . getToolbarPanel ( ) . add ( deco ) ;
}
2013-12-18 00:47:35 +01:00
2014-05-15 15:27:25 +02:00
/ * *
* enable the format text toolbar for the given Rich Textarea passed as argument
* @param d4sArea the enabled text area
* /
public void enableBiblioEntry ( RichTextArea d4sArea ) {
ReportGenerator . get ( ) . getHeader ( ) . enableBiblioEntry ( d4sArea ) ;
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
/ * *
* generate the docx to be passed to the fimesExporter
* @param model
* /
public void generateFiMES ( final TemplateModel model ) {
}
/ * *
*
* @param model .
* @param type .
* /
public void generateManifestation ( final TemplateModel model , final ExportManifestationType type ) {
GWT . runAsync ( ReportExporterPopup . class , new RunAsyncCallback ( ) {
2013-05-06 17:38:24 +02:00
2014-05-15 15:27:25 +02:00
@SuppressWarnings ( " incomplete-switch " )
@Override
public void onSuccess ( ) {
ReportExporterPopup popup = new ReportExporterPopup ( eventBus ) ;
Model reportModel = model . getSerializableModel ( ) ;
switch ( type ) {
case DOCX :
popup . export ( reportModel , TypeExporter . DOCX ) ;
break ;
case HTML :
popup . export ( reportModel , TypeExporter . HTML ) ;
break ;
case PDF :
popup . export ( reportModel , TypeExporter . PDF ) ;
break ;
case XML :
popup . export ( reportModel , TypeExporter . XML ) ;
break ;
}
}
2013-05-06 17:38:24 +02:00
2014-05-15 15:27:25 +02:00
@Override
public void onFailure ( Throwable reason ) {
}
} ) ;
2013-05-06 17:38:24 +02:00
2014-05-15 15:27:25 +02:00
}
2013-05-06 17:38:24 +02:00
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
public void openAddCitationDialog ( ) {
AddBiblioEntryDialog dlg = new AddBiblioEntryDialog ( eventBus ) ;
dlg . show ( ) ;
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
public void openManageCitationsDialog ( ) {
DeleteCitationsDialog dlg = new DeleteCitationsDialog ( eventBus , model . getSection ( model . getTotalPages ( ) ) ) ;
dlg . show ( ) ;
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
/ * *
*
* @return .
* /
public Headerbar getHeader ( ) {
return header ;
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
/ * *
*
* @return .
* /
public TemplateModel getModel ( ) {
return model ;
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
/ * *
*
* @return .
* /
public ToolboxPanel getToolBoxPanel ( ) {
return toolBoxPanel ;
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
/ * *
*
* @return .
* /
public WorkspacePanel getWp ( ) {
return wp ;
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
/ * *
* called when nextPage Button is Clicked
* /
public void nextPageButtonClicked ( ) {
cleanWorkspace ( ) ;
//refresh the current page in the model
model . setCurrentPage ( model . getCurrentPage ( ) + 1 ) ;
//refresh the current page in the UI
titleBar . getSectionSwitchPanel ( ) . setPageDisplayer ( model . getCurrentPage ( ) , model . getTotalPages ( ) ) ;
//read the previous user added elements to the template page from the model and place them back in the UI
placeTemplatePageElements ( model . getCurrentPage ( ) ) ;
if ( model . getCurrentPage ( ) = = model . getTotalPages ( ) )
titleBar . getSectionSwitchPanel ( ) . hideNextButton ( ) ;
else
titleBar . getSectionSwitchPanel ( ) . showNextButton ( ) ;
if ( model . getCurrentPage ( ) = = 1 )
titleBar . getSectionSwitchPanel ( ) . hidePrevButton ( ) ;
else
titleBar . getSectionSwitchPanel ( ) . showPrevButton ( ) ;
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
/ * *
*
* @param toLoad
* /
private void loadModel ( Model toLoad , boolean savingEnabled ) {
//reset the UI
cleanAllNotSession ( ) ;
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
//load the serializable model in my Model
model . loadModel ( toLoad , this ) ;
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
wp . setModel ( model ) ;
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
titleBar . setTemplateName ( model . getTemplateName ( ) ) ;
titleBar . getSectionSwitchPanel ( ) . setPageDisplayer ( model . getCurrentPage ( ) , model . getTotalPages ( ) ) ;
titleBar . getSectionSwitchPanel ( ) . setVisible ( true ) ;
resizeWorkingArea ( model . getPageWidth ( ) , model . getPageHeight ( ) ) ;
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
addTextToolBar ( savingEnabled ) ;
int currPage = model . getCurrentPage ( ) ;
//load the UI components of the current page
GWT . log ( " READ CURR PAGE " + currPage , null ) ;
placeTemplatePageElements ( currPage ) ;
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
//if there is more than one page place in the UI the next page button
if ( currPage < model . getTotalPages ( ) ) {
titleBar . getSectionSwitchPanel ( ) . showNextButton ( ) ;
}
if ( currPage > 1 )
titleBar . getSectionSwitchPanel ( ) . showPrevButton ( ) ;
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
if ( isShowingStructure )
showStructure ( ) ;
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
/ * *
* just clean the page
* /
public void cleanAllNotSession ( ) {
// reset the model
model = new TemplateModel ( this ) ;
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
//reset the UI
2013-11-26 18:37:13 +01:00
2014-05-15 15:27:25 +02:00
//give the new model instance
header . setModel ( model ) ;
wp . setModel ( model ) ;
2014-01-28 17:31:13 +01:00
2014-05-15 15:27:25 +02:00
cleanWorkspace ( ) ;
titleBar . getSectionSwitchPanel ( ) . hideNextButton ( ) ;
titleBar . getSectionSwitchPanel ( ) . hidePrevButton ( ) ;
titleBar . setTemplateName ( model . getTemplateName ( ) ) ;
titleBar . getSectionSwitchPanel ( ) . setPageDisplayer ( model . getCurrentPage ( ) , model . getTotalPages ( ) ) ;
titleBar . getSectionSwitchPanel ( ) . setVisible ( false ) ;
resizeWorkingArea ( model . getPageWidth ( ) , model . getPageHeight ( ) ) ;
}
2013-05-06 17:38:24 +02:00
2014-05-15 15:27:25 +02:00
private void loadFirstSection ( ) {
//reset the UI
cleanWorkspace ( ) ;
titleBar . getSectionSwitchPanel ( ) . hideNextButton ( ) ;
titleBar . getSectionSwitchPanel ( ) . hidePrevButton ( ) ;
model . setCurrentPage ( 1 ) ;
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
titleBar . setTemplateName ( model . getTemplateName ( ) ) ;
titleBar . getSectionSwitchPanel ( ) . setPageDisplayer ( model . getCurrentPage ( ) , model . getTotalPages ( ) ) ;
titleBar . getSectionSwitchPanel ( ) . setVisible ( true ) ;
addTextToolBar ( true ) ;
int currPage = model . getCurrentPage ( ) ;
//load the UI components of the current page
GWT . log ( " READ CURR PAGE " + currPage , null ) ;
placeTemplatePageElements ( currPage ) ;
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
//if there is more than one page place in the UI the next page button
if ( currPage < model . getTotalPages ( ) ) {
titleBar . getSectionSwitchPanel ( ) . showNextButton ( ) ;
}
if ( currPage > 1 )
titleBar . getSectionSwitchPanel ( ) . showPrevButton ( ) ;
2013-02-06 23:25:43 +01:00
}
2014-05-15 15:27:25 +02:00
/ * *
* It places back the user added widgets ( TemplateComponents ) in the page
*
* @param section . the section number of the wanted TemplateComponent ( s )
* /
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
public void placeTemplatePageElements ( int section ) {
if ( ! ( model . getSectionComponent ( section ) = = null ) ) {
List < TemplateComponent > pageElems = model . getSectionComponent ( section ) ;
for ( TemplateComponent component : pageElems ) {
int uiX = component . getX ( ) ;
int uiY = component . getY ( ) ;
switch ( component . getType ( ) ) {
case HEADING_1 :
case HEADING_2 :
case HEADING_3 :
case HEADING_4 :
case HEADING_5 :
case TITLE :
if ( component . isLocked ( ) ) {
HTML text = ( HTML ) component . getContent ( ) ;
wp . addComponentToLayout ( text , component . isDoubleColLayout ( ) ) ;
}
else {
HeadingTextArea textArea = ( HeadingTextArea ) component . getContent ( ) ;
textArea . getMyInstance ( ) . setTop ( uiY ) ;
textArea . getMyInstance ( ) . setLeft ( uiX ) ;
wp . addComponentToLayout ( textArea , component . isDoubleColLayout ( ) ) ;
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
break ;
case BODY_NOT_FORMATTED :
if ( component . isLocked ( ) ) {
HTML text = ( HTML ) component . getContent ( ) ;
text . addStyleName ( " readOnlyText " ) ;
wp . addComponentToLayout ( text , component . isDoubleColLayout ( ) ) ;
}
else {
BasicTextArea textArea = ( BasicTextArea ) component . getContent ( ) ;
wp . addComponentToLayout ( textArea , component . isDoubleColLayout ( ) ) ;
}
2013-03-13 11:06:47 +01:00
2014-05-15 15:27:25 +02:00
break ;
case BODY :
if ( component . isLocked ( ) ) {
HTML text = ( HTML ) component . getContent ( ) ;
wp . addComponentToLayout ( text , component . isDoubleColLayout ( ) ) ;
}
else {
D4sRichTextarea textArea = ( D4sRichTextarea ) component . getContent ( ) ;
textArea . getMyInstance ( ) . setTop ( uiY ) ;
textArea . getMyInstance ( ) . setLeft ( uiX ) ;
wp . addComponentToLayout ( textArea , component . isDoubleColLayout ( ) ) ;
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
break ;
case DYNA_IMAGE :
ClientImage imageDropping = ( ClientImage ) component . getContent ( ) ;
wp . addComponentToLayout ( imageDropping , component . isDoubleColLayout ( ) ) ;
break ;
case FAKE_TEXTAREA :
break ;
case TOC :
ReportTextArea dp = ( ReportTextArea ) component . getContent ( ) ;
wp . addComponentToLayout ( dp , component . isDoubleColLayout ( ) ) ;
setCurrCursorPos ( uiY ) ;
break ;
case BIBLIO :
ReportTextArea dp2 = ( ReportTextArea ) component . getContent ( ) ;
wp . addComponentToLayout ( dp2 , component . isDoubleColLayout ( ) ) ;
setCurrCursorPos ( uiY ) ;
break ;
case PAGEBREAK :
ReportTextArea dp3 = ( ReportTextArea ) component . getContent ( ) ;
wp . addComponentToLayout ( dp3 , component . isDoubleColLayout ( ) ) ;
setCurrCursorPos ( uiY ) ;
break ;
case TIME_SERIES :
break ;
case FLEX_TABLE :
GenericTable gt = ( GenericTable ) component . getContent ( ) ;
GWT . log ( " Reading TABLE rows: " + gt . getRowsNo ( ) + " cols: " + gt . getCols ( ) ) ;
wp . addComponentToLayout ( gt , component . isDoubleColLayout ( ) ) ;
break ;
case ATTRIBUTE_MULTI :
AttributeMultiSelection at = ( AttributeMultiSelection ) component . getContent ( ) ;
wp . addComponentToLayout ( at , component . isDoubleColLayout ( ) ) ;
setCurrCursorPos ( uiY ) ;
break ;
case ATTRIBUTE_UNIQUE :
AttributeSingleSelection atu = ( AttributeSingleSelection ) component . getContent ( ) ;
wp . addComponentToLayout ( atu , component . isDoubleColLayout ( ) ) ;
setCurrCursorPos ( uiY ) ;
break ;
case COMMENT :
2013-02-06 23:25:43 +01:00
HTML text = ( HTML ) component . getContent ( ) ;
wp . addComponentToLayout ( text , component . isDoubleColLayout ( ) ) ;
2014-05-15 15:27:25 +02:00
break ;
case INSTRUCTION :
HTML instr = ( HTML ) component . getContent ( ) ;
wp . addComponentToLayout ( instr , component . isDoubleColLayout ( ) ) ;
break ;
case REPEAT_SEQUENCE_DELIMITER :
GroupingDelimiterArea gpa = ( GroupingDelimiterArea ) component . getContent ( ) ;
wp . addComponentToLayout ( gpa , component . isDoubleColLayout ( ) ) ;
break ;
case REPEAT_SEQUENCE :
ClientRepeatableSequence rps = ( ClientRepeatableSequence ) component . getContent ( ) ;
wp . addComponentToLayout ( rps , component . isDoubleColLayout ( ) ) ;
break ;
case REPORT_REFERENCE :
ClientReportReference cmSeq = ( ClientReportReference ) component . getContent ( ) ;
wp . addComponentToLayout ( cmSeq , component . isDoubleColLayout ( ) ) ;
break ;
case BODY_TABLE_IMAGE :
TextTableImage tti = ( TextTableImage ) component . getContent ( ) ;
wp . addComponentToLayout ( tti , component . isDoubleColLayout ( ) ) ;
break ;
2013-02-06 23:25:43 +01:00
}
}
}
}
2014-05-15 15:27:25 +02:00
/ * *
*
* @param y .
* /
public void setCurrCursorPos ( int y ) {
this . currFocus = y ;
}
public Coords getInsertionPoint ( ) {
int y = getSelectedIndex ( ) ;
return new Coords ( 25 , y ) ;
}
public int getSelectedIndex ( ) {
return currFocus ;
}
/ * *
* called when prevPage Button is Clicked
* /
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
public void prevPageButtonClicked ( ) {
cleanWorkspace ( ) ;
//refresh the current page in the model
model . setCurrentPage ( model . getCurrentPage ( ) - 1 ) ;
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
//refresh the current page in the UI
titleBar . getSectionSwitchPanel ( ) . setPageDisplayer ( model . getCurrentPage ( ) , model . getTotalPages ( ) ) ;
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
//read the previous user added elements to the template page from the model and place them back in the UI
placeTemplatePageElements ( model . getCurrentPage ( ) ) ;
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
if ( model . getCurrentPage ( ) = = model . getTotalPages ( ) )
titleBar . getSectionSwitchPanel ( ) . hideNextButton ( ) ;
else
titleBar . getSectionSwitchPanel ( ) . showNextButton ( ) ;
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
if ( model . getCurrentPage ( ) = = 1 )
titleBar . getSectionSwitchPanel ( ) . hidePrevButton ( ) ;
else
titleBar . getSectionSwitchPanel ( ) . showPrevButton ( ) ;
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
/ * *
* Resize the template componet just the model
*
* @param toResize .
* @param newWidth .
* @param newHeight .
* /
public void resizeTemplateComponentInModel ( Widget toResize , int newWidth , int newHeight ) {
model . resizeModelComponent ( toResize , newWidth , newHeight ) ;
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
/ * *
* @param width .
* @param height .
* /
public void resizeWorkingArea ( int width , int height ) {
//save the new state ---> TO MODEL
model . setPageWidth ( width ) ;
model . setPageHeight ( height ) ;
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
//apply the change ---> TO VIEW
wp . resizeWorkspace ( width , height ) ;
}
/ * *
*
* @param header .
* /
public void setHeader ( Headerbar header ) {
this . header = header ;
}
/ * *
*
* @param toolBoxPanel It ' s the tool box panel
* /
public void setToolBoxPanel ( ToolboxPanel toolBoxPanel ) {
this . toolBoxPanel = toolBoxPanel ;
}
/ * *
*
* @param wp .
* /
public void setWp ( WorkspacePanel wp ) {
this . wp = wp ;
}
/ * *
*
* @return the scope in which the application is running on
* /
public String getCurrentScope ( ) {
return currentScope ;
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
/ * *
*
* @return the user username who is using the application
* /
public UserBean getCurrentUser ( ) {
return currentUser ;
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
/ * *
*
* @return .
* /
public TitleBar getTitleBar ( ) {
return titleBar ;
}
/ * *
* refresh the root in the workspace
* /
public void refreshWorkspace ( ) {
toolBoxPanel . refreshRoot ( ) ;
}
/ * *
* show the upload file popup
* /
public void showUploadImagePopup ( ClientImage selectedImage ) {
uploadDlg = new UploadProgressDialog ( " Upload Image " , eventBus , true ) ;
uploadDlg . center ( ) ;
uploadDlg . show ( ) ;
this . selectedImage = selectedImage ;
}
/ * *
* show the upload file popup
* /
public void showUploadFilePopup ( ) {
uploadDlg = new UploadProgressDialog ( " Upload Report " , eventBus ) ;
uploadDlg . center ( ) ;
uploadDlg . show ( ) ;
}
/ * *
*
* @return the current selected rich text area
* /
public RichTextToolbar getCurrentSelected ( ) {
return currentSelectedToolbar ;
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
public void setMenuForWorkflowDocument ( boolean enable ) {
menuForWorkflowDocument = enable ;
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
public boolean getMenuForWorkflowDocument ( ) {
return menuForWorkflowDocument ;
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
public void setAreaForBiblio ( RichTextArea d4sArea ) {
areaForBiblio = d4sArea ;
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
/ * *
* show / hide the structure view
* /
2014-01-28 17:31:13 +01:00
2014-05-15 15:27:25 +02:00
public void toggleReportStructure ( ) {
if ( ! isShowingStructure ) {
showStructure ( ) ;
isShowingStructure = true ;
}
else {
toolBoxPanel . collapse ( ) ;
isShowingStructure = false ;
}
2013-12-18 17:33:25 +01:00
}
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
private void showStructure ( ) {
toolBoxPanel . showStructure ( new ReportStructurePanel ( eventBus , model . getSerializableModel ( ) , ToolboxPanel . TOOLBOX_WIDTH + " px " , ToolboxPanel . TOOLBOX_HEIGHT + " px " ) ) ;
2014-01-28 17:31:13 +01:00
2014-05-15 15:27:25 +02:00
}
2014-01-28 17:31:13 +01:00
2014-05-15 15:27:25 +02:00
public HorizontalPanel getExportsPanel ( ) {
return exportsPanel ;
}
2013-03-15 19:06:43 +01:00
2013-02-06 23:25:43 +01:00
2014-05-15 15:27:25 +02:00
public void setExportsPanel ( HorizontalPanel exportsPanel ) {
this . exportsPanel = exportsPanel ;
}
2013-05-06 17:38:24 +02:00
2014-05-15 15:27:25 +02:00
/ * *
* when export is done this method is called
* @param filePath
* @param itemName
* @param type
2013-03-16 02:53:00 +01:00
* /
2014-05-15 15:27:25 +02:00
public void showExportSaveOptions ( final String filePath , final String itemName , final TypeExporter type ) {
clearExportPanel ( ) ;
/ *
* I need to save a temp file , in case the user uses the Save & Open .
* Smart popup blockers will allow a popup if it is directly associated to a user ’ s action .
* If it ’ s delayed in anyway , there ’ s a good chance it ’ s going to get blocked . The exported File needs to be there when clicking open .
* /
reportService . save ( filePath , null , " system.tmp " , type , true , new AsyncCallback < String > ( ) {
@Override
public void onSuccess ( String createdItemId ) {
//here i pass the temp createdItemId
showExportPanel ( filePath , itemName , type , createdItemId ) ;
}
2013-05-06 17:38:24 +02:00
2014-05-15 15:27:25 +02:00
@Override
public void onFailure ( Throwable caught ) {
Window . alert ( " Error while trying exporting this report: " + caught . getMessage ( ) ) ;
}
} ) ;
2013-05-06 17:38:24 +02:00
2014-05-15 15:27:25 +02:00
}
2013-05-06 17:38:24 +02:00
2014-05-15 15:27:25 +02:00
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 ) ;
//needed for applying the css3 transition effect
final Timer t = new Timer ( ) {
@Override
public void run ( ) {
exo . getMainPanel ( ) . addStyleName ( " exportPanel-show " ) ;
}
} ;
t . schedule ( 10 ) ;
}
2013-11-13 18:56:13 +01:00
2014-05-15 15:27:25 +02:00
public void clearExportPanel ( ) {
exportsPanel . clear ( ) ;
}
2014-01-28 17:31:13 +01:00
2014-05-15 15:27:25 +02:00
public void newDoc ( ) {
changeTemplateName ( TemplateModel . DEFAULT_NAME ) ;
cleanAll ( ) ;
showOpenOptions ( ) ;
}
2013-11-14 16:26:26 +01:00
2014-05-15 15:27:25 +02:00
/ * *
*
* /
public void showVMEImportDialog ( ) {
SelectVMEReportDialog dlg = new SelectVMEReportDialog ( getEventBus ( ) , VMETypeIdentifier . Vme , Action . SELECT ) ;
dlg . show ( ) ;
}
2013-11-14 16:26:26 +01:00
2014-05-15 15:27:25 +02:00
/ * *
*
* /
public void showVMEReportRefImportDialog ( VMETypeIdentifier refType ) {
SelectVMEReportDialog dlg = new SelectVMEReportDialog ( getEventBus ( ) , refType , Action . SELECT ) ;
dlg . show ( ) ;
}
/ * *
*
* /
public void showVMERefAssociateDialog ( VMETypeIdentifier refType ) {
SelectVMEReportDialog dlg = new SelectVMEReportDialog ( getEventBus ( ) , refType , Action . ASSOCIATE ) ;
dlg . show ( ) ;
}
/ * *
*
* /
public void showVMEDeleteDialog ( VMETypeIdentifier refType ) {
SelectVMEReportDialog dlg = new SelectVMEReportDialog ( getEventBus ( ) , refType , Action . DELETE ) ;
dlg . show ( ) ;
}
2013-12-18 16:30:32 +01:00
2014-05-15 15:27:25 +02:00
public void importVMETemplate ( final VMETypeIdentifier type ) {
showLoading ( ) ;
reportService . importVMETemplate ( type , new AsyncCallback < Model > ( ) {
@Override
public void onFailure ( Throwable caught ) {
Window . alert ( " Could not Load Template Model, error on server.: " + caught . getMessage ( ) ) ;
2013-12-18 16:30:32 +01:00
}
2014-05-15 15:27:25 +02:00
@Override
public void onSuccess ( Model toLoad ) {
if ( toLoad ! = null ) {
loadModel ( toLoad , type = = VMETypeIdentifier . Vme ) ;
currentVmeType = type ;
}
else
Window . alert ( " Could not Load Template Model, error on server. " ) ;
2014-01-29 17:34:57 +01:00
}
2014-05-15 15:27:25 +02:00
} ) ;
}
/ * *
* Export To the Reports Store Gateway
*
* /
public void exportReportToRSG ( ) {
2015-12-11 16:50:04 +01:00
MessageBox . confirm ( " Commit to VME-DB " , " Are you sure you want to commit the " + model . getTemplateName ( ) + " into the VME Database? " , new Listener < MessageBoxEvent > ( ) {
@Override
public void handleEvent ( MessageBoxEvent be ) {
if ( Dialog . YES . equalsIgnoreCase ( be . getButtonClicked ( ) . getItemId ( ) ) ) {
dlg . center ( ) ;
Model toSave = model . getSerializableModel ( ) ;
reportService . exportReportToRSG ( currentVmeType , toSave , new AsyncCallback < VmeExportResponse > ( ) {
public void onFailure ( Throwable caught ) {
dlg . hide ( ) ;
MessageBox . alert ( " Warning " , " Report Not Exported: " + caught . getMessage ( ) , null ) ;
}
public void onSuccess ( VmeExportResponse response ) {
dlg . hide ( ) ;
//write ok
if ( response . isGloballySucceded ( ) ) {
MessageBox . info ( " Exporting to RSG Operation " , " Report Exported Successfully " , null ) ;
newDoc ( ) ;
}
//runtime exception
else if ( response . getResponseMessageList ( ) . size ( ) = = 1 & & response . getResponseMessageList ( ) . get ( 0 ) . getResponseEntryCode ( ) . equals ( " RUNTIME_EXCEPTION " ) ) {
MessageBox . alert ( " Exporting to RSG Operation Failed " , " Report Exporting has failed for the following reason: <br/> " + response . getResponseMessageList ( ) . get ( 0 ) . getResponseMessage ( ) , null ) ;
}
//user report compile exception
else {
String failReasons = " " ;
for ( VmeResponseEntry entry : response . getResponseMessageList ( ) ) {
failReasons + = entry . getResponseMessage ( ) + " <br/> " ;
}
MessageBox . alert ( " Exporting to RSG Operation Failed " , " Report Exporting has failed for the following reasons: <br/> " + failReasons , null ) ;
}
}
} ) ;
}
}
} ) ;
2014-05-15 15:27:25 +02:00
}
private void deleteVMEReport ( String reportId , String name , final VMETypeIdentifier type ) {
if ( Window . confirm ( " Are you sure you want to delete " + name + " from the VME Database? (This action is Undoable) " ) ) {
showLoading ( ) ;
reportService . deleteReportFromRSG ( type , reportId , new AsyncCallback < VmeExportResponse > ( ) {
@Override
public void onFailure ( Throwable caught ) {
dlg . hide ( ) ;
Window . alert ( " Could not Delete, error on server.: " + caught . getMessage ( ) ) ;
}
@Override
public void onSuccess ( VmeExportResponse response ) {
dlg . hide ( ) ;
//delete ok
if ( response . getResponseMessageList ( ) . size ( ) = = 1 & & response . getResponseMessageList ( ) . get ( 0 ) . getResponseEntryCode ( ) . equalsIgnoreCase ( " SUCCEEDED " ) )
MessageBox . info ( " Delete VME Report Operation " , " Report Deleted Successfully " , null ) ;
//runtime exception
else if ( response . getResponseMessageList ( ) . size ( ) = = 1 & & response . getResponseMessageList ( ) . get ( 0 ) . getResponseEntryCode ( ) . equals ( " RUNTIME_EXCEPTION " ) ) {
MessageBox . alert ( " Delete VME Report Operation Failed " , " Report Delete has failed for the following reason: <br/> " + response . getResponseMessageList ( ) . get ( 0 ) . getResponseMessage ( ) , null ) ;
2014-01-29 17:34:57 +01:00
}
2014-05-15 15:27:25 +02:00
//user report compile exception
else {
String failReasons = " " ;
for ( VmeResponseEntry entry : response . getResponseMessageList ( ) ) {
failReasons + = entry . getResponseMessage ( ) + " <br/> " ;
}
MessageBox . alert ( " Deleting Operation Failed " , " Report Deletion has failed for the following reasons: <br/> " + failReasons , null ) ;
}
newDoc ( ) ;
2014-01-29 17:34:57 +01:00
}
2014-05-15 15:27:25 +02:00
} ) ;
}
2014-01-29 17:34:57 +01:00
}
2014-01-28 17:31:13 +01:00
2014-05-15 15:27:25 +02:00
private void importVMEReport ( String reportId , String name , final VMETypeIdentifier type ) {
2014-01-28 17:31:13 +01:00
showLoading ( ) ;
2014-05-15 15:27:25 +02:00
reportService . importVMEReport ( reportId , name , type , new AsyncCallback < Model > ( ) {
2014-01-28 17:31:13 +01:00
@Override
public void onFailure ( Throwable caught ) {
2014-05-15 15:27:25 +02:00
Window . alert ( " Could not Load Report Model, error on server.: " + caught . getMessage ( ) ) ;
2014-01-28 17:31:13 +01:00
}
@Override
2014-05-15 15:27:25 +02:00
public void onSuccess ( Model toLoad ) {
if ( toLoad ! = null ) {
loadModel ( toLoad , type = = VMETypeIdentifier . Vme ) ;
currentVmeType = type ;
2014-01-28 17:31:13 +01:00
}
2014-05-15 15:27:25 +02:00
else
Window . alert ( " Could not Load Report Model, error on server. " ) ;
2014-01-28 17:31:13 +01:00
}
} ) ;
}
2014-05-15 15:27:25 +02:00
private void associateVMEReportRef ( VMETypeIdentifier type , String reportId ) throws Exception {
GWT . log ( " Type= " + type ) ;
GWT . log ( " Id " + reportId ) ;
reportService . getVMEReportRef2Associate ( reportId , type , new AsyncCallback < Model > ( ) {
2013-11-13 18:56:13 +01:00
2014-05-15 15:27:25 +02:00
@Override
public void onFailure ( Throwable caught ) {
Window . alert ( " Could not Load Report Model, error on server.: " + caught . getMessage ( ) ) ;
2013-12-06 18:23:49 +01:00
}
2013-11-14 16:26:26 +01:00
2014-05-15 15:27:25 +02:00
@Override
public void onSuccess ( Model reportRef ) {
if ( reportRef ! = null & & reportRef . getSections ( ) . size ( ) > 0 ) {
//the Repeatable Seq must be in the 1st Section, second component. (because ReportsModeler put it there)
BasicSection firstSection = reportRef . getSections ( ) . get ( 0 ) ;
if ( firstSection . getComponents ( ) ! = null & & firstSection . getComponents ( ) . size ( ) = = 2 ) {
ReportReferences toPass = ( ReportReferences ) firstSection . getComponents ( ) . get ( 1 ) . getPossibleContent ( ) ;
GWT . log ( " Singola? " + toPass . isSingleRelation ( ) ) ;
String refKey = toPass . getTuples ( ) . get ( 0 ) . getKey ( ) ;
Tuple ref = toPass . getTuples ( ) . get ( 0 ) ;
clientSeqSelected . add ( refKey , ref , toPass . isSingleRelation ( ) ) ;
}
else {
Window . alert ( " Sorry, we could not locate the ReportRef correctly in the model instance " ) ;
}
2013-11-14 16:26:26 +01:00
}
2014-05-15 15:27:25 +02:00
else
Window . alert ( " Could not Load Report Model, error on server. " ) ;
2013-11-14 16:26:26 +01:00
}
2014-05-15 15:27:25 +02:00
} ) ;
}
2013-11-14 16:26:26 +01:00
2014-05-15 15:27:25 +02:00
/ * *
* this method translate the VME ReportRef String in an ENUM
* @param theType
* @return
* @throws Exception
* /
public VMETypeIdentifier getTypeIdFromString ( String theType ) throws Exception {
if ( theType . equals ( " GeneralMeasure " ) )
return VMETypeIdentifier . GeneralMeasure ;
else if ( theType . equals ( " InformationSource " ) )
return VMETypeIdentifier . InformationSource ;
else if ( theType . equals ( " FisheryAreasHistory " ) )
return VMETypeIdentifier . FisheryAreasHistory ;
else if ( theType . equals ( " VMEsHistory " ) )
return VMETypeIdentifier . VMEsHistory ;
else if ( theType . equals ( " Rfmo " ) )
return VMETypeIdentifier . Rfmo ;
throw new Exception ( " Could not find any valid Report Ref, got " + theType + " should be any of " + VMETypeIdentifier . values ( ) . toString ( ) ) ;
}
2013-11-13 18:56:13 +01:00
}