View Javadoc

1   /*
2    * FilterEditorModelGroup.java
3    * Created on 11 Июль 2006 г., 16:58
4    */
5   
6   package org.weda.model.impl;
7   
8   import java.util.ArrayList;
9   import java.util.Collection;
10  import java.util.List;
11  import java.util.Set;
12  import org.weda.action.ActionContainer;
13  import org.weda.action.ActionExecutionContext;
14  import org.weda.action.ActionRegistry;
15  import org.weda.action.ActionRegistryException;
16  import org.weda.action.ActionState;
17  import org.weda.action.ExecutedActionInfo;
18  import org.weda.common.NamesListRegistry;
19  import org.weda.common.NamesListRegistryException;
20  import org.weda.enhance.InjectHivemindObject;
21  import org.weda.model.EditorModelGroupException;
22  import org.weda.property.PropertyDescriptor;
23  import org.weda.store.ObjectSource;
24  import org.weda.store.ObjectSourceRegistry;
25  import org.weda.store.QueryFilterElement;
26  
27  /**
28   *
29   * @author Mikhail Titov
30   */
31  public class FilterEditorModelGroup
32          extends BaseEditorModelGroup<FilterEditorModel> 
33          implements ActionContainer
34  {
35      private String objectSourceName;
36      @InjectHivemindObject()
37      private static ObjectSourceRegistry objectSourceRegistry;
38      @InjectHivemindObject()
39      private static ActionRegistry actionRegistry;
40      @InjectHivemindObject()
41      private static NamesListRegistry namesListRegistry;
42      private List<ActionContainer> actionContainers = 
43              new ArrayList<ActionContainer>(1);
44      //
45      private String namesListName;
46      
47      
48      public FilterEditorModelGroup(){
49          actionContainers.add(this);
50      }
51          
52      public void init() throws EditorModelGroupException {
53          try {
54              if (getNamesListName()!=null){
55                  List<String> names = 
56                          namesListRegistry.getNamesList(getNamesListName());
57                  for (String name: names){
58                      FilterEditorModel model = 
59                              new FilterEditorModel();                    
60                      model.setName(name);
61                      model.setPropertyPath(name);
62                      addEditorModel(model);
63                  }
64              }
65          } catch (NamesListRegistryException ex) {
66              throw new EditorModelGroupException(
67                      String.format(
68                          "Error while initializing editor model group (%s)"
69                          , getName())
70                      , ex);
71          }
72      }
73      
74      public QueryFilterElement getFilterElement(
75              String propertyPath, String objectAlias)
76          throws EditorModelGroupException
77      {
78          try {
79              ObjectSource objectSource = 
80                      objectSourceRegistry.getObjectSource(objectSourceName);
81              if (objectAlias == null)
82                  objectAlias = objectSource.getBaseClassAlias();
83              String filterElementId = 
84                      objectSource.getQueryFilter().createFilterElementId(
85                          propertyPath, objectAlias);
86              QueryFilterElement filterElement = 
87                      objectSource.getQueryFilter().getFilterElement(
88                          filterElementId);
89              if (filterElement==null)
90                  throw new EditorModelGroupException(
91                          "Query filter element not found");
92              return filterElement;
93          } catch (Exception ex) {
94              throw new EditorModelGroupException(
95                      String.format(
96                          "Can't extract query filter element (%s.%s) " +
97                          "from objectSource (%s)"
98                          , propertyPath, objectAlias, objectSourceName)
99                      , ex);
100         }       
101     }
102     
103     public PropertyDescriptor getPropertyDescriptor(String propertyPath)
104         throws EditorModelGroupException 
105     {
106         return null;
107     }
108 
109     public List<ActionContainer> getActionContainers() throws Exception {
110         return actionContainers;
111     }
112 
113     public String getObjectSourceName() {
114         return objectSourceName;
115     }
116 
117     public void setObjectSourceName(String objectSourceName) {
118         this.objectSourceName = objectSourceName;
119     }
120 
121     public ExecutedActionInfo executeAction(ActionExecutionContext context) 
122         throws ActionRegistryException 
123     {
124         context.setTargetObject(this);
125         return actionRegistry.executeAction(context);
126     }
127 
128     public boolean hasRegisteredActions() {
129         return actionRegistry.hasRegisteredActions(this.getClass(), this);
130     }
131 
132     public Set<Class> getDisabledActions() {
133         return null;
134     }
135 
136     public List<ActionState> getActionsStates() throws ActionRegistryException {
137         return actionRegistry.getActionsStates(this, this.getClass());
138     }
139 
140     public String getActionContainerName() {
141         return "FilterEditorGroupModel#"+getName();
142     }
143 
144     public String getNamesListName() {
145         return namesListName;
146     }
147 
148     public void setNamesListName(String namesListName) {
149         this.namesListName = namesListName;
150     }
151 
152     public boolean isMultiLeveledModelValues() 
153         throws EditorModelGroupException 
154     {
155         return false;
156     }
157     
158 }