PlantUML view now shows correct state of preferences in menu

The PlantUML view has a pull-down menu which allows to select several
options, including whether transitive links are shown or not. The
selected state is stored in the preferences. However, these options were
not yet visible in the toggle state of these options in the menu. With
this fix, the state of the options is now read from the preferences when
the view is initialised and the toggles are set correctly.

Change-Id: Id136063a0ca455cfae4e74f6081b693986c0e4d4
diff --git a/bundles/org.eclipse.capra.ui.plantuml/src/org/eclipse/capra/ui/plantuml/ToggleDisplayGraphHandler.java b/bundles/org.eclipse.capra.ui.plantuml/src/org/eclipse/capra/ui/plantuml/ToggleDisplayGraphHandler.java
index 00e9531..01b2ae3 100644
--- a/bundles/org.eclipse.capra.ui.plantuml/src/org/eclipse/capra/ui/plantuml/ToggleDisplayGraphHandler.java
+++ b/bundles/org.eclipse.capra.ui.plantuml/src/org/eclipse/capra/ui/plantuml/ToggleDisplayGraphHandler.java
@@ -41,13 +41,11 @@
 	/**
 	 * Checks whether the trace view is set to show a graph.
 	 * 
-	 * @return {@code true} if the graph view is enabled, {@code false}
-	 *         otherwise
+	 * @return {@code true} if the graph view is enabled, {@code false} otherwise
 	 */
 	public static boolean isDisplayGraph() {
 		Preferences graphDisplay = getPreference();
-
-		return graphDisplay.get("option", "graph").equals("matrix");
+		return graphDisplay.get("option", "graph").equals("graph");
 	}
 
 	private static Preferences getPreference() {
@@ -59,9 +57,8 @@
 	/**
 	 * Sets whether the trace view is set to show a graph or a matrix.
 	 * 
-	 * @param value
-	 *            {@code true} if the graph view is enabled, {@code false}
-	 *            otherwise
+	 * @param value {@code true} if the graph view is enabled, {@code false}
+	 *              otherwise
 	 * 
 	 */
 	public static void setDisplayGraph(boolean value) {
diff --git a/bundles/org.eclipse.capra.ui.plantuml/src/org/eclipse/capra/ui/plantuml/ToggleTransitivityHandler.java b/bundles/org.eclipse.capra.ui.plantuml/src/org/eclipse/capra/ui/plantuml/ToggleTransitivityHandler.java
index 54829df..845bc90 100644
--- a/bundles/org.eclipse.capra.ui.plantuml/src/org/eclipse/capra/ui/plantuml/ToggleTransitivityHandler.java
+++ b/bundles/org.eclipse.capra.ui.plantuml/src/org/eclipse/capra/ui/plantuml/ToggleTransitivityHandler.java
@@ -45,8 +45,7 @@
 	 */
 	public static boolean isTraceViewTransitive() {
 		Preferences transitivity = getPreference();
-
-		return transitivity.get("option", "direct").equals("direct");
+		return transitivity.get("option", "direct").equals("transitive");
 	}
 
 	private static Preferences getPreference() {
@@ -58,12 +57,11 @@
 	/**
 	 * Sets whether the trace view is set to show transitive traces.
 	 *
-	 * @param value
-	 *            indicates whether transitive traces should be shown
+	 * @param value indicates whether transitive traces should be shown
 	 */
 	public static void setTraceViewTransitive(boolean value) {
 		Preferences transitivity = getPreference();
-		transitivity.put("option", value ? "direct" : "transitive");
+		transitivity.put("option", value ? "transitive" : "direct");
 
 		try {
 			// forces the application to save the preferences
diff --git a/bundles/org.eclipse.capra.ui.plantuml/src/org/eclipse/capra/ui/plantuml/views/CapraPlantUmlView.java b/bundles/org.eclipse.capra.ui.plantuml/src/org/eclipse/capra/ui/plantuml/views/CapraPlantUmlView.java
index 478d039..0df9b3e 100644
--- a/bundles/org.eclipse.capra.ui.plantuml/src/org/eclipse/capra/ui/plantuml/views/CapraPlantUmlView.java
+++ b/bundles/org.eclipse.capra.ui.plantuml/src/org/eclipse/capra/ui/plantuml/views/CapraPlantUmlView.java
@@ -13,6 +13,12 @@
  *******************************************************************************/
 package org.eclipse.capra.ui.plantuml.views;
 
+import org.eclipse.capra.ui.plantuml.ToggleDisplayGraphHandler;
+import org.eclipse.capra.ui.plantuml.ToggleTransitivityHandler;
+import org.eclipse.core.commands.Command;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.commands.ICommandService;
+
 import net.sourceforge.plantuml.eclipse.views.PlantUmlView;
 
 /**
@@ -21,4 +27,19 @@
  */
 public class CapraPlantUmlView extends PlantUmlView {
 
+	@Override
+	public void createPartControl(final Composite parent) {
+		super.createPartControl(parent);
+		ICommandService cmdService = getSite().getService(ICommandService.class);
+		Command toggleTransitivity = cmdService.getCommand("org.eclipse.capra.ui.plantuml.toggleTransitivity");
+		if (toggleTransitivity != null) {
+			toggleTransitivity.getState("org.eclipse.ui.commands.toggleState")
+					.setValue(ToggleTransitivityHandler.isTraceViewTransitive());
+		}
+		Command displayGraph = cmdService.getCommand("org.eclipse.capra.ui.plantuml.displayGraph");
+		if (displayGraph != null) {
+			displayGraph.getState("org.eclipse.ui.commands.toggleState")
+					.setValue(ToggleDisplayGraphHandler.isDisplayGraph());
+		}
+	}
 }