Search in sources :

Example 1 with JsJob

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
    }
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Request(com.google.gwt.http.client.Request) Label(com.google.gwt.user.client.ui.Label) JsJobParam(org.pentaho.mantle.client.workspace.JsJobParam) JSONString(com.google.gwt.json.client.JSONString) TextBox(com.google.gwt.user.client.ui.TextBox) IDialogCallback(org.pentaho.gwt.widgets.client.dialogs.IDialogCallback) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) RequestCallback(com.google.gwt.http.client.RequestCallback) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) Button(com.google.gwt.user.client.ui.Button) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel) JsJob(org.pentaho.mantle.client.workspace.JsJob) ScheduleRecurrenceDialog(org.pentaho.mantle.client.dialogs.scheduling.ScheduleRecurrenceDialog)

Aggregations

ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 Request (com.google.gwt.http.client.Request)1 RequestBuilder (com.google.gwt.http.client.RequestBuilder)1 RequestCallback (com.google.gwt.http.client.RequestCallback)1 RequestException (com.google.gwt.http.client.RequestException)1 Response (com.google.gwt.http.client.Response)1 JSONString (com.google.gwt.json.client.JSONString)1 Button (com.google.gwt.user.client.ui.Button)1 HorizontalPanel (com.google.gwt.user.client.ui.HorizontalPanel)1 Label (com.google.gwt.user.client.ui.Label)1 TextBox (com.google.gwt.user.client.ui.TextBox)1 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)1 IDialogCallback (org.pentaho.gwt.widgets.client.dialogs.IDialogCallback)1 MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)1 ScheduleRecurrenceDialog (org.pentaho.mantle.client.dialogs.scheduling.ScheduleRecurrenceDialog)1 JsJob (org.pentaho.mantle.client.workspace.JsJob)1 JsJobParam (org.pentaho.mantle.client.workspace.JsJobParam)1