Search in sources :

Example 11 with RepositoryFile

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

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

Example 13 with RepositoryFile

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

the class RepositoryFileUtils method convertToRepositoryFile.

public static RepositoryFile convertToRepositoryFile(RepositoryFileDto file) {
    RepositoryFile repositoryFile = new RepositoryFile();
    repositoryFile.setCreatedDate(file.getCreatedDate());
    repositoryFile.setDeletedDate(file.getDeletedDate());
    repositoryFile.setDescription(file.getDescription());
    repositoryFile.setFolder(file.isFolder());
    repositoryFile.setHidden(file.isHidden());
    repositoryFile.setId(file.getId());
    repositoryFile.setLastModifiedDate(file.getLastModifiedDate());
    repositoryFile.setLocale(file.getLocale());
    repositoryFile.setLockDate(file.getLockDate());
    repositoryFile.setLocked(file.isLocked());
    repositoryFile.setLockMessage(file.getLockMessage());
    repositoryFile.setLockOwner(file.getLockOwner());
    repositoryFile.setName(file.getName());
    repositoryFile.setOriginalParentFolderId(file.getOriginalParentFolderPath());
    repositoryFile.setOriginalParentFolderPath(file.getOriginalParentFolderPath());
    repositoryFile.setOwner(file.getOwner());
    repositoryFile.setPath(file.getPath());
    repositoryFile.setTitle(file.getTitle());
    repositoryFile.setVersionId(file.getVersionId());
    return repositoryFile;
}
Also used : RepositoryFile(org.pentaho.gwt.widgets.client.filechooser.RepositoryFile)

Example 14 with RepositoryFile

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

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

the class SolutionTree method onFetchRepositoryFileTree.

public void onFetchRepositoryFileTree(RepositoryFileTree fileTree, List<RepositoryFile> repositoryTrashItems) {
    if (fileTree == null) {
        WaitPopup.getInstance().setVisible(false);
        return;
    }
    repositoryFileTree = fileTree;
    trashItems = repositoryTrashItems;
    // remember selectedItem, so we can reselect it after the tree is loaded
    clear();
    // get document root item
    RepositoryFile rootRepositoryFile = repositoryFileTree.getFile();
    if (!rootRepositoryFile.isHidden() || isShowHiddenFiles()) {
        FileTreeItem rootItem = null;
        if (createRootNode) {
            rootItem = new FileTreeItem();
            rootItem.setText(rootRepositoryFile.getPath());
            rootItem.setTitle(rootRepositoryFile.getPath());
            rootItem.getElement().setId(rootRepositoryFile.getPath());
            // added so we can traverse the true names
            // $NON-NLS-1$
            rootItem.setFileName("/");
            rootItem.setRepositoryFile(rootRepositoryFile);
            addItem(rootItem);
            buildSolutionTree(rootItem, repositoryFileTree);
        } else {
            buildSolutionTree(null, repositoryFileTree);
            // sort the root elements
            ArrayList<TreeItem> roots = new ArrayList<TreeItem>();
            for (int i = 0; i < getItemCount(); i++) {
                roots.add(getItem(i));
            }
            // BISERVER-9599 - Custom Sort
            Collections.sort(roots, new TreeItemComparator());
            clear();
            for (TreeItem myRootItem : roots) {
                addItem(myRootItem);
            }
        }
    }
    fixLeafNodes();
    if (selectedPath != null) {
        select(selectedPath);
    } else if (selectedItem != null) {
        ArrayList<TreeItem> parents = new ArrayList<TreeItem>();
        while (selectedItem != null) {
            parents.add(selectedItem);
            selectedItem = selectedItem.getParentItem();
        }
        Collections.reverse(parents);
        selectFromList(parents);
    } else {
        for (int i = 0; i < getItemCount(); i++) {
            getItem(i).setState(true);
        }
    }
    WaitPopup.getInstance().setVisible(false);
}
Also used : TreeItem(com.google.gwt.user.client.ui.TreeItem) ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.gwt.widgets.client.filechooser.RepositoryFile) TreeItemComparator(org.pentaho.gwt.widgets.client.filechooser.TreeItemComparator)

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