1   /*
2    * Copyright 2003 - 2013 The eFaps Team
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   * Revision:        $Rev$
17   * Last Changed:    $Date$
18   * Last Changed By: $Author$
19   */
20  
21  package org.efaps.admin.ui.field;
22  
23  import org.efaps.util.cache.CacheReloadException;
24  
25  
26  /**
27   * @author The eFaps Team
28   * @version $Id$
29   */
30  public class FieldCommand
31      extends Field
32  {
33      /**
34       * Needed for serialization.
35       */
36      private static final long serialVersionUID = 1L;
37  
38      /**
39       * Must the button rendered? Default: true
40       */
41      private boolean renderButton = true;
42  
43      /**
44       * Must the field appended?
45       */
46      private boolean append;
47  
48      /**
49       * Target field.
50       */
51      private String targetField;
52  
53      /**
54       * Icon to be displayed on the button.
55       */
56      private String buttonIcon;
57  
58      /**
59       *
60       * @param _id       id of the field
61       * @param _uuid     UUID of the field
62       * @param _name     name of the field
63       */
64      public FieldCommand(final long _id,
65                          final String _uuid,
66                          final String _name)
67      {
68          super(_id, _uuid, _name);
69      }
70  
71      /**
72       * Returns for given parameter <i>_id</i> the instance of class
73       * {@link Field}.
74       *
75       * @param _id       id to search in the cache
76       * @return instance of class {@link Field}
77       */
78      public static FieldCommand get(final long _id)
79      {
80          return (FieldCommand) Field.get(_id);
81      }
82  
83      /**
84       * Sets the property for this field command. This includes
85       * <ul>
86       * <li>{@link #renderButton}</li>
87       * <li>{@link #append}</li>
88       * <li>{@link #targetField}</li>
89       * </ul>
90       *
91       * @param _name     name / key of the property
92       * @param _value    value of the property
93       * @throws CacheReloadException from called super property method
94       */
95      @Override
96      protected void setProperty(final String _name,
97                                 final String _value)
98          throws CacheReloadException
99      {
100         if ("CmdRenderButton".equals(_name)) {
101             this.renderButton = !("false".equalsIgnoreCase(_value));
102         } else if ("CmdAppend".equals(_name)) {
103             this.append = "true".equalsIgnoreCase(_value);
104         } else if ("CmdTargetField".equals(_name)) {
105             this.targetField = _value;
106         } else if ("CmdIcon".equals(_name)) {
107             this.buttonIcon = _value;
108         }   else {
109             super.setProperty(_name, _value);
110         }
111     }
112 
113     /**
114      * Getter method for instance variable {@link #renderButton}.
115      *
116      * @return value of instance variable {@link #renderButton}
117      */
118     public boolean isRenderButton()
119     {
120         return this.renderButton;
121     }
122 
123     /**
124      * Getter method for instance variable {@link #append}.
125      *
126      * @return value of instance variable {@link #append}
127      */
128     public boolean isAppend()
129     {
130         return this.append;
131     }
132 
133     /**
134      * Getter method for instance variable {@link #targetField}.
135      *
136      * @return value of instance variable {@link #targetField}
137      */
138     public String getTargetField()
139     {
140         return this.targetField;
141     }
142 
143     /**
144      * Getter method for the instance variable {@link #buttonIcon}.
145      *
146      * @return value of instance variable {@link #buttonIcon}
147      */
148     public String getButtonIcon()
149     {
150         return this.buttonIcon;
151     }
152 }