List of usage examples for com.google.gwt.user.client.ui TreeItem getParentItem
public TreeItem getParentItem()
From source file:org.iucn.sis.client.ui.TreeTable.java
License:Apache License
/** * Moves the selected item up one.// w ww. j av a2s . c o m */ private void moveSelectionUp(TreeItem sel) { TreeItem parent = sel.getParentItem(); if (parent == null) { parent = root; } int idx = parent.getChildIndex(sel); if (idx > 0) { TreeItem sibling = parent.getChild(idx - 1); onSelection(findDeepestOpenChild(sibling), true); } else { onSelection(parent, true); } }
From source file:org.iucn.sis.client.ui.TreeTable.java
License:Apache License
/** * Renders TreeItems recursively.//from www.ja v a2 s .c o m * * @param item */ public void render(TreeItem item) { getRenderer().renderTreeItem(this, item, item.getRow()); if (item.getParentItem() != null) { updateVisibility(item.getParentItem()); } for (int i = 0, s = item.getChildCount(); i < s; i++) { TreeItem child = item.getChild(i); render(child); } }
From source file:org.jboss.ballroom.client.layout.LHSNavTree.java
License:Open Source License
private void openParents(TreeItem treeItem) { TreeItem parentItem = treeItem.getParentItem(); if (parentItem != null) { parentItem.setState(true);/* w w w. ja v a2 s .com*/ openParents(parentItem); } }
From source file:org.jbpm.formbuilder.client.tree.TreeViewImpl.java
License:Apache License
@Override public void removeFormItem(FBFormItem item) { TreeItem treeBranch = tree.getItem(0); TreeItem treeBranch2 = getItem(treeBranch, item); if (treeBranch2 != null) { treeBranch = treeBranch2;/*from w ww. j a va 2s . c o m*/ } if (treeBranch.getParentItem() != null) { treeBranch.getParentItem().removeItem(treeBranch); } }
From source file:org.ned.server.nedadminconsole.client.widgets.NedLibraryTree.java
License:Open Source License
@Override public void objectMoved(NedDataModel source, boolean moveUp) { TreeItem moveObj = source.getCurrentTreeItem(); TreeItem parentItem = moveObj.getParentItem(); int moveObjIndex = parentItem.getChildIndex(moveObj); parentItem.removeItem(moveObj);/* www. j a v a2 s . c o m*/ int newIndex; if (moveUp) { newIndex = moveObjIndex - 1; } else { newIndex = moveObjIndex + 1; } parentItem.insertItem(newIndex, moveObj); moveObj.getTree().setSelectedItem(moveObj, true); }
From source file:org.openxdata.designer.client.view.FormsTreeView.java
/** * Removes a given tree item from the tree widget. * // ww w.j a v a 2s. c o m * @param item the tree item to delete. */ private void deleteItem(TreeItem item) { TreeItem parent = item.getParentItem(); int index; if (parent != null) { index = parent.getChildIndex(item); //If last item is the one selected, the select the previous, else the next. if (index == parent.getChildCount() - 1) index -= 1; removeFormDefItem(item, parent); //Remove the selected item. item.remove(); //If no more kids, then select the parent. if (parent.getChildCount() == 0) tree.setSelectedItem(parent); else tree.setSelectedItem(parent.getChild(index)); } else { //Must be the form root index = getRootItemIndex(item); item.remove(); int count = tree.getItemCount(); //If we have any items left, select the one which was after //the one we have just removed. if (count > 0) { //If we have deleted the last item, select the item which was before it. if (index == count) index--; tree.setSelectedItem(tree.getItem(index)); } } if (tree.getSelectedItem() == null) { Context.setFormDef(null); formDef = null; fireFormItemSelected(null); if (tree.getItemCount() == 0) { nextFormId = 0; nextOptionId = 0; nextPageId = 0; nextQuestionId = 0; } } }
From source file:org.openxdata.designer.client.view.FormsTreeView.java
/** * @see org.openxdata.designer.client.controller.IFormActionListener#addNewItem() *///from www . j a va 2s . c om public void addNewItem() { if (inReadOnlyMode()) return; TreeItem item = tree.getSelectedItem(); //Check if there is any selection. if (item != null) { Object userObj = item.getUserObject(); if (userObj instanceof QuestionDef) { int id = ++nextQuestionId; QuestionDef questionDef = new QuestionDef(id, i18n.question() + id, QuestionType.TEXT, "question" + id, item.getParentItem().getUserObject()); item = addImageItem(item.getParentItem(), questionDef.getText(), images.lookup(), questionDef, questionDef.getHelpText()); addFormDefItem(questionDef, item.getParentItem()); tree.setSelectedItem(item); } else if (userObj instanceof OptionDef) { int id = ++nextOptionId; OptionDef optionDef = new OptionDef(id, i18n.option() + id, "option" + id, (QuestionDef) item.getParentItem().getUserObject()); item = addImageItem(item.getParentItem(), optionDef.getText(), images.markRead(), optionDef, null); addFormDefItem(optionDef, item.getParentItem()); tree.setSelectedItem(item); } else if (userObj instanceof PageDef) { int id = ++nextPageId; PageDef pageDef = new PageDef(i18n.page() + id, id, null, (FormDef) item.getParentItem().getUserObject()); item = addImageItem(item.getParentItem(), pageDef.getName(), images.drafts(), pageDef, null); addFormDefItem(pageDef, item.getParentItem()); tree.setSelectedItem(item); } else if (userObj instanceof FormDef) addNewForm(); } else addNewForm(); }
From source file:org.openxdata.designer.client.view.FormsTreeView.java
/** * This is a hack. This method will add a new page to the current form definition * in context. Ideally, this entire class needs to be refactored. There are traces * of controller, view and model responsibilities in this class. * Also, instead of trying to pick out elements from the tree widget itself, a selection model * of some sort should be used. That would make this entire process less hideous *//*from ww w.jav a2 s . co m*/ public void addNewPage() { if (inReadOnlyMode()) { return; } TreeItem item = tree.getSelectedItem(); TreeItem parentItem = null; FormDef formDef = null; Object userObj = item.getUserObject(); // figure out which item is selected in the form definition list tree if (userObj instanceof PageDef) { parentItem = item.getParentItem(); formDef = ((PageDef) userObj).getParent(); } else if (userObj instanceof OptionDef) { parentItem = item.getParentItem().getParentItem().getParentItem(); // yikes! formDef = ((OptionDef) userObj).getParent().getParentFormDef(); } else if (userObj instanceof QuestionDef) { parentItem = item.getParentItem().getParentItem(); formDef = ((QuestionDef) userObj).getParentFormDef(); } else if (userObj instanceof FormDef) { parentItem = item; formDef = (FormDef) userObj; } // first add the page int pageId = ++nextPageId; PageDef pageDef = new PageDef(i18n.page() + pageId, pageId, null, formDef); TreeItem pageDefItem = addImageItem(parentItem, pageDef.getName(), images.drafts(), pageDef, null); addFormDefItem(pageDef, parentItem); // now the question int quesId = ++nextQuestionId; QuestionDef questionDef = new QuestionDef(quesId, i18n.question() + quesId, QuestionType.TEXT, "question" + quesId, pageDef); TreeItem quesDefItem = addImageItem(pageDefItem, questionDef.getText(), images.lookup(), questionDef, questionDef.getHelpText()); addFormDefItem(questionDef, pageDefItem); tree.setSelectedItem(quesDefItem); // make sure to open up the PageDef tree item pageDefItem.setState(true, true); }
From source file:org.openxdata.designer.client.view.FormsTreeView.java
public void addNewQuestion(QuestionType dataType) { if (inReadOnlyMode()) return;//from w w w .j a va2 s. c o m TreeItem item = tree.getSelectedItem(); //Check if there is any selection. if (item != null) { Object userObj = item.getUserObject(); if (userObj instanceof QuestionDef) { int id = ++nextQuestionId; QuestionDef questionDef = new QuestionDef(id, i18n.question() + id, QuestionType.TEXT, "question" + id, item.getParentItem().getUserObject()); questionDef.setDataType(dataType); item = addImageItem(item.getParentItem(), questionDef.getText(), images.lookup(), questionDef, questionDef.getHelpText()); addFormDefItem(questionDef, item.getParentItem()); if (dataType == QuestionType.LIST_EXCLUSIVE || dataType == QuestionType.LIST_MULTIPLE) addNewOptionDef(questionDef, item); tree.setSelectedItem(item); } else if (userObj instanceof OptionDef) { int id = ++nextQuestionId; QuestionDef questionDef = new QuestionDef(id, i18n.question() + id, QuestionType.TEXT, "question" + id, item.getParentItem().getParentItem().getUserObject()); questionDef.setDataType(dataType); item = addImageItem(item.getParentItem().getParentItem(), questionDef.getText(), images.lookup(), questionDef, questionDef.getHelpText()); addFormDefItem(questionDef, item.getParentItem()); if (dataType == QuestionType.LIST_EXCLUSIVE || dataType == QuestionType.LIST_MULTIPLE) addNewOptionDef(questionDef, item); tree.setSelectedItem(item); } else if (userObj instanceof PageDef) { int id = ++nextQuestionId; QuestionDef questionDef = new QuestionDef(id, i18n.question() + id, QuestionType.TEXT, "question" + id, item.getUserObject()); questionDef.setDataType(dataType); item = addImageItem(item, questionDef.getText(), images.lookup(), questionDef, questionDef.getHelpText()); addFormDefItem(questionDef, item.getParentItem()); if (dataType == QuestionType.LIST_EXCLUSIVE || dataType == QuestionType.LIST_MULTIPLE) addNewOptionDef(questionDef, item); tree.setSelectedItem(item); } else if (userObj instanceof FormDef) { //addNewForm(); //If not yet got pages, just quit. if (item.getChildCount() == 0) return; TreeItem parentItem = item.getChild(0); int id = ++nextQuestionId; QuestionDef questionDef = new QuestionDef(id, i18n.question() + id, QuestionType.TEXT, "question" + id, parentItem.getUserObject()); questionDef.setDataType(dataType); item = addImageItem(parentItem, questionDef.getText(), images.lookup(), questionDef, questionDef.getHelpText()); addFormDefItem(questionDef, item.getParentItem()); if (dataType == QuestionType.LIST_EXCLUSIVE || dataType == QuestionType.LIST_MULTIPLE) addNewOptionDef(questionDef, item); tree.setSelectedItem(item); } } else { addNewForm(); item = tree.getSelectedItem(); QuestionDef questionDef = (QuestionDef) item.getUserObject(); questionDef.setDataType(dataType); if (dataType == QuestionType.LIST_EXCLUSIVE || dataType == QuestionType.LIST_MULTIPLE) addNewOptionDef(questionDef, item); tree.setSelectedItem(item.getParentItem()); tree.setSelectedItem(item); } }
From source file:org.openxdata.designer.client.view.FormsTreeView.java
/** * Adds a new child item./*w ww.j av a 2s . com*/ */ public void addNewChildItem(boolean addNewIfNoKids) { if (inReadOnlyMode()) return; TreeItem item = tree.getSelectedItem(); //Check if there is any selection. if (item == null) { if (addNewIfNoKids) addNewItem(); return; } Object userObj = item.getUserObject(); if (userObj instanceof PageDef || (userObj instanceof QuestionDef && ((QuestionDef) userObj).getDataType() == QuestionType.REPEAT)) { int id = ++nextQuestionId; QuestionDef questionDef = new QuestionDef(id, i18n.question() + id, QuestionType.TEXT, "question" + id, userObj); item = addImageItem(item, questionDef.getText(), images.lookup(), questionDef, questionDef.getHelpText()); addFormDefItem(questionDef, item.getParentItem()); tree.setSelectedItem(item); item.getParentItem().setState(true); } else if (userObj instanceof QuestionDef && (((QuestionDef) userObj).getDataType() == QuestionType.LIST_EXCLUSIVE || ((QuestionDef) userObj).getDataType() == QuestionType.LIST_MULTIPLE)) { int id = ++nextOptionId; OptionDef optionDef = new OptionDef(id, i18n.option() + id, "option" + id, (QuestionDef) userObj); item = addImageItem(item, optionDef.getText(), images.markRead(), optionDef, null); addFormDefItem(optionDef, item.getParentItem()); tree.setSelectedItem(item); item.getParentItem().setState(true); } else if (userObj instanceof FormDef) { int id = ++nextPageId; PageDef pageDef = new PageDef(i18n.page() + id, id, null, (FormDef) userObj); item = addImageItem(item, pageDef.getName(), images.drafts(), pageDef, null); addFormDefItem(pageDef, item.getParentItem()); tree.setSelectedItem(item); item.getParentItem().setState(true); //Automatically add a new question addNewChildItem(false); } else if (addNewIfNoKids) addNewItem(); }