Commit 034606c6 authored by Philipp Spohr's avatar Philipp Spohr
Browse files

Some work on making CyColumns tunable via their name

parent f8d44b69
......@@ -20,9 +20,9 @@ public class ParameterSet implements TunableValidator
@Tunable(description="A column in the edge table containing weights", context="nogui")
public String weightColumnName;
@Tunable(description="A column containing boolean entries for edges that are to be treated as permanent",context="nogui")
public CyColumn permanentColumn;
public String permanentColumnName;
@Tunable(description="A column containing boolean entries for edges that are to be treated as forbidden",context="nogui")
public CyColumn forbiddenColumn;
public String forbiddenColumnName;
@Tunable(description="The default insertion cost that is to be used for non-existing edges",context="nogui")
public double defaultInsertionCost = -1;
......
......@@ -60,7 +60,7 @@ SetCurrentNetworkListener
{
//Swing components
private final JComboBox<CyColumn> editingCostMapper;
private final JComboBox<CyColumn> weightMapper;
private final JComboBox<CyColumn> permanentMapper;
private final JComboBox<CyColumn> forbiddenMapper;
......@@ -79,12 +79,12 @@ SetCurrentNetworkListener
//SWING COMPONENTS
//Combo-Boxes that map to the CyColumns
editingCostMapper = new JComboBox<CyColumn>();
weightMapper = new JComboBox<CyColumn>();
permanentMapper = new JComboBox<CyColumn>();
forbiddenMapper = new JComboBox<CyColumn>();
//Should only be enabled if the option is checked
editingCostMapper.setEnabled(false);
weightMapper.setEnabled(false);
permanentMapper.setEnabled(false);
forbiddenMapper.setEnabled(false);
......@@ -93,7 +93,7 @@ SetCurrentNetworkListener
useMappingForb = new JCheckBox("Map edges as forbidden");
useMappingCost.addActionListener(
new EnableWhenSelectedListener(useMappingCost, editingCostMapper)
new EnableWhenSelectedListener(useMappingCost, weightMapper)
);
useMappingPerm.addActionListener(
new EnableWhenSelectedListener(useMappingPerm, permanentMapper)
......@@ -103,7 +103,7 @@ SetCurrentNetworkListener
);
SwingUtil.addAll(this,useMappingCost,editingCostMapper);
SwingUtil.addAll(this,useMappingCost,weightMapper);
SwingUtil.addAll(this,useMappingPerm,permanentMapper);
SwingUtil.addAll(this,useMappingForb,forbiddenMapper);
......@@ -117,7 +117,7 @@ SetCurrentNetworkListener
.addComponent(useMappingForb)
)
.addGroup(layout.createParallelGroup(Alignment.LEADING)
.addComponent(editingCostMapper)
.addComponent(weightMapper)
.addComponent(permanentMapper)
.addComponent(forbiddenMapper)
)
......@@ -127,7 +127,7 @@ SetCurrentNetworkListener
layout.setVerticalGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup()
.addComponent(useMappingCost)
.addComponent(editingCostMapper)
.addComponent(weightMapper)
)
.addGroup(layout.createParallelGroup()
.addComponent(useMappingPerm)
......@@ -153,18 +153,18 @@ SetCurrentNetworkListener
if (net != null) { //Check if a network is loaded
//Clear entries
editingCostMapper.removeAllItems();
weightMapper.removeAllItems();
for (CyColumn c : net.getDefaultEdgeTable().getColumns()){
//Only add columns with numeric values
if (c.getType() == Integer.class || c.getType() == Double.class) {
editingCostMapper.addItem(c);
weightMapper.addItem(c);
}
}
boolean enable = (editingCostMapper.getItemCount() > 0) ? true : false;
boolean enable = (weightMapper.getItemCount() > 0) ? true : false;
useMappingCost.setEnabled(enable);
if (!useMappingCost.isEnabled()) {
useMappingCost.setSelected(false);
editingCostMapper.setEnabled(false);
weightMapper.setEnabled(false);
}
forbiddenMapper.removeAllItems();
......@@ -247,7 +247,7 @@ SetCurrentNetworkListener
public CyColumn getEditingCostColumn() {
if (useMappingCost.isSelected()) {
return editingCostMapper.getItemAt(editingCostMapper.getSelectedIndex());
return weightMapper.getItemAt(weightMapper.getSelectedIndex());
}
return null;
}
......
......@@ -109,17 +109,11 @@ public class EditCostPanel extends JPanel {
}
//SETTER / GETTER
public CyColumn getWeightColumn() {
return columnMapper.getEditingCostColumn();
}
public CyColumn getPermanentColumn() {
return columnMapper.getPermanentColumn();
}
public String getPermanentColumnName() {
return columnMapper.getPermanentColumn() != null ? columnMapper.getPermanentColumn().getName() : null; }
public CyColumn getForbiddenColumn() {
return columnMapper.getForbiddenColumn();
}
public String getForbiddenColumnName() {
return columnMapper.getForbiddenColumn() != null ? columnMapper.getForbiddenColumn().getName() : null; }
public double getDefaultInsertionCost() {
return icField.getValueAsDouble();
......@@ -133,4 +127,8 @@ public class EditCostPanel extends JPanel {
return columnMapper;
}
public String getWeightColumnName() {
return columnMapper.getEditingCostColumn() != null ? columnMapper.getEditingCostColumn().getName() : null;
}
}
......@@ -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.getWeightColumn().getName();
ret.permanentColumn = ecPanel.getPermanentColumn();
ret.forbiddenColumn = ecPanel.getForbiddenColumn();
ret.weightColumnName = ecPanel.getWeightColumnName();
ret.permanentColumnName = ecPanel.getPermanentColumnName();
ret.forbiddenColumnName = ecPanel.getForbiddenColumnName();
ret.defaultInsertionCost = ecPanel.getDefaultInsertionCost();
ret.defaultDeletionCost = ecPanel.getDefaultDeletionCost();
ret.useHeuristic = opModePanel.useHeuristic();
......
......@@ -30,13 +30,13 @@ import org.cytoscape.application.swing.CytoPanel;
import org.cytoscape.application.swing.CytoPanelComponent;
import org.cytoscape.application.swing.CytoPanelName;
import org.cytoscape.application.swing.CytoPanelState;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyColumn;
import org.cytoscape.model.CyNode;
import org.cytoscape.work.AbstractTask;
import org.cytoscape.work.ContainsTunables;
import org.cytoscape.work.ObservableTask;
import org.cytoscape.work.TaskMonitor;
import org.cytoscape.work.Tunable;
import org.cytoscape.work.TunableValidator;
import org.slf4j.Logger;
import de.hhu.ba.yoshikoWrapper.core.CyCore;
......@@ -58,7 +58,7 @@ import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface;
import de.hhu.ba.yoshikoWrapper.swing.components.ResultPanel;
public class AlgorithmTask extends AbstractTask implements ObservableTask {
public class AlgorithmTask extends AbstractTask implements ObservableTask, TunableValidator {
//Constants
private static final String SOLUTION_COLUMN_PREFIX = "yoshikoSolution_"; //TODO: Make customizable?
......@@ -131,22 +131,27 @@ public class AlgorithmTask extends AbstractTask implements ObservableTask {
NodeMap nodeMap = new NodeMap(parameterSet.net);
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;
//Generate an c_input instance from the network
c_input = NetworkParser.parseNetwork(
parameterSet.net,
nodeMap,
parameterSet.net.getDefaultEdgeTable().getColumn(parameterSet.weightColumnName), //Simplify
parameterSet.permanentColumn,
parameterSet.forbiddenColumn,
weightColumn,
permanentColumn,
forbiddenColumn,
parameterSet.defaultDeletionCost
);
taskMonitor.setProgress(0.2);
boolean containsRealValues = GraphAnalyzer.containsRealValues(
parameterSet.net,
parameterSet.net.getDefaultEdgeTable().getColumn(parameterSet.weightColumnName),
parameterSet.permanentColumn,
parameterSet.forbiddenColumn,
weightColumn,
permanentColumn,
forbiddenColumn,
parameterSet.defaultInsertionCost,
parameterSet.defaultDeletionCost);
......@@ -305,4 +310,10 @@ public class AlgorithmTask extends AbstractTask implements ObservableTask {
}
return null;
}
@Override
public ValidationState getValidationState(Appendable errMsg) {
//In order to validate the arguments for this task we simply check the ParameterSet
return parameterSet.getValidationState(errMsg);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment