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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
/*******************************************************************************
* 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.framework.ui.skynet.blam;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.logging.Level;
import org.eclipse.osee.framework.access.AccessControlManager;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.plugin.core.util.ExtensionDefinedObjects;
import org.eclipse.osee.framework.ui.plugin.PluginUiImage;
import org.eclipse.osee.framework.ui.plugin.xnavigate.IXNavigateCommonItem;
import org.eclipse.osee.framework.ui.plugin.xnavigate.XNavigateItem;
import org.eclipse.osee.framework.ui.skynet.FrameworkImage;
import org.eclipse.osee.framework.ui.skynet.internal.Activator;
import org.eclipse.osee.framework.ui.skynet.widgets.xnavigate.XNavigateItemBlam;
/**
* @author Donald G. Dunne
*/
public class BlamContributionManager implements IXNavigateCommonItem {
private static TreeMap<String, AbstractBlam> blams;
public synchronized static Map<String, AbstractBlam> getBlamMap() {
if (blams == null) {
blams = new TreeMap<String, AbstractBlam>();
ExtensionDefinedObjects<AbstractBlam> definedObjects =
new ExtensionDefinedObjects<AbstractBlam>("org.eclipse.osee.framework.ui.skynet.BlamOperation",
"Operation", "className");
for (AbstractBlam blam : definedObjects.getObjects()) {
blams.put(blam.getName(), blam);
}
}
return blams;
}
public static Collection<AbstractBlam> getBlamOperations() {
return getBlamMap().values();
}
private static void createCategories(String[] categoryElements, int index, XNavigateItem parentItem, Map<String, XNavigateItem> nameToParent) throws OseeCoreException {
String firstElement = categoryElements[index];
XNavigateItem thisCategoryItem = null;
for (XNavigateItem childItem : parentItem.getChildren()) {
if (childItem.getName().equals(firstElement)) {
thisCategoryItem = childItem;
break;
}
}
// Create new folder category
if (thisCategoryItem == null) {
// Add to parentItem
thisCategoryItem = new XNavigateItem(parentItem, firstElement, PluginUiImage.FOLDER);
String catName = "";
for (int x = 0; x <= index; x++) {
if (!catName.equals("")) {
catName += ".";
}
catName += categoryElements[x];
}
// Add to lookup map
nameToParent.put(catName, thisCategoryItem);
}
// Process children categories
if (categoryElements.length > index + 1) {
createCategories(categoryElements, index + 1, thisCategoryItem, nameToParent);
}
}
@Override
public void createCommonSection(List<XNavigateItem> items, List<String> excludeSectionIds) {
Map<String, XNavigateItem> nameToParent = new HashMap<String, XNavigateItem>();
XNavigateItem blamOperationItems = new XNavigateItem(null, "Blam Operations", FrameworkImage.BLAM);
for (AbstractBlam blamOperation : getBlamOperations()) {
// Create categories first (so can have them up top)
for (String category : blamOperation.getCategories()) {
try {
if (AccessControlManager.isOseeAdmin() || !category.contains("Admin") || category.contains("Admin") && AccessControlManager.isOseeAdmin()) {
createCategories(category.split("\\."), 0, blamOperationItems, nameToParent);
}
} catch (OseeCoreException ex) {
OseeLog.log(Activator.class, Level.SEVERE, ex);
}
}
}
// Add blams to categories
for (AbstractBlam blamOperation : BlamContributionManager.getBlamOperations()) {
// If categories not specified, add to top level
if (blamOperation.getCategories().isEmpty()) {
new XNavigateItemBlam(blamOperationItems, blamOperation);
}
for (String category : blamOperation.getCategories()) {
// Category will be null if admin category and not admin
if (nameToParent.get(category) != null) {
new XNavigateItemBlam(nameToParent.get(category), blamOperation);
}
}
}
items.add(blamOperationItems);
}
@Override
public String getSectionId() {
return "Blam";
}
}
|