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