blob: 38c09c30739aa33924793d60b7ee0f2c2f11f778 [file] [log] [blame]
package org.eclipse.stem.ui.grapheditor;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.stem.definitions.labels.AreaLabel;
import org.eclipse.stem.definitions.labels.PopulationLabel;
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;
public class ComboListenerType implements SelectionListener
{
NodeData nodeData;
//connectedCombo = Value of Label
Combo connectedCombo;
Label connectedLabel;
Graph zestGraph;
ComboListenerType(Graph zestGraph, Combo connectedCombo, Label connectedLabel)
{
this.zestGraph = zestGraph;
this.connectedCombo = connectedCombo;
this.connectedLabel = connectedLabel;
}
public void widgetDefaultSelected(final SelectionEvent e) {}
public void widgetSelected(final SelectionEvent e) {
connectedCombo.removeAll();
Combo typeCombo = (Combo) e.widget;
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;
int selected = typeCombo.getSelectionIndex();
if (selected >= 0)
{
EList<org.eclipse.stem.core.graph.NodeLabel> nodeLabels = nodeData.getNodeLabels();
org.eclipse.stem.core.graph.NodeLabel nodeLabel = nodeLabels.get(selected);
List<Integer> labelTypes = nodeData.getNodeLabelTypes();
switch(labelTypes.get(selected))
{
case GraphDefs.AREA_LABEL:
AreaLabel areaLabel = (AreaLabel) nodeLabel;
connectedCombo.add(String.valueOf(areaLabel.getCurrentAreaValue().getArea()));
connectedLabel.setText("Value (Area km^2): ");
connectedCombo.select(0);
break;
case GraphDefs.POPULATION_LABEL:
PopulationLabel populationLabel = (PopulationLabel) nodeLabel;
connectedCombo.add(populationLabel.getName());
connectedCombo.add(String.valueOf(populationLabel.getCurrentPopulationValue().getCount()));
connectedCombo.add(String.valueOf(populationLabel.getPopulatedArea()));
connectedLabel.setText("Value (Population name): ");
connectedCombo.select(0);
break;
}
}
}
}