REMOVE, INSERT, REMOVERESTRUCTURE, INSERTRESTRUCTURE
}
private TreeModelEvent branchOperations(ArrayList<String> stringsToBranch, TreeModification whatToDo)
throws BranchOperationException {
TreeModelEvent event = null;
if (whatToDo == TreeModification.REMOVE) {
Debug.println("Removing a branch......");
} else if (whatToDo == TreeModification.INSERT) {
Debug.println("Inserting a branch......");
} else if (whatToDo == TreeModification.REMOVERESTRUCTURE) {
Debug.println("Restructuring from branch to remove......");
} else if (whatToDo == TreeModification.INSERTRESTRUCTURE) {
Debug.println("Restructuring from branch to insert......");
}
Debug.println(stringsToBranch);
if (whatToDo == TreeModification.INSERT || whatToDo == TreeModification.INSERTRESTRUCTURE) {
resetData();
}
// ArrayList<Sortables>
// order=MainFrame.getInstance().getSorter().getOrder();
List<Sortables> order = st.getOrderBeforeDivider();
// Create an array of BugAspects of lengths from one to the full
// BugAspect list of the bugInstance
BugAspects[] toBug = new BugAspects[stringsToBranch.size()];
for (int x = 0; x < stringsToBranch.size(); x++) {
toBug[x] = new BugAspects();
for (int y = 0; y <= x; y++) {
Sortables s = order.get(y);
toBug[x].add(new SortableValue(s, stringsToBranch.get(y)));
}
}
// Add this array as elements of the path
TreePath pathToBranch = new TreePath(root);
for (int x = 0; x < stringsToBranch.size(); x++) {
BugAspects child = toBug[x];
BugAspects parent = (BugAspects) pathToBranch.getLastPathComponent();
if (getIndexOfChild(parent, child) != -1) {
pathToBranch = pathToBranch.pathByAddingChild(child);
} else {
Debug.println(parent + " does not contain " + child);
throw new BranchOperationException("Branch has been filtered out by another filter.");
// break;
}
}
if (pathToBranch.getParentPath() != null) {
while (getChildCount(pathToBranch.getParentPath().getLastPathComponent()) == 1) {
if (pathToBranch.getParentPath().getLastPathComponent().equals(root)) {
break;
}
pathToBranch = pathToBranch.getParentPath();
}
}
Debug.println(pathToBranch);
if (whatToDo == TreeModification.INSERT) {
event = new TreeModelEvent(this, pathToBranch.getParentPath(), new int[] { getIndexOfChild(pathToBranch
.getParentPath().getLastPathComponent(), pathToBranch.getLastPathComponent()) },
new Object[] { pathToBranch.getLastPathComponent() });
} else if (whatToDo == TreeModification.INSERTRESTRUCTURE) {
event = new TreeModelEvent(this, pathToBranch);
}
if (whatToDo == TreeModification.REMOVE) {
event = new TreeModelEvent(this, pathToBranch.getParentPath(), new int[] { getIndexOfChild(pathToBranch
.getParentPath().getLastPathComponent(), pathToBranch.getLastPathComponent()) },
new Object[] { pathToBranch.getLastPathComponent() });
} else if (whatToDo == TreeModification.REMOVERESTRUCTURE) {
event = new TreeModelEvent(this, pathToBranch);
}
if (whatToDo == TreeModification.REMOVE || whatToDo == TreeModification.REMOVERESTRUCTURE) {
resetData();
}