blob: ee1caf305b607f0566dc68b49a8f4e9ebb2d1505 (
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
|
/*******************************************************************************
* 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.render.word.template;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.model.type.AttributeType;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.Collections;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.Attribute;
import org.eclipse.osee.framework.skynet.core.attribute.AttributeTypeManager;
import org.eclipse.osee.framework.ui.skynet.render.word.WordMLProducer;
/**
* @author Andrew M. Finkbeiner
*/
public final class BasicTemplateAttributeHandler implements ITemplateAttributeHandler {
private final Set<String> ignoreAttributeExtensions;
public BasicTemplateAttributeHandler() {
this.ignoreAttributeExtensions = new HashSet<>();
}
@Override
public void process(WordMLProducer wordMl, Artifact artifact, TemplateAttribute templateAttribute) throws OseeCoreException {
AttributeType attributeType = AttributeTypeManager.getType(templateAttribute.getName());
Collection<Attribute<Object>> attributes = artifact.getAttributes(attributeType);
if (!attributes.isEmpty()) {
Attribute<Object> attribute = attributes.iterator().next();
attributeType = attribute.getAttributeType();
// check if the attribute descriptor name is in the ignore list.
if (ignoreAttributeExtensions.contains(attributeType.getName())) {
return;
}
if (templateAttribute.isParagrapthWrap()) {
wordMl.startParagraph();
}
// assumption: the label is of the form <w:r><w:t> text </w:t></w:r>
// if (allAttrs) {
if (templateAttribute.hasLabel()) {
wordMl.addWordMl("<w:r><w:t> " + templateAttribute.getName() + ": </w:t></w:r>");
}
// } else {
// if (templateAttribute.hasLabel()) {
// wordMl.addParagraph(templateAttribute.getLabel());
// }
//
String valueList;
if (attributeType.equals(CoreAttributeTypes.WordTemplateContent)) {
wordMl.addWordMl((String) attribute.getValue());
} else {
valueList = Collections.toString(", ", artifact.getAttributes(attributeType));
if (templateAttribute.hasFormatting()) {
if (templateAttribute.getFormat().contains(">x<")) {
wordMl.addWordMl(templateAttribute.getFormat().replace(">x<", ">" + valueList + "<"));
}
} else {
wordMl.addTextInsideParagraph(valueList);
}
}
if (templateAttribute.isParagrapthWrap()) {
wordMl.endParagraph();
}
}
}
@Override
public boolean canHandle(Artifact artifact, TemplateAttribute attribute) {
return true;
}
}
|