// pager.setRangeLimited(false);
VerticalPanel tableAndPager = new VerticalPanel();
tableAndPager.setHorizontalAlignment( HasHorizontalAlignment.ALIGN_CENTER );
Toolbar bar = new Toolbar();
bar.addSpacer( 10 );
bar.add( Toolbar.GLUE );
// Add control scheduler button
if ( isAdmin ) {
final ToolbarButton controlSchedulerButton =
new ToolbarButton( ImageUtil.getThemeableImage( "icon-small", "icon-start-scheduler" ) );
controlSchedulerButton.setCommand( new Command() {
public void execute() {
toggleSchedulerOnOff( controlSchedulerButton, isScheduler );
}
} );
updateControlSchedulerButtonState( controlSchedulerButton, isScheduler );
bar.add( controlSchedulerButton );
bar.addSpacer( 20 );
}
// Add filter button
filterButton.setCommand( new Command() {
public void execute() {
if ( filterDialog == null ) {
filterDialog = new FilterDialog( allJobs, filterDialogCallback );
} else {
filterDialog.initUI( allJobs );
}
filterDialog.center();
}
} );
filterButton.setToolTip( Messages.getString( "filterSchedules" ) );
if ( isAdmin ) {
bar.add( filterButton );
}
// Add remove filters button
filterRemoveButton.setCommand( new Command() {
public void execute() {
filterDialog = null;
filters.clear();
filterAndShowData();
filterRemoveButton.setEnabled( false );
filterButton.setImage( ImageUtil.getThemeableImage( "icon-small", "icon-filter-add" ) );
}
} );
filterRemoveButton.setToolTip( Messages.getString( "removeFilters" ) );
filterRemoveButton.setEnabled( filters.size() > 0 );
if ( isAdmin ) {
bar.add( filterRemoveButton );
}
// Add refresh button
ToolbarButton refresh = new ToolbarButton( ImageUtil.getThemeableImage( "icon-small", "icon-refresh" ) );
refresh.setToolTip( Messages.getString( "refreshTooltip" ) );
refresh.setCommand( new Command() {
public void execute() {
RefreshSchedulesCommand cmd = new RefreshSchedulesCommand();
cmd.execute();
}
} );
bar.add( refresh );
bar.addSpacer( 20 );
// Add execute now button
triggerNowButton.setToolTip( Messages.getString( "executeNow" ) );
triggerNowButton.setCommand( new Command() {
public void execute() {
Set<JsJob> selectedJobs = getSelectedJobs();
if ( selectedJobs != null && selectedJobs.size() > 0 ) {
MessageDialogBox messageDialog =
new MessageDialogBox( Messages.getString( "executeNow" ), Messages.getString( "executeNowStarted" ),
false, true, true );
messageDialog.setCallback( new IDialogCallback() {
public void okPressed() {
// wait a little to refresh to give schedule time to update the last run
Timer t = new Timer() {
public void run() {
refresh();
}
};
t.schedule( 2000 );
}
public void cancelPressed() {
}
} );
messageDialog.center();
controlJobs( selectedJobs, "triggerNow", RequestBuilder.POST, false );
}
}
} );
triggerNowButton.setEnabled( false );
bar.add( triggerNowButton );
// Add control schedule button
controlScheduleButton.setCommand( new Command() {
public void execute() {
Set<JsJob> selectedJobs = getSelectedJobs();
if ( selectedJobs != null && selectedJobs.size() > 0 ) {
JsJob[] jobs = selectedJobs.toArray( new JsJob[selectedJobs.size()] );
if ( "NORMAL".equals( jobs[0].getState() ) ) {
controlJobs( selectedJobs, "pauseJob", RequestBuilder.POST, false );
} else {
controlJobs( selectedJobs, "resumeJob", RequestBuilder.POST, false );
}
}
}
} );
controlScheduleButton.setEnabled( false );
bar.add( controlScheduleButton );
bar.addSpacer( 20 );
// Add edit button
editButton.setCommand( new Command() {
public void execute() {
Set<JsJob> selectedJobs = getSelectedJobs();
if ( selectedJobs != null && selectedJobs.size() > 0 ) {
JsJob[] jobs = selectedJobs.toArray( new JsJob[selectedJobs.size()] );
final JsJob editJob = jobs[0];
final String url =
GWT.getHostPageBaseURL() + "api/repo/files/"
+ SolutionBrowserPanel.pathToId( editJob.getFullResourceName() ) + "/canAccess?cb="
+ System.currentTimeMillis() + "&permissions=" + READ_PERMISSION;
RequestBuilder executableTypesRequestBuilder = new RequestBuilder( RequestBuilder.GET, url );
try {
executableTypesRequestBuilder.setHeader( "If-Modified-Since", "01 Jan 1970 00:00:00 GMT" );
executableTypesRequestBuilder.sendRequest( null, new RequestCallback() {
public void onError( Request request, Throwable exception ) {
promptForScheduleResourceError( editJob );
}
public void onResponseReceived( Request request, Response response ) {
if ( "true".equalsIgnoreCase( response.getText() ) ) {
editJob( editJob );
} else {
promptForScheduleResourceError( editJob );
}
}
} );
} catch ( RequestException e ) {
// showError(e);
}
}
}
} );
editButton.setEnabled( false );
editButton.setToolTip( Messages.getString( "editTooltip" ) );
bar.add( editButton );
// Add remove button
scheduleRemoveButton.setCommand( new Command() {
public void execute() {
Set<JsJob> selectedJobs = getSelectedJobs();
if ( selectedJobs != null && selectedJobs.size() > 0 ) {
final PromptDialogBox prompt =
new PromptDialogBox( Messages.getString( "warning" ), Messages.getString( "yes" ), Messages
.getString( "no" ), false, true );
prompt.setContent( new Label( Messages.getString( "deleteConfirmSchedles", "" + selectedJobs.size() ) ) );
prompt.setCallback( new IDialogCallback() {
public void okPressed() {
controlJobs( getSelectedJobs(), "removeJob", RequestBuilder.DELETE, true );
prompt.hide();
}
public void cancelPressed() {
prompt.hide();
}
} );
prompt.center();
}
}
} );
scheduleRemoveButton.setToolTip( Messages.getString( "remove" ) );
scheduleRemoveButton.setEnabled( false );
bar.add( scheduleRemoveButton );
tableAndPager.add( bar );
tableAndPager.add( table );
tableAndPager.add( pager );