001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.forms.formmodel;
018:
019: import org.apache.cocoon.forms.event.ActionEvent;
020: import org.apache.cocoon.forms.event.ActionListener;
021:
022: /**
023: *
024: * @version $Id: RowActionDefinition.java 449149 2006-09-23 03:58:05Z crossley $
025: */
026: public class RowActionDefinition extends ActionDefinition {
027:
028: public Widget createInstance() {
029: return new RowAction(this );
030: }
031:
032: /**
033: * Deletes the row containing this action. Action listeners, if any, are called <em>before</em>
034: * the row is deleted.
035: */
036: public static class DeleteRowDefinition extends RowActionDefinition {
037:
038: public boolean hasActionListeners() {
039: // We always want to be notified
040: return true;
041: }
042:
043: public void fireActionEvent(ActionEvent event) {
044: // Call event listeners, if any (the row still exists)
045: super .fireActionEvent(event);
046:
047: // and delete the row
048: Repeater.RepeaterRow row = Repeater.getParentRow(event
049: .getSourceWidget());
050: Repeater repeater = (Repeater) row.getParent();
051: repeater.removeRow(repeater.indexOf(row));
052: }
053: }
054:
055: /**
056: * Moves up the row containing this action. Action listeners, if any, are called <em>after</em>
057: * the row has been moved.
058: */
059: public static class MoveUpDefinition extends RowActionDefinition {
060: public MoveUpDefinition() {
061: super .addActionListener(new ActionListener() {
062:
063: public void actionPerformed(ActionEvent event) {
064: Repeater.RepeaterRow row = Repeater
065: .getParentRow(event.getSourceWidget());
066: Repeater repeater = (Repeater) row.getParent();
067: // Rotation: up in a table is left in a list!
068: repeater.moveRowLeft(repeater.indexOf(row));
069: }
070: });
071: }
072: }
073:
074: /**
075: * Moves up the row containing this action. Action listeners, if any, are called <em>after</em>
076: * the row has been moved.
077: */
078: public static class MoveDownDefinition extends RowActionDefinition {
079: public MoveDownDefinition() {
080: super .addActionListener(new ActionListener() {
081:
082: public void actionPerformed(ActionEvent event) {
083: Repeater.RepeaterRow row = Repeater
084: .getParentRow(event.getSourceWidget());
085: Repeater repeater = (Repeater) row.getParent();
086: // Rotation : down in a table is right in a list!
087: repeater.moveRowRight(repeater.indexOf(row));
088: }
089: });
090: }
091: }
092:
093: /**
094: * Adds a row after the one containing this action. Action listeners, if any, are called <em>after</em>
095: * the new row has been created.
096: */
097: public static class AddAfterDefinition extends RowActionDefinition {
098: public AddAfterDefinition() {
099: super .addActionListener(new ActionListener() {
100:
101: public void actionPerformed(ActionEvent event) {
102: Repeater.RepeaterRow row = Repeater
103: .getParentRow(event.getSourceWidget());
104: Repeater repeater = (Repeater) row.getParent();
105: repeater.addRow(repeater.indexOf(row) + 1);
106: }
107: });
108: }
109: }
110: }
|