KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > woody > formmodel > RowActionDefinitionBuilder


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.woody.formmodel;
17
18 import java.util.Iterator JavaDoc;
19
20 import org.apache.cocoon.woody.event.ActionListener;
21 import org.apache.cocoon.woody.util.DomHelper;
22 import org.w3c.dom.Element JavaDoc;
23
24 /**
25  *
26  * @author <a HREF="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
27  * @version CVS $Id: RowActionDefinitionBuilder.java 30932 2004-07-29 17:35:38Z vgritsenko $
28  */

29 public class RowActionDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
30     
31     
32     public WidgetDefinition buildWidgetDefinition(Element JavaDoc widgetElement) throws Exception JavaDoc {
33         String JavaDoc actionCommand = DomHelper.getAttribute(widgetElement, "action-command");
34         RowActionDefinition definition = createDefinition(widgetElement, actionCommand);
35         setLocation(widgetElement, definition);
36         setId(widgetElement, definition);
37         setDisplayData(widgetElement, definition);
38
39         definition.setActionCommand(actionCommand);
40
41         Iterator JavaDoc iter = buildEventListeners(widgetElement, "on-activate", ActionListener.class).iterator();
42         while (iter.hasNext()) {
43             definition.addActionListener((ActionListener)iter.next());
44         }
45
46         return definition;
47     }
48     
49     protected RowActionDefinition createDefinition(Element JavaDoc element, String JavaDoc actionCommand) throws Exception JavaDoc {
50
51         if ("delete".equals(actionCommand)) {
52             return new RowActionDefinition.DeleteRowDefinition();
53
54         } else if ("add-after".equals(actionCommand)) {
55             return new RowActionDefinition.AddAfterDefinition();
56
57         } else if ("move-up".equals(actionCommand)) {
58             return new RowActionDefinition.MoveUpDefinition();
59
60         } else if ("move-down".equals(actionCommand)) {
61             return new RowActionDefinition.MoveDownDefinition();
62
63         } else {
64             throw new Exception JavaDoc("Unknown repeater row action '" + actionCommand + "' at " + DomHelper.getLineLocation(element));
65         }
66     }
67 }
68
69
Popular Tags