2013-02-06 23:25:43 +01:00
package org.gcube.portlets.user.reportgenerator.client ;
import java.util.List ;
import org.gcube.portlets.d4sreporting.common.shared.Metadata ;
import org.gcube.portlets.user.gcubewidgets.client.popup.GCubeDialog ;
import org.gcube.portlets.user.reportgenerator.client.Presenter.CommonCommands ;
import org.gcube.portlets.user.reportgenerator.client.Presenter.Presenter ;
import org.gcube.portlets.user.reportgenerator.client.dialog.ImporterDialog ;
import org.gcube.portlets.user.reportgenerator.client.dialog.PagePropertiesDialog ;
import org.gcube.portlets.user.reportgenerator.client.model.ExportManifestationType ;
import org.gcube.portlets.user.reportgenerator.client.model.TemplateModel ;
2013-11-25 19:11:03 +01:00
import org.gcube.portlets.user.reportgenerator.shared.VMETypeIdentifier ;
2013-10-09 14:21:50 +02:00
import org.gcube.portlets.widgets.lighttree.client.ItemType ;
import org.gcube.portlets.widgets.lighttree.client.event.PopupEvent ;
import org.gcube.portlets.widgets.lighttree.client.event.PopupHandler ;
import org.gcube.portlets.widgets.lighttree.client.load.WorkspaceLightTreeLoadPopup ;
2013-02-06 23:25:43 +01:00
import com.extjs.gxt.ui.client.widget.MessageBox ;
import com.google.gwt.core.client.GWT ;
import com.google.gwt.core.client.RunAsyncCallback ;
2013-11-22 18:28:12 +01:00
import com.google.gwt.core.client.Scheduler.ScheduledCommand ;
2013-11-26 18:37:13 +01:00
import com.google.gwt.dom.client.Style.WhiteSpace ;
2013-02-06 23:25:43 +01:00
import com.google.gwt.user.client.Command ;
import com.google.gwt.user.client.Window ;
import com.google.gwt.user.client.ui.CellPanel ;
import com.google.gwt.user.client.ui.Composite ;
import com.google.gwt.user.client.ui.Grid ;
import com.google.gwt.user.client.ui.HTML ;
import com.google.gwt.user.client.ui.HasHorizontalAlignment ;
import com.google.gwt.user.client.ui.HasVerticalAlignment ;
import com.google.gwt.user.client.ui.HorizontalPanel ;
import com.google.gwt.user.client.ui.MenuBar ;
import com.google.gwt.user.client.ui.MenuItem ;
import com.google.gwt.user.client.ui.MenuItemSeparator ;
import com.google.gwt.user.client.ui.RichTextArea ;
/ * *
* < code > Headerbar < / code > class is the top bar component of the UI
*
* @author Massimiliano Assante , ISTI - CNR - massimiliano . assante @isti.cnr.it
* /
public class Headerbar extends Composite {
private static final String ADD_BIBLIO_ENTRY = " Add citation " ;
private static final String VIEW_BIBLIO = " View Bibliography " ;
private static final String MANAGE_BIBLIO = " Delete citation(s) " ;
private static final String EXPORT_OPENXML = " Export to OpenXML (docx) " ;
private static final String EXPORT_HTML = " Export to HTML " ;
private static final String EXPORT_FIMES = " Export to FiMES XML " ;
2013-03-13 12:10:23 +01:00
private static final String EXPORT_XML = " Export to XML " ;
2013-12-18 00:47:35 +01:00
private static final String IMPORT_VME = " Edit VME " ;
2013-11-13 18:56:13 +01:00
// private static final String EXPORT_ENCRYPTED_REPORT = "Save an Encrypted Version to Desktop";
2013-03-13 12:10:23 +01:00
2013-02-06 23:25:43 +01:00
private static final String VIEW_USER_COMMENTS = " View user comments " ;
String location ;
2013-03-13 19:22:15 +01:00
private Presenter presenter ;
2013-02-06 23:25:43 +01:00
/ * *
* the template Model
* /
private TemplateModel templateModel ;
/ * *
* mainLayout Panel
* /
private CellPanel mainLayout = new HorizontalPanel ( ) ;
//private MenuItem optionPDF;
private MenuItem importModel ;
private MenuItem addBiblioEntry ;
private MenuItem viewBiblio ;
private MenuItem manageBiblio ;
private MenuItem optionHTML ;
private MenuItem optionDOCX ;
2013-03-06 15:30:36 +01:00
private MenuItem optionPDF ;
2013-02-06 23:25:43 +01:00
private MenuItem optionFimes ;
2013-03-13 11:47:15 +01:00
2013-03-13 12:10:23 +01:00
private MenuItem optionXML ;
2013-03-13 11:47:15 +01:00
private MenuItem optionEncryptedModel ;
2013-02-06 23:25:43 +01:00
private MenuItem viewMetadata ;
private MenuItem viewComments ;
private MenuItem discardSection ;
2013-11-13 18:56:13 +01:00
private MenuItem importVME ;
2013-11-25 19:11:03 +01:00
private MenuItem importVMERef ;
2013-02-06 23:25:43 +01:00
MenuBar menuBar = new MenuBar ( ) ;
MenuItem fileMenu ;
MenuItem viewMenu ;
MenuItem sectionsMenu ;
MenuItem biblioMenu ;
MenuItem exportMenu ;
2013-11-26 18:37:13 +01:00
MenuItem vmeMenu ;
2013-02-06 23:25:43 +01:00
MenuItemSeparator separator1 ;
MenuItemSeparator separator2 ;
MenuItemSeparator separator3 ;
MenuItemSeparator separator4 ;
/ * *
* Constructor
* @param c the controller instance for this UI component
* /
public Headerbar ( Presenter c ) {
this . presenter = c ;
this . templateModel = presenter . getModel ( ) ;
menuBar . setAutoOpen ( false ) ;
// menuBar.setWidth("100px");
menuBar . setAnimationEnabled ( true ) ;
fileMenu = getFileMenu ( ) ;
menuBar . addItem ( fileMenu ) ;
separator1 = menuBar . addSeparator ( ) ;
viewMenu = getViewMenu ( ) ;
menuBar . addItem ( viewMenu ) ;
2013-12-18 00:47:35 +01:00
separator2 = menuBar . addSeparator ( ) ;
sectionsMenu = getSectionMenu ( ) ;
menuBar . addItem ( sectionsMenu ) ;
separator3 = menuBar . addSeparator ( ) ;
biblioMenu = getBiblioMenu ( ) ;
menuBar . addItem ( biblioMenu ) ;
2013-02-06 23:25:43 +01:00
separator4 = menuBar . addSeparator ( ) ;
exportMenu = getExportsMenu ( ) ;
menuBar . addItem ( exportMenu ) ;
2013-12-12 16:39:48 +01:00
2013-11-26 18:37:13 +01:00
2013-02-06 23:25:43 +01:00
mainLayout . setSize ( " 100% " , " 24px " ) ;
mainLayout . setStyleName ( " menubar " ) ;
mainLayout . add ( menuBar ) ;
//design the part for the template name and the pages handling
HorizontalPanel captionPanel = new HorizontalPanel ( ) ;
captionPanel . setWidth ( " 100% " ) ;
HorizontalPanel pageHandlerPanel = new HorizontalPanel ( ) ;
pageHandlerPanel . setHeight ( " 24 " ) ;
pageHandlerPanel . setVerticalAlignment ( HasVerticalAlignment . ALIGN_MIDDLE ) ;
captionPanel . setHorizontalAlignment ( HasHorizontalAlignment . ALIGN_CENTER ) ;
mainLayout . add ( captionPanel ) ;
mainLayout . add ( pageHandlerPanel ) ;
mainLayout . setCellHorizontalAlignment ( menuBar , HasHorizontalAlignment . ALIGN_LEFT ) ;
mainLayout . setCellHorizontalAlignment ( captionPanel , HasHorizontalAlignment . ALIGN_LEFT ) ;
mainLayout . setCellWidth ( menuBar , " 200 " ) ;
mainLayout . setCellWidth ( pageHandlerPanel , " 200 " ) ;
initWidget ( mainLayout ) ;
}
2013-12-18 00:47:35 +01:00
public void setMenuForVME ( ) {
menuBar . removeItem ( viewMenu ) ;
menuBar . removeItem ( sectionsMenu ) ;
menuBar . removeItem ( biblioMenu ) ;
menuBar . removeSeparator ( separator1 ) ;
menuBar . removeSeparator ( separator2 ) ;
menuBar . removeSeparator ( separator3 ) ;
menuBar . removeItem ( exportMenu ) ;
vmeMenu = getVMEMenuEdit ( ) ;
menuBar . addItem ( vmeMenu ) ;
menuBar . addSeparator ( ) ;
2013-12-18 16:30:32 +01:00
MenuItem vmeMenuCreate = getVMEMenuCreate ( ) ;
2013-12-18 00:47:35 +01:00
menuBar . addItem ( vmeMenuCreate ) ;
separator4 = menuBar . addSeparator ( ) ;
2014-01-28 17:31:13 +01:00
MenuItem vmeMenuDelete = getVMEMenuDelete ( ) ;
2013-12-18 00:47:35 +01:00
menuBar . addItem ( vmeMenuDelete ) ;
menuBar . addSeparator ( ) ;
exportMenu = getExportsMenu ( ) ;
menuBar . addItem ( exportMenu ) ;
}
2013-02-06 23:25:43 +01:00
public void setMenuForWorkflowDocument ( boolean canUpdate ) {
presenter . setMenuForWorkflowDocument ( true ) ;
menuBar . removeItem ( fileMenu ) ;
menuBar . removeItem ( viewMenu ) ;
menuBar . removeItem ( sectionsMenu ) ;
menuBar . removeItem ( biblioMenu ) ;
menuBar . removeSeparator ( separator1 ) ;
menuBar . removeSeparator ( separator2 ) ;
menuBar . removeItem ( exportMenu ) ;
MenuBar workflowMenu = new MenuBar ( true ) ;
workflowMenu . setAnimationEnabled ( true ) ;
MenuItem menu = new MenuItem ( " <nobr>Workflow Document Options</nobr> " , true , workflowMenu ) ;
menu . setWidth ( " 400px " ) ;
Command updateWfDocument = new Command ( ) {
public void execute ( ) {
presenter . updateWorkflowDocument ( true ) ;
}
} ;
Command backCommand = new Command ( ) {
public void execute ( ) {
presenter . updateWorkflowDocument ( false ) ;
}
} ;
2013-04-30 16:16:20 +02:00
2013-02-06 23:25:43 +01:00
if ( canUpdate )
workflowMenu . addItem ( " Update this document " , updateWfDocument ) ;
//workflowMenu.addItem("Show previous changes", showChanges);
workflowMenu . addSeparator ( ) ;
workflowMenu . addItem ( " Back to My Workflow Documents " , backCommand ) ;
menuBar . addItem ( menu ) ;
separator1 = menuBar . addSeparator ( ) ;
viewMenu = getViewMenu ( ) ;
menuBar . addItem ( viewMenu ) ;
separator2 = menuBar . addSeparator ( ) ;
sectionsMenu = getSectionMenu ( ) ;
menuBar . addItem ( sectionsMenu ) ;
separator3 = menuBar . addSeparator ( ) ;
biblioMenu = getBiblioMenu ( ) ;
menuBar . addItem ( biblioMenu ) ;
separator4 = menuBar . addSeparator ( ) ;
exportMenu = getExportsMenu ( ) ;
menuBar . addItem ( exportMenu ) ;
2013-11-13 18:56:13 +01:00
2013-02-06 23:25:43 +01:00
ReportGenerator . get ( ) . getToolbarPanel ( ) . clear ( ) ;
ReportGenerator . get ( ) . getToolbarPanel ( ) . add ( new HTML ( " " , true ) ) ;
enableExports ( ) ;
}
/ * *
* 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.Headerbar : : location = $wnd . location . href ;
} - * / ;
/ * *
* temporary command
* @return the command instance
* /
public Command getNullCommand ( ) {
Command openNothing = new Command ( ) {
2013-03-08 15:19:51 +01:00
public void execute ( ) {
}
} ;
return openNothing ;
}
public Command getDisabledExportMenuItemCmd ( ) {
Command disabledExportMenuItemCmd = new Command ( ) {
2013-03-07 12:00:21 +01:00
public void execute ( ) {
MessageBox . alert ( " Alert " ,
2013-03-08 15:19:51 +01:00
" Export is disabled for templates, please save this template as a Report and retry. " +
" If you just saved this Template as a Report please save it and reopen the Report " , null ) ;
2013-03-07 12:00:21 +01:00
}
2013-02-06 23:25:43 +01:00
} ;
2013-03-08 15:19:51 +01:00
return disabledExportMenuItemCmd ;
2013-02-06 23:25:43 +01:00
}
/ * *
* temporary command
* @return the command instance
* /
public Command getBiblioCommand ( ) {
Command openNothing = new Command ( ) {
public void execute ( ) {
MessageBox . alert ( " Warning " , " A textarea must be selected to add an entry " , null ) ;
}
} ;
return openNothing ;
}
Command addCitationCmd = new Command ( ) {
public void execute ( ) {
presenter . openAddCitationDialog ( ) ;
}
} ;
Command viewBiblioCmd = new Command ( ) {
public void execute ( ) {
if ( presenter . hasBibliography ( ) ) {
presenter . seekLastPage ( ) ;
}
else {
MessageBox . alert ( " Warning " , " No bibliography found, to add bibliography start adding citations:<br />Bibliography > Add citation (from within a text area) " , null ) ;
}
}
} ;
Command manageBiblioCmd = new Command ( ) {
public void execute ( ) {
if ( presenter . hasBibliography ( ) ) {
presenter . openManageCitationsDialog ( ) ;
}
else {
MessageBox . alert ( " Warning " , " No bibliography found, to add bibliography start adding citations:<br />Bibliography > Add citation (from within a text area) " , null ) ;
}
}
} ;
2013-11-26 18:37:13 +01:00
2014-01-28 17:31:13 +01:00
private MenuItem getVMEMenuDelete ( ) {
2013-12-18 00:47:35 +01:00
MenuBar createMenu = new MenuBar ( true ) ;
createMenu . setAnimationEnabled ( true ) ;
2014-01-28 17:31:13 +01:00
MenuItem toReturn = new MenuItem ( " Delete VME-DB " , createMenu ) ;
2013-12-18 00:47:35 +01:00
toReturn . getElement ( ) . getStyle ( ) . setWhiteSpace ( WhiteSpace . NOWRAP ) ;
2014-01-28 17:31:13 +01:00
MenuItem item = new MenuItem ( " Delete VME " , true , new Command ( ) {
public void execute ( ) {
presenter . showVMEDeleteDialog ( VMETypeIdentifier . Vme ) ;
}
} ) ;
2013-12-18 00:47:35 +01:00
createMenu . addItem ( item ) ;
createMenu . addSeparator ( ) ;
2014-01-28 17:31:13 +01:00
item = new MenuItem ( " Delete VME General Measure " , true , new Command ( ) {
public void execute ( ) {
presenter . showVMEDeleteDialog ( VMETypeIdentifier . GeneralMeasure ) ;
}
} ) ;
2013-12-18 00:47:35 +01:00
createMenu . addItem ( item ) ;
2014-01-28 17:31:13 +01:00
item = new MenuItem ( " Delete Information Source " , true , new Command ( ) {
public void execute ( ) {
presenter . showVMEDeleteDialog ( VMETypeIdentifier . InformationSource ) ;
}
} ) ;
2013-12-18 00:47:35 +01:00
createMenu . addItem ( item ) ;
2014-01-28 17:31:13 +01:00
item = new MenuItem ( " Delete Fishing footprint " , true , new Command ( ) {
public void execute ( ) {
presenter . showVMEDeleteDialog ( VMETypeIdentifier . FisheryAreasHistory ) ;
}
} ) ;
2013-12-18 00:47:35 +01:00
createMenu . addItem ( item ) ;
2014-01-28 17:31:13 +01:00
item = new MenuItem ( " Delete Regional History of VMEs " , true , new Command ( ) {
public void execute ( ) {
presenter . showVMEDeleteDialog ( VMETypeIdentifier . VMEsHistory ) ;
}
} ) ;
2013-12-18 00:47:35 +01:00
createMenu . addItem ( item ) ;
return toReturn ;
}
private MenuItem getVMEMenuEdit ( ) {
2013-11-26 18:37:13 +01:00
MenuBar importMenu = new MenuBar ( true ) ;
importMenu . setAnimationEnabled ( true ) ;
2013-12-18 00:47:35 +01:00
MenuItem toReturn = new MenuItem ( " Edit VME-DB " , importMenu ) ;
2013-11-26 18:37:13 +01:00
toReturn . getElement ( ) . getStyle ( ) . setWhiteSpace ( WhiteSpace . NOWRAP ) ;
Command importVMEReport = new Command ( ) {
public void execute ( ) {
presenter . showVMEImportDialog ( ) ;
}
} ;
importVME = new MenuItem ( IMPORT_VME , true , importVMEReport ) ;
importMenu . addItem ( importVME ) ;
importMenu . addSeparator ( ) ;
2013-12-12 16:39:48 +01:00
MenuItem item = new MenuItem ( " Edit VME General Measures " , true , new Command ( ) {
public void execute ( ) {
presenter . showVMEReportRefImportDialog ( VMETypeIdentifier . GeneralMeasure ) ;
2013-11-26 18:37:13 +01:00
}
2013-12-12 16:39:48 +01:00
} ) ;
importMenu . addItem ( item ) ;
item = new MenuItem ( " Edit Information Sources " , true , new Command ( ) {
public void execute ( ) {
presenter . showVMEReportRefImportDialog ( VMETypeIdentifier . InformationSource ) ;
}
} ) ;
importMenu . addItem ( item ) ;
item = new MenuItem ( " Edit Fishing footprint " , true , new Command ( ) {
public void execute ( ) {
presenter . showVMEReportRefImportDialog ( VMETypeIdentifier . FisheryAreasHistory ) ;
}
} ) ;
importMenu . addItem ( item ) ;
item = new MenuItem ( " Edit Regional History of VMEs " , true , new Command ( ) {
public void execute ( ) {
presenter . showVMEReportRefImportDialog ( VMETypeIdentifier . VMEsHistory ) ;
}
} ) ;
importMenu . addItem ( item ) ;
// item = new MenuItem("Edit Rfmo", true, new Command() {
// public void execute() {
// presenter.showVMEReportRefImportDialog(VMETypeIdentifier.Rfmo);
// }
// });
// importMenu.addItem(item);
2013-12-17 19:19:51 +01:00
//
// importMenu.addSeparator();
// MenuItem exportVME = new MenuItem("Export Current to VME-DB", true, importVMEReport);
// importMenu.addItem(exportVME);
2013-11-26 18:37:13 +01:00
return toReturn ;
}
2013-12-18 16:30:32 +01:00
private MenuItem getVMEMenuCreate ( ) {
MenuBar importMenu = new MenuBar ( true ) ;
importMenu . setAnimationEnabled ( true ) ;
MenuItem toReturn = new MenuItem ( " Create VME-DB " , importMenu ) ;
toReturn . getElement ( ) . getStyle ( ) . setWhiteSpace ( WhiteSpace . NOWRAP ) ;
MenuItem item = new MenuItem ( " Create new VME " , true , new Command ( ) {
public void execute ( ) {
presenter . importVMETemplate ( VMETypeIdentifier . Vme ) ;
}
} ) ;
importMenu . addItem ( item ) ;
importMenu . addSeparator ( ) ;
item = new MenuItem ( " Create new General Measure " , true , new Command ( ) {
public void execute ( ) {
presenter . importVMETemplate ( VMETypeIdentifier . GeneralMeasure ) ;
}
} ) ;
importMenu . addItem ( item ) ;
item = new MenuItem ( " Create new Information Source " , true , new Command ( ) {
public void execute ( ) {
presenter . importVMETemplate ( VMETypeIdentifier . InformationSource ) ;
}
} ) ;
importMenu . addItem ( item ) ;
item = new MenuItem ( " Create new Fishing footprint " , true , new Command ( ) {
public void execute ( ) {
presenter . importVMETemplate ( VMETypeIdentifier . FisheryAreasHistory ) ;
}
} ) ;
importMenu . addItem ( item ) ;
item = new MenuItem ( " Create new Regional History of VMEs " , true , new Command ( ) {
public void execute ( ) {
presenter . importVMETemplate ( VMETypeIdentifier . VMEsHistory ) ;
}
} ) ;
importMenu . addItem ( item ) ;
return toReturn ;
}
2013-02-06 23:25:43 +01:00
/ * *
*
* @return
* /
private MenuItem getBiblioMenu ( ) {
// Create the Options menu
MenuBar biblioMenu = new MenuBar ( true ) ;
MenuItem toReturn = new MenuItem ( " Bibliography " , biblioMenu ) ;
biblioMenu . setAnimationEnabled ( true ) ;
addBiblioEntry = new MenuItem ( " <font color= \" gray \" > " + ADD_BIBLIO_ENTRY + " </font> " , true , getBiblioCommand ( ) ) ;
biblioMenu . addItem ( addBiblioEntry ) ;
viewBiblio = new MenuItem ( VIEW_BIBLIO , true , viewBiblioCmd ) ;
manageBiblio = new MenuItem ( MANAGE_BIBLIO , true , manageBiblioCmd ) ;
biblioMenu . addSeparator ( ) ;
biblioMenu . addItem ( manageBiblio ) ;
biblioMenu . addItem ( viewBiblio ) ;
return toReturn ;
}
/ * *
*
* @return
* /
private MenuItem getSectionMenu ( ) {
// Create the Options menu
MenuBar insertsMenu = new MenuBar ( true ) ;
MenuItem toReturn = new MenuItem ( " Section " , insertsMenu ) ;
insertsMenu . setAnimationEnabled ( true ) ;
importModel = new MenuItem ( " <font color= \" gray \" >Import from Template or Report</font> " , true , getNullCommand ( ) ) ;
insertsMenu . addItem ( importModel ) ;
viewMetadata = new MenuItem ( " <font color= \" gray \" >View Metadata</font> " , true , getNullCommand ( ) ) ;
discardSection = new MenuItem ( " <font color= \" gray \" >Discard current</font> " , true , getNullCommand ( ) ) ;
viewComments = new MenuItem ( " <font color= \" gray \" > " + VIEW_USER_COMMENTS + " </font> " , true , getNullCommand ( ) ) ;
insertsMenu . addItem ( discardSection ) ;
insertsMenu . addSeparator ( ) ;
insertsMenu . addItem ( viewMetadata ) ;
insertsMenu . addItem ( viewComments ) ;
return toReturn ;
}
private MenuItem getExportsMenu ( ) {
MenuBar exportsMenu = new MenuBar ( true ) ;
exportsMenu . setAnimationEnabled ( true ) ;
MenuItem toReturn = new MenuItem ( " Export " , exportsMenu ) ;
2013-03-08 15:19:51 +01:00
optionDOCX = new MenuItem ( " <font color= \" gray \" > " + EXPORT_OPENXML + " </font> " , true , getDisabledExportMenuItemCmd ( ) ) ;
optionPDF = new MenuItem ( " <font color= \" gray \" >Export to PDF</font> " , true , getDisabledExportMenuItemCmd ( ) ) ;
optionHTML = new MenuItem ( " <font color= \" gray \" > " + EXPORT_HTML + " </font> " , true , getDisabledExportMenuItemCmd ( ) ) ;
optionFimes = new MenuItem ( " <font color= \" gray \" > " + EXPORT_FIMES + " </font> " , true , getDisabledExportMenuItemCmd ( ) ) ;
2013-03-13 12:10:23 +01:00
optionXML = new MenuItem ( " <font color= \" gray \" > " + EXPORT_XML + " </font> " , true , getDisabledExportMenuItemCmd ( ) ) ;
2013-11-13 18:56:13 +01:00
// optionEncryptedModel = new MenuItem("<font color=\"gray\">"+ EXPORT_ENCRYPTED_REPORT +"</font>", true, getDisabledExportMenuItemCmd());
2013-03-13 11:47:15 +01:00
2013-02-06 23:25:43 +01:00
exportsMenu . addItem ( optionDOCX ) ;
exportsMenu . addItem ( optionHTML ) ;
2013-03-06 15:30:36 +01:00
exportsMenu . addItem ( optionPDF ) ;
2013-03-13 12:10:23 +01:00
exportsMenu . addItem ( optionXML ) ;
2013-03-14 18:57:06 +01:00
exportsMenu . addSeparator ( ) ;
2013-11-13 18:56:13 +01:00
// exportsMenu.addItem(optionEncryptedModel);
2013-02-06 23:25:43 +01:00
//optionsMenu.addItem(optionPDF);
//exportsMenu.addItem(optionFimes);
return toReturn ;
}
private MenuItem getViewMenu ( ) {
Command openPageProperties = new Command ( ) {
public void execute ( ) {
int left = mainLayout . getAbsoluteLeft ( ) + 50 ;
int top = mainLayout . getAbsoluteTop ( ) + 25 ;
PagePropertiesDialog dlg = new PagePropertiesDialog ( templateModel , presenter ) ;
dlg . setPopupPosition ( left , top ) ;
dlg . setAnimationEnabled ( true ) ;
dlg . show ( ) ;
}
} ;
Command showReportStructure = new Command ( ) {
2013-03-15 11:37:45 +01:00
public void execute ( ) {
2013-12-18 17:33:25 +01:00
presenter . toggleReportStructure ( ) ;
2013-02-06 23:25:43 +01:00
}
} ;
2013-11-13 18:56:13 +01:00
2013-02-06 23:25:43 +01:00
// Create the Options menu
MenuBar optionsMenu = new MenuBar ( true ) ;
optionsMenu . setAnimationEnabled ( true ) ;
MenuItem toReturn = new MenuItem ( " View " , optionsMenu ) ;
optionsMenu . addItem ( " View Properties " , openPageProperties ) ;
2013-12-18 17:33:25 +01:00
optionsMenu . addItem ( " View/Hide Structure " , showReportStructure ) ;
2013-02-06 23:25:43 +01:00
optionsMenu . addSeparator ( ) ;
return toReturn ;
}
/ * *
* rewrite with setHTML to remove the gray color
* /
public void enableExports ( ) {
optionDOCX . setHTML ( EXPORT_OPENXML ) ;
2013-11-22 18:28:12 +01:00
optionDOCX . setScheduledCommand ( generateDOCX ) ;
2013-02-06 23:25:43 +01:00
2013-03-07 12:00:21 +01:00
optionPDF . setHTML ( " Export to PDF " ) ;
2013-11-22 18:28:12 +01:00
optionPDF . setScheduledCommand ( generatePDF ) ;
2013-02-06 23:25:43 +01:00
optionHTML . setHTML ( EXPORT_HTML ) ;
2013-11-22 18:28:12 +01:00
optionHTML . setScheduledCommand ( generateHTML ) ;
2013-02-06 23:25:43 +01:00
optionFimes . setHTML ( EXPORT_FIMES ) ;
2013-11-22 18:28:12 +01:00
optionFimes . setScheduledCommand ( generateFimes ) ;
2013-03-13 11:47:15 +01:00
2013-03-13 12:10:23 +01:00
optionXML . setHTML ( EXPORT_XML ) ;
2013-11-22 18:28:12 +01:00
optionXML . setScheduledCommand ( generatedXML ) ;
2013-03-13 12:10:23 +01:00
2013-11-13 18:56:13 +01:00
// optionEncryptedModel.setHTML(EXPORT_ENCRYPTED_REPORT);
2013-11-22 18:28:12 +01:00
2013-02-06 23:25:43 +01:00
//
2013-11-27 14:51:58 +01:00
// importModel.setHTML("Import from Template or Report");
// importModel.setScheduledCommand(importModelOrReport);
//
// viewMetadata.setHTML("View Metadata");
// viewMetadata.setScheduledCommand(openMetadata);
2013-02-06 23:25:43 +01:00
2013-11-25 17:12:01 +01:00
// discardSection.setHTML("Discard current");
// discardSection.setScheduledCommand(discardSectionCom);
2013-02-06 23:25:43 +01:00
}
2013-11-25 17:12:01 +01:00
2013-02-06 23:25:43 +01:00
/ * *
* rewrite with setHTML to remove the gray color
* @param d4sArea
* /
public void enableBiblioEntry ( RichTextArea d4sArea ) {
addBiblioEntry . setHTML ( ADD_BIBLIO_ENTRY ) ;
2013-11-22 18:28:12 +01:00
addBiblioEntry . setScheduledCommand ( addBiblioEntryCommand ) ;
2013-02-06 23:25:43 +01:00
presenter . setAreaForBiblio ( d4sArea ) ;
}
/ * *
* build the File Menu
* @return
* /
private MenuItem getFileMenu ( ) {
2013-04-30 16:16:20 +02:00
CommonCommands cmd = new CommonCommands ( presenter ) ;
2013-02-06 23:25:43 +01:00
Command openHelp = new Command ( ) {
public void execute ( ) {
if ( ! ReportConstants . isDeployed ) {
presenter . openTemplate ( " " , " " , true ) ;
enableExports ( ) ;
}
else {
String url = " https://gcube.wiki.gcube-system.org/gcube/index.php/Common_Functionality#Report_Management " ;
int width = Window . getClientWidth ( ) ;
int height = Window . getClientHeight ( ) ;
int winWidth = ( int ) ( Window . getClientWidth ( ) * 0 . 8 ) ;
int winHeight = ( int ) ( Window . getClientHeight ( ) * 0 . 7 ) ;
int left = ( width - winWidth ) / 2 ;
int top = ( height - winHeight ) / 2 ;
Window . open ( url , null , " left= " + left + " top " + top + " , width= " + winWidth + " , height= " + winHeight + " , resizable=yes, scrollbars=yes, status=yes " ) ;
}
}
} ;
2013-04-30 16:16:20 +02:00
2013-02-06 23:25:43 +01:00
Command saveReportAs = new Command ( ) {
public void execute ( ) {
CommonCommands cmd = new CommonCommands ( presenter ) ;
cmd . saveReportAsDialog ( ) ;
}
} ;
Command saveReport = new Command ( ) {
public void execute ( ) {
if ( templateModel . getTemplateName ( ) . endsWith ( " d4sR " ) )
presenter . saveReport ( ) ;
else {
CommonCommands cmd = new CommonCommands ( presenter ) ;
cmd . saveReportAsDialog ( ) ;
}
}
} ;
2013-03-15 14:19:27 +01:00
2013-02-06 23:25:43 +01:00
// Create the file menu
MenuBar fileMenu = new MenuBar ( true ) ;
fileMenu . setAnimationEnabled ( true ) ;
MenuItem toReturn = new MenuItem ( " File " , fileMenu ) ;
2013-12-18 00:47:35 +01:00
fileMenu . addItem ( " Open Report from Workspace " , cmd . openReport ) ;
//fileMenu.addItem("Open template...", cmd.openTemplate);
2013-02-06 23:25:43 +01:00
fileMenu . addSeparator ( ) ;
fileMenu . addItem ( " Save " , saveReport ) ;
fileMenu . addItem ( " Save As .. " , saveReportAs ) ;
fileMenu . addSeparator ( ) ;
// fileMenu.addItem("Import from FiMES XML", importFimes);
2013-04-30 16:16:20 +02:00
fileMenu . addItem ( " Close Report " , cmd . newTemplate ) ;
2013-02-06 23:25:43 +01:00
fileMenu . addSeparator ( ) ;
2013-12-18 00:47:35 +01:00
// fileMenu.addItem("? Open User's Guide", openHelp);
2013-02-06 23:25:43 +01:00
return toReturn ;
}
/ * *
*
* @param model .
* /
public void setModel ( TemplateModel model ) {
this . templateModel = model ;
}
//************** COMMANDS ********************************////
2013-11-22 18:28:12 +01:00
ScheduledCommand generateFimes = new ScheduledCommand ( ) {
2013-02-06 23:25:43 +01:00
public void execute ( ) {
presenter . generateFiMES ( templateModel ) ;
}
} ;
2013-11-22 18:28:12 +01:00
ScheduledCommand generateDOCX = new ScheduledCommand ( ) {
2013-02-06 23:25:43 +01:00
public void execute ( ) {
presenter . generateManifestation ( templateModel , ExportManifestationType . DOCX ) ;
}
} ;
2013-11-22 18:28:12 +01:00
ScheduledCommand generatePDF = new ScheduledCommand ( ) {
2013-02-06 23:25:43 +01:00
public void execute ( ) {
2013-03-06 15:30:36 +01:00
// Window.alert("PDF Exporting may not be fully working, you can also generate a PDF using your Word Processor application starting from the docx exported file");
2013-02-06 23:25:43 +01:00
presenter . generateManifestation ( templateModel , ExportManifestationType . PDF ) ;
}
} ;
2013-11-22 18:28:12 +01:00
ScheduledCommand generateHTML = new ScheduledCommand ( ) {
2013-02-06 23:25:43 +01:00
public void execute ( ) {
presenter . generateManifestation ( templateModel , ExportManifestationType . HTML ) ;
}
} ;
2013-03-13 11:47:15 +01:00
2013-11-22 18:28:12 +01:00
ScheduledCommand generatedXML = new ScheduledCommand ( ) {
2013-03-13 12:10:23 +01:00
public void execute ( ) {
presenter . generateManifestation ( templateModel , ExportManifestationType . XML ) ;
}
} ;
2013-11-22 18:28:12 +01:00
ScheduledCommand generateEncryptedModel = new ScheduledCommand ( ) {
2013-03-13 11:47:15 +01:00
@Override
2013-03-15 11:37:45 +01:00
public void execute ( ) {
2013-03-13 11:47:15 +01:00
GWT . runAsync ( WorkspaceLightTreeLoadPopup . class , new RunAsyncCallback ( ) {
public void onSuccess ( ) {
2013-11-22 18:28:12 +01:00
WorkspaceLightTreeLoadPopup wpTreepopup = new WorkspaceLightTreeLoadPopup ( " Select the Report (or Template) to encrypt " , true , true ) ;
2013-03-14 18:53:52 +01:00
wpTreepopup . setShowableTypes ( ItemType . REPORT_TEMPLATE , ItemType . REPORT ) ;
wpTreepopup . setSelectableTypes ( ItemType . REPORT_TEMPLATE , ItemType . REPORT ) ;
2013-03-13 11:47:15 +01:00
wpTreepopup . addPopupHandler ( new PopupHandler ( ) {
public void onPopup ( PopupEvent event ) {
if ( ! event . isCanceled ( ) ) {
if ( event . getSelectedItem ( ) ! = null ) {
final String itemId = event . getSelectedItem ( ) . getId ( ) ;
final String url = GWT . getModuleBaseURL ( ) + " downloadEncryptedReport?itemId= " + itemId ;
Window . open ( url , " _blank " , " " ) ;
}
}
2013-02-06 23:25:43 +01:00
2013-03-13 11:47:15 +01:00
}
} ) ;
wpTreepopup . center ( ) ;
wpTreepopup . show ( ) ;
}
public void onFailure ( Throwable reason ) {
Window . alert ( " There are networks problem, please check your connection. " ) ;
}
} ) ;
}
} ;
2013-02-06 23:25:43 +01:00
//************** COMMANDS ********************************////
Command addBiblioEntryCommand = new Command ( ) {
public void execute ( ) {
2013-03-15 11:37:45 +01:00
GWT . runAsync ( new RunAsyncCallback ( ) {
@Override
public void onSuccess ( ) {
presenter . openAddCitationDialog ( ) ;
}
@Override
public void onFailure ( Throwable reason ) {
}
} ) ;
2013-02-06 23:25:43 +01:00
}
} ;
/ * *
*
* /
Command openMetadata = new Command ( ) {
public void execute ( ) {
2013-03-15 11:37:45 +01:00
GWT . runAsync ( new RunAsyncCallback ( ) {
@Override
public void onSuccess ( ) {
int left = mainLayout . getAbsoluteLeft ( ) + 50 ;
int top = mainLayout . getAbsoluteTop ( ) + 25 ;
GCubeDialog dlg = new GCubeDialog ( true ) ;
dlg . setText ( " Report Metadata: " ) ;
int pageNo = presenter . getModel ( ) . getCurrentPage ( ) ;
List < Metadata > metadatas = presenter . getModel ( ) . getSection ( pageNo ) . getAllMetadata ( ) ;
int nRows = metadatas . size ( ) ;
Grid metadataGrid = new Grid ( nRows , 2 ) ;
int i = 0 ;
for ( Metadata md : metadatas ) {
metadataGrid . setWidget ( i , 0 , new HTML ( " <b> " + md . getAttribute ( ) + " : </b> " ) ) ;
metadataGrid . setWidget ( i , 1 , new HTML ( md . getValue ( ) ) ) ;
i + + ;
}
2013-02-06 23:25:43 +01:00
2013-03-15 11:37:45 +01:00
dlg . setWidget ( metadataGrid ) ;
dlg . setPopupPosition ( left , top ) ;
dlg . setAnimationEnabled ( true ) ;
dlg . show ( ) ;
}
@Override
public void onFailure ( Throwable reason ) { }
} ) ;
2013-02-06 23:25:43 +01:00
}
} ;
Command importModelOrReport = new Command ( ) {
public void execute ( ) {
if ( ! ReportConstants . isDeployed ) {
int left = mainLayout . getAbsoluteLeft ( ) + 50 ;
int top = mainLayout . getAbsoluteTop ( ) + 25 ;
ImporterDialog dlg = new ImporterDialog ( null , presenter ) ;
dlg . setPopupPosition ( left , top ) ;
dlg . setAnimationEnabled ( true ) ;
dlg . show ( ) ;
}
else {
2013-03-15 11:37:45 +01:00
GWT . runAsync ( new RunAsyncCallback ( ) {
@Override
public void onSuccess ( ) {
int left = mainLayout . getAbsoluteLeft ( ) + 50 ;
int top = mainLayout . getAbsoluteTop ( ) + 25 ;
WorkspaceLightTreeLoadPopup wpTreepopup = new WorkspaceLightTreeLoadPopup ( " Pick the item you want to import from " , true , true ) ;
wpTreepopup . setShowableTypes ( ItemType . REPORT_TEMPLATE , ItemType . REPORT ) ;
2013-02-06 23:25:43 +01:00
2013-03-15 11:37:45 +01:00
wpTreepopup . addPopupHandler ( new PopupHandler ( ) {
public void onPopup ( PopupEvent event ) {
if ( ! event . isCanceled ( ) ) {
if ( event . getSelectedItem ( ) ! = null ) {
int left = mainLayout . getAbsoluteLeft ( ) + 50 ;
int top = mainLayout . getAbsoluteTop ( ) + 25 ;
ImporterDialog dlg = new ImporterDialog ( event . getSelectedItem ( ) , presenter ) ;
dlg . setPopupPosition ( left , top ) ;
dlg . setAnimationEnabled ( true ) ;
dlg . show ( ) ;
}
presenter . getHeader ( ) . enableExports ( ) ;
}
2013-02-06 23:25:43 +01:00
2013-03-15 11:37:45 +01:00
}
} ) ;
wpTreepopup . setPopupPosition ( left , top ) ;
wpTreepopup . show ( ) ;
}
@Override
public void onFailure ( Throwable reason ) {
2013-02-06 23:25:43 +01:00
}
} ) ;
2013-03-15 11:37:45 +01:00
2013-02-06 23:25:43 +01:00
}
}
} ;
/ * *
*
* @return .
* /
public CellPanel getMainLayout ( ) {
return mainLayout ;
}
}