editor.setValidator(new ICellEditorValidator() {
@Override
public String isValid(Object value) {
VertexEditPart part = (VertexEditPart) getHost();
Vertex vertex = (Vertex) part.getModel();
Graph graph = vertex.getParent();
String vertexId = (String) value;
if (vertexId.isEmpty()) {
return "";
}
vertex = graph.findVertex(vertexId);
if (vertex != null && !vertex.equals(getHost().getModel())) {
return "A vertex already exists with the same identifier";
}
return null;
}
});
Vertex vertex = (Vertex) getHost().getModel();
if (editor.getValidator().isValid(editor.getValue()) == null) {
VertexRenameCommand cmd = new VertexRenameCommand(vertex);
cmd.setName((String) editor.getValue());
return cmd;
} else {
String id = (String) vertex.getValue(ObjectType.PARAMETER_ID);
VertexFigure figure = (VertexFigure) getHostFigure();
figure.getLabelId().setText(id);
figure.adjustSize();
return null;
}