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;
22
23 import java.util.UUID;
24
25 import org.efaps.admin.datamodel.Type;
26 import org.efaps.ci.CIAdminUserInterface;
27 import org.efaps.util.EFapsException;
28 import org.efaps.util.RequestHandler;
29 import org.efaps.util.cache.CacheReloadException;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 /**
34 * @author The eFaps Team
35 * @version $Id$ TODO:
36 * description
37 */
38 public class Image
39 extends AbstractUserInterfaceObject
40 {
41 /**
42 * Logging instance used in this class.
43 */
44 protected static final Logger LOG = LoggerFactory.getLogger(Image.class);
45
46 /**
47 * Needed for serialization.
48 */
49 private static final long serialVersionUID = 1L;
50
51 /**
52 * Constructor to set the id and name of the command object.
53 *
54 * @param _id id of the command to set
55 * @param _uuid uuid of the command to set
56 * @param _name name of the command to set
57 */
58 public Image(final Long _id,
59 final String _uuid,
60 final String _name)
61 {
62 super(_id, _uuid, _name);
63 }
64
65 /**
66 * Returns the URL of this image.
67 *
68 * @return URL of this image
69 */
70 public String getUrl()
71 {
72 return RequestHandler.replaceMacrosInUrl(RequestHandler.URL_IMAGE + getName());
73 }
74
75 /**
76 * Returns for given parameter <i>_id</i> the instance of class
77 * {@link Image}.
78 *
79 * @param _id id to search in the cache
80 * @return instance of class {@link Image}
81 * @throws CacheReloadException on error
82 * @see #getCache
83 */
84 public static Image get(final long _id)
85 throws CacheReloadException
86 {
87 return AbstractUserInterfaceObject.<Image>get(_id, Image.class, CIAdminUserInterface.Image.getType());
88 }
89
90 /**
91 * Returns for given parameter <i>_name</i> the instance of class
92 * {@link Image}.
93 *
94 * @param _name name to search in the cache
95 * @return instance of class {@link Image}
96 * @throws CacheReloadException on error
97 * @see #getCache
98 */
99 public static Image get(final String _name)
100 throws CacheReloadException
101 {
102 return AbstractUserInterfaceObject.<Image>get(_name, Image.class, CIAdminUserInterface.Image.getType());
103 }
104
105 /**
106 * Returns for given parameter <i>UUID</i> the instance of class
107 * {@link Image}.
108 *
109 * @param _uuid UUID to search in the cache
110 * @return instance of class {@link Image}
111 * @throws CacheReloadException on error
112 * @see #getCache
113 */
114 public static Image get(final UUID _uuid)
115 throws CacheReloadException
116 {
117 return AbstractUserInterfaceObject.<Image>get(_uuid, Image.class, CIAdminUserInterface.Image.getType());
118 }
119
120 /**
121 * Returns for given type the type tree menu. If no type tree menu is
122 * defined for the type, it is searched if for parent type a menu is
123 * defined.
124 *
125 * @param _type type for which the type tree menu is searched
126 * @return Image for type tree menu for given type if found; otherwise
127 * <code>null</code>.
128 * @throws EFapsException on error
129 */
130 public static Image getTypeIcon(final Type _type)
131 throws EFapsException
132 {
133 Image ret = null;
134 if (_type != null) {
135 ret = _type.getTypeIcon();
136 }
137 return ret;
138 }
139
140 @Override
141 public boolean equals(final Object _obj)
142 {
143 boolean ret;
144 if (_obj instanceof Image) {
145 ret = ((Image) _obj).getId() == getId();
146 } else {
147 ret = super.equals(_obj);
148 }
149 return ret;
150 }
151
152 @Override
153 public int hashCode()
154 {
155 return Long.valueOf(getId()).intValue();
156 }
157 }