From 7e53598d927ebbfff87e01e114e0c4887acfee69 Mon Sep 17 00:00:00 2001
From: Philipp Spohr <spohr.philipp@web.de>
Date: Mon, 4 Dec 2017 11:32:14 +0100
Subject: [PATCH] Fix for reloading app on the fly / hotswapping

---
 .../de/hhu/ba/yoshikoWrapper/CyActivator.java   |  1 -
 .../ba/yoshikoWrapper/core/ParameterSet.java    |  9 +++++++--
 .../ba/yoshikoWrapper/core/YoshikoLoader.java   | 13 ++++++++-----
 .../swing/LanguageSwitcherPanel.java            |  2 +-
 .../taskFactories/YoshikoCommand.java           | 12 +++++++++++-
 .../ba/yoshikoWrapper/tasks/AlgorithmTask.java  | 17 ++++++++++++++---
 .../tasks/CreateClusterViews.java               |  6 +++---
 7 files changed, 44 insertions(+), 16 deletions(-)

diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java b/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java
index 63a875a..1652fed 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java
@@ -117,7 +117,6 @@ public class CyActivator extends AbstractCyActivator {
 		props.setProperty(COMMAND, YoshikoCommand.PERFORM_ALGORITHM.toString());
 		props.setProperty(COMMAND_DESCRIPTION,"TEST PERFORM ALGORITHM");
 		registerService(context, commandTaskFactory, TaskFactory.class, props);
-		System.out.println(props.toString());
 
 		//Initialize and register main panel
 		MainPanel mainPanel = new MainPanel();
diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/core/ParameterSet.java b/src/main/java/de/hhu/ba/yoshikoWrapper/core/ParameterSet.java
index f74c050..87da79a 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/core/ParameterSet.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/core/ParameterSet.java
@@ -1,11 +1,16 @@
 package de.hhu.ba.yoshikoWrapper.core;
 
+
 import org.cytoscape.model.CyColumn;
+import org.cytoscape.work.Tunable;
 
 public class ParameterSet {
 
-	public int timeLimit;
+	@Tunable(description="Time Limit for the ILP mode", context="nogui")
+	public int timeLimit = -1;
+	@Tunable(description="A column in the edge table containing weights", context="nogui")
 	public CyColumn weightColumn;
+
 	public CyColumn permanentColumn;
 	public CyColumn forbiddenColumn;
 	public double defaultInsertionCost;
@@ -17,5 +22,5 @@ public class ParameterSet {
 	public boolean useHeuristic;
 	public int solCount;
 	public boolean disableMultiThreading;
-	
+
 }
diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/core/YoshikoLoader.java b/src/main/java/de/hhu/ba/yoshikoWrapper/core/YoshikoLoader.java
index 4a970c0..1eec501 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/core/YoshikoLoader.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/core/YoshikoLoader.java
@@ -39,7 +39,6 @@ public class YoshikoLoader {
 	private static Logger logger = YoshikoLogger.getInstance().getLogger();
 
 	public static void loadLibrary(String libPath) {
-
 		//Attempt to load from a previously stored path
 		File f = new File (libPath);
 		if (!f.exists()) {
@@ -49,15 +48,19 @@ public class YoshikoLoader {
 
 		try {
 			logger.info("Attempting to load library @: "+libPath);
+			//Verify version ending
 			if (!libPath.substring(0,libPath.lastIndexOf(".")).endsWith(REQUIRED_VERSION)) {
-				throw new Exception(LocalizationManager.get("libFail")+" "+REQUIRED_VERSION);
+				logger.info(LocalizationManager.get("libFail")+" "+REQUIRED_VERSION);
+				return;
 			}
+			//Perform actual loading
 			System.load(libPath);
+
 		}
-		catch(Exception e) {
+		catch(UnsatisfiedLinkError e) {
+			//This might happen as Java doesn't unload native libs
+			//One such case might be reloading the Cytoscape app on-the-fly
 			logger.error(e.getMessage());
-			logger.info(LocalizationManager.get("libFail")+" "+REQUIRED_VERSION);
-
 			return;
 		}
 		LibraryInterface.setVerbosity(3);
diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/LanguageSwitcherPanel.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/LanguageSwitcherPanel.java
index 1b175e4..8848647 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/LanguageSwitcherPanel.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/LanguageSwitcherPanel.java
@@ -37,7 +37,7 @@ public class LanguageSwitcherPanel extends BasicCollapsiblePanel{
 		super(LocalizationManager.get("switchLanguage"));
 		final LanguageSwitcher switcher;
 		//final BasicCollapsiblePanel ret = new BasicCollapsiblePanel();
-		getContentPane().setLayout(new BoxLayout(getContentPane(),BoxLayout.X_AXIS));
+		//getContentPane().setLayout(new BoxLayout(getContentPane(),BoxLayout.X_AXIS));
 		//SWING COMPONENTS INIT
 		switcher = new LanguageSwitcher();
 
diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/taskFactories/YoshikoCommand.java b/src/main/java/de/hhu/ba/yoshikoWrapper/taskFactories/YoshikoCommand.java
index 0a964ec..8125643 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/taskFactories/YoshikoCommand.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/taskFactories/YoshikoCommand.java
@@ -11,5 +11,15 @@ public enum YoshikoCommand {
 	 */
 	CREATE_CLUSTER_VIEW,
 	CREATE_META_GRAPH,
-	PERFORM_ALGORITHM
+	PERFORM_ALGORITHM;
+
+	@Override
+	public String toString() {
+		if (this==PERFORM_ALGORITHM) {
+			return "cluster"; //TODO: Dynamic
+		}
+		return "null";
+	}
 }
+
+
diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/AlgorithmTask.java b/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/AlgorithmTask.java
index c3a0af7..80bc8ae 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/AlgorithmTask.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/AlgorithmTask.java
@@ -31,6 +31,7 @@ import org.cytoscape.application.swing.CytoPanelState;
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyNode;
 import org.cytoscape.work.AbstractTask;
+import org.cytoscape.work.ContainsTunables;
 import org.cytoscape.work.TaskMonitor;
 import org.cytoscape.work.Tunable;
 import org.slf4j.Logger;
@@ -65,11 +66,15 @@ public class AlgorithmTask extends AbstractTask {
 	private final Window statusWindow; //TODO: Make tunable?
 
 	//Parameters
-	@Tunable(description="Parameter Set determining the operation mode for Yoshiko", context="nogui")
-	private final ParameterSet parameterSet;
+
+	/**The ParameterSet specifying how the algorithm is to be performed
+	 *
+	 */
+	@ContainsTunables
+	public ParameterSet parameterSet = null;
 
 	@Tunable(description="Network to analyze for clusters", context="nogui")
-	private final CyNetwork net;
+	public CyNetwork net;
 
 	//Temps, pointing to and need to be freed in C++
 	private LibraryInput input;
@@ -78,6 +83,12 @@ public class AlgorithmTask extends AbstractTask {
 
 	private ResultPanel resultPanel;
 
+	/**
+	 * Default constructor, creates a new AlgorithmTask
+	 * @param statusWindow The Window in which the status-bar is to be shown, can be null
+	 * @param net The network that is to be clustered
+	 * @param parameterSet The parameter set specifying the clustering mode
+	 */
 	public AlgorithmTask(
 			Window statusWindow,
 			CyNetwork net,
diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/CreateClusterViews.java b/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/CreateClusterViews.java
index 103d03c..a5674a7 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/CreateClusterViews.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/CreateClusterViews.java
@@ -10,6 +10,7 @@ import org.cytoscape.work.ObservableTask;
 import org.cytoscape.work.Task;
 import org.cytoscape.work.TaskMonitor;
 import org.cytoscape.work.TaskObserver;
+import org.cytoscape.work.Tunable;
 
 import de.hhu.ba.yoshikoWrapper.core.CyCore;
 import de.hhu.ba.yoshikoWrapper.core.LocalizationManager;
@@ -18,9 +19,8 @@ import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoCluster;
 
 public class CreateClusterViews implements Task {
 
-	//TODO: Merge redundant code with CreateMetaGraphTask
-
-	private ArrayList<YoshikoCluster> clusters;
+	@Tunable
+	public ArrayList<YoshikoCluster> clusters;
 
 	private boolean isTerminated;
 
-- 
GitLab