/* * (non-Javadoc) * * @see javax.swing.tree.TreeModel#getChildCount(java.lang.Object) */ public int getChildCount(Object parent) { if (parent instanceof UserDefinedOpcode) { return 0; } else if (parent instanceof UDOCategory) { UDOCategory cat = (UDOCategory) parent; return cat.getSubCategories().size() + cat.getUserDefinedOpcodes().size(); } return 0; }
public Object getChild(Object parent, int index) { UDOCategory category = (UDOCategory) parent; if (category == null) { return null; } if (index >= category.getSubCategories().size()) { return category.getUserDefinedOpcodes().get(index - category.getSubCategories().size()); } return category.getSubCategories().get(index); }
public void addUDO(UDOCategory parent, int insertIndex, UserDefinedOpcode udo) { if (insertIndex < 0 || insertIndex >= parent.getUserDefinedOpcodes().size()) { parent.addUDO(udo); } else { parent.addUDO(insertIndex, udo); } int index = getIndexOfChild(parent, udo); int[] childIndices = new int[1]; childIndices[0] = index; Object[] children = new Object[1]; children[0] = udo; TreeModelEvent e = new TreeModelEvent(this, getPathForObject(udo), childIndices, children); fireNodesInserted(e); }
private UDOCategory findParent(UDOCategory cat, Object obj) { if (ListUtil.containsByRef(cat.getUserDefinedOpcodes(), obj) || ListUtil.containsByRef(cat.getSubCategories(), obj)) { return cat; } for (Iterator iter = cat.getSubCategories().iterator(); iter.hasNext(); ) { UDOCategory c = (UDOCategory) iter.next(); UDOCategory temp = findParent(c, obj); if (temp != null) { return temp; } } return null; }
public int getIndexOfChild(Object parent, Object child) { UDOCategory category = (UDOCategory) parent; if (category == null || child == null) { return -1; } int retVal = ListUtil.indexOfByRef(category.getSubCategories(), child); if (retVal >= 0) { return retVal; } retVal = ListUtil.indexOfByRef(category.getUserDefinedOpcodes(), child); if (retVal >= 0) { return retVal + category.getSubCategories().size(); } return -1; }
/* * (non-Javadoc) * * @see javax.swing.tree.TreeModel#valueForPathChanged(javax.swing.tree.TreePath, * java.lang.Object) */ public void valueForPathChanged(TreePath path, Object newValue) { Object obj = path.getLastPathComponent(); if (obj instanceof UDOCategory) { ((UDOCategory) obj).setCategoryName(newValue.toString()); } else if (obj instanceof UserDefinedOpcode) { ((UserDefinedOpcode) obj).setOpcodeName(newValue.toString()); } TreeModelEvent e = new TreeModelEvent(this, path); fireNodesChanged(e); }
private Object getPathForObject(UDOCategory current, Object obj, Vector v) { if (current == obj) { return v; } if (ListUtil.containsByRef(current.getUserDefinedOpcodes(), obj)) { v.add(current); return v; } for (Iterator iter = current.getSubCategories().iterator(); iter.hasNext(); ) { UDOCategory cat = (UDOCategory) iter.next(); Object pathObj = getPathForObject(cat, obj, v); if (pathObj != null) { v.add(current); return v; } } return null; }
public void addCategory(UDOCategory parent, UDOCategory cat) { parent.addUDOCategory(cat); int index = getIndexOfChild(parent, cat); int[] childIndices = new int[1]; childIndices[0] = index; Object[] children = new Object[1]; children[0] = cat; TreeModelEvent e = new TreeModelEvent(this, getPathForObject(cat), childIndices, children); fireNodesInserted(e); }
public void removeCategory(UDOCategory cat) { UDOCategory parent = findParent(rootUDOCategory, cat); int index = getIndexOfChild(parent, cat); int[] childIndices = new int[1]; childIndices[0] = index; Object[] children = new Object[1]; children[0] = cat; TreeModelEvent e = new TreeModelEvent(this, getPathForObject(cat), childIndices, children); rootUDOCategory.removeUDOCategory(cat); fireNodesRemoved(e); }
public void removeUDO(UserDefinedOpcode udo) { UDOCategory parent = findParent(rootUDOCategory, udo); int index = getIndexOfChild(parent, udo); int[] childIndices = new int[1]; childIndices[0] = index; Object[] children = new Object[1]; children[0] = udo; TreeModelEvent e = new TreeModelEvent(this, getPathForObject(udo), childIndices, children); rootUDOCategory.removeUDO(udo); fireNodesRemoved(e); }
public Element saveAsXML() { Element retVal = new Element("udoLibrary"); retVal.addElement(rootUDOCategory.saveAsXML()); return retVal; }
public static UDOLibrary loadFromXML(Element data) throws Exception { UDOLibrary iLibrary = new UDOLibrary(); iLibrary.setRootUDOCategory(UDOCategory.loadFromXML(data.getElement("udoCategory"))); return iLibrary; }