diff options
Diffstat (limited to 'plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/editor/stateItem/AtsStateItemManager.java')
-rw-r--r-- | plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/editor/stateItem/AtsStateItemManager.java | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/editor/stateItem/AtsStateItemManager.java b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/editor/stateItem/AtsStateItemManager.java new file mode 100644 index 00000000000..27d5f12865b --- /dev/null +++ b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/editor/stateItem/AtsStateItemManager.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * 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.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(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.getWorkPageDefinition().getId()); + } + + @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; + } +} |