Search in sources :

Example 11 with MessageDialogBox

use of org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox in project pentaho-platform by pentaho.

the class RestoreFileCommand method execute.

/*
   * (non-Javadoc)
   * 
   * @see com.google.gwt.user.client.Command#execute()
   */
@Override
public void execute() {
    final SolutionFileActionEvent event = new SolutionFileActionEvent();
    event.setAction(this.getClass().getName());
    String temp = "";
    if (repositoryFiles != null) {
        for (RepositoryFile repoFile : repositoryFiles) {
            // $NON-NLS-1$
            temp += repoFile.getId() + ",";
        }
    }
    // Add file names from js
    temp = temp + fileList;
    // remove trailing ","
    temp = temp.substring(0, temp.length() - 1);
    final String filesList = temp;
    // $NON-NLS-1$
    String deleteFilesURL = contextURL + "api/repo/files/restore";
    RequestBuilder deleteFilesRequestBuilder = new RequestBuilder(RequestBuilder.PUT, deleteFilesURL);
    // $NON-NLS-1$//$NON-NLS-2$
    deleteFilesRequestBuilder.setHeader("Content-Type", "text/plain");
    deleteFilesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    try {
        deleteFilesRequestBuilder.sendRequest(filesList, new RequestCallback() {

            @Override
            public void onError(Request request, Throwable exception) {
                MessageDialogBox dialogBox = new MessageDialogBox(// $NON-NLS-1$ //$NON-NLS-2$
                Messages.getString("cannotRestore"), // $NON-NLS-1$ //$NON-NLS-2$
                Messages.getString("couldNotRestoreItem", type), false, false, true);
                dialogBox.center();
                event.setMessage("cannotRestore");
                EventBusUtil.EVENT_BUS.fireEvent(event);
            }

            @Override
            public void onResponseReceived(final Request request, final Response response) {
                if (response.getStatusCode() == Response.SC_OK) {
                    new RefreshRepositoryCommand().execute(false);
                    event.setMessage("Success");
                    EventBusUtil.EVENT_BUS.fireEvent(event);
                } else if (response.getStatusCode() == Response.SC_CONFLICT || response.getStatusCode() == Response.SC_NOT_ACCEPTABLE) {
                    final int restoreResponseStatusCode = response.getStatusCode();
                    final String userHomeDirUrl = GWT.getHostPageBaseURL() + "api/session/userWorkspaceDir";
                    final RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, userHomeDirUrl);
                    try {
                        // Get user home folder string
                        builder.sendRequest("", new RequestCallback() {

                            @Override
                            public void onResponseReceived(final Request request, final Response response) {
                                if (response.getStatusCode() == 200) {
                                    // API returns /user/home_folder/workspace
                                    String userHomeFolderPath = response.getText().replaceAll("/workspace", "");
                                    performRestoreToHomeFolder(filesList, restoreResponseStatusCode, userHomeFolderPath, event);
                                }
                            }

                            @Override
                            public void onError(Request request, Throwable exception) {
                                showErrorDialogBox(event);
                            }
                        });
                    } catch (RequestException e) {
                        showErrorDialogBox(event);
                    }
                } else {
                    MessageDialogBox dialogBox = new MessageDialogBox(// $NON-NLS-1$ //$NON-NLS-2$
                    Messages.getString("cannotRestore"), // $NON-NLS-1$ //$NON-NLS-2$
                    Messages.getString("couldNotRestoreItem", type), false, false, true, Messages.getString("close"));
                    dialogBox.center();
                    event.setMessage("Success");
                    FileChooserDialog.setIsDirty(Boolean.TRUE);
                    setBrowseRepoDirty(Boolean.TRUE);
                    EventBusUtil.EVENT_BUS.fireEvent(event);
                }
            }
        });
    } catch (RequestException e) {
        showErrorDialogBox(event);
    }
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) Request(com.google.gwt.http.client.Request) SolutionFileActionEvent(org.pentaho.mantle.client.events.SolutionFileActionEvent) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) RequestCallback(com.google.gwt.http.client.RequestCallback) RepositoryFile(org.pentaho.gwt.widgets.client.filechooser.RepositoryFile)

Example 12 with MessageDialogBox

use of org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox in project pentaho-platform by pentaho.

the class RunInBackgroundCommand method checkSchedulePermissionAndDialog.

protected void checkSchedulePermissionAndDialog() {
    // $NON-NLS-1$
    final String url = ScheduleHelper.getFullyQualifiedURL() + "api/scheduler/isScheduleAllowed?id=" + repositoryFile.getRepositoryFile().getId();
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    requestBuilder.setHeader("accept", "text/plain");
    requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    final MessageDialogBox errorDialog = new MessageDialogBox(Messages.getString("error"), Messages.getString("noSchedulePermission"), false, false, // $NON-NLS-1$ //$NON-NLS-2$
    true);
    try {
        requestBuilder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable caught) {
                errorDialog.center();
            }

            public void onResponseReceived(Request request, Response response) {
                if ("true".equalsIgnoreCase(response.getText())) {
                    showDialog(true);
                } else {
                    errorDialog.center();
                }
            }
        });
    } catch (RequestException re) {
        errorDialog.center();
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) RequestCallback(com.google.gwt.http.client.RequestCallback) Request(com.google.gwt.http.client.Request) JSONString(com.google.gwt.json.client.JSONString) RequestException(com.google.gwt.http.client.RequestException)

Example 13 with MessageDialogBox

use of org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox in project pentaho-platform by pentaho.

the class NewDropdownCommand method performOperation.

protected void performOperation(boolean feedback) {
    final PopupPanel popup = new PopupPanel(true, false) {

        public void show() {
            // show glass pane
            super.show();
            if (pageBackground == null) {
                pageBackground = new FocusPanel() {

                    public void onBrowserEvent(Event event) {
                        int type = event.getTypeInt();
                        switch(type) {
                            case Event.ONKEYDOWN:
                                {
                                    if ((char) event.getKeyCode() == KeyCodes.KEY_ESCAPE) {
                                        event.stopPropagation();
                                        hide();
                                    }
                                    return;
                                }
                        }
                        super.onBrowserEvent(event);
                    }
                };
                pageBackground.addClickHandler(new ClickHandler() {

                    public void onClick(ClickEvent event) {
                        hide();
                        pageBackground.setVisible(false);
                        pageBackground.getElement().getStyle().setDisplay(Display.NONE);
                    }
                });
                RootPanel.get().add(pageBackground, 0, 0);
            }
            // $NON-NLS-1$ //$NON-NLS-2$
            pageBackground.setSize("100%", Window.getClientHeight() + Window.getScrollTop() + "px");
            pageBackground.setVisible(true);
            pageBackground.getElement().getStyle().setDisplay(Display.BLOCK);
            // hide <embeds>
            // TODO: migrate to GlassPane Listener
            FrameUtils.toggleEmbedVisibility(false);
            // Notify listeners that we're showing a dialog (hide PDFs, flash).
            GlassPane.getInstance().show();
        }

        public void hide(boolean autoClosed) {
            super.hide(autoClosed);
            pageBackground.setVisible(false);
            GlassPane.getInstance().hide();
        }

        protected void onPreviewNativeEvent(final NativePreviewEvent event) {
            // Switch on the event type
            int type = event.getTypeInt();
            switch(type) {
                case Event.ONKEYDOWN:
                    {
                        Event nativeEvent = Event.as(event.getNativeEvent());
                        if ((char) nativeEvent.getKeyCode() == KeyCodes.KEY_ESCAPE) {
                            event.cancel();
                            hide();
                        }
                        return;
                    }
            }
        }
    };
    if (popup.isShowing()) {
        popup.hide();
        return;
    }
    // $NON-NLS-1$
    String url = GWT.getHostPageBaseURL() + "api/plugin-manager/settings/new-toolbar-button";
    RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url);
    // $NON-NLS-1$//$NON-NLS-2$
    rb.setHeader("Content-Type", "text/plain");
    // $NON-NLS-1$//$NON-NLS-2$
    rb.setHeader("accept", "application/json");
    rb.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    try {
        rb.sendRequest(null, new RequestCallback() {

            @Override
            public void onError(Request request, Throwable exception) {
                MessageDialogBox dialogBox = new // $NON-NLS-1$ //$NON-NLS-2$
                MessageDialogBox(// $NON-NLS-1$ //$NON-NLS-2$
                Messages.getString("error"), // $NON-NLS-1$ //$NON-NLS-2$
                exception.getMessage(), false, false, true);
                dialogBox.center();
            }

            @Override
            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == 200) {
                    JsArray<JsCreateNewConfig> jsarray = parseJson(JsonUtils.escapeJsonForEval(response.getText()));
                    final ArrayList<JsCreateNewConfig> sorted = new ArrayList<JsCreateNewConfig>();
                    for (int i = 0; i < jsarray.length(); i++) {
                        sorted.add(jsarray.get(i));
                    }
                    Collections.sort(sorted, new JsCreateNewConfigComparator());
                    popup.setStyleName("newToolbarDropdown");
                    VerticalPanel buttonPanel = new VerticalPanel();
                    popup.add(buttonPanel);
                    for (int i = 0; i < sorted.size(); i++) {
                        final int finali = i;
                        String enabledUrl = sorted.get(i).getEnabledUrl();
                        if (buttonEnabled(enabledUrl)) {
                            Button button = new Button(Messages.getString(sorted.get(i).getLabel()));
                            button.setStyleName("pentaho-button");
                            button.getElement().addClassName("newToolbarDropdownButton");
                            button.addClickHandler(new ClickHandler() {

                                public void onClick(ClickEvent event) {
                                    if (sorted.get(finali).getActionUrl().startsWith("javascript:")) {
                                        doEvalJS(sorted.get(finali).getActionUrl().substring("javascript:".length()));
                                    } else {
                                        SolutionBrowserPanel.getInstance().getContentTabPanel().showNewURLTab(Messages.getString(sorted.get(finali).getTabName()), Messages.getString(sorted.get(finali).getTabName()), sorted.get(finali).getActionUrl(), false);
                                    }
                                    popup.hide();
                                }
                            });
                            String name = sorted.get(i).getName();
                            if ("data-access".equals(name)) {
                                buttonPanel.add(new HTML("<hr style='color: #a7a7a7' />"));
                            }
                            buttonPanel.add(button);
                        }
                    }
                    popup.setPopupPosition(anchorWidget.getAbsoluteLeft(), anchorWidget.getAbsoluteTop() + anchorWidget.getOffsetHeight());
                    popup.show();
                } else {
                    MessageDialogBox dialogBox = new // $NON-NLS-1$ //$NON-NLS-2$
                    MessageDialogBox(// $NON-NLS-1$ //$NON-NLS-2$
                    Messages.getString("error"), // $NON-NLS-1$ //$NON-NLS-2$
                    Messages.getString("error"), false, false, true);
                    dialogBox.center();
                }
            }

            private boolean buttonEnabled(String enabledUrl) {
                if (enabledUrl == null || enabledUrl.isEmpty()) {
                    return true;
                } else {
                    Boolean enabled = false;
                    try {
                        enabled = Boolean.valueOf(sendRequest(enabledUrl));
                    } catch (Exception e) {
                    }
                    return enabled;
                }
            }
        });
    } catch (RequestException e) {
        MessageDialogBox dialogBox = new // $NON-NLS-1$ //$NON-NLS-2$
        MessageDialogBox(// $NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("error"), // $NON-NLS-1$ //$NON-NLS-2$
        e.getMessage(), false, false, true);
        dialogBox.center();
    }
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) PopupPanel(com.google.gwt.user.client.ui.PopupPanel) ArrayList(java.util.ArrayList) HTML(com.google.gwt.user.client.ui.HTML) FocusPanel(com.google.gwt.user.client.ui.FocusPanel) RequestException(com.google.gwt.http.client.RequestException) Button(com.google.gwt.user.client.ui.Button) JsCreateNewConfigComparator(org.pentaho.mantle.client.objects.JsCreateNewConfigComparator) JsArray(com.google.gwt.core.client.JsArray) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) NativePreviewEvent(com.google.gwt.user.client.Event.NativePreviewEvent) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) RequestCallback(com.google.gwt.http.client.RequestCallback) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Event(com.google.gwt.user.client.Event) NativePreviewEvent(com.google.gwt.user.client.Event.NativePreviewEvent) JsCreateNewConfig(org.pentaho.mantle.client.objects.JsCreateNewConfig)

Example 14 with MessageDialogBox

use of org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox in project pentaho-platform by pentaho.

the class NewFolderCommand method performOperation.

protected void performOperation(boolean feedback) {
    final SolutionFolderActionEvent event = new SolutionFolderActionEvent();
    event.setAction(this.getClass().getName());
    final TextBox folderNameTextBox = new TextBox();
    folderNameTextBox.setTabIndex(1);
    folderNameTextBox.setVisibleLength(40);
    VerticalPanel vp = new VerticalPanel();
    // $NON-NLS-1$
    vp.add(new Label(Messages.getString("newFolderName")));
    vp.add(folderNameTextBox);
    final PromptDialogBox newFolderDialog = new PromptDialogBox(Messages.getString("newFolder"), Messages.getString("ok"), Messages.getString("cancel"), false, true, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    vp);
    newFolderDialog.setFocusWidget(folderNameTextBox);
    folderNameTextBox.setFocus(true);
    final IDialogCallback callback = new IDialogCallback() {

        public void cancelPressed() {
            newFolderDialog.hide();
        }

        public void okPressed() {
            if (!NameUtils.isValidFolderName(folderNameTextBox.getText())) {
                event.setMessage(Messages.getString("containsIllegalCharacters", folderNameTextBox.getText()));
                EventBusUtil.EVENT_BUS.fireEvent(event);
                return;
            }
            solutionPath = parentFolder.getPath() + "/" + URL.encodePathSegment(folderNameTextBox.getText());
            // $NON-NLS-1$
            String createDirUrl = contextURL + "api/repo/dirs/" + SolutionBrowserPanel.pathToId(solutionPath);
            RequestBuilder createDirRequestBuilder = new RequestBuilder(RequestBuilder.PUT, createDirUrl);
            try {
                createDirRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
                createDirRequestBuilder.sendRequest("", new RequestCallback() {

                    @Override
                    public void onError(Request createFolderRequest, Throwable exception) {
                        MessageDialogBox dialogBox = new MessageDialogBox(// $NON-NLS-1$ //$NON-NLS-2$
                        Messages.getString("error"), // $NON-NLS-1$ //$NON-NLS-2$
                        Messages.getString("couldNotCreateFolder", folderNameTextBox.getText()), false, false, true);
                        dialogBox.center();
                        event.setMessage(Messages.getString("couldNotCreateFolder", folderNameTextBox.getText()));
                        EventBusUtil.EVENT_BUS.fireEvent(event);
                    }

                    @Override
                    public void onResponseReceived(Request createFolderRequest, Response createFolderResponse) {
                        if (createFolderResponse.getStatusCode() == 200) {
                            NewFolderCommand.this.callback.onHandle(solutionPath);
                            new RefreshRepositoryCommand().execute(false);
                            event.setMessage("Success");
                            FileChooserDialog.setIsDirty(Boolean.TRUE);
                            setBrowseRepoDirty(Boolean.TRUE);
                            EventBusUtil.EVENT_BUS.fireEvent(event);
                        } else {
                            event.setMessage(StringUtils.isEmpty(createFolderResponse.getText()) || Messages.getString(createFolderResponse.getText()) == null ? // $NON-NLS-1$
                            Messages.getString("couldNotCreateFolder", folderNameTextBox.getText()) : Messages.getString(createFolderResponse.getText(), folderNameTextBox.getText()));
                            EventBusUtil.EVENT_BUS.fireEvent(event);
                        }
                    }
                });
            } catch (RequestException e) {
                Window.alert(e.getLocalizedMessage());
                event.setMessage(e.getLocalizedMessage());
                EventBusUtil.EVENT_BUS.fireEvent(event);
            }
        }
    };
    newFolderDialog.setCallback(callback);
    newFolderDialog.center();
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) PromptDialogBox(org.pentaho.gwt.widgets.client.dialogs.PromptDialogBox) SolutionFolderActionEvent(org.pentaho.mantle.client.events.SolutionFolderActionEvent) Label(com.google.gwt.user.client.ui.Label) Request(com.google.gwt.http.client.Request) 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) RequestCallback(com.google.gwt.http.client.RequestCallback)

Example 15 with MessageDialogBox

use of org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox in project pentaho-platform by pentaho.

the class AbstractFilePickList method save.

/**
 * Convert the FilePickList to JSON and save it to a user setting
 *
 * @param settingName
 */
public void save(String settingName) {
    // $NON-NLS-1$
    final String url = GWT.getHostPageBaseURL() + "api/user-settings/" + settingName;
    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
    try {
        builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
        builder.sendRequest(toJson().toString(), new RequestCallback() {

            public void onError(Request request, Throwable exception) {
                MessageDialogBox dialog = new MessageDialogBox(Messages.getString("error"), Messages.getString("couldNotSetUserSettings"), true, false, // $NON-NLS-1$ //$NON-NLS-2$
                true);
                dialog.center();
            }

            public void onResponseReceived(Request request, Response response) {
                fireOnSavedEvent();
            }
        });
    } catch (RequestException e) {
    // showError(e);
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException)

Aggregations

MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)43 RequestException (com.google.gwt.http.client.RequestException)29 Request (com.google.gwt.http.client.Request)28 RequestBuilder (com.google.gwt.http.client.RequestBuilder)28 RequestCallback (com.google.gwt.http.client.RequestCallback)28 Response (com.google.gwt.http.client.Response)28 IDialogCallback (org.pentaho.gwt.widgets.client.dialogs.IDialogCallback)9 JSONString (com.google.gwt.json.client.JSONString)7 PromptDialogBox (org.pentaho.gwt.widgets.client.dialogs.PromptDialogBox)6 JsArrayString (com.google.gwt.core.client.JsArrayString)5 Label (com.google.gwt.user.client.ui.Label)5 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)5 HTML (com.google.gwt.user.client.ui.HTML)4 TextBox (com.google.gwt.user.client.ui.TextBox)3 Widget (com.google.gwt.user.client.ui.Widget)3 JsArray (com.google.gwt.core.client.JsArray)2 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 JSONObject (com.google.gwt.json.client.JSONObject)2 Button (com.google.gwt.user.client.ui.Button)2