Example usage for com.google.gwt.user.client.ui TreeItem getParentItem

List of usage examples for com.google.gwt.user.client.ui TreeItem getParentItem

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui TreeItem getParentItem.

Prototype

public TreeItem getParentItem() 

Source Link

Document

Gets this item's parent.

Usage

From source file:org.pentaho.gwt.widgets.client.filechooser.FileChooser.java

License:Open Source License

private void handleFileClicked(final TreeItem item, final boolean isDir, final Event event,
        com.google.gwt.user.client.Element sourceElement) {
    boolean eventWeCareAbout = false;
    TreeItem tmpItem = null;
    if ((DOM.eventGetType(event) & Event.ONDBLCLICK) == Event.ONDBLCLICK) {
        eventWeCareAbout = true;//from  w w  w  . java 2 s .  c om
    } else if ((DOM.eventGetType(event) & Event.ONCLICK) == Event.ONCLICK) {
        eventWeCareAbout = true;
    }
    if (eventWeCareAbout) {
        setFileSelected(true);
        selectedTreeItem = tmpItem = item;

        List<String> parentSegments = new ArrayList<String>();
        while (tmpItem != null) {
            RepositoryFileTree tree = (RepositoryFileTree) tmpItem.getUserObject();
            RepositoryFile file = tree.getFile();
            if (file != null && file.getName() != null) {
                parentSegments.add(file.getName());
            }
            tmpItem = tmpItem.getParentItem();
        }
        Collections.reverse(parentSegments);
        String myPath = ""; //$NON-NLS-1$
        for (int i = 0; isDir ? i < parentSegments.size() : i < parentSegments.size() - 1; i++) {
            String segment = parentSegments.get(i);
            if (segment != null && segment.length() > 0) {
                myPath += "/" + segment; //$NON-NLS-1$
            }
        }
        setSelectedPath(myPath);
        if (!isDir) {
            RepositoryFileTree tree = (RepositoryFileTree) selectedTreeItem.getUserObject();
            if (tree.getFile() != null) {
                fileNameTextBox.setText(tree.getFile().getTitle());
                actualFileName = tree.getFile().getName();
            }
        }
    }
    // double click
    if ((DOM.eventGetType(event) & Event.ONDBLCLICK) == Event.ONDBLCLICK) {
        if (isDir) {
            initUI();
        } else {
            fireFileSelected();
        }
    } else if ((DOM.eventGetType(event) & Event.ONCLICK) == Event.ONCLICK) {
        fireFileSelectionChanged();
        // single click
        // highlight row
        if (lastSelectedFileElement != null) {
            com.google.gwt.dom.client.Element parentRow = ElementUtils
                    .findElementAboveByTagName(lastSelectedFileElement, "table"); //$NON-NLS-1$
            parentRow.removeClassName("pentaho-file-chooser-selection");
        }
        com.google.gwt.dom.client.Element parentRow = ElementUtils.findElementAboveByTagName(sourceElement,
                "table"); //$NON-NLS-1$
        parentRow.addClassName("pentaho-file-chooser-selection"); //$NON-NLS-1$
        lastSelectedFileElement = sourceElement;
    }
}

From source file:org.pentaho.mantle.client.dialogs.folderchooser.FolderTree.java

License:Open Source License

public void select(String path) {
    this.selectedPath = path;
    List<String> pathSegments = new ArrayList<String>();
    if (path != null) {
        if (path.startsWith("/")) { //$NON-NLS-1$
            path = path.substring(1);// w  w w  . ja v  a2 s  . c  o m
        }
        StringTokenizer st = new StringTokenizer(path, '/');
        for (int i = 0; i < st.countTokens(); i++) {
            String token = st.tokenAt(i);
            pathSegments.add(token);
        }
    }
    TreeItem item = getTreeItem(pathSegments);
    selectedItem = item;
    ArrayList<TreeItem> parents = new ArrayList<TreeItem>();
    if (item != null) {
        this.setSelectedItem(item, false);
        parents.add(item);
        item = item.getParentItem();
        while (item != null) {
            parents.add(item);
            item = item.getParentItem();
        }
        Collections.reverse(parents);
        selectFromList(parents);
    }
}

From source file:org.pentaho.mantle.client.solutionbrowser.SolutionBrowserPerspective.java

License:Open Source License

@SuppressWarnings("unchecked")
public void openFile(String path, String name, String localizedFileName, FileCommand.COMMAND mode) {
    ArrayList<String> pathSegments = solutionTree.getPathSegments(path);
    final boolean fileExists = solutionTree.doesFileExist(pathSegments, name);
    if (!fileExists) {
        final MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("open"), //$NON-NLS-1$
                Messages.getString("fileDoesNotExist", name), false, false, true); //$NON-NLS-1$
        dialogBox.center();/*w  w w. j  av a  2  s . co m*/
        return;
    }

    String repoPath = ""; //$NON-NLS-1$
    for (int i = 1; i < pathSegments.size(); i++) {
        repoPath += "/" + pathSegments.get(i); //$NON-NLS-1$
    }

    FileItem selectedFileItem = new FileItem(name, localizedFileName, localizedFileName, pathSegments.get(0),
            repoPath, "", null, null, null, false, null); //$NON-NLS-1$
    filesListPanel.setSelectedFileItem(selectedFileItem);

    solutionTree.setSelectedItem(null);
    FileTreeItem fileTreeItem = solutionTree.getTreeItem(pathSegments);
    solutionTree.setSelectedItem(fileTreeItem, true);

    TreeItem tmpTreeItem = fileTreeItem;
    while (tmpTreeItem != null) {
        tmpTreeItem.setState(true);
        tmpTreeItem = tmpTreeItem.getParentItem();
    }
    fileTreeItem.setSelected(true);

    ArrayList<com.google.gwt.xml.client.Element> files = (ArrayList<com.google.gwt.xml.client.Element>) fileTreeItem
            .getUserObject();
    if (files != null) {
        for (com.google.gwt.xml.client.Element fileElement : files) {
            if (name.equals(fileElement.getAttribute("name")) //$NON-NLS-1$
                    || name.equals(fileElement.getAttribute("localized-name"))) { //$NON-NLS-1$
                selectedFileItem.setURL(fileElement.getAttribute("url")); //$NON-NLS-1$
            }
        }
    }

    if (mode == FileCommand.COMMAND.EDIT) {
        editFile();
    } else if (mode == FileCommand.COMMAND.SCHEDULE_NEW) {
        ScheduleHelper.createSchedule(filesListPanel.getSelectedFileItem());
    } else if (mode == FileCommand.COMMAND.SHARE) {
        (new ShareFileCommand()).execute();
    } else {
        if (name.endsWith(".xaction")) { //$NON-NLS-1$
            executeActionSequence(mode);
            // contentTabPanel.setFileInfoInFrame(filesListPanel.getSelectedFileItem());
        } else if (name.endsWith(".url")) { //$NON-NLS-1$
            if (mode == FileCommand.COMMAND.NEWWINDOW) {
                Window.open(filesListPanel.getSelectedFileItem().getURL(), "_blank", //$NON-NLS-1$
                        "menubar=yes,location=no,resizable=yes,scrollbars=yes,status=no"); //$NON-NLS-1$
            } else {
                contentTabPanel.showNewURLTab(filesListPanel.getSelectedFileItem().getLocalizedName(),
                        filesListPanel.getSelectedFileItem().getLocalizedName(),
                        filesListPanel.getSelectedFileItem().getURL(), true);
            }
        } else {
            // see if this file is a plugin
            ContentTypePlugin plugin = PluginOptionsHelper
                    .getContentTypePlugin(filesListPanel.getSelectedFileItem().getName());
            if (plugin != null && plugin.hasCommand(mode)) {
                // load the editor for this plugin
                String url = plugin.getCommandUrl(filesListPanel.getSelectedFileItem(), mode);
                if (StringUtils.isEmpty(url)) {
                    url = filesListPanel.getSelectedFileItem().getURL();
                }

                if (GWT.isScript()) {
                    if (url != null && !"".equals(url)) { //$NON-NLS-1$
                        // we have a URL so open it
                        if (mode == FileCommand.COMMAND.NEWWINDOW) {
                            Window.open(url, "_blank", //$NON-NLS-1$
                                    "menubar=yes,location=no,resizable=yes,scrollbars=yes,status=no"); //$NON-NLS-1$
                        } else if (mode == FileCommand.COMMAND.BACKGROUND) {
                            RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
                            try {
                                builder.sendRequest(null, new RequestCallback() {

                                    public void onError(Request request, Throwable exception) {
                                        MessageDialogBox dialogBox = new MessageDialogBox(
                                                Messages.getString("error"), //$NON-NLS-1$
                                                Messages.getString("couldNotBackgroundExecute"), false, false, //$NON-NLS-1$
                                                true);
                                        dialogBox.center();
                                    }

                                    public void onResponseReceived(Request request, Response response) {
                                        MessageDialogBox dialogBox = new MessageDialogBox(
                                                Messages.getString("info"), //$NON-NLS-1$
                                                Messages.getString("backgroundExecutionWarning"), //$NON-NLS-1$
                                                true, false, true);
                                        dialogBox.setCallback(new IDialogCallback() {
                                            public void cancelPressed() {
                                            }

                                            public void okPressed() {
                                                if (isWorkspaceShowing()) {
                                                    workspacePanel.refreshWorkspace();
                                                }
                                            }
                                        });
                                        dialogBox.center();
                                    }

                                });
                            } catch (RequestException e) {
                                MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                                        e.getMessage(), //$NON-NLS-1$
                                        true, false, true);
                                dialogBox.center();
                            }
                        } else {
                            UrlCommand cmd = new UrlCommand(url,
                                    filesListPanel.getSelectedFileItem().getLocalizedName());
                            cmd.execute(new CommandCallback() {
                                public void afterExecute() {
                                    contentTabPanel.setFileInfoInFrame(filesListPanel.getSelectedFileItem());
                                }
                            });
                        }
                    }
                } else {
                    if (url != null && !"".equals(url)) { //$NON-NLS-1$
                        // we have a URL so open it in a new tab
                        String updateUrl = "/MantleService?passthru=" + url; //$NON-NLS-1$

                        if (mode == FileCommand.COMMAND.NEWWINDOW) {
                            Window.open(updateUrl, "_blank", //$NON-NLS-1$
                                    "menubar=yes,location=no,resizable=yes,scrollbars=yes,status=no"); //$NON-NLS-1$
                        } else {
                            contentTabPanel.showNewURLTab(
                                    filesListPanel.getSelectedFileItem().getLocalizedName(),
                                    filesListPanel.getSelectedFileItem().getLocalizedName(), updateUrl, true);
                        }
                    }
                }
            } else {
                // see if this file has a URL
                String url = filesListPanel.getSelectedFileItem().getURL();
                if (url != null && !"".equals(url)) { //$NON-NLS-1$
                    // we have a URL so open it in a new tab
                    if (mode == FileCommand.COMMAND.NEWWINDOW) {
                        Window.open(filesListPanel.getSelectedFileItem().getURL(), "_blank", //$NON-NLS-1$
                                "menubar=yes,location=no,resizable=yes,scrollbars=yes,status=no"); //$NON-NLS-1$
                    } else {
                        contentTabPanel.showNewURLTab(filesListPanel.getSelectedFileItem().getLocalizedName(),
                                filesListPanel.getSelectedFileItem().getLocalizedName(),
                                filesListPanel.getSelectedFileItem().getURL(), true);
                    }
                }
            }
        }
    }
}

From source file:org.pentaho.mantle.client.solutionbrowser.tree.SolutionTree.java

License:Open Source License

public void select(String path) {
    this.selectedPath = path;
    ArrayList<String> pathSegments = new ArrayList<String>();
    if (path != null) {
        if (path.startsWith("/")) { //$NON-NLS-1$
            path = path.substring(1);//from   w w  w  . j av a2s.c  o  m
        }
        StringTokenizer st = new StringTokenizer(path, '/');
        for (int i = 0; i < st.countTokens(); i++) {
            String token = st.tokenAt(i);
            pathSegments.add(token);
        }
    }
    TreeItem item = getTreeItem(pathSegments);
    selectedItem = item;
    ArrayList<TreeItem> parents = new ArrayList<TreeItem>();
    if (item != null) {
        this.setSelectedItem(item, false);
        parents.add(item);
        item = item.getParentItem();
        while (item != null) {
            parents.add(item);
            item = item.getParentItem();
        }
        Collections.reverse(parents);
        selectFromList(parents);
        // this.setSelectedItem(selectedItem, false);
        // selectedItem.setSelected(true);
    }
}

From source file:org.pentaho.pat.client.ui.panels.windows.DimensionMenu.java

License:Open Source License

/**
 * Returns the full path of the member in the dimension tree
 * //from ww  w  .java 2  s .  co  m
 * @param currentTreeItem
 *            - TreeItem of interest
 * @return String[] path
 */
public final String[] getFullPath(final TreeItem currentTreeItem) {
    TreeItem treeItem = currentTreeItem;
    final List<String> pathList = new ArrayList<String>();
    pathList.add(treeItem.getText());
    while (treeItem.getParentItem() != null
            && treeItem.getParentItem().getWidget() instanceof MemberSelectionLabel) {
        treeItem = treeItem.getParentItem();
        pathList.add(0, ((MemberSelectionLabel) treeItem.getWidget()).getText());
    }
    final String[] values = new String[pathList.size()];
    return pathList.toArray(values);
}

From source file:org.primordion.xholon.io.XholonGuiClassic.java

License:Open Source License

protected boolean isInInheritanceHierarchy(Object guiItem) {
    TreeItem treeItem = (TreeItem) guiItem;
    while (treeItem != null) {
        if (treeItem.getText().equals("InheritanceHierarchy")) {
            return true;
        }/*from   w  ww.  j  a va2 s.  c o m*/
        treeItem = treeItem.getParentItem();
    }
    return false;
}

From source file:org.primordion.xholon.io.XholonGuiClassic.java

License:Open Source License

protected boolean isInMechanismHierarchy(Object guiItem) {
    TreeItem treeItem = (TreeItem) guiItem;
    while (treeItem != null) {
        if (treeItem.getText().equals("MechanismHierarchy")) {
            return true;
        }/*from   w  w  w  .  j  av a2s . com*/
        treeItem = treeItem.getParentItem();
    }
    return false;
}

From source file:org.raccoon.filemanager.client.ui.FileSystemTreeWidget.java

License:Apache License

private String findPath(TreeItem item) {
    TreeItem parent = item.getParentItem();

    if (parent == null) {
        return "/";
    } else {/*w w w .  j  a  va  2 s  .  c  om*/
        return findPath(parent) + "/" + item.getText();
    }
}