package org.eclipse.stem.ui.grapheditor; | |
import java.util.List; | |
import org.eclipse.swt.events.ModifyEvent; | |
import org.eclipse.swt.events.ModifyListener; | |
import org.eclipse.swt.widgets.Text; | |
import org.eclipse.zest.core.widgets.Graph; | |
import org.eclipse.zest.core.widgets.GraphConnection; | |
import org.eclipse.zest.core.widgets.GraphItem; | |
import org.eclipse.zest.core.widgets.GraphNode; | |
public class TextModifyListener implements ModifyListener | |
{ | |
final static int NODE_TITLE=GraphDefs.NODE_TITLE, | |
NODE_URI=GraphDefs.NODE_URI, | |
NODE_LABEL=GraphDefs.NODE_LABEL, | |
EDGE_TITLE=GraphDefs.EDGE_TITLE, | |
EDGE_AURI=GraphDefs.EDGE_AURI, | |
EDGE_BURI=GraphDefs.EDGE_BURI, | |
EDGE_LABEL_VALUE=GraphDefs.EDGE_LABEL_VALUE; | |
NodeData nodeData; | |
ConnectionData connectionData; | |
int attribute; | |
Graph zestGraph; | |
TextModifyListener(Graph zestGraph, int attribute) | |
{ | |
this.attribute = attribute; | |
this.zestGraph = zestGraph; | |
} | |
public void modifyText(final ModifyEvent e) { | |
Text text = (Text) e.widget; | |
if (!text.isFocusControl()) | |
return; | |
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 (selectedItems.get(0) instanceof GraphConnection) | |
{ | |
GraphConnection selectedConnection = (GraphConnection) selectedItems.get(0); | |
ConnectionData connectionData = (ConnectionData) selectedConnection.getData(); | |
this.connectionData = connectionData; | |
} | |
} | |
if ( (this.nodeData == null) && (this.connectionData == null)) | |
return; | |
switch(attribute) | |
{ | |
case NODE_TITLE: nodeData.setNodeTitle(text.getText()); break; | |
case NODE_URI: nodeData.setNodeURI(text.getText()); break; | |
case NODE_LABEL: break; | |
case EDGE_TITLE: connectionData.setEdgeTitle(text.getText()); break; | |
case EDGE_AURI: connectionData.setNodeAURI(text.getText()); break; | |
case EDGE_BURI: connectionData.setNodeBURI(text.getText()); break; | |
case EDGE_LABEL_VALUE: connectionData.setEdgeLabelValue(text.getText()); break; | |
} | |
} | |
} |