KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > formmodel > tree > TreeSelectionEvent


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.forms.formmodel.tree;
17
18 import org.apache.cocoon.forms.event.WidgetEvent;
19
20 /**
21  * An event fired when the selection of a {@link Tree} changes.
22  *
23  * @version $Id: TreeSelectionEvent.java 190962 2005-06-16 17:17:00Z sylvain $
24  */

25 public class TreeSelectionEvent extends WidgetEvent {
26     
27     TreePath[] paths;
28     boolean [] isNew;
29
30     public TreeSelectionEvent(Tree source, TreePath path, boolean isNew) {
31         super(source);
32         this.paths = new TreePath[] { path };
33         this.isNew = new boolean[] { isNew };
34     }
35     
36     public TreeSelectionEvent(Tree source, TreePath paths[], boolean areNew[]) {
37         super(source);
38         this.paths = paths;
39         this.isNew = areNew;
40     }
41     
42     public TreeSelectionEvent(Tree source, TreePath paths[], boolean allNew) {
43         super(source);
44         this.paths = paths;
45         
46         // Fill isNew with allNew
47
this.isNew = new boolean[paths.length];
48         for (int i = 0; i < isNew.length; i++) {
49             this.isNew[i] = allNew;
50         }
51     }
52     
53     public Tree getTree() {
54         return (Tree)super.getSource();
55     }
56     
57     /**
58      * Get the first path element.
59      */

60     public TreePath getPath() {
61         return this.paths[0];
62     }
63     
64     /**
65      * Is the first path a new addition to the selection?
66      *
67      * @return
68      */

69     public boolean isAddedPath() {
70         return this.isNew[0];
71     }
72
73     /**
74      * Get paths that have been added or removed from the selection.
75      */

76     public TreePath[] getPaths() {
77         return this.getPaths();
78     }
79
80     /**
81      * Was the <code>index</code>th path added to the selection?
82      */

83     public boolean isAddedPath(int index) {
84         return this.isNew[index];
85     }
86 }
87
Popular Tags