use of org.pentaho.mantle.client.workspace.JsJob in project pentaho-platform by pentaho.
the class ContentCleanerPanel method activate.
public void activate() {
clear();
String moduleBaseURL = GWT.getModuleBaseURL();
String moduleName = GWT.getModuleName();
String contextURL = moduleBaseURL.substring(0, moduleBaseURL.lastIndexOf(moduleName));
RequestBuilder scheduleFileRequestBuilder = new RequestBuilder(RequestBuilder.GET, contextURL + "api/scheduler/getContentCleanerJob?cb=" + System.currentTimeMillis());
scheduleFileRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
// $NON-NLS-1$//$NON-NLS-2$
scheduleFileRequestBuilder.setHeader("Content-Type", "application/json");
// $NON-NLS-1$//$NON-NLS-2$
scheduleFileRequestBuilder.setHeader("accept", "application/json");
try {
scheduleFileRequestBuilder.sendRequest("", new RequestCallback() {
public void onError(Request request, Throwable exception) {
}
public void onResponseReceived(Request request, Response response) {
final TextBox nowTextBox = new TextBox();
nowTextBox.setWidth("24px");
nowTextBox.getElement().getStyle().setPadding(5, Unit.PX);
nowTextBox.getElement().getStyle().setMarginLeft(5, Unit.PX);
nowTextBox.getElement().getStyle().setMarginRight(5, Unit.PX);
final TextBox scheduleTextBox = new TextBox();
scheduleTextBox.setVisibleLength(4);
JsJob tmpJsJob = parseJsonJob(JsonUtils.escapeJsonForEval(response.getText()));
boolean fakeJob = false;
if (tmpJsJob == null) {
tmpJsJob = createJsJob();
fakeJob = true;
}
final JsJob jsJob = tmpJsJob;
if (jsJob != null) {
scheduleTextBox.setValue("" + (Long.parseLong(jsJob.getJobParamValue("age")) / DAY_IN_MILLIS));
} else {
scheduleTextBox.setText("180");
}
scheduleTextBox.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
if (jsJob != null) {
JsArray<JsJobParam> params = jsJob.getJobParams();
for (int i = 0; i < params.length(); i++) {
if (params.get(i).getName().equals("age")) {
params.get(i).setValue("" + (Long.parseLong(scheduleTextBox.getText()) * DAY_IN_MILLIS));
break;
}
}
}
}
});
Label settingsLabel = new Label(Messages.getString("settings"));
settingsLabel.setStyleName("pentaho-fieldgroup-major");
add(settingsLabel, DockPanel.NORTH);
VerticalPanel nowPanelWrapper = new VerticalPanel();
Label deleteNowLabel = new Label(Messages.getString("deleteGeneratedFilesNow"));
deleteNowLabel.getElement().getStyle().setPaddingTop(15, Unit.PX);
deleteNowLabel.setStyleName("pentaho-fieldgroup-minor");
nowPanelWrapper.add(deleteNowLabel);
HorizontalPanel nowLabelPanel = new HorizontalPanel();
nowLabelPanel.getElement().getStyle().setPaddingTop(10, Unit.PX);
nowLabelPanel.getElement().getStyle().setPaddingBottom(10, Unit.PX);
Label deleteGeneratedFilesOlderThan = new Label(Messages.getString("deleteGeneratedFilesOlderThan"));
deleteGeneratedFilesOlderThan.getElement().getStyle().setPaddingTop(7, Unit.PX);
nowLabelPanel.add(deleteGeneratedFilesOlderThan);
nowLabelPanel.add(nowTextBox);
nowTextBox.setText("180");
Label days = new Label(Messages.getString("daysDot"));
days.getElement().getStyle().setPaddingTop(7, Unit.PX);
nowLabelPanel.add(days);
Button deleteNowButton = new Button(Messages.getString("deleteNow"));
deleteNowButton.setStylePrimaryName("pentaho-button");
deleteNowButton.addStyleName("first");
deleteNowButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
MessageDialogBox warning = new MessageDialogBox(Messages.getString("deleteNow"), Messages.getString("confirmDeleteGeneratedContentNow"), false, false, true, Messages.getString("yes"), null, Messages.getString("no"));
warning.setCallback(new IDialogCallback() {
@Override
public void okPressed() {
deleteContentNow(Long.parseLong(nowTextBox.getValue()) * DAY_IN_MILLIS);
}
@Override
public void cancelPressed() {
}
});
warning.center();
}
});
nowPanelWrapper.add(nowLabelPanel);
nowPanelWrapper.add(deleteNowButton);
add(nowPanelWrapper, DockPanel.NORTH);
// scheduled
VerticalPanel scheduledPanel = new VerticalPanel();
Label deleteScheduleLabel = new Label(Messages.getString("scheduleDeletionOfGeneratedFiles"));
deleteScheduleLabel.setStyleName("pentaho-fieldgroup-minor");
deleteScheduleLabel.getElement().getStyle().setPaddingTop(15, Unit.PX);
scheduledPanel.add(deleteScheduleLabel);
Label descLabel;
if (!fakeJob) {
String desc = jsJob.getJobTrigger().getDescription();
descLabel = new Label(desc);
scheduledPanel.add(descLabel);
} else {
descLabel = new Label(Messages.getString("generatedFilesAreNotScheduledToBeDeleted"));
scheduledPanel.add(descLabel);
}
descLabel.getElement().getStyle().setPaddingTop(10, Unit.PX);
descLabel.getElement().getStyle().setPaddingBottom(10, Unit.PX);
Button editScheduleButton = new Button(Messages.getString("edit"));
if (fakeJob) {
editScheduleButton.setText(Messages.getString("scheduleDeletion"));
}
Button deleteScheduleButton = new Button(Messages.getString("cancelSchedule"));
deleteScheduleButton.setStylePrimaryName("pentaho-button");
deleteScheduleButton.addStyleName("last");
deleteScheduleButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
deleteContentCleaner(jsJob);
}
});
editScheduleButton.setStylePrimaryName("pentaho-button");
editScheduleButton.addStyleName("first");
editScheduleButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
IDialogCallback callback = new IDialogCallback() {
public void okPressed() {
deleteContentCleaner(jsJob);
}
public void cancelPressed() {
}
};
HorizontalPanel scheduleLabelPanel = new HorizontalPanel();
scheduleLabelPanel.add(new Label(Messages.getString("deleteGeneratedFilesOlderThan"), false));
scheduleLabelPanel.add(scheduleTextBox);
scheduleLabelPanel.add(new Label(Messages.getString("daysUsingTheFollowingRules"), false));
ScheduleRecurrenceDialog editSchedule = new ScheduleRecurrenceDialog(null, jsJob, callback, false, false, AbstractWizardDialog.ScheduleDialogType.SCHEDULER);
editSchedule.setShowSuccessDialog(false);
editSchedule.addCustomPanel(scheduleLabelPanel, DockPanel.NORTH);
editSchedule.center();
}
});
HorizontalPanel scheduleButtonPanel = new HorizontalPanel();
scheduleButtonPanel.add(editScheduleButton);
if (!fakeJob) {
scheduleButtonPanel.add(deleteScheduleButton);
}
scheduledPanel.add(scheduleButtonPanel);
add(scheduledPanel, DockPanel.NORTH);
VerticalPanel fillPanel = new VerticalPanel();
add(fillPanel, DockPanel.NORTH);
fillPanel.getElement().getParentElement().getStyle().setHeight(100, Unit.PCT);
}
});
} catch (RequestException re) {
// ignored
}
}
Aggregations