Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2015-05-25 20:25:00 +0000
committerChristian W. Damus2015-05-25 20:25:00 +0000
commit3f9191df4607715c8552fffdd54ece295fc10a39 (patch)
tree22f434038e390ba61f0f24c9c38d3c03932ba484 /plugins/developer
parent2db995bf738548d0f16678ef87eecc03890642be (diff)
downloadorg.eclipse.papyrus-3f9191df4607715c8552fffdd54ece295fc10a39.tar.gz
org.eclipse.papyrus-3f9191df4607715c8552fffdd54ece295fc10a39.tar.xz
org.eclipse.papyrus-3f9191df4607715c8552fffdd54ece295fc10a39.zip
Bug 468079: [Developer] Design documentation generator limitations
https://bugs.eclipse.org/bugs/show_bug.cgi?id=468079 Include collaborations in the design model, to generate their behaviour diagrams and traceability information. Add traceability cross-references to classifiers in the use case and design models. Generate references in taxonomy and traceability cross-references as hyperlinks. This involves a new LinkUtil API for encoding links in the comment text with corresponding new API in the ITranscription back-end to support transcoding the links to the output format required by the generated document.
Diffstat (limited to 'plugins/developer')
-rw-r--r--plugins/developer/org.eclipse.papyrus.uml.developer.mde/META-INF/MANIFEST.MF3
-rw-r--r--plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/LinkUtil.java162
-rw-r--r--plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/command/CreateDocumentModelCommand.java174
-rw-r--r--plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/handler/GetHTMLTextHandler.java12
-rw-r--r--plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/handler/GetWikiTextHandler.java6
-rw-r--r--plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/handler/IDMAbstractHandler.java38
-rw-r--r--plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/transcription/HTMLTranscription.java83
-rw-r--r--plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/transcription/ITranscription.java79
-rw-r--r--plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/transcription/TranscriptionEngine.java71
-rw-r--r--plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/transcription/WikiTranscription.java68
10 files changed, 542 insertions, 154 deletions
diff --git a/plugins/developer/org.eclipse.papyrus.uml.developer.mde/META-INF/MANIFEST.MF b/plugins/developer/org.eclipse.papyrus.uml.developer.mde/META-INF/MANIFEST.MF
index 3281630ad70..cac56edaa66 100644
--- a/plugins/developer/org.eclipse.papyrus.uml.developer.mde/META-INF/MANIFEST.MF
+++ b/plugins/developer/org.eclipse.papyrus.uml.developer.mde/META-INF/MANIFEST.MF
@@ -18,7 +18,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.papyrus.infra.core.log;bundle-version="1.1.0",
org.eclipse.emf.ecore.edit;bundle-version="2.9.0",
org.eclipse.papyrus.infra.tools;bundle-version="1.1.0",
- com.google.guava;bundle-version="11.0.0"
+ com.google.guava;bundle-version="11.0.0",
+ org.eclipse.uml2.uml.profile.standard;bundle-version="1.0.100"
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
Bundle-Version: 1.1.0.qualifier
diff --git a/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/LinkUtil.java b/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/LinkUtil.java
new file mode 100644
index 00000000000..2508f75063a
--- /dev/null
+++ b/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/LinkUtil.java
@@ -0,0 +1,162 @@
+/*****************************************************************************
+ * Copyright (c) 2015 Christian W. Damus and others.
+ *
+ * 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:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.developper.mde;
+
+import java.util.List;
+import java.util.regex.MatchResult;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.papyrus.infra.emf.utils.EMFFunctions;
+import org.eclipse.papyrus.uml.developper.mde.handler.IDMAbstractHandler;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.UMLPackage;
+
+import com.google.common.base.Function;
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableList;
+
+/**
+ * An utility for generating and parsing simple textual hyperlinks.
+ */
+public class LinkUtil {
+ private static final Pattern HYPERLINK_PATTERN = Pattern.compile("\\$\\{link:([^\\|]+)\\|([^\\|]*)\\|([^\\}]*)\\}");
+
+ private final Function<? super NamedElement, String> titleFunction;
+ private final Function<? super NamedElement, String> nameFunction = EMFFunctions.getFeature(UMLPackage.Literals.NAMED_ELEMENT__NAME, String.class);
+ private final Function<NamedElement, String> hyperlinkFunction = new Function<NamedElement, String>() {
+
+ @Override
+ public String apply(NamedElement input) {
+ return createHyperlink(input, titleFunction.apply(input), nameFunction.apply(input));
+ }
+ };
+
+ /**
+ * Initializes me with the function that I use to obtain titles for links to model elements.
+ *
+ * @param titleFunction
+ * my element title function
+ */
+ public LinkUtil(Function<? super NamedElement, String> titleFunction) {
+ super();
+
+ this.titleFunction = titleFunction;
+ }
+
+ public static String createHyperlink(NamedElement element, String title, String name) {
+ return String.format("${link:%s|%s|%s}", element.eResource().getURIFragment(element), title, name);
+ }
+
+ public Function<? super NamedElement, String> getHyperlinkFunction() {
+ return hyperlinkFunction;
+ }
+
+ public static List<Hyperlink> parseHyperlinks(CharSequence text, int start, int end) {
+ ImmutableList.Builder<Hyperlink> result = ImmutableList.builder();
+
+ for (Matcher m = HYPERLINK_PATTERN.matcher(text.subSequence(start, end)); m.find();) {
+ result.add(new Hyperlink(m, start));
+ }
+
+ return result.build();
+ }
+
+ /**
+ * Transcodes a length of {@code text} with any potential encoded hyperlinks into a format suitable for the
+ * output of the generation pipeline.
+ *
+ * @param text
+ * a string of (comment) text from the documentation model
+ * @param start
+ * the starting offset (inclusive) in the {@code text} to process
+ * @param end
+ * the ending offset (exclusive) in the {@code text} to process
+ * @param transcoder
+ * a function that generates the textual representation of an hyperlink in the output format
+ *
+ * @return the transcoded text, or {@code null} if it had no embedded hyperlinks
+ */
+ public static String transcodeHyperlinks(CharSequence text, int start, int end, Function<? super Hyperlink, String> transcoder) {
+ String result = null;
+
+ List<Hyperlink> hyperlinks = parseHyperlinks(text, start, end);
+ if (!hyperlinks.isEmpty()) {
+ StringBuilder buf = new StringBuilder(3 * text.length() / 2);
+ int offset = start;
+
+ for (Hyperlink next : hyperlinks) {
+ // Up to the start of the hyperlink
+ buf.append(text, offset, next.offset());
+
+ // Output representation of the hyperlink
+ buf.append(transcoder.apply(next));
+
+ // Prepare for next
+ offset = next.offset() + next.length();
+ }
+
+ // Remainder of the string
+ buf.append(text, offset, end);
+
+ result = buf.toString();
+ }
+
+ return result;
+ }
+
+ //
+ // Nested types
+ //
+
+ public static final class Hyperlink {
+ private final int offset;
+ private final int length;
+ private final String href;
+ private final String title;
+ private final String text;
+
+ Hyperlink(MatchResult match, int offset) {
+ super();
+
+ this.offset = offset + match.start();
+ this.length = match.end() - match.start();
+
+ this.href = match.group(1);
+ this.title = match.group(2);
+ this.text = match.group(3);
+ }
+
+ public int offset() {
+ return offset;
+ }
+
+ public int length() {
+ return length;
+ }
+
+ public String href() {
+ String result = IDMAbstractHandler.getDocHREF(href);
+ return (result == null) ? href : result;
+ }
+
+ public String title() {
+ return Strings.isNullOrEmpty(title) ? text : title;
+ }
+
+ public String text() {
+ return text;
+ }
+ }
+}
diff --git a/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/command/CreateDocumentModelCommand.java b/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/command/CreateDocumentModelCommand.java
index d495076033d..c67b59595dd 100644
--- a/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/command/CreateDocumentModelCommand.java
+++ b/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/command/CreateDocumentModelCommand.java
@@ -35,7 +35,6 @@ import org.eclipse.gmf.runtime.diagram.ui.image.ImageFileFormat;
import org.eclipse.gmf.runtime.diagram.ui.render.util.CopyToImageUtil;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.emf.utils.EMFFunctions;
import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
import org.eclipse.papyrus.infra.hyperlink.helper.AbstractHyperLinkHelper;
import org.eclipse.papyrus.infra.hyperlink.helper.HyperLinkHelperFactory;
@@ -46,6 +45,7 @@ import org.eclipse.papyrus.infra.hyperlink.util.HyperLinkHelpersRegistrationUtil
import org.eclipse.papyrus.infra.tools.util.TypeUtils;
import org.eclipse.papyrus.uml.developper.mde.I_DeveloperIDMStereotype;
import org.eclipse.papyrus.uml.developper.mde.I_DocumentStereotype;
+import org.eclipse.papyrus.uml.developper.mde.LinkUtil;
import org.eclipse.papyrus.uml.developper.mde.handler.IDMAbstractHandler;
import org.eclipse.papyrus.views.modelexplorer.NavigatorUtils;
import org.eclipse.uml2.uml.Actor;
@@ -54,9 +54,11 @@ import org.eclipse.uml2.uml.Behavior;
import org.eclipse.uml2.uml.BehavioredClassifier;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Collaboration;
import org.eclipse.uml2.uml.Comment;
import org.eclipse.uml2.uml.DataType;
import org.eclipse.uml2.uml.Dependency;
+import org.eclipse.uml2.uml.DirectedRelationship;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Interface;
import org.eclipse.uml2.uml.Model;
@@ -66,10 +68,13 @@ import org.eclipse.uml2.uml.PackageImport;
import org.eclipse.uml2.uml.PackageableElement;
import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.uml2.uml.UMLFactory;
-import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.UseCase;
+import org.eclipse.uml2.uml.profile.standard.Trace;
+import org.eclipse.uml2.uml.util.UMLUtil;
+import com.google.common.base.Function;
import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
/**
@@ -94,6 +99,8 @@ public class CreateDocumentModelCommand extends RecordingCommand {
private AdapterFactory adapterFactory;
+ private LinkUtil linkUtil;
+
/**
*
* Constructor to transform model into document model
@@ -114,6 +121,12 @@ public class CreateDocumentModelCommand extends RecordingCommand {
hyperlinkHelperFactory = new HyperLinkHelperFactory(hyperLinkHelpers);
adapterFactory = ((AdapterFactoryEditingDomain) domain).getAdapterFactory();
+ linkUtil = new LinkUtil(new Function<NamedElement, String>() {
+ @Override
+ public String apply(NamedElement input) {
+ return title(input);
+ }
+ });
}
@Override
@@ -195,7 +208,7 @@ public class CreateDocumentModelCommand extends RecordingCommand {
Stereotype tableOfContentStereotype = toc.getAppliedStereotype(I_DocumentStereotype.TABLEOFCONTENT_STEREOTYPE);
if (!(section.isStereotypeApplied(tableOfContentStereotype))) {
Package chapter = createSection(toc, ((Package) section).getName());
- IDMAbstractHandler.Toc2DocElt.put(chapter, (Package) section);
+ IDMAbstractHandler.putTOCPackage(chapter, (Package) section);
setTableOfContents(section, chapter);
}
}
@@ -218,7 +231,7 @@ public class CreateDocumentModelCommand extends RecordingCommand {
Stereotype sectionStereotype = cddElement.getAppliedStereotype(I_DocumentStereotype.SECTION_STEREOTYPE);
if (sectionStereotype != null) {
Package chapter = createSection(chapterPackage, ((Package) cddElement).getName());
- IDMAbstractHandler.Toc2DocElt.put(chapter, (Package) cddElement);
+ IDMAbstractHandler.putTOCPackage(chapter, (Package) cddElement);
setTableOfContents(cddElement, chapter);
}
}
@@ -246,7 +259,7 @@ public class CreateDocumentModelCommand extends RecordingCommand {
Stereotype contentStereotype = comment.getApplicableStereotype(I_DocumentStereotype.CONTENT_STEREOTYPE);
comment.applyStereotype(contentStereotype);
comment.setBody(out);
- IDMAbstractHandler.elt2DocElt.put(currentReq, comment);
+ IDMAbstractHandler.putDocElement(currentReq, comment);
}
}
}
@@ -271,8 +284,6 @@ public class CreateDocumentModelCommand extends RecordingCommand {
generateUseCaseFromSubject(copyImageUtil, subjectIn, subSectionOUT);
}
}
-
-
}
protected void generateUseCaseFromSubject(CopyToImageUtil copyImageUtil, Classifier subjectIN, Package useCaseModelOUT) {
@@ -290,9 +301,11 @@ public class CreateDocumentModelCommand extends RecordingCommand {
for (Iterator<EObject> iterator = subjectIN.eAllContents(); iterator.hasNext();) {
EObject packageableElement = iterator.next();
if (packageableElement instanceof UseCase) {
- Package useCaseSectionOUT = createSection(useCaseModelOUT, ((UseCase) packageableElement).getName());
+ UseCase useCase = (UseCase) packageableElement;
+ Package useCaseSectionOUT = createSection(useCaseModelOUT, useCase.getName());
+ generateTraceability(useCaseSectionOUT, useCase);
- for (Iterator<Comment> iteComment = ((UseCase) packageableElement).getOwnedComments().iterator(); iteComment.hasNext();) {
+ for (Iterator<Comment> iteComment = useCase.getOwnedComments().iterator(); iteComment.hasNext();) {
Comment currentComment = iteComment.next();
transformToContentWithUser(copyImageUtil, useCaseSectionOUT, currentComment);
}
@@ -329,7 +342,7 @@ public class CreateDocumentModelCommand extends RecordingCommand {
if (packageImport.getAppliedStereotype(I_DeveloperIDMStereotype.DESIGN_STEREOTYPE) != null) {
Package importedDesignPackageIn = packageImport.getImportedPackage();
Package subSectionOUT = createSection(designPackageOUT, importedDesignPackageIn.getName());
- IDMAbstractHandler.elt2DocElt.put(importedDesignPackageIn, subSectionOUT);
+ IDMAbstractHandler.putDocElement(importedDesignPackageIn, subSectionOUT);
generateDesign(copyImageUtil, importedDesignPackageIn, subSectionOUT);
}
}
@@ -349,24 +362,62 @@ public class CreateDocumentModelCommand extends RecordingCommand {
for (Iterator<PackageableElement> iterator = designPackageIn.getPackagedElements().iterator(); iterator.hasNext();) {
EObject packageableElement = iterator.next();
if ((packageableElement instanceof Class) || (packageableElement instanceof Interface) || (packageableElement instanceof DataType)) {
- Package designSectionOUT = createSection(designPackageOUT, title((Classifier) packageableElement));
- IDMAbstractHandler.elt2DocElt.put((Element) packageableElement, designSectionOUT);
- generateTaxonomy(designSectionOUT, (Classifier) packageableElement);
- for (Iterator<Comment> iteComment = ((Classifier) packageableElement).getOwnedComments().iterator(); iteComment.hasNext();) {
+ final Classifier classifier = (Classifier) packageableElement;
+ Package designSectionOUT = createSection(designPackageOUT, title(classifier));
+ IDMAbstractHandler.putDocElement(classifier, designSectionOUT);
+ generateTaxonomy(designSectionOUT, classifier);
+ generateTraceability(designSectionOUT, classifier);
+ for (Iterator<Comment> iteComment = classifier.getOwnedComments().iterator(); iteComment.hasNext();) {
Comment currentComment = iteComment.next();
transformToContentWithUser(copyImageUtil, designSectionOUT, currentComment);
}
}
+
+ if (packageableElement instanceof Collaboration) {
+ generateDesignCollaboration(copyImageUtil, designPackageOUT, (Collaboration) packageableElement);
+ }
+
if (packageableElement instanceof Package) {
- Package designSectionOUT = createSection(designPackageOUT, title((Package) packageableElement));
- IDMAbstractHandler.elt2DocElt.put((Element) packageableElement, designSectionOUT);
- generateDesign(copyImageUtil, (Package) packageableElement, designSectionOUT);
+ Package package_ = (Package) packageableElement;
+ Package designSectionOUT = createSection(designPackageOUT, title(package_));
+ generateTraceability(designSectionOUT, package_);
+ IDMAbstractHandler.putDocElement(package_, designSectionOUT);
+ generateDesign(copyImageUtil, package_, designSectionOUT);
}
}
}
+ protected void generateDesignCollaboration(CopyToImageUtil copyImageUtil, Package designPackage, Collaboration collaboration) {
+ Package designSectionOUT = createSection(designPackage, title(collaboration));
+ IDMAbstractHandler.putDocElement(collaboration, designSectionOUT);
+
+ generateTraceability(designSectionOUT, collaboration);
+
+ for (Diagram diagram : containedDiagrams(collaboration)) {
+ generateImg(copyImageUtil, designSectionOUT, diagram);
+ }
+
+ for (Comment comment : collaboration.getOwnedComments()) {
+ transformToContentWithUser(copyImageUtil, designSectionOUT, comment);
+ }
+
+ // Look for interaction diagrams
+
+ for (Behavior behavior : collaboration.getOwnedBehaviors()) {
+ Package behaviorSection = createSection(designSectionOUT, title(behavior));
+ IDMAbstractHandler.putDocElement(behavior, behaviorSection);
+
+ for (Comment comment : behavior.getOwnedComments()) {
+ transformToContentWithUser(copyImageUtil, behaviorSection, comment);
+ }
+ for (Diagram diagram : containedDiagrams(behavior)) {
+ generateImg(copyImageUtil, behaviorSection, diagram);
+ }
+ }
+ }
+
protected String title(NamedElement element) {
return String.format("%s %s", getMetaclassLabel(element), element.getLabel());
}
@@ -374,11 +425,17 @@ public class CreateDocumentModelCommand extends RecordingCommand {
protected String getMetaclassLabel(Element element) {
String result;
- EModelElementItemProvider itemProvider = TypeUtils.as(adapterFactory.adapt(element, IItemLabelProvider.class), EModelElementItemProvider.class);
- if (itemProvider == null) {
- result = element.eClass().getName();
+ // If the element has a stereotype, prefer that
+ Stereotype stereotype = Iterables.getFirst(element.getAppliedStereotypes(), null);
+ if (stereotype != null) {
+ result = stereotype.getLabel();
} else {
- result = itemProvider.getResourceLocator().getString(String.format("_UI_%s_type", element.eClass().getName())); //$NON-NLS-1$
+ EModelElementItemProvider itemProvider = TypeUtils.as(adapterFactory.adapt(element, IItemLabelProvider.class), EModelElementItemProvider.class);
+ if (itemProvider == null) {
+ result = element.eClass().getName();
+ } else {
+ result = itemProvider.getResourceLocator().getString(String.format("_UI_%s_type", element.eClass().getName())); //$NON-NLS-1$
+ }
}
return result;
@@ -389,7 +446,7 @@ public class CreateDocumentModelCommand extends RecordingCommand {
if (!classifier.getGenerals().isEmpty()) {
taxonomy = taxonomy + " - specializes " + Joiner.on(", ").join(
- Iterables.transform(classifier.getGenerals(), EMFFunctions.getFeature(UMLPackage.Literals.NAMED_ELEMENT__NAME, String.class)));
+ Iterables.transform(classifier.getGenerals(), linkUtil.getHyperlinkFunction()));
}
if (classifier instanceof BehavioredClassifier) {
@@ -400,7 +457,7 @@ public class CreateDocumentModelCommand extends RecordingCommand {
}
taxonomy = taxonomy + " - realizes " + Joiner.on(", ").join(
- Iterables.transform(behaviored.getImplementedInterfaces(), EMFFunctions.getFeature(UMLPackage.Literals.NAMED_ELEMENT__NAME, String.class)));
+ Iterables.transform(behaviored.getImplementedInterfaces(), linkUtil.getHyperlinkFunction()));
}
}
@@ -412,6 +469,73 @@ public class CreateDocumentModelCommand extends RecordingCommand {
}
}
+ protected void generateTraceability(Package sectionPackage, NamedElement concept) {
+ String traceability = ""; //$NON-NLS-1$
+
+ List<NamedElement> traceTo = getTracesTo(concept);
+ if (!traceTo.isEmpty()) {
+ traceability = traceability + " - traces to " + Joiner.on(", ").join(
+ Iterables.transform(traceTo, linkUtil.getHyperlinkFunction()));
+ }
+
+ List<NamedElement> traceFrom = getTracesFrom(concept);
+ if (!traceFrom.isEmpty()) {
+ if (!traceability.isEmpty()) {
+ traceability = traceability + "\n\n"; //$NON-NLS-1$
+ }
+
+ traceability = traceability + " - traces from " + Joiner.on(", ").join(
+ Iterables.transform(traceFrom, linkUtil.getHyperlinkFunction()));
+ }
+
+ if (!traceability.isEmpty()) {
+ Comment comment = sectionPackage.createOwnedComment();
+ Stereotype contentStereotype = comment.getApplicableStereotype(I_DocumentStereotype.CONTENT_STEREOTYPE);
+ comment.applyStereotype(contentStereotype);
+ comment.setBody(traceability);
+ }
+ }
+
+ /**
+ * Gets the elements that a {@code concept} traces to via {@literal «trace» Abstractions}.
+ *
+ * @param concept
+ * a concept in the model
+ * @return its trace-to elements
+ */
+ protected List<NamedElement> getTracesTo(NamedElement concept) {
+ ImmutableList.Builder<NamedElement> result = ImmutableList.builder();
+
+ for (DirectedRelationship next : concept.getSourceDirectedRelationships()) {
+ Trace trace = UMLUtil.getStereotypeApplication(next, Trace.class);
+ if (trace != null) {
+ result.addAll(trace.getBase_Abstraction().getSuppliers());
+ }
+ }
+
+ return result.build();
+ }
+
+ /**
+ * Gets the elements that a {@code concept} traces from via {@literal «trace» Abstractions}.
+ *
+ * @param concept
+ * a concept in the model
+ * @return its trace-from elements
+ */
+ protected List<NamedElement> getTracesFrom(NamedElement concept) {
+ ImmutableList.Builder<NamedElement> result = ImmutableList.builder();
+
+ for (DirectedRelationship next : concept.getTargetDirectedRelationships()) {
+ Trace trace = UMLUtil.getStereotypeApplication(next, Trace.class);
+ if (trace != null) {
+ result.addAll(trace.getBase_Abstraction().getClients());
+ }
+ }
+
+ return result.build();
+ }
+
protected void generateTests(CopyToImageUtil copyImageUtil, Package testIN, Package testModelOUT) {
if (testIN.getPackageImports().size() > 0) {
for (PackageImport packageImport : testIN.getPackageImports()) {
@@ -440,7 +564,7 @@ public class CreateDocumentModelCommand extends RecordingCommand {
if (packageableElement instanceof Package) {
Package testCaseSectionOUT = createSection(testModelOUT, ((Package) packageableElement).getName());
- IDMAbstractHandler.elt2DocElt.put((Element) packageableElement, testCaseSectionOUT);
+ IDMAbstractHandler.putDocElement((Element) packageableElement, testCaseSectionOUT);
generateTests(copyImageUtil, (Package) packageableElement, testCaseSectionOUT);
for (Iterator<Comment> iteComment = ((Package) packageableElement).getOwnedComments().iterator(); iteComment.hasNext();) {
Comment currentComment = iteComment.next();
@@ -450,7 +574,7 @@ public class CreateDocumentModelCommand extends RecordingCommand {
} else if (packageableElement instanceof Behavior || packageableElement instanceof Classifier) {
Package testCaseSectionOUT = createSection(testModelOUT, ((NamedElement) packageableElement).getName());
- IDMAbstractHandler.elt2DocElt.put((Element) packageableElement, testCaseSectionOUT);
+ IDMAbstractHandler.putDocElement((Element) packageableElement, testCaseSectionOUT);
for (Iterator<Comment> iteComment = ((NamedElement) packageableElement).getOwnedComments().iterator(); iteComment.hasNext();) {
Comment currentComment = iteComment.next();
createImageFromHyperLink(copyImageUtil, testCaseSectionOUT, currentComment);
diff --git a/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/handler/GetHTMLTextHandler.java b/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/handler/GetHTMLTextHandler.java
index 80c38de6714..3280610d653 100644
--- a/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/handler/GetHTMLTextHandler.java
+++ b/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/handler/GetHTMLTextHandler.java
@@ -14,8 +14,6 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.developper.mde.handler;
-import java.util.List;
-
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
@@ -27,7 +25,6 @@ import org.eclipse.papyrus.uml.developper.mde.command.CreateDocumentModelCommand
import org.eclipse.papyrus.uml.developper.mde.transcription.HTMLTranscription;
import org.eclipse.papyrus.uml.developper.mde.transcription.TranscriptionEngine;
import org.eclipse.uml2.uml.Model;
-import org.eclipse.uml2.uml.Stereotype;
/**
* This class is used to create and html developper doc file.
@@ -44,8 +41,7 @@ public class GetHTMLTextHandler extends IDMAbstractHandler {
public Object execute(ExecutionEvent event) throws ExecutionException {
super.execute(event);
System.err.println(getCurrentProject().getLocationURI().getPath());
- IDMAbstractHandler.elt2DocElt.clear();
- IDMAbstractHandler.Toc2DocElt.clear();
+ IDMAbstractHandler.clear();
try {
CreateDocumentModelCommand createDocumentModelCommand = new CreateDocumentModelCommand(transactionalEditingDomain, (Model) getSelection(), getCurrentProject().getLocationURI().getPath() + INTERNAL_DIRECTORY_NAME);
@@ -54,8 +50,7 @@ public class GetHTMLTextHandler extends IDMAbstractHandler {
TranscriptionEngine engine = new TranscriptionEngine((Model) getSelection(), project, new HTMLTranscription());
engine.traduce();
} finally {
- IDMAbstractHandler.elt2DocElt.clear();
- IDMAbstractHandler.Toc2DocElt.clear();
+ IDMAbstractHandler.clear();
}
return null;
@@ -80,8 +75,7 @@ public class GetHTMLTextHandler extends IDMAbstractHandler {
public boolean isEnabled() {
if (getSelection() instanceof Model) {
Model model = (Model) getSelection();
- List<Stereotype> stereotypes = model.getAppliedStereotypes();
- if (((Model) getSelection()).getAppliedStereotype(I_DeveloperIDMStereotype.PROJECT_STEREOTYPE) != null) {
+ if (model.getAppliedStereotype(I_DeveloperIDMStereotype.PROJECT_STEREOTYPE) != null) {
return true;
}
diff --git a/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/handler/GetWikiTextHandler.java b/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/handler/GetWikiTextHandler.java
index 1f8bd1ae1e5..fac26701a59 100644
--- a/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/handler/GetWikiTextHandler.java
+++ b/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/handler/GetWikiTextHandler.java
@@ -38,8 +38,7 @@ public class GetWikiTextHandler extends IDMAbstractHandler {
public Object execute(ExecutionEvent event) throws ExecutionException {
super.execute(event);
System.err.println(getCurrentProject().getLocationURI().getPath());
- IDMAbstractHandler.elt2DocElt.clear();
- IDMAbstractHandler.Toc2DocElt.clear();
+ IDMAbstractHandler.clear();
try {
CreateDocumentModelCommand createDocumentModelCommand = new CreateDocumentModelCommand(transactionalEditingDomain, (Model) getSelection(), getCurrentProject().getLocationURI().getPath() + INTERNAL_DIRECTORY_NAME);
@@ -48,8 +47,7 @@ public class GetWikiTextHandler extends IDMAbstractHandler {
TranscriptionEngine engine = new TranscriptionEngine((Model) getSelection(), project, new WikiTranscription());
engine.traduce();
} finally {
- IDMAbstractHandler.elt2DocElt.clear();
- IDMAbstractHandler.Toc2DocElt.clear();
+ IDMAbstractHandler.clear();
}
return null;
diff --git a/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/handler/IDMAbstractHandler.java b/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/handler/IDMAbstractHandler.java
index ce7ccf779a8..9d5ac7d9b6d 100644
--- a/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/handler/IDMAbstractHandler.java
+++ b/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/handler/IDMAbstractHandler.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
+ * Copyright (c) 2014, 2015 CEA LIST, Christian W. Damus, and others.
*
*
* All rights reserved. This program and the accompanying materials
@@ -9,6 +9,7 @@
*
* Contributors:
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 468079
*
*****************************************************************************/
package org.eclipse.papyrus.uml.developper.mde.handler;
@@ -16,6 +17,7 @@ package org.eclipse.papyrus.uml.developper.mde.handler;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
@@ -41,9 +43,10 @@ public abstract class IDMAbstractHandler extends AbstractHandler {
protected TransactionalEditingDomain transactionalEditingDomain = null;
protected PapyrusMultiDiagramEditor papyrusEditor;
- public static HashMap<Element, Element> elt2DocElt = new HashMap<Element, Element>();
- public static HashMap<Package, Package> Toc2DocElt = new HashMap<Package, Package>();
-
+ private static Map<Element, Element> elt2DocElt = new HashMap<Element, Element>();
+ private static Map<String, String> href2DocHREF = new HashMap<String, String>();
+ private static Map<Package, Package> Toc2DocElt = new HashMap<Package, Package>();
+
/**
* get the root package
*
@@ -117,4 +120,31 @@ public abstract class IDMAbstractHandler extends AbstractHandler {
}
return selectedSet;
}
+
+ public static void clear() {
+ elt2DocElt.clear();
+ href2DocHREF.clear();
+ Toc2DocElt.clear();
+ }
+
+ public static Element getDocElement(Element modelElement) {
+ return elt2DocElt.get(modelElement);
+ }
+
+ public static String getDocHREF(String href) {
+ return href2DocHREF.get(href);
+ }
+
+ public static void putDocElement(Element modelElement, Element docElement) {
+ elt2DocElt.put(modelElement, docElement);
+ href2DocHREF.put(modelElement.eResource().getURIFragment(modelElement), docElement.eResource().getURIFragment(docElement));
+ }
+
+ public static Package getDocPackageForTOC(Package tocPackage) {
+ return Toc2DocElt.get(tocPackage);
+ }
+
+ public static void putTOCPackage(Package tocPackage, Package docPackage) {
+ Toc2DocElt.put(tocPackage, docPackage);
+ }
}
diff --git a/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/transcription/HTMLTranscription.java b/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/transcription/HTMLTranscription.java
index b7f2ceaca53..56e397e3d9f 100644
--- a/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/transcription/HTMLTranscription.java
+++ b/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/transcription/HTMLTranscription.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
+ * Copyright (c) 2014, 2015 CEA LIST, Christian W. Damus, and others.
*
*
* All rights reserved. This program and the accompanying materials
@@ -9,18 +9,23 @@
*
* Contributors:
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 468079
*
*****************************************************************************/
package org.eclipse.papyrus.uml.developper.mde.transcription;
import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eclipse.papyrus.uml.developper.mde.I_DocumentStereotype;
+import org.eclipse.papyrus.uml.developper.mde.LinkUtil;
+import org.eclipse.papyrus.uml.developper.mde.LinkUtil.Hyperlink;
import org.eclipse.uml2.uml.Comment;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.Stereotype;
+import com.google.common.base.Function;
+
/**
* this class is a specialization to generate html files.
*
@@ -29,6 +34,18 @@ import org.eclipse.uml2.uml.Stereotype;
*/
public class HTMLTranscription implements ITranscription {
+ private final Function<LinkUtil.Hyperlink, String> hyperlinkFunction = new Function<LinkUtil.Hyperlink, String>() {
+ @Override
+ public String apply(Hyperlink input) {
+ return String.format("<a href=\"#%s\" title=\"%s\">%s</a>", input.href(), input.title(), input.text());
+ }
+ };
+
+ @Override
+ public Function<? super Hyperlink, String> getHyperlinkTranscoder() {
+ return hyperlinkFunction;
+ }
+
/**
* @see org.eclipse.papyrus.uml.developper.mde.transcription.ITranscription#writeEndingDocument(java.lang.StringBuffer)
*
@@ -38,6 +55,7 @@ public class HTMLTranscription implements ITranscription {
@Override
public void writeEndingDocument(StringBuffer out) {
out.append("</html>"); //$NON-NLS-1$
+ out.append(System.lineSeparator());
}
@@ -51,7 +69,9 @@ public class HTMLTranscription implements ITranscription {
@Override
public StringBuffer writeBeginningDocument(StringBuffer out) {
out.append("<html>"); //$NON-NLS-1$
+ out.append(System.lineSeparator());
out.append("<link rel=\"stylesheet\" href=\"default.css\" type=\"text/css\">"); //$NON-NLS-1$
+ out.append(System.lineSeparator());
return out;
}
@@ -64,6 +84,7 @@ public class HTMLTranscription implements ITranscription {
@Override
public void writeDocumentTitle(StringBuffer out, Model documentModel) {
out.append("<H1>" + documentModel.getName() + "</H1>"); //$NON-NLS-1$ //$NON-NLS-2$
+ out.append(System.lineSeparator());
}
/**
@@ -74,8 +95,9 @@ public class HTMLTranscription implements ITranscription {
* @param packageableElement
*/
@Override
- public void writesectionTitle(StringBuffer out, int level, Element packageableElement) {
- out.append("<H" + level + getId(packageableElement) + ">" + ((Package) packageableElement).getName() + "</H" + level + ">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ public void writeSectionTitle(StringBuffer out, int level, Element packageableElement) {
+ out.append("<H" + level + getId(packageableElement) + ">" + ((Package) packageableElement).getName() + "</H" + level + ">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ out.append(System.lineSeparator());
}
@@ -92,6 +114,7 @@ public class HTMLTranscription implements ITranscription {
out.append("<P align=\"middle\"><img src=" + packageableElement.getValue(imgRefStereotype, I_DocumentStereotype.IMAGEREF_REF_ATT) + " alt=" + ((Comment) packageableElement).getBody() + " ></P>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
out.append("<P align=\"middle\">" + ((Comment) packageableElement).getBody() + "</P>"); //$NON-NLS-1$ //$NON-NLS-2$
out.append("</BR>"); //$NON-NLS-1$
+ out.append(System.lineSeparator());
}
@@ -104,14 +127,15 @@ public class HTMLTranscription implements ITranscription {
@Override
public void writeParagraph(StringBuffer out, Element packageableElement) {
- out.append("<pre" + getId(packageableElement)+ ">" + ((Comment) packageableElement).getBody().replaceAll("\n", "<BR/>") + "</pre>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ out.append("<pre" + getId(packageableElement) + ">" + ((Comment) packageableElement).getBody().replaceAll("\n", "<BR/>") + "</pre>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ out.append(System.lineSeparator());
}
/**
* @return
*/
public String getId(Element packageableElement) {
- String packageableElementtFragment = ((XMIResource)packageableElement.eResource()).getID(packageableElement);
+ String packageableElementtFragment = ((XMIResource) packageableElement.eResource()).getID(packageableElement);
String id = " id =\"" + packageableElementtFragment + "\"";
return id;
}
@@ -139,7 +163,7 @@ public class HTMLTranscription implements ITranscription {
out.append("<th style=\"border: 1px solid black\">Verify by</th>");
writeEndTRTag(out);
}
-
+
/**
*
* @see org.eclipse.papyrus.uml.developper.mde.transcription.ITranscription#writeLine(java.lang.StringBuffer, java.lang.String, java.lang.String, java.lang.String)
@@ -149,14 +173,15 @@ public class HTMLTranscription implements ITranscription {
* @param referenceName
* @param text
*/
+ @Override
public void writeLine(StringBuffer out, String uri, String referenceName, String text) {
if (uri.equals("")) {
- out.append(text);
+ out.append(text);
} else {
- out.append("<a href=\"#" + uri + "\" title=\"" + referenceName + "\">" + text + "</a>");
- }
+ out.append("<a href=\"#" + uri + "\" title=\"" + referenceName + "\">" + text + "</a>");
+ }
}
-
+
/**
* @see org.eclipse.papyrus.uml.developper.mde.transcription.ITranscription#writeNewLine(java.lang.StringBuffer)
*
@@ -164,26 +189,28 @@ public class HTMLTranscription implements ITranscription {
*/
@Override
public void writeNewLine(StringBuffer out) {
- out.append("</BR>");
-
+ out.append("<BR/>");
+ out.append(System.lineSeparator());
}
-
+
/**
*
* @see org.eclipse.papyrus.uml.developper.mde.transcription.ITranscription#writeBeginTDTag(java.lang.StringBuffer)
*
* @param out
*/
+ @Override
public void writeBeginTDTag(StringBuffer out) {
out.append("<td style=\"border : 1px solid black\">");
}
-
+
/**
*
* @see org.eclipse.papyrus.uml.developper.mde.transcription.ITranscription#writeEndTDTag(java.lang.StringBuffer)
*
* @param out
*/
+ @Override
public void writeEndTDTag(StringBuffer out) {
out.append("</td>");
}
@@ -194,6 +221,7 @@ public class HTMLTranscription implements ITranscription {
*
* @param out
*/
+ @Override
public void writeBeginTRTag(StringBuffer out) {
out.append("<tr>");
}
@@ -204,8 +232,10 @@ public class HTMLTranscription implements ITranscription {
*
* @param out
*/
+ @Override
public void writeEndTRTag(StringBuffer out) {
out.append("</tr>");
+ out.append(System.lineSeparator());
}
@@ -217,29 +247,33 @@ public class HTMLTranscription implements ITranscription {
@Override
public void writeEndingTable(StringBuffer out) {
out.append("</table>");
+ out.append(System.lineSeparator());
}
-
+
/**
*
* @see org.eclipse.papyrus.uml.developper.mde.transcription.ITranscription#writeBeginParagraph(java.lang.StringBuffer)
*
* @param out
*/
+ @Override
public void writeBeginParagraph(StringBuffer out) {
out.append("<pre>");
}
-
+
/**
*
* @see org.eclipse.papyrus.uml.developper.mde.transcription.ITranscription#writeEndingParagraph(java.lang.StringBuffer)
*
* @param out
*/
+ @Override
public void writeEndingParagraph(StringBuffer out) {
out.append("</pre>");
+ out.append(System.lineSeparator());
}
-
-
+
+
/**
*
* @see org.eclipse.papyrus.uml.developper.mde.transcription.ITranscription#writeRefContent(java.lang.StringBuffer, java.lang.String, java.lang.String, java.lang.String)
@@ -249,12 +283,13 @@ public class HTMLTranscription implements ITranscription {
* @param requirementName
* @param reqID
*/
+ @Override
public void writeRefContent(StringBuffer out, String uri, String requirementName, String reqID) {
if (uri.equals("")) {
- out.append(reqID);
+ out.append(reqID);
} else {
- out.append("<a href=\"#" + uri + "\" title=\"" + requirementName + "\">" + reqID + "</a>");
- }
+ out.append("<a href=\"#" + uri + "\" title=\"" + requirementName + "\">" + reqID + "</a>");
+ }
}
@@ -268,7 +303,7 @@ public class HTMLTranscription implements ITranscription {
*/
@Override
public void writeTOCSection(StringBuffer out, String chapterName, String uri) {
- out.append("<a href=\"#" + uri + "\">" + chapterName + "</a>" );
+ out.append("<a href=\"#" + uri + "\">" + chapterName + "</a>");
}
@@ -283,7 +318,8 @@ public class HTMLTranscription implements ITranscription {
*/
@Override
public void writeTOCSubSection(StringBuffer out, String subSectionName, String uri) {
- out.append("<li><a href=\"#" + uri + "\"> " + subSectionName + "</a></li>");
+ out.append("<li><a href=\"#" + uri + "\"> " + subSectionName + "</a></li>");
+ out.append(System.lineSeparator());
}
@@ -306,6 +342,7 @@ public class HTMLTranscription implements ITranscription {
@Override
public void writeEndTOC(StringBuffer out) {
out.append("</ul>");
+ out.append(System.lineSeparator());
}
}
diff --git a/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/transcription/ITranscription.java b/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/transcription/ITranscription.java
index 5a377fd77db..1ed461f084f 100644
--- a/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/transcription/ITranscription.java
+++ b/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/transcription/ITranscription.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
+ * Copyright (c) 2014, 2015 CEA LIST, Christian W. Damus, and others.
*
*
* All rights reserved. This program and the accompanying materials
@@ -9,14 +9,18 @@
*
* Contributors:
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 468079
*
*****************************************************************************/
package org.eclipse.papyrus.uml.developper.mde.transcription;
+import org.eclipse.papyrus.uml.developper.mde.LinkUtil;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.Stereotype;
+import com.google.common.base.Function;
+
/**
* This class is used to generated very swiftly a document from the document model
@@ -25,6 +29,13 @@ import org.eclipse.uml2.uml.Stereotype;
public interface ITranscription {
/**
+ * Obtains a function that generates the output format of an element hyperlink.
+ *
+ * @return
+ */
+ public abstract Function<? super LinkUtil.Hyperlink, String> getHyperlinkTranscoder();
+
+ /**
* finalize the document
*
* @param out
@@ -57,7 +68,7 @@ public interface ITranscription {
* @param packageableElement
* the package
*/
- public abstract void writesectionTitle(StringBuffer out, int level, Element packageableElement);
+ public abstract void writeSectionTitle(StringBuffer out, int level, Element packageableElement);
/**
* write a image
@@ -85,8 +96,8 @@ public interface ITranscription {
* @return the name of the document to generate
*/
public abstract String getNameFile();
-
-
+
+
/**
* write the beginning of the table (header, style)
*
@@ -94,21 +105,21 @@ public interface ITranscription {
* @param tableCaption
*/
public abstract void writeTable(StringBuffer out, String tableCaption);
-
+
/**
* write line in the table
*
* @param out
- * @param uri
- * represents the uri of the referent element
+ * @param uri
+ * represents the uri of the referent element
* @param referenceName
- * name of the referent element
+ * name of the referent element
* @param text
- * represents content of the line
+ * represents content of the line
*/
public abstract void writeLine(StringBuffer out, String uri, String referenceName, String text);
-
-
+
+
/**
*
* write the beginning of a line
@@ -116,95 +127,95 @@ public interface ITranscription {
* @param out
*/
public abstract void writeBeginTRTag(StringBuffer out);
-
+
/**
* write the ending of a line
*
* @param out
*/
public abstract void writeEndTRTag(StringBuffer out);
-
+
/**
* finalize the table
*
* @param out
*/
public abstract void writeEndingTable(StringBuffer out);
-
+
/**
* write the beginning of a column
*
* @param out
*/
public abstract void writeBeginTDTag(StringBuffer out);
-
+
/**
* write the ending of a column
*
* @param out
*/
public abstract void writeEndTDTag(StringBuffer out);
-
+
public abstract void writeBeginTOC(StringBuffer out);
-
+
public abstract void writeEndTOC(StringBuffer out);
-
-
+
+
/**
* write the requirements which aren't covered
*
* @param out
* @param uri
- * represents the uri of the Requirements Doc Element
+ * represents the uri of the Requirements Doc Element
* @param requirementName
- * the requirement name
+ * the requirement name
* @param reqID
- * id of the requirement
+ * id of the requirement
*/
public abstract void writeRefContent(StringBuffer out, String uri, String requirementName, String reqID);
-
+
/**
* write beginning of a paragraph
*
* @param out
*/
public abstract void writeBeginParagraph(StringBuffer out);
-
+
/**
* write ending of a paragraph
*
* @param out
*/
public abstract void writeEndingParagraph(StringBuffer out);
-
+
/**
* write section in table of contents
*
* @param out
* @param chapterName
- * represents the name of the section
+ * represents the name of the section
* @param uri
- * represents the uri of the Section Doc Element
+ * represents the uri of the Section Doc Element
*/
-
+
public abstract void writeTOCSection(StringBuffer out, String chapterName, String uri);
-
+
/**
*
* @param out
* @param subSectionName
- * represents the name of the sub section
+ * represents the name of the sub section
* @param uri
- * represents the uri of the sub section doc element
+ * represents the uri of the sub section doc element
*/
public abstract void writeTOCSubSection(StringBuffer out, String subSectionName, String uri);
-
+
/**
*
* @param out
*/
public abstract void writeNewLine(StringBuffer out);
-
-
+
+
}
diff --git a/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/transcription/TranscriptionEngine.java b/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/transcription/TranscriptionEngine.java
index a2956a3db0b..f33ffc3ee02 100644
--- a/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/transcription/TranscriptionEngine.java
+++ b/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/transcription/TranscriptionEngine.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
+ * Copyright (c) 2014, 2015 CEA LIST, Christian W. Damus, and others.
*
*
* All rights reserved. This program and the accompanying materials
@@ -9,6 +9,7 @@
*
* Contributors:
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 468079
*
*****************************************************************************/
package org.eclipse.papyrus.uml.developper.mde.transcription;
@@ -24,6 +25,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eclipse.papyrus.uml.developper.mde.I_DocumentStereotype;
+import org.eclipse.papyrus.uml.developper.mde.LinkUtil;
import org.eclipse.papyrus.uml.developper.mde.handler.IDMAbstractHandler;
import org.eclipse.uml2.uml.Comment;
import org.eclipse.uml2.uml.Element;
@@ -134,9 +136,18 @@ public class TranscriptionEngine {
Element packageableElement = iteComment.next();
if (packageableElement.getAppliedStereotype(I_DocumentStereotype.CONTENT_STEREOTYPE) != null) {
if (((Comment) packageableElement).getBody() != null) {
+ // Mark position
+ final int offset = out.length();
+
transcription.writeParagraph(out, packageableElement);
if (packageableElement.getOwnedComments() != null) {
- writeRefContent(out, (Comment)packageableElement);
+ writeRefContent(out, (Comment) packageableElement);
+ }
+
+ // Expand in-line hyperlinks
+ String expanded = LinkUtil.transcodeHyperlinks(out, offset, out.length(), transcription.getHyperlinkTranscoder());
+ if (expanded != null) {
+ out.replace(offset, out.length(), expanded);
}
}
}
@@ -147,15 +158,15 @@ public class TranscriptionEngine {
}
}
if (packageableElement.getAppliedStereotype(I_DocumentStereotype.SECTION_STEREOTYPE) != null) {
- transcription.writesectionTitle(out, level, packageableElement);
- writeContent(out, ((Package) packageableElement), level + 1);
+ transcription.writeSectionTitle(out, level, packageableElement);
+ writeContent(out, ((Package) packageableElement), level + 1);
}
if (packageableElement.getAppliedStereotype(I_DocumentStereotype.TABLE_STEREOTYPE) != null) {
writeTable(out, packageableElement);
}
if (packageableElement.getAppliedStereotype(I_DocumentStereotype.TABLEOFCONTENT_STEREOTYPE) != null) {
- transcription.writesectionTitle(out, 2, packageableElement);
- writeTOC(out, (Package)packageableElement);
+ transcription.writeSectionTitle(out, 2, packageableElement);
+ writeTOC(out, (Package) packageableElement);
}
}
}
@@ -174,29 +185,29 @@ public class TranscriptionEngine {
Stereotype refContentStereotype = commentElement.getAppliedStereotype(I_DocumentStereotype.REF_CONTENT_STEREOTYPE);
if (refContentStereotype != null) {
Object ref = commentElement.getValue(refContentStereotype, I_DocumentStereotype.REF_CONTENT_REF_ATT);
-
+
/* Get the URI of the model element */
if (ref instanceof NamedElement) {
- Element referent = IDMAbstractHandler.elt2DocElt.get((NamedElement)ref);
+ Element referent = IDMAbstractHandler.getDocElement((NamedElement) ref);
if (referent != null) {
- String referentURI = ((XMIResource)referent.eResource()).getID(referent);
+ String referentURI = referent.eResource().getURIFragment(referent);
String body = commentElement.getBody();
-
+
/* Write the text */
- if (iteComment.hasNext()) {
+ if (iteComment.hasNext()) {
body = body + ", ";
}
- transcription.writeRefContent(out, referentURI, ((NamedElement)ref).getName(), body);
- }
+ transcription.writeRefContent(out, referentURI, ((NamedElement) ref).getName(), body);
+ }
}
}
}
}
/**
- * Retrieves the Table of Contents "Section" Package
+ * Retrieves the Table of Contents "Section" Package
* and iterates on it "Section" package.
- * For each, write it name and URI in the output file.
+ * For each, write it name and URI in the output file.
* Then, iterates on it child
*
* @param out
@@ -209,17 +220,17 @@ public class TranscriptionEngine {
if (sectionStereotype != null) {
transcription.writeBeginTOC(out);
Package chapter = (Package) cddPackageableElement;
- Package chapterDocElt = IDMAbstractHandler.Toc2DocElt.get(chapter);
- String URI = ((XMIResource)chapterDocElt.eResource()).getID(chapterDocElt);
+ Package chapterDocElt = IDMAbstractHandler.getDocPackageForTOC(chapter);
+ String URI = ((XMIResource) chapterDocElt.eResource()).getID(chapterDocElt);
transcription.writeTOCSection(out, chapter.getName(), URI);
- writeSubSectionTOC(out, chapter);
+ writeSubSectionTOC(out, chapter);
transcription.writeEndTOC(out);
}
}
}
/**
- * Retrieves the sub section of a "Section" package.
+ * Retrieves the sub section of a "Section" package.
* Then for each, writes it name and URI on the output file.
* It's a recursive method, so call it again with this package as argument.
*
@@ -231,9 +242,9 @@ public class TranscriptionEngine {
Element cddSubSection = elements.next();
Stereotype sectionStereotype = cddSubSection.getAppliedStereotype(I_DocumentStereotype.SECTION_STEREOTYPE);
if (sectionStereotype != null) {
- Package subSection = (Package)cddSubSection;
- Package subSectionDocElt = IDMAbstractHandler.Toc2DocElt.get(subSection);
- String URI = ((XMIResource)subSectionDocElt.eResource()).getID(subSectionDocElt);
+ Package subSection = (Package) cddSubSection;
+ Package subSectionDocElt = IDMAbstractHandler.getDocPackageForTOC(subSection);
+ String URI = ((XMIResource) subSectionDocElt.eResource()).getID(subSectionDocElt);
transcription.writeTOCSubSection(out, subSection.getName(), URI);
transcription.writeBeginTOC(out);
writeSubSectionTOC(out, subSection);
@@ -253,11 +264,11 @@ public class TranscriptionEngine {
* @param packageableElement
*/
public void writeTable(StringBuffer out, Element packageableElement) {
- Comment tableComment = (Comment)packageableElement;
+ Comment tableComment = (Comment) packageableElement;
Stereotype tableStereotype = tableComment.getAppliedStereotype(I_DocumentStereotype.TABLE_STEREOTYPE);
// Write the structure of the table and it head line
- String tableCaption = (String) ((Comment)packageableElement).getValue(tableStereotype, I_DocumentStereotype.TABLE_CAPTION_ATT);
+ String tableCaption = (String) ((Comment) packageableElement).getValue(tableStereotype, I_DocumentStereotype.TABLE_CAPTION_ATT);
transcription.writeTable(out, tableCaption);
// Iterates on table ownedComments
@@ -265,7 +276,7 @@ public class TranscriptionEngine {
Comment lineComment = cddLineComment.next();
if (lineComment.getAppliedStereotype(I_DocumentStereotype.LINE_STEREOTYPE) != null) {
transcription.writeBeginTRTag(out);
- // Iterates on line ownedComments
+ // Iterates on line ownedComments
for (Iterator<Comment> cddCellComment = lineComment.getOwnedComments().iterator(); cddCellComment.hasNext();) {
Comment cellComment = cddCellComment.next();
if (cellComment.getAppliedStereotype(I_DocumentStereotype.CELL_STEREOTYPE) != null) {
@@ -284,15 +295,15 @@ public class TranscriptionEngine {
String referentURI = "";
String referenceName = "";
Object ref = refContentComment.getValue(refContentStereotype, I_DocumentStereotype.REF_CONTENT_REF_ATT);
-
+
/* Get the URI of the model element */
if (ref instanceof NamedElement) {
NamedElement refElement = (NamedElement) ref;
referenceName = refElement.getName();
- Element referentElement = IDMAbstractHandler.elt2DocElt.get(refElement);
+ Element referentElement = IDMAbstractHandler.getDocElement(refElement);
if (referentElement != null) {
- referentURI = ((XMIResource)referentElement.eResource()).getID(referentElement);
- }
+ referentURI = ((XMIResource) referentElement.eResource()).getID(referentElement);
+ }
}
if (cellSize > 1 && cddRefContentComment.hasNext()) {
@@ -311,6 +322,6 @@ public class TranscriptionEngine {
transcription.writeEndTRTag(out);
}
}
- transcription.writeEndingTable(out);
+ transcription.writeEndingTable(out);
}
}
diff --git a/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/transcription/WikiTranscription.java b/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/transcription/WikiTranscription.java
index ded7c503632..719f6cf6178 100644
--- a/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/transcription/WikiTranscription.java
+++ b/plugins/developer/org.eclipse.papyrus.uml.developer.mde/src/org/eclipse/papyrus/uml/developper/mde/transcription/WikiTranscription.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
+ * Copyright (c) 2014, 2015 CEA LIST, Christian W. Damus, and others.
*
*
* All rights reserved. This program and the accompanying materials
@@ -9,24 +9,41 @@
*
* Contributors:
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 468079
*
*****************************************************************************/
package org.eclipse.papyrus.uml.developper.mde.transcription;
import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eclipse.papyrus.uml.developper.mde.I_DocumentStereotype;
+import org.eclipse.papyrus.uml.developper.mde.LinkUtil;
+import org.eclipse.papyrus.uml.developper.mde.LinkUtil.Hyperlink;
import org.eclipse.uml2.uml.Comment;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.Stereotype;
+import com.google.common.base.Function;
+
/**
* this class is a specialization to generate mediawiki files.
*
*/
public class WikiTranscription implements ITranscription {
+ private final Function<LinkUtil.Hyperlink, String> hyperlinkFunction = new Function<LinkUtil.Hyperlink, String>() {
+ @Override
+ public String apply(Hyperlink input) {
+ return String.format("[[#%s|%s]]", input.href(), input.text());
+ }
+ };
+
+ @Override
+ public Function<? super Hyperlink, String> getHyperlinkTranscoder() {
+ return hyperlinkFunction;
+ }
+
/**
* @see org.eclipse.papyrus.uml.developper.mde.transcription.ITranscription#writeEndingDocument(java.lang.StringBuffer)
*
@@ -76,13 +93,16 @@ public class WikiTranscription implements ITranscription {
*/
@Override
- public void writesectionTitle(StringBuffer out, int level, Element packageableElement) {
+ public void writeSectionTitle(StringBuffer out, int level, Element packageableElement) {
if (level == 2) {
- out.append("\n==<span" + getId(packageableElement) + ">" + ((Package) packageableElement).getName() + "</span>==");} //$NON-NLS-1$ //$NON-NLS-2$
+ out.append("\n==<span" + getId(packageableElement) + ">" + ((Package) packageableElement).getName() + "</span>=="); //$NON-NLS-1$ //$NON-NLS-2$
+ }
if (level == 3) {
- out.append("\n===<span" + getId(packageableElement) + ">" + ((Package) packageableElement).getName() + "</span>===");} //$NON-NLS-1$ //$NON-NLS-2$
+ out.append("\n===<span" + getId(packageableElement) + ">" + ((Package) packageableElement).getName() + "</span>==="); //$NON-NLS-1$ //$NON-NLS-2$
+ }
if (level == 4) {
- out.append("\n====<span" + getId(packageableElement) + ">" + ((Package) packageableElement).getName() + "</span>====");} //$NON-NLS-1$ //$NON-NLS-2$
+ out.append("\n====<span" + getId(packageableElement) + ">" + ((Package) packageableElement).getName() + "</span>===="); //$NON-NLS-1$ //$NON-NLS-2$
+ }
}
@@ -110,7 +130,7 @@ public class WikiTranscription implements ITranscription {
@Override
public void writeParagraph(StringBuffer out, Element packageableElement) {
- out.append("\n<span" + getId(packageableElement)+ ">" + ((Comment) packageableElement).getBody() + "</span>"); //$NON-NLS-1$
+ out.append("\n<span" + getId(packageableElement) + ">" + ((Comment) packageableElement).getBody() + "</span>"); //$NON-NLS-1$
}
@@ -119,12 +139,12 @@ public class WikiTranscription implements ITranscription {
return "DeveloperDoc.mediawiki"; //$NON-NLS-1$
}
-
+
/**
* @return
*/
public String getId(Element packageableElement) {
- String packageableElementtFragment = ((XMIResource)packageableElement.eResource()).getID(packageableElement);
+ String packageableElementtFragment = ((XMIResource) packageableElement.eResource()).getID(packageableElement);
String id = " id=\"" + packageableElementtFragment + "\"";
return id;
}
@@ -155,13 +175,13 @@ public class WikiTranscription implements ITranscription {
@Override
public void writeLine(StringBuffer out, String uri, String requirementName, String text) {
if (uri.equals("")) {
- out.append(text);
+ out.append(text);
} else {
- out.append("[[#" + uri + "|" + text + "]]");
- }
-
+ out.append("[[#" + uri + "|" + text + "]]");
+ }
+
}
-
+
/**
* @see org.eclipse.papyrus.uml.developper.mde.transcription.ITranscription#writeNewLine(java.lang.StringBuffer)
*
@@ -170,7 +190,7 @@ public class WikiTranscription implements ITranscription {
@Override
public void writeNewLine(StringBuffer out) {
out.append("\n");
-
+
}
@@ -193,7 +213,7 @@ public class WikiTranscription implements ITranscription {
@Override
public void writeEndTRTag(StringBuffer out) {
// TODO Auto-generated method stub
-
+
}
@@ -227,7 +247,7 @@ public class WikiTranscription implements ITranscription {
@Override
public void writeEndTDTag(StringBuffer out) {
out.append("\n");
-
+
}
@@ -241,10 +261,10 @@ public class WikiTranscription implements ITranscription {
@Override
public void writeRefContent(StringBuffer out, String uri, String requirementName, String reqID) {
if (uri.equals("")) {
- out.append(reqID);
+ out.append(reqID);
} else {
- out.append("[[#" + uri + "|" + reqID + "]]");
- }
+ out.append("[[#" + uri + "|" + reqID + "]]");
+ }
}
@@ -256,7 +276,7 @@ public class WikiTranscription implements ITranscription {
@Override
public void writeBeginParagraph(StringBuffer out) {
out.append("\n<span>");
-
+
}
@@ -268,7 +288,7 @@ public class WikiTranscription implements ITranscription {
@Override
public void writeEndingParagraph(StringBuffer out) {
out.append("</span>\n");
-
+
}
@@ -297,7 +317,7 @@ public class WikiTranscription implements ITranscription {
*/
@Override
public void writeTOCSubSection(StringBuffer out, String subSectionName, String uri) {
- out.append("\n::[[#" + uri + "|" + subSectionName + "]]");
+ out.append("\n::[[#" + uri + "|" + subSectionName + "]]");
}
@@ -309,7 +329,7 @@ public class WikiTranscription implements ITranscription {
@Override
public void writeBeginTOC(StringBuffer out) {
// TODO Auto-generated method stub
-
+
}
@@ -321,7 +341,7 @@ public class WikiTranscription implements ITranscription {
@Override
public void writeEndTOC(StringBuffer out) {
// TODO Auto-generated method stub
-
+
}

Back to the top