Search in sources :

Example 16 with RepositoryFile

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

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

the class FilesListPanel method setSelectedFileItems.

public void setSelectedFileItems(List<FileItem> fileItems) {
    // Deselect all prior selections
    for (FileItem fileItem : selectedFileItems) {
        RepositoryFile file = fileItem.getRepositoryFile();
        if (file.isHidden()) {
            fileItem.setStyleName("hiddenFileLabel");
        } else {
            fileItem.setStyleName("fileLabel");
        }
    }
    // clear the prior selections list
    selectedFileItems.clear();
    // Add all the new items
    selectedFileItems.addAll(fileItems);
    // and make sure they're selected
    for (FileItem fileItem : selectedFileItems) {
        RepositoryFile file = fileItem.getRepositoryFile();
        if (file.isHidden()) {
            fileItem.setStyleName("hiddenFileLabelSelected");
        } else {
            fileItem.setStyleName("fileLabelSelected");
        }
    }
}
Also used : RepositoryFile(org.pentaho.gwt.widgets.client.filechooser.RepositoryFile)

Example 18 with RepositoryFile

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

the class FilesListPanel method deselect.

public void deselect() {
    for (int i = 0; i < filesList.getRowCount(); i++) {
        FileItem item = (FileItem) filesList.getWidget(i, 0);
        RepositoryFile file = item.getRepositoryFile();
        if (file.isHidden()) {
            // $NON-NLS-1$
            item.setStyleName("hiddenFileLabel");
        } else {
            // $NON-NLS-1$
            item.setStyleName("fileLabel");
        }
    }
}
Also used : RepositoryFile(org.pentaho.gwt.widgets.client.filechooser.RepositoryFile)

Example 19 with RepositoryFile

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

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

the class ShareFileCommand method performOperation.

public void performOperation() {
    final SolutionFileActionEvent event = new SolutionFileActionEvent();
    event.setAction(this.getClass().getName());
    if (selectedList != null && selectedList.size() == 1) {
        final RepositoryFile item = selectedList.get(0);
        // 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, defaultTab, false);
                    dialog.showTab(defaultTab);
                    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, defaultTab, Boolean.parseBoolean(response.getText()));
                    dialog.showTab(FilePropertiesDialog.Tabs.PERMISSION);
                    dialog.center();
                    event.setMessage("Success");
                    EventBusUtil.EVENT_BUS.fireEvent(event);
                }
            });
        } catch (RequestException e) {
            FilePropertiesDialog dialog = new FilePropertiesDialog(item, new PentahoTabPanel(), null, defaultTab, false);
            dialog.showTab(FilePropertiesDialog.Tabs.PERMISSION);
            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)

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