Search in sources :

Example 6 with RepositoryFile

use of org.pentaho.gwt.widgets.client.filechooser.RepositoryFile 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 7 with RepositoryFile

use of org.pentaho.gwt.widgets.client.filechooser.RepositoryFile in project pentaho-platform by pentaho.

the class ShareFileCommand method execute.

public void execute() {
    final SolutionBrowserPanel sbp = SolutionBrowserPanel.getInstance();
    if (this.getSolutionPath() != null) {
        selectedList = new ArrayList<RepositoryFile>();
        sbp.getFile(this.getSolutionPath(), new SolutionFileHandler() {

            @Override
            public void handle(RepositoryFile repositoryFile) {
                selectedList.add(repositoryFile);
                performOperation();
            }
        });
    } else {
        selectedList = sbp.getFilesListPanel().getRepositoryFiles();
        performOperation();
    }
}
Also used : SolutionFileHandler(org.pentaho.mantle.client.events.SolutionFileHandler) RepositoryFile(org.pentaho.gwt.widgets.client.filechooser.RepositoryFile) SolutionBrowserPanel(org.pentaho.mantle.client.solutionbrowser.SolutionBrowserPanel)

Example 8 with RepositoryFile

use of org.pentaho.gwt.widgets.client.filechooser.RepositoryFile in project pentaho-platform by pentaho.

the class ImportFileCommand method performOperation.

protected void performOperation() {
    if (this.getSolutionPath() != null) {
        SolutionBrowserPanel sbp = SolutionBrowserPanel.getInstance();
        sbp.getFile(this.getSolutionPath(), new SolutionFileHandler() {

            @Override
            public void handle(RepositoryFile repositoryFile) {
                ImportFileCommand.this.repositoryFile = repositoryFile;
                performOperation(true);
            }
        });
    } else {
        performOperation(true);
    }
}
Also used : SolutionFileHandler(org.pentaho.mantle.client.events.SolutionFileHandler) RepositoryFile(org.pentaho.gwt.widgets.client.filechooser.RepositoryFile) SolutionBrowserPanel(org.pentaho.mantle.client.solutionbrowser.SolutionBrowserPanel)

Example 9 with RepositoryFile

use of org.pentaho.gwt.widgets.client.filechooser.RepositoryFile in project pentaho-platform by pentaho.

the class FilesListPanel method selectPreviousItem.

public void selectPreviousItem(List<FileItem> currentItems) {
    if (currentItems == null || currentItems.size() < 1) {
        return;
    }
    FileItem currentItem = currentItems.get(0);
    RepositoryFile currentRepositoryFile = currentItem.getRepositoryFile();
    int myIndex = -1;
    for (int i = 0; i < getFileCount(); i++) {
        FileItem fileItem = getFileItem(i);
        if (fileItem == currentItem) {
            myIndex = i;
        }
    }
    if (myIndex > 0 && myIndex < getFileCount()) {
        if (currentRepositoryFile.isHidden()) {
            // $NON-NLS-1$
            currentItem.setStyleName("hiddenFileLabel");
        } else {
            // $NON-NLS-1$
            currentItem.setStyleName("fileLabel");
        }
        FileItem previousItem = getFileItem(myIndex - 1);
        RepositoryFile previousCurrentRepositoryFile = previousItem.getRepositoryFile();
        if (previousCurrentRepositoryFile.isHidden()) {
            // $NON-NLS-1$
            previousItem.setStyleName("hiddenFileLabelSelected");
        } else {
            // $NON-NLS-1$
            previousItem.setStyleName("fileLabelSelected");
        }
        List<FileItem> fileItems = new ArrayList<FileItem>();
        fileItems.add(previousItem);
        setSelectedFileItems(fileItems);
        previousItem.fireFileSelectionEvent();
    }
}
Also used : ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.gwt.widgets.client.filechooser.RepositoryFile)

Example 10 with RepositoryFile

use of org.pentaho.gwt.widgets.client.filechooser.RepositoryFile in project pentaho-platform by pentaho.

the class RepositoryFileTreeManager method fetchRepositoryFileTree.

public void fetchRepositoryFileTree(final AsyncCallback<RepositoryFileTree> callback, Integer depth, String filter, Boolean showHidden) {
    // notify listeners that we are about to talk to the server (in case there's anything they want to do
    // such as busy cursor or tree loading indicators)
    beforeFetchRepositoryFileTree();
    RequestBuilder builder = null;
    // $NON-NLS-1$
    String url = GWT.getHostPageBaseURL() + "api/repo/files/:/tree?";
    if (depth == null) {
        depth = -1;
    }
    if (filter == null) {
        // $NON-NLS-1$
        filter = "*";
    }
    if (showHidden == null) {
        showHidden = Boolean.FALSE;
    }
    url = url + "depth=" + depth + "&filter=" + filter + "&showHidden=" + showHidden + "&ts=" + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    System.currentTimeMillis();
    builder = new RequestBuilder(RequestBuilder.GET, url);
    builder.setHeader("Accept", "application/json");
    builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    RequestCallback innerCallback = new RequestCallback() {

        public void onError(Request request, Throwable exception) {
            Window.alert(exception.toString());
        }

        public void onResponseReceived(Request request, Response response) {
            if (response.getStatusCode() == Response.SC_OK) {
                String json = response.getText();
                System.out.println(json);
                final JsonToRepositoryFileTreeConverter converter = new JsonToRepositoryFileTreeConverter(response.getText());
                fileTree = converter.getTree();
                String deletedFilesUrl = GWT.getHostPageBaseURL() + "api/repo/files/deleted?ts=" + System.currentTimeMillis();
                RequestBuilder deletedFilesRequestBuilder = new RequestBuilder(RequestBuilder.GET, deletedFilesUrl);
                deletedFilesRequestBuilder.setHeader("Accept", "application/json");
                deletedFilesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
                try {
                    deletedFilesRequestBuilder.sendRequest(null, new RequestCallback() {

                        public void onError(Request request, Throwable exception) {
                            fireRepositoryFileTreeFetched();
                            Window.alert(exception.toString());
                        }

                        public void onResponseReceived(Request delRequest, Response delResponse) {
                            if (delResponse.getStatusCode() == Response.SC_OK) {
                                try {
                                    trashItems = JsonToRepositoryFileTreeConverter.getTrashFiles(delResponse.getText());
                                } catch (Throwable t) {
                                // apparently this happens when you have no trash
                                }
                                fireRepositoryFileTreeFetched();
                            } else {
                                fireRepositoryFileTreeFetched();
                            }
                        }
                    });
                } catch (Exception e) {
                    fireRepositoryFileTreeFetched();
                }
                if (callback != null) {
                    callback.onSuccess(fileTree);
                }
            } else {
                fileTree = new RepositoryFileTree();
                RepositoryFile errorFile = new RepositoryFile();
                errorFile.setFolder(true);
                errorFile.setName("!ERROR!");
                fileTree.setFile(errorFile);
            }
        }
    };
    try {
        builder.sendRequest(null, innerCallback);
    } catch (RequestException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : 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) RepositoryFile(org.pentaho.gwt.widgets.client.filechooser.RepositoryFile) RequestException(com.google.gwt.http.client.RequestException) RequestException(com.google.gwt.http.client.RequestException) RepositoryFileTree(org.pentaho.gwt.widgets.client.filechooser.RepositoryFileTree) JsonToRepositoryFileTreeConverter(org.pentaho.gwt.widgets.client.filechooser.JsonToRepositoryFileTreeConverter)

Aggregations

RepositoryFile (org.pentaho.gwt.widgets.client.filechooser.RepositoryFile)23 SolutionBrowserPanel (org.pentaho.mantle.client.solutionbrowser.SolutionBrowserPanel)7 Request (com.google.gwt.http.client.Request)6 RequestBuilder (com.google.gwt.http.client.RequestBuilder)6 RequestCallback (com.google.gwt.http.client.RequestCallback)6 RequestException (com.google.gwt.http.client.RequestException)6 Response (com.google.gwt.http.client.Response)6 RepositoryFileTree (org.pentaho.gwt.widgets.client.filechooser.RepositoryFileTree)6 JsArrayString (com.google.gwt.core.client.JsArrayString)5 ArrayList (java.util.ArrayList)4 SolutionFileHandler (org.pentaho.mantle.client.events.SolutionFileHandler)4 FileChooserDialog (org.pentaho.gwt.widgets.client.filechooser.FileChooserDialog)3 FileChooserListener (org.pentaho.gwt.widgets.client.filechooser.FileChooserListener)3 SolutionFileActionEvent (org.pentaho.mantle.client.events.SolutionFileActionEvent)3 JSONObject (com.google.gwt.json.client.JSONObject)2 MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)2 TreeItemComparator (org.pentaho.gwt.widgets.client.filechooser.TreeItemComparator)2 PentahoTabPanel (org.pentaho.gwt.widgets.client.tabs.PentahoTabPanel)2 EmptyRequestCallback (org.pentaho.mantle.client.EmptyRequestCallback)2 ContentTypePlugin (org.pentaho.mantle.client.solutionbrowser.PluginOptionsHelper.ContentTypePlugin)2