Search in sources :

Example 1 with SolutionBrowserFile

use of org.pentaho.mantle.client.solutionbrowser.SolutionBrowserFile in project pentaho-platform by pentaho.

the class CopyFilesCommand method performOperation.

/*
         * (non-Javadoc)
         *
         * @see org.pentaho.mantle.client.commands.AbstractCommand#performOperation()
         */
@Override
protected void performOperation() {
    event.setMessage("Click");
    EventBusUtil.EVENT_BUS.fireEvent(event);
    if (this.getSolutionPath() != null && this.getFileNames() != null && this.getFileIds() != null) {
        StringTokenizer pathTk = new StringTokenizer(this.getSolutionPath(), "\n");
        StringTokenizer nameTk = new StringTokenizer(this.getFileNames(), "\n");
        StringTokenizer idTk = new StringTokenizer(this.getFileIds(), "\n");
        // Build Arrays since we cannot pass complex objects from the js bus
        for (int i = 0; i < pathTk.countTokens(); i++) {
            filesToCopy.add(new SolutionBrowserFile(idTk.tokenAt(i), nameTk.tokenAt(i), pathTk.tokenAt(i)));
        }
        performOperation(false);
    } else {
        performOperation(true);
    }
}
Also used : SolutionBrowserFile(org.pentaho.mantle.client.solutionbrowser.SolutionBrowserFile) StringTokenizer(org.pentaho.gwt.widgets.client.utils.string.StringTokenizer)

Example 2 with SolutionBrowserFile

use of org.pentaho.mantle.client.solutionbrowser.SolutionBrowserFile in project pentaho-platform by pentaho.

the class CutFilesCommand method performOperation.

/*
     * (non-Javadoc)
     *
     * @see org.pentaho.mantle.client.commands.AbstractCommand#performOperation()
     */
@Override
protected void performOperation() {
    event.setMessage("Click");
    EventBusUtil.EVENT_BUS.fireEvent(event);
    if (this.getSolutionPath() != null && this.getFileNames() != null && this.getFileIds() != null) {
        StringTokenizer pathTk = new StringTokenizer(this.getSolutionPath(), "\n");
        StringTokenizer nameTk = new StringTokenizer(this.getFileNames(), "\n");
        StringTokenizer idTk = new StringTokenizer(this.getFileIds(), "\n");
        // Build Arrays since we cannot pass complex objects from the js bus
        for (int i = 0; i < pathTk.countTokens(); i++) {
            filesToCut.add(new SolutionBrowserFile(idTk.tokenAt(i), nameTk.tokenAt(i), pathTk.tokenAt(i)));
        }
        performOperation(false);
    } else {
        performOperation(true);
    }
}
Also used : SolutionBrowserFile(org.pentaho.mantle.client.solutionbrowser.SolutionBrowserFile) StringTokenizer(org.pentaho.gwt.widgets.client.utils.string.StringTokenizer)

Example 3 with SolutionBrowserFile

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

use of org.pentaho.mantle.client.solutionbrowser.SolutionBrowserFile in project pentaho-platform by pentaho.

the class DeleteFileCommand method doDelete.

public void doDelete(String filesList, final SolutionFileActionEvent event) {
    // $NON-NLS-1$
    String deleteFilesURL = contextURL + "api/repo/files/delete";
    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) {
                    event.setMessage("Success");
                    EventBusUtil.EVENT_BUS.fireEvent(event);
                    new RefreshRepositoryCommand().execute(false);
                    FileChooserDialog.setIsDirty(Boolean.TRUE);
                    setBrowseRepoDirty(Boolean.TRUE);
                    for (SolutionBrowserFile file : filesToDelete) {
                        if (file.getPath() != null) {
                            SolutionBrowserPanel.getInstance().removeRecent(file.getPath());
                            SolutionBrowserPanel.getInstance().removeFavorite(file.getPath());
                        }
                    }
                } 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);
    }
}
Also used : Response(com.google.gwt.http.client.Response) SolutionBrowserFile(org.pentaho.mantle.client.solutionbrowser.SolutionBrowserFile) 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)

Example 5 with SolutionBrowserFile

use of org.pentaho.mantle.client.solutionbrowser.SolutionBrowserFile in project pentaho-platform by pentaho.

the class PasteFilesCommand method performOperation.

/*
   * (non-Javadoc)
   *
   * @see org.pentaho.mantle.client.commands.AbstractCommand#performOperation(boolean)
   */
@Override
protected void performOperation(boolean feedback) {
    final SolutionBrowserClipboard clipBoard = SolutionBrowserClipboard.getInstance();
    @SuppressWarnings("unchecked") final List<SolutionBrowserFile> clipboardFileItems = clipBoard.getClipboardItems();
    if (clipboardFileItems != null && clipboardFileItems.size() > 0 && getSolutionPath() != null) {
        String getChildrenUrl = contextURL + "api/repo/files/" + SolutionBrowserPanel.pathToId(getSolutionPath()) + "/tree?depth=1" + "&showHidden=" + // $NON-NLS-1$ //$NON-NLS-2$
        SolutionBrowserPanel.getInstance().getSolutionTree().isShowHiddenFiles();
        RequestBuilder childrenRequestBuilder = new RequestBuilder(RequestBuilder.GET, getChildrenUrl);
        try {
            childrenRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
            childrenRequestBuilder.sendRequest(null, new RequestCallback() {

                @Override
                public void onError(Request getChildrenRequest, Throwable exception) {
                    Window.alert(exception.getLocalizedMessage());
                    event.setMessage(exception.getLocalizedMessage());
                    EventBusUtil.EVENT_BUS.fireEvent(event);
                }

                @Override
                public void onResponseReceived(Request getChildrenRequest, Response getChildrenResponse) {
                    event.setMessage("Click");
                    EventBusUtil.EVENT_BUS.fireEvent(event);
                    boolean cutSameDir = false;
                    if (getChildrenResponse.getStatusCode() >= 200 && getChildrenResponse.getStatusCode() < 300) {
                        boolean promptForOptions = false;
                        Document children = XMLParser.parse(getChildrenResponse.getText());
                        NodeList childrenNameNodes = children.getElementsByTagName(NAME_NODE_TAG);
                        List<String> childNames = new ArrayList<String>();
                        for (int i = 0; i < childrenNameNodes.getLength(); i++) {
                            Node childNameNode = childrenNameNodes.item(i);
                            childNames.add(childNameNode.getFirstChild().getNodeValue());
                        }
                        for (SolutionBrowserFile file : clipboardFileItems) {
                            if (file.getPath() != null) {
                                String pasteFileParentPath = file.getPath();
                                // $NON-NLS-1$
                                String fileNameWithExt = pasteFileParentPath.substring(pasteFileParentPath.lastIndexOf("/") + 1, pasteFileParentPath.length());
                                // $NON-NLS-1$
                                pasteFileParentPath = pasteFileParentPath.substring(0, pasteFileParentPath.lastIndexOf("/"));
                                if (childNames.contains(fileNameWithExt) && !getSolutionPath().equals(pasteFileParentPath)) {
                                    promptForOptions = true;
                                    break;
                                } else if (childNames.contains(fileNameWithExt) && getSolutionPath().equals(pasteFileParentPath) && SolutionBrowserClipboard.getInstance().getClipboardAction() == SolutionBrowserClipboard.ClipboardAction.CUT) {
                                    cutSameDir = true;
                                    break;
                                }
                            }
                        }
                        if (promptForOptions) {
                            final OverwritePromptDialog overwriteDialog = new OverwritePromptDialog();
                            final IDialogCallback callback = new IDialogCallback() {

                                public void cancelPressed() {
                                    event.setMessage("Cancel");
                                    EventBusUtil.EVENT_BUS.fireEvent(event);
                                    overwriteDialog.hide();
                                }

                                public void okPressed() {
                                    performSave(clipBoard, overwriteDialog.getOverwriteMode());
                                }
                            };
                            overwriteDialog.setCallback(callback);
                            overwriteDialog.center();
                        } else {
                            if (!cutSameDir) {
                                performSave(clipBoard, 2);
                            } else {
                                event.setMessage("Cancel");
                                EventBusUtil.EVENT_BUS.fireEvent(event);
                            }
                        }
                    } else {
                        Window.alert(getChildrenResponse.getText());
                    }
                }
            });
        } catch (RequestException e) {
            Window.alert(e.getLocalizedMessage());
        }
    }
}
Also used : SolutionBrowserFile(org.pentaho.mantle.client.solutionbrowser.SolutionBrowserFile) RequestBuilder(com.google.gwt.http.client.RequestBuilder) NodeList(com.google.gwt.xml.client.NodeList) Node(com.google.gwt.xml.client.Node) Request(com.google.gwt.http.client.Request) Document(com.google.gwt.xml.client.Document) 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) OverwritePromptDialog(org.pentaho.mantle.client.dialogs.OverwritePromptDialog) ArrayList(java.util.ArrayList) List(java.util.List) NodeList(com.google.gwt.xml.client.NodeList) SolutionBrowserClipboard(org.pentaho.mantle.client.solutionbrowser.SolutionBrowserClipboard)

Aggregations

SolutionBrowserFile (org.pentaho.mantle.client.solutionbrowser.SolutionBrowserFile)7 Request (com.google.gwt.http.client.Request)3 RequestBuilder (com.google.gwt.http.client.RequestBuilder)3 RequestCallback (com.google.gwt.http.client.RequestCallback)3 RequestException (com.google.gwt.http.client.RequestException)3 Response (com.google.gwt.http.client.Response)3 StringTokenizer (org.pentaho.gwt.widgets.client.utils.string.StringTokenizer)3 IDialogCallback (org.pentaho.gwt.widgets.client.dialogs.IDialogCallback)2 HTML (com.google.gwt.user.client.ui.HTML)1 Document (com.google.gwt.xml.client.Document)1 Node (com.google.gwt.xml.client.Node)1 NodeList (com.google.gwt.xml.client.NodeList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)1 PromptDialogBox (org.pentaho.gwt.widgets.client.dialogs.PromptDialogBox)1 OverwritePromptDialog (org.pentaho.mantle.client.dialogs.OverwritePromptDialog)1 SolutionFileActionEvent (org.pentaho.mantle.client.events.SolutionFileActionEvent)1 SolutionBrowserClipboard (org.pentaho.mantle.client.solutionbrowser.SolutionBrowserClipboard)1