Bug 501157 - [GenDoc] Support for new document types - reuse of the UI
action
Change-Id: I548b035fbfeb809b92f5b5de6ea25f92c9db163b
diff --git a/plugins/org.eclipse.gendoc.services.docx/plugin.xml b/plugins/org.eclipse.gendoc.services.docx/plugin.xml
index 18bca6f..fbc5512 100644
--- a/plugins/org.eclipse.gendoc.services.docx/plugin.xml
+++ b/plugins/org.eclipse.gendoc.services.docx/plugin.xml
@@ -12,9 +12,10 @@
point="org.eclipse.ui.handlers">
<handler
class="org.eclipse.gendoc.ui.actions.GenerateDocumentation"
- commandId="org.eclipse.gendoc.script">
+ commandId="org.eclipse.gendoc.script.doc">
<activeWhen>
- <iterate>
+ <iterate
+ ifEmpty="false">
<or>
<and>
<instanceof
diff --git a/plugins/org.eclipse.gendoc.services.odt/plugin.xml b/plugins/org.eclipse.gendoc.services.odt/plugin.xml
index 2413ecf..32e88a1 100644
--- a/plugins/org.eclipse.gendoc.services.odt/plugin.xml
+++ b/plugins/org.eclipse.gendoc.services.odt/plugin.xml
@@ -12,9 +12,10 @@
point="org.eclipse.ui.handlers">
<handler
class="org.eclipse.gendoc.ui.actions.GenerateDocumentation"
- commandId="org.eclipse.gendoc.script">
+ commandId="org.eclipse.gendoc.script.doc">
<activeWhen>
- <iterate>
+ <iterate
+ ifEmpty="false">
<or>
<and>
<instanceof
diff --git a/plugins/org.eclipse.gendoc.services.pptx/plugin.xml b/plugins/org.eclipse.gendoc.services.pptx/plugin.xml
index c301180..a9e08b0 100644
--- a/plugins/org.eclipse.gendoc.services.pptx/plugin.xml
+++ b/plugins/org.eclipse.gendoc.services.pptx/plugin.xml
@@ -93,9 +93,10 @@
point="org.eclipse.ui.handlers">
<handler
class="org.eclipse.gendoc.ui.actions.GenerateDocumentation"
- commandId="org.eclipse.gendoc.script">
+ commandId="org.eclipse.gendoc.script.doc">
<activeWhen>
- <iterate>
+ <iterate
+ ifEmpty="false">
<or>
<and>
<instanceof
diff --git a/plugins/org.eclipse.gendoc.services.xlsx/plugin.xml b/plugins/org.eclipse.gendoc.services.xlsx/plugin.xml
index 15e08b5..b45376f 100644
--- a/plugins/org.eclipse.gendoc.services.xlsx/plugin.xml
+++ b/plugins/org.eclipse.gendoc.services.xlsx/plugin.xml
@@ -28,9 +28,10 @@
point="org.eclipse.ui.handlers">
<handler
class="org.eclipse.gendoc.ui.actions.GenerateDocumentation"
- commandId="org.eclipse.gendoc.script">
+ commandId="org.eclipse.gendoc.script.doc">
<activeWhen>
- <iterate>
+ <iterate
+ ifEmpty="false">
<or>
<and>
<instanceof
diff --git a/plugins/org.eclipse.gendoc.ui/plugin.xml b/plugins/org.eclipse.gendoc.ui/plugin.xml
index 29fc860..1447aad 100644
--- a/plugins/org.eclipse.gendoc.ui/plugin.xml
+++ b/plugins/org.eclipse.gendoc.ui/plugin.xml
@@ -11,7 +11,7 @@
<command
categoryId="org.eclipse.gendoc.category"
description="Generate documentation using Gendoc"
- id="org.eclipse.gendoc.script"
+ id="org.eclipse.gendoc.script.doc"
name="Generate documentation using Gendoc">
</command>
</extension>
@@ -21,20 +21,12 @@
allPopups="false"
locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<command
- commandId="org.eclipse.gendoc.script"
+ commandId="org.eclipse.gendoc.script.doc"
icon="icons/gendoc16.ico"
label="Generate documentation using Gendoc"
style="push">
<visibleWhen
- checkEnabled="false">
- <or>
- <with
- variable="activePartId">
- <equals
- value="org.eclipse.ui.navigator.ProjectExplorer">
- </equals>
- </with>
- </or>
+ checkEnabled="true">
</visibleWhen>
</command>
</menuContribution>
diff --git a/plugins/org.eclipse.gendoc.wizard.papyrus/src/org/eclipse/gendoc/bundle/acceleo/papyrus/utils/OneFileUMLSelectionConverter.java b/plugins/org.eclipse.gendoc.wizard.papyrus/src/org/eclipse/gendoc/bundle/acceleo/papyrus/utils/OneFileUMLSelectionConverter.java
index 9f26461..58e5b53 100644
--- a/plugins/org.eclipse.gendoc.wizard.papyrus/src/org/eclipse/gendoc/bundle/acceleo/papyrus/utils/OneFileUMLSelectionConverter.java
+++ b/plugins/org.eclipse.gendoc.wizard.papyrus/src/org/eclipse/gendoc/bundle/acceleo/papyrus/utils/OneFileUMLSelectionConverter.java
@@ -15,7 +15,9 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.Path;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
import org.eclipse.gendoc.wizard.ISelectionConverter;
import org.eclipse.papyrus.infra.onefile.model.IPapyrusFile;
@@ -39,17 +41,17 @@
}
else if (selectedObject instanceof EObject){
EObject eobject = (EObject) selectedObject;
- selectedFile = WorkspaceSynchronizer.getFile(eobject.eResource());
+ selectedFile = getPapyrusUMLFile(eobject.eResource());
} else if (selectedObject instanceof IAdaptable) {
- selectedFile = (IFile)((IAdaptable) selectedObject).getAdapter(IFile.class); // Can be null
+ selectedFile = getPapyrusUMLFile((IFile)((IAdaptable) selectedObject).getAdapter(IFile.class)); // Can be null
if (selectedFile == null){
EObject eobject = (EObject) ((IAdaptable) selectedObject).getAdapter(EObject.class);
if (eobject != null){
- selectedFile = WorkspaceSynchronizer.getFile(eobject.eResource());
+ selectedFile = getPapyrusUMLFile(eobject.eResource());
}
}
} else if (selectedObject instanceof IFile) {
- selectedFile = (IFile) selectedObject;
+ selectedFile = getPapyrusUMLFile((IFile) selectedObject);
} else {
// No valid selection
}
@@ -61,6 +63,28 @@
return selectedFile;
}
+ private IFile getPapyrusUMLFile(Resource resource) {
+ return getPapyrusUMLFile(WorkspaceSynchronizer.getFile(resource));
+ }
+
+ private IFile getPapyrusUMLFile(IFile file) {
+ if (file == null)
+ return null;
+ String extension = file.getFileExtension();
+ if (extension == null)
+ return null;
+ if (!extension.equals("uml") && !extension.equals("di") && !extension.equals("notation"))
+ return null;
+ String name = file.getName();
+ name = name.substring(0, name.length()-extension.length());
+ IFile diFile = file.getParent().getFile(new Path(name+"di"));
+ IFile umlFile = file.getParent().getFile(new Path(name+"uml"));
+
+ if (diFile.exists() && umlFile.exists())
+ return umlFile;
+ return null;
+ }
+
private boolean isUMLFile(IFile file) {
return "uml".equals(file.getFileExtension());
}
diff --git a/plugins/org.eclipse.gendoc.wizard.papyrus/src/org/eclipse/gendoc/wizard/papyrus/PapyrusGendocRunner.java b/plugins/org.eclipse.gendoc.wizard.papyrus/src/org/eclipse/gendoc/wizard/papyrus/PapyrusGendocRunner.java
index 20eb18d..9722d21 100644
--- a/plugins/org.eclipse.gendoc.wizard.papyrus/src/org/eclipse/gendoc/wizard/papyrus/PapyrusGendocRunner.java
+++ b/plugins/org.eclipse.gendoc.wizard.papyrus/src/org/eclipse/gendoc/wizard/papyrus/PapyrusGendocRunner.java
@@ -42,7 +42,7 @@
*/
public Pattern getPattern()
{
- return Pattern.compile(".*\\.di");
+ return Pattern.compile(".*\\.uml");
}
/**
diff --git a/plugins/org.eclipse.gendoc.wizard/plugin.xml b/plugins/org.eclipse.gendoc.wizard/plugin.xml
index fbf9239..521443a 100644
--- a/plugins/org.eclipse.gendoc.wizard/plugin.xml
+++ b/plugins/org.eclipse.gendoc.wizard/plugin.xml
@@ -3,49 +3,28 @@
<plugin>
<extension-point id="org.eclipse.gendoc.wizard.runner" name="GendocPoint" schema="schema/org.eclipse.gendoc.wizard.runner.exsd"/>
<extension
+ point="org.eclipse.ui.commands">
+ <command
+ categoryId="org.eclipse.gendoc.category"
+ description="Generate documentation using Gendoc"
+ id="org.eclipse.gendoc.script.wizard"
+ name="Generate documentation using Gendoc">
+ </command>
+ </extension>
+ <extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.ui.popup.any">
<command
- commandId="org.eclipse.gendoc.script"
+ commandId="org.eclipse.gendoc.script.wizard"
icon="icons/gendoc16.ico"
- label="Generate Documentation using Gendoc"
+ label="Generate Documentation using Gendoc ..."
style="push"
tooltip="Use Gendoc to generate documentation from model">
- <visibleWhen
- checkEnabled="false">
- <iterate
- ifEmpty="false">
- <and>
- <or>
- <test
- forcePluginActivation="true"
- property="org.eclipse.gendoc.wizard.isEnabled">
- </test>
- <adapt
- type="java.util.Collection">
- <test
- forcePluginActivation="true"
- property="org.eclipse.gendoc.wizard.isCollectionEnabled">
- </test>
- </adapt>
- <adapt
- type="org.eclipse.emf.ecore.EObject">
- <test
- forcePluginActivation="true"
- property="org.eclipse.gendoc.wizard.isEnabled">
- </test>
- </adapt>
- </or>
- <not>
- <adapt
- type="org.eclipse.core.resources.IFile">
- </adapt>
- </not>
- </and>
- </iterate>
- </visibleWhen>
+ <visibleWhen
+ checkEnabled="true">
+ </visibleWhen>
</command>
</menuContribution>
</extension>
@@ -75,10 +54,11 @@
point="org.eclipse.ui.handlers">
<handler
class="org.eclipse.gendoc.wizard.popup.actions.GenerateDocumentationHandler"
- commandId="org.eclipse.gendoc.script">
+ commandId="org.eclipse.gendoc.script.wizard">
<enabledWhen>
<iterate
- ifEmpty="false">
+ ifEmpty="false"
+ operator="and">
<or>
<test
forcePluginActivation="true"
diff --git a/plugins/org.eclipse.gendoc.wizard/src/org/eclipse/gendoc/wizard/Utils.java b/plugins/org.eclipse.gendoc.wizard/src/org/eclipse/gendoc/wizard/Utils.java
index 4d5c558..bf40d98 100644
--- a/plugins/org.eclipse.gendoc.wizard/src/org/eclipse/gendoc/wizard/Utils.java
+++ b/plugins/org.eclipse.gendoc.wizard/src/org/eclipse/gendoc/wizard/Utils.java
@@ -215,7 +215,7 @@
if (runner instanceof IGendocSelectionConverterRunner){
if (((IGendocSelectionConverterRunner) runner).getSelectionConverter().matches(selectedObject)) {
IFile selectedFile = ((IGendocSelectionConverterRunner) runner).getSelectionConverter().getFile(selectedObject);
- if (selectedFile !=null && runner.getPattern().matcher(selectedFile.getName()).matches()) {
+ if (selectedFile !=null && runner.getPattern() !=null && runner.getPattern().matcher(selectedFile.getName()).matches()) {
runners.add(runner);
} else {
// invalid runner