01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.forms.formmodel.tree;
18:
19: import org.apache.cocoon.forms.event.WidgetEvent;
20:
21: /**
22: * An event fired when the selection of a {@link Tree} changes.
23: *
24: * @version $Id: TreeSelectionEvent.java 449149 2006-09-23 03:58:05Z crossley $
25: */
26: public class TreeSelectionEvent extends WidgetEvent {
27:
28: TreePath[] paths;
29: boolean[] isNew;
30:
31: public TreeSelectionEvent(Tree source, TreePath path, boolean isNew) {
32: super (source);
33: this .paths = new TreePath[] { path };
34: this .isNew = new boolean[] { isNew };
35: }
36:
37: public TreeSelectionEvent(Tree source, TreePath paths[],
38: boolean areNew[]) {
39: super (source);
40: this .paths = paths;
41: this .isNew = areNew;
42: }
43:
44: public TreeSelectionEvent(Tree source, TreePath paths[],
45: boolean allNew) {
46: super (source);
47: this .paths = paths;
48:
49: // Fill isNew with allNew
50: this .isNew = new boolean[paths.length];
51: for (int i = 0; i < isNew.length; i++) {
52: this .isNew[i] = allNew;
53: }
54: }
55:
56: public Tree getTree() {
57: return (Tree) super .getSource();
58: }
59:
60: /**
61: * Get the first path element.
62: */
63: public TreePath getPath() {
64: return this .paths[0];
65: }
66:
67: /**
68: * Is the first path a new addition to the selection?
69: */
70: public boolean isAddedPath() {
71: return this .isNew[0];
72: }
73:
74: /**
75: * Get paths that have been added or removed from the selection.
76: */
77: public TreePath[] getPaths() {
78: return this .paths;
79: }
80:
81: /**
82: * Was the <code>index</code>th path added to the selection?
83: */
84: public boolean isAddedPath(int index) {
85: return this.isNew[index];
86: }
87: }
|