2013-02-06 23:25:43 +01:00
package org.gcube.portlets.user.reportgenerator.client.Presenter ;
2015-09-28 19:05:00 +02:00
import java.util.Arrays ;
2013-02-06 23:25:43 +01:00
import org.gcube.portlets.user.reportgenerator.client.ReportConstants ;
import org.gcube.portlets.user.reportgenerator.client.dialog.ImporterDialog ;
2015-09-28 19:05:00 +02:00
import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSaveNotification.WorskpaceExplorerSaveNotificationListener ;
import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSelectNotification.WorskpaceExplorerSelectNotificationListener ;
import org.gcube.portlets.widgets.wsexplorer.client.save.WorkspaceExplorerSaveDialog ;
import org.gcube.portlets.widgets.wsexplorer.client.select.WorkspaceExplorerSelectDialog ;
import org.gcube.portlets.widgets.wsexplorer.shared.Item ;
import org.gcube.portlets.widgets.wsexplorer.shared.ItemType ;
2013-02-06 23:25:43 +01:00
import com.extjs.gxt.ui.client.event.ColorPaletteEvent ;
import com.extjs.gxt.ui.client.event.Events ;
import com.extjs.gxt.ui.client.event.Listener ;
import com.extjs.gxt.ui.client.widget.ColorPalette ;
import com.google.gwt.core.client.GWT ;
import com.google.gwt.core.client.RunAsyncCallback ;
import com.google.gwt.user.client.Command ;
import com.google.gwt.user.client.Window ;
import com.google.gwt.user.client.ui.PopupPanel ;
/ * *
* *
* / * *
* < code > CommonCommands < / code > class contains the menu commands for the UI
*
* @author Massimiliano Assante , ISTI - CNR - massimiliano . assante @isti.cnr.it
* /
public class CommonCommands {
2014-01-23 19:11:55 +01:00
/ * *
*
* /
public Command exportToRSG ;
2013-02-06 23:25:43 +01:00
/ * *
*
* /
public Command openTemplate ;
2013-03-16 18:14:36 +01:00
/ * *
*
* /
public Command openReport ;
2013-04-30 16:16:20 +02:00
2013-12-18 16:30:32 +01:00
2013-04-30 16:16:20 +02:00
public Command newTemplate ;
2013-02-06 23:25:43 +01:00
/ * *
*
* /
public Command importTemplateCommand ;
/ * *
*
* /
public Command insertImage ;
/ * *
*
* /
2013-12-18 17:33:25 +01:00
public Command saveTemplate ;
/ * *
*
* /
public Command structureView ;
2013-02-06 23:25:43 +01:00
/ * *
*
* /
public Command pickColor ;
private Presenter presenter ;
/ * *
*
* @param presenter .
* /
public CommonCommands ( final Presenter presenter ) {
this . presenter = presenter ;
2013-12-18 17:33:25 +01:00
structureView = new Command ( ) {
public void execute ( ) {
presenter . toggleReportStructure ( ) ;
}
} ;
2013-04-30 16:16:20 +02:00
newTemplate = new Command ( ) {
public void execute ( ) {
2014-01-28 17:31:13 +01:00
presenter . newDoc ( ) ;
2013-04-30 16:16:20 +02:00
}
} ;
2013-02-06 23:25:43 +01:00
openTemplate = new Command ( ) {
public void execute ( ) {
2015-09-28 19:05:00 +02:00
GWT . runAsync ( WorkspaceExplorerSelectDialog . class , new RunAsyncCallback ( ) {
2013-02-06 23:25:43 +01:00
public void onSuccess ( ) {
2015-09-28 19:05:00 +02:00
ItemType [ ] types = { ItemType . REPORT_TEMPLATE } ;
final WorkspaceExplorerSelectDialog wpTreepopup = new WorkspaceExplorerSelectDialog ( " Select a Template to open " , Arrays . asList ( types ) , Arrays . asList ( types ) ) ;
2013-02-06 23:25:43 +01:00
2015-09-28 19:05:00 +02:00
WorskpaceExplorerSelectNotificationListener listener = new WorskpaceExplorerSelectNotificationListener ( ) {
2013-02-06 23:25:43 +01:00
2015-09-28 19:05:00 +02:00
@Override
public void onSelectedItem ( Item item ) {
presenter . openTemplate ( item . getName ( ) , item . getId ( ) , true ) ;
wpTreepopup . hide ( ) ;
2013-02-06 23:25:43 +01:00
}
2015-09-28 19:05:00 +02:00
@Override
public void onFailed ( Throwable throwable ) {
Window . alert ( " There are networks problem, please check your connection. " ) ;
}
@Override
public void onAborted ( ) { }
@Override
public void onNotValidSelection ( ) {
}
} ;
wpTreepopup . addWorkspaceExplorerSelectNotificationListener ( listener ) ;
wpTreepopup . show ( ) ;
2013-02-06 23:25:43 +01:00
}
public void onFailure ( Throwable reason ) {
Window . alert ( " There are networks problem, please check your connection. " ) ;
}
} ) ;
}
} ;
2013-03-16 18:14:36 +01:00
openReport = new Command ( ) {
2015-09-28 19:05:00 +02:00
public void execute ( ) {
GWT . runAsync ( WorkspaceExplorerSelectDialog . class , new RunAsyncCallback ( ) {
public void onSuccess ( ) {
ItemType [ ] types = { ItemType . REPORT } ;
final WorkspaceExplorerSelectDialog wpTreepopup = new WorkspaceExplorerSelectDialog ( " Select a Report to open " , Arrays . asList ( types ) , Arrays . asList ( types ) ) ;
2013-03-16 18:14:36 +01:00
2015-09-28 19:05:00 +02:00
WorskpaceExplorerSelectNotificationListener listener = new WorskpaceExplorerSelectNotificationListener ( ) {
2013-03-16 18:14:36 +01:00
2015-09-28 19:05:00 +02:00
@Override
public void onSelectedItem ( Item item ) {
presenter . openTemplate ( item . getName ( ) , item . getId ( ) , true ) ;
wpTreepopup . hide ( ) ;
}
@Override
public void onFailed ( Throwable throwable ) {
Window . alert ( " There are networks problem, please check your connection. " ) ;
}
@Override
public void onAborted ( ) { }
@Override
public void onNotValidSelection ( ) {
2013-03-16 18:14:36 +01:00
}
2015-09-28 19:05:00 +02:00
} ;
wpTreepopup . addWorkspaceExplorerSelectNotificationListener ( listener ) ;
wpTreepopup . show ( ) ;
2013-03-16 18:14:36 +01:00
}
public void onFailure ( Throwable reason ) {
Window . alert ( " There are networks problem, please check your connection. " ) ;
}
2015-09-28 19:05:00 +02:00
} ) ;
}
2013-03-16 18:14:36 +01:00
} ;
2013-02-06 23:25:43 +01:00
pickColor = new Command ( ) {
public void execute ( ) {
int left = presenter . getHeader ( ) . getMainLayout ( ) . getAbsoluteLeft ( ) + 600 ;
int top = presenter . getHeader ( ) . getMainLayout ( ) . getAbsoluteTop ( ) + 50 ;
final PopupPanel pp = new PopupPanel ( true ) ;
ColorPalette colorPalette = new ColorPalette ( ) ;
colorPalette . addListener ( Events . Select , new Listener < ColorPaletteEvent > ( ) {
@SuppressWarnings ( " deprecation " )
public void handleEvent ( ColorPaletteEvent be ) {
presenter . getCurrentSelected ( ) . getExtendedFormatter ( ) . setForeColor ( be . getColor ( ) ) ;
pp . hide ( ) ;
}
} ) ;
pp . add ( colorPalette ) ;
pp . setAnimationEnabled ( false ) ;
pp . setPopupPosition ( left , top ) ;
pp . show ( ) ;
}
} ;
importTemplateCommand = new Command ( ) {
public void execute ( ) {
if ( ! ReportConstants . isDeployed ) {
int left = presenter . getHeader ( ) . getMainLayout ( ) . getAbsoluteLeft ( ) + 50 ;
int top = presenter . getHeader ( ) . getMainLayout ( ) . getAbsoluteTop ( ) + 25 ;
ImporterDialog dlg = new ImporterDialog ( null , presenter ) ;
dlg . setPopupPosition ( left , top ) ;
dlg . setAnimationEnabled ( true ) ;
dlg . show ( ) ;
}
2015-09-28 19:05:00 +02:00
else {
GWT . runAsync ( WorkspaceExplorerSelectDialog . class , new RunAsyncCallback ( ) {
2013-02-06 23:25:43 +01:00
public void onSuccess ( ) {
2015-09-28 19:05:00 +02:00
ItemType [ ] types = { ItemType . REPORT_TEMPLATE } ;
final WorkspaceExplorerSelectDialog wpTreepopup = new WorkspaceExplorerSelectDialog ( " Pick the item you want to import from " , Arrays . asList ( types ) , Arrays . asList ( types ) ) ;
WorskpaceExplorerSelectNotificationListener listener = new WorskpaceExplorerSelectNotificationListener ( ) {
@Override
public void onSelectedItem ( Item item ) {
int left = presenter . getHeader ( ) . getMainLayout ( ) . getAbsoluteLeft ( ) + 50 ;
int top = presenter . getHeader ( ) . getMainLayout ( ) . getAbsoluteTop ( ) + 25 ;
ImporterDialog dlg = new ImporterDialog ( item , presenter ) ;
dlg . setPopupPosition ( left , top ) ;
dlg . setAnimationEnabled ( true ) ;
dlg . show ( ) ;
wpTreepopup . hide ( ) ;
2013-02-06 23:25:43 +01:00
}
2015-09-28 19:05:00 +02:00
@Override
public void onFailed ( Throwable throwable ) {
Window . alert ( " There are networks problem, please check your connection. " ) ;
}
@Override
public void onAborted ( ) { }
@Override
public void onNotValidSelection ( ) {
}
} ;
wpTreepopup . addWorkspaceExplorerSelectNotificationListener ( listener ) ;
wpTreepopup . show ( ) ;
2013-02-06 23:25:43 +01:00
}
public void onFailure ( Throwable reason ) {
Window . alert ( " There are networks problem, please check your connection. " ) ;
}
2015-09-28 19:05:00 +02:00
} ) ;
2013-02-06 23:25:43 +01:00
}
}
} ;
saveTemplate = new Command ( ) {
public void execute ( ) {
if ( presenter . getModel ( ) . getTemplateName ( ) . endsWith ( " d4sR " ) )
presenter . saveReport ( ) ;
else
saveReportAsDialog ( ) ;
}
} ;
2014-01-23 19:11:55 +01:00
exportToRSG = new Command ( ) {
public void execute ( ) {
presenter . exportReportToRSG ( ) ;
}
} ;
2013-02-06 23:25:43 +01:00
} //end constructor
public void saveReportAsDialog ( ) {
2015-09-28 19:05:00 +02:00
GWT . runAsync ( WorskpaceExplorerSaveNotificationListener . class , new RunAsyncCallback ( ) {
2013-02-06 23:25:43 +01:00
public void onSuccess ( ) {
2015-09-28 19:05:00 +02:00
ItemType [ ] types = { ItemType . FOLDER } ;
final WorkspaceExplorerSaveDialog navigator = new WorkspaceExplorerSaveDialog ( " Save Report, choose folder please: " , Arrays . asList ( types ) ) ;
WorskpaceExplorerSaveNotificationListener listener = new WorskpaceExplorerSaveNotificationListener ( ) {
@Override
public void onSaving ( Item parent , String fileName ) {
2013-02-06 23:25:43 +01:00
//checking user input
2015-09-28 19:05:00 +02:00
String inputUser = fileName ;
2013-02-06 23:25:43 +01:00
String newTemplateName = inputUser ;
if ( presenter . getModel ( ) . getTemplateName ( ) . compareTo ( newTemplateName ) ! = 0 ) {
newTemplateName = newTemplateName . trim ( ) ;
presenter . getModel ( ) . setTemplateName ( newTemplateName + " .d4sR " ) ;
}
presenter . changeTemplateName ( newTemplateName ) ;
2015-09-28 19:05:00 +02:00
presenter . saveReport ( parent . getId ( ) , newTemplateName ) ;
navigator . hide ( ) ;
2013-02-06 23:25:43 +01:00
}
2015-09-28 19:05:00 +02:00
@Override
public void onAborted ( ) {
GWT . log ( " onAborted " ) ;
}
@Override
public void onFailed ( Throwable throwable ) {
GWT . log ( " onFailed " ) ;
}
} ;
navigator . addWorkspaceExplorerSaveNotificationListener ( listener ) ;
navigator . show ( ) ;
2013-02-06 23:25:43 +01:00
}
public void onFailure ( Throwable reason ) {
Window . alert ( " There are networks problem, please check your connection. " ) ;
}
} ) ;
}
}