View Javadoc
1   /*
2    * Copyright (c) 2002-2022, City of 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.i18n.I18nService;
37  import fr.paris.lutece.portal.service.plugin.Plugin;
38  import fr.paris.lutece.portal.service.plugin.PluginService;
39  import fr.paris.lutece.portal.web.l10n.LocaleService;
40  import java.util.Locale;
41  
42  import org.apache.commons.lang3.ObjectUtils;
43  
44  /**
45   * Dashboard Component
46   */
47  public abstract class DashboardComponent implements IDashboardComponent
48  {
49      private String _strName;
50      private String _strRight;
51      private int _nZone;
52      private int _nOrder;
53      private Plugin _plugin;
54      private Locale _locale;
55  
56      /**
57       * Returns the Name
58       * 
59       * @return The Name
60       */
61      @Override
62      public String getName( )
63      {
64          return _strName;
65      }
66  
67      /**
68       * Sets the Name
69       * 
70       * @param strName
71       *            The Name
72       */
73      @Override
74      public void setName( String strName )
75      {
76          _strName = strName;
77      }
78  
79      /**
80       * Returns the PluginName
81       *
82       * @return The PluginName
83       */
84  
85      /**
86       * Returns the Right
87       * 
88       * @return The Right
89       */
90      @Override
91      public String getRight( )
92      {
93          return _strRight;
94      }
95  
96      /**
97       * Sets the Right
98       * 
99       * @param strRight
100      *            The Right
101      */
102     @Override
103     public void setRight( String strRight )
104     {
105         _strRight = strRight;
106     }
107 
108     /**
109      * Returns the Zone
110      * 
111      * @return The Zone
112      */
113     @Override
114     public int getZone( )
115     {
116         return _nZone;
117     }
118 
119     /**
120      * Sets the Zone
121      * 
122      * @param nZone
123      *            The Zone
124      */
125     @Override
126     public void setZone( int nZone )
127     {
128         _nZone = nZone;
129     }
130 
131     /**
132      * Returns the Order
133      * 
134      * @return The Order
135      */
136     @Override
137     public int getOrder( )
138     {
139         return _nOrder;
140     }
141 
142     /**
143      * Sets the Order
144      * 
145      * @param nOrder
146      *            The Order
147      */
148     @Override
149     public void setOrder( int nOrder )
150     {
151         _nOrder = nOrder;
152     }
153 
154     /**
155      * Returns the Plugin
156      * 
157      * @return The Plugin
158      */
159     @Override
160     public Plugin getPlugin( )
161     {
162         return _plugin;
163     }
164 
165     /**
166      * Sets the Plugin
167      * 
168      * @param plugin
169      *            The plugin
170      */
171     @Override
172     public void setPlugin( Plugin plugin )
173     {
174         _plugin = plugin;
175     }
176 
177     /**
178      * Compare component order
179      * 
180      * @param o
181      *            The component to compare to
182      * @return less than 0 if the order is lower, 0 if equals and greater than 0 if higher
183      */
184     @Override
185     public int compareTo( IDashboardComponent o )
186     {
187         return getOrder( ) - o.getOrder( );
188     }
189 
190     /**
191      * Tells if the component is enabled
192      * 
193      * @return true if enabled
194      */
195     @Override
196     public boolean isEnabled( )
197     {
198         return PluginService.isPluginEnable( _plugin.getName( ) );
199     }
200 
201     /**
202      *
203      * {@inheritDoc}
204      */
205     @Override
206     public boolean equals( Object obj )
207     {
208         if ( obj instanceof IDashboardComponent )
209         {
210             IDashboardComponent../../fr/paris/lutece/portal/service/dashboard/IDashboardComponent.html#IDashboardComponent">IDashboardComponent other = (IDashboardComponent) obj;
211 
212             return ObjectUtils.equals( this.getName( ), other.getName( ) );
213         }
214 
215         return false;
216     }
217 
218     /**
219      *
220      * {@inheritDoc}
221      */
222     @Override
223     public int hashCode( )
224     {
225         return ObjectUtils.hashCode( this.getName( ) );
226     }
227 
228     /**
229      *
230      * {@inheritDoc}
231      */
232     @Override
233     public String toString( )
234     {
235         return getClass( ).getName( ) + "[name=" + this.getName( ) + ", zone=" + this.getZone( ) + ", order=" + this.getOrder( ) + "]";
236     }
237 
238     /**
239      *
240      * {@inheritDoc}
241      */
242     @Override
243     public void setLocale( Locale locale )
244     {
245         _locale = locale;
246     }
247 
248     @Override
249     public String getDescription( )
250     {
251         String strKey;
252         Locale locale = ( _locale != null ) ? _locale : LocaleService.getDefault( );
253 
254         if ( _plugin == PluginService.getCore( ) )
255         {
256             strKey = "portal.dashboard.dashboardComponent." + _strName + ".description";
257         }
258         else
259         {
260             strKey = _plugin.getName( ) + ".dashboardComponent." + _strName + ".description";
261         }
262         return I18nService.getLocalizedString( strKey, locale );
263     }
264 }