Java Code Examples for com.google.gwt.user.client.ui.TreeItem#getChild()

The following examples show how to use com.google.gwt.user.client.ui.TreeItem#getChild() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModelBrowserView.java    From core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static TreeItem findTreeItem(TreeItem tree, Iterator<String> iterator)
{
    TreeItem next = null;
    if(iterator.hasNext())
    {
        final String pathName = iterator.next();
        for(int i=0; i<tree.getChildCount(); i++)
        {

            if(tree.getChild(i).getText().equals(pathName))
            {
                next = tree.getChild(i);
                break;
            }
        }
    }

    if(next==null)
        return null;
    else if (!iterator.hasNext())
        return next;
    else
        return findTreeItem(next, iterator);

}
 
Example 2
Source File: SubsetJSONPropertyEditor.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
private void toggleChildren(TreeItem item, Boolean checked) {
  for (int i = 0; i <item.getChildCount(); ++i) {
    TreeItem childItem = item.getChild(i);
    ((CheckBox)childItem.getWidget()).setValue(checked, false);
    if (childItem.getChildCount() > 0) {
      toggleChildren(childItem, checked);
    }
  }
}
 
Example 3
Source File: FolderTree.java    From document-management-system with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Change recursivelly all the childs path
 *
 * @param oldPath
 *            The old path
 * @param newPath
 *            The new path
 * @param itemToChange
 *            The tree item to change the path
 */
public void changePathBeforeRenaming(String oldPath, String newPath, TreeItem itemToChange) {
	for (int i = 0; i < itemToChange.getChildCount(); i++) {
		TreeItem tmpItem = itemToChange.getChild(i);
		GWTFolder gwtFolder = ((GWTFolder) tmpItem.getUserObject());
		gwtFolder.setPath(gwtFolder.getPath().replaceAll(oldPath, newPath));
		gwtFolder.setParentPath(gwtFolder.getParentPath().replaceAll(oldPath, newPath));
		if (tmpItem.getChildCount() > 0) {
			changePathBeforeRenaming(oldPath, newPath, tmpItem);
		}
	}
}
 
Example 4
Source File: ModelBrowserView.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Child selection within editor components (outside left hand tree)
 * @param address
 * @param childName
 */
@Override
public void onViewChild(ModelNode address, String childName) {
    TreeItem rootNode = findTreeItem(tree, address);
    TreeItem childNode = null;
    for(int i=0; i<rootNode.getChildCount(); i++)
    {
        TreeItem candidate = rootNode.getChild(i);
        if(childName.equals(candidate.getText()))
        {
            childNode = candidate;
            break;
        }
    }

    if(null==childNode)
        throw new IllegalArgumentException("No such child "+ childName + " on "+ address.toString());


    // deselect previous
    tree.setSelectedItem(null, false);

    // select next
    tree.setSelectedItem(childNode, false);
    tree.ensureSelectedItemVisible();

    onItemSelected(childNode);
}
 
Example 5
Source File: SubsetJSONPropertyEditor.java    From appinventor-extensions with Apache License 2.0 4 votes vote down vote up
private void loadComponents(JSONObject jsonObj) {
  // TODO: Review JSON format. There has to be a better way to store and retrieve this info.
  JSONObject shownComponents = jsonObj.get("shownComponentTypes").isObject();
  JSONObject shownComponentBlocks = jsonObj.get("shownBlockTypes").isObject().get("ComponentBlocks").isObject();
  for (int i = 0; i < componentTree.getItemCount(); ++i) {
    TreeItem componentCatItem = componentTree.getItem(i);
    CheckBox componentCatCb = (CheckBox)componentCatItem.getWidget();
    String catName = componentCatCb.getName().toUpperCase();
    if (shownComponents.containsKey(catName)) {
      JSONArray jsonComponentCat = shownComponents.get(catName).isArray();
      if (jsonComponentCat.size() > 0) {
        componentCatCb.setValue(true, false);
        HashMap<String, String> jsonComponentHash = new HashMap<String, String>();
        for (int j = 0; j < jsonComponentCat.size(); ++j) {
          JSONValue jsonComponentHashCat = jsonComponentCat.get(j);
          if (jsonComponentHashCat != null) {
            jsonComponentHash.put(jsonComponentHashCat.isObject().get("type").isString().stringValue(), "type");
          }
        }
        for (int j = 0; j < componentCatItem.getChildCount(); ++j) {
          TreeItem componentItem = componentCatItem.getChild(j);
          CheckBox componentCb = (CheckBox) componentItem.getWidget();
          if (jsonComponentHash.get(componentCb.getName()) != null) {
            componentCb.setValue(true, false);
            JSONArray jsonComponentBlockProps = shownComponentBlocks.get(componentCb.getName()).isArray();
            HashMap<String, String> componentPropHash = new HashMap<String, String>();
            for (int k = 0; k < jsonComponentBlockProps.size(); ++k) {
              JSONObject jsonComponentBlockType = jsonComponentBlockProps.get(k).isObject();
              String componentBlockType = jsonComponentBlockType.get("type").isString().stringValue();
              if ("component_set_get".equals(componentBlockType)) {
                componentPropHash.put(jsonComponentBlockType.get("mutatorNameToValue").isObject().get("property_name").isString().stringValue(), "PROP");
              } else if ("component_event".equals(componentBlockType)) {
                JSONValue mutatorValue = jsonComponentBlockType.get("mutatorNameToValue");
                JSONValue event_name = mutatorValue.isObject().get("event_name");
                componentPropHash.put(event_name.isString().stringValue(), "EVENT");
              } else if ("component_method".equals(componentBlockType)) {
                componentPropHash.put(jsonComponentBlockType.get("mutatorNameToValue").isObject().get("method_name").isString().stringValue(), "METHOD");
              }
            }
            for (int k = 0; k < componentItem.getChildCount(); ++k) {
              TreeItem componentPropItem = componentItem.getChild(k);
              CheckBox componentPropCb = (CheckBox) componentPropItem.getWidget();
              if (componentPropHash.get(componentPropCb.getText()) != null) {
                componentPropCb.setValue(true, false);
              } else {
                componentPropCb.setValue(false, false);
              }
            }

          } else {
            componentCb.setValue(false, false);
            toggleChildren(componentItem, false);
          }
        }
      } else {
        componentCatCb.setValue(false, false);
        toggleChildren(componentCatItem, false);
      }
    } else {
      componentCatCb.setValue(false, false);
      toggleChildren(componentCatItem, false);
    }
  }
}