Example #1
0
	/*
	 * * Tree Node
	 * 
	 * @param parentCode
	 * 
	 * @param node
	 */
	@SuppressWarnings("unchecked")
	public void addNodes(TreeNode<Department> node, int orgId, int parentId, String oName, String pName) {
		try {
			Query query = getSession().getNamedQuery("core.department.getchildren");
			query.setParameter("orgId", orgId);
			query.setParameter("parentId", parentId);
			Iterator<?> it = query.list().iterator();
			int id;
			String name, desc;
			while (it.hasNext()) {
				Object obj[] = (Object[]) it.next();
				id = 0;
				name = desc = "";
				if (obj[0] != null)
					id = Integer.valueOf(String.valueOf(obj[0]));
				if (obj[1] != null)
					name = String.valueOf(obj[1]);
				if (obj[2] != null)
					desc = String.valueOf(obj[2]);
				@SuppressWarnings("rawtypes")
				TreeNodeImpl nodeImpl = new TreeNodeImpl();
				nodeImpl.setData(new Department(orgId, id, id, oName, pName, name, desc));
				node.addChild(key, nodeImpl);
				key++;
				if (hasChild(orgId, id))
					addNodes(nodeImpl, orgId, id, oName, name);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
Example #2
0
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public void loadTree() {
		try {
			rootNode = new TreeNodeImpl();

			Query query = getSession().getNamedQuery("core.org.records");
			Iterator it = query.list().iterator();
			int id;
			String name, desc;
			key = 1;
			while (it.hasNext()) {
				Object obj[] = (Object[]) it.next();
				id = 0;
				name = desc = "";
				if (obj[0] != null)
					id = Integer.valueOf(String.valueOf(obj[0]));
				if (obj[6] != null)
					name = String.valueOf(obj[6]);
				if (obj[7] != null)
					desc = String.valueOf(obj[7]);
				TreeNodeImpl nodeImpl = new TreeNodeImpl();
				nodeImpl.setData(new Department(id, 0, 0, name, name, name, desc));
				rootNode.addChild(key, nodeImpl);
				key++;
				addNodes(nodeImpl, id, 0, name, name);

			}
			it = null;

		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
  private void buildTableNameList() {
    databaseNode = new TreeNodeImpl();

    TreeNodeImpl tableNode;

    tableList = new ArrayList<XmlObject>();
    columnList = new ArrayList<XmlObject>();

    tableNamesList = new ArrayList<String>();

    ExtendedRegistry tempExtendedRegistry = this.extendedRegistryList.get(resourceIndex);
    Resource tempResource = tempExtendedRegistry.getResource();
    XmlObject tempObject = tempResource.copy();

    XmlObject xmlObjectTableChild[] = tempObject.selectChildren(new QName("", "table"));

    // System.out.println("Table: " + xmlObjectTableChild.length);
    for (int tableIndex = 0; tableIndex < xmlObjectTableChild.length; tableIndex++) {
      tableNode = new TreeNodeImpl();
      XmlObject xmlObjectTableName[] =
          xmlObjectTableChild[tableIndex].selectChildren(new QName("", "name"));

      tableList.add(xmlObjectTableChild[tableIndex]);

      String tableXML = xmlObjectTableName[0].xmlText();
      int indexGreaterThan = tableXML.indexOf(">") + 1;
      int indexSecondLessThan = tableXML.indexOf("</");
      String tableName = tableXML.substring(indexGreaterThan, indexSecondLessThan);

      XmlObject xmlObjectColumnChild[] =
          xmlObjectTableChild[tableIndex].selectChildren(new QName("", "column"));
      for (int columnIndex = 0; columnIndex < xmlObjectColumnChild.length; columnIndex++) {

        XmlObject xmlObjectColumnName[] =
            xmlObjectColumnChild[columnIndex].selectChildren(new QName("", "name"));

        XmlObject xmlObjectColumnType[] =
            xmlObjectColumnChild[columnIndex].selectChildren(new QName("", "dataType"));
        columnList.add(xmlObjectColumnChild[columnIndex]);

        String columnXML = xmlObjectColumnName[0].xmlText();
        indexGreaterThan = columnXML.indexOf(">") + 1;
        indexSecondLessThan = columnXML.indexOf("</");
        String columnName = columnXML.substring(indexGreaterThan, indexSecondLessThan);
        if (xmlObjectColumnType.length > 0) {
          String columnTypeXML = xmlObjectColumnType[0].xmlText();
          indexGreaterThan = columnTypeXML.indexOf(">") + 1;
          indexSecondLessThan = columnTypeXML.indexOf("</");
          String columnType = columnTypeXML.substring(indexGreaterThan, indexSecondLessThan);

          TreeNodeImpl columnNode = new TreeNodeImpl();

          columnNode.setData(columnName + ": " + columnType);
          tableNode.addChild(columnIndex, columnNode); /* */
        }
      }

      tableNamesList.add(tableName);
      tableNode.setData(tableName);
      databaseNode.addChild(tableIndex, tableNode);
    }
  }