Search in sources :

Example 6 with SolutionBrowserFile

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

the class DeleteFileCommand method performOperation.

protected void performOperation() {
    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++) {
            filesToDelete.add(new SolutionBrowserFile(idTk.tokenAt(i), nameTk.tokenAt(i), pathTk.tokenAt(i)));
        }
        performOperation(true);
    } else {
        performOperation(true);
    }
}
Also used : SolutionBrowserFile(org.pentaho.mantle.client.solutionbrowser.SolutionBrowserFile) StringTokenizer(org.pentaho.gwt.widgets.client.utils.string.StringTokenizer)

Example 7 with SolutionBrowserFile

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

the class PasteFilesCommand method performSave.

void performSave(final SolutionBrowserClipboard clipBoard, Integer overwriteMode) {
    @SuppressWarnings("unchecked") final List<SolutionBrowserFile> clipboardFileItems = clipBoard.getClipboardItems();
    // $NON-NLS-1$
    String temp = "";
    for (SolutionBrowserFile file : clipboardFileItems) {
        // $NON-NLS-1$
        temp += file.getId() + ",";
    }
    // remove trailing ","
    temp = temp.substring(0, temp.length() - 1);
    final String filesList = temp;
    String copyUrl = contextURL + "api/repo/files/" + SolutionBrowserPanel.pathToId(getSolutionPath()) + "/children?mode=" + // $NON-NLS-1$//$NON-NLS-2$
    overwriteMode;
    String moveUrl = contextURL + "api/repo/files/" + SolutionBrowserPanel.pathToId(getSolutionPath()) + // $NON-NLS-1$//$NON-NLS-2$
    "/move";
    RequestBuilder pasteChildrenRequestBuilder = new RequestBuilder(RequestBuilder.PUT, (SolutionBrowserClipboard.getInstance().getClipboardAction() == SolutionBrowserClipboard.ClipboardAction.CUT) ? moveUrl : copyUrl);
    // $NON-NLS-1$//$NON-NLS-2$
    pasteChildrenRequestBuilder.setHeader("Content-Type", "text/plain");
    pasteChildrenRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    try {
        pasteChildrenRequestBuilder.sendRequest(filesList, new RequestCallback() {

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

            @Override
            public void onResponseReceived(Request pasteChildrenRequest, Response pasteChildrenResponse) {
                switch(pasteChildrenResponse.getStatusCode()) {
                    case Response.SC_OK:
                        event.setMessage("Success");
                        EventBusUtil.EVENT_BUS.fireEvent(event);
                        FileChooserDialog.setIsDirty(Boolean.TRUE);
                        setBrowseRepoDirty(Boolean.TRUE);
                        // This will allow for multiple paste presses after a cut/paste.
                        SolutionBrowserClipboard.getInstance().setClipboardAction(SolutionBrowserClipboard.ClipboardAction.COPY);
                        break;
                    case Response.SC_FORBIDDEN:
                        event.setMessage(Messages.getString("pasteFilesCommand.accessDenied"));
                        EventBusUtil.EVENT_BUS.fireEvent(event);
                        break;
                    default:
                        event.setMessage(pasteChildrenResponse.getText());
                        EventBusUtil.EVENT_BUS.fireEvent(event);
                        break;
                }
            }
        });
    } catch (RequestException e) {
        Window.alert(e.getLocalizedMessage());
        event.setMessage(e.getLocalizedMessage());
        EventBusUtil.EVENT_BUS.fireEvent(event);
    }
}
Also used : SolutionBrowserFile(org.pentaho.mantle.client.solutionbrowser.SolutionBrowserFile) Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException)

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