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.openxdata.designer.client.view.FormsTreeView.java

/**
 * @see org.openxdata.designer.client.controller.IFormActionListener#moveItemUp()
 *//*from  w w  w . java2  s.c  om*/
public void moveItemUp() {
    if (inReadOnlyMode())
        return;

    TreeItem item = tree.getSelectedItem();

    //Check if there is any selection.
    if (item == null)
        return;

    TreeItem parent = item.getParentItem();

    //We don't move root node (which has no parent, that is the form itself, since we design one form at a time)
    if (parent == null)
        return;

    //One item can't move against itself.
    int count = parent.getChildCount();
    if (count == 1)
        return;

    int index = parent.getChildIndex(item);
    if (index == 0)
        return; //Can't move any further upwards.

    //move the item in the form object model.
    moveFormItemUp(item, parent);

    TreeItem currentItem; // = parent.getChild(index - 1);
    List<TreeItem> list = new ArrayList<TreeItem>();

    item.remove();

    while (parent.getChildCount() >= index) {
        currentItem = parent.getChild(index - 1);
        list.add(currentItem);
        currentItem.remove();
    }

    parent.addItem(item);
    for (int i = 0; i < list.size(); i++)
        parent.addItem((TreeItem) list.get(i));

    tree.setSelectedItem(item);
}

From source file:org.openxdata.designer.client.view.FormsTreeView.java

/**
 * @see org.openxdata.designer.client.controller.IFormActionListener#moveItemDown()
 *//*from   www.j  av a  2s  .c o  m*/
public void moveItemDown() {
    if (inReadOnlyMode())
        return;

    TreeItem item = tree.getSelectedItem();

    //Check if there is any selection.
    if (item == null)
        return;

    TreeItem parent = item.getParentItem();

    //We don't move root node (which has no parent, that is the form itself, since we design one form at a time)
    if (parent == null)
        return;

    //One item can't move against itself.
    int count = parent.getChildCount();
    if (count == 1)
        return;

    int index = parent.getChildIndex(item);
    if (index == count - 1)
        return; //Can't move any further downwards.

    //move the item in the form object model.
    moveFormItemDown(item, parent);

    TreeItem currentItem; // = parent.getChild(index - 1);
    List<TreeItem> list = new ArrayList<TreeItem>();

    item.remove();

    while (parent.getChildCount() > 0 && parent.getChildCount() > index) {
        currentItem = parent.getChild(index);
        list.add(currentItem);
        currentItem.remove();
    }

    for (int i = 0; i < list.size(); i++) {
        if (i == 1)
            parent.addItem(item); //Add after the first item.
        parent.addItem((TreeItem) list.get(i));
    }

    if (list.size() == 1)
        parent.addItem(item);

    tree.setSelectedItem(item);
}

From source file:org.openxdata.designer.client.view.FormsTreeView.java

/**
 * @see org.openxdata.designer.client.controller.IFormActionListener#pasteItem()
 *///from ww  w . j a va2  s. c o  m
public void pasteItem() {
    if (inReadOnlyMode())
        return;

    //Check if we have anything in the clipboard.
    if (clipboardItem == null)
        return;

    TreeItem item = tree.getSelectedItem();
    if (item == null)
        return;

    Object userObj = item.getUserObject();

    if (clipboardItem instanceof QuestionDef) {
        //Questions can be pasted only as kids of pages or repeat questions.
        if (!((userObj instanceof PageDef) || (userObj instanceof QuestionDef
                && ((QuestionDef) userObj).getDataType() == QuestionType.REPEAT))) {
            return;
        }

        //create a copy of the clipboard question.
        QuestionDef questionDef = new QuestionDef((QuestionDef) clipboardItem, userObj);

        //Repeat question can only be child of a page but not another question.
        if (questionDef.getDataType() == QuestionType.REPEAT && userObj instanceof QuestionDef)
            return;

        questionDef.setId(item.getChildCount() + 1);

        if (userObj instanceof PageDef)
            ((PageDef) userObj).addQuestion(questionDef);
        else
            ((QuestionDef) userObj).getRepeatQtnsDef().addQuestion(questionDef);

        item = loadQuestion(questionDef, item);

        tree.setSelectedItem(item);
        item.getParentItem().setState(true);
        item.setState(true);
    } else if (clipboardItem instanceof PageDef) {
        //Pages can be pasted only as kids of forms.
        if (!(userObj instanceof FormDef))
            return;

        //create a copy of the clipboard page.
        PageDef pageDef = new PageDef((PageDef) clipboardItem, (FormDef) userObj);

        pageDef.setPageNo(item.getChildCount() + 1);
        ((FormDef) userObj).addPage(pageDef);
        item = loadPage(pageDef, item);

        tree.setSelectedItem(item);
        item.getParentItem().setState(true);
        item.setState(true);
    } else if (clipboardItem instanceof OptionDef) {
        //Question options can be pasted only as kids of single and multi select questions.
        if (!(userObj instanceof QuestionDef
                && (((QuestionDef) userObj).getDataType() == QuestionType.LIST_EXCLUSIVE)
                || ((QuestionDef) userObj).getDataType() == QuestionType.LIST_MULTIPLE))
            return;

        //         create a copy of the clipboard page.
        OptionDef optionDef = new OptionDef((OptionDef) clipboardItem, (QuestionDef) userObj);
        optionDef.setId(item.getChildCount() + 1);
        ((QuestionDef) userObj).addOption(optionDef);
        item = addImageItem(item, optionDef.getText(), images.markRead(), optionDef, null);

        tree.setSelectedItem(item);
        item.getParentItem().setState(true);
        item.setState(true);
    }
}

From source file:org.openxdata.designer.client.view.FormsTreeView.java

/**
 * Gets the form to which the selected tree item belongs.
 * //from   ww w .  ja va  2 s.co m
 * @param item the tree item.
 * @return the form definition object.
 */
private FormDef getSelectedForm(TreeItem item) {
    Object obj = item.getUserObject();
    if (obj instanceof FormDef)
        return (FormDef) obj;
    return getSelectedForm(item.getParentItem());
}

From source file:org.openxdata.designer.client.view.FormsTreeView.java

private TreeItem getSelectedItemRoot(TreeItem item) {
    if (item == null)
        return null;

    if (item.getParentItem() == null)
        return item;
    return getSelectedItemRoot(item.getParentItem());
}

From source file:org.openxdata.designer.client.view.FormsTreeView.java

/**
 * @see org.openxdata.designer.client.controller.IFormActionListener#moveUp()
 *//*from ww w .  j  a va  2  s  . c  o  m*/
public void moveUp() {
    TreeItem item = tree.getSelectedItem();
    if (item == null)
        return;

    int index;
    TreeItem parent = item.getParentItem();
    if (parent == null) {
        index = getRootItemIndex(parent);
        if (index == 0)
            return;
        tree.setSelectedItem(tree.getItem(index - 1));
    } else {
        index = parent.getChildIndex(item);
        if (index == 0)
            return;
        tree.setSelectedItem(parent.getChild(index - 1));
    }
}

From source file:org.openxdata.designer.client.view.FormsTreeView.java

/**
 * @see org.openxdata.designer.client.controller.IFormActionListener#moveDown()
 *//*w  w w .ja  v a2  s . c om*/
public void moveDown() {
    TreeItem item = tree.getSelectedItem();
    if (item == null)
        return;

    int index;
    TreeItem parent = item.getParentItem();
    if (parent == null) {
        index = getRootItemIndex(parent);
        if (index == tree.getItemCount() - 1)
            return;
        tree.setSelectedItem(tree.getItem(index + 1));
    } else {
        index = parent.getChildIndex(item);
        if (index == parent.getChildCount() - 1)
            return;
        tree.setSelectedItem(parent.getChild(index + 1));
    }
}

From source file:org.openxdata.designer.client.view.FormsTreeView.java

/**
 * Selected the parent of the selected item.
 *//*from  ww w . j av  a2 s  .c  o  m*/
public void moveToParent() {
    TreeItem item = tree.getSelectedItem();
    if (item == null)
        return;

    TreeItem parent = item.getParentItem();
    if (parent == null)
        return;

    tree.setSelectedItem(parent);
    tree.ensureSelectedItemVisible();
}

From source file:org.optaplanner.workbench.screens.solver.client.editor.TerminationTreeItemContent.java

License:Apache License

public void setTreeItem(TreeItem treeItem) {
    this.treeItem = treeItem;
    view.setRoot(treeItem.getParentItem() == null);
}

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

License:Open Source License

public void initUI() {

    if (mode == FileChooserMode.OPEN_READ_ONLY) {
        fileNameTextBox.setReadOnly(true);
    }/*from www. j  a  v a 2s .c  o  m*/
    // We are here because we are initiating a fresh UI for a new directory
    // Since there is no file selected currently, we are setting file selected to false.
    setFileSelected(false);

    String path = this.selectedPath;

    // find the selected item from the list
    List<String> pathSegments = new ArrayList<String>();
    if (path != null) {
        int index = path.indexOf("/", 0); //$NON-NLS-1$
        while (index >= 0) {
            int oldIndex = index;
            index = path.indexOf("/", oldIndex + 1); //$NON-NLS-1$
            if (index >= 0) {
                pathSegments.add(path.substring(oldIndex + 1, index));
            }
        }
        pathSegments.add(path.substring(path.lastIndexOf("/") + 1)); //$NON-NLS-1$
    }

    selectedTreeItem = getTreeItem(pathSegments);
    navigationListBox = new ListBox();
    navigationListBox.getElement().setId("navigationListBox"); //$NON-NLS-1$
    navigationListBox.setWidth("350px"); //$NON-NLS-1$
    // now we can find the tree nodes who match the path segments
    navigationListBox.addItem("/", "/"); //$NON-NLS-1$ //$NON-NLS-2$

    for (int i = 0; i < pathSegments.size(); i++) {
        String segment = pathSegments.get(i);
        String fullPath = ""; //$NON-NLS-1$
        for (int j = 0; j <= i; j++) {
            String segmentPath = pathSegments.get(j);
            if (segmentPath != null && segmentPath.length() > 0) {
                fullPath += "/" + segmentPath; //$NON-NLS-1$
            }
        }
        if (!fullPath.equals("/")) { //$NON-NLS-1$
            navigationListBox.addItem(fullPath, segment);
        }
    }

    navigationListBox.setSelectedIndex(navigationListBox.getItemCount() - 1);
    navigationListBox.addChangeListener(new ChangeListener() {
        public void onChange(Widget sender) {
            changeToPath(navigationListBox.getItemText(navigationListBox.getSelectedIndex()));
        }
    });

    clear();

    VerticalPanel locationBar = new VerticalPanel();
    locationBar.add(new Label(FileChooserEntryPoint.messages.getString("location"))); //$NON-NLS-1$

    HorizontalPanel navigationBar = new HorizontalPanel();

    final Image upDirImage = new Image();
    upDirImage.setUrl(GWT.getModuleBaseURL() + "images/spacer.gif"); //$NON-NLS-1$
    upDirImage.addStyleName("pentaho-filechooseupbutton"); //$NON-NLS-1$
    upDirImage.setTitle(FileChooserEntryPoint.messages.getString("upOneLevel")); //$NON-NLS-1$
    upDirImage.addMouseListener(new MouseListener() {

        public void onMouseDown(Widget sender, int x, int y) {
        }

        public void onMouseEnter(Widget sender) {
        }

        public void onMouseLeave(Widget sender) {
        }

        public void onMouseMove(Widget sender, int x, int y) {
        }

        public void onMouseUp(Widget sender, int x, int y) {
        }

    });
    upDirImage.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            // go up a dir
            TreeItem tmpItem = selectedTreeItem;
            List<String> parentSegments = new ArrayList<String>();
            while (tmpItem != null) {
                RepositoryFileTree tree = (RepositoryFileTree) tmpItem.getUserObject();
                if (tree.getFile() != null && tree.getFile().getName() != null) {
                    parentSegments.add(tree.getFile().getName());
                }
                tmpItem = tmpItem.getParentItem();
            }
            Collections.reverse(parentSegments);
            String myPath = ""; //$NON-NLS-1$
            // If we have a file selected then we need to go one lesser level deep
            final int loopCount = isFileSelected() ? parentSegments.size() - 2 : parentSegments.size() - 1;
            for (int i = 0; i < loopCount; i++) {
                String pathSegment = parentSegments.get(i);
                if (pathSegment != null && pathSegment.length() > 0) {
                    myPath += "/" + pathSegment; //$NON-NLS-1$
                }
            }
            if (myPath.equals("")) { //$NON-NLS-1$
                myPath = "/"; //$NON-NLS-1$
            }
            selectedTreeItem = selectedTreeItem.getParentItem();
            if (selectedTreeItem == null) {
                selectedTreeItem = repositoryTree.getItem(0);
            }
            changeToPath(myPath);
        }
    });
    navigationBar.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
    navigationBar.add(navigationListBox);
    navigationBar.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
    navigationBar.add(upDirImage);
    navigationBar.setCellWidth(upDirImage, "100%"); //$NON-NLS-1$
    DOM.setStyleAttribute(upDirImage.getElement(), "marginLeft", "4px");
    navigationBar.setWidth("100%"); //$NON-NLS-1$

    locationBar.add(navigationBar);
    locationBar.setWidth("100%"); //$NON-NLS-1$

    Label filenameLabel = new Label(FileChooserEntryPoint.messages.getString("filename")); //$NON-NLS-1$
    filenameLabel.setWidth("550px"); //$NON-NLS-1$
    add(filenameLabel);
    fileNameTextBox.setWidth("300px"); //$NON-NLS-1$
    add(fileNameTextBox);
    add(locationBar);
    add(buildFilesList(selectedTreeItem));
}