blob: eaa40e72679026a96015ef658b24f4e11f6d98ce (
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
|
/*******************************************************************************
* Copyright (c) 2010 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.define.blam.operation;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osee.framework.core.data.BranchId;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.enums.CoreRelationTypes;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.importing.ReqNumbering;
import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction;
import org.eclipse.osee.framework.skynet.core.transaction.TransactionManager;
import org.eclipse.osee.framework.ui.skynet.blam.AbstractBlam;
import org.eclipse.osee.framework.ui.skynet.blam.VariableMap;
public class RequirementReorderOperation extends AbstractBlam {
private SkynetTransaction transaction;
@Override
public Collection<String> getCategories() {
return Arrays.asList("Define");
}
@Override
public void runOperation(VariableMap variableMap, IProgressMonitor monitor) throws Exception {
List<Artifact> artifacts = variableMap.getArtifacts("artifacts");
BranchId branch = artifacts.get(0).getBranch();
transaction = TransactionManager.createTransaction(branch, "Fix Requirement Ordering BLAM");
for (Artifact input : artifacts) {
reorderChildren(input);
}
transaction.execute();
}
public void reorderChildren(Artifact parent) throws OseeCoreException {
List<Artifact> oldChildren = parent.getChildren();
List<Artifact> children = parent.getChildren();
Collections.sort(children, new ParagraphComparator());
if (!oldChildren.equals(children)) {
parent.setRelationOrder(CoreRelationTypes.Default_Hierarchical__Child, children);
parent.persist(transaction);
}
for (Artifact child : children) {
reorderChildren(child);
}
}
private class ParagraphComparator implements Comparator<Artifact> {
@Override
public int compare(Artifact o1, Artifact o2) {
try {
ReqNumbering n1 = new ReqNumbering((String) o1.getSoleAttributeValue(CoreAttributeTypes.ParagraphNumber));
ReqNumbering n2 = new ReqNumbering((String) o2.getSoleAttributeValue(CoreAttributeTypes.ParagraphNumber));
return n1.compareTo(n2);
} catch (OseeCoreException e) {
return 0;
}
}
}
@Override
public String getXWidgetsXml() {
return "<xWidgets><XWidget xwidgetType=\"XListDropViewer\" displayName=\"artifacts\" /></xWidgets>";
}
@Override
public String getName() {
return "Fix Requirement Ordering";
}
}
|