1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 /***
19 * <p>Title: WSMO Studio</p>
20 * <p>Description: Semantic Web Service Editor</p>
21 * <p>Copyright: Copyright (c) 2004-2006</p>
22 * <p>Company: OntoText Lab. / SIRMA </p>
23 */
24
25 package org.wsmostudio.repository;
26
27 import java.util.*;
28
29 import org.eclipse.jface.dialogs.MessageDialog;
30 import org.eclipse.jface.resource.JFaceResources;
31 import org.eclipse.swt.graphics.Image;
32 import org.eclipse.swt.widgets.Display;
33 import org.eclipse.ui.*;
34 import org.wsmo.datastore.WsmoRepository;
35 import org.wsmostudio.repository.ui.RepositoryEditor;
36 import org.wsmostudio.repository.ui.actions.ActionsManager;
37 import org.wsmostudio.repository.ui.manageractions.ExtensionActionsManager;
38 import org.wsmostudio.runtime.*;
39 import org.wsmostudio.runtime.extension.Configurator;
40
41
42 public class Registry {
43
44 private static Registry _instance = new Registry();
45
46 private ActionsManager actionsManager;
47 private ExtensionActionsManager actionsContentManager;
48
49 private Map<WsmoRepository, Configurator> repoStore;
50 private Map<String, Image> iconsMap;
51 private Set<WsmoRepository> configuredSet;
52
53 public static Registry getInstance() {
54 return _instance;
55 }
56
57 public Registry() {
58 iconsMap = new HashMap<String, Image>();
59 configuredSet = new HashSet<WsmoRepository>();
60 actionsManager = new ActionsManager();
61 actionsContentManager = new ExtensionActionsManager();
62 repoStore = ExtensionManager.loadRepositories();
63
64 }
65
66 public void addRepository(String repoName, String repoType) {
67 try {
68 WsmoRepository repInstance = ExtensionManager.createRepository(repoName, repoType);
69 Configurator conf = ExtensionManager.getConfiguratorFor(repoType);
70 this.repoStore.put(repInstance, conf);
71 }
72 catch(Exception ex) {
73 MessageDialog.openError(Display.getCurrent().getActiveShell(),
74 "Plugin Error",
75 ex.getMessage());
76 }
77 }
78
79 public void removeRepository(WsmoRepository repository) {
80 RepositoryPlugin.getDefault()
81 .getPluginPreferences()
82 .setToDefault(ExtensionManager.REP_PROP_PREFIX
83 + repository.getDescription());
84
85 repoStore.remove(repository);
86 }
87
88 public static void reloadRepository(WsmoRepository repo) {
89 IWorkbenchPage page =
90 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
91 if (page == null) {
92 return;
93 }
94 IEditorReference[] refs = page.getEditorReferences();
95 if (refs == null) {
96 return;
97 }
98 for(int i = 0; i < refs.length; i++) {
99 try {
100 if (repo.equals(
101 refs[i].getEditorInput().getAdapter(WsmoRepository.class))) {
102 IEditorPart editor = refs[i].getEditor(true);
103 if (editor instanceof RepositoryEditor) {
104 ((RepositoryEditor)editor).reloadRepositoryContent();
105 return;
106 }
107 }
108 }
109 catch(PartInitException pie) {
110 continue;
111 }
112 }
113 }
114
115
116 public boolean configureRepository(WsmoRepository repository, boolean forceConfig) {
117 if (configuredSet.contains(repository)
118 && false == forceConfig) {
119 return true;
120 }
121 try {
122 Configurator conf = repoStore.get(repository);
123 if (conf == null) {
124 throw new Exception("Configurator for repository '"
125 + repository.getDescription()
126 + "' not found!");
127 }
128 boolean status = ExtensionManager.configureRepository(repository, conf, forceConfig);
129 if (status == false) {
130 return false;
131 }
132 }
133 catch(Exception ex) {
134 MessageDialog.openError(Display.getCurrent().getActiveShell(),
135 "Repository Error",
136 "Unable to configure repository '"
137 + repository.getDescription()
138 + "':\n"
139 + ex.getMessage());
140 LogManager.logError("Repository Error", ex);
141 return false;
142 }
143 configuredSet.add(repository);
144 return true;
145 }
146
147 public Map<WsmoRepository, Configurator> getRepositoriesData() {
148 return this.repoStore;
149 }
150
151 public ActionsManager getActionsManager() {
152 return this.actionsManager;
153 }
154
155 public ExtensionActionsManager getContentActionsManager() {
156 return this.actionsContentManager;
157 }
158
159 public Image iconForRepository(String type) {
160 if (type == null) {
161 return null;
162 }
163 if (iconsMap.containsKey(type)) {
164 return iconsMap.get(type);
165 }
166 Image newIcon = ExtensionManager.loadImageForType(type);
167 if (newIcon != null) {
168 iconsMap.put(type, newIcon);
169 return newIcon;
170 }
171 newIcon = JFaceResources.getImageRegistry()
172 .get(WsmoImageRegistry.REPOSITORY_ICON);
173 if (newIcon == null) {
174 WSMORuntime.forceEarlyInit();
175 }
176 return JFaceResources.getImageRegistry()
177 .get(WsmoImageRegistry.REPOSITORY_ICON);
178 }
179
180 }
181
182
183
184
185
186
187
188
189
190
191
192
193
194