KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > formmodel > RowActionDefinition


1 /*
2  * Copyright 1999-2004 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;
17
18 import org.apache.cocoon.forms.event.ActionEvent;
19 import org.apache.cocoon.forms.event.ActionListener;
20
21 /**
22  *
23  * @author <a HREF="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
24  * @version $Id: RowActionDefinition.java 151179 2005-02-03 16:55:16Z tim $
25  */

26 public class RowActionDefinition extends ActionDefinition {
27     
28     public Widget createInstance() {
29         return new RowAction(this);
30     }
31     
32     /**
33      * Deletes the row containing this action. Action listeners, if any, are called <em>before</em>
34      * the row is deleted.
35      */

36     public static class DeleteRowDefinition extends RowActionDefinition {
37         
38         public boolean hasActionListeners() {
39             // We always want to be notified
40
return true;
41         }
42         
43         public void fireActionEvent(ActionEvent event) {
44             // Call event listeners, if any (the row still exists)
45
super.fireActionEvent(event);
46
47             // and delete the row
48
Repeater.RepeaterRow row = Repeater.getParentRow(event.getSourceWidget());
49             Repeater repeater = (Repeater)row.getParent();
50             repeater.removeRow(repeater.indexOf(row));
51         }
52     }
53     
54     /**
55      * Moves up the row containing this action. Action listeners, if any, are called <em>after</em>
56      * the row has been moved.
57      */

58     public static class MoveUpDefinition extends RowActionDefinition {
59         public MoveUpDefinition() {
60             super.addActionListener(new ActionListener() {
61
62                 public void actionPerformed(ActionEvent event) {
63                     Repeater.RepeaterRow row = Repeater.getParentRow(event.getSourceWidget());
64                     Repeater repeater = (Repeater)row.getParent();
65                     // Rotation: up in a table is left in a list!
66
repeater.moveRowLeft(repeater.indexOf(row));
67                 }
68             });
69         }
70     }
71     
72     /**
73      * Moves up the row containing this action. Action listeners, if any, are called <em>after</em>
74      * the row has been moved.
75      */

76     public static class MoveDownDefinition extends RowActionDefinition {
77         public MoveDownDefinition() {
78             super.addActionListener(new ActionListener() {
79
80                 public void actionPerformed(ActionEvent event) {
81                     Repeater.RepeaterRow row = Repeater.getParentRow(event.getSourceWidget());
82                     Repeater repeater = (Repeater)row.getParent();
83                     // Rotation : down in a table is right in a list!
84
repeater.moveRowRight(repeater.indexOf(row));
85                 }
86             });
87         }
88     }
89     
90     /**
91      * Adds a row after the one containing this action. Action listeners, if any, are called <em>after</em>
92      * the new row has been created.
93      */

94     public static class AddAfterDefinition extends RowActionDefinition {
95         public AddAfterDefinition() {
96             super.addActionListener(new ActionListener() {
97
98                 public void actionPerformed(ActionEvent event) {
99                     Repeater.RepeaterRow row = Repeater.getParentRow(event.getSourceWidget());
100                     Repeater repeater = (Repeater)row.getParent();
101                     repeater.addRow(repeater.indexOf(row)+1);
102                 }
103             });
104         }
105     }
106 }
107
Popular Tags