1 /*
2 * Copyright (c) 2002-2014, Mairie de Paris
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice
10 * and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice
13 * and the following disclaimer in the documentation and/or other materials
14 * provided with the distribution.
15 *
16 * 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 *
32 * License 1.0
33 */
34 package fr.paris.lutece.portal.service.dashboard;
35
36 import fr.paris.lutece.portal.service.plugin.Plugin;
37 import fr.paris.lutece.portal.service.plugin.PluginService;
38
39 import org.apache.commons.lang.ObjectUtils;
40
41
42 /**
43 * Dashboard Component
44 */
45 public abstract class DashboardComponent implements IDashboardComponent
46 {
47 private String _strName;
48 private String _strRight;
49 private int _nZone;
50 private int _nOrder;
51 private Plugin _plugin;
52
53 /**
54 * Returns the Name
55 * @return The Name
56 */
57 @Override
58 public String getName( )
59 {
60 return _strName;
61 }
62
63 /**
64 * Sets the Name
65 * @param strName The Name
66 */
67 @Override
68 public void setName( String strName )
69 {
70 _strName = strName;
71 }
72
73 /**
74 * Returns the PluginName
75 *
76 * @return The PluginName
77 */
78
79 /**
80 * Returns the Right
81 * @return The Right
82 */
83 @Override
84 public String getRight( )
85 {
86 return _strRight;
87 }
88
89 /**
90 * Sets the Right
91 * @param strRight The Right
92 */
93 @Override
94 public void setRight( String strRight )
95 {
96 _strRight = strRight;
97 }
98
99 /**
100 * Returns the Zone
101 * @return The Zone
102 */
103 @Override
104 public int getZone( )
105 {
106 return _nZone;
107 }
108
109 /**
110 * Sets the Zone
111 * @param nZone The Zone
112 */
113 @Override
114 public void setZone( int nZone )
115 {
116 _nZone = nZone;
117 }
118
119 /**
120 * Returns the Order
121 * @return The Order
122 */
123 @Override
124 public int getOrder( )
125 {
126 return _nOrder;
127 }
128
129 /**
130 * Sets the Order
131 * @param nOrder The Order
132 */
133 @Override
134 public void setOrder( int nOrder )
135 {
136 _nOrder = nOrder;
137 }
138
139 /**
140 * Returns the Plugin
141 * @return The Plugin
142 */
143 @Override
144 public Plugin getPlugin( )
145 {
146 return _plugin;
147 }
148
149 /**
150 * Sets the Plugin
151 * @param plugin The plugin
152 */
153 @Override
154 public void setPlugin( Plugin plugin )
155 {
156 _plugin = plugin;
157 }
158
159 /**
160 * Compare component order
161 * @param o The component to compare to
162 * @return less than 0 if the order is lower, 0 if equals and greater than 0 if higher
163 */
164 @Override
165 public int compareTo( IDashboardComponent o )
166 {
167 return getOrder( ) - o.getOrder( );
168 }
169
170 /**
171 * Tells if the component is enabled
172 * @return true if enabled
173 */
174 @Override
175 public boolean isEnabled( )
176 {
177 return PluginService.isPluginEnable( _plugin.getName( ) );
178 }
179
180 /**
181 *
182 * {@inheritDoc}
183 */
184 @Override
185 public boolean equals( Object obj )
186 {
187 if ( obj instanceof IDashboardComponent )
188 {
189 IDashboardComponent other = (IDashboardComponent) obj;
190
191 return ObjectUtils.equals( this.getName( ), other.getName( ) );
192 }
193
194 return false;
195 }
196
197 /**
198 *
199 * {@inheritDoc}
200 */
201 @Override
202 public int hashCode( )
203 {
204 return ObjectUtils.hashCode( this.getName( ) );
205 }
206
207 /**
208 *
209 * {@inheritDoc}
210 */
211 @Override
212 public String toString( )
213 {
214 return getClass( ).getName( ) + "[name=" + this.getName( ) + ", zone=" + this.getZone( ) + ", order=" +
215 this.getOrder( ) + "]";
216 }
217 }