1 package org.weda.model.impl;
2
3 import java.util.Arrays;
4 import java.util.List;
5 import org.weda.action.ActionContainer;
6 import org.weda.common.NamesListRegistry;
7 import org.weda.common.NamesListRegistryException;
8 import org.weda.enhance.InjectHivemindObject;
9 import org.weda.model.EditorModelGroupException;
10 import org.weda.store.ObjectSourceRegistry;
11 import org.weda.store.impl.ObjectSet;
12
13 /**
14 *
15 * @author Mikhail Titov
16 */
17 public class ObjectSourceEditorModelGroup
18 extends ObjectSetEditorModelGroup<ObjectSetEditorModel>
19 {
20 private String objectSourceName;
21 @InjectHivemindObject()
22 private static ObjectSourceRegistry objectSourceRegistry;
23 @InjectHivemindObject()
24 private static NamesListRegistry namesListRegistry;
25
26 private String namesListName;
27
28 public void init() throws EditorModelGroupException {
29 try {
30 if (namesListName!=null){
31 List<String> names =
32 namesListRegistry.getNamesList(namesListName);
33 for (String name: names){
34 ObjectSetEditorModel model =
35 new ObjectSetEditorModel();
36 model.setName(name);
37 model.setPropertyPath(name);
38 addEditorModel(model);
39 }
40 }
41 } catch (NamesListRegistryException ex) {
42 throw new EditorModelGroupException(
43 String.format(
44 "Error while initializing editor model group (%s)"
45 , getName())
46 , ex);
47 }
48 }
49
50 public ObjectSet getObjectSet() throws EditorModelGroupException {
51 try{
52 return
53 objectSourceRegistry
54 .getObjectSource(getObjectSourceName())
55 .getSelectedObjectSet();
56 }catch(Exception e){
57 throw new EditorModelGroupException(
58 String.format(
59 "Can't get object set for datasource (%s)"
60 , getObjectSourceName())
61 , e);
62 }
63 }
64
65 public String getObjectSourceName() {
66 return objectSourceName;
67 }
68
69 public void setObjectSourceName(String dataSourceName) {
70 this.objectSourceName = dataSourceName;
71 }
72
73 public List<ActionContainer> getActionContainers() throws Exception {
74 return Arrays.asList(
75 (ActionContainer)objectSourceRegistry
76 .getObjectSource(objectSourceName));
77 }
78
79 public String getNamesListName() {
80 return namesListName;
81 }
82
83 public void setNamesListName(String namesListName) {
84 this.namesListName = namesListName;
85 }
86 }