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.behavior;
18:
19: import org.apache.wicket.Component;
20: import org.apache.wicket.markup.ComponentTag;
21:
22: /**
23: * A lightweight version of the attribute modifier. This is convenient for
24: * simpler situations where you know the value upfront and you do not need a
25: * pull-based model.
26: *
27: * @author Igor Vaynberg (ivaynberg)
28: */
29: public class SimpleAttributeModifier extends AbstractBehavior {
30: private static final long serialVersionUID = 1L;
31:
32: /** The attribute */
33: private final String attribute;
34:
35: /** The value to set */
36: private final CharSequence value;
37:
38: /**
39: * Construct.
40: *
41: * @param attribute
42: * The attribute
43: * @param value
44: * The value
45: */
46: public SimpleAttributeModifier(final String attribute,
47: final CharSequence value) {
48: if (attribute == null) {
49: throw new IllegalArgumentException(
50: "Argument [attr] cannot be null");
51: }
52: if (value == null) {
53: throw new IllegalArgumentException(
54: "Argument [value] cannot be null");
55: }
56: this .attribute = attribute;
57: this .value = value;
58: }
59:
60: /**
61: * @return the attribute
62: */
63: public final String getAttribute() {
64: return attribute;
65: }
66:
67: /**
68: * @return the value to set
69: */
70: public final CharSequence getValue() {
71: return value;
72: }
73:
74: /**
75: * This method is deprecated, use the isEnabled(Component)
76: *
77: * @return true
78: * @deprecated use isEnabled(Component) now.
79: */
80: public final boolean isEnabled() {
81: return true;
82: }
83:
84: /**
85: * @see org.apache.wicket.behavior.AbstractBehavior#onComponentTag(org.apache.wicket.Component,
86: * org.apache.wicket.markup.ComponentTag)
87: */
88: public void onComponentTag(final Component component,
89: final ComponentTag tag) {
90: if (isEnabled(component)) {
91: tag.getAttributes().put(attribute, value);
92: }
93: }
94: }
|