package org.eclipse.stem.ui.grapheditor; | |
import java.util.List; | |
import org.eclipse.swt.events.SelectionEvent; | |
import org.eclipse.swt.events.SelectionListener; | |
import org.eclipse.swt.widgets.Combo; | |
import org.eclipse.swt.widgets.Label; | |
import org.eclipse.zest.core.widgets.Graph; | |
import org.eclipse.zest.core.widgets.GraphItem; | |
import org.eclipse.zest.core.widgets.GraphNode; | |
// when selection of label contents changes | |
public class ComboSelectionListenerValue implements SelectionListener { | |
NodeData nodeData; | |
Graph zestGraph; | |
Label connectedLabel; | |
Combo connectedCombo; | |
int selectedValue = -1; | |
ComboSelectionListenerValue(Graph zestGraph, Combo connectedCombo, Label connectedLabel) | |
{ | |
this.zestGraph = zestGraph; | |
this.connectedCombo = connectedCombo; | |
this.connectedLabel = connectedLabel; | |
} | |
public void widgetDefaultSelected(final SelectionEvent e) {} | |
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { | |
Combo valueCombo = (Combo) e.widget; | |
//no idea but seems to be necessary in some cases | |
if (valueCombo.getSelectionIndex() != -1) | |
{ | |
this.selectedValue = valueCombo.getSelectionIndex(); | |
} | |
int selectedType = connectedCombo.getSelectionIndex(); | |
List<GraphItem> selectedItems = zestGraph.getSelection(); | |
if (selectedItems.size() == 1) | |
{ | |
if (selectedItems.get(0) instanceof GraphNode) | |
{ | |
GraphNode selectedNode = (GraphNode) selectedItems.get(0); | |
NodeData nodeData = (NodeData) selectedNode.getData(); | |
this.nodeData = nodeData; | |
} | |
} | |
if (this.nodeData == null) | |
return; | |
if (selectedValue >= 0) | |
{ | |
/*String oldValueString = valueCombo.getItem(selectedValue); | |
String newValueString = valueCombo.getText(); | |
EList<org.eclipse.stem.core.graph.NodeLabel> nodeLabels = nodeData.getNodeLabels(); | |
org.eclipse.stem.core.graph.NodeLabel nodeLabel = nodeLabels.get(selectedType);*/ | |
List<Integer> labelTypes = nodeData.getNodeLabelTypes(); | |
switch(labelTypes.get(selectedType)) | |
{ | |
case GraphDefs.AREA_LABEL: | |
connectedLabel.setText("Value (Area km^2): "); | |
break; | |
case GraphDefs.POPULATION_LABEL: | |
//order defined in other listener | |
if (this.selectedValue == 0) // population name | |
{ | |
connectedLabel.setText("Value (Population Name): "); | |
} | |
if (this.selectedValue == 1) // pop size | |
{ | |
connectedLabel.setText("Value (Population Size): "); | |
} | |
if (this.selectedValue == 2) //population area | |
{ | |
connectedLabel.setText("Value (Population Area): "); | |
} | |
break; | |
} //end switch | |
} // selected value index in combo >= 0 | |
} // widget selected | |
} //end combo listener for Node Label Values |