Search in sources :

Example 1 with SolutionFolderActionEvent

use of org.pentaho.mantle.client.events.SolutionFolderActionEvent 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 2 with SolutionFolderActionEvent

use of org.pentaho.mantle.client.events.SolutionFolderActionEvent in project pentaho-platform by pentaho.

the class DeleteFolderCommand method performOperation.

protected void performOperation(boolean feedback) {
    final SolutionFolderActionEvent event = new SolutionFolderActionEvent();
    event.setAction(this.getClass().getName());
    final String filesList = repositoryFile.getId();
    final String folderName = repositoryFile.getTitle() == null ? repositoryFile.getName() : repositoryFile.getTitle();
    final HTML messageTextBox = new HTML(Messages.getString("moveToTrashQuestionFolder", escapeHtmlEntities(folderName)));
    final PromptDialogBox folderDeleteWarningDialogBox = new PromptDialogBox(Messages.getString("moveToTrash"), Messages.getString("yesMoveToTrash"), Messages.getString("no"), true, true);
    folderDeleteWarningDialogBox.setContent(messageTextBox);
    final IDialogCallback callback = new IDialogCallback() {

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

        public void okPressed() {
            // $NON-NLS-1$
            String deleteFilesURL = contextURL + "api/repo/files/delete";
            RequestBuilder deleteFilesRequestBuilder = new RequestBuilder(RequestBuilder.PUT, deleteFilesURL);
            deleteFilesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
            // $NON-NLS-1$//$NON-NLS-2$
            deleteFilesRequestBuilder.setHeader("Content-Type", "text/plain");
            try {
                deleteFilesRequestBuilder.sendRequest(filesList, 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$
                        Messages.getString("couldNotDeleteFolder"), false, false, true);
                        dialogBox.center();
                        event.setMessage(Messages.getString("couldNotDeleteFolder"));
                        EventBusUtil.EVENT_BUS.fireEvent(event);
                    }

                    @Override
                    public void onResponseReceived(Request request, Response response) {
                        if (response.getStatusCode() == 200) {
                            new RefreshRepositoryCommand().execute(false);
                            event.setMessage("Success");
                            FileChooserDialog.setIsDirty(Boolean.TRUE);
                            setBrowseRepoDirty(Boolean.TRUE);
                            EventBusUtil.EVENT_BUS.fireEvent(event);
                        } 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("couldNotDeleteFolder"), false, false, true);
                            dialogBox.center();
                            event.setMessage(Messages.getString("couldNotDeleteFolder"));
                            EventBusUtil.EVENT_BUS.fireEvent(event);
                        }
                    }
                });
            } 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$
                Messages.getString("couldNotDeleteFolder"), false, false, true);
                dialogBox.center();
                event.setMessage(Messages.getString("couldNotDeleteFolder"));
                EventBusUtil.EVENT_BUS.fireEvent(event);
            }
        }
    };
    folderDeleteWarningDialogBox.setCallback(callback);
    folderDeleteWarningDialogBox.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) Request(com.google.gwt.http.client.Request) HTML(com.google.gwt.user.client.ui.HTML) IDialogCallback(org.pentaho.gwt.widgets.client.dialogs.IDialogCallback) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) RequestCallback(com.google.gwt.http.client.RequestCallback)

Aggregations

Request (com.google.gwt.http.client.Request)2 RequestBuilder (com.google.gwt.http.client.RequestBuilder)2 RequestCallback (com.google.gwt.http.client.RequestCallback)2 RequestException (com.google.gwt.http.client.RequestException)2 Response (com.google.gwt.http.client.Response)2 IDialogCallback (org.pentaho.gwt.widgets.client.dialogs.IDialogCallback)2 MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)2 PromptDialogBox (org.pentaho.gwt.widgets.client.dialogs.PromptDialogBox)2 SolutionFolderActionEvent (org.pentaho.mantle.client.events.SolutionFolderActionEvent)2 HTML (com.google.gwt.user.client.ui.HTML)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