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.wicket.version.undo;
18:
19: import org.apache.wicket.Component;
20: import org.apache.wicket.util.lang.Classes;
21: import org.slf4j.Logger;
22: import org.slf4j.LoggerFactory;
23:
24: /**
25: * An add change operation.
26: *
27: * @author Jonathan Locke
28: */
29: class Add extends Change {
30: private static final long serialVersionUID = 1L;
31:
32: /** log. */
33: private static final Logger log = LoggerFactory
34: .getLogger(Add.class);
35:
36: /** subject. */
37: private final Component component;
38:
39: /**
40: * Construct.
41: *
42: * @param component
43: * subject
44: */
45: Add(final Component component) {
46: if (component == null) {
47: throw new IllegalArgumentException(
48: "argument component must be not null");
49: }
50:
51: if (component.getParent() == null) {
52: throw new IllegalStateException("component " + component
53: + " doesn't have a parent");
54: }
55:
56: if (log.isDebugEnabled()) {
57: log.debug("RECORD ADD: added " + component.getPath() + " ("
58: + Classes.simpleName(component.getClass()) + "@"
59: + component.hashCode() + ") to parent");
60: }
61:
62: this .component = component;
63: }
64:
65: /**
66: * @see org.apache.wicket.version.undo.Change#undo()
67: */
68: public void undo() {
69: if (log.isDebugEnabled()) {
70: log.debug("UNDO ADD: removing " + component.getPath()
71: + " (" + Classes.simpleName(component.getClass())
72: + "@" + component.hashCode() + ") from parent");
73: }
74:
75: // check if somehow the component isn't already removed.
76: if (component.getParent() != null) {
77: component.remove();
78: }
79: }
80:
81: /**
82: * @see java.lang.Object#toString()
83: */
84: public String toString() {
85: return "Add[component: " + component.getPath() + "]";
86: }
87: }
|