Search in sources :

Example 1 with RepositoryFileTree

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

the class FolderCommand method execute.

public void execute() {
    if (popupMenu != null) {
        popupMenu.hide();
    }
    SolutionBrowserPanel sbp = SolutionBrowserPanel.getInstance();
    if (mode == COMMAND.PROPERTIES) {
        new FilePropertiesCommand(repositoryFile).execute();
    } else if (mode == COMMAND.DELETE) {
        TreeItem item = sbp.getSolutionTree().getSelectedItem();
        RepositoryFileTree tree = (RepositoryFileTree) item.getUserObject();
        new DeleteFolderCommand(tree.getFile()).execute();
    } else if (mode == COMMAND.CREATE_FOLDER) {
        TreeItem item = sbp.getSolutionTree().getSelectedItem();
        RepositoryFileTree tree = (RepositoryFileTree) item.getUserObject();
        new NewFolderCommand(tree.getFile()).execute();
    } else if (mode == COMMAND.EXPORT) {
        new ExportFileCommand(repositoryFile).execute();
    } else if (mode == COMMAND.IMPORT) {
        new ImportFileCommand(repositoryFile).execute();
    } else if (mode == COMMAND.PASTE) {
        new PasteFilesCommand().execute();
    } else if (mode == COMMAND.EMPTY_TRASH) {
        new DeletePermanentFileCommand().execute();
    }
}
Also used : ImportFileCommand(org.pentaho.mantle.client.commands.ImportFileCommand) DeletePermanentFileCommand(org.pentaho.mantle.client.commands.DeletePermanentFileCommand) TreeItem(com.google.gwt.user.client.ui.TreeItem) FilePropertiesCommand(org.pentaho.mantle.client.commands.FilePropertiesCommand) NewFolderCommand(org.pentaho.mantle.client.commands.NewFolderCommand) PasteFilesCommand(org.pentaho.mantle.client.commands.PasteFilesCommand) RepositoryFileTree(org.pentaho.gwt.widgets.client.filechooser.RepositoryFileTree) ExportFileCommand(org.pentaho.mantle.client.commands.ExportFileCommand) DeleteFolderCommand(org.pentaho.mantle.client.commands.DeleteFolderCommand)

Example 2 with RepositoryFileTree

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

Example 3 with RepositoryFileTree

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

the class SolutionTree method buildSolutionTree.

private void buildSolutionTree(FileTreeItem parentTreeItem, RepositoryFileTree repositoryFileTree) {
    List<RepositoryFileTree> children = repositoryFileTree.getChildren();
    // BISERVER-9599 - Custom Sort
    Collections.sort(children, new Comparator<RepositoryFileTree>() {

        @Override
        public int compare(RepositoryFileTree repositoryFileTree, RepositoryFileTree repositoryFileTree2) {
            return (new TreeItemComparator()).compare(repositoryFileTree.getFile().getTitle(), repositoryFileTree2.getFile().getTitle());
        }
    });
    for (RepositoryFileTree treeItem : children) {
        RepositoryFile file = treeItem.getFile();
        boolean isDirectory = file.isFolder();
        String fileName = file.getName();
        if ((!file.isHidden() || isShowHiddenFiles()) && !StringUtils.isEmpty(fileName)) {
            // TODO Mapping Title to LocalizedName
            String localizedName = file.getTitle();
            String description = file.getDescription();
            FileTreeItem childTreeItem = new FileTreeItem();
            childTreeItem.setStylePrimaryName("leaf-widget");
            // $NON-NLS-1$
            childTreeItem.getElement().setAttribute("id", file.getPath());
            childTreeItem.setUserObject(treeItem);
            childTreeItem.setRepositoryFile(file);
            if (file.isHidden() && file.isFolder()) {
                childTreeItem.addStyleDependentName("hidden");
            }
            if (treeItem != null && treeItem.getChildren() != null) {
                for (RepositoryFileTree childItem : treeItem.getChildren()) {
                    if (childItem.getFile().isFolder()) {
                        childTreeItem.addStyleName("parent-widget");
                        break;
                    }
                }
            }
            ElementUtils.killAllTextSelection(childTreeItem.getElement());
            childTreeItem.setURL(fileName);
            if (showLocalizedFileNames) {
                childTreeItem.setText(localizedName);
                if (isUseDescriptionsForTooltip() && !StringUtils.isEmpty(description)) {
                    childTreeItem.setTitle(description);
                } else {
                    childTreeItem.setTitle(fileName);
                }
            } else {
                childTreeItem.setText(fileName);
                if (isUseDescriptionsForTooltip() && !StringUtils.isEmpty(description)) {
                    childTreeItem.setTitle(description);
                } else {
                    childTreeItem.setTitle(localizedName);
                }
            }
            childTreeItem.setFileName(fileName);
            if (parentTreeItem == null && isDirectory) {
                addItem(childTreeItem);
            } else if (parentTreeItem != null) {
                parentTreeItem.addItem(childTreeItem);
            }
            FileTreeItem tmpParent = childTreeItem;
            String pathToChild = tmpParent.getFileName();
            while (tmpParent.getParentItem() != null) {
                tmpParent = (FileTreeItem) tmpParent.getParentItem();
                // $NON-NLS-1$
                pathToChild = tmpParent.getFileName() + "/" + pathToChild;
            }
            /*
         * TODO Not sure what to do here if (parentTreeItem != null) { ArrayList<FileChooserRepositoryFile> files =
         * (ArrayList<FileChooserRepositoryFile>) parentTreeItem.getUserObject(); if (files == null) { files = new
         * ArrayList<FileChooserRepositoryFile>(); parentTreeItem.setUserObject(files); } files.add(file); }
         */
            if (isDirectory) {
                buildSolutionTree(childTreeItem, treeItem);
            } else {
                if (parentTreeItem != null) {
                    parentTreeItem.removeItem(childTreeItem);
                }
            }
        }
    }
}
Also used : TreeItemComparator(org.pentaho.gwt.widgets.client.filechooser.TreeItemComparator) RepositoryFile(org.pentaho.gwt.widgets.client.filechooser.RepositoryFile) RepositoryFileTree(org.pentaho.gwt.widgets.client.filechooser.RepositoryFileTree)

Example 4 with RepositoryFileTree

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

the class RepositoryFileUtils method convertFromRepositoryFileTree.

public static RepositoryFileTreeDto convertFromRepositoryFileTree(RepositoryFileTree tree) {
    RepositoryFileTreeDto fileTreeDto = new RepositoryFileTreeDto();
    List<RepositoryFileTreeDto> fileList = new ArrayList<RepositoryFileTreeDto>();
    RepositoryFileDto file = convertFromRepositoryFile(tree.getFile());
    fileTreeDto.setFile(file);
    for (RepositoryFileTree treeItem : tree.getChildren()) {
        fileList.add(convertFromRepositoryFileTree(treeItem));
    }
    fileTreeDto.setChildren(fileList);
    return fileTreeDto;
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) RepositoryFileTreeDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileTreeDto) ArrayList(java.util.ArrayList) RepositoryFileTree(org.pentaho.gwt.widgets.client.filechooser.RepositoryFileTree)

Example 5 with RepositoryFileTree

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

the class RepositoryFileUtils method convertToRepositoryFileTree.

public static RepositoryFileTree convertToRepositoryFileTree(RepositoryFileTreeDto tree) {
    RepositoryFileTree fileTree = new RepositoryFileTree();
    List<RepositoryFileTree> fileList = new ArrayList<RepositoryFileTree>();
    RepositoryFile file = convertToRepositoryFile(tree.getFile());
    fileTree.setFile(file);
    for (RepositoryFileTreeDto treeItem : tree.getChildren()) {
        fileList.add(convertToRepositoryFileTree(treeItem));
    }
    fileTree.setChildren(fileList);
    return fileTree;
}
Also used : RepositoryFileTreeDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileTreeDto) ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.gwt.widgets.client.filechooser.RepositoryFile) RepositoryFileTree(org.pentaho.gwt.widgets.client.filechooser.RepositoryFileTree)

Aggregations

RepositoryFileTree (org.pentaho.gwt.widgets.client.filechooser.RepositoryFileTree)9 RepositoryFile (org.pentaho.gwt.widgets.client.filechooser.RepositoryFile)6 JsArrayString (com.google.gwt.core.client.JsArrayString)2 ArrayList (java.util.ArrayList)2 FileChooserDialog (org.pentaho.gwt.widgets.client.filechooser.FileChooserDialog)2 FileChooserListener (org.pentaho.gwt.widgets.client.filechooser.FileChooserListener)2 SolutionBrowserPanel (org.pentaho.mantle.client.solutionbrowser.SolutionBrowserPanel)2 RepositoryFileTreeDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileTreeDto)2 Request (com.google.gwt.http.client.Request)1 RequestBuilder (com.google.gwt.http.client.RequestBuilder)1 RequestCallback (com.google.gwt.http.client.RequestCallback)1 RequestException (com.google.gwt.http.client.RequestException)1 Response (com.google.gwt.http.client.Response)1 DialogBox (com.google.gwt.user.client.ui.DialogBox)1 Label (com.google.gwt.user.client.ui.Label)1 TreeItem (com.google.gwt.user.client.ui.TreeItem)1 IDialogCallback (org.pentaho.gwt.widgets.client.dialogs.IDialogCallback)1 PromptDialogBox (org.pentaho.gwt.widgets.client.dialogs.PromptDialogBox)1 JsonToRepositoryFileTreeConverter (org.pentaho.gwt.widgets.client.filechooser.JsonToRepositoryFileTreeConverter)1 TreeItemComparator (org.pentaho.gwt.widgets.client.filechooser.TreeItemComparator)1