Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

renaming nodes over ot now works

Signed-off-by: Sam Phippen <samphippen@googlemail.com>
  • Loading branch information...
commit 0586fb44f51fbd3eb317505f05969a45e805bbec 1 parent 51c8bfe
@samphippen authored
View
5 src/uk/me/graphe/client/ClientOT.java
@@ -28,6 +28,7 @@
import uk.me.graphe.shared.messages.operations.DeleteEdgeOperation;
import uk.me.graphe.shared.messages.operations.DeleteNodeOperation;
import uk.me.graphe.shared.messages.operations.GraphOperation;
+import uk.me.graphe.shared.messages.operations.RenameNodeOperation;
import uk.me.graphe.shared.messages.operations.SetStyleOperation;
import com.google.gwt.user.client.Timer;
@@ -294,7 +295,9 @@ public void notifyUpdateParameters(boolean isDigraph, boolean isWeighted,
}
public void notifyRenameVertex(String label, String name) {
-
+ RenameNodeOperation rno = new RenameNodeOperation(new Vertex(label), name);
+ mUnsentOps.add(rno);
+ mStore.store(rno, false);
}
}
View
3  src/uk/me/graphe/client/Graphemeui.java
@@ -257,10 +257,11 @@ public void editNodeName(String name)
//TODO: implement - edit node name locally and over OT too. Remember you need to edit the
// vertex and the vertex drawable label. Keep the invalidate to redraw
VertexDrawable vd = selectedVertices.get(0);
+ String oldLabel = vd.getLabel();
Console.log("cows");
graphManager.renameVertex(vd.getLabel(), name);
Console.log("cheese");
- ClientOT.getInstance().notifyRenameVertex(vd.getLabel(), name);
+ ClientOT.getInstance().notifyRenameVertex(oldLabel, name);
graphManager.invalidate();
}
View
2  src/uk/me/graphe/shared/GraphTransform.java
@@ -38,6 +38,8 @@ public static GraphOperation transform(GraphOperation toApply,
else return no;
} else if (no.isStyleOperation() && !historyDelta.deletesNode(effectedNode)) {
return no;
+ } else if (no.isRenameOperation() && !historyDelta.deletesNode(effectedNode)) {
+ return no;
}
}
View
28 src/uk/me/graphe/shared/graphmanagers/GraphManager2dImpl.java
@@ -203,7 +203,7 @@ public void removeAllEdges(Vertex v1, Vertex v2) {
@Override
public void removeEdge(Edge e) {
- if (GWT.isClient()) Console.log("removing edge e: " +e);
+ if (GWT.isClient()) Console.log("removing edge e: " + e);
mEdges.remove(e);
mEdgeRenderMap.remove(e);
mVertexEdgeMap.get(e.getFromVertex()).remove(e);
@@ -346,19 +346,21 @@ public void setEdgeWeight(EdgeDrawable ed, int weight) {
@Override
public void renameVertex(String label, String name) {
int j = 0;
- mVertices.remove(new Vertex(label));
- mVertices.add(new Vertex(name));
- VertexDrawable vd = mVertexRenderMap.get(new Vertex(label));
- vd.rename(name);
- mVertexRenderMap.remove(new Vertex(label));
- mVertexRenderMap.put(new Vertex(name), vd);
- List<Edge> edges = mVertexEdgeMap.get(new Vertex(label));
- for (Edge e : edges) {
- e.replaceVertex(label, name);
- }
+ if (mVertices.contains(new Vertex(label))) {
+ mVertices.remove(new Vertex(label));
+ mVertices.add(new Vertex(name));
+ VertexDrawable vd = mVertexRenderMap.get(new Vertex(label));
+ vd.rename(name);
+ mVertexRenderMap.remove(new Vertex(label));
+ mVertexRenderMap.put(new Vertex(name), vd);
+ List<Edge> edges = mVertexEdgeMap.get(new Vertex(label));
+ for (Edge e : edges) {
+ e.replaceVertex(label, name);
+ }
- mVertexEdgeMap.remove(new Vertex(label));
- mVertexEdgeMap.put(new Vertex(name), edges);
+ mVertexEdgeMap.remove(new Vertex(label));
+ mVertexEdgeMap.put(new Vertex(name), edges);
+ }
}
}
View
2  src/uk/me/graphe/shared/messages/MessageFactory.java
@@ -19,6 +19,7 @@
import uk.me.graphe.shared.messages.factories.MoveNodeFactory;
import uk.me.graphe.shared.messages.factories.NoSuchGraphFactory;
import uk.me.graphe.shared.messages.factories.OpenGraphFactory;
+import uk.me.graphe.shared.messages.factories.RenameNodeFactory;
import uk.me.graphe.shared.messages.factories.RequestGraphFactory;
import uk.me.graphe.shared.messages.factories.SetGraphPropertiesFactory;
import uk.me.graphe.shared.messages.factories.SetNameForIdFactory;
@@ -47,6 +48,7 @@
sOpFactoryMap.put("setStyle", new SetStyleFactory());
sOpFactoryMap.put("setNameForId", new SetNameForIdFactory());
sOpFactoryMap.put("sgp", new SetGraphPropertiesFactory());
+ sOpFactoryMap.put("rename", new RenameNodeFactory());
}
/**
View
24 src/uk/me/graphe/shared/messages/factories/RenameNodeFactory.java
@@ -0,0 +1,24 @@
+package uk.me.graphe.shared.messages.factories;
+
+import uk.me.graphe.shared.Vertex;
+import uk.me.graphe.shared.jsonwrapper.JSONException;
+import uk.me.graphe.shared.jsonwrapper.JSONObject;
+import uk.me.graphe.shared.messages.Message;
+import uk.me.graphe.shared.messages.operations.RenameNodeOperation;
+
+public class RenameNodeFactory implements ConversionFactory {
+
+ @Override
+ public Message make(JSONObject o) {
+ Vertex old;
+ try {
+ old = new Vertex(o.getString("oldNode"));
+ String newN = o.getString("newNode");
+ RenameNodeOperation rno = new RenameNodeOperation(old, newN);
+ return rno;
+ } catch (JSONException e) {
+ throw new Error(e);
+ }
+ }
+
+}
View
4 src/uk/me/graphe/shared/messages/operations/NodeOperation.java
@@ -44,4 +44,8 @@ public boolean isStyleOperation() {
return false;
}
+ public boolean isRenameOperation() {
+ return false;
+ }
+
}
View
49 src/uk/me/graphe/shared/messages/operations/RenameNodeOperation.java
@@ -0,0 +1,49 @@
+package uk.me.graphe.shared.messages.operations;
+
+import uk.me.graphe.shared.Vertex;
+import uk.me.graphe.shared.graphmanagers.GraphManager2d;
+import uk.me.graphe.shared.jsonwrapper.JSONException;
+import uk.me.graphe.shared.jsonwrapper.JSONImplHolder;
+import uk.me.graphe.shared.jsonwrapper.JSONObject;
+
+public class RenameNodeOperation extends NodeOperation {
+
+ private String mNewName;
+
+ public RenameNodeOperation(Vertex v, String newN) {
+ super(v);
+ mNewName = newN;
+
+ }
+
+
+ @Override
+ public void applyTo(GraphManager2d mGraph) {
+ mGraph.renameVertex(getNode().getLabel(), mNewName);
+ }
+
+ @Override
+ public String getMessage() {
+ return "rename";
+ }
+
+ @Override
+ public String toJson() {
+ JSONObject repr = JSONImplHolder.make();
+ try {
+ repr.put("message", getMessage());
+ repr.put("oldNode", getNode().getLabel());
+ repr.put("newNode", mNewName);
+ } catch (JSONException e) {
+ throw new Error(e);
+ }
+
+ return repr.toString();
+ }
+
+ @Override
+ public boolean isRenameOperation() {
+ return true;
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.