blob: 17cab9713f17b3a454c1c53c87f37b2a4fca490c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
/*******************************************************************************
* Copyright (c) 2004, 2007 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.ats.editor.stateItem;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.Platform;
import org.eclipse.osee.ats.artifact.AbstractWorkflowArtifact;
import org.eclipse.osee.ats.internal.AtsPlugin;
import org.eclipse.osee.ats.workdef.StateDefinition;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.logging.OseeLog;
import org.osgi.framework.Bundle;
/**
* @author Donald G. Dunne
*/
public class AtsStateItemManager {
private final static List<IAtsStateItem> stateItems = new ArrayList<IAtsStateItem>();
public static List<IAtsStateItem> getStateItems(StateDefinition stateDef) throws OseeCoreException {
return getStateItems(stateDef.getFullName());
}
private static List<IAtsStateItem> getStateItems(String stateId) throws OseeCoreException {
loadAllStateItems();
List<IAtsStateItem> items = new ArrayList<IAtsStateItem>();
for (IAtsStateItem item : stateItems) {
if (item.getIds().contains(AtsStateItem.ALL_STATE_IDS) || item.getIds().contains(stateId)) {
items.add(item);
}
}
return items;
}
public static List<IAtsStateItem> getCurrentPageStateItems(AbstractWorkflowArtifact sma) throws OseeCoreException {
return getStateItems(sma.getStateDefinition().getFullName());
}
@SuppressWarnings({"rawtypes"})
private static void loadAllStateItems() {
if (stateItems.size() > 0) {
return;
}
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint("org.eclipse.osee.ats.AtsStateItem");
if (point == null) {
OseeLog.log(AtsPlugin.class, OseeLevel.SEVERE_POPUP, "Can't access AtsStateItem extension point");
return;
}
IExtension[] extensions = point.getExtensions();
for (IExtension extension : extensions) {
IConfigurationElement[] elements = extension.getConfigurationElements();
String classname = null;
String bundleName = null;
for (IConfigurationElement el : elements) {
if (el.getName().equals("AtsStateItem")) {
classname = el.getAttribute("classname");
bundleName = el.getContributor().getName();
if (classname != null && bundleName != null) {
Bundle bundle = Platform.getBundle(bundleName);
try {
Class taskClass = bundle.loadClass(classname);
Object obj = taskClass.newInstance();
if (obj == null) {
OseeLog.log(AtsPlugin.class, Level.SEVERE,
"Error Instantiating AtsStateItem extension \"" + classname + "\"", null);
} else {
stateItems.add((IAtsStateItem) obj);
}
} catch (Exception ex) {
OseeLog.log(AtsPlugin.class, OseeLevel.SEVERE_POPUP, "Error loading AtsStateItem extension", ex);
}
}
}
}
}
}
public static List<IAtsStateItem> getAllStateItems() {
return stateItems;
}
}
|