- Timestamp:
- 2003-06-12T17:21:47+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/util/DragTreeSelectionModel.java
r4545 r4618 48 48 implements MouseListener { 49 49 50 boolean immediate = false; 50 private boolean immediate = false; 51 private boolean mixed_selection = false; 51 52 52 53 private int type = -1; … … 59 60 static private final int SET = 1; 60 61 61 public DragTreeSelectionModel(DragTree tree) { 62 /** Constructor. 63 * @param tree the DragTree which will use this selection model. 64 * @param mixed_selection true if this selection model allows selections to contain files and folders, false otherwise. 65 */ 66 public DragTreeSelectionModel(DragTree tree, boolean mixed_selection) { 62 67 super(); 68 this.mixed_selection = mixed_selection; 63 69 setSelectionMode(DISCONTIGUOUS_TREE_SELECTION); 64 70 tree.addMouseListener(this); … … 240 246 } 241 247 242 /** Ensure that the given path is appropriate to add to the current selection, preventing mixed selections of files and folder. We also must check that no path is a ancestor/descendant of another. There is also a slight optimization in that if the current selection contains only files (which if the rules are followed, and the first 'test' node is a file, then it must) there is no point in checking the remaining files in the selection. Its a different story for folders however as we have to ensure no folder is in the lineage of another, even if they are all folders! */ 248 /** Ensure that the given path is appropriate to add to the current selection, preventing mixed selections of files and folder if required. We also must check that no path is a ancestor/descendant of another. 249 */ 243 250 private boolean isAppropriate(TreePath path) { 244 251 boolean appropriate = true; 245 252 TreeNode new_node = (TreeNode) path.getLastPathComponent(); 253 // If there is a current selection 246 254 if(selection != null && selection.length > 0) { 247 TreeNode test_node = (TreeNode) selection[0].getLastPathComponent(); 248 appropriate = appropriate && (new_node.isLeaf() == test_node.isLeaf()); 249 if(!test_node.isLeaf()) { 250 appropriate = appropriate && !path.isDescendant(selection[0]) && !selection[0].isDescendant(path); 251 for(int i = 1; appropriate && selection != null && i < selection.length; i++) { 252 TreeNode current_node = (TreeNode) selection[i].getLastPathComponent(); 253 appropriate = appropriate && (new_node.isLeaf() == current_node.isLeaf()); 254 appropriate = appropriate && !path.isDescendant(selection[i]) && !selection[i].isDescendant(path); 255 } 255 for(int i = 0; appropriate && i < selection.length; i++) { 256 TreeNode current_node = (TreeNode) selection[i].getLastPathComponent(); 257 appropriate = appropriate && (mixed_selection || new_node.isLeaf() == current_node.isLeaf()); 258 appropriate = appropriate && !path.isDescendant(selection[i]) && !selection[i].isDescendant(path); 256 259 } 257 260 } 258 261 return appropriate; 259 262 } 260 /** Ensure that the given paths are appropriate to add to the current selection, preventing mixed selections of files and folder . We also must check that no path is a ancestor/descendant of another. One last detail to keep in mind is that adding selections depends upon the current selection, whereas set the selection paths doesn't (replaces them instead) and thus no check of the current paths is needed. */263 /** Ensure that the given paths are appropriate to add to the current selection, preventing mixed selections of files and folder if required. We also must check that no path is a ancestor/descendant of another. One last detail to keep in mind is that adding selections depends upon the current selection, whereas set the selection paths doesn't (replaces them instead) and thus no check of the current paths is needed. */ 261 264 private boolean isAppropriate(TreePath[] paths, boolean check_current) { 262 265 boolean appropriate = true; 263 if(paths != null) { 264 if(paths.length >= 2) { 265 // Prevent folders being added to a previous selection of files and vice-versa 266 // First check that the new selection are all of the same type 267 for(int i = 0; appropriate && paths != null && i < paths.length - 1; i++) { 268 TreeNode one_node = (TreeNode) paths[i].getLastPathComponent(); 269 TreeNode other_node = (TreeNode) paths[i+1].getLastPathComponent(); 270 appropriate = appropriate && (one_node.isLeaf() == other_node.isLeaf()); 271 appropriate = appropriate && !paths[i].isDescendant(paths[i+1]) && !paths[i+1].isDescendant(paths[i]); 272 } 273 } 274 // Now we check the current selection against the first node in our new selection 275 if(appropriate && check_current) { 276 appropriate = isAppropriate(paths[0]); 266 if(check_current && paths != null && paths.length > 0) { 267 for(int i = 0; appropriate && i < paths.length; i++) { 268 appropriate = appropriate && isAppropriate(paths[i]); 277 269 } 278 270 }
Note:
See TracChangeset
for help on using the changeset viewer.