Skip to content

Commit

Permalink
Fix #1536 Add Edge dialog only remembers source index
Browse files Browse the repository at this point in the history
  • Loading branch information
eduramiba committed Nov 5, 2016
1 parent a2d4262 commit 4a5895e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 16 deletions.
4 changes: 4 additions & 0 deletions modules/DataLaboratoryPlugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
<groupId>${project.groupId}</groupId>
<artifactId>graph-api</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>project-api</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>core-library-wrapper</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Development and Distribution License("CDDL") (collectively, the
*/
package org.gephi.datalab.plugin.manipulators.general.ui;

import javax.swing.JComboBox;
import javax.swing.JPanel;
import org.gephi.datalab.plugin.manipulators.general.AddEdgeToGraph;
import org.gephi.datalab.spi.DialogControls;
Expand All @@ -49,6 +50,8 @@ Development and Distribution License("CDDL") (collectively, the
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.Node;
import org.gephi.project.api.ProjectController;
import org.gephi.project.api.Workspace;
import org.openide.util.Lookup;

/**
Expand All @@ -61,7 +64,7 @@ public class AddEdgeToGraphUI extends javax.swing.JPanel implements ManipulatorU
private AddEdgeToGraph manipulator;
private Node[] nodes;
private Graph graph;
private DialogControls dialogControls;
private Workspace workspace;

/**
* Creates new form AddEdgeToGraphUI
Expand All @@ -73,7 +76,6 @@ public AddEdgeToGraphUI() {
@Override
public void setup(Manipulator m, DialogControls dialogControls) {
this.manipulator = (AddEdgeToGraph) m;
this.dialogControls = dialogControls;
if (manipulator.isDirected()) {
directedRadioButton.setSelected(true);
} else {
Expand All @@ -83,34 +85,63 @@ public void setup(Manipulator m, DialogControls dialogControls) {
graph = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getGraph();
nodes = graph.getNodes().toArray();

workspace = Lookup.getDefault().lookup(ProjectController.class).getCurrentWorkspace();

for (Node n : nodes) {
sourceNodesComboBox.addItem(n.getId() + " - " + n.getLabel());
targetNodesComboBox.addItem(n.getId() + " - " + n.getLabel());
}

Node selectedSource = manipulator.getSource();
if (selectedSource != null) {
for (int i = 0; i < nodes.length; i++) {
if (nodes[i] == selectedSource) {
sourceNodesComboBox.setSelectedIndex(i);
}
}
SelectedOptions selectedOptions = workspace.getLookup().lookup(SelectedOptions.class);
if (selectedOptions != null) {
setNodeComboBoxSelection(sourceNodesComboBox, selectedOptions.source);
setNodeComboBoxSelection(targetNodesComboBox, selectedOptions.target);
edgeTypeComboBox.setSelectedItem(selectedOptions.edgeType);
} else {
workspace.add(new SelectedOptions());
}

refreshAvailableEdgeTypes();

dialogControls.setOkButtonEnabled(nodes.length > 0);
}

private void setNodeComboBoxSelection(JComboBox comboBox, Node node) {
if (node != null) {
for (int i = 0; i < nodes.length; i++) {
if (nodes[i] == node) {//Make sure the node is still in the graph
comboBox.setSelectedIndex(i);
}
}
}
}

@Override
public void unSetup() {
manipulator.setDirected(directedRadioButton.isSelected());
Object edgeType = getSelectedEdgeType();
boolean directed = directedRadioButton.isSelected();
Node source = null;
Node target = null;

if (sourceNodesComboBox.getSelectedIndex() != -1) {
source = nodes[sourceNodesComboBox.getSelectedIndex()];
}

if (targetNodesComboBox.getSelectedIndex() != -1) {
manipulator.setSource(nodes[sourceNodesComboBox.getSelectedIndex()]);
manipulator.setTarget(nodes[targetNodesComboBox.getSelectedIndex()]);
String edgeType = getSelectedEdgeType();
manipulator.setEdgeTypeLabel(edgeType);
target = nodes[targetNodesComboBox.getSelectedIndex()];
}

manipulator.setDirected(directed);
manipulator.setEdgeTypeLabel(edgeType);
manipulator.setSource(source);
manipulator.setTarget(target);

SelectedOptions selectedOptions = workspace.getLookup().lookup(SelectedOptions.class);

selectedOptions.directed = directed;
selectedOptions.edgeType = edgeType;
selectedOptions.source = source;
selectedOptions.target = target;
}

@Override
Expand Down Expand Up @@ -143,6 +174,17 @@ private void refreshAvailableEdgeTypes() {
}
}

private class SelectedOptions {

private Node source;
private Node target;
private Object edgeType;
private boolean directed = false;

public SelectedOptions() {
}
}

/**
* This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor.
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/DataLaboratoryPlugin/src/main/nbm/manifest.mf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Manifest-Version: 1.0
AutoUpdate-Essential-Module: true
OpenIDE-Module-Localizing-Bundle: org/gephi/datalab/plugin/Bundle.properties
OpenIDE-Module-Specification-Version: ${gephi.modules.specification.version}
OpenIDE-Module-Specification-Version: 0.9.1.1
OpenIDE-Module-Display-Category: Plugin
OpenIDE-Module-Name: Data Laboratory Plugin

0 comments on commit 4a5895e

Please sign in to comment.