Search in sources :

Example 1 with SolutionFileActionEvent

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

the class DeleteFileCommand method performOperation.

protected void performOperation(boolean feedback) {
    final SolutionFileActionEvent event = new SolutionFileActionEvent();
    event.setAction(this.getClass().getName());
    String temp = "";
    String names = "";
    // Convert to a comma delimted list for rest call
    for (SolutionBrowserFile file : filesToDelete) {
        // $NON-NLS-1$
        temp += file.getId() + ",";
        // $NON-NLS-1$
        names += file.getName() + ",";
    }
    // remove trailing ","
    temp = temp.substring(0, temp.length() - 1);
    names = names.substring(0, names.length() - 1);
    final String filesList = temp;
    if (feedback) {
        final HTML messageTextBox;
        if (filesToDelete.size() > 1) {
            messageTextBox = new HTML(Messages.getString("moveAllToTrashQuestionFile"));
        } else {
            messageTextBox = new HTML(Messages.getString("moveToTrashQuestionFile", names));
        }
        final PromptDialogBox fileMoveToTrashWarningDialogBox = new PromptDialogBox(Messages.getString("moveToTrash"), Messages.getString("yesMoveToTrash"), Messages.getString("no"), true, true);
        fileMoveToTrashWarningDialogBox.setContent(messageTextBox);
        final IDialogCallback callback = new IDialogCallback() {

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

            public void okPressed() {
                doDelete(filesList, event);
            }
        };
        fileMoveToTrashWarningDialogBox.setCallback(callback);
        fileMoveToTrashWarningDialogBox.center();
    } else {
        doDelete(filesList, event);
    }
}
Also used : SolutionBrowserFile(org.pentaho.mantle.client.solutionbrowser.SolutionBrowserFile) PromptDialogBox(org.pentaho.gwt.widgets.client.dialogs.PromptDialogBox) HTML(com.google.gwt.user.client.ui.HTML) SolutionFileActionEvent(org.pentaho.mantle.client.events.SolutionFileActionEvent) IDialogCallback(org.pentaho.gwt.widgets.client.dialogs.IDialogCallback)

Example 2 with SolutionFileActionEvent

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

the class ExportFileCommand method performOperation.

protected void performOperation(boolean feedback) {
    String path = repositoryFile.getPath();
    String moduleBaseURL = GWT.getModuleBaseURL();
    String moduleName = GWT.getModuleName();
    String contextURL = moduleBaseURL.substring(0, moduleBaseURL.lastIndexOf(moduleName));
    String exportURL = contextURL + "api/repo/files/" + SolutionBrowserPanel.pathToId(path) + "/download?withManifest=true";
    Window.open(exportURL, "_new", "");
    final SolutionFileActionEvent event = new SolutionFileActionEvent();
    event.setAction(this.getClass().getName());
    event.setMessage("Success");
    EventBusUtil.EVENT_BUS.fireEvent(event);
}
Also used : SolutionFileActionEvent(org.pentaho.mantle.client.events.SolutionFileActionEvent)

Example 3 with SolutionFileActionEvent

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

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

the class AbstractFilePropertiesCommand method performOperation.

public void performOperation() {
    final SolutionFileActionEvent event = new SolutionFileActionEvent();
    event.setAction(this.getClass().getName());
    if (getRepositoryFile() != null) {
        final RepositoryFile item = getRepositoryFile();
        // Checking if the user has access to manage permissions
        String url = contextURL + "api/repo/files/" + SolutionBrowserPanel.pathToId(item.getPath()) + "/canAccess?permissions=" + // $NON-NLS-1$ //$NON-NLS-2$
        MANAGE_ACLS;
        RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
        try {
            builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
            builder.sendRequest(null, new RequestCallback() {

                public void onError(Request request, Throwable exception) {
                    FilePropertiesDialog dialog = new FilePropertiesDialog(item, new PentahoTabPanel(), null, getActiveTab(), false);
                    dialog.showTab(getActiveTab());
                    dialog.center();
                    event.setMessage(exception.getMessage());
                    EventBusUtil.EVENT_BUS.fireEvent(event);
                }

                public void onResponseReceived(Request request, Response response) {
                    FilePropertiesDialog dialog = new FilePropertiesDialog(item, new PentahoTabPanel(), null, getActiveTab(), Boolean.parseBoolean(response.getText()));
                    dialog.showTab(getActiveTab());
                    dialog.center();
                    event.setMessage("Success");
                    EventBusUtil.EVENT_BUS.fireEvent(event);
                }
            });
        } catch (RequestException e) {
            FilePropertiesDialog dialog = new FilePropertiesDialog(item, new PentahoTabPanel(), null, getActiveTab(), false);
            dialog.showTab(getActiveTab());
            dialog.center();
            event.setMessage(e.getMessage());
            EventBusUtil.EVENT_BUS.fireEvent(event);
        }
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) FilePropertiesDialog(org.pentaho.mantle.client.solutionbrowser.fileproperties.FilePropertiesDialog) Request(com.google.gwt.http.client.Request) RepositoryFile(org.pentaho.gwt.widgets.client.filechooser.RepositoryFile) PentahoTabPanel(org.pentaho.gwt.widgets.client.tabs.PentahoTabPanel) SolutionFileActionEvent(org.pentaho.mantle.client.events.SolutionFileActionEvent) RequestException(com.google.gwt.http.client.RequestException)

Example 5 with SolutionFileActionEvent

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

the class DeletePermanentFileCommand method performOperation.

/*
 * (non-Javadoc)
 *
 * @see com.google.gwt.user.client.Command#execute()
 */
protected void performOperation(boolean feedback) {
    final SolutionFileActionEvent event = new SolutionFileActionEvent();
    event.setAction(this.getClass().getName());
    VerticalPanel vp = new VerticalPanel();
    String deleteMessage;
    final PromptDialogBox deleteConfirmDialog;
    if (mode.equals("purge")) {
        deleteMessage = Messages.getString("deleteAllQuestion");
        deleteConfirmDialog = new PromptDialogBox(Messages.getString("emptyTrash"), Messages.getString("yesEmptyTrash"), Messages.getString("no"), false, true, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        vp);
    } else {
        if (MULTIPLE_DELETE_TYPE.equals(type)) {
            deleteMessage = Messages.getString("deleteMultiQuestion");
        } else {
            deleteMessage = Messages.getString("deleteQuestion", type);
        }
        deleteConfirmDialog = new PromptDialogBox(Messages.getString("permDelete"), Messages.getString("yesPermDelete"), Messages.getString("no"), false, true, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        vp);
    }
    // $NON-NLS-1$
    vp.add(new HTML(deleteMessage));
    final IDialogCallback callback = new IDialogCallback() {

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

        public void okPressed() {
            String temp = "";
            // Add js file list
            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/deletepermanent";
            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 // $NON-NLS-1$ //$NON-NLS-2$
                        MessageDialogBox(// $NON-NLS-1$ //$NON-NLS-2$
                        Messages.getString("error"), // $NON-NLS-1$ //$NON-NLS-2$
                        Messages.getString("couldNotDeleteFile"), false, false, true);
                        dialogBox.center();
                        event.setMessage(Messages.getString("couldNotDeleteFile"));
                        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 {
                            event.setMessage(Messages.getString("couldNotDeleteFile"));
                            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("couldNotDeleteFile"), false, false, true);
                dialogBox.center();
                event.setMessage(Messages.getString("couldNotDeleteFile"));
                EventBusUtil.EVENT_BUS.fireEvent(event);
            }
        }
    };
    if (!feedback) {
        callback.okPressed();
    } else {
        deleteConfirmDialog.setCallback(callback);
        deleteConfirmDialog.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) Request(com.google.gwt.http.client.Request) HTML(com.google.gwt.user.client.ui.HTML) SolutionFileActionEvent(org.pentaho.mantle.client.events.SolutionFileActionEvent) 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)

Aggregations

SolutionFileActionEvent (org.pentaho.mantle.client.events.SolutionFileActionEvent)6 Request (com.google.gwt.http.client.Request)4 RequestBuilder (com.google.gwt.http.client.RequestBuilder)4 RequestCallback (com.google.gwt.http.client.RequestCallback)4 RequestException (com.google.gwt.http.client.RequestException)4 Response (com.google.gwt.http.client.Response)4 RepositoryFile (org.pentaho.gwt.widgets.client.filechooser.RepositoryFile)3 HTML (com.google.gwt.user.client.ui.HTML)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 PentahoTabPanel (org.pentaho.gwt.widgets.client.tabs.PentahoTabPanel)2 FilePropertiesDialog (org.pentaho.mantle.client.solutionbrowser.fileproperties.FilePropertiesDialog)2 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)1 SolutionBrowserFile (org.pentaho.mantle.client.solutionbrowser.SolutionBrowserFile)1