16 package net.squiz.matrix.matrixtree;
18 import net.squiz.matrix.core.*;
19 import net.squiz.matrix.debug.*;
21 import net.squiz.matrix.inspector.*;
22 import javax.swing.tree.DefaultTreeModel;
33 private static List models =
new ArrayList();
34 private static DefaultTreeModel[] components;
43 public static void addToBus(DefaultTreeModel model) {
44 synchronized(models) {
50 public static void removeFromBus(DefaultTreeModel model) {
51 synchronized(models) {
57 public static DefaultTreeModel[] getBusComponents() {
58 synchronized(models) {
59 if (components == null) {
60 components = (DefaultTreeModel[]) models.toArray(
61 new DefaultTreeModel[models.size()]);
67 public static void setRoot(MatrixTreeNode root) {
68 for (
int i = 0; i < components.length; i++) {
69 ((DefaultTreeModel) components[i]).setRoot(root);
73 public static void moveNode(
75 MatrixTreeNode newParent,
78 if ((child.getParent() == newParent) && newParent.getIndex(child) == index)
82 insertNodeInto(child, newParent, index);
85 public static void insertNodeInto(
86 MatrixTreeNode newChild,
87 MatrixTreeNode parent,
95 if (parent.hasPreviousNode() && !(newChild instanceof ExpandingNextNode)) {
100 if (parent.hasNextNode() && !(newChild instanceof ExpandingPreviousNode) && (index == parent.getChildCount()) && index != 0) {
104 parent.insert(newChild, index);
105 int[] newIndexs =
new int[1];
106 newIndexs[0] = index;
108 DefaultTreeModel[] components = getBusComponents();
110 for (
int i = 0; i < components.length; i++) {
111 DefaultTreeModel model = components[i];
114 if (((MatrixTreeNode) model.getRoot()).isNodeDescendant(parent)) {
115 model.nodesWereInserted(parent, newIndexs);
118 }
catch (Throwable t) {
119 Log.log(
"Could Not insert node", MatrixTreeModelBus.class, t);
126 throw new IllegalArgumentException(
"node does not have a parent");
140 int[] childIndex =
new int[1];
141 Object[] removedArray =
new Object[1];
142 childIndex[0] = parent.getIndex(child);
143 parent.remove(child);
144 removedArray[0] = child;
146 DefaultTreeModel[] components = getBusComponents();
148 for (
int i = 0; i < components.length; i++) {
149 DefaultTreeModel model = components[i];
153 model.nodesWereRemoved(parent, childIndex, removedArray);
157 }
catch (Throwable t) {
163 Asset parentAsset = AssetManager.getAsset(parent.
getAsset().getId());
164 Iterator iterator = parentAsset.getTreeNodes();
167 while (iterator.hasNext()) {
169 if (nextNode == parent)
172 mirrorParent = nextNode;
179 public static void nodeChanged(MatrixTreeNode node) {
181 DefaultTreeModel[] components = getBusComponents();
182 for (
int i = 0; i < components.length; i++) {
183 DefaultTreeModel model = components[i];
186 if (((MatrixTreeNode) model.getRoot()).isNodeDescendant(node))
187 model.nodeChanged(node);