diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java b/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java index 080eb6a453f4ad873556e1fe8ad92b1e50e07d0a..feb666df60918d5d31bf6c2400222f75655ce008 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java @@ -39,15 +39,22 @@ import org.cytoscape.view.presentation.RenderingEngineFactory; import org.cytoscape.view.vizmap.VisualMappingFunctionFactory; import org.cytoscape.view.vizmap.VisualMappingManager; import org.cytoscape.view.vizmap.VisualStyleFactory; +import org.cytoscape.work.TaskFactory; import org.cytoscape.work.swing.DialogTaskManager; import org.osgi.framework.BundleContext; + +import static org.cytoscape.work.ServiceProperties.COMMAND; +import static org.cytoscape.work.ServiceProperties.COMMAND_DESCRIPTION; + import de.hhu.ba.yoshikoWrapper.core.ConfigurationManager; import de.hhu.ba.yoshikoWrapper.core.CyCore; import de.hhu.ba.yoshikoWrapper.core.LocalizationManager; import de.hhu.ba.yoshikoWrapper.core.YoshUtil; import de.hhu.ba.yoshikoWrapper.core.YoshikoLoader; import de.hhu.ba.yoshikoWrapper.swing.components.MainPanel; +import de.hhu.ba.yoshikoWrapper.taskFactories.CommandTaskFactory; +import de.hhu.ba.yoshikoWrapper.taskFactories.YoshikoCommand; /** * Entry point for the application as required by the Cytoscape API @@ -55,13 +62,15 @@ import de.hhu.ba.yoshikoWrapper.swing.components.MainPanel; */ public class CyActivator extends AbstractCyActivator { + private static final String COMMAND_NAMESPACE = "yoshiko"; + public CyActivator() { super(); } @Override public void start(BundleContext context) throws Exception { - //Initialize cytoscape configuration system + //Initialize Cytoscape configuration system //This is responsible for saving/loading configuration ConfigurationManager cm = new ConfigurationManager("yoshikoWrapper", "yoshiko.props"); Properties propsReaderServiceProps = new Properties(); @@ -83,17 +92,18 @@ public class CyActivator extends AbstractCyActivator { CyCore.visualStyleFactory = getService(context,VisualStyleFactory.class); CyCore.continuousMappingFactory = getService(context,VisualMappingFunctionFactory.class, "(mapping.type=continuous)"); CyCore.rootNetworkManager = getService(context,CyRootNetworkManager.class); - //Not sure how to correctly infer arguments here + //TODO: Not sure how to correctly infer arguments here CyCore.renderingEngineFactory = getService(context,RenderingEngineFactory.class); CyCore.cloneNetworkTaskFactory = getService(context,CloneNetworkTaskFactory.class); - //Store a reference to the Version + //Store a reference to the Version for easier access YoshUtil.version = context.getBundle().getVersion(); //Set language according to settings -> Default to enUS LocalizationManager.switchLanguage(cm.getProperties().getProperty("locale", "enUS")); - //Attempt to find the yoshiko lib in a previously stored location and load it + //Attempt to find the Yoshiko lib in a previously stored location and load it + //TODO: Move into a separate handler to keep CyActivator clean if (!YoshikoLoader.isLibraryLoaded()){ String pathToYosh = cm.getProperties().getProperty("pathToYoshiko"); if (pathToYosh != null && pathToYosh != "null") { @@ -101,12 +111,20 @@ public class CyActivator extends AbstractCyActivator { } } + //Register commands / CyRest + + TaskFactory commandTaskFactory = new CommandTaskFactory(YoshikoCommand.PERFORM_ALGORITHM); + Properties props = new Properties(); + props.setProperty(COMMAND_NAMESPACE, "yoshiko"); + props.setProperty(COMMAND, YoshikoCommand.PERFORM_ALGORITHM.toString()); + props.setProperty(COMMAND_DESCRIPTION,"TEST PERFORM ALGORITHM"); + registerService(context, commandTaskFactory, TaskFactory.class, props); + + //Initialize and register main panel MainPanel mainPanel = new MainPanel(); registerService(context,mainPanel,CytoPanelComponent.class, new Properties()); - } - -} +} \ No newline at end of file diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/LanguageSwitcherPanelFactory.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/LanguageSwitcherPanel.java similarity index 81% rename from src/main/java/de/hhu/ba/yoshikoWrapper/swing/LanguageSwitcherPanelFactory.java rename to src/main/java/de/hhu/ba/yoshikoWrapper/swing/LanguageSwitcherPanel.java index 0d408884c60bdd98e28eb9a5f0046d3931a530ab..1b175e4f3eaf153c37fb3700e858bfe7eeab9aa7 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/LanguageSwitcherPanelFactory.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/LanguageSwitcherPanel.java @@ -1,16 +1,16 @@ /******************************************************************************* * Copyright (C) 2017 Philipp Spohr - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -29,19 +29,21 @@ import org.cytoscape.util.swing.BasicCollapsiblePanel; import de.hhu.ba.yoshikoWrapper.core.LocalizationManager; import de.hhu.ba.yoshikoWrapper.swing.components.LanguageSwitcher; -public class LanguageSwitcherPanelFactory{ - - public static BasicCollapsiblePanel createLanguageSwitcherPanel() { +@SuppressWarnings("serial") +public class LanguageSwitcherPanel extends BasicCollapsiblePanel{ + + + public LanguageSwitcherPanel() { + super(LocalizationManager.get("switchLanguage")); final LanguageSwitcher switcher; - final BasicCollapsiblePanel ret = new BasicCollapsiblePanel(LocalizationManager.get("switchLanguage")); - ret.getContentPane().setLayout(new BoxLayout(ret.getContentPane(),BoxLayout.X_AXIS)); + //final BasicCollapsiblePanel ret = new BasicCollapsiblePanel(); + getContentPane().setLayout(new BoxLayout(getContentPane(),BoxLayout.X_AXIS)); //SWING COMPONENTS INIT switcher = new LanguageSwitcher(); - - SwingUtil.addAll(ret, + + SwingUtil.addAll(this, switcher ); - return ret; } } diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ColumnMapper.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ColumnMapper.java index 859de27bf79a3fa30253e804ec57cf5999439131..ada41217a66d5f9c8265426c933e1cbb47e5997e 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ColumnMapper.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ColumnMapper.java @@ -44,6 +44,11 @@ import de.hhu.ba.yoshikoWrapper.core.CyCore; import de.hhu.ba.yoshikoWrapper.swing.EnableWhenSelectedListener; import de.hhu.ba.yoshikoWrapper.swing.SwingUtil; +/** + * + * @author Philipp Spohr, Nov 30, 2017 + * + */ @SuppressWarnings("serial") //will never be serialized public class ColumnMapper extends JPanel implements //everything @@ -208,24 +213,36 @@ SetCurrentNetworkListener @Override public void handleEvent(ColumnDeletedEvent e) { - if ( - e.getSource() == CyCore.cy.getCurrentNetwork().getDefaultEdgeTable() || - e.getSource() == CyCore.cy.getCurrentNetwork().getDefaultNetworkTable() - ) - { - updateValues(); + try { + if ( + e.getSource() == CyCore.cy.getCurrentNetwork().getDefaultEdgeTable() || + e.getSource() == CyCore.cy.getCurrentNetwork().getDefaultNetworkTable() + ) + { + updateValues(); + } + } + catch (Exception ex) { + //TODO: } + } @Override public void handleEvent(ColumnCreatedEvent e) { - if ( - e.getSource() == CyCore.cy.getCurrentNetwork().getDefaultEdgeTable() || - e.getSource() == CyCore.cy.getCurrentNetwork().getDefaultNetworkTable() - ) - { - updateValues(); + try { + if ( + e.getSource() == CyCore.cy.getCurrentNetwork().getDefaultEdgeTable() || + e.getSource() == CyCore.cy.getCurrentNetwork().getDefaultNetworkTable() + ) + { + updateValues(); + } + } + catch (Exception ex) { + //TODO: } + } public CyColumn getEditingCostColumn() { diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/MainPanel.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/MainPanel.java index 54063d36c3689abec64f5158236e10d21667b806..5a5289a1e143f89a8ff491cec91f943bed282ef8 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/MainPanel.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/MainPanel.java @@ -59,7 +59,7 @@ import de.hhu.ba.yoshikoWrapper.core.ParameterSet; import de.hhu.ba.yoshikoWrapper.core.YoshikoLoader; import de.hhu.ba.yoshikoWrapper.swing.AboutDialogFactory; import de.hhu.ba.yoshikoWrapper.swing.GraphicsLoader; -import de.hhu.ba.yoshikoWrapper.swing.LanguageSwitcherPanelFactory; +import de.hhu.ba.yoshikoWrapper.swing.LanguageSwitcherPanel; import de.hhu.ba.yoshikoWrapper.swing.LibraryPanelFactory; import de.hhu.ba.yoshikoWrapper.swing.SwingUtil; import de.hhu.ba.yoshikoWrapper.tasks.AlgorithmTask; @@ -125,7 +125,7 @@ public class MainPanel extends JPanel implements CytoPanelComponent { scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setBorder(BorderFactory.createEmptyBorder()); - langPanel = LanguageSwitcherPanelFactory.createLanguageSwitcherPanel(); + langPanel = new LanguageSwitcherPanel(); libraryPanel = LibraryPanelFactory.createLibraryPanel(); //If no library is loaded yet the obvious panel should be showing up diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/taskFactories/CommandTaskFactory.java b/src/main/java/de/hhu/ba/yoshikoWrapper/taskFactories/CommandTaskFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..8d17d1bb0ff85c60a6d059de43180ac2ef2210f4 --- /dev/null +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/taskFactories/CommandTaskFactory.java @@ -0,0 +1,43 @@ +package de.hhu.ba.yoshikoWrapper.taskFactories; + +import org.cytoscape.work.AbstractTaskFactory; +import org.cytoscape.work.TaskIterator; + +import de.hhu.ba.yoshikoWrapper.tasks.AlgorithmTask; + +public class CommandTaskFactory extends AbstractTaskFactory{ + + private final YoshikoCommand command; + + /** + * Default constructor + */ + public CommandTaskFactory(YoshikoCommand command) { + super(); + this.command = command; + } + + @Override + public TaskIterator createTaskIterator() { + //We simply switch between the possible commands + if (command == YoshikoCommand.CREATE_CLUSTER_VIEW) { + return null; + } + else if (command == YoshikoCommand.CREATE_META_GRAPH) { + return null; + } + else if (command == YoshikoCommand.PERFORM_ALGORITHM) { + return new TaskIterator( + new AlgorithmTask( + null, + null, + null + ) + ); + } + else return null; //TODO: Might be useful to generate an error/ throw an exception here as this should never be invoked + } + + + public boolean isReady () { return true; } //TODO: Think about when that would actually make sense / prevent launching of multiple tasks +} diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/taskFactories/YoshikoCommand.java b/src/main/java/de/hhu/ba/yoshikoWrapper/taskFactories/YoshikoCommand.java new file mode 100644 index 0000000000000000000000000000000000000000..0a964ecd2d1a98ee7f11490def7ea976b7a41ad7 --- /dev/null +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/taskFactories/YoshikoCommand.java @@ -0,0 +1,15 @@ +package de.hhu.ba.yoshikoWrapper.taskFactories; + +/** + * Describes commands for the Yoshiko App that can be invoked via REST/CyREST + * @author Philipp Spohr, Nov 30, 2017 + * + */ +public enum YoshikoCommand { + /** + * Creates a CV for a given Cluster found in a result + */ + CREATE_CLUSTER_VIEW, + CREATE_META_GRAPH, + PERFORM_ALGORITHM +} diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/taskFactories/package-info.java b/src/main/java/de/hhu/ba/yoshikoWrapper/taskFactories/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..2058a2032e2915e38793c91ab64dfd263e7af57a --- /dev/null +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/taskFactories/package-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * @author Philipp Spohr, Nov 30, 2017 + * + */ +package de.hhu.ba.yoshikoWrapper.taskFactories; \ No newline at end of file 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 fbe450f777d3eb576cdf6c36fe80bc9417b6a007..70568cf9914887ce8537afca0e515923153f85e2 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/AlgorithmTask.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/AlgorithmTask.java @@ -32,6 +32,7 @@ import org.cytoscape.model.CyNetwork; import org.cytoscape.model.CyNode; import org.cytoscape.work.AbstractTask; import org.cytoscape.work.TaskMonitor; +import org.cytoscape.work.Tunable; import org.slf4j.Logger; import de.hhu.ba.yoshikoWrapper.core.CyCore; @@ -54,17 +55,23 @@ import de.hhu.ba.yoshikoWrapper.swing.components.ResultPanel; public class AlgorithmTask extends AbstractTask { - private String SOLUTION_COLUMN_PREFIX = "yoshikoSolution_"; + //Constants + private static final String SOLUTION_COLUMN_PREFIX = "yoshikoSolution_"; //TODO: Make customizable? //Symbolic links private static Logger logger = YoshikoLogger.getInstance().getLogger(); - private Window statusWindow; + + + private final Window statusWindow; //TODO: Make tunable? //Parameters + @Tunable(description="Parameter Set determining the operation mode for Yoshiko", context="nogui") private final ParameterSet parameterSet; + + @Tunable(description="Network to analyze for clusters", context="nogui") private final CyNetwork net; - //Temps, need to be freed in C++ + //Temps, pointing to and need to be freed in C++ private LibraryInput input; private ClusterEditingSolutions result; private CoreAlgorithm ca; diff --git a/src/main/resources/yoshiko b/src/main/resources/yoshiko.props similarity index 100% rename from src/main/resources/yoshiko rename to src/main/resources/yoshiko.props