Search in sources :

Example 6 with RepositoryFileTree

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

the class SolutionTree method fixLeafNodes.

/**
 */
private void fixLeafNodes() {
    List<FileTreeItem> allNodes = getAllNodes();
    for (FileTreeItem treeItem : allNodes) {
        RepositoryFileTree userObject = (RepositoryFileTree) treeItem.getUserObject();
        if (userObject != null && userObject.getChildren().size() == 0) {
            // This is a leaf node so change the
            // widget
            treeItem.setWidget(// $NON-NLS-1$
            new LeafItemWidget(treeItem.getText(), "icon-tree-node", "icon-tree-leaf", "icon-folder"));
        } else {
            // $NON-NLS-1$
            treeItem.setWidget(new LeafItemWidget(treeItem.getText(), "icon-tree-node", "icon-folder"));
        }
        // $NON-NLS-1$ //$NON-NLS-2$
        DOM.setStyleAttribute(treeItem.getElement(), "paddingLeft", "0px");
    }
}
Also used : RepositoryFileTree(org.pentaho.gwt.widgets.client.filechooser.RepositoryFileTree)

Example 7 with RepositoryFileTree

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

the class FilesListPanel method populateFilesList.

public void populateFilesList(SolutionBrowserPanel perspective, SolutionTree solutionTree, TreeItem item, JsArrayString filters) {
    filesList.clear();
    List<RepositoryFile> files;
    if (item == solutionTree.getTrashItem()) {
        // If we're populating from the trash then
        files = solutionTree.getTrashItems();
    } else {
        files = new ArrayList<RepositoryFile>();
        // Get the user object.
        RepositoryFileTree tree = (RepositoryFileTree) item.getUserObject();
        // Since we are only listing the files here. Get to each item of the tree and get the file from it
        for (RepositoryFileTree treeItem : tree.getChildren()) {
            String fileName = treeItem.getFile().getName();
            if (filters != null) {
                for (int i = 0; i < filters.length(); i++) {
                    if (fileName.endsWith(filters.get(i))) {
                        files.add(treeItem.getFile());
                    }
                }
            }
        }
    }
    // let's sort this list based on localized name
    // BISERVER-9599 - Custom Sort
    Collections.sort(files, new RepositoryFileComparator());
    if (files != null) {
        int rowCounter = 0;
        for (RepositoryFile file : files) {
            if ((item == solutionTree.getTrashItem()) || (!file.isFolder() && (isShowHiddenFiles() || !file.isHidden()))) {
                // TODO Currently Old solution repository stores url type files. New repository does not have that
                // concept. What do we need to do here
                // String url = fileElement.getAttribute("url"); //$NON-NLS-1$
                ContentTypePlugin plugin = PluginOptionsHelper.getContentTypePlugin(file.getName());
                String icon = null;
                if (plugin != null) {
                    icon = plugin.getFileIcon();
                }
                if (item == solutionTree.getTrashItem() && file.isFolder()) {
                    // $NON-NLS-1$
                    icon = "mantle/images/folderIcon.png";
                }
                final FileItem fileLabel = new FileItem(file, this, PluginOptionsHelper.getEnabledOptions(file.getName()), true, icon);
                // BISERVER-2317: Request for more IDs for Mantle UI elements
                // set element id as the filename
                // $NON-NLS-1$
                fileLabel.getElement().setId(file.getPath());
                fileLabel.addFileSelectionChangedListener(toolbar);
                // $NON-NLS-1$
                fileLabel.setWidth("100%");
                try {
                    perspective.getDragController().makeDraggable(fileLabel);
                } catch (Throwable e) {
                    Throwable throwable = e;
                    String text = "Uncaught exception: ";
                    while (throwable != null) {
                        StackTraceElement[] stackTraceElements = throwable.getStackTrace();
                        text += throwable.toString() + "\n";
                        for (int ii = 0; ii < stackTraceElements.length; ii++) {
                            text += "    at " + stackTraceElements[ii] + "\n";
                        }
                        throwable = throwable.getCause();
                        if (throwable != null) {
                            text += "Caused by: ";
                        }
                    }
                    DialogBox dialogBox = new DialogBox(true);
                    DOM.setStyleAttribute(dialogBox.getElement(), "backgroundColor", "#ABCDEF");
                    System.err.print(text);
                    text = text.replaceAll(" ", "&nbsp;");
                    dialogBox.setHTML("<pre>" + text + "</pre>");
                    dialogBox.center();
                }
                fileLabel.setRepositoryFile(file);
                filesList.setWidget(rowCounter++, 0, fileLabel);
                if (selectedFileItems != null && selectedFileItems.size() > 0) {
                    for (FileItem fileItem : selectedFileItems) {
                        if (fileItem.getRepositoryFile().equals(fileLabel.getRepositoryFile())) {
                            if (file.isHidden()) {
                                fileLabel.setStyleName("hiddenFileLabelSelected");
                            } else {
                                // $NON-NLS-1$
                                fileLabel.setStyleName("fileLabelSelected");
                            }
                            selectedFileItems.add(fileLabel);
                            // if we do not break this loop, it will go forever! (we added an item)
                            break;
                        }
                    }
                } else {
                    if (file.isHidden()) {
                        // $NON-NLS-1$
                        fileLabel.setStyleName("hiddenFileLabel");
                    } else {
                        // $NON-NLS-1$
                        fileLabel.setStyleName("fileLabel");
                    }
                }
            }
        }
    }
}
Also used : RepositoryFile(org.pentaho.gwt.widgets.client.filechooser.RepositoryFile) JsArrayString(com.google.gwt.core.client.JsArrayString) RepositoryFileTree(org.pentaho.gwt.widgets.client.filechooser.RepositoryFileTree) ContentTypePlugin(org.pentaho.mantle.client.solutionbrowser.PluginOptionsHelper.ContentTypePlugin) DialogBox(com.google.gwt.user.client.ui.DialogBox)

Example 8 with RepositoryFileTree

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

the class SaveCommand method performOperation.

protected void performOperation(boolean feedback) {
    final SolutionBrowserPanel navigatorPerspective = SolutionBrowserPanel.getInstance();
    retrieveCachedValues(navigatorPerspective.getContentTabPanel().getCurrentFrame());
    boolean forceReload = false;
    if (FileChooserDialog.getIsDirty()) {
        forceReload = true;
        WaitPopup.getInstance().setVisibleById(true, spinnerId);
        FileChooserDialog.setIsDirty(Boolean.FALSE);
    }
    RepositoryFileTreeManager.getInstance().fetchRepositoryFileTree(new AsyncCallback<RepositoryFileTree>() {

        public void onFailure(Throwable caught) {
        }

        public void onSuccess(RepositoryFileTree tree) {
            retrieveCachedValues(navigatorPerspective.getContentTabPanel().getCurrentFrame());
            if (isSaveAs || name == null) {
                String fileDir = "";
                if (path != null && !StringUtils.isEmpty(path)) {
                    // If has extension
                    if (path.endsWith(name)) {
                        fileDir = path.substring(0, path.lastIndexOf("/"));
                    } else {
                        fileDir = path;
                    }
                }
                WaitPopup.getInstance().setVisibleById(false, spinnerId);
                final FileChooserDialog dialog = new FileChooserDialog(FileChooserMode.SAVE, fileDir, tree, false, true, Messages.getString("save"), Messages.getString("save"), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                navigatorPerspective.getSolutionTree().isShowHiddenFiles());
                dialog.setSubmitOnEnter(MantleApplication.submitOnEnter);
                if (isSaveAs) {
                    // $NON-NLS-1$
                    dialog.setTitle(Messages.getString("saveAs"));
                    // $NON-NLS-1$
                    dialog.setText(Messages.getString("saveAs"));
                } else {
                    // $NON-NLS-1$
                    dialog.setTitle(Messages.getString("save"));
                    // $NON-NLS-1$
                    dialog.setText(Messages.getString("save"));
                }
                // TODO Uncomment the line below and delete the line after that once gwtwidets have been branched
                dialog.addFileChooserListener(new FileChooserListener() {

                    public void dialogCanceled() {
                    }

                    @Override
                    public void fileSelected(final RepositoryFile file, String filePath, String fileName, String title) {
                        SaveCommand.this.type = SolutionFileInfo.Type.XACTION;
                        SaveCommand.this.name = fileName;
                        SaveCommand.this.path = filePath;
                        tabName = name;
                        if (tabName.indexOf("analysisview.xaction") != -1) {
                            // trim off the analysisview.xaction from the localized-name
                            tabName = tabName.substring(0, tabName.indexOf("analysisview.xaction") - 1);
                        }
                        JsArrayString extensions = getPossibleExtensions(navigatorPerspective.getContentTabPanel().getCurrentFrameElementId());
                        final String fileExtension = extensions.length() == 1 ? extensions.get(0) : null;
                        if (dialog.doesSelectedFileExist(fileExtension)) {
                            dialog.hide();
                            PromptDialogBox overWriteDialog = new PromptDialogBox(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                            Messages.getString("question"), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                            Messages.getString("yes"), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                            Messages.getString("no"), false, true);
                            // $NON-NLS-1$
                            overWriteDialog.setContent(new Label(Messages.getString("fileExistsOverwrite"), false));
                            overWriteDialog.setCallback(new IDialogCallback() {

                                public void okPressed() {
                                    if (fileExtension != null && tabName.endsWith(fileExtension)) {
                                        tabName = tabName.substring(0, tabName.lastIndexOf(fileExtension));
                                    }
                                    doSaveAs(navigatorPerspective.getContentTabPanel().getCurrentFrameElementId(), name, path, type, true);
                                    // $NON-NLS-1$ //$NON-NLS-2$
                                    Window.setTitle(Messages.getString("productName") + " - " + name);
                                    FileChooserDialog.setIsDirty(Boolean.TRUE);
                                    persistFileInfoInFrame();
                                }

                                public void cancelPressed() {
                                    dialog.show();
                                }
                            });
                            overWriteDialog.center();
                        } else {
                            // [Fix for PIR-833]
                            if (file != null && !file.isFolder() && !fileName.equals(title) && filePath.endsWith(file.getName())) {
                                SaveCommand.this.path = filePath.substring(0, filePath.lastIndexOf("/" + file.getName()));
                            }
                            doSaveAs(navigatorPerspective.getContentTabPanel().getCurrentFrameElementId(), name, path, type, true);
                            // $NON-NLS-1$ //$NON-NLS-2$
                            Window.setTitle(Messages.getString("productName") + " - " + name);
                            persistFileInfoInFrame();
                            // navigatorPerspective.addRecent(fullPathWithName, name);
                            clearValues();
                        }
                    }

                    @Override
                    public void fileSelectionChanged(RepositoryFile file, String filePath, String fileName, String title) {
                    // TODO Auto-generated method stub
                    }
                });
                dialog.center();
            } else {
                doSaveAs(navigatorPerspective.getContentTabPanel().getCurrentFrameElementId(), name, path, type, true);
                clearValues();
            }
            WaitPopup.getInstance().setVisibleById(false, spinnerId);
        }
    }, forceReload, null, null, SolutionBrowserPanel.getInstance().getSolutionTree().isShowHiddenFiles());
}
Also used : PromptDialogBox(org.pentaho.gwt.widgets.client.dialogs.PromptDialogBox) Label(com.google.gwt.user.client.ui.Label) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString) IDialogCallback(org.pentaho.gwt.widgets.client.dialogs.IDialogCallback) SolutionBrowserPanel(org.pentaho.mantle.client.solutionbrowser.SolutionBrowserPanel) RepositoryFileTree(org.pentaho.gwt.widgets.client.filechooser.RepositoryFileTree) FileChooserDialog(org.pentaho.gwt.widgets.client.filechooser.FileChooserDialog) FileChooserListener(org.pentaho.gwt.widgets.client.filechooser.FileChooserListener) RepositoryFile(org.pentaho.gwt.widgets.client.filechooser.RepositoryFile)

Example 9 with RepositoryFileTree

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

the class OpenFileCommand method performOperation.

protected void performOperation(boolean feedback) {
    final IPluginPerspective activePerspective = PerspectiveManager.getInstance().getActivePerspective();
    final SolutionBrowserPanel solutionBrowserPerspective = SolutionBrowserPanel.getInstance();
    boolean forceReload = false;
    if (FileChooserDialog.getIsDirty()) {
        forceReload = true;
        WaitPopup.getInstance().setVisibleById(true, spinnerId);
        FileChooserDialog.setIsDirty(Boolean.FALSE);
    }
    RepositoryFileTreeManager.getInstance().fetchRepositoryFileTree(new AsyncCallback<RepositoryFileTree>() {

        public void onFailure(Throwable caught) {
        }

        public void onSuccess(RepositoryFileTree tree) {
            // TODO Uncomment the line below and delete the line after that once gwtwidets have been branched
            WaitPopup.getInstance().setVisibleById(false, spinnerId);
            final FileChooserDialog dialog = new FileChooserDialog(FileChooserMode.OPEN, lastPath, tree, false, true, solutionBrowserPerspective.getSolutionTree().isShowHiddenFiles());
            dialog.setSubmitOnEnter(MantleApplication.submitOnEnter);
            dialog.addFileChooserListener(new FileChooserListener() {

                public void dialogCanceled() {
                    // retain current active perspective
                    PerspectiveManager.getInstance().setPerspective(activePerspective.getId());
                }

                @Override
                public void fileSelected(RepositoryFile repositoryFile, String filePath, String fileName, String title) {
                    dialog.hide();
                    solutionBrowserPerspective.openFile(repositoryFile, openMethod);
                }

                @Override
                public void fileSelectionChanged(RepositoryFile repositoryFile, String filePath, String fileName, String title) {
                // TODO Auto-generated method stub
                }
            });
            dialog.center();
        }
    }, forceReload, null, null, SolutionBrowserPanel.getInstance().getSolutionTree().isShowHiddenFiles());
}
Also used : FileChooserListener(org.pentaho.gwt.widgets.client.filechooser.FileChooserListener) RepositoryFile(org.pentaho.gwt.widgets.client.filechooser.RepositoryFile) IPluginPerspective(org.pentaho.platform.api.engine.perspective.pojo.IPluginPerspective) SolutionBrowserPanel(org.pentaho.mantle.client.solutionbrowser.SolutionBrowserPanel) RepositoryFileTree(org.pentaho.gwt.widgets.client.filechooser.RepositoryFileTree) FileChooserDialog(org.pentaho.gwt.widgets.client.filechooser.FileChooserDialog)

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