Addressed the comments from the previous push: replaced the String filePath with a io.File object in the office project.
Change-Id: Ibb6ed4a3fe7309f3a0240483514d92f1dc55cd21
Signed-off-by: Dusan Kalanj <kalanj@chalmers.se>
diff --git a/org.eclipse.capra.feature/feature.xml b/org.eclipse.capra.feature/feature.xml
index 52aa0cf..e9705d8 100644
--- a/org.eclipse.capra.feature/feature.xml
+++ b/org.eclipse.capra.feature/feature.xml
@@ -99,13 +99,6 @@
unpack="false"/>
<plugin
- id="org.eclipse.capra.ui"
- download-size="0"
- install-size="0"
- version="0.0.0"
- unpack="false"/>
-
- <plugin
id="org.eclipse.capra.ui.notification"
download-size="0"
install-size="0"
@@ -126,6 +119,27 @@
version="0.0.0"/>
<plugin
+ id="org.eclipse.capra.ui"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+ <plugin
+ id="org.eclipse.capra.ui.office"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+ <plugin
+ id="org.eclipse.capra.handler.office"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+ <plugin
id="org.eclipse.capra.handler.reqIf"
download-size="0"
install-size="0"
diff --git a/org.eclipse.capra.handler.office/.classpath b/org.eclipse.capra.handler.office/.classpath
new file mode 100644
index 0000000..eca7bdb
--- /dev/null
+++ b/org.eclipse.capra.handler.office/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.capra.handler.office/.project b/org.eclipse.capra.handler.office/.project
new file mode 100644
index 0000000..87f6ca0
--- /dev/null
+++ b/org.eclipse.capra.handler.office/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.capra.handler.office</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.capra.handler.office/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.capra.handler.office/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..0c68a61
--- /dev/null
+++ b/org.eclipse.capra.handler.office/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/org.eclipse.capra.handler.office/META-INF/MANIFEST.MF b/org.eclipse.capra.handler.office/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..75433ff
--- /dev/null
+++ b/org.eclipse.capra.handler.office/META-INF/MANIFEST.MF
@@ -0,0 +1,8 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Capra: Traceability Management
+Bundle-SymbolicName: org.eclipse.capra.handler.office;singleton:=true
+Bundle-Version: 0.7.0.qualifier
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+Require-Bundle: org.eclipse.capra.core,
+ org.eclipse.capra.ui.office;bundle-version="0.7.0"
diff --git a/org.eclipse.capra.handler.office/build.properties b/org.eclipse.capra.handler.office/build.properties
new file mode 100644
index 0000000..9fc85e9
--- /dev/null
+++ b/org.eclipse.capra.handler.office/build.properties
@@ -0,0 +1,14 @@
+###############################################################################
+# Copyright (c) 2016 Chalmers | University of Gothenburg, rt-labs 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:
+# Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+###############################################################################
+source.. = src/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/org.eclipse.capra.handler.office/plugin.xml b/org.eclipse.capra.handler.office/plugin.xml
new file mode 100644
index 0000000..4669752
--- /dev/null
+++ b/org.eclipse.capra.handler.office/plugin.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<!--
+ Copyright (c) 2016 Chalmers | University of Gothenburg, rt-labs 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:
+ Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+ -->
+
+<plugin>
+ <extension
+ id="org.eclipse.capra.handler.office.OfficeHandler"
+ point="org.eclipse.capra.configuration.artifactHandler">
+ <artifactHandler
+ class="org.eclipse.capra.handler.office.OfficeHandler">
+ </artifactHandler>
+ </extension>
+</plugin>
diff --git a/org.eclipse.capra.handler.office/pom.xml b/org.eclipse.capra.handler.office/pom.xml
new file mode 100644
index 0000000..2b62fa8
--- /dev/null
+++ b/org.eclipse.capra.handler.office/pom.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2016 Chalmers | University of Gothenburg, rt-labs 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:
+ Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>org.eclipse.capra.handler.office</artifactId>
+ <parent>
+ <artifactId>parent</artifactId>
+ <groupId>org.eclipse.capra</groupId>
+ <version>0.7.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <packaging>eclipse-plugin</packaging>
+</project>
diff --git a/org.eclipse.capra.handler.office/src/org/eclipse/capra/handler/office/OfficeHandler.java b/org.eclipse.capra.handler.office/src/org/eclipse/capra/handler/office/OfficeHandler.java
new file mode 100644
index 0000000..33aec6e
--- /dev/null
+++ b/org.eclipse.capra.handler.office/src/org/eclipse/capra/handler/office/OfficeHandler.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Chalmers | University of Gothenburg, rt-labs 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:
+ * Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+
+package org.eclipse.capra.handler.office;
+
+import org.eclipse.capra.core.adapters.ArtifactMetaModelAdapter;
+import org.eclipse.capra.core.handlers.ArtifactHandler;
+import org.eclipse.capra.core.helpers.ExtensionPointHelper;
+import org.eclipse.capra.ui.office.objects.CapraOfficeObject;
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ * A handler to create trace links from and to content of Office files.
+ *
+ * @author Dusan Kalanj
+ *
+ */
+public class OfficeHandler implements ArtifactHandler {
+
+ @Override
+ public boolean canHandleSelection(Object selection) {
+ return selection instanceof CapraOfficeObject;
+ }
+
+ @Override
+ public EObject getEObjectForSelection(Object selection, EObject artifactModel) {
+ // Returns the EObject corresponding to the input object if the input is
+ // an EObject, or if it is Adaptable to an EObject
+ CapraOfficeObject officeObject = (CapraOfficeObject) selection;
+ if (officeObject != null) {
+ ArtifactMetaModelAdapter adapter = ExtensionPointHelper.getArtifactWrapperMetaModelAdapter().get();
+ // TODO here artifactName is the same as the row/paragraph
+ // description. Should it be different?
+ EObject wrapper = adapter.createArtifact(artifactModel, this.getClass().getName(), officeObject.getUri(),
+ officeObject.toString());
+ return wrapper;
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public Object resolveArtifact(EObject artifact) {
+ // TODO Decide on how to resolve the artifact.
+ // Just return the appropriate row / requirement or display it in the
+ // OfficeView?
+ return null;
+ }
+
+}
diff --git a/org.eclipse.capra.releng.target/org.eclipse.capra.releng.target.target b/org.eclipse.capra.releng.target/org.eclipse.capra.releng.target.target
index e104344..b90a01b 100644
--- a/org.eclipse.capra.releng.target/org.eclipse.capra.releng.target.target
+++ b/org.eclipse.capra.releng.target/org.eclipse.capra.releng.target.target
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<?pde version="3.8"?><target name="Neon" sequenceNumber="27">
+<?pde version="3.8"?><target name="Neon" sequenceNumber="43">
<locations>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
-<unit id="org.eclipse.sdk.ide" version="0.0.0"/>
-<repository location="http://download.eclipse.org/eclipse/updates/4.6"/>
+<unit id="net.sourceforge.plantuml.feature.feature.group" version="0.0.0"/>
+<repository location="http://basar.idi.ntnu.no/svn/tdt4100/anonymous/trunk/updatesite"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
-<unit id="com.google.guava" version="0.0.0"/>
-<unit id="com.google.guava.source" version="0.0.0"/>
-<repository location="http://download.eclipse.org/tools/orbit/downloads/drops/R20160520211859/repository"/>
+<unit id="org.eclipse.rmf.reqif10.sdk.feature.feature.group" version="0.13.0.201509161042"/>
+<unit id="org.eclipse.rmf.reqif10.pror.sdk.feature.feature.group" version="0.13.0.201509161042"/>
+<repository location="http://download.eclipse.org/rmf/updates/releases"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.xtext.sdk.feature.group" version="0.0.0"/>
@@ -36,13 +36,18 @@
<repository location="http://download.eclipse.org/egit/github/updates/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
-<unit id="net.sourceforge.plantuml.feature.feature.group" version="0.0.0"/>
-<repository location="http://basar.idi.ntnu.no/svn/tdt4100/anonymous/trunk/updatesite"/>
+<unit id="org.eclipse.sdk.ide" version="0.0.0"/>
+<repository location="http://download.eclipse.org/eclipse/updates/4.6"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
-<unit id="org.eclipse.rmf.reqif10.sdk.feature.feature.group" version="0.13.0.201509161042"/>
-<unit id="org.eclipse.rmf.reqif10.pror.sdk.feature.feature.group" version="0.13.0.201509161042"/>
-<repository location="http://download.eclipse.org/rmf/updates/releases"/>
+<unit id="org.apache.poi.ooxml" version="3.9.0.v201405241905"/>
+<unit id="org.apache.xmlbeans" version="2.3.0.v201605172150"/>
+<unit id="com.google.guava" version="15.0.0.v201403281430"/>
+<unit id="com.google.guava.source" version="15.0.0.v201403281430"/>
+<unit id="org.apache.commons.collections" version="3.2.2.v201511171945"/>
+<unit id="org.apache.poi.ooxml.schemas" version="3.9.0.v201405241750"/>
+<unit id="org.apache.poi" version="3.9.0.v201405241750"/>
+<repository location="http://download.eclipse.org/tools/orbit/downloads/drops/R20160520211859/repository"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.gef4.common.sdk.feature.group" version="0.0.0"/>
diff --git a/org.eclipse.capra.ui.office/.classpath b/org.eclipse.capra.ui.office/.classpath
new file mode 100644
index 0000000..9f3184e
--- /dev/null
+++ b/org.eclipse.capra.ui.office/.classpath
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
+ <attributes>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/org.eclipse.capra.ui.office/.project b/org.eclipse.capra.ui.office/.project
new file mode 100644
index 0000000..dc190ba
--- /dev/null
+++ b/org.eclipse.capra.ui.office/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.capra.ui.office</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.capra.ui.office/.settings/org.eclipse.core.resources.prefs b/org.eclipse.capra.ui.office/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..7a53139
--- /dev/null
+++ b/org.eclipse.capra.ui.office/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,3 @@
+eclipse.preferences.version=1
+encoding/<project>=UTF-8
+encoding/src=UTF-8
diff --git a/org.eclipse.capra.ui.office/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.capra.ui.office/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..6e80039
--- /dev/null
+++ b/org.eclipse.capra.ui.office/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/org.eclipse.capra.ui.office/.settings/org.eclipse.m2e.core.prefs b/org.eclipse.capra.ui.office/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000..f897a7f
--- /dev/null
+++ b/org.eclipse.capra.ui.office/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/org.eclipse.capra.ui.office/META-INF/MANIFEST.MF b/org.eclipse.capra.ui.office/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..c627907
--- /dev/null
+++ b/org.eclipse.capra.ui.office/META-INF/MANIFEST.MF
@@ -0,0 +1,27 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Capra: Traceability Management
+Bundle-SymbolicName: org.eclipse.capra.ui.office;singleton:=true
+Bundle-Version: 0.7.0.qualifier
+Bundle-ClassPath: .
+Bundle-Vendor: Chalmers | University of Gothenburg
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+Require-Bundle: org.eclipse.emf.edit.ui;bundle-version="2.12.0",
+ org.eclipse.equinox.registry,
+ org.eclipse.swt,
+ org.eclipse.ui,
+ org.eclipse.jface,
+ com.google.guava,
+ org.apache.poi;bundle-version="3.9.0",
+ org.apache.poi.ooxml;bundle-version="3.9.0",
+ org.apache.poi.ooxml.schemas;bundle-version="3.9.0",
+ org.apache.commons.codec;bundle-version="1.6.0",
+ org.apache.commons.collections;bundle-version="3.2.2",
+ org.apache.commons.logging;bundle-version="1.1.1",
+ org.apache.log4j;bundle-version="1.2.15",
+ org.apache.xmlbeans;bundle-version="2.3.0"
+Bundle-ActivationPolicy: lazy
+Export-Package: org.eclipse.capra.ui.office.objects,
+ org.eclipse.capra.ui.office.utils,
+ org.eclipse.capra.ui.office.views
+
diff --git a/org.eclipse.capra.ui.office/build.properties b/org.eclipse.capra.ui.office/build.properties
new file mode 100644
index 0000000..87a7085
--- /dev/null
+++ b/org.eclipse.capra.ui.office/build.properties
@@ -0,0 +1,16 @@
+###############################################################################
+# Copyright (c) 2016 Chalmers | University of Gothenburg, rt-labs 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:
+# Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+###############################################################################
+source.. = src/
+bin.includes = META-INF/,\
+ icons/,\
+ .,\
+ plugin.xml
+
diff --git a/org.eclipse.capra.ui.office/icons/capra.png b/org.eclipse.capra.ui.office/icons/capra.png
new file mode 100644
index 0000000..4e60434
--- /dev/null
+++ b/org.eclipse.capra.ui.office/icons/capra.png
Binary files differ
diff --git a/org.eclipse.capra.ui.office/icons/selectionView.png b/org.eclipse.capra.ui.office/icons/selectionView.png
new file mode 100644
index 0000000..42fdc5a
--- /dev/null
+++ b/org.eclipse.capra.ui.office/icons/selectionView.png
Binary files differ
diff --git a/org.eclipse.capra.ui.office/plugin.xml b/org.eclipse.capra.ui.office/plugin.xml
new file mode 100644
index 0000000..16f3ce1
--- /dev/null
+++ b/org.eclipse.capra.ui.office/plugin.xml
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<!--
+ Copyright (c) 2016 Chalmers | University of Gothenburg, rt-labs 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:
+ Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+ -->
+
+<plugin>
+ <extension
+ point="org.eclipse.ui.views">
+ <category
+ id="org.eclipse.capra.ui.views"
+ name="Capra Views">
+ </category>
+ <view
+ category="org.eclipse.capra.ui.views"
+ class="org.eclipse.capra.ui.office.views.OfficeView"
+ icon="icons/selectionView.png"
+ id="org.eclipse.capra.ui.views.OfficeView"
+ name="Office Selection View">
+ </view>
+ </extension>
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ id="org.eclipse.capra.ui.office.clearselection"
+ name="Clear Selection">
+ </command>
+ <command
+ id="org.eclipse.capra.ui.office.showdetails"
+ name="Show Details">
+ </command>
+ <command
+ id="org.eclipse.capra.ui.office.openfile"
+ name="Open File">
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.capra.ui.office.handlers.ClearSelectionHandler"
+ commandId="org.eclipse.capra.ui.office.clearselection">
+ </handler>
+ <handler
+ class="org.eclipse.capra.ui.office.handlers.ShowObjectDetailsHandler"
+ commandId="org.eclipse.capra.ui.office.showdetails">
+ </handler>
+ <handler
+ class="org.eclipse.capra.ui.office.handlers.OpenFileHandler"
+ commandId="org.eclipse.capra.ui.office.openfile">
+ </handler>
+ </extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ locationURI="popup:org.eclipse.capra.ui.views.OfficeView?after=additions">
+ <command
+ commandId="org.eclipse.capra.ui.office.openfile"
+ label="Open File"
+ style="push"
+ tooltip="Triggers the file selection dialog.">
+ </command>
+ <separator
+ name="org.eclipse.capra.generic.tracecreation.separator1"
+ visible="true">
+ </separator>
+ <command
+ commandId="org.eclipse.capra.ui.office.showdetails"
+ label="Show Details"
+ style="push"
+ tooltip="Shows the details of the selected row">
+ </command>
+ <command
+ commandId="org.eclipse.capra.ui.office.clearselection"
+ label="Clear Selection"
+ style="push"
+ tooltip="Clears the current selection of elements">
+ </command>
+ <separator
+ name="org.eclipse.capra.generic.tracecreation.separator1"
+ visible="true">
+ </separator>
+ </menuContribution>
+ </extension>
+</plugin>
\ No newline at end of file
diff --git a/org.eclipse.capra.ui.office/pom.xml b/org.eclipse.capra.ui.office/pom.xml
new file mode 100644
index 0000000..2691c29
--- /dev/null
+++ b/org.eclipse.capra.ui.office/pom.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2016 Chalmers | University of Gothenburg, rt-labs 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:
+ Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <relativePath>../pom.xml</relativePath>
+ <groupId>org.eclipse.capra</groupId>
+ <artifactId>parent</artifactId>
+ <version>0.7.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>org.eclipse.capra.ui.office</artifactId>
+ <packaging>eclipse-plugin</packaging>
+
+</project>
\ No newline at end of file
diff --git a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/handlers/ClearSelectionHandler.java b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/handlers/ClearSelectionHandler.java
new file mode 100644
index 0000000..839239a
--- /dev/null
+++ b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/handlers/ClearSelectionHandler.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Chalmers | University of Gothenburg, rt-labs 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:
+ * Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+
+package org.eclipse.capra.ui.office.handlers;
+
+import org.eclipse.capra.ui.office.views.OfficeView;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+
+/**
+ * A handler for removing all OfficeObjects from the OfficeView.
+ *
+ * @author Dusan Kalanj
+ *
+ */
+public class ClearSelectionHandler extends AbstractHandler {
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ OfficeView.getOpenedView().clearSelection();
+ return null;
+ }
+}
diff --git a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/handlers/OpenFileHandler.java b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/handlers/OpenFileHandler.java
new file mode 100644
index 0000000..78cd281
--- /dev/null
+++ b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/handlers/OpenFileHandler.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Chalmers | University of Gothenburg, rt-labs 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:
+ * Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+
+package org.eclipse.capra.ui.office.handlers;
+
+import org.eclipse.capra.ui.office.views.OfficeView;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+
+/**
+ * A handler for opening the File-chooser dialog from the context menu.
+ *
+ * @author Dusan Kalanj
+ *
+ */
+public class OpenFileHandler extends AbstractHandler {
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ OfficeView.getOpenedView().openFile();
+ return null;
+ }
+}
diff --git a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/handlers/ShowObjectDetailsHandler.java b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/handlers/ShowObjectDetailsHandler.java
new file mode 100644
index 0000000..5dcb070
--- /dev/null
+++ b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/handlers/ShowObjectDetailsHandler.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Chalmers | University of Gothenburg, rt-labs 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:
+ * Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+
+package org.eclipse.capra.ui.office.handlers;
+
+import org.eclipse.capra.ui.office.views.OfficeView;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * A handler that shows the details of the selected row when the option is
+ * selected through a context menu.
+ *
+ * @author Dusan Kalanj
+ *
+ */
+public class ShowObjectDetailsHandler extends AbstractHandler {
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ OfficeView.getOpenedView().showObjectDetails(event, HandlerUtil.getActiveWorkbenchWindow(event).getShell());
+ return null;
+ }
+}
diff --git a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/objects/CapraExcelRow.java b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/objects/CapraExcelRow.java
new file mode 100644
index 0000000..fa4ea8c
--- /dev/null
+++ b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/objects/CapraExcelRow.java
@@ -0,0 +1,68 @@
+package org.eclipse.capra.ui.office.objects;
+
+import java.io.File;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.DataFormatter;
+import org.apache.poi.ss.usermodel.Row;
+
+public class CapraExcelRow extends CapraOfficeObject {
+
+ /**
+ * Delimiter between excel cells as displayed in the Office View.
+ */
+ private static final String cellDelimiter = " | ";
+
+ /**
+ * Regex of characters to be replaced with white-spaces in the Office View.
+ */
+ private static final String replaceRegex = "[\r\n\t\\p{C}]+";
+
+ public CapraExcelRow() {
+ super();
+ }
+
+ public CapraExcelRow(String data, String uri) {
+ super(data, uri);
+ }
+
+ /**
+ * A constructor that generates a new instance of CapraExcelRow where the
+ * parent properties are extracted from the provided Excel row and File
+ * object that contains the row.
+ */
+ public CapraExcelRow(Row row, File officeFile, DataFormatter formatter) {
+ int rowNum = row.getRowNum();
+
+ StringBuilder rowBuilder = new StringBuilder();
+ rowBuilder.append("Row " + (rowNum + 1) + ": ");
+
+ boolean firstCellSet = false;
+
+ for (int j = 0; j < row.getLastCellNum(); j++) {
+ Cell cell = row.getCell(j);
+ String cellValue = formatter.formatCellValue(cell);
+ if (!cellValue.isEmpty()) {
+ if (!firstCellSet) {
+ rowBuilder.append(cellValue);
+ firstCellSet = true;
+ } else {
+ rowBuilder.append(cellDelimiter + cellValue);
+ }
+ }
+ }
+
+ if (firstCellSet) {
+ Pattern p = Pattern.compile(replaceRegex);
+ Matcher m = p.matcher(rowBuilder);
+
+ String rowContent = (m.replaceAll(" ")).trim();
+ String rowUri = CapraOfficeObject.createUri(officeFile, rowNum);
+
+ this.setData(rowContent);
+ this.setUri(rowUri);
+ }
+ }
+}
diff --git a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/objects/CapraOfficeObject.java b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/objects/CapraOfficeObject.java
new file mode 100644
index 0000000..f595765
--- /dev/null
+++ b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/objects/CapraOfficeObject.java
@@ -0,0 +1,198 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Chalmers | University of Gothenburg, rt-labs 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:
+ * Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+
+package org.eclipse.capra.ui.office.objects;
+
+import java.io.File;
+
+/**
+ * This class provides a custom object for describing the contents of MS Excel
+ * and MS Word related data.
+ *
+ * @author Dusan Kalanj
+ *
+ */
+public class CapraOfficeObject {
+
+ /**
+ * The description of the object (row in Excel, requirement in Word)
+ */
+ private String data = "";
+
+ /**
+ * The uri of the object in the form of filePath/objectId
+ */
+ private String uri = "";
+
+ /**
+ * The delimiter separating the filePath from the objectId in uri
+ */
+
+ /**
+ * A constructor that generates an empty instance of OfficeObject.
+ */
+ public CapraOfficeObject() {
+ }
+
+ /**
+ * A constructor that generates a new instance of OfficeObject with defined
+ * OfficeData and rowUri properties.
+ */
+ public CapraOfficeObject(String data, String uri) {
+ this.data = data;
+ this.uri = uri;
+ }
+
+ /**
+ * A constructor that generates a new instance of OfficeObject with defined
+ * data and uri properties, the latter being constructed from the file-path
+ * and objectId.
+ */
+ public CapraOfficeObject(String data, File officeFile, String objectId) {
+ // TODO here data can be extracted by reading the object in its file
+ this.data = data;
+ this.uri = createUri(officeFile, objectId);
+ }
+
+ /**
+ * Returns the uri of the OfficeObject
+ */
+ public String getUri() {
+ return uri;
+ }
+
+ /**
+ * Sets the uri of the OfficeObject
+ */
+ public void setUri(String uri) {
+ this.uri = uri;
+ }
+
+ /**
+ * Returns the description of the OfficeObject
+ */
+ public String getData() {
+ return this.data;
+ }
+
+ /**
+ * Sets the description of the OfficeObject
+ */
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ /**
+ * Returns the ID of the OfficeObject.
+ */
+ public String getId() {
+ int lastDelimiterIndex = uri.lastIndexOf(File.separator);
+ return uri.substring(lastDelimiterIndex + 1);
+ }
+
+ /**
+ * Returns the file-path of the file that contains the OfficeObject
+ */
+ public String getFilePath() {
+ int lastDelimiterIndex = uri.lastIndexOf(File.separator);
+ return uri.substring(0, lastDelimiterIndex);
+ }
+
+ /**
+ * Extracts the ID of the object from uri of the OfficeObject.
+ *
+ * @param uri
+ * uri of the object
+ * @return ID of the object
+ */
+ public static String getIdFromUri(String uri) {
+ int lastDelimiterIndex = uri.lastIndexOf(File.separator);
+ return uri.substring(lastDelimiterIndex + 1);
+ }
+
+ /**
+ * Extracts the file-path from uri of the OfficeObject.
+ *
+ * @param uri
+ * uri of the object
+ * @return file-path of the file that contains the object
+ */
+ public static String getFilePathFromUri(String uri) {
+ int lastDelimiterIndex = uri.lastIndexOf(File.separator);
+ return uri.substring(0, lastDelimiterIndex);
+ }
+
+ /**
+ * Generates a uri given the file-path of the file that contains the object
+ * and an objectID
+ *
+ * @param officeFile
+ * File object containing the absolute file-path of the file that
+ * contains the object
+ * @param objectID
+ * ID of the object - usually its index in the file
+ *
+ * @return a uri of the object in the form of filePath/objectID
+ */
+ public static String createUri(File officeFile, Object objectId) {
+ return officeFile.getAbsolutePath() + File.separator + objectId;
+ }
+
+ /**
+ * Returns the description of the OfficeObject. If the description is too
+ * long, it limits the return value.
+ */
+ @Override
+ public String toString() {
+ int minAllowed = 30;
+ int dataLength = Math.min(data.length(), minAllowed);
+ if (dataLength == minAllowed)
+ return this.data.substring(0, dataLength) + "...";
+ else
+ return this.data;
+ }
+
+ /**
+ * Provides the hash code of the OfficeObject.
+ */
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((data == null) ? 0 : data.hashCode());
+ result = prime * result + ((uri == null) ? 0 : uri.hashCode());
+ return result;
+ }
+
+ /**
+ * Compares two instances of OfficeObject.
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ CapraOfficeObject other = (CapraOfficeObject) obj;
+ if (data == null) {
+ if (other.data != null)
+ return false;
+ } else if (!data.equals(other.data))
+ return false;
+ if (uri == null) {
+ if (other.uri != null)
+ return false;
+ } else if (!uri.equals(other.uri))
+ return false;
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/objects/CapraWordRequirement.java b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/objects/CapraWordRequirement.java
new file mode 100644
index 0000000..240f066
--- /dev/null
+++ b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/objects/CapraWordRequirement.java
@@ -0,0 +1,97 @@
+package org.eclipse.capra.ui.office.objects;
+
+import java.io.File;
+import java.io.StringReader;
+import java.util.Arrays;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.poi.xwpf.usermodel.XWPFParagraph;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+public class CapraWordRequirement extends CapraOfficeObject {
+
+ /**
+ * Start and end XML tags of MS Word field commands
+ */
+ private static final String wordFieldTag = "w:instrText";
+
+ /**
+ * Regex of characters to be replaced with white-spaces in the Office View.
+ */
+ private static final String replaceRegex = "[\r\n\t\\p{C}]+";
+
+ /**
+ * Regex of characters to be used as delimiters when splitting the field
+ * contents.
+ */
+ private static final String splitFieldRegex = "(\")|(\\\\\\*)";
+
+ /**
+ * The name of the requirement field as defined in Word.
+ */
+ // TODO define in properties?
+ private static final String fieldName = "REQ";
+
+ public CapraWordRequirement() {
+ super();
+ }
+
+ public CapraWordRequirement(String data, String uri) {
+ super(data, uri);
+ }
+
+ /**
+ * A constructor that generates a new instance of CapraWordRequirement where
+ * the parent properties are extracted from the provided Word paragraph and
+ * File object that contains containing the paragraph.
+ */
+ public CapraWordRequirement(XWPFParagraph paragraph, File officeFile, int objectID) {
+ // TODO This solution assumes that there is only one requirement per
+ // paragraph. Should it be different?
+
+ String rText = "";
+ String rId = "";
+
+ CTP pCtp = paragraph.getCTP();
+ Document doc;
+ try {
+ doc = loadXMLFromString(pCtp.toString());
+ } catch (Exception e) {
+ e.printStackTrace();
+ return;
+ }
+
+ NodeList nodeList = doc.getElementsByTagName(wordFieldTag);
+ if (nodeList.getLength() > 0) {
+ // TODO Use a for loop if the solution needs to parse multiple
+ // requirements in a single paragraph. In that case,
+ // paragraph.getText() should be replaced with something from the
+ // org.w3c.dom.Document class.
+ String[] parts = nodeList.item(0).getTextContent().split(splitFieldRegex);
+ if (Arrays.asList(parts).contains(fieldName) && parts.length > 2) {
+ rText = paragraph.getText();
+ rId = parts[2].trim();
+ }
+ }
+
+ rText = rText.replaceAll(replaceRegex, " ").trim();
+ if (!rText.isEmpty()) {
+ String pUri = CapraOfficeObject.createUri(officeFile, rId);
+
+ this.setData(rText);
+ this.setUri(pUri);
+ }
+ }
+
+ private Document loadXMLFromString(String xml) throws Exception {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ InputSource is = new InputSource(new StringReader(xml));
+ return builder.parse(is);
+ }
+}
diff --git a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/utils/OfficeTransferType.java b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/utils/OfficeTransferType.java
new file mode 100644
index 0000000..6b174c3
--- /dev/null
+++ b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/utils/OfficeTransferType.java
@@ -0,0 +1,168 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Chalmers | University of Gothenburg, rt-labs 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:
+ * Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+
+package org.eclipse.capra.ui.office.utils;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.eclipse.capra.ui.office.objects.CapraOfficeObject;
+import org.eclipse.swt.dnd.ByteArrayTransfer;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.TransferData;
+
+/**
+ * The OfficeTransferType object provides the logic necessary to drag and drop a
+ * non-native-java OfficeObject from one swt view (OfficeView) to another
+ * (SelectionView). It does that by extending the ByteArrayTransfer class and
+ * overriding the javaToNative and nativeToJava methods.
+ *
+ * Code adapted from IBM example at:
+ * http://www.java2s.com/Tutorial/Java/0280__SWT/DragandDropdefinemyowndatatransfertype.htm
+ *
+ * @author Dusan Kalanj
+ *
+ */
+public class OfficeTransferType extends ByteArrayTransfer {
+
+ private static final String MIME_TYPE = "capra_office";
+ private static final int MIME_TYPE_ID = registerType(MIME_TYPE);
+
+ private static OfficeTransferType _instance = new OfficeTransferType();
+
+ /** Provides an instance of the class. */
+ public static OfficeTransferType getInstance() {
+ return _instance;
+ }
+
+ @Override
+ protected int[] getTypeIds() {
+ return new int[] { MIME_TYPE_ID };
+ }
+
+ @Override
+ protected String[] getTypeNames() {
+ return new String[] { MIME_TYPE };
+ }
+
+ @Override
+ protected boolean validate(Object object) {
+ return checkMyType(object);
+ }
+
+ @SuppressWarnings("unchecked")
+ private boolean checkMyType(Object object) {
+ if (object == null || !(object instanceof ArrayList)) {
+ return false;
+ }
+
+ if (object instanceof ArrayList<?>) {
+ ArrayList<Object> objectList = (ArrayList<Object>) object;
+ if (!(objectList.get(0) instanceof CapraOfficeObject)) {
+ return false;
+ }
+ }
+
+ ArrayList<CapraOfficeObject> officeObjects = (ArrayList<CapraOfficeObject>) object;
+ if (officeObjects.isEmpty()) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /** Converts a java byte[] to a platform specific representation. */
+ @SuppressWarnings("unchecked")
+ @Override
+ public void javaToNative(Object object, TransferData transferData) {
+ if (!checkMyType(object) || !isSupportedType(transferData)) {
+ DND.error(DND.ERROR_INVALID_DATA);
+ }
+
+ ArrayList<CapraOfficeObject> officeObjects = (ArrayList<CapraOfficeObject>) object;
+
+ try {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ DataOutputStream writeOut = new DataOutputStream(out);
+
+ for (int i = 0; i < officeObjects.size(); i++) {
+ CapraOfficeObject currOfficeObject = officeObjects.get(i);
+
+ byte[] buffer = currOfficeObject.getData().getBytes();
+ writeOut.writeInt(buffer.length);
+ writeOut.write(buffer);
+
+ buffer = currOfficeObject.getUri().getBytes();
+ writeOut.writeInt(buffer.length);
+ writeOut.write(buffer);
+ }
+
+ byte[] bufferOut = out.toByteArray();
+ writeOut.close();
+
+ super.javaToNative(bufferOut, transferData);
+ } catch (IOException e) {
+
+ }
+ }
+
+ /**
+ * Converts a platform specific representation of a byte array to a java
+ * byte[].
+ */
+ @Override
+ public Object nativeToJava(TransferData transferData) {
+ if (isSupportedType(transferData)) {
+ byte[] buffer = (byte[]) super.nativeToJava(transferData);
+
+ if (buffer == null) {
+ return null;
+ }
+
+ ArrayList<CapraOfficeObject> officeObjects = new ArrayList<CapraOfficeObject>();
+
+ try {
+ ByteArrayInputStream in = new ByteArrayInputStream(buffer);
+ DataInputStream readIn = new DataInputStream(in);
+
+ while (readIn.available() > 0) {
+
+ CapraOfficeObject currOfficeObject = new CapraOfficeObject();
+
+ int size = readIn.readInt();
+ byte[] objectData = new byte[size];
+ readIn.read(objectData);
+
+ size = readIn.readInt();
+ byte[] objectUri = new byte[size];
+ readIn.read(objectUri);
+
+ currOfficeObject.setData(new String(objectData));
+ currOfficeObject.setUri(new String(objectUri));
+
+ officeObjects.add(currOfficeObject);
+ }
+ readIn.close();
+
+ } catch (IOException ex) {
+ return null;
+ }
+
+ return officeObjects;
+ }
+
+ return null;
+ }
+}
diff --git a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/views/OfficeView.java b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/views/OfficeView.java
new file mode 100644
index 0000000..e526eb2
--- /dev/null
+++ b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/views/OfficeView.java
@@ -0,0 +1,532 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Chalmers | University of Gothenburg, rt-labs 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:
+ * Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+
+package org.eclipse.capra.ui.office.views;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.poi.hssf.OldExcelFormatException;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.ss.usermodel.DataFormatter;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFParagraph;
+import org.apache.xmlbeans.SchemaTypeLoaderException;
+import org.eclipse.capra.ui.office.objects.CapraExcelRow;
+import org.eclipse.capra.ui.office.objects.CapraOfficeObject;
+import org.eclipse.capra.ui.office.objects.CapraWordRequirement;
+import org.eclipse.capra.ui.office.utils.OfficeTransferType;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.edit.ui.dnd.ViewerDragAdapter;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerDropAdapter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DragSourceEvent;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.dnd.TransferData;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.part.ViewPart;
+
+import com.google.common.io.Files;
+
+/**
+ * Provides a Capra perspective view for displaying the contents of Excel and
+ * Word documents. The view displays the contents if the user drags an Excel or
+ * a Word document into the surface.
+ *
+ * @author Dusan Kalanj
+ *
+ */
+public class OfficeView extends ViewPart {
+
+ /**
+ * The ID of the view as specified by the extension.
+ */
+ public static final String ID = "org.eclipse.capra.ui.views.OfficeView";
+
+ /**
+ * A constant that is used for checking whether the ID of the object is
+ * provided or not
+ */
+ public static final String OBJECT_ID_NOT_SPECIFIED = "-1";
+
+ /**
+ * The MS Office file-types that are supported by the plugin.
+ */
+ public static final String DOCX = "docx";
+ public static final String XLS = "xls";
+ public static final String XLSX = "xlsx";
+
+ /**
+ * This file-type is not supported, but is needed to display the correct
+ * error message.
+ */
+ public static final String DOC = "doc";
+
+ /**
+ * The actual view that contains the contents of the documents.
+ */
+ private TableViewer viewer;
+
+ /**
+ * The collection that contains the Excel/Word contents.
+ */
+ private ArrayList<Object> selection = new ArrayList<Object>();
+
+ /**
+ * The content provider class used by the view.
+ */
+ class ViewContentProvider implements IStructuredContentProvider {
+ @Override
+ public void inputChanged(Viewer v, Object oldInput, Object newInput) {
+ }
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ public Object[] getElements(Object parent) {
+ return selection.toArray();
+ }
+ }
+
+ /**
+ * The label provider class used by the view.
+ */
+ class ViewLabelProvider extends LabelProvider implements ITableLabelProvider {
+
+ @Override
+ public String getText(Object obj) {
+ return obj.toString();
+ };
+
+ @Override
+ public String getColumnText(Object obj, int index) {
+ return getText(obj);
+ }
+
+ @Override
+ public Image getColumnImage(Object obj, int index) {
+ return getImage(obj);
+ }
+
+ @Override
+ public Image getImage(Object obj) {
+ return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
+ }
+ }
+
+ /**
+ * Adapter used by the view to handle drop events.
+ */
+ class SelectionDropAdapter extends ViewerDropAdapter {
+
+ public SelectionDropAdapter(TableViewer viewer) {
+ super(viewer);
+ }
+
+ @Override
+ public boolean performDrop(Object data) {
+ dropToSelection(data);
+ return true;
+ }
+
+ @Override
+ public boolean validateDrop(Object target, int operation, TransferData transferType) {
+ return true;
+ }
+ }
+
+ /**
+ * Adapter used by the view to handle drag events.
+ */
+ class SelectionDragAdapter extends ViewerDragAdapter {
+
+ TableViewer viewer;
+
+ public SelectionDragAdapter(TableViewer viewer) {
+ super(viewer);
+ this.viewer = viewer;
+ }
+
+ @Override
+ public void dragSetData(DragSourceEvent event) {
+
+ if (OfficeTransferType.getInstance().isSupportedType(event.dataType)) {
+ TableItem[] items = viewer.getTable().getSelection();
+ ArrayList<CapraOfficeObject> officeObjects = new ArrayList<CapraOfficeObject>();
+
+ for (int i = 0; i < items.length; i++) {
+ officeObjects.add((CapraOfficeObject) items[i].getData());
+ }
+
+ event.data = officeObjects;
+ }
+ }
+ }
+
+ @Override
+ public void setFocus() {
+ viewer.getControl().setFocus();
+ }
+
+ @Override
+ public void createPartControl(Composite parent) {
+
+ viewer = new TableViewer(parent);
+ viewer.setContentProvider(new ViewContentProvider());
+ viewer.setLabelProvider(new ViewLabelProvider());
+ viewer.setInput(getViewSite());
+
+ getSite().setSelectionProvider(viewer);
+ hookContextMenu();
+
+ int ops = DND.DROP_COPY | DND.DROP_MOVE;
+ Transfer[] transfersIn = new Transfer[] { org.eclipse.swt.dnd.FileTransfer.getInstance() };
+ Transfer[] transfersOut = new Transfer[] { org.eclipse.capra.ui.office.utils.OfficeTransferType.getInstance() };
+
+ viewer.addDropSupport(ops, transfersIn, new SelectionDropAdapter(viewer));
+ viewer.addDragSupport(ops, transfersOut, new SelectionDragAdapter(viewer));
+ viewer.addDoubleClickListener(new IDoubleClickListener() {
+
+ @Override
+ public void doubleClick(DoubleClickEvent event) {
+ showObjectDetails(event, parent.getShell());
+ }
+ });
+ }
+
+ /**
+ * A method that is called when the user drags a file into the OfficeView.
+ * Its main task is to parse the dragged file and display its contents in
+ * the OfficeView. It only parses the file if it is of type xlsx, xls, or
+ * docx.
+ *
+ * @param data
+ * the object that was dragged into the view
+ */
+ public void dropToSelection(Object data) {
+
+ File officeFile = null;
+
+ if (data instanceof String[])
+ officeFile = new File(((String[]) data)[0]);
+
+ if (officeFile != null)
+ parseFile(officeFile, OBJECT_ID_NOT_SPECIFIED);
+ else
+ showMessage(viewer.getControl().getShell(), SWT.ERROR, "Error", "Not an Excel or Word file.");
+
+ viewer.refresh();
+ }
+
+ /**
+ * Calls the appropriate parse method (according to the file extension),
+ * which displays the data in the Office view.
+ *
+ * @param officeFile
+ * the File object that points to the file that is to be parsed
+ * @param objectID
+ * if provided, only the object with this ID will be displayed
+ */
+ private void parseFile(File officeFile, String objectID) {
+
+ String fileType = Files.getFileExtension(officeFile.getAbsolutePath());
+
+ if (fileType.equals(XLSX) || fileType.equals(XLS)) {
+ getOpenedView().clearSelection();
+ parseExcelDocument(officeFile, objectID);
+
+ } else if (fileType.equals(DOCX)) {
+ getOpenedView().clearSelection();
+ parseWordDocument(officeFile, objectID);
+
+ } else if (fileType.equals(DOC)) {
+ showMessage(viewer.getControl().getShell(), SWT.ERROR, "Error",
+ ".doc file format not supported, use .docx");
+
+ } else {
+ showMessage(viewer.getControl().getShell(), SWT.ERROR, "Error", "Not an Excel or Word file.");
+ }
+ }
+
+ /**
+ * Extracts the data from the Excel document and adds it to the view.
+ *
+ * @param officeFile
+ * the File object pointing to the Excel document that was
+ * dragged into the view.
+ * @param objectID
+ * the row ID; if "-1" (the value of constant
+ * OBJECT_ID_NOT_SPECIFIED), the whole document will print out,
+ * otherwise only the selected row
+ */
+ private void parseExcelDocument(File officeFile, String objectID) {
+
+ String fileType = Files.getFileExtension(officeFile.getAbsolutePath());
+ Sheet sheet;
+
+ try {
+ if (fileType.equals(XLSX)) {
+ sheet = new XSSFWorkbook(OPCPackage.open(officeFile)).getSheetAt(0);
+ } else {
+ sheet = new HSSFWorkbook(new FileInputStream(officeFile)).getSheetAt(0);
+ }
+ } catch (OldExcelFormatException e) {
+ showMessage(viewer.getControl().getShell(), SWT.ERROR, "Error", "This version of Excel is not supported.");
+ return;
+ } catch (Exception e) {
+ e.printStackTrace();
+ showMessage(viewer.getControl().getShell(), SWT.ERROR, "Error", "Couldn't open the file.");
+ return;
+ }
+
+ DataFormatter formatter = new DataFormatter();
+
+ getOpenedView().clearSelection();
+
+ // TODO Currently, the first block of code is only accessed
+ // if the method is triggered via OfficeHandler. Does this have to
+ // change if the handler is not allowed to have a dependency on UI?
+ // Also, the solution assumes that the location of the row is also the
+ // rowId, should that be different? Should the ID be defined, for
+ // example, in the first cell?
+ if (!objectID.equals(OBJECT_ID_NOT_SPECIFIED)) {
+ Row row = sheet.getRow(Integer.parseInt(objectID));
+ if (row != null) {
+ CapraExcelRow cRow = new CapraExcelRow(row, officeFile, formatter);
+
+ if (!cRow.getData().isEmpty())
+ selection.add(cRow);
+ }
+ } else {
+ for (int i = 0; i <= sheet.getLastRowNum(); i++) {
+ Row row = sheet.getRow(i);
+ if (row != null) {
+ CapraExcelRow cRow = new CapraExcelRow(row, officeFile, formatter);
+
+ if (!cRow.getData().isEmpty())
+ selection.add(cRow);
+ }
+ }
+ }
+ }
+
+ /**
+ * Extracts the data from the Word document and adds it to the view.
+ *
+ * @param officeFile
+ * the File object pointing of the Word document that was dragged
+ * into the view.
+ * @param objectID
+ * the paragraph/requirement ID; if "-1" (the value of constant
+ * OBJECT_ID_NOT_SPECIFIED), the whole document will print out,
+ * otherwise only the selected object
+ */
+ private void parseWordDocument(File officeFile, String objectID) {
+ List<XWPFParagraph> paragraphs;
+
+ try {
+ FileInputStream fs = new FileInputStream(officeFile);
+ // TODO The following line always triggers an exception!
+ XWPFDocument xwpfDoc = new XWPFDocument(fs);
+ paragraphs = (xwpfDoc).getParagraphs();
+ // If poi 3.15 is used, it allows closing the XWPFDocument. If 3.9
+ // is used it is not possible.
+ // xwpfDoc.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ showMessage(viewer.getControl().getShell(), SWT.ERROR, "Error", "Couldn't open the file.");
+ return;
+ } catch (SchemaTypeLoaderException e) {
+ // TODO This is the exception for the error!
+ e.printStackTrace();
+ showMessage(viewer.getControl().getShell(), SWT.ERROR, "Error", "Couldn't open the file.");
+ return;
+ }
+
+ for (int i = 0; i < paragraphs.size(); i++) {
+ XWPFParagraph paragraph = paragraphs.get(i);
+ if (paragraph != null) {
+ CapraWordRequirement cRequirement = new CapraWordRequirement(paragraph, officeFile, i);
+
+ // TODO Currently, this condition is only true if the method
+ // is triggered via OfficeHandler. Does this have to change
+ // if the handler is not allowed to have a dependency on UI?
+ if (!objectID.equals(OBJECT_ID_NOT_SPECIFIED)) {
+ if (cRequirement.getId().equals(objectID)) {
+ selection.add(cRequirement);
+ break;
+ }
+ } else if (!cRequirement.getData().isEmpty())
+ selection.add(cRequirement);
+ }
+ }
+ }
+
+ /**
+ * Shows only the selected OfficeObject in the Office Selection View.
+ *
+ * @param uri
+ * the uri of the row/word_requirement, containing the file path
+ * and the index of the row/word_requirement
+ */
+ public void showSingleOfficeObjectInOfficeView(String uri) {
+
+ if (uri.isEmpty())
+ return;
+
+ File officeFile = new File(CapraOfficeObject.getFilePathFromUri(uri));
+ String objectID = CapraOfficeObject.getIdFromUri(uri);
+
+ // Check if the file (still) exists.
+ if (officeFile.exists())
+ parseFile(officeFile, objectID);
+ else
+ showMessage(viewer.getControl().getShell(), SWT.ERROR, "Error", "Resource not found.");
+
+ viewer.refresh();
+ }
+
+ /**
+ * Shows the dialog with the information about the selected element in the
+ * view.
+ *
+ * @param event
+ * Should be of type DoubleClickEvent or ExecutionEvent, hold the
+ * event that triggered the request for details.
+ * @param parentShell
+ * Shell which will be the parent of the dialog window.
+ */
+ public void showObjectDetails(Object event, Shell parentShell) {
+
+ CapraOfficeObject officeObject;
+
+ if (event instanceof DoubleClickEvent) { // If called with double click
+ IStructuredSelection selection = (IStructuredSelection) ((DoubleClickEvent) event).getSelection();
+ officeObject = (CapraOfficeObject) selection.getFirstElement();
+
+ } else if (event instanceof ExecutionEvent) { // If called from menu
+ IStructuredSelection selection;
+
+ try {
+ selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked((ExecutionEvent) event);
+ officeObject = (CapraOfficeObject) selection.getFirstElement();
+ } catch (ExecutionException e) {
+ e.printStackTrace();
+ officeObject = null;
+ }
+ } else {
+ officeObject = null;
+ }
+
+ String caption;
+ String message;
+
+ if (officeObject == null) {
+ caption = "Notification";
+ message = "No information to show.";
+ } else {
+ caption = "Row " + officeObject.getId();
+ message = officeObject.getData();
+ }
+
+ showMessage(parentShell, SWT.OK, caption, message);
+ }
+
+ /**
+ * Clears the OfficeView.
+ */
+ public void clearSelection() {
+ selection.clear();
+ viewer.refresh();
+ }
+
+ /**
+ * Opens a file-chooser dialog and calls the parseFile method, which
+ * displays the contents of the selected file in the TableViewer (if the
+ * file is of type xlsx, xls or docx).
+ */
+ public void openFile() {
+
+ FileDialog fd = new FileDialog(viewer.getControl().getShell(), SWT.OK);
+ File officeFile = new File(fd.open());
+
+ parseFile(officeFile, OBJECT_ID_NOT_SPECIFIED);
+
+ viewer.refresh();
+ }
+
+ /**
+ * Provides the instance of the view.
+ *
+ * @return instance of the view.
+ */
+ public static OfficeView getOpenedView() {
+ try {
+ return (OfficeView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(ID);
+ } catch (PartInitException e) {
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+ private int showMessage(Shell parentShell, int style, String caption, String message) {
+ MessageBox dialog = new MessageBox(parentShell, style);
+ dialog.setText(caption);
+ dialog.setMessage(message);
+
+ return dialog.open();
+ }
+
+ private void hookContextMenu() {
+ MenuManager menuMgr = new MenuManager("#PopupMenu");
+ menuMgr.setRemoveAllWhenShown(true);
+ menuMgr.addMenuListener(new IMenuListener() {
+ public void menuAboutToShow(IMenuManager manager) {
+ }
+ });
+ Menu menu = menuMgr.createContextMenu(viewer.getControl());
+ viewer.getControl().setMenu(menu);
+ getSite().registerContextMenu(menuMgr, viewer);
+ }
+}
diff --git a/org.eclipse.capra.ui/META-INF/MANIFEST.MF b/org.eclipse.capra.ui/META-INF/MANIFEST.MF
index e7065ac..23086b0 100644
--- a/org.eclipse.capra.ui/META-INF/MANIFEST.MF
+++ b/org.eclipse.capra.ui/META-INF/MANIFEST.MF
@@ -22,7 +22,8 @@
org.eclipse.ui.ide;bundle-version="3.10.2",
org.eclipse.ui,
org.eclipse.core.resources,
- org.eclipse.capra.core
+ org.eclipse.capra.core,
+ org.eclipse.capra.ui.office
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.capra.ui.handlers,
org.eclipse.capra.ui.helpers,
diff --git a/pom.xml b/pom.xml
index d0eb887..b8f240e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -35,6 +35,7 @@
<module>org.eclipse.capra.handler.hudson</module>
<module>org.eclipse.capra.handler.jdt</module>
<module>org.eclipse.capra.handler.jdt.tests</module>
+ <module>org.eclipse.capra.handler.office</module>
<module>org.eclipse.capra.handler.mylyn</module>
<module>org.eclipse.capra.handler.papyrus</module>
<module>org.eclipse.capra.handler.reqIf</module>
@@ -46,6 +47,7 @@
<module>org.eclipse.capra.releng.p2</module>
<module>org.eclipse.capra.ui.cdt</module>
<module>org.eclipse.capra.ui.jdt</module>
+ <module>org.eclipse.capra.ui.office</module>
<module>org.eclipse.capra.ui.zest</module>
</modules>