From 335c02422ae7519eabafbfef53ddf781b798a215 Mon Sep 17 00:00:00 2001 From: Philipp Spohr <spohr.philipp@web.de> Date: Mon, 5 Mar 2018 12:34:22 +0100 Subject: [PATCH] Changed column mapping parameters to Cytoscape ListSingleSelection -> easier and more intuitive for automation users Updated some license headers --- .../ba/yoshikoWrapper/core/ParameterSet.java | 107 +++++++++++++++++- .../yoshikoWrapper/cytoUtil/StyleManager.java | 2 +- .../hhu/ba/yoshikoWrapper/help/HelpLinks.java | 2 +- .../ba/yoshikoWrapper/swing/SwingUtil.java | 2 +- .../swing/components/MainPanel.java | 6 +- .../swing/components/SolutionTab.java | 2 +- .../yoshikoWrapper/tasks/AlgorithmTask.java | 6 +- 7 files changed, 113 insertions(+), 14 deletions(-) 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 ce7fbd1..1ae45b2 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/core/ParameterSet.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/core/ParameterSet.java @@ -1,12 +1,36 @@ +/******************************************************************************* + * Copyright (C) 2018 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 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + ******************************************************************************/ + package de.hhu.ba.yoshikoWrapper.core; import java.io.IOException; +import java.util.ArrayList; import org.cytoscape.model.CyColumn; import org.cytoscape.model.CyNetwork; import org.cytoscape.work.Tunable; import org.cytoscape.work.TunableValidator; +import org.cytoscape.work.util.ListSingleSelection; public class ParameterSet implements TunableValidator { @@ -16,13 +40,15 @@ public class ParameterSet implements TunableValidator @Tunable(description="Time Limit for the ILP mode", context="nogui") public int timeLimit = -1; + + //COLUMN-MAPPINGS @Tunable(description="A column in the edge table containing weights", context="nogui") - public String weightColumnName; + public ListSingleSelection<String> weightColumnName = null; @Tunable(description="A column containing boolean entries for edges that are to be treated as permanent",context="nogui") - public String permanentColumnName; + public ListSingleSelection<String> permanentColumnName = null; @Tunable(description="A column containing boolean entries for edges that are to be treated as forbidden",context="nogui") - public String forbiddenColumnName; + public ListSingleSelection<String> forbiddenColumnName = null; @Tunable(description="The default insertion cost that is to be used for non-existing edges",context="nogui") public double defaultInsertionCost = -1; @@ -54,6 +80,33 @@ public class ParameterSet implements TunableValidator @Tunable(description="Determines the number of clusters that are to be generated. -1 generates the optimal amount of clusters in the sense of WCE",context="nogui") public int clusterCount = -1; + + /** + * Default constructor, initializes the column mappings to provide a selection of fitting columns + */ + public ParameterSet() { + + ArrayList<String> columnNames = new ArrayList<String>(); + + //Only numeric columns are relevant for weight mapping + for (CyColumn col : net.getDefaultEdgeTable().getColumns()) { + if (Number.class.isAssignableFrom(col.getType())) { + columnNames.add(col.getName()); + } + } + weightColumnName = new ListSingleSelection<String>(columnNames); + + columnNames = new ArrayList<String>(); + + //Only boolean columns are relevant for forbidden/permanent mapping + for (CyColumn col : net.getDefaultEdgeTable().getColumns()) { + if (col.getType() == Boolean.class) { + columnNames.add(col.getName()); + } + } + forbiddenColumnName = new ListSingleSelection<String>(columnNames); + permanentColumnName = new ListSingleSelection<String>(columnNames); + } @Override public ValidationState getValidationState(Appendable errMsg) { @@ -61,7 +114,7 @@ public class ParameterSet implements TunableValidator try { if (net!= null) { //Verify column validity - CyColumn weightColumn = net.getDefaultEdgeTable().getColumn(weightColumnName); + CyColumn weightColumn = net.getDefaultEdgeTable().getColumn(weightColumnName.getSelectedValue()); if (weightColumn == null) { errMsg.append("Could not find a column named: "+weightColumnName+"\n"); return ValidationState.INVALID; @@ -108,5 +161,51 @@ public class ParameterSet implements TunableValidator //TODO return ret; } + + //SETTER & GETTER + + //TODO: Code Redundancy, might be smart to insert the three columns into some sort of super structure and then remove the redundant setters/getters, pass column type as argument + + public void setWeightColumnName(String columnName) { + if (weightColumnName.getPossibleValues().contains(columnName)) { + weightColumnName.setSelectedValue(columnName); + } + else { + //Attempting to set a column that is not part of the possible values + //TODO: Output debug/warning if Cytoscape logger will eventually work + } + } + + public void setPermanentColumnName(String columnName) { + if (permanentColumnName.getPossibleValues().contains(columnName)) { + permanentColumnName.setSelectedValue(columnName); + } + else { + //Attempting to set a column that is not part of the possible values + //TODO: Output debug/warning if Cytoscape logger will eventually work + } + } + + public void setForbiddenColumnName(String columnName) { + if (forbiddenColumnName.getPossibleValues().contains(columnName)) { + forbiddenColumnName.setSelectedValue(columnName); + } + else { + //Attempting to set a column that is not part of the possible values + //TODO: Output debug/warning if Cytoscape logger will eventually work + } + } + + public String getWeightColumnName() { + return weightColumnName.getSelectedValue(); + } + + public String getPermanentColumnName() { + return permanentColumnName.getSelectedValue(); + } + + public String getForbiddenColumnName() { + return forbiddenColumnName.getSelectedValue(); + } } diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/cytoUtil/StyleManager.java b/src/main/java/de/hhu/ba/yoshikoWrapper/cytoUtil/StyleManager.java index 48c8d13..65d7e79 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/cytoUtil/StyleManager.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/cytoUtil/StyleManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (C) 2017 Philipp Spohr + * Copyright (C) 2018 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 diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/help/HelpLinks.java b/src/main/java/de/hhu/ba/yoshikoWrapper/help/HelpLinks.java index d96a9c8..04fde39 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/help/HelpLinks.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/help/HelpLinks.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (C) 2017 Philipp Spohr + * Copyright (C) 2018 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 diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/SwingUtil.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/SwingUtil.java index 003518e..7310c61 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/SwingUtil.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/SwingUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (C) 2017 Philipp Spohr + * Copyright (C) 2018 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 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 5fc0e50..e48efbf 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 @@ -346,9 +346,9 @@ public class MainPanel extends JPanel implements CytoPanelComponent { ParameterSet ret = new ParameterSet(); ret.net = net; ret.timeLimit = opModePanel.getTimeLimit(); - ret.weightColumnName = ecPanel.getWeightColumnName(); - ret.permanentColumnName = ecPanel.getPermanentColumnName(); - ret.forbiddenColumnName = ecPanel.getForbiddenColumnName(); + ret.setWeightColumnName(ecPanel.getWeightColumnName()); + ret.setPermanentColumnName(ecPanel.getPermanentColumnName()); + ret.setForbiddenColumnName(ecPanel.getForbiddenColumnName()); ret.defaultInsertionCost = ecPanel.getDefaultInsertionCost(); ret.defaultDeletionCost = ecPanel.getDefaultDeletionCost(); ret.useHeuristic = opModePanel.useHeuristic(); diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/SolutionTab.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/SolutionTab.java index 83a7ef3..e6fd5b2 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/SolutionTab.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/SolutionTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (C) 2017 Philipp Spohr + * Copyright (C) 2018 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 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 bf314c9..52d75a3 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/AlgorithmTask.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/AlgorithmTask.java @@ -132,9 +132,9 @@ public class AlgorithmTask extends AbstractTask implements ObservableTask, Tunab taskMonitor.setProgress(0.1); //We identify the columns if they exist from their given names - CyColumn weightColumn = parameterSet.weightColumnName != null ? parameterSet.net.getDefaultEdgeTable().getColumn(parameterSet.weightColumnName) : null; - CyColumn permanentColumn = parameterSet.permanentColumnName != null ? parameterSet.net.getDefaultEdgeTable().getColumn(parameterSet.permanentColumnName) : null; - CyColumn forbiddenColumn = parameterSet.forbiddenColumnName != null ? parameterSet.net.getDefaultEdgeTable().getColumn(parameterSet.forbiddenColumnName) : null; + CyColumn weightColumn = parameterSet.getWeightColumnName() != null ? parameterSet.net.getDefaultEdgeTable().getColumn(parameterSet.getWeightColumnName()) : null; + CyColumn permanentColumn = parameterSet.permanentColumnName != null ? parameterSet.net.getDefaultEdgeTable().getColumn(parameterSet.getPermanentColumnName()) : null; + CyColumn forbiddenColumn = parameterSet.forbiddenColumnName != null ? parameterSet.net.getDefaultEdgeTable().getColumn(parameterSet.getForbiddenColumnName()) : null; //Generate an c_input instance from the network c_input = NetworkParser.parseNetwork( -- GitLab