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.ci.CIAdminUserInterface;
26  import org.efaps.util.EFapsException;
27  import org.efaps.util.cache.CacheReloadException;
28  import org.slf4j.Logger;
29  import org.slf4j.LoggerFactory;
30  
31  /**
32   * @author The eFaps Team
33   * @version $Id$
34   *
35   */
36  public class Search
37      extends AbstractMenu
38  {
39  
40      /**
41       * Logging instance used in this class.
42       */
43      protected static final Logger LOG = LoggerFactory.getLogger(Search.class);
44  
45      /**
46       * Needed for serialization.
47       */
48      private static final long serialVersionUID = 1L;
49  
50      /**
51       * Stores the default search command used when the search is called.
52       */
53      private AbstractCommand defaultCommand = null;
54  
55      /**
56       * This is the constructor to create a new instance of the class Search. The
57       * parameter <i>_name</i> is a must value to identify clearly the search
58       * instance.
59       *
60       * @param _id search id
61       * @param _uuid uuid for this search
62       * @param _name search name
63       */
64      public Search(final Long _id,
65                    final String _uuid,
66                    final String _name)
67      {
68          super(_id, _uuid, _name);
69      }
70  
71      /**
72       * An sub command or menu with the given id is added to this menu.
73       *
74       * @param _sortId id used to sort
75       * @param _id command / menu id
76       * @throws CacheReloadException on error
77       */
78      @Override
79      protected void add(final long _sortId,
80                         final long _id)
81          throws CacheReloadException
82      {
83          final Command command = Command.get(_id);
84          if (command == null) {
85              final Menu subMenu = Menu.get(_id);
86              add(_sortId, subMenu);
87          } else {
88              add(_sortId, command);
89          }
90      }
91  
92      /**
93       * {@inheritDoc}
94       */
95      @Override
96      protected void setLinkProperty(final UUID _linkTypeUUID,
97                                     final long _toId,
98                                     final UUID _toTypeUUID,
99                                     final String _toName)
100         throws EFapsException
101     {
102         if (_linkTypeUUID.equals(CIAdminUserInterface.LinkDefaultSearchCommand.uuid)) {
103             this.defaultCommand = Command.get(_toId);
104             if (this.defaultCommand == null) {
105                 this.defaultCommand = Menu.get(_toId);
106             }
107         }
108         super.setLinkProperty(_linkTypeUUID, _toId, _toTypeUUID, _toName);
109     }
110 
111     /**
112      * This is the getter method for the instance variable
113      * {@link #defaultCommand}.
114      *
115      * @return value of instance variable {@link #defaultCommand}
116      * @see #defaultCommand
117      */
118     public AbstractCommand getDefaultCommand()
119     {
120         return this.defaultCommand;
121     }
122 
123     /**
124      * Returns for given parameter <i>_id</i> the instance of class {@link Form}
125      * .
126      *
127      * @param _id id to search in the cache
128      * @return instance of class {@link Form}
129      * @throws CacheReloadException on error
130      */
131     public static Search get(final long _id)
132         throws CacheReloadException
133     {
134         return AbstractUserInterfaceObject.<Search>get(_id, Search.class, CIAdminUserInterface.Search.getType());
135     }
136 
137     /**
138      * Returns for given parameter <i>_name</i> the instance of class
139      * {@link Command}.
140      *
141      * @param _name name to search in the cache
142      * @return instance of class {@link Command}
143      * @throws CacheReloadException on error
144      */
145     public static Search get(final String _name)
146         throws CacheReloadException
147     {
148         return AbstractUserInterfaceObject.<Search>get(_name, Search.class, CIAdminUserInterface.Search.getType());
149     }
150 
151     /**
152      * Returns for given parameter <i>_name</i> the instance of class
153      * {@link Command}.
154      *
155      * @param _uuid uuid to search in the cache
156      * @return instance of class {@link Command}
157      * @throws CacheReloadException on error
158      */
159     public static Search get(final UUID _uuid)
160         throws CacheReloadException
161     {
162         return AbstractUserInterfaceObject.<Search>get(_uuid, Search.class, CIAdminUserInterface.Search.getType());
163     }
164 }