From 5f6eba89e10967e6181183ffbf139367adc30e29 Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Mon, 9 Apr 2018 16:35:40 -0300 Subject: [PATCH 01/88] Launching server does not add a new tab, making possible open and use a saved model --- src/controller/TabController.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/controller/TabController.java b/src/controller/TabController.java index 1643405..a660edd 100644 --- a/src/controller/TabController.java +++ b/src/controller/TabController.java @@ -117,8 +117,9 @@ public void handleMenuActionNewSequenceDiagram() { } public void handleMenuActionServer(){ - Tab tab = addTab(CLASS_DIAGRAM_VIEW_PATH); - tabPane.getSelectionModel().select(tab); + // Tab tab = addTab(CLASS_DIAGRAM_VIEW_PATH); + // tabPane.getSelectionModel().select(tab); + Tab tab = tabPane.getSelectionModel().getSelectedItem(); tabMap.get(tabPane.getSelectionModel().getSelectedItem()).handleMenuActionServer(); } From 3685d246bb54722a579aabacab169a463a3ec71d Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Mon, 9 Apr 2018 16:37:20 -0300 Subject: [PATCH 02/88] Added association multiplicity range persistence support --- src/util/persistence/PersistenceManager.java | 38 ++++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/util/persistence/PersistenceManager.java b/src/util/persistence/PersistenceManager.java index 35e0b5d..d3a08e9 100644 --- a/src/util/persistence/PersistenceManager.java +++ b/src/util/persistence/PersistenceManager.java @@ -149,9 +149,10 @@ public static Document createXmi(Graph pGraph){ Element associationConnection = doc.createElement("UML:Association.connection"); umlAssociation.appendChild(associationConnection); - - addAssociatonEnd(edge.getStartNode().getId(), associationConnection, doc, "true"); - addAssociatonEnd(edge.getEndNode().getId(), associationConnection, doc, "false"); + + AbstractEdge abstractEdge = (AbstractEdge) edge; + addAssociatonEnd(edge.getStartNode().getId(), abstractEdge.getStartMultiplicity(), associationConnection, doc, "true"); + addAssociatonEnd(edge.getEndNode().getId(), abstractEdge.getEndMultiplicity(), associationConnection, doc, "false"); umlNamespace.appendChild(umlAssociation); @@ -227,8 +228,8 @@ private static void addClassNode(Document doc, ClassNode node, Element parent, G } parent.appendChild(umlClass); } - - private static void addAssociatonEnd(String nodeId, Element association, Document doc, String isStart){ + + private static void addAssociatonEnd(String nodeId, String multiplicityRange, Element association, Document doc, String isStart){ Element associationEnd = doc.createElement("UML:AssociationEnd"); associationEnd.setAttribute("xmi.id", "end0"); associationEnd.setAttribute("type", nodeId); @@ -241,8 +242,14 @@ private static void addAssociatonEnd(String nodeId, Element association, Documen Element multiplicityRange1 = doc.createElement("UML:Multiplicity.range"); multiplicity1.appendChild(multiplicityRange1); Element multiplicityRange11 = doc.createElement("UML:MultiplicityRange"); - multiplicityRange11.setAttribute("upper", ""); //TODO - multiplicityRange11.setAttribute("lower", ""); + // Split multiplicityRange string into upper and lower attributes and add to element. + if (multiplicityRange.contains(".")) { + multiplicityRange11.setAttribute("lower", multiplicityRange.substring(0, multiplicityRange.indexOf("."))); + multiplicityRange11.setAttribute("upper", multiplicityRange.substring(multiplicityRange.lastIndexOf(".")+1)); + } else { + multiplicityRange11.setAttribute("lower", multiplicityRange); // TODO: Is correct set to lower? + multiplicityRange11.setAttribute("upper", ""); + } multiplicityRange1.appendChild(multiplicityRange11); association.appendChild(associationEnd); } @@ -329,6 +336,23 @@ public static Graph importXMI(Document doc){ } else { //Standard is Assocation edge = new AssociationEdge(idMap.get(startNodeId), idMap.get(endNodeId)); } + // Recovering lower and upper multiplicity + NodeList nList2 = associationElement.getElementsByTagName("UML:AssociationEnd"); + for(int i2 = 0; i2 < nList2.getLength(); i2++) { + Element associationEndElement = (Element) nList2.item(i2); + NodeList nList3 = associationEndElement.getElementsByTagName("UML:MultiplicityRange"); + Element multiplicityRangeElement = (Element) nList3.item(0); + String multiplicityRange = multiplicityRangeElement.getAttribute("lower"); + if (!multiplicityRangeElement.getAttribute("upper").isEmpty()) { + multiplicityRange = multiplicityRange + ".." + multiplicityRangeElement.getAttribute("upper"); + } + String isStart = associationEndElement.getAttribute("isStart"); + if (isStart.equals("true")){ + edge.setStartMultiplicity(multiplicityRange); + } else { + edge.setEndMultiplicity(multiplicityRange); + } + } graph.addEdge(edge, false); } From f0ebdd8aa6211030730a91f2bc6afadb5c7d4db4 Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Tue, 24 Apr 2018 15:39:38 -0300 Subject: [PATCH 03/88] Code indentation to permit compare xml files with tools --- src/util/persistence/PersistenceManager.java | 25 +++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/util/persistence/PersistenceManager.java b/src/util/persistence/PersistenceManager.java index d3a08e9..56070a5 100644 --- a/src/util/persistence/PersistenceManager.java +++ b/src/util/persistence/PersistenceManager.java @@ -11,17 +11,24 @@ import model.nodes.PackageNode; import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + import java.io.*; import java.util.HashMap; import java.util.Map; @@ -39,9 +46,11 @@ public static void exportXMI(Graph pGraph, String path){ DOMSource source = new DOMSource(createXmi(pGraph)); StreamResult result = new StreamResult(new File(path)); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer.transform(source, result); } catch (TransformerException tfe) { - tfe.printStackTrace(); + tfe.printStackTrace(); } } @@ -266,6 +275,20 @@ public static Graph importXMIFromPath(String path){ } catch (ParserConfigurationException | SAXException | IOException e) { e.printStackTrace(); } + // Remove indentation to avoid errors. + XPathFactory xfact = XPathFactory.newInstance(); + XPath xpath = xfact.newXPath(); + try { + NodeList empty = + (NodeList)xpath.evaluate("//text()[normalize-space(.) = '']", + doc, XPathConstants.NODESET); + for (int i = 0; i < empty.getLength(); i++) { + Node node = empty.item(i); + node.getParentNode().removeChild(node); + } + } catch (XPathExpressionException e) { + e.printStackTrace(); + } return importXMI(doc); } public static Graph importXMI(Document doc){ From 175f3f89696b90884d06402aab71b6ec5b764565 Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Wed, 25 Apr 2018 15:08:28 -0300 Subject: [PATCH 04/88] Fixed NullPointerException while saving model with relation without cardinality --- src/util/persistence/PersistenceManager.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/util/persistence/PersistenceManager.java b/src/util/persistence/PersistenceManager.java index 56070a5..09b67a1 100644 --- a/src/util/persistence/PersistenceManager.java +++ b/src/util/persistence/PersistenceManager.java @@ -252,13 +252,18 @@ private static void addAssociatonEnd(String nodeId, String multiplicityRange, El multiplicity1.appendChild(multiplicityRange1); Element multiplicityRange11 = doc.createElement("UML:MultiplicityRange"); // Split multiplicityRange string into upper and lower attributes and add to element. - if (multiplicityRange.contains(".")) { - multiplicityRange11.setAttribute("lower", multiplicityRange.substring(0, multiplicityRange.indexOf("."))); - multiplicityRange11.setAttribute("upper", multiplicityRange.substring(multiplicityRange.lastIndexOf(".")+1)); - } else { - multiplicityRange11.setAttribute("lower", multiplicityRange); // TODO: Is correct set to lower? + if (multiplicityRange != null) { + if (multiplicityRange.contains(".")) { + multiplicityRange11.setAttribute("lower", multiplicityRange.substring(0, multiplicityRange.indexOf("."))); + multiplicityRange11.setAttribute("upper", multiplicityRange.substring(multiplicityRange.lastIndexOf(".")+1)); + } else { + multiplicityRange11.setAttribute("lower", multiplicityRange); // TODO: Is correct set to lower? + multiplicityRange11.setAttribute("upper", ""); + } + } else { + multiplicityRange11.setAttribute("lower", ""); multiplicityRange11.setAttribute("upper", ""); - } + } multiplicityRange1.appendChild(multiplicityRange11); association.appendChild(associationEnd); } From 0fb266bc7fc89ee7081b45594ac80fa06131aa1d Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Sun, 29 Apr 2018 13:25:35 -0300 Subject: [PATCH 05/88] Partial implementation of detailed synchronization --- src/model/IdentifiedTextField.java | 41 +++++++ src/util/persistence/PersistenceManager.java | 15 ++- src/view/nodes/ClassNodeView.java | 118 +++++++++++++++---- 3 files changed, 145 insertions(+), 29 deletions(-) create mode 100644 src/model/IdentifiedTextField.java diff --git a/src/model/IdentifiedTextField.java b/src/model/IdentifiedTextField.java new file mode 100644 index 0000000..03f669b --- /dev/null +++ b/src/model/IdentifiedTextField.java @@ -0,0 +1,41 @@ +package model; + +import javafx.scene.control.TextField; + +public class IdentifiedTextField extends TextField { + + public static final String SEPARATOR = "|"; + + private String xmiId; + + public IdentifiedTextField(String text) { + int ind = text.indexOf(SEPARATOR); + if (ind != -1) { + xmiId = text.substring(0, ind); + setText(text.substring(ind+1)); + } else { + setText(text); + } + } + + public String getXmiId() { + return xmiId; + } + + public void setXmiId(String xmiId) { + this.xmiId = xmiId; + } + + public String toString() { + return xmiId + "SEPARATOR" + getText(); + } + + @Override + public boolean equals(Object obj) { + IdentifiedTextField aux = (IdentifiedTextField) obj; + if (xmiId.equals(aux.getXmiId()) && xmiId.equals(aux.getText())) { + return true; + } + return false; + } +} diff --git a/src/util/persistence/PersistenceManager.java b/src/util/persistence/PersistenceManager.java index 09b67a1..8d53772 100644 --- a/src/util/persistence/PersistenceManager.java +++ b/src/util/persistence/PersistenceManager.java @@ -29,9 +29,11 @@ import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; +import java.awt.TextField; import java.io.*; import java.util.HashMap; import java.util.Map; +import java.util.UUID; /** * Class with static methods for importing and exporting xmi models. @@ -204,6 +206,7 @@ public static Document createXmi(Graph pGraph){ } private static void addClassNode(Document doc, ClassNode node, Element parent, Graph pGraph, boolean isChild){ + IdentifiedTextField textField; Element umlClass = doc.createElement("UML:Class"); if(isChild){ umlClass.setAttribute("namespace", ((Element)parent.getParentNode()).getAttribute("xmi.id")); @@ -215,23 +218,23 @@ private static void addClassNode(Document doc, ClassNode node, Element parent, G Element classifierFeature = doc.createElement("UML:Classifier.feature"); umlClass.appendChild(classifierFeature); - int attIdCount = 0; - int opIdCount = 0; if(node.getAttributes() != null){ String attributes[] = node.getAttributes().split("\\r?\\n"); for(String att : attributes){ + textField = new IdentifiedTextField(att); Element attribute = doc.createElement("UML:Attribute"); - attribute.setAttribute("name", att); - attribute.setAttribute("xmi.id", "att" + ++attIdCount + "_" + node.getId()); + attribute.setAttribute("name", textField.getText()); + attribute.setAttribute("xmi.id", "att" + UUID.randomUUID().toString() + "_" + node.getId()); classifierFeature.appendChild(attribute); } } if(node.getOperations() != null){ String operations[] = node.getOperations().split("\\r?\\n"); for(String op : operations) { + textField = new IdentifiedTextField(op); Element operation = doc.createElement("UML:Operation"); - operation.setAttribute("name", op); - operation.setAttribute("xmi.id", "oper" + ++opIdCount + "_" + node.getId()); + operation.setAttribute("name", textField.getText()); + operation.setAttribute("xmi.id", "oper" + UUID.randomUUID().toString() + "_" + node.getId()); classifierFeature.appendChild(operation); } } diff --git a/src/view/nodes/ClassNodeView.java b/src/view/nodes/ClassNodeView.java index 7399a56..beed9e1 100644 --- a/src/view/nodes/ClassNodeView.java +++ b/src/view/nodes/ClassNodeView.java @@ -1,10 +1,15 @@ package view.nodes; import javafx.geometry.Bounds; + import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.control.Label; import javafx.scene.control.Separator; +import javafx.scene.layout.Background; +import javafx.scene.layout.BackgroundFill; +import javafx.scene.layout.BorderStroke; +import javafx.scene.layout.CornerRadii; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; @@ -13,19 +18,27 @@ import javafx.scene.shape.Rectangle; import javafx.scene.text.Font; import javafx.scene.text.FontWeight; +import javafx.scene.control.TextField; +import model.IdentifiedTextField; import model.nodes.ClassNode; import util.Constants; import java.beans.PropertyChangeEvent; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.w3c.dom.Element; + /** * Visual representation of ClassNode class. */ public class ClassNodeView extends AbstractNodeView implements NodeView { - private Label title; - private Label attributes; - private Label operations; + private TextField title; + private List attributes; + private List operations; private Rectangle rectangle; @@ -80,6 +93,9 @@ private void changeHeight(double height){ } private void changeWidth(double width){ + TextField textField; + Iterator i; + setWidth(width); rectangle.setWidth(width); container.setMaxWidth(width); @@ -94,12 +110,20 @@ private void changeWidth(double width){ title.setMaxWidth(width); title.setPrefWidth(width); + + i = attributes.iterator(); + while (i.hasNext()) { + textField = (TextField) i.next(); + textField.setMaxWidth(width); + textField.setPrefWidth(width); + } - attributes.setMaxWidth(width); - attributes.setPrefWidth(width); - - operations.setMaxWidth(width); - operations.setPrefWidth(width); + i = operations.iterator(); + while (i.hasNext()) { + textField = (TextField) i.next(); + textField.setMaxWidth(width); + textField.setPrefWidth(width); + } } private void createHandles(){ @@ -133,35 +157,61 @@ private void initVBox(){ secondLine = new Separator(); secondLine.setMaxWidth(node.getWidth()); - title = new Label(); + title = new TextField(); title.setFont(Font.font("Verdana", FontWeight.BOLD, 12)); if(node.getTitle() != null) { title.setText(node.getTitle()); } title.setAlignment(Pos.CENTER); + + attributes = new ArrayList<>(); + for(String text : node.getAttributes().split("\\r?\\n")){ + TextField textfield = new IdentifiedTextField(text); + textfield.setFont(Font.font("Verdana", 10)); + attributes.add(textfield); + } - attributes = new Label(node.getAttributes()); - attributes.setFont(Font.font("Verdana", 10)); - - operations = new Label(node.getOperations()); - operations.setFont(Font.font("Verdana", 10)); - + operations = new ArrayList<>(); + for(String text : node.getOperations().split("\\r?\\n")){ + TextField textfield = new IdentifiedTextField(text); + textfield.setFont(Font.font("Verdana", 10)); + operations.add(textfield); + } - if(operations.getText() == null || operations.getText().equals("")){ + if(operations.isEmpty()){ secondLine.setVisible(false); } titlePane.getChildren().add(title); - vbox.getChildren().addAll(titlePane, firstLine, attributes, secondLine, operations); + vbox.getChildren().addAll(titlePane, firstLine); + vbox.getChildren().addAll(attributes); + vbox.getChildren().addAll(secondLine); + vbox.getChildren().addAll(operations); } private void initLooks(){ + TextField textfield; + Iterator i; + Background background; + rectangle.setStrokeWidth(STROKE_WIDTH); rectangle.setFill(Color.LIGHTSKYBLUE); rectangle.setStroke(Color.BLACK); StackPane.setAlignment(title, Pos.CENTER); - VBox.setMargin(attributes, new Insets(5,0,0,5)); - VBox.setMargin(operations, new Insets(5,0,0,5)); + background = new Background(new BackgroundFill(Color.LIGHTSKYBLUE, CornerRadii.EMPTY, Insets.EMPTY)); + title.setBackground(background); + i = attributes.iterator(); + while (i.hasNext()) { + textfield = (TextField) i.next(); + textfield.setPadding(new Insets(0)); + textfield.setBackground(background); + } + i = operations.iterator(); + while (i.hasNext()) { + textfield = (TextField) i.next(); + textfield.setPadding(new Insets(0)); + textfield.setBackground(background); + } } public void setSelected(boolean selected){ @@ -193,7 +243,11 @@ public Bounds getBounds(){ @Override public void propertyChange(PropertyChangeEvent evt) { - + Iterator i; + IdentifiedTextField textField; + String array[]; + int ind; + super.propertyChange(evt); if (evt.getPropertyName().equals(Constants.changeNodeX)) { setX((double) evt.getNewValue()); @@ -211,10 +265,28 @@ public void propertyChange(PropertyChangeEvent evt) { firstLine.setVisible(true); } } else if (evt.getPropertyName().equals(Constants.changeClassNodeAttributes)) { - attributes.setText((String) evt.getNewValue()); + array = ((String)evt.getNewValue()).split(";"); + ind = Integer.parseInt(array[0]); + textField = new IdentifiedTextField(array[1]); + if (attributes.contains(textField)) { + attributes.remove(textField); + } + // ind = -1 means the field was deleted + if (ind != -1) { + attributes.add(ind,textField); + } } else if (evt.getPropertyName().equals(Constants.changeClassNodeOperations)) { - operations.setText((String) evt.getNewValue()); - if (operations.getText() == null || operations.getText().equals("")) { + array = ((String)evt.getNewValue()).split(";"); + ind = Integer.parseInt(array[0]); + textField = new IdentifiedTextField(array[1]); + if (operations.contains(textField)) { + operations.remove(textField); + } + // ind = -1 means the field was deleted + if (ind != -1) { + operations.add(ind,textField); + } + if (operations.isEmpty()) { secondLine.setVisible(false); } else { secondLine.setVisible(true); From 1aec3a8f2d7fb65b04a54e522677a4b3385f593d Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Mon, 30 Apr 2018 17:43:41 -0300 Subject: [PATCH 06/88] Partial implementation of detailed synchronization --- src/controller/ClientController.java | 4 +- src/controller/ServerController.java | 3 +- src/model/IdentifiedTextField.java | 19 +++-- src/util/persistence/PersistenceManager.java | 7 +- src/view/nodes/ClassNodeView.java | 76 +++++++++++++++----- 5 files changed, 81 insertions(+), 28 deletions(-) diff --git a/src/controller/ClientController.java b/src/controller/ClientController.java index 878c6ea..190f534 100644 --- a/src/controller/ClientController.java +++ b/src/controller/ClientController.java @@ -37,7 +37,8 @@ public ClientController(AbstractDiagramController pDiagramController, String pSe serverIp = pServerIp; port = pPort; - client = new Client(); + // Increase of buffers size to avoid overflow. Defaults: 8192, 2048 + client = new Client(8192,8192); initKryo(client.getKryo()); @@ -63,6 +64,7 @@ else if (object instanceof String[]){ public boolean connect(){ client.start(); + int test = client.getTcpWriteBufferSize(); try { client.connect(5000, serverIp, port, port); } catch (IOException e) { diff --git a/src/controller/ServerController.java b/src/controller/ServerController.java index af08a44..d8ab83e 100644 --- a/src/controller/ServerController.java +++ b/src/controller/ServerController.java @@ -36,7 +36,8 @@ public ServerController(Graph pGraph, AbstractDiagramController pDiagramControll graph = pGraph; graph.addRemotePropertyChangeListener(this); - server = new Server(); + // Increase of buffers size to avoid overflow. Defaults: 16384, 2048 + server = new Server(16384,8192); server.start(); try { server.bind(port,port); diff --git a/src/model/IdentifiedTextField.java b/src/model/IdentifiedTextField.java index 03f669b..83bbf33 100644 --- a/src/model/IdentifiedTextField.java +++ b/src/model/IdentifiedTextField.java @@ -1,5 +1,7 @@ package model; +import java.util.UUID; + import javafx.scene.control.TextField; public class IdentifiedTextField extends TextField { @@ -14,6 +16,7 @@ public IdentifiedTextField(String text) { xmiId = text.substring(0, ind); setText(text.substring(ind+1)); } else { + xmiId = UUID.randomUUID().toString(); setText(text); } } @@ -27,14 +30,22 @@ public void setXmiId(String xmiId) { } public String toString() { - return xmiId + "SEPARATOR" + getText(); + return xmiId + SEPARATOR + getText(); } @Override public boolean equals(Object obj) { - IdentifiedTextField aux = (IdentifiedTextField) obj; - if (xmiId.equals(aux.getXmiId()) && xmiId.equals(aux.getText())) { - return true; + if (obj instanceof IdentifiedTextField) { + IdentifiedTextField aux = (IdentifiedTextField) obj; + if (xmiId != null) { + if (xmiId.equals(aux.getXmiId()) && getText().equals(aux.getText())) { + return true; + } + } else { + if (getText().equals(aux.getText())) { + return true; + } + } } return false; } diff --git a/src/util/persistence/PersistenceManager.java b/src/util/persistence/PersistenceManager.java index 8d53772..a908b54 100644 --- a/src/util/persistence/PersistenceManager.java +++ b/src/util/persistence/PersistenceManager.java @@ -429,12 +429,13 @@ private static AbstractNode createAbstractNode(Element view, Element model, bool String operations = ""; for(int i = 0; i < attsOps.getLength(); i++){ Element item = ((Element)attsOps.item(i)); + String name = item.getAttribute("name"); + String xmiId = item.getAttribute("xmi.id"); if(item.getNodeName().equals("UML:Attribute")){ - String att = item.getAttribute("name"); - attributes = attributes + att + System.getProperty("line.separator"); + attributes = attributes + xmiId + IdentifiedTextField.SEPARATOR + name + System.getProperty("line.separator"); } else if(item.getNodeName().equals("UML:Operation")){ String op = item.getAttribute("name"); - operations = operations + op + System.getProperty("line.separator"); + operations = operations + xmiId + IdentifiedTextField.SEPARATOR + name + System.getProperty("line.separator"); } } ((ClassNode)abstractNode).setAttributes(attributes); diff --git a/src/view/nodes/ClassNodeView.java b/src/view/nodes/ClassNodeView.java index beed9e1..1ecdda3 100644 --- a/src/view/nodes/ClassNodeView.java +++ b/src/view/nodes/ClassNodeView.java @@ -1,5 +1,7 @@ package view.nodes; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; import javafx.geometry.Bounds; import javafx.geometry.Insets; @@ -93,9 +95,6 @@ private void changeHeight(double height){ } private void changeWidth(double width){ - TextField textField; - Iterator i; - setWidth(width); rectangle.setWidth(width); container.setMaxWidth(width); @@ -110,14 +109,14 @@ private void changeWidth(double width){ title.setMaxWidth(width); title.setPrefWidth(width); - - i = attributes.iterator(); + + TextField textField; + Iterator i = attributes.iterator(); while (i.hasNext()) { textField = (TextField) i.next(); textField.setMaxWidth(width); textField.setPrefWidth(width); } - i = operations.iterator(); while (i.hasNext()) { textField = (TextField) i.next(); @@ -127,7 +126,6 @@ private void changeWidth(double width){ } private void createHandles(){ - shortHandleLine = new Line(); longHandleLine = new Line(); @@ -141,6 +139,41 @@ private void createHandles(){ longHandleLine.endYProperty().bind(rectangle.heightProperty().subtract(15)); this.getChildren().addAll(shortHandleLine, longHandleLine); + + title.textProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, + String oldValue, String newValue) { + ((ClassNode)getRefNode()).setTitle(newValue); + System.out.println("Title changed to " + newValue + ")\n"); + } + }); + Iterator i = attributes.iterator(); + while (i.hasNext()){ + IdentifiedTextField textField = (IdentifiedTextField) i.next(); + textField.textProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, + String oldValue, String newValue) { + String fullText = attributes.indexOf(textField) + ";" + textField.getXmiId() + "|" + newValue; + ((ClassNode)getRefNode()).setAttributes(fullText); + System.out.println("Attribute changed to " + fullText + ")\n"); + } + }); + } + i = operations.iterator(); + while (i.hasNext()){ + IdentifiedTextField textField = (IdentifiedTextField) i.next(); + textField.textProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, + String oldValue, String newValue) { + String fullText = operations.indexOf(textField) + ";" + textField.getXmiId() + "|" + newValue; + ((ClassNode)getRefNode()).setOperations(fullText); + System.out.println("Operation changed to " + fullText + ")\n"); + } + }); + } } private void initVBox(){ @@ -165,17 +198,20 @@ private void initVBox(){ title.setAlignment(Pos.CENTER); attributes = new ArrayList<>(); - for(String text : node.getAttributes().split("\\r?\\n")){ - TextField textfield = new IdentifiedTextField(text); - textfield.setFont(Font.font("Verdana", 10)); - attributes.add(textfield); + if (node.getAttributes() != null) { + for(String text : node.getAttributes().split("\\r?\\n")){ + TextField textfield = new IdentifiedTextField(text); + textfield.setFont(Font.font("Verdana", 10)); + attributes.add(textfield); + } } - operations = new ArrayList<>(); - for(String text : node.getOperations().split("\\r?\\n")){ - TextField textfield = new IdentifiedTextField(text); - textfield.setFont(Font.font("Verdana", 10)); - operations.add(textfield); + if (node.getOperations() != null) { + for(String text : node.getOperations().split("\\r?\\n")){ + TextField textfield = new IdentifiedTextField(text); + textfield.setFont(Font.font("Verdana", 10)); + operations.add(textfield); + } } if(operations.isEmpty()){ @@ -245,7 +281,7 @@ public Bounds getBounds(){ public void propertyChange(PropertyChangeEvent evt) { Iterator i; IdentifiedTextField textField; - String array[]; + String newValue, array[]; int ind; super.propertyChange(evt); @@ -265,7 +301,8 @@ public void propertyChange(PropertyChangeEvent evt) { firstLine.setVisible(true); } } else if (evt.getPropertyName().equals(Constants.changeClassNodeAttributes)) { - array = ((String)evt.getNewValue()).split(";"); + newValue = (String) evt.getNewValue(); + array = newValue.split(";"); ind = Integer.parseInt(array[0]); textField = new IdentifiedTextField(array[1]); if (attributes.contains(textField)) { @@ -276,7 +313,8 @@ public void propertyChange(PropertyChangeEvent evt) { attributes.add(ind,textField); } } else if (evt.getPropertyName().equals(Constants.changeClassNodeOperations)) { - array = ((String)evt.getNewValue()).split(";"); + newValue = (String) evt.getNewValue(); + array = newValue.split(";"); ind = Integer.parseInt(array[0]); textField = new IdentifiedTextField(array[1]); if (operations.contains(textField)) { From 427c0af7bfb53cad89818ee3042c126958c8e7ac Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Tue, 1 May 2018 00:01:57 -0300 Subject: [PATCH 07/88] Partial implementation of detailed synchronization --- src/util/persistence/PersistenceManager.java | 9 +- src/view/nodes/ClassNodeView.java | 148 ++++++++++++------- 2 files changed, 105 insertions(+), 52 deletions(-) diff --git a/src/util/persistence/PersistenceManager.java b/src/util/persistence/PersistenceManager.java index a908b54..e520068 100644 --- a/src/util/persistence/PersistenceManager.java +++ b/src/util/persistence/PersistenceManager.java @@ -420,6 +420,7 @@ private static AbstractNode createAbstractNode(Element view, Element model, bool double y = Double.parseDouble(geometry[1]); double width = Double.parseDouble(geometry[2]) - x; double height = Double.parseDouble(geometry[3]) - y; + int attributesCont, operationsCont; AbstractNode abstractNode; if(!isPackage){ @@ -427,15 +428,19 @@ private static AbstractNode createAbstractNode(Element view, Element model, bool NodeList attsOps = model.getChildNodes().item(0).getChildNodes(); String attributes = ""; String operations = ""; + attributesCont = 0; + operationsCont = 0; for(int i = 0; i < attsOps.getLength(); i++){ Element item = ((Element)attsOps.item(i)); String name = item.getAttribute("name"); String xmiId = item.getAttribute("xmi.id"); if(item.getNodeName().equals("UML:Attribute")){ - attributes = attributes + xmiId + IdentifiedTextField.SEPARATOR + name + System.getProperty("line.separator"); + attributes = attributes + attributesCont + ";" + xmiId + IdentifiedTextField.SEPARATOR + name + System.getProperty("line.separator"); + attributesCont++; } else if(item.getNodeName().equals("UML:Operation")){ String op = item.getAttribute("name"); - operations = operations + xmiId + IdentifiedTextField.SEPARATOR + name + System.getProperty("line.separator"); + operations = operations + operationsCont + ";" + xmiId + IdentifiedTextField.SEPARATOR + name + System.getProperty("line.separator"); + operationsCont++; } } ((ClassNode)abstractNode).setAttributes(attributes); diff --git a/src/view/nodes/ClassNodeView.java b/src/view/nodes/ClassNodeView.java index 1ecdda3..3d19d0e 100644 --- a/src/view/nodes/ClassNodeView.java +++ b/src/view/nodes/ClassNodeView.java @@ -39,8 +39,8 @@ public class ClassNodeView extends AbstractNodeView implements NodeView { private TextField title; - private List attributes; - private List operations; + private List attributes; + private List operations; private Rectangle rectangle; @@ -77,8 +77,6 @@ public ClassNodeView(ClassNode node) { this.setTranslateX(node.getTranslateX()); this.setTranslateY(node.getTranslateY()); createHandles(); - - } private void createRectangles(){ @@ -148,32 +146,40 @@ public void changed(ObservableValue observable, System.out.println("Title changed to " + newValue + ")\n"); } }); - Iterator i = attributes.iterator(); - while (i.hasNext()){ - IdentifiedTextField textField = (IdentifiedTextField) i.next(); + for (TextField textField: attributes) { textField.textProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observable, String oldValue, String newValue) { - String fullText = attributes.indexOf(textField) + ";" + textField.getXmiId() + "|" + newValue; - ((ClassNode)getRefNode()).setAttributes(fullText); - System.out.println("Attribute changed to " + fullText + ")\n"); + System.out.println("'" + oldValue + "' changed to '" + newValue + "')\n"); + for (int index = 0; index < attributes.size(); index++) { + IdentifiedTextField localTextField = (IdentifiedTextField) attributes.get(index); + if (localTextField.getText().equals(newValue)) { + String fullText = index + ";" + localTextField.getXmiId() + "|" + newValue; + ((ClassNode)getRefNode()).setAttributes(fullText); + break; + } + } } }); - } - i = operations.iterator(); - while (i.hasNext()){ - IdentifiedTextField textField = (IdentifiedTextField) i.next(); + } + for (TextField textField: operations) { textField.textProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observable, String oldValue, String newValue) { - String fullText = operations.indexOf(textField) + ";" + textField.getXmiId() + "|" + newValue; - ((ClassNode)getRefNode()).setOperations(fullText); - System.out.println("Operation changed to " + fullText + ")\n"); + System.out.println("'" + oldValue + "' changed to '" + newValue + "')\n"); + for (int index = 0; index < operations.size(); index++) { + IdentifiedTextField localTextField = (IdentifiedTextField) operations.get(index); + if (localTextField.getText().equals(newValue)) { + String fullText = index + ";" + localTextField.getXmiId() + "|" + newValue; + ((ClassNode)getRefNode()).setOperations(fullText); + break; + } + } } }); - } + } } private void initVBox(){ @@ -200,7 +206,10 @@ private void initVBox(){ attributes = new ArrayList<>(); if (node.getAttributes() != null) { for(String text : node.getAttributes().split("\\r?\\n")){ - TextField textfield = new IdentifiedTextField(text); + if (text.contains(";")) { + text = text.substring(text.indexOf(";")+1); + } + IdentifiedTextField textfield = new IdentifiedTextField(text); textfield.setFont(Font.font("Verdana", 10)); attributes.add(textfield); } @@ -208,7 +217,10 @@ private void initVBox(){ operations = new ArrayList<>(); if (node.getOperations() != null) { for(String text : node.getOperations().split("\\r?\\n")){ - TextField textfield = new IdentifiedTextField(text); + if (text.contains(";")) { + text = text.substring(text.indexOf(";")+1); + } + IdentifiedTextField textfield = new IdentifiedTextField(text); textfield.setFont(Font.font("Verdana", 10)); operations.add(textfield); } @@ -279,10 +291,7 @@ public Bounds getBounds(){ @Override public void propertyChange(PropertyChangeEvent evt) { - Iterator i; - IdentifiedTextField textField; - String newValue, array[]; - int ind; + super.propertyChange(evt); if (evt.getPropertyName().equals(Constants.changeNodeX)) { @@ -294,41 +303,80 @@ public void propertyChange(PropertyChangeEvent evt) { } else if (evt.getPropertyName().equals(Constants.changeNodeHeight)) { changeHeight((double) evt.getNewValue()); } else if (evt.getPropertyName().equals(Constants.changeNodeTitle)) { - title.setText((String) evt.getNewValue()); + String newValue = (String) evt.getNewValue(); + // Update text if it was altered + if (!title.getText().equals(newValue)) { + title.setText(newValue); + } if (title.getText() == null || title.getText().equals("")) { firstLine.setVisible(false); } else { firstLine.setVisible(true); } } else if (evt.getPropertyName().equals(Constants.changeClassNodeAttributes)) { - newValue = (String) evt.getNewValue(); - array = newValue.split(";"); - ind = Integer.parseInt(array[0]); - textField = new IdentifiedTextField(array[1]); - if (attributes.contains(textField)) { - attributes.remove(textField); - } - // ind = -1 means the field was deleted - if (ind != -1) { - attributes.add(ind,textField); + String newValue = (String) evt.getNewValue(); + for(String text : newValue.split("\\r?\\n")){ + String array[] = text.split(";"); + int ind = Integer.parseInt(array[0]); + IdentifiedTextField remoteTextField = new IdentifiedTextField(array[1]); + boolean found = false; + for (int index = 0; index < attributes.size(); index++) { + IdentifiedTextField localTextField = attributes.get(index); + if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { + found = true; + if (ind != -1) { + // Update text if it was altered + if (!localTextField.getText().equals(remoteTextField.getText())) { + localTextField.setText(remoteTextField.getText()); + } + // If moved upper or down + if (attributes.indexOf(localTextField) != ind) { + attributes.remove(localTextField); + attributes.add(ind,localTextField); + } + } else { + attributes.remove(localTextField); + } + break; + } + } + // New attribute + if (!found) { + attributes.add(ind,remoteTextField); + } } } else if (evt.getPropertyName().equals(Constants.changeClassNodeOperations)) { - newValue = (String) evt.getNewValue(); - array = newValue.split(";"); - ind = Integer.parseInt(array[0]); - textField = new IdentifiedTextField(array[1]); - if (operations.contains(textField)) { - operations.remove(textField); - } - // ind = -1 means the field was deleted - if (ind != -1) { - operations.add(ind,textField); + String newValue = (String) evt.getNewValue(); + for(String text : newValue.split("\\r?\\n")){ + String array[] = text.split(";"); + int ind = Integer.parseInt(array[0]); + IdentifiedTextField remoteTextField = new IdentifiedTextField(array[1]); + boolean found = false; + for (int index = 0; index < operations.size(); index++) { + IdentifiedTextField localTextField = operations.get(index); + if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { + found = true; + if (ind != -1) { + // Update text if it was altered + if (!localTextField.getText().equals(remoteTextField.getText())) { + localTextField.setText(remoteTextField.getText()); + } + // If moved upper or down + if (operations.indexOf(localTextField) != ind) { + operations.remove(localTextField); + operations.add(ind,localTextField); + } + } else { + operations.remove(localTextField); + } + break; + } + } + // New operation + if (!found) { + operations.add(ind,remoteTextField); + } } - if (operations.isEmpty()) { - secondLine.setVisible(false); - } else { - secondLine.setVisible(true); - } } } } From f828c2b50ea2bbcdefce63f8b28d3c600d1c1ab3 Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Tue, 1 May 2018 20:58:04 -0300 Subject: [PATCH 08/88] Partial implementation of detailed synchronization --- src/controller/AbstractDiagramController.java | 10 +- src/model/IdentifiedTextField.java | 14 +- src/view/nodes/ClassNodeView.java | 142 +++++++++++------- 3 files changed, 108 insertions(+), 58 deletions(-) diff --git a/src/controller/AbstractDiagramController.java b/src/controller/AbstractDiagramController.java index 31c6af3..08abedb 100644 --- a/src/controller/AbstractDiagramController.java +++ b/src/controller/AbstractDiagramController.java @@ -588,6 +588,14 @@ private void initContextMenu() { deleteSelected(); }); + MenuItem cmItemAddAttribute = new MenuItem("Add attribute"); + cmItemAddAttribute.setOnAction(event -> { + if (aContextMenu.getOwnerNode() instanceof ClassNodeView) { + ClassNodeView classNodeView = (ClassNodeView) aContextMenu.getOwnerNode(); + classNodeView.addAttribute(); + } + }); + MenuItem cmItemCopy = new MenuItem("Copy"); cmItemCopy.setOnAction(e -> { copyPasteController.copy(); @@ -607,7 +615,7 @@ private void initContextMenu() { insertImg.openFileChooser(AbstractDiagramController.this, point); }); - aContextMenu.getItems().addAll(cmItemCopy, cmItemPaste, cmItemDelete, cmItemInsertImg); + aContextMenu.getItems().addAll(cmItemCopy, cmItemPaste, cmItemDelete, cmItemInsertImg, cmItemAddAttribute); } /** diff --git a/src/model/IdentifiedTextField.java b/src/model/IdentifiedTextField.java index 83bbf33..0e0928d 100644 --- a/src/model/IdentifiedTextField.java +++ b/src/model/IdentifiedTextField.java @@ -11,13 +11,17 @@ public class IdentifiedTextField extends TextField { private String xmiId; public IdentifiedTextField(String text) { - int ind = text.indexOf(SEPARATOR); - if (ind != -1) { - xmiId = text.substring(0, ind); - setText(text.substring(ind+1)); + if (!text.isEmpty()) { + int ind = text.indexOf(SEPARATOR); + if (ind != -1) { + xmiId = text.substring(0, ind); + setText(text.substring(ind+1)); + } else { + xmiId = UUID.randomUUID().toString(); + setText(text); + } } else { xmiId = UUID.randomUUID().toString(); - setText(text); } } diff --git a/src/view/nodes/ClassNodeView.java b/src/view/nodes/ClassNodeView.java index 3d19d0e..6f3cc0e 100644 --- a/src/view/nodes/ClassNodeView.java +++ b/src/view/nodes/ClassNodeView.java @@ -2,11 +2,15 @@ import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; import javafx.geometry.Bounds; import javafx.geometry.Insets; import javafx.geometry.Pos; +import javafx.scene.control.ContextMenu; import javafx.scene.control.Label; +import javafx.scene.control.MenuItem; import javafx.scene.control.Separator; import javafx.scene.layout.Background; import javafx.scene.layout.BackgroundFill; @@ -20,7 +24,10 @@ import javafx.scene.shape.Rectangle; import javafx.scene.text.Font; import javafx.scene.text.FontWeight; +import javafx.stage.WindowEvent; import javafx.scene.control.TextField; +import javafx.scene.input.KeyEvent; +import javafx.scene.input.MouseEvent; import model.IdentifiedTextField; import model.nodes.ClassNode; import util.Constants; @@ -146,39 +153,11 @@ public void changed(ObservableValue observable, System.out.println("Title changed to " + newValue + ")\n"); } }); - for (TextField textField: attributes) { - textField.textProperty().addListener(new ChangeListener() { - @Override - public void changed(ObservableValue observable, - String oldValue, String newValue) { - System.out.println("'" + oldValue + "' changed to '" + newValue + "')\n"); - for (int index = 0; index < attributes.size(); index++) { - IdentifiedTextField localTextField = (IdentifiedTextField) attributes.get(index); - if (localTextField.getText().equals(newValue)) { - String fullText = index + ";" + localTextField.getXmiId() + "|" + newValue; - ((ClassNode)getRefNode()).setAttributes(fullText); - break; - } - } - } - }); + for (IdentifiedTextField textField: attributes) { + createHandlesAttributesOperations(textField, attributes, "attribute"); } - for (TextField textField: operations) { - textField.textProperty().addListener(new ChangeListener() { - @Override - public void changed(ObservableValue observable, - String oldValue, String newValue) { - System.out.println("'" + oldValue + "' changed to '" + newValue + "')\n"); - for (int index = 0; index < operations.size(); index++) { - IdentifiedTextField localTextField = (IdentifiedTextField) operations.get(index); - if (localTextField.getText().equals(newValue)) { - String fullText = index + ";" + localTextField.getXmiId() + "|" + newValue; - ((ClassNode)getRefNode()).setOperations(fullText); - break; - } - } - } - }); + for (IdentifiedTextField textField: operations) { + createHandlesAttributesOperations(textField, operations, "operation"); } } @@ -238,27 +217,20 @@ private void initVBox(){ } private void initLooks(){ - TextField textfield; - Iterator i; - Background background; - rectangle.setStrokeWidth(STROKE_WIDTH); rectangle.setFill(Color.LIGHTSKYBLUE); rectangle.setStroke(Color.BLACK); StackPane.setAlignment(title, Pos.CENTER); - background = new Background(new BackgroundFill(Color.LIGHTSKYBLUE, CornerRadii.EMPTY, Insets.EMPTY)); + BackgroundFill backgroundFill = new BackgroundFill(Color.LIGHTSKYBLUE, CornerRadii.EMPTY, Insets.EMPTY); + Background background = new Background(backgroundFill); title.setBackground(background); - i = attributes.iterator(); - while (i.hasNext()) { - textfield = (TextField) i.next(); - textfield.setPadding(new Insets(0)); - textfield.setBackground(background); + for (TextField tf: attributes) { + tf.setPadding(new Insets(0)); + tf.setBackground(background); } - i = operations.iterator(); - while (i.hasNext()) { - textfield = (TextField) i.next(); - textfield.setPadding(new Insets(0)); - textfield.setBackground(background); + for (TextField tf: operations) { + tf.setPadding(new Insets(0)); + tf.setBackground(background); } } @@ -287,7 +259,71 @@ public void setStroke(Paint p) { public Bounds getBounds(){ return container.getBoundsInParent(); } - + + private void createHandlesAttributesOperations(IdentifiedTextField tf, + List attributes, String type) { + tf.setOnKeyReleased(new EventHandler() { + public void handle(KeyEvent ke) { + IdentifiedTextField tf = (IdentifiedTextField) ke.getSource(); + String fullText = attributes.indexOf(tf) + ";" + tf.getXmiId() + "|" + tf.getText(); + if (type.equals("attribute")) { + ((ClassNode)getRefNode()).setAttributes(fullText); + } else { + ((ClassNode)getRefNode()).setOperations(fullText); + } + } + }); + MenuItem item1 = new MenuItem("Delete"); + item1.setUserData(tf); + item1.setOnAction(new EventHandler() { + public void handle(ActionEvent e) { + IdentifiedTextField tf = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); + String fullText = "-1;" + tf.getXmiId() + "|" + tf.getText(); + if (type.equals("attribute")) { + ((ClassNode)getRefNode()).setAttributes(fullText); + } else { + ((ClassNode)getRefNode()).setOperations(fullText); + } + } + }); + ContextMenu contextMenu = new ContextMenu(); + contextMenu.getItems().addAll(item1); + tf.setContextMenu(contextMenu); + } + + private IdentifiedTextField addAttributeOperationCommon() { + IdentifiedTextField textField = new IdentifiedTextField(""); + vbox.getChildren().add(textField); + + // initLooks + textField.setFont(Font.font("Verdana", 10)); + BackgroundFill backgroundFill = new BackgroundFill(Color.LIGHTSKYBLUE, CornerRadii.EMPTY, Insets.EMPTY); + Background background = new Background(backgroundFill); + textField.setPadding(new Insets(0)); + textField.setBackground(background); + + return textField; + } + + public void addAttribute() { + IdentifiedTextField textField = addAttributeOperationCommon(); + + // Create Handles + createHandlesAttributesOperations(textField, attributes, "attribute"); + + textField.setPromptText("-nome_do_atributo:Tipo"); + attributes.add(textField); + } + + public void addOperation() { + IdentifiedTextField textField = addAttributeOperationCommon(); + + // Create Handles + createHandlesAttributesOperations(textField, operations, "operation"); + + textField.setPromptText("+nome_da_operação()"); + operations.add(textField); + } @Override public void propertyChange(PropertyChangeEvent evt) { @@ -320,8 +356,7 @@ public void propertyChange(PropertyChangeEvent evt) { int ind = Integer.parseInt(array[0]); IdentifiedTextField remoteTextField = new IdentifiedTextField(array[1]); boolean found = false; - for (int index = 0; index < attributes.size(); index++) { - IdentifiedTextField localTextField = attributes.get(index); + for (IdentifiedTextField localTextField: attributes) { if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { found = true; if (ind != -1) { @@ -336,6 +371,7 @@ public void propertyChange(PropertyChangeEvent evt) { } } else { attributes.remove(localTextField); + vbox.getChildren().remove(localTextField); } break; } @@ -343,6 +379,7 @@ public void propertyChange(PropertyChangeEvent evt) { // New attribute if (!found) { attributes.add(ind,remoteTextField); + vbox.getChildren().add(remoteTextField); } } } else if (evt.getPropertyName().equals(Constants.changeClassNodeOperations)) { @@ -352,8 +389,7 @@ public void propertyChange(PropertyChangeEvent evt) { int ind = Integer.parseInt(array[0]); IdentifiedTextField remoteTextField = new IdentifiedTextField(array[1]); boolean found = false; - for (int index = 0; index < operations.size(); index++) { - IdentifiedTextField localTextField = operations.get(index); + for (IdentifiedTextField localTextField: operations) { if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { found = true; if (ind != -1) { @@ -368,6 +404,7 @@ public void propertyChange(PropertyChangeEvent evt) { } } else { operations.remove(localTextField); + vbox.getChildren().remove(localTextField); } break; } @@ -375,6 +412,7 @@ public void propertyChange(PropertyChangeEvent evt) { // New operation if (!found) { operations.add(ind,remoteTextField); + vbox.getChildren().add(remoteTextField); } } } From c233bf760487f06221fcd06749c11738ae41dbfd Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Tue, 1 May 2018 21:14:27 -0300 Subject: [PATCH 09/88] Partial implementation of detailed synchronization --- src/controller/AbstractDiagramController.java | 10 +---- src/view/nodes/ClassNodeView.java | 40 ++++++++++++++----- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/controller/AbstractDiagramController.java b/src/controller/AbstractDiagramController.java index 08abedb..31c6af3 100644 --- a/src/controller/AbstractDiagramController.java +++ b/src/controller/AbstractDiagramController.java @@ -588,14 +588,6 @@ private void initContextMenu() { deleteSelected(); }); - MenuItem cmItemAddAttribute = new MenuItem("Add attribute"); - cmItemAddAttribute.setOnAction(event -> { - if (aContextMenu.getOwnerNode() instanceof ClassNodeView) { - ClassNodeView classNodeView = (ClassNodeView) aContextMenu.getOwnerNode(); - classNodeView.addAttribute(); - } - }); - MenuItem cmItemCopy = new MenuItem("Copy"); cmItemCopy.setOnAction(e -> { copyPasteController.copy(); @@ -615,7 +607,7 @@ private void initContextMenu() { insertImg.openFileChooser(AbstractDiagramController.this, point); }); - aContextMenu.getItems().addAll(cmItemCopy, cmItemPaste, cmItemDelete, cmItemInsertImg, cmItemAddAttribute); + aContextMenu.getItems().addAll(cmItemCopy, cmItemPaste, cmItemDelete, cmItemInsertImg); } /** diff --git a/src/view/nodes/ClassNodeView.java b/src/view/nodes/ClassNodeView.java index 6f3cc0e..792003a 100644 --- a/src/view/nodes/ClassNodeView.java +++ b/src/view/nodes/ClassNodeView.java @@ -262,6 +262,7 @@ public Bounds getBounds(){ private void createHandlesAttributesOperations(IdentifiedTextField tf, List attributes, String type) { + tf.setOnKeyReleased(new EventHandler() { public void handle(KeyEvent ke) { IdentifiedTextField tf = (IdentifiedTextField) ke.getSource(); @@ -273,9 +274,10 @@ public void handle(KeyEvent ke) { } } }); - MenuItem item1 = new MenuItem("Delete"); - item1.setUserData(tf); - item1.setOnAction(new EventHandler() { + + MenuItem cmItemDelete = new MenuItem("Delete"); + cmItemDelete.setUserData(tf); + cmItemDelete.setOnAction(new EventHandler() { public void handle(ActionEvent e) { IdentifiedTextField tf = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); String fullText = "-1;" + tf.getXmiId() + "|" + tf.getText(); @@ -286,22 +288,37 @@ public void handle(ActionEvent e) { } } }); + + MenuItem cmItemAdd; + if (type.equals("attribute")) { + cmItemAdd = new MenuItem("Add attribute"); + cmItemAdd.setOnAction(event -> { + addAttribute(); + }); + } else { + cmItemAdd = new MenuItem("Add operation"); + cmItemAdd.setOnAction(event -> { + addOperation(); + }); + } + ContextMenu contextMenu = new ContextMenu(); - contextMenu.getItems().addAll(item1); + contextMenu.getItems().addAll(cmItemDelete,cmItemAdd); tf.setContextMenu(contextMenu); } - private IdentifiedTextField addAttributeOperationCommon() { - IdentifiedTextField textField = new IdentifiedTextField(""); - vbox.getChildren().add(textField); - - // initLooks + private void initLooksAttributeOperation(IdentifiedTextField textField) { textField.setFont(Font.font("Verdana", 10)); BackgroundFill backgroundFill = new BackgroundFill(Color.LIGHTSKYBLUE, CornerRadii.EMPTY, Insets.EMPTY); Background background = new Background(backgroundFill); textField.setPadding(new Insets(0)); - textField.setBackground(background); - + textField.setBackground(background); + } + + private IdentifiedTextField addAttributeOperationCommon() { + IdentifiedTextField textField = new IdentifiedTextField(""); + vbox.getChildren().add(textField); + initLooksAttributeOperation(textField); return textField; } @@ -380,6 +397,7 @@ public void propertyChange(PropertyChangeEvent evt) { if (!found) { attributes.add(ind,remoteTextField); vbox.getChildren().add(remoteTextField); + initLooksAttributeOperation(remoteTextField); } } } else if (evt.getPropertyName().equals(Constants.changeClassNodeOperations)) { From 8b595b64ddbd3fe5df275f5fdd78238ec762c9a6 Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Wed, 2 May 2018 00:29:17 -0300 Subject: [PATCH 10/88] Partial implementation of detailed synchronization --- src/model/nodes/ClassNode.java | 14 ++++++++++++++ src/view/nodes/ClassNodeView.java | 21 +++++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/model/nodes/ClassNode.java b/src/model/nodes/ClassNode.java index b0e246e..68e303c 100644 --- a/src/model/nodes/ClassNode.java +++ b/src/model/nodes/ClassNode.java @@ -3,6 +3,8 @@ import util.Constants; import java.io.Serializable; + +import model.IdentifiedTextField; /** * Represents a UML class. */ @@ -25,12 +27,24 @@ public void setAttributes(String pAttributes){ attributes = pAttributes; changes.firePropertyChange(Constants.changeClassNodeAttributes, null, attributes); remoteChanges.firePropertyChange(Constants.changeClassNodeAttributes, null, attributes); + int index = attributes.indexOf("-1;"); + if (index != -1) { + System.out.println("Before: "+attributes); + attributes = attributes.substring(0,index); + System.out.println("After: "+attributes); + } } public void setOperations(String pOperations){ operations = pOperations; changes.firePropertyChange(Constants.changeClassNodeOperations, null, operations); remoteChanges.firePropertyChange(Constants.changeClassNodeOperations, null, operations); + int index = operations.indexOf("-1;"); + if (index != -1) { + System.out.println("Before: "+operations); + attributes = operations.substring(0,index); + System.out.println("After: "+operations); + } } public void remoteSetAttributes(String pAttributes){ diff --git a/src/view/nodes/ClassNodeView.java b/src/view/nodes/ClassNodeView.java index 792003a..61b74ea 100644 --- a/src/view/nodes/ClassNodeView.java +++ b/src/view/nodes/ClassNodeView.java @@ -261,12 +261,14 @@ public Bounds getBounds(){ } private void createHandlesAttributesOperations(IdentifiedTextField tf, - List attributes, String type) { + List list, String type) { tf.setOnKeyReleased(new EventHandler() { public void handle(KeyEvent ke) { - IdentifiedTextField tf = (IdentifiedTextField) ke.getSource(); - String fullText = attributes.indexOf(tf) + ";" + tf.getXmiId() + "|" + tf.getText(); + String fullText = ""; + for (IdentifiedTextField tf: list) { + fullText = fullText + list.indexOf(tf) + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); + } if (type.equals("attribute")) { ((ClassNode)getRefNode()).setAttributes(fullText); } else { @@ -279,13 +281,19 @@ public void handle(KeyEvent ke) { cmItemDelete.setUserData(tf); cmItemDelete.setOnAction(new EventHandler() { public void handle(ActionEvent e) { - IdentifiedTextField tf = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); - String fullText = "-1;" + tf.getXmiId() + "|" + tf.getText(); + IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); + String fullText = ""; + for (IdentifiedTextField tf: list) { + if (!tf.equals(modifiedTextField)) { + fullText = fullText + list.indexOf(tf) + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); + } + } + fullText = fullText + "-1;" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); if (type.equals("attribute")) { ((ClassNode)getRefNode()).setAttributes(fullText); } else { ((ClassNode)getRefNode()).setOperations(fullText); - } + } } }); @@ -375,6 +383,7 @@ public void propertyChange(PropertyChangeEvent evt) { boolean found = false; for (IdentifiedTextField localTextField: attributes) { if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { + System.out.println("Found: "+ind+"|"+localTextField); found = true; if (ind != -1) { // Update text if it was altered From e985740d982d0b0d6ccb0c5af2654d158f61ed2e Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Wed, 2 May 2018 02:12:14 -0300 Subject: [PATCH 11/88] Partial implementation of detailed synchronization --- src/controller/AbstractDiagramController.java | 16 ++++++++++++ src/model/nodes/ClassNode.java | 4 --- src/view/nodes/ClassNodeView.java | 25 +++++++++---------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/controller/AbstractDiagramController.java b/src/controller/AbstractDiagramController.java index 31c6af3..0e6886b 100644 --- a/src/controller/AbstractDiagramController.java +++ b/src/controller/AbstractDiagramController.java @@ -606,8 +606,24 @@ private void initContextMenu() { InsertIMG insertImg = new InsertIMG(aStage, drawPane); insertImg.openFileChooser(AbstractDiagramController.this, point); }); + + MenuItem cmItemAddAttribute= new MenuItem("Add attribute"); + cmItemAddAttribute.setOnAction(event -> { + if (aContextMenu.getOwnerNode() instanceof ClassNodeView) { + ((ClassNodeView) aContextMenu.getOwnerNode()).addAttribute(); + } + }); + MenuItem cmItemAddOperation = new MenuItem("Add operation"); + cmItemAddOperation.setOnAction(event -> { + if (aContextMenu.getOwnerNode() instanceof ClassNodeView) { + ((ClassNodeView) aContextMenu.getOwnerNode()).addOperation(); + } + }); + + aContextMenu.getItems().addAll(cmItemCopy, cmItemPaste, cmItemDelete, cmItemInsertImg); + aContextMenu.getItems().addAll(cmItemAddAttribute,cmItemAddOperation); } /** diff --git a/src/model/nodes/ClassNode.java b/src/model/nodes/ClassNode.java index 68e303c..52b12d3 100644 --- a/src/model/nodes/ClassNode.java +++ b/src/model/nodes/ClassNode.java @@ -29,9 +29,7 @@ public void setAttributes(String pAttributes){ remoteChanges.firePropertyChange(Constants.changeClassNodeAttributes, null, attributes); int index = attributes.indexOf("-1;"); if (index != -1) { - System.out.println("Before: "+attributes); attributes = attributes.substring(0,index); - System.out.println("After: "+attributes); } } @@ -41,9 +39,7 @@ public void setOperations(String pOperations){ remoteChanges.firePropertyChange(Constants.changeClassNodeOperations, null, operations); int index = operations.indexOf("-1;"); if (index != -1) { - System.out.println("Before: "+operations); attributes = operations.substring(0,index); - System.out.println("After: "+operations); } } diff --git a/src/view/nodes/ClassNodeView.java b/src/view/nodes/ClassNodeView.java index 61b74ea..4e878fd 100644 --- a/src/view/nodes/ClassNodeView.java +++ b/src/view/nodes/ClassNodeView.java @@ -8,6 +8,7 @@ import javafx.geometry.Insets; import javafx.geometry.Pos; +import javafx.scene.Node; import javafx.scene.control.ContextMenu; import javafx.scene.control.Label; import javafx.scene.control.MenuItem; @@ -323,15 +324,11 @@ private void initLooksAttributeOperation(IdentifiedTextField textField) { textField.setBackground(background); } - private IdentifiedTextField addAttributeOperationCommon() { - IdentifiedTextField textField = new IdentifiedTextField(""); - vbox.getChildren().add(textField); - initLooksAttributeOperation(textField); - return textField; - } public void addAttribute() { - IdentifiedTextField textField = addAttributeOperationCommon(); + IdentifiedTextField textField = new IdentifiedTextField(""); + initLooksAttributeOperation(textField); + vbox.getChildren().add(2+attributes.size(),textField); // Create Handles createHandlesAttributesOperations(textField, attributes, "attribute"); @@ -341,8 +338,10 @@ public void addAttribute() { } public void addOperation() { - IdentifiedTextField textField = addAttributeOperationCommon(); - + IdentifiedTextField textField = new IdentifiedTextField(""); + initLooksAttributeOperation(textField); + vbox.getChildren().add(2+attributes.size()+1+operations.size(),textField); + // Create Handles createHandlesAttributesOperations(textField, operations, "operation"); @@ -372,7 +371,7 @@ public void propertyChange(PropertyChangeEvent evt) { if (title.getText() == null || title.getText().equals("")) { firstLine.setVisible(false); } else { - firstLine.setVisible(true); + firstLine.setVisible(true); } } else if (evt.getPropertyName().equals(Constants.changeClassNodeAttributes)) { String newValue = (String) evt.getNewValue(); @@ -383,7 +382,6 @@ public void propertyChange(PropertyChangeEvent evt) { boolean found = false; for (IdentifiedTextField localTextField: attributes) { if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { - System.out.println("Found: "+ind+"|"+localTextField); found = true; if (ind != -1) { // Update text if it was altered @@ -405,7 +403,7 @@ public void propertyChange(PropertyChangeEvent evt) { // New attribute if (!found) { attributes.add(ind,remoteTextField); - vbox.getChildren().add(remoteTextField); + vbox.getChildren().add(2+ind,remoteTextField); initLooksAttributeOperation(remoteTextField); } } @@ -439,7 +437,8 @@ public void propertyChange(PropertyChangeEvent evt) { // New operation if (!found) { operations.add(ind,remoteTextField); - vbox.getChildren().add(remoteTextField); + vbox.getChildren().add(2+attributes.size()+1+ind,remoteTextField); + initLooksAttributeOperation(remoteTextField); } } } From fc5cfcbdceea4deb22874cf9b944ebdce10b3daa Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Wed, 2 May 2018 02:52:02 -0300 Subject: [PATCH 12/88] Partial implementation of detailed synchronization --- src/view/nodes/ClassNodeView.java | 51 +++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/view/nodes/ClassNodeView.java b/src/view/nodes/ClassNodeView.java index 4e878fd..1a234a0 100644 --- a/src/view/nodes/ClassNodeView.java +++ b/src/view/nodes/ClassNodeView.java @@ -298,6 +298,40 @@ public void handle(ActionEvent e) { } }); + MenuItem cmItemMoveUp; + cmItemMoveUp = new MenuItem("Move Up"); + cmItemMoveUp.setUserData(tf); + MenuItem cmItemMoveDown; + cmItemMoveDown = new MenuItem("Move Up"); + cmItemMoveDown.setUserData(tf); + if (type.equals("attribute")) { + cmItemMoveUp.setOnAction(new EventHandler() { + public void handle(ActionEvent e) { + IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); + attributeMoveUp(modifiedTextField); + } + }); + cmItemMoveDown.setOnAction(new EventHandler() { + public void handle(ActionEvent e) { + IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); + attributeMoveDown(modifiedTextField); + } + }); + } else { + cmItemMoveUp.setOnAction(new EventHandler() { + public void handle(ActionEvent e) { + IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); + operationMoveUp(modifiedTextField); + } + }); + cmItemMoveDown.setOnAction(new EventHandler() { + public void handle(ActionEvent e) { + IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); + operationMoveDown(modifiedTextField); + } + }); + } + MenuItem cmItemAdd; if (type.equals("attribute")) { cmItemAdd = new MenuItem("Add attribute"); @@ -316,8 +350,25 @@ public void handle(ActionEvent e) { tf.setContextMenu(contextMenu); } + private void attributeMoveUp(IdentifiedTextField textField) { + + } + + private void attributeMoveDown(IdentifiedTextField textField) { + + } + + private void operationMoveUp(IdentifiedTextField textField) { + + } + + private void operationMoveDown(IdentifiedTextField textField) { + + } + private void initLooksAttributeOperation(IdentifiedTextField textField) { textField.setFont(Font.font("Verdana", 10)); + textField.setStyle("-fx-prompt-text-fill: black"); BackgroundFill backgroundFill = new BackgroundFill(Color.LIGHTSKYBLUE, CornerRadii.EMPTY, Insets.EMPTY); Background background = new Background(backgroundFill); textField.setPadding(new Insets(0)); From 3f05985442f082c243293b977cf4fe5dc3d325bf Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Wed, 2 May 2018 04:23:42 -0300 Subject: [PATCH 13/88] Complete implementation of detailed synchronization --- src/view/nodes/ClassNodeView.java | 150 +++++++++++++++++------------- 1 file changed, 86 insertions(+), 64 deletions(-) diff --git a/src/view/nodes/ClassNodeView.java b/src/view/nodes/ClassNodeView.java index 1a234a0..be86c97 100644 --- a/src/view/nodes/ClassNodeView.java +++ b/src/view/nodes/ClassNodeView.java @@ -278,60 +278,67 @@ public void handle(KeyEvent ke) { } }); - MenuItem cmItemDelete = new MenuItem("Delete"); - cmItemDelete.setUserData(tf); - cmItemDelete.setOnAction(new EventHandler() { + MenuItem cmItemMoveUp; + cmItemMoveUp = new MenuItem("Move Up"); + cmItemMoveUp.setUserData(tf); + cmItemMoveUp.setOnAction(new EventHandler() { public void handle(ActionEvent e) { - IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); + IdentifiedTextField textField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); + System.out.println("textField:"+textField); String fullText = ""; - for (IdentifiedTextField tf: list) { - if (!tf.equals(modifiedTextField)) { + int index = list.indexOf(textField); + System.out.println("index("+index+" > 0"); + if (index > 0) { + index--; + list.remove(textField); + list.add(index,textField); + for (IdentifiedTextField tf: list) { fullText = fullText + list.indexOf(tf) + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); - } - } - fullText = fullText + "-1;" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); - if (type.equals("attribute")) { - ((ClassNode)getRefNode()).setAttributes(fullText); - } else { - ((ClassNode)getRefNode()).setOperations(fullText); - } + } + System.out.println("fullText:"+fullText); + if (type.equals("attribute")) { + vbox.getChildren().remove(textField); + vbox.getChildren().add(2+index,textField); + ((ClassNode)getRefNode()).setAttributes(fullText); + } else { + vbox.getChildren().remove(textField); + vbox.getChildren().add(2+attributes.size()+1+index,textField); + ((ClassNode)getRefNode()).setOperations(fullText); + } + } } - }); - - MenuItem cmItemMoveUp; - cmItemMoveUp = new MenuItem("Move Up"); - cmItemMoveUp.setUserData(tf); + }); MenuItem cmItemMoveDown; - cmItemMoveDown = new MenuItem("Move Up"); + cmItemMoveDown = new MenuItem("Move Down"); cmItemMoveDown.setUserData(tf); - if (type.equals("attribute")) { - cmItemMoveUp.setOnAction(new EventHandler() { - public void handle(ActionEvent e) { - IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); - attributeMoveUp(modifiedTextField); - } - }); - cmItemMoveDown.setOnAction(new EventHandler() { - public void handle(ActionEvent e) { - IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); - attributeMoveDown(modifiedTextField); - } - }); - } else { - cmItemMoveUp.setOnAction(new EventHandler() { - public void handle(ActionEvent e) { - IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); - operationMoveUp(modifiedTextField); - } - }); - cmItemMoveDown.setOnAction(new EventHandler() { - public void handle(ActionEvent e) { - IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); - operationMoveDown(modifiedTextField); - } - }); - } - + cmItemMoveDown.setOnAction(new EventHandler() { + public void handle(ActionEvent e) { + IdentifiedTextField textField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); + System.out.println("textField:"+textField); + String fullText = ""; + int index = list.indexOf(textField); + System.out.println("index("+index+" < list.size("+list.size()+")"); + if (index < list.size()-1) { + index++; + list.remove(textField); + list.add(index,textField); + for (IdentifiedTextField tf: list) { + fullText = fullText + list.indexOf(tf) + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); + } + System.out.println("fullText:"+fullText); + if (type.equals("attribute")) { + vbox.getChildren().remove(textField); + vbox.getChildren().add(2+index,textField); + ((ClassNode)getRefNode()).setAttributes(fullText); + } else { + vbox.getChildren().remove(textField); + vbox.getChildren().add(2+attributes.size()+1+index,textField); + ((ClassNode)getRefNode()).setOperations(fullText); + } + } + } + }); + MenuItem cmItemAdd; if (type.equals("attribute")) { cmItemAdd = new MenuItem("Add attribute"); @@ -345,26 +352,36 @@ public void handle(ActionEvent e) { }); } + MenuItem cmItemDelete; + if (type.equals("attribute")) { + cmItemDelete = new MenuItem("Delete attribute"); + } else { + cmItemDelete = new MenuItem("Delete operation"); + } + cmItemDelete.setUserData(tf); + cmItemDelete.setOnAction(new EventHandler() { + public void handle(ActionEvent e) { + IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); + String fullText = ""; + for (IdentifiedTextField tf: list) { + if (!tf.equals(modifiedTextField)) { + fullText = fullText + list.indexOf(tf) + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); + } + } + fullText = fullText + "-1;" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); + if (type.equals("attribute")) { + ((ClassNode)getRefNode()).setAttributes(fullText); + } else { + ((ClassNode)getRefNode()).setOperations(fullText); + } + } + }); + ContextMenu contextMenu = new ContextMenu(); - contextMenu.getItems().addAll(cmItemDelete,cmItemAdd); + contextMenu.getItems().addAll(cmItemMoveUp,cmItemMoveDown,cmItemAdd,cmItemDelete); tf.setContextMenu(contextMenu); } - - private void attributeMoveUp(IdentifiedTextField textField) { - - } - - private void attributeMoveDown(IdentifiedTextField textField) { - - } - - private void operationMoveUp(IdentifiedTextField textField) { - - } - private void operationMoveDown(IdentifiedTextField textField) { - - } private void initLooksAttributeOperation(IdentifiedTextField textField) { textField.setFont(Font.font("Verdana", 10)); @@ -443,6 +460,9 @@ public void propertyChange(PropertyChangeEvent evt) { if (attributes.indexOf(localTextField) != ind) { attributes.remove(localTextField); attributes.add(ind,localTextField); + vbox.getChildren().remove(localTextField); + vbox.getChildren().add(2+ind,localTextField); + } } else { attributes.remove(localTextField); @@ -477,6 +497,8 @@ public void propertyChange(PropertyChangeEvent evt) { if (operations.indexOf(localTextField) != ind) { operations.remove(localTextField); operations.add(ind,localTextField); + vbox.getChildren().remove(localTextField); + vbox.getChildren().add(2+attributes.size()+1+ind,localTextField); } } else { operations.remove(localTextField); From 7c54de15ccc439a6fa1f88ae082cb4763c375fab Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Wed, 2 May 2018 20:27:06 -0300 Subject: [PATCH 14/88] Refactoring of implementation of detailed synchronization --- src/model/nodes/Attribute.java | 8 + src/model/nodes/ClassNode.java | 2 - .../{ => nodes}/IdentifiedTextField.java | 2 +- src/model/nodes/Operation.java | 8 + src/util/persistence/PersistenceManager.java | 1 + src/view/nodes/ClassNodeView.java | 383 ++++++++++-------- 6 files changed, 232 insertions(+), 172 deletions(-) create mode 100644 src/model/nodes/Attribute.java rename src/model/{ => nodes}/IdentifiedTextField.java (98%) create mode 100644 src/model/nodes/Operation.java diff --git a/src/model/nodes/Attribute.java b/src/model/nodes/Attribute.java new file mode 100644 index 0000000..a404ff2 --- /dev/null +++ b/src/model/nodes/Attribute.java @@ -0,0 +1,8 @@ +package model.nodes; + +public class Attribute extends IdentifiedTextField { + public Attribute(String text) { + super(text); + setPromptText("-nome_do_atributo:Tipo"); + } +} diff --git a/src/model/nodes/ClassNode.java b/src/model/nodes/ClassNode.java index 52b12d3..b8966ce 100644 --- a/src/model/nodes/ClassNode.java +++ b/src/model/nodes/ClassNode.java @@ -3,8 +3,6 @@ import util.Constants; import java.io.Serializable; - -import model.IdentifiedTextField; /** * Represents a UML class. */ diff --git a/src/model/IdentifiedTextField.java b/src/model/nodes/IdentifiedTextField.java similarity index 98% rename from src/model/IdentifiedTextField.java rename to src/model/nodes/IdentifiedTextField.java index 0e0928d..5ad4289 100644 --- a/src/model/IdentifiedTextField.java +++ b/src/model/nodes/IdentifiedTextField.java @@ -1,4 +1,4 @@ -package model; +package model.nodes; import java.util.UUID; diff --git a/src/model/nodes/Operation.java b/src/model/nodes/Operation.java new file mode 100644 index 0000000..058c9b7 --- /dev/null +++ b/src/model/nodes/Operation.java @@ -0,0 +1,8 @@ +package model.nodes; + +public class Operation extends IdentifiedTextField { + public Operation(String text) { + super(text); + setPromptText("+nome_da_operação()"); + } +} diff --git a/src/util/persistence/PersistenceManager.java b/src/util/persistence/PersistenceManager.java index e520068..3442392 100644 --- a/src/util/persistence/PersistenceManager.java +++ b/src/util/persistence/PersistenceManager.java @@ -8,6 +8,7 @@ import model.edges.*; import model.nodes.AbstractNode; import model.nodes.ClassNode; +import model.nodes.IdentifiedTextField; import model.nodes.PackageNode; import org.w3c.dom.Document; import org.w3c.dom.Element; diff --git a/src/view/nodes/ClassNodeView.java b/src/view/nodes/ClassNodeView.java index be86c97..f882284 100644 --- a/src/view/nodes/ClassNodeView.java +++ b/src/view/nodes/ClassNodeView.java @@ -29,8 +29,10 @@ import javafx.scene.control.TextField; import javafx.scene.input.KeyEvent; import javafx.scene.input.MouseEvent; -import model.IdentifiedTextField; +import model.nodes.Attribute; import model.nodes.ClassNode; +import model.nodes.IdentifiedTextField; +import model.nodes.Operation; import util.Constants; import java.beans.PropertyChangeEvent; @@ -47,8 +49,6 @@ public class ClassNodeView extends AbstractNodeView implements NodeView { private TextField title; - private List attributes; - private List operations; private Rectangle rectangle; @@ -115,20 +115,14 @@ private void changeWidth(double width){ title.setMaxWidth(width); title.setPrefWidth(width); - - TextField textField; - Iterator i = attributes.iterator(); - while (i.hasNext()) { - textField = (TextField) i.next(); - textField.setMaxWidth(width); - textField.setPrefWidth(width); - } - i = operations.iterator(); - while (i.hasNext()) { - textField = (TextField) i.next(); - textField.setMaxWidth(width); - textField.setPrefWidth(width); - } + + for(Node node: vbox.getChildren()) { + if (node instanceof Attribute || node instanceof Operation) { + TextField tf = (TextField) node; + tf.setMaxWidth(width); + tf.setPrefWidth(width); + } + } } private void createHandles(){ @@ -154,11 +148,13 @@ public void changed(ObservableValue observable, System.out.println("Title changed to " + newValue + ")\n"); } }); - for (IdentifiedTextField textField: attributes) { - createHandlesAttributesOperations(textField, attributes, "attribute"); - } - for (IdentifiedTextField textField: operations) { - createHandlesAttributesOperations(textField, operations, "operation"); + for(Node node: vbox.getChildren()) { + if (node instanceof Attribute) { + createHandlesAttributesOperations((Attribute) node); + } + if (node instanceof Operation) { + createHandlesAttributesOperations((Operation) node); + } } } @@ -182,39 +178,39 @@ private void initVBox(){ title.setText(node.getTitle()); } title.setAlignment(Pos.CENTER); + + titlePane.getChildren().add(title); + vbox.getChildren().addAll(titlePane, firstLine); - attributes = new ArrayList<>(); if (node.getAttributes() != null) { for(String text : node.getAttributes().split("\\r?\\n")){ if (text.contains(";")) { text = text.substring(text.indexOf(";")+1); } - IdentifiedTextField textfield = new IdentifiedTextField(text); - textfield.setFont(Font.font("Verdana", 10)); - attributes.add(textfield); + Attribute attribute = new Attribute(text); + attribute.setFont(Font.font("Verdana", 10)); + vbox.getChildren().add(attribute); } } - operations = new ArrayList<>(); + + vbox.getChildren().addAll(secondLine); + if (node.getOperations() != null) { for(String text : node.getOperations().split("\\r?\\n")){ if (text.contains(";")) { text = text.substring(text.indexOf(";")+1); } - IdentifiedTextField textfield = new IdentifiedTextField(text); - textfield.setFont(Font.font("Verdana", 10)); - operations.add(textfield); + Operation operation = new Operation(text); + operation.setFont(Font.font("Verdana", 10)); + vbox.getChildren().add(operation); } } - if(operations.isEmpty()){ + if (operationsSize() > 0) { + secondLine.setVisible(true); + } else { secondLine.setVisible(false); } - - titlePane.getChildren().add(title); - vbox.getChildren().addAll(titlePane, firstLine); - vbox.getChildren().addAll(attributes); - vbox.getChildren().addAll(secondLine); - vbox.getChildren().addAll(operations); } private void initLooks(){ @@ -225,14 +221,13 @@ private void initLooks(){ BackgroundFill backgroundFill = new BackgroundFill(Color.LIGHTSKYBLUE, CornerRadii.EMPTY, Insets.EMPTY); Background background = new Background(backgroundFill); title.setBackground(background); - for (TextField tf: attributes) { - tf.setPadding(new Insets(0)); - tf.setBackground(background); - } - for (TextField tf: operations) { - tf.setPadding(new Insets(0)); - tf.setBackground(background); - } + for(Node node: vbox.getChildren()) { + if (node instanceof Attribute || node instanceof Operation) { + TextField tf = (TextField) node; + tf.setPadding(new Insets(0)); + tf.setBackground(background); + } + } } public void setSelected(boolean selected){ @@ -261,18 +256,49 @@ public Bounds getBounds(){ return container.getBoundsInParent(); } - private void createHandlesAttributesOperations(IdentifiedTextField tf, - List list, String type) { + private int attributesSize() { + int cont = 0; + for(Node node: vbox.getChildren()) { + if (node instanceof Attribute) { + cont++; + } + } + return cont; + } + + private int operationsSize() { + int cont = 0; + for(Node node: vbox.getChildren()) { + if (node instanceof Operation) { + cont++; + } + } + return cont; + } + + + private void createHandlesAttributesOperations(IdentifiedTextField textfield) { - tf.setOnKeyReleased(new EventHandler() { + textfield.setOnKeyReleased(new EventHandler() { public void handle(KeyEvent ke) { String fullText = ""; - for (IdentifiedTextField tf: list) { - fullText = fullText + list.indexOf(tf) + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); - } - if (type.equals("attribute")) { + if (textfield instanceof Attribute) { + for(Node node: vbox.getChildren()) { + if (node instanceof Attribute) { + IdentifiedTextField tf = (IdentifiedTextField) node; + fullText = fullText + vbox.getChildren().indexOf(tf) + + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); + } + } ((ClassNode)getRefNode()).setAttributes(fullText); - } else { + } else if (textfield instanceof Operation) { + for(Node node: vbox.getChildren()) { + if (node instanceof Operation) { + IdentifiedTextField tf = (IdentifiedTextField) node; + fullText = fullText + vbox.getChildren().indexOf(tf) + + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); + } + } ((ClassNode)getRefNode()).setOperations(fullText); } } @@ -280,67 +306,77 @@ public void handle(KeyEvent ke) { MenuItem cmItemMoveUp; cmItemMoveUp = new MenuItem("Move Up"); - cmItemMoveUp.setUserData(tf); + cmItemMoveUp.setUserData(textfield); cmItemMoveUp.setOnAction(new EventHandler() { public void handle(ActionEvent e) { - IdentifiedTextField textField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); - System.out.println("textField:"+textField); + IdentifiedTextField tf = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); String fullText = ""; - int index = list.indexOf(textField); - System.out.println("index("+index+" > 0"); - if (index > 0) { + int index = vbox.getChildren().indexOf(tf); + System.out.println("textfield instanceof Attribute && "+index+" > 2"); + if (textfield instanceof Attribute && index > 2) { index--; - list.remove(textField); - list.add(index,textField); - for (IdentifiedTextField tf: list) { - fullText = fullText + list.indexOf(tf) + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); - } - System.out.println("fullText:"+fullText); - if (type.equals("attribute")) { - vbox.getChildren().remove(textField); - vbox.getChildren().add(2+index,textField); - ((ClassNode)getRefNode()).setAttributes(fullText); - } else { - vbox.getChildren().remove(textField); - vbox.getChildren().add(2+attributes.size()+1+index,textField); - ((ClassNode)getRefNode()).setOperations(fullText); - } - } + vbox.getChildren().remove(tf); + vbox.getChildren().add(index,tf); + for(Node node: vbox.getChildren()) { + if (node instanceof Attribute) { + fullText = fullText + vbox.getChildren().indexOf(tf) + ";" + tf.getXmiId() + + "|" + tf.getText() + System.getProperty("line.separator"); + } + } + ((ClassNode)getRefNode()).setAttributes(fullText); + } else if (textfield instanceof Operation && index > (3+attributesSize())) { + System.out.println("textfield instanceof Operation && "+index+" > "+(3+attributesSize())); + index--; + vbox.getChildren().remove(tf); + vbox.getChildren().add(index,tf); + for(Node node: vbox.getChildren()) { + if (node instanceof Operation) { + fullText = fullText + vbox.getChildren().indexOf(tf) + ";" + tf.getXmiId() + + "|" + tf.getText() + System.getProperty("line.separator"); + } + } + ((ClassNode)getRefNode()).setOperations(fullText); + } } }); MenuItem cmItemMoveDown; cmItemMoveDown = new MenuItem("Move Down"); - cmItemMoveDown.setUserData(tf); + cmItemMoveDown.setUserData(textfield); cmItemMoveDown.setOnAction(new EventHandler() { public void handle(ActionEvent e) { - IdentifiedTextField textField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); - System.out.println("textField:"+textField); + IdentifiedTextField tf = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); String fullText = ""; - int index = list.indexOf(textField); - System.out.println("index("+index+" < list.size("+list.size()+")"); - if (index < list.size()-1) { + int index = vbox.getChildren().indexOf(tf); + System.out.println("textfield instanceof Attribute && "+index+" < "+(1+attributesSize())); + if (textfield instanceof Attribute && index < (1+attributesSize())) { index++; - list.remove(textField); - list.add(index,textField); - for (IdentifiedTextField tf: list) { - fullText = fullText + list.indexOf(tf) + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); + vbox.getChildren().remove(tf); + vbox.getChildren().add(index,tf); + for(Node node: vbox.getChildren()) { + if (node instanceof Attribute) { + fullText = fullText + vbox.getChildren().indexOf(tf) + ";" + tf.getXmiId() + + "|" + tf.getText() + System.getProperty("line.separator"); + } } - System.out.println("fullText:"+fullText); - if (type.equals("attribute")) { - vbox.getChildren().remove(textField); - vbox.getChildren().add(2+index,textField); - ((ClassNode)getRefNode()).setAttributes(fullText); - } else { - vbox.getChildren().remove(textField); - vbox.getChildren().add(2+attributes.size()+1+index,textField); - ((ClassNode)getRefNode()).setOperations(fullText); - } - } + ((ClassNode)getRefNode()).setAttributes(fullText); + } else if (textfield instanceof Operation && index < (2+attributesSize()+operationsSize())) { + System.out.println("textfield instanceof Operation && "+index+" < "+(2+attributesSize()+operationsSize())); + index++; + vbox.getChildren().remove(tf); + vbox.getChildren().add(index,tf); + for(Node node: vbox.getChildren()) { + if (node instanceof Operation) { + fullText = fullText + vbox.getChildren().indexOf(tf) + ";" + tf.getXmiId() + + "|" + tf.getText() + System.getProperty("line.separator"); + } + } + ((ClassNode)getRefNode()).setOperations(fullText); + } } }); MenuItem cmItemAdd; - if (type.equals("attribute")) { + if (textfield instanceof Attribute) { cmItemAdd = new MenuItem("Add attribute"); cmItemAdd.setOnAction(event -> { addAttribute(); @@ -353,25 +389,46 @@ public void handle(ActionEvent e) { } MenuItem cmItemDelete; - if (type.equals("attribute")) { + if (textfield instanceof Attribute) { cmItemDelete = new MenuItem("Delete attribute"); - } else { + } else { cmItemDelete = new MenuItem("Delete operation"); } - cmItemDelete.setUserData(tf); + cmItemDelete.setUserData(textfield); cmItemDelete.setOnAction(new EventHandler() { public void handle(ActionEvent e) { IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); String fullText = ""; - for (IdentifiedTextField tf: list) { - if (!tf.equals(modifiedTextField)) { - fullText = fullText + list.indexOf(tf) + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); - } - } - fullText = fullText + "-1;" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); - if (type.equals("attribute")) { + if (textfield instanceof Attribute) { + for (Node node: vbox.getChildren()) { + if (node instanceof Attribute) { + IdentifiedTextField tf = (IdentifiedTextField) node; + if (!tf.equals(modifiedTextField)) { + fullText = fullText + vbox.getChildren().indexOf(tf) + + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); + } + } + } + fullText = fullText + "-1;" + modifiedTextField.getXmiId() + + "|" + modifiedTextField.getText() + System.getProperty("line.separator"); ((ClassNode)getRefNode()).setAttributes(fullText); } else { + for (Node node: vbox.getChildren()) { + if (node instanceof Operation) { + IdentifiedTextField tf = (IdentifiedTextField) node; + if (!tf.equals(modifiedTextField)) { + fullText = fullText + vbox.getChildren().indexOf(tf) + + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); + } + } + } + fullText = fullText + "-1;" + modifiedTextField.getXmiId() + + "|" + modifiedTextField.getText() + System.getProperty("line.separator"); + if (operationsSize() > 0) { + secondLine.setVisible(true); + } else { + secondLine.setVisible(false); + } ((ClassNode)getRefNode()).setOperations(fullText); } } @@ -379,13 +436,13 @@ public void handle(ActionEvent e) { ContextMenu contextMenu = new ContextMenu(); contextMenu.getItems().addAll(cmItemMoveUp,cmItemMoveDown,cmItemAdd,cmItemDelete); - tf.setContextMenu(contextMenu); + textfield.setContextMenu(contextMenu); } private void initLooksAttributeOperation(IdentifiedTextField textField) { textField.setFont(Font.font("Verdana", 10)); - textField.setStyle("-fx-prompt-text-fill: black"); + textField.setStyle("-fx-prompt-text-fill: white"); BackgroundFill backgroundFill = new BackgroundFill(Color.LIGHTSKYBLUE, CornerRadii.EMPTY, Insets.EMPTY); Background background = new Background(backgroundFill); textField.setPadding(new Insets(0)); @@ -394,27 +451,17 @@ private void initLooksAttributeOperation(IdentifiedTextField textField) { public void addAttribute() { - IdentifiedTextField textField = new IdentifiedTextField(""); + Attribute textField = new Attribute(""); initLooksAttributeOperation(textField); - vbox.getChildren().add(2+attributes.size(),textField); - - // Create Handles - createHandlesAttributesOperations(textField, attributes, "attribute"); - - textField.setPromptText("-nome_do_atributo:Tipo"); - attributes.add(textField); + vbox.getChildren().add(2+attributesSize(),textField); + createHandlesAttributesOperations(textField); } public void addOperation() { - IdentifiedTextField textField = new IdentifiedTextField(""); + Operation textField = new Operation(""); initLooksAttributeOperation(textField); - vbox.getChildren().add(2+attributes.size()+1+operations.size(),textField); - - // Create Handles - createHandlesAttributesOperations(textField, operations, "operation"); - - textField.setPromptText("+nome_da_operação()"); - operations.add(textField); + vbox.getChildren().add(textField); + createHandlesAttributesOperations(textField); } @Override @@ -448,33 +495,32 @@ public void propertyChange(PropertyChangeEvent evt) { int ind = Integer.parseInt(array[0]); IdentifiedTextField remoteTextField = new IdentifiedTextField(array[1]); boolean found = false; - for (IdentifiedTextField localTextField: attributes) { - if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { - found = true; - if (ind != -1) { - // Update text if it was altered - if (!localTextField.getText().equals(remoteTextField.getText())) { - localTextField.setText(remoteTextField.getText()); - } - // If moved upper or down - if (attributes.indexOf(localTextField) != ind) { - attributes.remove(localTextField); - attributes.add(ind,localTextField); - vbox.getChildren().remove(localTextField); - vbox.getChildren().add(2+ind,localTextField); - + for (Node node: vbox.getChildren()) { + if (node instanceof Attribute) { + IdentifiedTextField localTextField = (IdentifiedTextField) node; + if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { + found = true; + if (ind != -1) { + // Update text if it was altered + if (!localTextField.getText().equals(remoteTextField.getText())) { + localTextField.setText(remoteTextField.getText()); + } + // If moved upper or down + if (vbox.getChildren().indexOf(localTextField) != ind) { + vbox.getChildren().remove(localTextField); + vbox.getChildren().add(2+ind,localTextField); + + } + } else { + vbox.getChildren().remove(localTextField); } - } else { - attributes.remove(localTextField); - vbox.getChildren().remove(localTextField); - } - break; + break; + } } } // New attribute if (!found) { - attributes.add(ind,remoteTextField); - vbox.getChildren().add(2+ind,remoteTextField); + vbox.getChildren().add(ind,remoteTextField); initLooksAttributeOperation(remoteTextField); } } @@ -485,32 +531,31 @@ public void propertyChange(PropertyChangeEvent evt) { int ind = Integer.parseInt(array[0]); IdentifiedTextField remoteTextField = new IdentifiedTextField(array[1]); boolean found = false; - for (IdentifiedTextField localTextField: operations) { - if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { - found = true; - if (ind != -1) { - // Update text if it was altered - if (!localTextField.getText().equals(remoteTextField.getText())) { - localTextField.setText(remoteTextField.getText()); - } - // If moved upper or down - if (operations.indexOf(localTextField) != ind) { - operations.remove(localTextField); - operations.add(ind,localTextField); - vbox.getChildren().remove(localTextField); - vbox.getChildren().add(2+attributes.size()+1+ind,localTextField); - } - } else { - operations.remove(localTextField); - vbox.getChildren().remove(localTextField); - } - break; + for (Node node: vbox.getChildren()) { + if (node instanceof Operation) { + IdentifiedTextField localTextField = (IdentifiedTextField) node; + if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { + found = true; + if (ind != -1) { + // Update text if it was altered + if (!localTextField.getText().equals(remoteTextField.getText())) { + localTextField.setText(remoteTextField.getText()); + } + // If moved upper or down + if (vbox.getChildren().indexOf(localTextField) != ind) { + vbox.getChildren().remove(localTextField); + vbox.getChildren().add(2+attributesSize()+1+ind,localTextField); + } + } else { + vbox.getChildren().remove(localTextField); + } + break; + } } } // New operation if (!found) { - operations.add(ind,remoteTextField); - vbox.getChildren().add(2+attributes.size()+1+ind,remoteTextField); + vbox.getChildren().add(ind,remoteTextField); initLooksAttributeOperation(remoteTextField); } } From 3218dd0e07690540fcebae73e2b6adb814f9230f Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Thu, 3 May 2018 00:24:37 -0300 Subject: [PATCH 15/88] Refactoring of implementation of detailed synchronization --- src/model/nodes/ClassNode.java | 8 -- src/view/nodes/ClassNodeView.java | 172 ++++++++++++++++++------------ 2 files changed, 105 insertions(+), 75 deletions(-) diff --git a/src/model/nodes/ClassNode.java b/src/model/nodes/ClassNode.java index b8966ce..b0e246e 100644 --- a/src/model/nodes/ClassNode.java +++ b/src/model/nodes/ClassNode.java @@ -25,20 +25,12 @@ public void setAttributes(String pAttributes){ attributes = pAttributes; changes.firePropertyChange(Constants.changeClassNodeAttributes, null, attributes); remoteChanges.firePropertyChange(Constants.changeClassNodeAttributes, null, attributes); - int index = attributes.indexOf("-1;"); - if (index != -1) { - attributes = attributes.substring(0,index); - } } public void setOperations(String pOperations){ operations = pOperations; changes.firePropertyChange(Constants.changeClassNodeOperations, null, operations); remoteChanges.firePropertyChange(Constants.changeClassNodeOperations, null, operations); - int index = operations.indexOf("-1;"); - if (index != -1) { - attributes = operations.substring(0,index); - } } public void remoteSetAttributes(String pAttributes){ diff --git a/src/view/nodes/ClassNodeView.java b/src/view/nodes/ClassNodeView.java index f882284..951250f 100644 --- a/src/view/nodes/ClassNodeView.java +++ b/src/view/nodes/ClassNodeView.java @@ -309,16 +309,17 @@ public void handle(KeyEvent ke) { cmItemMoveUp.setUserData(textfield); cmItemMoveUp.setOnAction(new EventHandler() { public void handle(ActionEvent e) { - IdentifiedTextField tf = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); + IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); String fullText = ""; - int index = vbox.getChildren().indexOf(tf); + int index = vbox.getChildren().indexOf(modifiedTextField); System.out.println("textfield instanceof Attribute && "+index+" > 2"); if (textfield instanceof Attribute && index > 2) { index--; - vbox.getChildren().remove(tf); - vbox.getChildren().add(index,tf); + vbox.getChildren().remove(modifiedTextField); + vbox.getChildren().add(index,modifiedTextField); for(Node node: vbox.getChildren()) { if (node instanceof Attribute) { + IdentifiedTextField tf = (IdentifiedTextField) node; fullText = fullText + vbox.getChildren().indexOf(tf) + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); } @@ -327,10 +328,11 @@ public void handle(ActionEvent e) { } else if (textfield instanceof Operation && index > (3+attributesSize())) { System.out.println("textfield instanceof Operation && "+index+" > "+(3+attributesSize())); index--; - vbox.getChildren().remove(tf); - vbox.getChildren().add(index,tf); + vbox.getChildren().remove(modifiedTextField); + vbox.getChildren().add(index,modifiedTextField); for(Node node: vbox.getChildren()) { if (node instanceof Operation) { + IdentifiedTextField tf = (IdentifiedTextField) node; fullText = fullText + vbox.getChildren().indexOf(tf) + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); } @@ -344,16 +346,17 @@ public void handle(ActionEvent e) { cmItemMoveDown.setUserData(textfield); cmItemMoveDown.setOnAction(new EventHandler() { public void handle(ActionEvent e) { - IdentifiedTextField tf = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); + IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); String fullText = ""; - int index = vbox.getChildren().indexOf(tf); + int index = vbox.getChildren().indexOf(modifiedTextField); System.out.println("textfield instanceof Attribute && "+index+" < "+(1+attributesSize())); if (textfield instanceof Attribute && index < (1+attributesSize())) { index++; - vbox.getChildren().remove(tf); - vbox.getChildren().add(index,tf); + vbox.getChildren().remove(modifiedTextField); + vbox.getChildren().add(index,modifiedTextField); for(Node node: vbox.getChildren()) { if (node instanceof Attribute) { + IdentifiedTextField tf = (IdentifiedTextField) node; fullText = fullText + vbox.getChildren().indexOf(tf) + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); } @@ -362,10 +365,11 @@ public void handle(ActionEvent e) { } else if (textfield instanceof Operation && index < (2+attributesSize()+operationsSize())) { System.out.println("textfield instanceof Operation && "+index+" < "+(2+attributesSize()+operationsSize())); index++; - vbox.getChildren().remove(tf); - vbox.getChildren().add(index,tf); + vbox.getChildren().remove(modifiedTextField); + vbox.getChildren().add(index,modifiedTextField); for(Node node: vbox.getChildren()) { if (node instanceof Operation) { + IdentifiedTextField tf = (IdentifiedTextField) node; fullText = fullText + vbox.getChildren().indexOf(tf) + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); } @@ -398,32 +402,25 @@ public void handle(ActionEvent e) { cmItemDelete.setOnAction(new EventHandler() { public void handle(ActionEvent e) { IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); + vbox.getChildren().remove(modifiedTextField); String fullText = ""; if (textfield instanceof Attribute) { for (Node node: vbox.getChildren()) { if (node instanceof Attribute) { IdentifiedTextField tf = (IdentifiedTextField) node; - if (!tf.equals(modifiedTextField)) { - fullText = fullText + vbox.getChildren().indexOf(tf) + - ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); - } + fullText = fullText + vbox.getChildren().indexOf(tf) + + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); } } - fullText = fullText + "-1;" + modifiedTextField.getXmiId() + - "|" + modifiedTextField.getText() + System.getProperty("line.separator"); ((ClassNode)getRefNode()).setAttributes(fullText); } else { for (Node node: vbox.getChildren()) { if (node instanceof Operation) { IdentifiedTextField tf = (IdentifiedTextField) node; - if (!tf.equals(modifiedTextField)) { - fullText = fullText + vbox.getChildren().indexOf(tf) + - ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); - } + fullText = fullText + vbox.getChildren().indexOf(tf) + + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); } } - fullText = fullText + "-1;" + modifiedTextField.getXmiId() + - "|" + modifiedTextField.getText() + System.getProperty("line.separator"); if (operationsSize() > 0) { secondLine.setVisible(true); } else { @@ -488,75 +485,116 @@ public void propertyChange(PropertyChangeEvent evt) { } else { firstLine.setVisible(true); } - } else if (evt.getPropertyName().equals(Constants.changeClassNodeAttributes)) { + } else if ( evt.getPropertyName().equals(Constants.changeClassNodeAttributes) ) { String newValue = (String) evt.getNewValue(); - for(String text : newValue.split("\\r?\\n")){ + System.out.println("propertyChangeAttributes:\n"+newValue); + // Check for removed attributes or operations + for (int cont = 0; cont < vbox.getChildren().size(); cont++ ) { + Node node = vbox.getChildren().get(cont); + if ( node instanceof Attribute ) { + IdentifiedTextField localTextField = (IdentifiedTextField) node; + if (!newValue.contains(localTextField.getXmiId())) { + vbox.getChildren().remove(localTextField); + } + } + } + // Check for new attributes or operations + for(String text : newValue.split("\\r?\\n")) { String array[] = text.split(";"); - int ind = Integer.parseInt(array[0]); + int index = Integer.parseInt(array[0]); IdentifiedTextField remoteTextField = new IdentifiedTextField(array[1]); boolean found = false; for (Node node: vbox.getChildren()) { - if (node instanceof Attribute) { + if ( node instanceof Attribute ) { IdentifiedTextField localTextField = (IdentifiedTextField) node; if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { found = true; - if (ind != -1) { - // Update text if it was altered - if (!localTextField.getText().equals(remoteTextField.getText())) { - localTextField.setText(remoteTextField.getText()); - } - // If moved upper or down - if (vbox.getChildren().indexOf(localTextField) != ind) { - vbox.getChildren().remove(localTextField); - vbox.getChildren().add(2+ind,localTextField); - - } - } else { - vbox.getChildren().remove(localTextField); - } break; } } } - // New attribute if (!found) { - vbox.getChildren().add(ind,remoteTextField); + vbox.getChildren().add(index,remoteTextField); initLooksAttributeOperation(remoteTextField); + } + } + // Check for text altered or attribute or operation moved up or down + for(String text : newValue.split("\\r?\\n")){ + String array[] = text.split(";"); + int index = Integer.parseInt(array[0]); + IdentifiedTextField remoteTextField = new IdentifiedTextField(array[1]); + for (Node node: vbox.getChildren()) { + if ( node instanceof Attribute ) { + IdentifiedTextField localTextField = (IdentifiedTextField) node; + if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { + // Update text if it was altered + if (!localTextField.getText().equals(remoteTextField.getText())) { + localTextField.setText(remoteTextField.getText()); + } + // If moved upper or down + if (vbox.getChildren().indexOf(localTextField) != index) { + vbox.getChildren().remove(localTextField); + vbox.getChildren().add(index,localTextField); + } + break; + } + } } } - } else if (evt.getPropertyName().equals(Constants.changeClassNodeOperations)) { + } else if ( evt.getPropertyName().equals(Constants.changeClassNodeOperations) ) { String newValue = (String) evt.getNewValue(); - for(String text : newValue.split("\\r?\\n")){ + System.out.println("propertyChangeOperations:\n"+newValue); + // Check for removed attributes or operations + for (int cont = 0; cont < vbox.getChildren().size(); cont++ ) { + Node node = vbox.getChildren().get(cont); + if ( node instanceof Operation ) { + IdentifiedTextField localTextField = (IdentifiedTextField) node; + if (!newValue.contains(localTextField.getXmiId())) { + vbox.getChildren().remove(localTextField); + } + } + } + // Check for new attributes or operations + for(String text : newValue.split("\\r?\\n")) { String array[] = text.split(";"); - int ind = Integer.parseInt(array[0]); + int index = Integer.parseInt(array[0]); IdentifiedTextField remoteTextField = new IdentifiedTextField(array[1]); boolean found = false; for (Node node: vbox.getChildren()) { - if (node instanceof Operation) { + if ( node instanceof Operation ) { IdentifiedTextField localTextField = (IdentifiedTextField) node; - if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { - found = true; - if (ind != -1) { - // Update text if it was altered - if (!localTextField.getText().equals(remoteTextField.getText())) { - localTextField.setText(remoteTextField.getText()); - } - // If moved upper or down - if (vbox.getChildren().indexOf(localTextField) != ind) { - vbox.getChildren().remove(localTextField); - vbox.getChildren().add(2+attributesSize()+1+ind,localTextField); - } - } else { - vbox.getChildren().remove(localTextField); - } - break; - } + if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { + found = true; + break; + } } } - // New operation if (!found) { - vbox.getChildren().add(ind,remoteTextField); + vbox.getChildren().add(index,remoteTextField); initLooksAttributeOperation(remoteTextField); + } + } + // Check for text altered or attribute or operation moved up or down + for(String text : newValue.split("\\r?\\n")){ + String array[] = text.split(";"); + int index = Integer.parseInt(array[0]); + IdentifiedTextField remoteTextField = new IdentifiedTextField(array[1]); + for (Node node: vbox.getChildren()) { + if ( node instanceof Operation ) { + IdentifiedTextField localTextField = (IdentifiedTextField) node; + if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { + // Update text if it was altered + if (!localTextField.getText().equals(remoteTextField.getText())) { + localTextField.setText(remoteTextField.getText()); + } + // If moved upper or down + if (vbox.getChildren().indexOf(localTextField) != index) { + vbox.getChildren().remove(localTextField); + vbox.getChildren().add(index,localTextField); + } + break; + } + } } } } From 4c52251ef2c095cecbd99a6ff78f5d53086875e5 Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Thu, 3 May 2018 02:05:06 -0300 Subject: [PATCH 16/88] Refactoring of implementation of detailed synchronization --- src/model/nodes/ClassNode.java | 6 +++ src/util/persistence/PersistenceManager.java | 19 +++++--- src/view/nodes/ClassNodeView.java | 50 ++++++++++---------- 3 files changed, 43 insertions(+), 32 deletions(-) diff --git a/src/model/nodes/ClassNode.java b/src/model/nodes/ClassNode.java index b0e246e..c3ec6d9 100644 --- a/src/model/nodes/ClassNode.java +++ b/src/model/nodes/ClassNode.java @@ -23,23 +23,29 @@ public ClassNode(double x, double y, double width, double height) public void setAttributes(String pAttributes){ attributes = pAttributes; + System.out.println("setAttributes.changes.firePropertyChange"); changes.firePropertyChange(Constants.changeClassNodeAttributes, null, attributes); + System.out.println("setAttributes.remoteChanges.firePropertyChange"); remoteChanges.firePropertyChange(Constants.changeClassNodeAttributes, null, attributes); } public void setOperations(String pOperations){ operations = pOperations; + System.out.println("setOperations.changes.firePropertyChange"); changes.firePropertyChange(Constants.changeClassNodeOperations, null, operations); + System.out.println("setOperations.remoteChanges.firePropertyChange"); remoteChanges.firePropertyChange(Constants.changeClassNodeOperations, null, operations); } public void remoteSetAttributes(String pAttributes){ attributes = pAttributes; + System.out.println("remoteSetAttributes.changes.firePropertyChange"); changes.firePropertyChange(Constants.changeClassNodeAttributes, null, attributes); } public void remoteSetOperations(String pOperations){ operations = pOperations; + System.out.println("remoteSetOperations.changes.firePropertyChange"); changes.firePropertyChange(Constants.changeClassNodeOperations, null, operations); } diff --git a/src/util/persistence/PersistenceManager.java b/src/util/persistence/PersistenceManager.java index 3442392..9e8d727 100644 --- a/src/util/persistence/PersistenceManager.java +++ b/src/util/persistence/PersistenceManager.java @@ -428,23 +428,28 @@ private static AbstractNode createAbstractNode(Element view, Element model, bool abstractNode = new ClassNode(x, y, width, height); NodeList attsOps = model.getChildNodes().item(0).getChildNodes(); String attributes = ""; - String operations = ""; attributesCont = 0; - operationsCont = 0; for(int i = 0; i < attsOps.getLength(); i++){ Element item = ((Element)attsOps.item(i)); String name = item.getAttribute("name"); String xmiId = item.getAttribute("xmi.id"); if(item.getNodeName().equals("UML:Attribute")){ - attributes = attributes + attributesCont + ";" + xmiId + IdentifiedTextField.SEPARATOR + name + System.getProperty("line.separator"); + attributes = attributes + (2+attributesCont) + ";" + xmiId + IdentifiedTextField.SEPARATOR + name + System.getProperty("line.separator"); attributesCont++; - } else if(item.getNodeName().equals("UML:Operation")){ - String op = item.getAttribute("name"); - operations = operations + operationsCont + ";" + xmiId + IdentifiedTextField.SEPARATOR + name + System.getProperty("line.separator"); - operationsCont++; } } ((ClassNode)abstractNode).setAttributes(attributes); + String operations = ""; + operationsCont = 0; + for(int i = 0; i < attsOps.getLength(); i++){ + Element item = ((Element)attsOps.item(i)); + String name = item.getAttribute("name"); + String xmiId = item.getAttribute("xmi.id"); + if(item.getNodeName().equals("UML:Operation")){ + operations = operations + (attributesCont+3+operationsCont) + ";" + xmiId + IdentifiedTextField.SEPARATOR + name + System.getProperty("line.separator"); + operationsCont++; + } + } ((ClassNode)abstractNode).setOperations(operations); } else { abstractNode = new PackageNode(x, y, width, height); diff --git a/src/view/nodes/ClassNodeView.java b/src/view/nodes/ClassNodeView.java index 951250f..bf0909d 100644 --- a/src/view/nodes/ClassNodeView.java +++ b/src/view/nodes/ClassNodeView.java @@ -183,6 +183,7 @@ private void initVBox(){ vbox.getChildren().addAll(titlePane, firstLine); if (node.getAttributes() != null) { + System.out.println("initVBox.node.getAttributes():\n"+node.getAttributes()); for(String text : node.getAttributes().split("\\r?\\n")){ if (text.contains(";")) { text = text.substring(text.indexOf(";")+1); @@ -196,7 +197,8 @@ private void initVBox(){ vbox.getChildren().addAll(secondLine); if (node.getOperations() != null) { - for(String text : node.getOperations().split("\\r?\\n")){ + System.out.println("initVBox.node.getOperations():\n"+node.getOperations()); + for(String text : node.getOperations().split("\\r?\\n")){ if (text.contains(";")) { text = text.substring(text.indexOf(";")+1); } @@ -404,30 +406,28 @@ public void handle(ActionEvent e) { IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); vbox.getChildren().remove(modifiedTextField); String fullText = ""; - if (textfield instanceof Attribute) { - for (Node node: vbox.getChildren()) { - if (node instanceof Attribute) { - IdentifiedTextField tf = (IdentifiedTextField) node; - fullText = fullText + vbox.getChildren().indexOf(tf) + - ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); - } - } - ((ClassNode)getRefNode()).setAttributes(fullText); - } else { - for (Node node: vbox.getChildren()) { - if (node instanceof Operation) { - IdentifiedTextField tf = (IdentifiedTextField) node; - fullText = fullText + vbox.getChildren().indexOf(tf) + - ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); - } - } - if (operationsSize() > 0) { - secondLine.setVisible(true); - } else { - secondLine.setVisible(false); - } - ((ClassNode)getRefNode()).setOperations(fullText); - } + for (Node node: vbox.getChildren()) { + if (node instanceof Attribute) { + IdentifiedTextField tf = (IdentifiedTextField) node; + fullText = fullText + vbox.getChildren().indexOf(tf) + + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); + } + } + ((ClassNode)getRefNode()).setAttributes(fullText); + fullText = ""; + for (Node node: vbox.getChildren()) { + if (node instanceof Operation) { + IdentifiedTextField tf = (IdentifiedTextField) node; + fullText = fullText + vbox.getChildren().indexOf(tf) + + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); + } + } + if (operationsSize() > 0) { + secondLine.setVisible(true); + } else { + secondLine.setVisible(false); + } + ((ClassNode)getRefNode()).setOperations(fullText); } }); From 734706df5d5a7d63b8b73da61715c04618744389 Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Thu, 3 May 2018 14:37:35 -0300 Subject: [PATCH 17/88] Refactoring of implementation of detailed synchronization --- src/model/nodes/ClassNode.java | 37 +++++++++++++--- src/view/nodes/ClassNodeView.java | 73 +++++++++++++++++++++---------- 2 files changed, 81 insertions(+), 29 deletions(-) diff --git a/src/model/nodes/ClassNode.java b/src/model/nodes/ClassNode.java index c3ec6d9..bfdad73 100644 --- a/src/model/nodes/ClassNode.java +++ b/src/model/nodes/ClassNode.java @@ -20,32 +20,55 @@ public ClassNode(double x, double y, double width, double height) this.height = height < CLASS_MIN_HEIGHT ? CLASS_MIN_HEIGHT : height; } - + public void setAttributesAndOperations(String pAttributes, String pOperations){ + System.out.println("setAttributesAndOperations"); + System.out.println("pAttributes:\n"+pAttributes); + System.out.println("pOperations:\n"+pOperations); + attributes = pAttributes; + operations = pOperations; + System.out.println("changes.firePropertyChange"); + changes.firePropertyChange(Constants.changeClassNodeAttributes, null, attributes); + System.out.println("remoteChanges.firePropertyChange"); + remoteChanges.firePropertyChange(Constants.changeClassNodeAttributes, null, attributes); + System.out.println("changes.firePropertyChange"); + changes.firePropertyChange(Constants.changeClassNodeOperations, null, operations); + System.out.println("remoteChanges.firePropertyChange"); + remoteChanges.firePropertyChange(Constants.changeClassNodeOperations, null, operations); + } + public void setAttributes(String pAttributes){ + System.out.println("setAttributes"); + System.out.println("pAttributes:\n"+pAttributes); attributes = pAttributes; - System.out.println("setAttributes.changes.firePropertyChange"); + System.out.println("changes.firePropertyChange"); changes.firePropertyChange(Constants.changeClassNodeAttributes, null, attributes); - System.out.println("setAttributes.remoteChanges.firePropertyChange"); + System.out.println("remoteChanges.firePropertyChange"); remoteChanges.firePropertyChange(Constants.changeClassNodeAttributes, null, attributes); } public void setOperations(String pOperations){ + System.out.println("setOperations"); + System.out.println("pOperations:\n"+pOperations); operations = pOperations; - System.out.println("setOperations.changes.firePropertyChange"); + System.out.println("changes.firePropertyChange"); changes.firePropertyChange(Constants.changeClassNodeOperations, null, operations); - System.out.println("setOperations.remoteChanges.firePropertyChange"); + System.out.println("remoteChanges.firePropertyChange"); remoteChanges.firePropertyChange(Constants.changeClassNodeOperations, null, operations); } public void remoteSetAttributes(String pAttributes){ + System.out.println("remoteSetAttributes"); + System.out.println("pAttributes:\n"+pAttributes); attributes = pAttributes; - System.out.println("remoteSetAttributes.changes.firePropertyChange"); + System.out.println("changes.firePropertyChange"); changes.firePropertyChange(Constants.changeClassNodeAttributes, null, attributes); } public void remoteSetOperations(String pOperations){ + System.out.println("remoteSetOperations"); + System.out.println("pOperations:\n"+pOperations); operations = pOperations; - System.out.println("remoteSetOperations.changes.firePropertyChange"); + System.out.println("changes.firePropertyChange"); changes.firePropertyChange(Constants.changeClassNodeOperations, null, operations); } diff --git a/src/view/nodes/ClassNodeView.java b/src/view/nodes/ClassNodeView.java index bf0909d..adf961c 100644 --- a/src/view/nodes/ClassNodeView.java +++ b/src/view/nodes/ClassNodeView.java @@ -283,6 +283,7 @@ private void createHandlesAttributesOperations(IdentifiedTextField textfield) { textfield.setOnKeyReleased(new EventHandler() { public void handle(KeyEvent ke) { + System.out.println("setOnKeyReleased"); String fullText = ""; if (textfield instanceof Attribute) { for(Node node: vbox.getChildren()) { @@ -292,7 +293,8 @@ public void handle(KeyEvent ke) { ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); } } - ((ClassNode)getRefNode()).setAttributes(fullText); + System.out.println("Broadcasting:\n"+fullText); + ((ClassNode)getRefNode()).setAttributes(fullText); } else if (textfield instanceof Operation) { for(Node node: vbox.getChildren()) { if (node instanceof Operation) { @@ -301,6 +303,7 @@ public void handle(KeyEvent ke) { ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); } } + System.out.println("Broadcasting:\n"+fullText); ((ClassNode)getRefNode()).setOperations(fullText); } } @@ -311,6 +314,7 @@ public void handle(KeyEvent ke) { cmItemMoveUp.setUserData(textfield); cmItemMoveUp.setOnAction(new EventHandler() { public void handle(ActionEvent e) { + System.out.println("Move Up"); IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); String fullText = ""; int index = vbox.getChildren().indexOf(modifiedTextField); @@ -326,7 +330,8 @@ public void handle(ActionEvent e) { "|" + tf.getText() + System.getProperty("line.separator"); } } - ((ClassNode)getRefNode()).setAttributes(fullText); + System.out.println("Broadcasting:\n"+fullText); + ((ClassNode)getRefNode()).setAttributes(fullText); } else if (textfield instanceof Operation && index > (3+attributesSize())) { System.out.println("textfield instanceof Operation && "+index+" > "+(3+attributesSize())); index--; @@ -339,6 +344,7 @@ public void handle(ActionEvent e) { "|" + tf.getText() + System.getProperty("line.separator"); } } + System.out.println("Broadcasting:\n"+fullText); ((ClassNode)getRefNode()).setOperations(fullText); } } @@ -348,6 +354,7 @@ public void handle(ActionEvent e) { cmItemMoveDown.setUserData(textfield); cmItemMoveDown.setOnAction(new EventHandler() { public void handle(ActionEvent e) { + System.out.println("Move Down"); IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); String fullText = ""; int index = vbox.getChildren().indexOf(modifiedTextField); @@ -363,6 +370,7 @@ public void handle(ActionEvent e) { "|" + tf.getText() + System.getProperty("line.separator"); } } + System.out.println("Broadcasting:\n"+fullText); ((ClassNode)getRefNode()).setAttributes(fullText); } else if (textfield instanceof Operation && index < (2+attributesSize()+operationsSize())) { System.out.println("textfield instanceof Operation && "+index+" < "+(2+attributesSize()+operationsSize())); @@ -376,6 +384,7 @@ public void handle(ActionEvent e) { "|" + tf.getText() + System.getProperty("line.separator"); } } + System.out.println("Broadcasting:\n"+fullText); ((ClassNode)getRefNode()).setOperations(fullText); } } @@ -403,31 +412,28 @@ public void handle(ActionEvent e) { cmItemDelete.setUserData(textfield); cmItemDelete.setOnAction(new EventHandler() { public void handle(ActionEvent e) { + System.out.println("Delete attribute/operation"); IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); vbox.getChildren().remove(modifiedTextField); - String fullText = ""; + String attributesfullText = ""; for (Node node: vbox.getChildren()) { if (node instanceof Attribute) { IdentifiedTextField tf = (IdentifiedTextField) node; - fullText = fullText + vbox.getChildren().indexOf(tf) + + attributesfullText = attributesfullText + vbox.getChildren().indexOf(tf) + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); } } - ((ClassNode)getRefNode()).setAttributes(fullText); - fullText = ""; + System.out.println("Broadcasting:\n"+attributesfullText); + String operationsFullText = ""; for (Node node: vbox.getChildren()) { if (node instanceof Operation) { IdentifiedTextField tf = (IdentifiedTextField) node; - fullText = fullText + vbox.getChildren().indexOf(tf) + + operationsFullText = operationsFullText + vbox.getChildren().indexOf(tf) + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); } } - if (operationsSize() > 0) { - secondLine.setVisible(true); - } else { - secondLine.setVisible(false); - } - ((ClassNode)getRefNode()).setOperations(fullText); + System.out.println("Broadcasting:\n"+operationsFullText); + ((ClassNode)getRefNode()).setAttributesAndOperations(attributesfullText,operationsFullText); } }); @@ -488,21 +494,22 @@ public void propertyChange(PropertyChangeEvent evt) { } else if ( evt.getPropertyName().equals(Constants.changeClassNodeAttributes) ) { String newValue = (String) evt.getNewValue(); System.out.println("propertyChangeAttributes:\n"+newValue); - // Check for removed attributes or operations + // Check for removed attributes for (int cont = 0; cont < vbox.getChildren().size(); cont++ ) { Node node = vbox.getChildren().get(cont); if ( node instanceof Attribute ) { IdentifiedTextField localTextField = (IdentifiedTextField) node; if (!newValue.contains(localTextField.getXmiId())) { + System.out.println(localTextField+" not found. Removing..."); vbox.getChildren().remove(localTextField); } } } - // Check for new attributes or operations + // Check for new attributes for(String text : newValue.split("\\r?\\n")) { String array[] = text.split(";"); int index = Integer.parseInt(array[0]); - IdentifiedTextField remoteTextField = new IdentifiedTextField(array[1]); + Attribute remoteTextField = new Attribute(array[1]); boolean found = false; for (Node node: vbox.getChildren()) { if ( node instanceof Attribute ) { @@ -514,11 +521,13 @@ public void propertyChange(PropertyChangeEvent evt) { } } if (!found) { - vbox.getChildren().add(index,remoteTextField); + System.out.println(remoteTextField+" not found. Adding with index = "+index); initLooksAttributeOperation(remoteTextField); + createHandlesAttributesOperations(remoteTextField); + vbox.getChildren().add(index,remoteTextField); } } - // Check for text altered or attribute or operation moved up or down + // Check for text altered or attribute moved up or down for(String text : newValue.split("\\r?\\n")){ String array[] = text.split(";"); int index = Integer.parseInt(array[0]); @@ -529,10 +538,13 @@ public void propertyChange(PropertyChangeEvent evt) { if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { // Update text if it was altered if (!localTextField.getText().equals(remoteTextField.getText())) { + System.out.println(localTextField+" is old. Updating to "+remoteTextField); localTextField.setText(remoteTextField.getText()); } // If moved upper or down if (vbox.getChildren().indexOf(localTextField) != index) { + System.out.println(localTextField+" index is " + vbox.getChildren().indexOf(localTextField) + + ". Updating to index to "+ index); vbox.getChildren().remove(localTextField); vbox.getChildren().add(index,localTextField); } @@ -541,24 +553,31 @@ public void propertyChange(PropertyChangeEvent evt) { } } } + if (operationsSize() > 0) { + secondLine.setVisible(true); + } else { + secondLine.setVisible(false); + } + } else if ( evt.getPropertyName().equals(Constants.changeClassNodeOperations) ) { String newValue = (String) evt.getNewValue(); System.out.println("propertyChangeOperations:\n"+newValue); - // Check for removed attributes or operations + // Check for removed operations for (int cont = 0; cont < vbox.getChildren().size(); cont++ ) { Node node = vbox.getChildren().get(cont); if ( node instanceof Operation ) { IdentifiedTextField localTextField = (IdentifiedTextField) node; if (!newValue.contains(localTextField.getXmiId())) { + System.out.println(localTextField+" not found. Removing..."); vbox.getChildren().remove(localTextField); } } } - // Check for new attributes or operations + // Check for new operations for(String text : newValue.split("\\r?\\n")) { String array[] = text.split(";"); int index = Integer.parseInt(array[0]); - IdentifiedTextField remoteTextField = new IdentifiedTextField(array[1]); + Operation remoteTextField = new Operation(array[1]); boolean found = false; for (Node node: vbox.getChildren()) { if ( node instanceof Operation ) { @@ -570,8 +589,10 @@ public void propertyChange(PropertyChangeEvent evt) { } } if (!found) { - vbox.getChildren().add(index,remoteTextField); + System.out.println(remoteTextField+" not found. Adding with index = "+index); initLooksAttributeOperation(remoteTextField); + createHandlesAttributesOperations(remoteTextField); + vbox.getChildren().add(index,remoteTextField); } } // Check for text altered or attribute or operation moved up or down @@ -585,10 +606,13 @@ public void propertyChange(PropertyChangeEvent evt) { if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { // Update text if it was altered if (!localTextField.getText().equals(remoteTextField.getText())) { + System.out.println(localTextField+" is old. Updating to "+remoteTextField); localTextField.setText(remoteTextField.getText()); } // If moved upper or down if (vbox.getChildren().indexOf(localTextField) != index) { + System.out.println(localTextField+" index is " + vbox.getChildren().indexOf(localTextField) + + ". Updating index to "+ index); vbox.getChildren().remove(localTextField); vbox.getChildren().add(index,localTextField); } @@ -597,6 +621,11 @@ public void propertyChange(PropertyChangeEvent evt) { } } } + if (operationsSize() > 0) { + secondLine.setVisible(true); + } else { + secondLine.setVisible(false); + } } } } From c3179753d9644bed3df9eaf34b2174e43db7147f Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Thu, 3 May 2018 18:05:55 -0300 Subject: [PATCH 18/88] Refactoring of implementation of detailed synchronization --- src/model/nodes/ClassNode.java | 25 +---- src/view/nodes/ClassNodeView.java | 159 ++++++++++++------------------ 2 files changed, 66 insertions(+), 118 deletions(-) diff --git a/src/model/nodes/ClassNode.java b/src/model/nodes/ClassNode.java index bfdad73..ccb395b 100644 --- a/src/model/nodes/ClassNode.java +++ b/src/model/nodes/ClassNode.java @@ -20,55 +20,34 @@ public ClassNode(double x, double y, double width, double height) this.height = height < CLASS_MIN_HEIGHT ? CLASS_MIN_HEIGHT : height; } - public void setAttributesAndOperations(String pAttributes, String pOperations){ - System.out.println("setAttributesAndOperations"); - System.out.println("pAttributes:\n"+pAttributes); - System.out.println("pOperations:\n"+pOperations); + public void setAttributesWithOperations(String pAttributes, String pOperations){ attributes = pAttributes; operations = pOperations; - System.out.println("changes.firePropertyChange"); changes.firePropertyChange(Constants.changeClassNodeAttributes, null, attributes); - System.out.println("remoteChanges.firePropertyChange"); - remoteChanges.firePropertyChange(Constants.changeClassNodeAttributes, null, attributes); - System.out.println("changes.firePropertyChange"); changes.firePropertyChange(Constants.changeClassNodeOperations, null, operations); - System.out.println("remoteChanges.firePropertyChange"); + remoteChanges.firePropertyChange(Constants.changeClassNodeAttributes, null, attributes); remoteChanges.firePropertyChange(Constants.changeClassNodeOperations, null, operations); } public void setAttributes(String pAttributes){ - System.out.println("setAttributes"); - System.out.println("pAttributes:\n"+pAttributes); attributes = pAttributes; - System.out.println("changes.firePropertyChange"); changes.firePropertyChange(Constants.changeClassNodeAttributes, null, attributes); - System.out.println("remoteChanges.firePropertyChange"); remoteChanges.firePropertyChange(Constants.changeClassNodeAttributes, null, attributes); } public void setOperations(String pOperations){ - System.out.println("setOperations"); - System.out.println("pOperations:\n"+pOperations); operations = pOperations; - System.out.println("changes.firePropertyChange"); changes.firePropertyChange(Constants.changeClassNodeOperations, null, operations); - System.out.println("remoteChanges.firePropertyChange"); remoteChanges.firePropertyChange(Constants.changeClassNodeOperations, null, operations); } public void remoteSetAttributes(String pAttributes){ - System.out.println("remoteSetAttributes"); - System.out.println("pAttributes:\n"+pAttributes); attributes = pAttributes; - System.out.println("changes.firePropertyChange"); changes.firePropertyChange(Constants.changeClassNodeAttributes, null, attributes); } public void remoteSetOperations(String pOperations){ - System.out.println("remoteSetOperations"); - System.out.println("pOperations:\n"+pOperations); operations = pOperations; - System.out.println("changes.firePropertyChange"); changes.firePropertyChange(Constants.changeClassNodeOperations, null, operations); } diff --git a/src/view/nodes/ClassNodeView.java b/src/view/nodes/ClassNodeView.java index adf961c..915fd34 100644 --- a/src/view/nodes/ClassNodeView.java +++ b/src/view/nodes/ClassNodeView.java @@ -144,8 +144,8 @@ private void createHandles(){ @Override public void changed(ObservableValue observable, String oldValue, String newValue) { + System.out.println("Broadcasting title '" + newValue + "'\n"); ((ClassNode)getRefNode()).setTitle(newValue); - System.out.println("Title changed to " + newValue + ")\n"); } }); for(Node node: vbox.getChildren()) { @@ -183,7 +183,6 @@ private void initVBox(){ vbox.getChildren().addAll(titlePane, firstLine); if (node.getAttributes() != null) { - System.out.println("initVBox.node.getAttributes():\n"+node.getAttributes()); for(String text : node.getAttributes().split("\\r?\\n")){ if (text.contains(";")) { text = text.substring(text.indexOf(";")+1); @@ -197,7 +196,6 @@ private void initVBox(){ vbox.getChildren().addAll(secondLine); if (node.getOperations() != null) { - System.out.println("initVBox.node.getOperations():\n"+node.getOperations()); for(String text : node.getOperations().split("\\r?\\n")){ if (text.contains(";")) { text = text.substring(text.indexOf(";")+1); @@ -283,27 +281,14 @@ private void createHandlesAttributesOperations(IdentifiedTextField textfield) { textfield.setOnKeyReleased(new EventHandler() { public void handle(KeyEvent ke) { - System.out.println("setOnKeyReleased"); String fullText = ""; if (textfield instanceof Attribute) { - for(Node node: vbox.getChildren()) { - if (node instanceof Attribute) { - IdentifiedTextField tf = (IdentifiedTextField) node; - fullText = fullText + vbox.getChildren().indexOf(tf) + - ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); - } - } - System.out.println("Broadcasting:\n"+fullText); + fullText = extractAttributesFromVBox(); + System.out.println("KeyReleased. Broadcasting:\n"+fullText+"\n"); ((ClassNode)getRefNode()).setAttributes(fullText); } else if (textfield instanceof Operation) { - for(Node node: vbox.getChildren()) { - if (node instanceof Operation) { - IdentifiedTextField tf = (IdentifiedTextField) node; - fullText = fullText + vbox.getChildren().indexOf(tf) + - ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); - } - } - System.out.println("Broadcasting:\n"+fullText); + fullText = extractOperationsFromVBox(); + System.out.println("KeyReleased. Broadcasting:\n"+fullText+"\n"); ((ClassNode)getRefNode()).setOperations(fullText); } } @@ -314,37 +299,22 @@ public void handle(KeyEvent ke) { cmItemMoveUp.setUserData(textfield); cmItemMoveUp.setOnAction(new EventHandler() { public void handle(ActionEvent e) { - System.out.println("Move Up"); IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); String fullText = ""; int index = vbox.getChildren().indexOf(modifiedTextField); - System.out.println("textfield instanceof Attribute && "+index+" > 2"); if (textfield instanceof Attribute && index > 2) { index--; vbox.getChildren().remove(modifiedTextField); - vbox.getChildren().add(index,modifiedTextField); - for(Node node: vbox.getChildren()) { - if (node instanceof Attribute) { - IdentifiedTextField tf = (IdentifiedTextField) node; - fullText = fullText + vbox.getChildren().indexOf(tf) + ";" + tf.getXmiId() + - "|" + tf.getText() + System.getProperty("line.separator"); - } - } - System.out.println("Broadcasting:\n"+fullText); + vbox.getChildren().add(index,modifiedTextField); + fullText = extractAttributesFromVBox(); + System.out.println("Move Up. Broadcasting:\n"+fullText+"\n"); ((ClassNode)getRefNode()).setAttributes(fullText); } else if (textfield instanceof Operation && index > (3+attributesSize())) { - System.out.println("textfield instanceof Operation && "+index+" > "+(3+attributesSize())); index--; vbox.getChildren().remove(modifiedTextField); - vbox.getChildren().add(index,modifiedTextField); - for(Node node: vbox.getChildren()) { - if (node instanceof Operation) { - IdentifiedTextField tf = (IdentifiedTextField) node; - fullText = fullText + vbox.getChildren().indexOf(tf) + ";" + tf.getXmiId() + - "|" + tf.getText() + System.getProperty("line.separator"); - } - } - System.out.println("Broadcasting:\n"+fullText); + vbox.getChildren().add(index,modifiedTextField); + fullText = extractOperationsFromVBox(); + System.out.println("Move Up. Broadcasting:\n"+fullText+"\n"); ((ClassNode)getRefNode()).setOperations(fullText); } } @@ -354,37 +324,22 @@ public void handle(ActionEvent e) { cmItemMoveDown.setUserData(textfield); cmItemMoveDown.setOnAction(new EventHandler() { public void handle(ActionEvent e) { - System.out.println("Move Down"); IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); String fullText = ""; int index = vbox.getChildren().indexOf(modifiedTextField); - System.out.println("textfield instanceof Attribute && "+index+" < "+(1+attributesSize())); if (textfield instanceof Attribute && index < (1+attributesSize())) { index++; vbox.getChildren().remove(modifiedTextField); - vbox.getChildren().add(index,modifiedTextField); - for(Node node: vbox.getChildren()) { - if (node instanceof Attribute) { - IdentifiedTextField tf = (IdentifiedTextField) node; - fullText = fullText + vbox.getChildren().indexOf(tf) + ";" + tf.getXmiId() + - "|" + tf.getText() + System.getProperty("line.separator"); - } - } - System.out.println("Broadcasting:\n"+fullText); + vbox.getChildren().add(index,modifiedTextField); + fullText = extractAttributesFromVBox(); + System.out.println("Move Down. Broadcasting:\n"+fullText+"\n"); ((ClassNode)getRefNode()).setAttributes(fullText); } else if (textfield instanceof Operation && index < (2+attributesSize()+operationsSize())) { - System.out.println("textfield instanceof Operation && "+index+" < "+(2+attributesSize()+operationsSize())); index++; vbox.getChildren().remove(modifiedTextField); - vbox.getChildren().add(index,modifiedTextField); - for(Node node: vbox.getChildren()) { - if (node instanceof Operation) { - IdentifiedTextField tf = (IdentifiedTextField) node; - fullText = fullText + vbox.getChildren().indexOf(tf) + ";" + tf.getXmiId() + - "|" + tf.getText() + System.getProperty("line.separator"); - } - } - System.out.println("Broadcasting:\n"+fullText); + vbox.getChildren().add(index,modifiedTextField); + fullText = extractOperationsFromVBox(); + System.out.println("Move Down. Broadcasting:\n"+fullText+"\n"); ((ClassNode)getRefNode()).setOperations(fullText); } } @@ -415,25 +370,7 @@ public void handle(ActionEvent e) { System.out.println("Delete attribute/operation"); IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); vbox.getChildren().remove(modifiedTextField); - String attributesfullText = ""; - for (Node node: vbox.getChildren()) { - if (node instanceof Attribute) { - IdentifiedTextField tf = (IdentifiedTextField) node; - attributesfullText = attributesfullText + vbox.getChildren().indexOf(tf) + - ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); - } - } - System.out.println("Broadcasting:\n"+attributesfullText); - String operationsFullText = ""; - for (Node node: vbox.getChildren()) { - if (node instanceof Operation) { - IdentifiedTextField tf = (IdentifiedTextField) node; - operationsFullText = operationsFullText + vbox.getChildren().indexOf(tf) + - ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); - } - } - System.out.println("Broadcasting:\n"+operationsFullText); - ((ClassNode)getRefNode()).setAttributesAndOperations(attributesfullText,operationsFullText); + broadcastingAttributesWithOperations(); } }); @@ -452,19 +389,52 @@ private void initLooksAttributeOperation(IdentifiedTextField textField) { textField.setBackground(background); } + private String extractAttributesFromVBox() { + String fullText = ""; + for (Node node: vbox.getChildren()) { + if (node instanceof Attribute) { + IdentifiedTextField tf = (IdentifiedTextField) node; + fullText = fullText + vbox.getChildren().indexOf(tf) + + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); + } + } + return fullText; + } + + private String extractOperationsFromVBox() { + String fullText = ""; + for (Node node: vbox.getChildren()) { + if (node instanceof Operation) { + IdentifiedTextField tf = (IdentifiedTextField) node; + fullText = fullText + vbox.getChildren().indexOf(tf) + + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); + } + } + return fullText; + } + + private void broadcastingAttributesWithOperations() { + String attributesfullText = extractAttributesFromVBox(); + String operationsFullText = extractOperationsFromVBox(); + System.out.println("Broadcasting attributes with operations:\n"+attributesfullText+ + "\n"+operationsFullText+"\n"); + ((ClassNode)getRefNode()).setAttributesWithOperations(attributesfullText,operationsFullText); + } public void addAttribute() { Attribute textField = new Attribute(""); initLooksAttributeOperation(textField); - vbox.getChildren().add(2+attributesSize(),textField); createHandlesAttributesOperations(textField); + vbox.getChildren().add(2+attributesSize(),textField); + broadcastingAttributesWithOperations(); } public void addOperation() { Operation textField = new Operation(""); initLooksAttributeOperation(textField); - vbox.getChildren().add(textField); createHandlesAttributesOperations(textField); + vbox.getChildren().add(textField); + broadcastingAttributesWithOperations(); } @Override @@ -484,6 +454,7 @@ public void propertyChange(PropertyChangeEvent evt) { String newValue = (String) evt.getNewValue(); // Update text if it was altered if (!title.getText().equals(newValue)) { + System.out.println("Title changed to '" + newValue + "'\n"); title.setText(newValue); } if (title.getText() == null || title.getText().equals("")) { @@ -493,14 +464,13 @@ public void propertyChange(PropertyChangeEvent evt) { } } else if ( evt.getPropertyName().equals(Constants.changeClassNodeAttributes) ) { String newValue = (String) evt.getNewValue(); - System.out.println("propertyChangeAttributes:\n"+newValue); // Check for removed attributes for (int cont = 0; cont < vbox.getChildren().size(); cont++ ) { Node node = vbox.getChildren().get(cont); if ( node instanceof Attribute ) { IdentifiedTextField localTextField = (IdentifiedTextField) node; if (!newValue.contains(localTextField.getXmiId())) { - System.out.println(localTextField+" not found. Removing..."); + System.out.println("'"+localTextField+"' not found. Removing...\n"); vbox.getChildren().remove(localTextField); } } @@ -521,7 +491,7 @@ public void propertyChange(PropertyChangeEvent evt) { } } if (!found) { - System.out.println(remoteTextField+" not found. Adding with index = "+index); + System.out.println("'"+remoteTextField+"' not found. Adding with index = "+index+"\n"); initLooksAttributeOperation(remoteTextField); createHandlesAttributesOperations(remoteTextField); vbox.getChildren().add(index,remoteTextField); @@ -538,13 +508,13 @@ public void propertyChange(PropertyChangeEvent evt) { if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { // Update text if it was altered if (!localTextField.getText().equals(remoteTextField.getText())) { - System.out.println(localTextField+" is old. Updating to "+remoteTextField); + System.out.println("'"+localTextField+"' is old. Updating to '"+remoteTextField+"'\n"); localTextField.setText(remoteTextField.getText()); } // If moved upper or down if (vbox.getChildren().indexOf(localTextField) != index) { - System.out.println(localTextField+" index is " + vbox.getChildren().indexOf(localTextField) + - ". Updating to index to "+ index); + System.out.println("'"+localTextField+"' index is " + vbox.getChildren().indexOf(localTextField) + + ". Updating to index to "+ index+"\n"); vbox.getChildren().remove(localTextField); vbox.getChildren().add(index,localTextField); } @@ -561,14 +531,13 @@ public void propertyChange(PropertyChangeEvent evt) { } else if ( evt.getPropertyName().equals(Constants.changeClassNodeOperations) ) { String newValue = (String) evt.getNewValue(); - System.out.println("propertyChangeOperations:\n"+newValue); // Check for removed operations for (int cont = 0; cont < vbox.getChildren().size(); cont++ ) { Node node = vbox.getChildren().get(cont); if ( node instanceof Operation ) { IdentifiedTextField localTextField = (IdentifiedTextField) node; if (!newValue.contains(localTextField.getXmiId())) { - System.out.println(localTextField+" not found. Removing..."); + System.out.println("'"+localTextField+"' not found. Removing...\n"); vbox.getChildren().remove(localTextField); } } @@ -589,7 +558,7 @@ public void propertyChange(PropertyChangeEvent evt) { } } if (!found) { - System.out.println(remoteTextField+" not found. Adding with index = "+index); + System.out.println("'"+remoteTextField+"' not found. Adding with index = "+index+"\n"); initLooksAttributeOperation(remoteTextField); createHandlesAttributesOperations(remoteTextField); vbox.getChildren().add(index,remoteTextField); @@ -606,13 +575,13 @@ public void propertyChange(PropertyChangeEvent evt) { if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { // Update text if it was altered if (!localTextField.getText().equals(remoteTextField.getText())) { - System.out.println(localTextField+" is old. Updating to "+remoteTextField); + System.out.println("'"+localTextField+"' is old. Updating to "+remoteTextField+"\n"); localTextField.setText(remoteTextField.getText()); } // If moved upper or down if (vbox.getChildren().indexOf(localTextField) != index) { - System.out.println(localTextField+" index is " + vbox.getChildren().indexOf(localTextField) + - ". Updating index to "+ index); + System.out.println("'"+localTextField+"' index is " + vbox.getChildren().indexOf(localTextField) + + ". Updating index to "+ index+"\n"); vbox.getChildren().remove(localTextField); vbox.getChildren().add(index,localTextField); } From 0c9062bead0c7a0d3dadce077c1eb11c1575d379 Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Thu, 3 May 2018 21:24:59 -0300 Subject: [PATCH 19/88] Refactoring of implementation of detailed synchronization --- src/util/persistence/PersistenceManager.java | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/util/persistence/PersistenceManager.java b/src/util/persistence/PersistenceManager.java index 9e8d727..1674b95 100644 --- a/src/util/persistence/PersistenceManager.java +++ b/src/util/persistence/PersistenceManager.java @@ -225,7 +225,12 @@ private static void addClassNode(Document doc, ClassNode node, Element parent, G textField = new IdentifiedTextField(att); Element attribute = doc.createElement("UML:Attribute"); attribute.setAttribute("name", textField.getText()); - attribute.setAttribute("xmi.id", "att" + UUID.randomUUID().toString() + "_" + node.getId()); + if (textField.getXmiId().contains("-")) { + attribute.setAttribute("xmi.id", textField.getXmiId()); + } else { + attribute.setAttribute("xmi.id", "att" + UUID.randomUUID().toString() + + "_" + node.getId()); + } classifierFeature.appendChild(attribute); } } @@ -235,7 +240,12 @@ private static void addClassNode(Document doc, ClassNode node, Element parent, G textField = new IdentifiedTextField(op); Element operation = doc.createElement("UML:Operation"); operation.setAttribute("name", textField.getText()); - operation.setAttribute("xmi.id", "oper" + UUID.randomUUID().toString() + "_" + node.getId()); + if (textField.getXmiId().contains("-")) { + operation.setAttribute("xmi.id", textField.getXmiId()); + } else { + operation.setAttribute("xmi.id", "oper" + UUID.randomUUID().toString() + + "_" + node.getId()); + } classifierFeature.appendChild(operation); } } @@ -434,7 +444,8 @@ private static AbstractNode createAbstractNode(Element view, Element model, bool String name = item.getAttribute("name"); String xmiId = item.getAttribute("xmi.id"); if(item.getNodeName().equals("UML:Attribute")){ - attributes = attributes + (2+attributesCont) + ";" + xmiId + IdentifiedTextField.SEPARATOR + name + System.getProperty("line.separator"); + attributes = attributes + (2+attributesCont) + ";" + xmiId + + IdentifiedTextField.SEPARATOR + name + System.getProperty("line.separator"); attributesCont++; } } @@ -446,7 +457,8 @@ private static AbstractNode createAbstractNode(Element view, Element model, bool String name = item.getAttribute("name"); String xmiId = item.getAttribute("xmi.id"); if(item.getNodeName().equals("UML:Operation")){ - operations = operations + (attributesCont+3+operationsCont) + ";" + xmiId + IdentifiedTextField.SEPARATOR + name + System.getProperty("line.separator"); + operations = operations + (attributesCont+3+operationsCont) + ";" + xmiId + + IdentifiedTextField.SEPARATOR + name + System.getProperty("line.separator"); operationsCont++; } } From 4c5be8dba2856ac907d6b1caffca3a1d1337016e Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Fri, 4 May 2018 00:41:40 -0300 Subject: [PATCH 20/88] Refactoring of implementation of detailed synchronization --- src/controller/AbstractDiagramController.java | 16 ----- src/model/nodes/IdentifiedTextField.java | 21 +++--- src/util/persistence/PersistenceManager.java | 16 +++-- src/view/nodes/ClassNodeView.java | 65 +++++++++---------- 4 files changed, 54 insertions(+), 64 deletions(-) diff --git a/src/controller/AbstractDiagramController.java b/src/controller/AbstractDiagramController.java index 0e6886b..8937c2d 100644 --- a/src/controller/AbstractDiagramController.java +++ b/src/controller/AbstractDiagramController.java @@ -607,23 +607,7 @@ private void initContextMenu() { insertImg.openFileChooser(AbstractDiagramController.this, point); }); - MenuItem cmItemAddAttribute= new MenuItem("Add attribute"); - cmItemAddAttribute.setOnAction(event -> { - if (aContextMenu.getOwnerNode() instanceof ClassNodeView) { - ((ClassNodeView) aContextMenu.getOwnerNode()).addAttribute(); - } - }); - - MenuItem cmItemAddOperation = new MenuItem("Add operation"); - cmItemAddOperation.setOnAction(event -> { - if (aContextMenu.getOwnerNode() instanceof ClassNodeView) { - ((ClassNodeView) aContextMenu.getOwnerNode()).addOperation(); - } - }); - - aContextMenu.getItems().addAll(cmItemCopy, cmItemPaste, cmItemDelete, cmItemInsertImg); - aContextMenu.getItems().addAll(cmItemAddAttribute,cmItemAddOperation); } /** diff --git a/src/model/nodes/IdentifiedTextField.java b/src/model/nodes/IdentifiedTextField.java index 5ad4289..0ada2ef 100644 --- a/src/model/nodes/IdentifiedTextField.java +++ b/src/model/nodes/IdentifiedTextField.java @@ -1,7 +1,5 @@ package model.nodes; -import java.util.UUID; - import javafx.scene.control.TextField; public class IdentifiedTextField extends TextField { @@ -11,17 +9,22 @@ public class IdentifiedTextField extends TextField { private String xmiId; public IdentifiedTextField(String text) { + int index; + if (!text.isEmpty()) { - int ind = text.indexOf(SEPARATOR); - if (ind != -1) { - xmiId = text.substring(0, ind); - setText(text.substring(ind+1)); + // Remove index of VBox + index = text.indexOf(";"); + if (index != -1) { + text = text.substring(index+1); + } + // Split xmiId and text + index = text.indexOf(SEPARATOR); + if (index != -1) { + xmiId = text.substring(0, index); + setText(text.substring(index+1)); } else { - xmiId = UUID.randomUUID().toString(); setText(text); } - } else { - xmiId = UUID.randomUUID().toString(); } } diff --git a/src/util/persistence/PersistenceManager.java b/src/util/persistence/PersistenceManager.java index 1674b95..1344580 100644 --- a/src/util/persistence/PersistenceManager.java +++ b/src/util/persistence/PersistenceManager.java @@ -1,14 +1,17 @@ package util.persistence; import javafx.scene.shape.LineTo; + import javafx.scene.shape.MoveTo; import javafx.scene.shape.Path; import javafx.scene.shape.PathElement; import model.*; import model.edges.*; import model.nodes.AbstractNode; +import model.nodes.Attribute; import model.nodes.ClassNode; import model.nodes.IdentifiedTextField; +import model.nodes.Operation; import model.nodes.PackageNode; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -30,7 +33,6 @@ import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; -import java.awt.TextField; import java.io.*; import java.util.HashMap; import java.util.Map; @@ -222,7 +224,7 @@ private static void addClassNode(Document doc, ClassNode node, Element parent, G if(node.getAttributes() != null){ String attributes[] = node.getAttributes().split("\\r?\\n"); for(String att : attributes){ - textField = new IdentifiedTextField(att); + textField = new Attribute(att); Element attribute = doc.createElement("UML:Attribute"); attribute.setAttribute("name", textField.getText()); if (textField.getXmiId().contains("-")) { @@ -237,7 +239,7 @@ private static void addClassNode(Document doc, ClassNode node, Element parent, G if(node.getOperations() != null){ String operations[] = node.getOperations().split("\\r?\\n"); for(String op : operations) { - textField = new IdentifiedTextField(op); + textField = new Operation(op); Element operation = doc.createElement("UML:Operation"); operation.setAttribute("name", textField.getText()); if (textField.getXmiId().contains("-")) { @@ -449,7 +451,9 @@ private static AbstractNode createAbstractNode(Element view, Element model, bool attributesCont++; } } - ((ClassNode)abstractNode).setAttributes(attributes); + if (attributesCont > 0) { + ((ClassNode)abstractNode).setAttributes(attributes); + } String operations = ""; operationsCont = 0; for(int i = 0; i < attsOps.getLength(); i++){ @@ -462,7 +466,9 @@ private static AbstractNode createAbstractNode(Element view, Element model, bool operationsCont++; } } - ((ClassNode)abstractNode).setOperations(operations); + if (operationsCont > 0) { + ((ClassNode)abstractNode).setOperations(operations); + } } else { abstractNode = new PackageNode(x, y, width, height); } diff --git a/src/view/nodes/ClassNodeView.java b/src/view/nodes/ClassNodeView.java index 915fd34..9c7f670 100644 --- a/src/view/nodes/ClassNodeView.java +++ b/src/view/nodes/ClassNodeView.java @@ -10,12 +10,10 @@ import javafx.geometry.Pos; import javafx.scene.Node; import javafx.scene.control.ContextMenu; -import javafx.scene.control.Label; import javafx.scene.control.MenuItem; import javafx.scene.control.Separator; import javafx.scene.layout.Background; import javafx.scene.layout.BackgroundFill; -import javafx.scene.layout.BorderStroke; import javafx.scene.layout.CornerRadii; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; @@ -25,10 +23,8 @@ import javafx.scene.shape.Rectangle; import javafx.scene.text.Font; import javafx.scene.text.FontWeight; -import javafx.stage.WindowEvent; import javafx.scene.control.TextField; import javafx.scene.input.KeyEvent; -import javafx.scene.input.MouseEvent; import model.nodes.Attribute; import model.nodes.ClassNode; import model.nodes.IdentifiedTextField; @@ -36,11 +32,7 @@ import util.Constants; import java.beans.PropertyChangeEvent; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.w3c.dom.Element; +import java.util.UUID; /** @@ -178,6 +170,20 @@ private void initVBox(){ title.setText(node.getTitle()); } title.setAlignment(Pos.CENTER); + + MenuItem cmItemAddAttribute; + cmItemAddAttribute = new MenuItem("Add Attribute"); + cmItemAddAttribute.setOnAction(event -> { + addAttribute(); + }); + MenuItem cmItemAddOperation; + cmItemAddOperation = new MenuItem("Add Operation"); + cmItemAddOperation.setOnAction(event -> { + addOperation(); + }); + ContextMenu contextMenu = new ContextMenu(); + contextMenu.getItems().addAll(cmItemAddAttribute,cmItemAddOperation); + title.setContextMenu(contextMenu); titlePane.getChildren().add(title); vbox.getChildren().addAll(titlePane, firstLine); @@ -345,19 +351,6 @@ public void handle(ActionEvent e) { } }); - MenuItem cmItemAdd; - if (textfield instanceof Attribute) { - cmItemAdd = new MenuItem("Add attribute"); - cmItemAdd.setOnAction(event -> { - addAttribute(); - }); - } else { - cmItemAdd = new MenuItem("Add operation"); - cmItemAdd.setOnAction(event -> { - addOperation(); - }); - } - MenuItem cmItemDelete; if (textfield instanceof Attribute) { cmItemDelete = new MenuItem("Delete attribute"); @@ -375,14 +368,14 @@ public void handle(ActionEvent e) { }); ContextMenu contextMenu = new ContextMenu(); - contextMenu.getItems().addAll(cmItemMoveUp,cmItemMoveDown,cmItemAdd,cmItemDelete); + contextMenu.getItems().addAll(cmItemMoveUp,cmItemMoveDown,cmItemDelete); textfield.setContextMenu(contextMenu); } private void initLooksAttributeOperation(IdentifiedTextField textField) { textField.setFont(Font.font("Verdana", 10)); - textField.setStyle("-fx-prompt-text-fill: white"); + textField.setStyle("-fx-prompt-text-fill: red"); BackgroundFill backgroundFill = new BackgroundFill(Color.LIGHTSKYBLUE, CornerRadii.EMPTY, Insets.EMPTY); Background background = new Background(backgroundFill); textField.setPadding(new Insets(0)); @@ -393,7 +386,7 @@ private String extractAttributesFromVBox() { String fullText = ""; for (Node node: vbox.getChildren()) { if (node instanceof Attribute) { - IdentifiedTextField tf = (IdentifiedTextField) node; + Attribute tf = (Attribute) node; fullText = fullText + vbox.getChildren().indexOf(tf) + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); } @@ -405,7 +398,7 @@ private String extractOperationsFromVBox() { String fullText = ""; for (Node node: vbox.getChildren()) { if (node instanceof Operation) { - IdentifiedTextField tf = (IdentifiedTextField) node; + Operation tf = (Operation) node; fullText = fullText + vbox.getChildren().indexOf(tf) + ";" + tf.getXmiId() + "|" + tf.getText() + System.getProperty("line.separator"); } @@ -423,6 +416,8 @@ private void broadcastingAttributesWithOperations() { public void addAttribute() { Attribute textField = new Attribute(""); + textField.setXmiId("att" + UUID.randomUUID().toString() + + "_" + ((ClassNode)getRefNode()).getId()); initLooksAttributeOperation(textField); createHandlesAttributesOperations(textField); vbox.getChildren().add(2+attributesSize(),textField); @@ -431,6 +426,8 @@ public void addAttribute() { public void addOperation() { Operation textField = new Operation(""); + textField.setXmiId("oper" + UUID.randomUUID().toString() + + "_" + ((ClassNode)getRefNode()).getId()); initLooksAttributeOperation(textField); createHandlesAttributesOperations(textField); vbox.getChildren().add(textField); @@ -468,7 +465,7 @@ public void propertyChange(PropertyChangeEvent evt) { for (int cont = 0; cont < vbox.getChildren().size(); cont++ ) { Node node = vbox.getChildren().get(cont); if ( node instanceof Attribute ) { - IdentifiedTextField localTextField = (IdentifiedTextField) node; + Attribute localTextField = (Attribute) node; if (!newValue.contains(localTextField.getXmiId())) { System.out.println("'"+localTextField+"' not found. Removing...\n"); vbox.getChildren().remove(localTextField); @@ -483,7 +480,7 @@ public void propertyChange(PropertyChangeEvent evt) { boolean found = false; for (Node node: vbox.getChildren()) { if ( node instanceof Attribute ) { - IdentifiedTextField localTextField = (IdentifiedTextField) node; + Attribute localTextField = (Attribute) node; if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { found = true; break; @@ -501,10 +498,10 @@ public void propertyChange(PropertyChangeEvent evt) { for(String text : newValue.split("\\r?\\n")){ String array[] = text.split(";"); int index = Integer.parseInt(array[0]); - IdentifiedTextField remoteTextField = new IdentifiedTextField(array[1]); + Attribute remoteTextField = new Attribute(array[1]); for (Node node: vbox.getChildren()) { if ( node instanceof Attribute ) { - IdentifiedTextField localTextField = (IdentifiedTextField) node; + Attribute localTextField = (Attribute) node; if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { // Update text if it was altered if (!localTextField.getText().equals(remoteTextField.getText())) { @@ -535,7 +532,7 @@ public void propertyChange(PropertyChangeEvent evt) { for (int cont = 0; cont < vbox.getChildren().size(); cont++ ) { Node node = vbox.getChildren().get(cont); if ( node instanceof Operation ) { - IdentifiedTextField localTextField = (IdentifiedTextField) node; + Operation localTextField = (Operation) node; if (!newValue.contains(localTextField.getXmiId())) { System.out.println("'"+localTextField+"' not found. Removing...\n"); vbox.getChildren().remove(localTextField); @@ -550,7 +547,7 @@ public void propertyChange(PropertyChangeEvent evt) { boolean found = false; for (Node node: vbox.getChildren()) { if ( node instanceof Operation ) { - IdentifiedTextField localTextField = (IdentifiedTextField) node; + Operation localTextField = (Operation) node; if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { found = true; break; @@ -568,10 +565,10 @@ public void propertyChange(PropertyChangeEvent evt) { for(String text : newValue.split("\\r?\\n")){ String array[] = text.split(";"); int index = Integer.parseInt(array[0]); - IdentifiedTextField remoteTextField = new IdentifiedTextField(array[1]); + Operation remoteTextField = new Operation(array[1]); for (Node node: vbox.getChildren()) { if ( node instanceof Operation ) { - IdentifiedTextField localTextField = (IdentifiedTextField) node; + Operation localTextField = (Operation) node; if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { // Update text if it was altered if (!localTextField.getText().equals(remoteTextField.getText())) { From 51721a902dc0689028ac0cd1f043eef2f81642b0 Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Sat, 5 May 2018 21:13:32 -0300 Subject: [PATCH 21/88] Avoid generating new nodes ids each time a model is saved --- src/controller/ClientController.java | 2 +- src/controller/ServerController.java | 2 +- src/model/Graph.java | 6 +++++- src/model/edges/AbstractEdge.java | 6 +++++- src/model/nodes/AbstractNode.java | 6 +++++- src/util/persistence/PersistenceManager.java | 4 ++++ 6 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/controller/ClientController.java b/src/controller/ClientController.java index 190f534..49f2ae2 100644 --- a/src/controller/ClientController.java +++ b/src/controller/ClientController.java @@ -38,7 +38,7 @@ public ClientController(AbstractDiagramController pDiagramController, String pSe port = pPort; // Increase of buffers size to avoid overflow. Defaults: 8192, 2048 - client = new Client(8192,8192); + client = new Client(16384,16384); initKryo(client.getKryo()); diff --git a/src/controller/ServerController.java b/src/controller/ServerController.java index d8ab83e..2b96d48 100644 --- a/src/controller/ServerController.java +++ b/src/controller/ServerController.java @@ -37,7 +37,7 @@ public ServerController(Graph pGraph, AbstractDiagramController pDiagramControll graph.addRemotePropertyChangeListener(this); // Increase of buffers size to avoid overflow. Defaults: 16384, 2048 - server = new Server(16384,8192); + server = new Server(16384,16384); server.start(); try { server.bind(port,port); diff --git a/src/model/Graph.java b/src/model/Graph.java index 14f956c..ccbdef5 100644 --- a/src/model/Graph.java +++ b/src/model/Graph.java @@ -216,8 +216,12 @@ public void setAllSketches(List allSketches) { public String getId(){ return "GRAPH_" + id; } + + public void setId(int id) { + this.id = id; + } - public void addRemotePropertyChangeListener(PropertyChangeListener l) { + public void addRemotePropertyChangeListener(PropertyChangeListener l) { remoteChanges.addPropertyChangeListener(l); } diff --git a/src/model/edges/AbstractEdge.java b/src/model/edges/AbstractEdge.java index 44c153e..3cd9779 100644 --- a/src/model/edges/AbstractEdge.java +++ b/src/model/edges/AbstractEdge.java @@ -163,7 +163,11 @@ public String getId(){ return "EDGE_" + id; } - public static void incrementObjectCount(){ + public void setId(int id) { + this.id = id; + } + + public static void incrementObjectCount(){ objectCount++; } diff --git a/src/model/nodes/AbstractNode.java b/src/model/nodes/AbstractNode.java index eb0ece4..392a05b 100644 --- a/src/model/nodes/AbstractNode.java +++ b/src/model/nodes/AbstractNode.java @@ -226,8 +226,12 @@ public AbstractNode(){ public String getId(){ return "NODE_" + id; } + + public void setId(int id) { + this.id = id; + } - public static void incrementObjectCount(){ + public static void incrementObjectCount(){ objectCount++; } diff --git a/src/util/persistence/PersistenceManager.java b/src/util/persistence/PersistenceManager.java index 1344580..72825a1 100644 --- a/src/util/persistence/PersistenceManager.java +++ b/src/util/persistence/PersistenceManager.java @@ -322,6 +322,7 @@ public static Graph importXMI(Document doc){ Element umlModel = ((Element)nList.item(0)); graph.setName(umlModel.getAttribute("name")); String modelNamespace = umlModel.getAttribute("xmi.id"); + graph.setId(Integer.parseInt(modelNamespace.substring(modelNamespace.indexOf("_")+1))); //Import packages nList = doc.getElementsByTagName("UML:Package"); @@ -333,6 +334,7 @@ public static Graph importXMI(Document doc){ if(viewElement.getAttribute("subject").equals(modelElement.getAttribute("xmi.id"))){ Boolean isChild = !modelElement.getAttribute("namespace").equals(modelNamespace); AbstractNode node = createAbstractNode(viewElement, modelElement, isChild, true); + node.setId(Integer.parseInt(modelElement.getAttribute("xmi.id").substring(modelElement.getAttribute("xmi.id").indexOf("_")+1))); idMap.put(modelElement.getAttribute("xmi.id"), node); graph.addNode(node, false); } @@ -349,6 +351,7 @@ public static Graph importXMI(Document doc){ if(viewElement.getAttribute("subject").equals(modelElement.getAttribute("xmi.id"))){ Boolean isChild = !modelElement.getAttribute("namespace").equals(modelNamespace); AbstractNode node = createAbstractNode(viewElement, modelElement, isChild, false); + node.setId(Integer.parseInt(modelElement.getAttribute("xmi.id").substring(modelElement.getAttribute("xmi.id").indexOf("_")+1))); idMap.put(modelElement.getAttribute("xmi.id"), node); graph.addNode(node, false); } @@ -398,6 +401,7 @@ public static Graph importXMI(Document doc){ } } graph.addEdge(edge, false); + edge.setId(Integer.parseInt(associationElement.getAttribute("xmi.id").substring(associationElement.getAttribute("xmi.id").indexOf("_")+1))); } From 2c6bacdd86807f48c6b8b0fa789390c0ea4645ef Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Mon, 7 May 2018 21:16:19 -0300 Subject: [PATCH 22/88] Better log code for synchonization debug --- src/model/nodes/IdentifiedTextField.java | 15 +++++- src/view/nodes/ClassNodeView.java | 60 +++++++++--------------- 2 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/model/nodes/IdentifiedTextField.java b/src/model/nodes/IdentifiedTextField.java index 0ada2ef..da599e5 100644 --- a/src/model/nodes/IdentifiedTextField.java +++ b/src/model/nodes/IdentifiedTextField.java @@ -36,8 +36,21 @@ public void setXmiId(String xmiId) { this.xmiId = xmiId; } + // Make UUIDs short for log purposes + private String getShortXmiId() { + String leftside, rightside; + + if (xmiId.contains("-")) { + leftside = xmiId.substring(0, xmiId.indexOf("-")-4); + rightside = xmiId.substring(xmiId.indexOf("-")+24); + } else { + return xmiId; + } + return leftside + ".." + rightside; + } + public String toString() { - return xmiId + SEPARATOR + getText(); + return getShortXmiId() + SEPARATOR + getText(); } @Override diff --git a/src/view/nodes/ClassNodeView.java b/src/view/nodes/ClassNodeView.java index 9c7f670..655831f 100644 --- a/src/view/nodes/ClassNodeView.java +++ b/src/view/nodes/ClassNodeView.java @@ -136,7 +136,7 @@ private void createHandles(){ @Override public void changed(ObservableValue observable, String oldValue, String newValue) { - System.out.println("Broadcasting title '" + newValue + "'\n"); + System.out.println("Title '" + newValue + "' updated. Broadcasting...\n"); ((ClassNode)getRefNode()).setTitle(newValue); } }); @@ -282,20 +282,16 @@ private int operationsSize() { return cont; } - private void createHandlesAttributesOperations(IdentifiedTextField textfield) { textfield.setOnKeyReleased(new EventHandler() { public void handle(KeyEvent ke) { - String fullText = ""; if (textfield instanceof Attribute) { - fullText = extractAttributesFromVBox(); - System.out.println("KeyReleased. Broadcasting:\n"+fullText+"\n"); - ((ClassNode)getRefNode()).setAttributes(fullText); + System.out.println("'"+textfield+"' updated. Broadcasting...\n"); + ((ClassNode)getRefNode()).setAttributes(extractAttributesFromVBox()); } else if (textfield instanceof Operation) { - fullText = extractOperationsFromVBox(); - System.out.println("KeyReleased. Broadcasting:\n"+fullText+"\n"); - ((ClassNode)getRefNode()).setOperations(fullText); + System.out.println("'"+textfield+"' updated. Broadcasting...\n"); + ((ClassNode)getRefNode()).setOperations(extractOperationsFromVBox()); } } }); @@ -306,22 +302,19 @@ public void handle(KeyEvent ke) { cmItemMoveUp.setOnAction(new EventHandler() { public void handle(ActionEvent e) { IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); - String fullText = ""; int index = vbox.getChildren().indexOf(modifiedTextField); if (textfield instanceof Attribute && index > 2) { index--; vbox.getChildren().remove(modifiedTextField); vbox.getChildren().add(index,modifiedTextField); - fullText = extractAttributesFromVBox(); - System.out.println("Move Up. Broadcasting:\n"+fullText+"\n"); - ((ClassNode)getRefNode()).setAttributes(fullText); + System.out.println("'"+modifiedTextField+"' Moved Up. Broadcasting...\n"); + ((ClassNode)getRefNode()).setAttributes(extractAttributesFromVBox()); } else if (textfield instanceof Operation && index > (3+attributesSize())) { index--; vbox.getChildren().remove(modifiedTextField); vbox.getChildren().add(index,modifiedTextField); - fullText = extractOperationsFromVBox(); - System.out.println("Move Up. Broadcasting:\n"+fullText+"\n"); - ((ClassNode)getRefNode()).setOperations(fullText); + System.out.println("'"+modifiedTextField+"' Moved Up. Broadcasting...\n"); + ((ClassNode)getRefNode()).setOperations(extractOperationsFromVBox()); } } }); @@ -331,22 +324,19 @@ public void handle(ActionEvent e) { cmItemMoveDown.setOnAction(new EventHandler() { public void handle(ActionEvent e) { IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); - String fullText = ""; int index = vbox.getChildren().indexOf(modifiedTextField); if (textfield instanceof Attribute && index < (1+attributesSize())) { index++; vbox.getChildren().remove(modifiedTextField); vbox.getChildren().add(index,modifiedTextField); - fullText = extractAttributesFromVBox(); - System.out.println("Move Down. Broadcasting:\n"+fullText+"\n"); - ((ClassNode)getRefNode()).setAttributes(fullText); + System.out.println("'"+modifiedTextField+"' Moved Down. Broadcasting...\n"); + ((ClassNode)getRefNode()).setAttributes(extractAttributesFromVBox()); } else if (textfield instanceof Operation && index < (2+attributesSize()+operationsSize())) { index++; vbox.getChildren().remove(modifiedTextField); vbox.getChildren().add(index,modifiedTextField); - fullText = extractOperationsFromVBox(); - System.out.println("Move Down. Broadcasting:\n"+fullText+"\n"); - ((ClassNode)getRefNode()).setOperations(fullText); + System.out.println("'"+modifiedTextField+"' Moved Down. Broadcasting...\n"); + ((ClassNode)getRefNode()).setOperations(extractOperationsFromVBox()); } } }); @@ -360,9 +350,9 @@ public void handle(ActionEvent e) { cmItemDelete.setUserData(textfield); cmItemDelete.setOnAction(new EventHandler() { public void handle(ActionEvent e) { - System.out.println("Delete attribute/operation"); IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); vbox.getChildren().remove(modifiedTextField); + System.out.println("'"+modifiedTextField+"' deleted. Broadcasting...\n"); broadcastingAttributesWithOperations(); } }); @@ -409,8 +399,6 @@ private String extractOperationsFromVBox() { private void broadcastingAttributesWithOperations() { String attributesfullText = extractAttributesFromVBox(); String operationsFullText = extractOperationsFromVBox(); - System.out.println("Broadcasting attributes with operations:\n"+attributesfullText+ - "\n"+operationsFullText+"\n"); ((ClassNode)getRefNode()).setAttributesWithOperations(attributesfullText,operationsFullText); } @@ -451,7 +439,7 @@ public void propertyChange(PropertyChangeEvent evt) { String newValue = (String) evt.getNewValue(); // Update text if it was altered if (!title.getText().equals(newValue)) { - System.out.println("Title changed to '" + newValue + "'\n"); + System.out.println("Received title '" + newValue + "'. Updating...\n"); title.setText(newValue); } if (title.getText() == null || title.getText().equals("")) { @@ -467,7 +455,7 @@ public void propertyChange(PropertyChangeEvent evt) { if ( node instanceof Attribute ) { Attribute localTextField = (Attribute) node; if (!newValue.contains(localTextField.getXmiId())) { - System.out.println("'"+localTextField+"' not found. Removing...\n"); + System.out.println("Received '"+localTextField+"'. Deleting...\n"); vbox.getChildren().remove(localTextField); } } @@ -488,7 +476,7 @@ public void propertyChange(PropertyChangeEvent evt) { } } if (!found) { - System.out.println("'"+remoteTextField+"' not found. Adding with index = "+index+"\n"); + System.out.println("Received '"+index+"|"+remoteTextField+"' Adding...\n"); initLooksAttributeOperation(remoteTextField); createHandlesAttributesOperations(remoteTextField); vbox.getChildren().add(index,remoteTextField); @@ -505,13 +493,12 @@ public void propertyChange(PropertyChangeEvent evt) { if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { // Update text if it was altered if (!localTextField.getText().equals(remoteTextField.getText())) { - System.out.println("'"+localTextField+"' is old. Updating to '"+remoteTextField+"'\n"); + System.out.println("Received '"+remoteTextField+"'. Updating text...\n"); localTextField.setText(remoteTextField.getText()); } // If moved upper or down if (vbox.getChildren().indexOf(localTextField) != index) { - System.out.println("'"+localTextField+"' index is " + vbox.getChildren().indexOf(localTextField) + - ". Updating to index to "+ index+"\n"); + System.out.println("Received '"+localTextField+"'. Updating index to " + index+ "\n"); vbox.getChildren().remove(localTextField); vbox.getChildren().add(index,localTextField); } @@ -534,7 +521,7 @@ public void propertyChange(PropertyChangeEvent evt) { if ( node instanceof Operation ) { Operation localTextField = (Operation) node; if (!newValue.contains(localTextField.getXmiId())) { - System.out.println("'"+localTextField+"' not found. Removing...\n"); + System.out.println("Received '"+localTextField+"'. Deleting..."); vbox.getChildren().remove(localTextField); } } @@ -555,7 +542,7 @@ public void propertyChange(PropertyChangeEvent evt) { } } if (!found) { - System.out.println("'"+remoteTextField+"' not found. Adding with index = "+index+"\n"); + System.out.println("Received '"+remoteTextField+"'. Adding...\n"); initLooksAttributeOperation(remoteTextField); createHandlesAttributesOperations(remoteTextField); vbox.getChildren().add(index,remoteTextField); @@ -572,13 +559,12 @@ public void propertyChange(PropertyChangeEvent evt) { if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { // Update text if it was altered if (!localTextField.getText().equals(remoteTextField.getText())) { - System.out.println("'"+localTextField+"' is old. Updating to "+remoteTextField+"\n"); + System.out.println("Received '"+remoteTextField+"'. Updating text...\n"); localTextField.setText(remoteTextField.getText()); } // If moved upper or down if (vbox.getChildren().indexOf(localTextField) != index) { - System.out.println("'"+localTextField+"' index is " + vbox.getChildren().indexOf(localTextField) + - ". Updating index to "+ index+"\n"); + System.out.println("Received '"+localTextField+"'. Updating index to " + index+ "\n"); vbox.getChildren().remove(localTextField); vbox.getChildren().add(index,localTextField); } From 913b281123c2045f804f5b3e8f314937d4c4f6b8 Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Tue, 8 May 2018 02:33:24 -0300 Subject: [PATCH 23/88] Better log code for synchonization debug --- src/model/nodes/IdentifiedTextField.java | 12 ++++++++ src/view/nodes/ClassNodeView.java | 39 +++++------------------- 2 files changed, 19 insertions(+), 32 deletions(-) diff --git a/src/model/nodes/IdentifiedTextField.java b/src/model/nodes/IdentifiedTextField.java index da599e5..40adb96 100644 --- a/src/model/nodes/IdentifiedTextField.java +++ b/src/model/nodes/IdentifiedTextField.java @@ -1,6 +1,12 @@ package model.nodes; +import javafx.geometry.Insets; import javafx.scene.control.TextField; +import javafx.scene.layout.Background; +import javafx.scene.layout.BackgroundFill; +import javafx.scene.layout.CornerRadii; +import javafx.scene.paint.Color; +import javafx.scene.text.Font; public class IdentifiedTextField extends TextField { @@ -26,6 +32,12 @@ public IdentifiedTextField(String text) { setText(text); } } + BackgroundFill backgroundFill = new BackgroundFill(Color.LIGHTSKYBLUE, CornerRadii.EMPTY, Insets.EMPTY); + Background background = new Background(backgroundFill); + setPadding(new Insets(0)); + setBackground(background); + setFont(Font.font("Verdana", 10)); + setStyle("-fx-prompt-text-fill: red"); } public String getXmiId() { diff --git a/src/view/nodes/ClassNodeView.java b/src/view/nodes/ClassNodeView.java index 655831f..fb43836 100644 --- a/src/view/nodes/ClassNodeView.java +++ b/src/view/nodes/ClassNodeView.java @@ -132,12 +132,10 @@ private void createHandles(){ this.getChildren().addAll(shortHandleLine, longHandleLine); - title.textProperty().addListener(new ChangeListener() { - @Override - public void changed(ObservableValue observable, - String oldValue, String newValue) { - System.out.println("Title '" + newValue + "' updated. Broadcasting...\n"); - ((ClassNode)getRefNode()).setTitle(newValue); + title.setOnKeyReleased(new EventHandler() { + public void handle(KeyEvent ke) { + System.out.println("Title '" + title.getText() + "' updated. Broadcasting...\n"); + ((ClassNode)getRefNode()).setTitle(title.getText()); } }); for(Node node: vbox.getChildren()) { @@ -194,7 +192,6 @@ private void initVBox(){ text = text.substring(text.indexOf(";")+1); } Attribute attribute = new Attribute(text); - attribute.setFont(Font.font("Verdana", 10)); vbox.getChildren().add(attribute); } } @@ -207,7 +204,6 @@ private void initVBox(){ text = text.substring(text.indexOf(";")+1); } Operation operation = new Operation(text); - operation.setFont(Font.font("Verdana", 10)); vbox.getChildren().add(operation); } } @@ -227,13 +223,6 @@ private void initLooks(){ BackgroundFill backgroundFill = new BackgroundFill(Color.LIGHTSKYBLUE, CornerRadii.EMPTY, Insets.EMPTY); Background background = new Background(backgroundFill); title.setBackground(background); - for(Node node: vbox.getChildren()) { - if (node instanceof Attribute || node instanceof Operation) { - TextField tf = (TextField) node; - tf.setPadding(new Insets(0)); - tf.setBackground(background); - } - } } public void setSelected(boolean selected){ @@ -361,16 +350,6 @@ public void handle(ActionEvent e) { contextMenu.getItems().addAll(cmItemMoveUp,cmItemMoveDown,cmItemDelete); textfield.setContextMenu(contextMenu); } - - - private void initLooksAttributeOperation(IdentifiedTextField textField) { - textField.setFont(Font.font("Verdana", 10)); - textField.setStyle("-fx-prompt-text-fill: red"); - BackgroundFill backgroundFill = new BackgroundFill(Color.LIGHTSKYBLUE, CornerRadii.EMPTY, Insets.EMPTY); - Background background = new Background(backgroundFill); - textField.setPadding(new Insets(0)); - textField.setBackground(background); - } private String extractAttributesFromVBox() { String fullText = ""; @@ -406,7 +385,6 @@ public void addAttribute() { Attribute textField = new Attribute(""); textField.setXmiId("att" + UUID.randomUUID().toString() + "_" + ((ClassNode)getRefNode()).getId()); - initLooksAttributeOperation(textField); createHandlesAttributesOperations(textField); vbox.getChildren().add(2+attributesSize(),textField); broadcastingAttributesWithOperations(); @@ -416,7 +394,6 @@ public void addOperation() { Operation textField = new Operation(""); textField.setXmiId("oper" + UUID.randomUUID().toString() + "_" + ((ClassNode)getRefNode()).getId()); - initLooksAttributeOperation(textField); createHandlesAttributesOperations(textField); vbox.getChildren().add(textField); broadcastingAttributesWithOperations(); @@ -476,8 +453,7 @@ public void propertyChange(PropertyChangeEvent evt) { } } if (!found) { - System.out.println("Received '"+index+"|"+remoteTextField+"' Adding...\n"); - initLooksAttributeOperation(remoteTextField); + System.out.println("Received '"+remoteTextField+"'. Adding...\n"); createHandlesAttributesOperations(remoteTextField); vbox.getChildren().add(index,remoteTextField); } @@ -498,7 +474,7 @@ public void propertyChange(PropertyChangeEvent evt) { } // If moved upper or down if (vbox.getChildren().indexOf(localTextField) != index) { - System.out.println("Received '"+localTextField+"'. Updating index to " + index+ "\n"); + System.out.println("Received '"+localTextField+"'. Updating index to " + index + "\n"); vbox.getChildren().remove(localTextField); vbox.getChildren().add(index,localTextField); } @@ -521,7 +497,7 @@ public void propertyChange(PropertyChangeEvent evt) { if ( node instanceof Operation ) { Operation localTextField = (Operation) node; if (!newValue.contains(localTextField.getXmiId())) { - System.out.println("Received '"+localTextField+"'. Deleting..."); + System.out.println("Received '"+localTextField+"'. Deleting...\n"); vbox.getChildren().remove(localTextField); } } @@ -543,7 +519,6 @@ public void propertyChange(PropertyChangeEvent evt) { } if (!found) { System.out.println("Received '"+remoteTextField+"'. Adding...\n"); - initLooksAttributeOperation(remoteTextField); createHandlesAttributesOperations(remoteTextField); vbox.getChildren().add(index,remoteTextField); } From 048ce81a7fa809fe44227ffe18a709862b15642a Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Wed, 8 Aug 2018 21:24:31 -0300 Subject: [PATCH 24/88] Update id of nodes and edges to uuid --- src/model/edges/AbstractEdge.java | 7 +++-- src/model/nodes/AbstractNode.java | 7 +++-- src/util/persistence/PersistenceManager.java | 33 ++++++++++++++++---- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/model/edges/AbstractEdge.java b/src/model/edges/AbstractEdge.java index 3cd9779..228679d 100644 --- a/src/model/edges/AbstractEdge.java +++ b/src/model/edges/AbstractEdge.java @@ -3,6 +3,7 @@ import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.io.Serializable; +import java.util.UUID; import model.nodes.Node; import util.Constants; @@ -13,7 +14,7 @@ public abstract class AbstractEdge implements Edge, Serializable { private static int objectCount = 0; //Used to ID instance - private int id = 0; + private String id; private static final long serialVersionUID = 1L; //Listened to by the view, is always fired. @@ -38,7 +39,7 @@ public AbstractEdge(Node startNode, Node endNode) { this.endNode = endNode; direction = Direction.NO_DIRECTION; - id = ++objectCount; + id = UUID.randomUUID().toString(); } public void setDirection(Direction pDirection) { @@ -163,7 +164,7 @@ public String getId(){ return "EDGE_" + id; } - public void setId(int id) { + public void setId(String id) { this.id = id; } diff --git a/src/model/nodes/AbstractNode.java b/src/model/nodes/AbstractNode.java index 392a05b..4ed9cc7 100644 --- a/src/model/nodes/AbstractNode.java +++ b/src/model/nodes/AbstractNode.java @@ -6,6 +6,7 @@ import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.io.Serializable; +import java.util.UUID; /** * Abstract Node to hide some basic functionality for Nodes. @@ -21,7 +22,7 @@ public abstract class AbstractNode implements Node, Serializable private static final long serialVersionUID = 1L; protected static int objectCount = 0; //Used to ID instance - private int id; + private String id; //Listened to by the view, is always fired. protected transient PropertyChangeSupport changes = new PropertyChangeSupport(this); @@ -43,7 +44,7 @@ public AbstractNode(double x, double y, double width, double height){ scaleX = 1.0d; scaleY = 1.0d; - id = ++objectCount; + id = UUID.randomUUID().toString(); } public void setIsChild(boolean pIsChild){ @@ -227,7 +228,7 @@ public String getId(){ return "NODE_" + id; } - public void setId(int id) { + public void setId(String id) { this.id = id; } diff --git a/src/util/persistence/PersistenceManager.java b/src/util/persistence/PersistenceManager.java index 72825a1..605f8df 100644 --- a/src/util/persistence/PersistenceManager.java +++ b/src/util/persistence/PersistenceManager.java @@ -334,7 +334,15 @@ public static Graph importXMI(Document doc){ if(viewElement.getAttribute("subject").equals(modelElement.getAttribute("xmi.id"))){ Boolean isChild = !modelElement.getAttribute("namespace").equals(modelNamespace); AbstractNode node = createAbstractNode(viewElement, modelElement, isChild, true); - node.setId(Integer.parseInt(modelElement.getAttribute("xmi.id").substring(modelElement.getAttribute("xmi.id").indexOf("_")+1))); + String id; + try { + // If id is a int type (for old files), replace for UUID + Integer.parseInt(modelElement.getAttribute("xmi.id").substring(modelElement.getAttribute("xmi.id").indexOf("_")+1)); + id = UUID.randomUUID().toString(); + } catch (Exception e) { + id = modelElement.getAttribute("xmi.id").substring(modelElement.getAttribute("xmi.id").indexOf("_")+1); + } + node.setId(id); idMap.put(modelElement.getAttribute("xmi.id"), node); graph.addNode(node, false); } @@ -351,7 +359,15 @@ public static Graph importXMI(Document doc){ if(viewElement.getAttribute("subject").equals(modelElement.getAttribute("xmi.id"))){ Boolean isChild = !modelElement.getAttribute("namespace").equals(modelNamespace); AbstractNode node = createAbstractNode(viewElement, modelElement, isChild, false); - node.setId(Integer.parseInt(modelElement.getAttribute("xmi.id").substring(modelElement.getAttribute("xmi.id").indexOf("_")+1))); + String id; + try { + // If id is a int type (for old files), replace for UUID + Integer.parseInt(modelElement.getAttribute("xmi.id").substring(modelElement.getAttribute("xmi.id").indexOf("_")+1)); + id = UUID.randomUUID().toString(); + } catch (Exception e) { + id = modelElement.getAttribute("xmi.id").substring(modelElement.getAttribute("xmi.id").indexOf("_")+1); + } + node.setId(id); idMap.put(modelElement.getAttribute("xmi.id"), node); graph.addNode(node, false); } @@ -401,12 +417,17 @@ public static Graph importXMI(Document doc){ } } graph.addEdge(edge, false); - edge.setId(Integer.parseInt(associationElement.getAttribute("xmi.id").substring(associationElement.getAttribute("xmi.id").indexOf("_")+1))); + String id; + try { + // If id is a int type (for old files), replace for UUID + Integer.parseInt(associationElement.getAttribute("xmi.id").substring(associationElement.getAttribute("xmi.id").indexOf("_")+1)); + id = UUID.randomUUID().toString(); + } catch (Exception e) { + id = associationElement.getAttribute("xmi.id").substring(associationElement.getAttribute("xmi.id").indexOf("_")+1); + } + edge.setId(id); } - - - //Import sketches nList = doc.getElementsByTagName("Sketch"); for(int i = 0; i < nList.getLength(); i++) { From ca458a19de3e43b1fa13aaa684e35beda99f6de0 Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Wed, 8 Aug 2018 23:50:12 -0300 Subject: [PATCH 25/88] Remove old id node suffix --- src/util/persistence/PersistenceManager.java | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/util/persistence/PersistenceManager.java b/src/util/persistence/PersistenceManager.java index 605f8df..c97ef9d 100644 --- a/src/util/persistence/PersistenceManager.java +++ b/src/util/persistence/PersistenceManager.java @@ -228,10 +228,14 @@ private static void addClassNode(Document doc, ClassNode node, Element parent, G Element attribute = doc.createElement("UML:Attribute"); attribute.setAttribute("name", textField.getText()); if (textField.getXmiId().contains("-")) { - attribute.setAttribute("xmi.id", textField.getXmiId()); + if (textField.getXmiId().contains("_")) { + // Remove old id node suffix + attribute.setAttribute("xmi.id", textField.getXmiId().substring(0,textField.getXmiId().indexOf("_"))); + } else { + attribute.setAttribute("xmi.id", textField.getXmiId()); + } } else { - attribute.setAttribute("xmi.id", "att" + UUID.randomUUID().toString() - + "_" + node.getId()); + attribute.setAttribute("xmi.id", "att" + UUID.randomUUID().toString()); } classifierFeature.appendChild(attribute); } @@ -243,10 +247,14 @@ private static void addClassNode(Document doc, ClassNode node, Element parent, G Element operation = doc.createElement("UML:Operation"); operation.setAttribute("name", textField.getText()); if (textField.getXmiId().contains("-")) { - operation.setAttribute("xmi.id", textField.getXmiId()); + if (textField.getXmiId().contains("_")) { + // Remove old id node suffix + operation.setAttribute("xmi.id", textField.getXmiId().substring(0,textField.getXmiId().indexOf("_"))); + } else { + operation.setAttribute("xmi.id", textField.getXmiId()); + } } else { - operation.setAttribute("xmi.id", "oper" + UUID.randomUUID().toString() - + "_" + node.getId()); + operation.setAttribute("xmi.id", "oper" + UUID.randomUUID().toString()); } classifierFeature.appendChild(operation); } From 68e5b6a3c6908679644215bdc6f19691af5a0fdc Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Thu, 9 Aug 2018 23:59:39 -0300 Subject: [PATCH 26/88] Added username support for colaboration --- src/controller/AbstractDiagramController.java | 3 + src/controller/ClientController.java | 78 ++++++++++-------- src/controller/ServerController.java | 82 +++++++++++-------- src/util/GlobalVariables.java | 14 ++++ src/util/NetworkUtils.java | 26 ++++-- src/view/nodes/ClassNodeView.java | 54 +++++++----- 6 files changed, 160 insertions(+), 97 deletions(-) create mode 100644 src/util/GlobalVariables.java diff --git a/src/controller/AbstractDiagramController.java b/src/controller/AbstractDiagramController.java index 8937c2d..afea102 100644 --- a/src/controller/AbstractDiagramController.java +++ b/src/controller/AbstractDiagramController.java @@ -20,6 +20,7 @@ import model.edges.*; import model.nodes.*; import util.Constants; +import util.GlobalVariables; import util.NetworkUtils; import util.commands.*; import util.insertIMG.*; @@ -516,6 +517,7 @@ public void handleMenuActionServer(){ Optional port = portDialog.showAndWait(); + GlobalVariables.setUserName("server"); ServerController server = new ServerController(graph, this, Integer.parseInt(port.get())); serverControllers.add(server); } @@ -525,6 +527,7 @@ public boolean handleMenuActionClient(){ String[] result = NetworkUtils.queryServerPort(); if (result != null) { + GlobalVariables.setUserName(result[2]); ClientController client = new ClientController(this, result[0], Integer.parseInt(result[1])); if(!client.connect()){ client.close(); diff --git a/src/controller/ClientController.java b/src/controller/ClientController.java index 49f2ae2..ea6338b 100644 --- a/src/controller/ClientController.java +++ b/src/controller/ClientController.java @@ -14,6 +14,7 @@ import model.nodes.ClassNode; import model.nodes.PackageNode; import util.Constants; +import util.GlobalVariables; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -31,12 +32,11 @@ public class ClientController implements PropertyChangeListener { private String serverIp; private int port; - public ClientController(AbstractDiagramController pDiagramController, String pServerIp, int pPort) { diagramController = pDiagramController; serverIp = pServerIp; port = pPort; - + // Increase of buffers size to avoid overflow. Defaults: 8192, 2048 client = new Client(16384,16384); @@ -44,20 +44,23 @@ public ClientController(AbstractDiagramController pDiagramController, String pSe client.addListener(new Listener() { public void received (Connection connection, Object object) { - if (object instanceof AbstractNode) { - Platform.runLater(() -> diagramController.createNodeView((AbstractNode)object, true)); - } - else if (object instanceof AbstractEdge) { - Platform.runLater(() -> diagramController.addEdgeView((AbstractEdge)object, true)); - } - else if (object instanceof Graph){ - Graph graph = (Graph) object; - graph.addRemotePropertyChangeListener(ClientController.this); - Platform.runLater(() -> diagramController.load(graph, true)); - } - else if (object instanceof String[]){ - Platform.runLater(() -> diagramController.remoteCommand((String[])object)); - } + if ( object instanceof Object[]) { + Object[] dataArray = (Object[]) object; + if ( dataArray[0] instanceof AbstractNode) { + Platform.runLater(() -> diagramController.createNodeView((AbstractNode)dataArray[0], true)); + } + else if (dataArray[0] instanceof AbstractEdge) { + Platform.runLater(() -> diagramController.addEdgeView((AbstractEdge)dataArray[0], true)); + } + else if (dataArray[0] instanceof Graph){ + Graph graph = (Graph) dataArray[0]; + graph.addRemotePropertyChangeListener(ClientController.this); + Platform.runLater(() -> diagramController.load(graph, true)); + } + else if (object instanceof String[]){ + Platform.runLater(() -> diagramController.remoteCommand((String[])object)); + } + } } }); } @@ -77,8 +80,8 @@ public boolean connect(){ client.close(); return false; } - - client.sendTCP(Constants.requestGraph); + Object[] dataArray = {Constants.requestGraph, GlobalVariables.getUserName()}; + client.sendTCP(dataArray); return true; } @@ -93,79 +96,85 @@ public void close(){ public void propertyChange(PropertyChangeEvent evt) { String propertyName = evt.getPropertyName(); if(propertyName.equals(Constants.sketchAdd)){ - String[] dataArray = {Constants.sketchAdd}; //Because serializing Sketch was tricky + String[] dataArray = { Constants.sketchAdd, GlobalVariables.getUserName()}; //Because serializing Sketch was tricky client.sendTCP(dataArray); } else if (propertyName.equals(Constants.changeSketchPoint)){ Sketch sketch = (Sketch) evt.getSource(); Point2D point = (Point2D) evt.getNewValue(); String[] dataArray = {Constants.changeSketchPoint, sketch.getId(), - Double.toString(point.getX()), Double.toString(point.getY())}; + Double.toString(point.getX()), Double.toString(point.getY()), GlobalVariables.getUserName()}; client.sendTCP(dataArray); } else if (propertyName.equals(Constants.changeSketchStart)) { Sketch sketch = (Sketch) evt.getSource(); Point2D point = (Point2D) evt.getNewValue(); String[] dataArray = {Constants.changeSketchStart, sketch.getId(), - Double.toString(point.getX()), Double.toString(point.getY()), sketch.getColor().toString()}; + Double.toString(point.getX()), Double.toString(point.getY()), sketch.getColor().toString(), GlobalVariables.getUserName()}; client.sendTCP(dataArray); } else if (propertyName.equals(Constants.sketchRemove)){ - String[] dataArray = {Constants.sketchRemove, (String)evt.getNewValue()}; + String[] dataArray = {Constants.sketchRemove, (String)evt.getNewValue(), GlobalVariables.getUserName()}; client.sendTCP(dataArray); } else if(propertyName.equals(Constants.NodeAdd)) { AbstractNode node = (AbstractNode) evt.getNewValue(); - client.sendTCP(node); + Object[] dataArray = {node, GlobalVariables.getUserName()}; + client.sendTCP(dataArray); } else if (propertyName.equals(Constants.NodeRemove)){ - String[] dataArray = {Constants.NodeRemove, (String)evt.getNewValue()}; + String[] dataArray = {Constants.NodeRemove, (String)evt.getNewValue(), GlobalVariables.getUserName()}; client.sendTCP(dataArray); } else if (propertyName.equals(Constants.EdgeAdd)){ AbstractEdge edge = (AbstractEdge) evt.getNewValue(); - client.sendTCP(edge); + Object[] dataArray = {edge, GlobalVariables.getUserName()}; + client.sendTCP(dataArray); } else if(propertyName.equals(Constants.EdgeRemove)) { - String [] dataArray = {Constants.EdgeRemove, (String)evt.getNewValue()}; + String [] dataArray = {Constants.EdgeRemove, (String)evt.getNewValue(), GlobalVariables.getUserName()}; client.sendTCP(dataArray); } else if (propertyName.equals(Constants.changeNodeTranslateX) || propertyName.equals(Constants.changeNodeTranslateY)) { //NodeX/Y not needed AbstractNode node = (AbstractNode) evt.getSource(); - String[] dataArray = {propertyName, node.getId(), Double.toString(node.getTranslateX()), Double.toString(node.getTranslateY())}; + String[] dataArray = {propertyName, node.getId(), + Double.toString(node.getTranslateX()), + Double.toString(node.getTranslateY()), GlobalVariables.getUserName()}; client.sendTCP(dataArray); } else if (propertyName.equals(Constants.changeNodeWidth) || propertyName.equals(Constants.changeNodeHeight)){ AbstractNode node = (AbstractNode) evt.getSource(); - String[] dataArray = {propertyName, node.getId(), Double.toString(node.getWidth()), Double.toString(node.getHeight())}; + String[] dataArray = {propertyName, node.getId(), + Double.toString(node.getWidth()), + Double.toString(node.getHeight()), GlobalVariables.getUserName()}; client.sendTCP(dataArray); } else if (propertyName.equals(Constants.changeNodeTitle)) { AbstractNode node = (AbstractNode) evt.getSource(); - String[] dataArray = {propertyName, node.getId(), node.getTitle()}; + String[] dataArray = {propertyName, node.getId(), node.getTitle(), GlobalVariables.getUserName()}; client.sendTCP(dataArray); } else if (propertyName.equals(Constants.changeClassNodeAttributes) || propertyName.equals(Constants.changeClassNodeOperations)){ ClassNode node = (ClassNode) evt.getSource(); - String[] dataArray = {propertyName, node.getId(), node.getAttributes(), node.getOperations()}; + String[] dataArray = {propertyName, node.getId(), node.getAttributes(), node.getOperations(), GlobalVariables.getUserName()}; client.sendTCP(dataArray); } else if(propertyName.equals(Constants.changeEdgeStartMultiplicity) || propertyName.equals(Constants.changeEdgeEndMultiplicity)){ AbstractEdge edge = (AbstractEdge) evt.getSource(); - String[] dataArray = {propertyName, edge.getId(), edge.getStartMultiplicity(), edge.getEndMultiplicity()}; + String[] dataArray = {propertyName, edge.getId(), edge.getStartMultiplicity(), edge.getEndMultiplicity(), GlobalVariables.getUserName()}; client.sendTCP(dataArray); } else if(propertyName.equals(Constants.changeLabel)){ AbstractEdge edge = (AbstractEdge) evt.getSource(); - String[] dataArray = {propertyName, edge.getId(), edge.getLabel()}; + String[] dataArray = {propertyName, edge.getId(), edge.getLabel(), GlobalVariables.getUserName()}; client.sendTCP(dataArray); } else if (propertyName.equals(Constants.changeSketchTranslateX)) { Sketch sketch = (Sketch) evt.getSource(); - String[] dataArray = {propertyName, sketch.getId(), Double.toString(sketch.getTranslateX())}; + String[] dataArray = {propertyName, sketch.getId(), Double.toString(sketch.getTranslateX()), GlobalVariables.getUserName()}; client.sendTCP(dataArray); } else if (propertyName.equals(Constants.changeSketchTranslateY)) { Sketch sketch = (Sketch) evt.getSource(); - String[] dataArray = {propertyName, sketch.getId(), Double.toString(sketch.getTranslateY())}; + String[] dataArray = {propertyName, sketch.getId(), Double.toString(sketch.getTranslateY()), GlobalVariables.getUserName()}; client.sendTCP(dataArray); } } @@ -183,6 +192,7 @@ private void initKryo(Kryo kryo){ kryo.register(ArrayList.class); kryo.register(AbstractEdge.Direction.class); kryo.register(String[].class); + kryo.register(Object[].class); } public void closeClient(){ diff --git a/src/controller/ServerController.java b/src/controller/ServerController.java index 2b96d48..5b299f7 100644 --- a/src/controller/ServerController.java +++ b/src/controller/ServerController.java @@ -51,27 +51,31 @@ public ServerController(Graph pGraph, AbstractDiagramController pDiagramControll server.addListener(new Listener() { public void received (Connection connection, Object object) { - if (object instanceof Sketch) { - Platform.runLater(() -> diagramController.addSketch((Sketch)object, false, true)); - } - else if (object instanceof String) { - String request = (String)object; - if(request.equals(Constants.requestGraph)){ - connection.sendTCP(diagramController.getGraphModel()); + if ( object instanceof Object[]) { + Object[] dataArray = (Object[]) object; + if (dataArray[0] instanceof Sketch) { + Platform.runLater(() -> diagramController.addSketch((Sketch)dataArray[0], false, true)); } - } - else if (object instanceof AbstractNode) { - server.sendToAllExceptTCP(connection.getID(), object); - Platform.runLater(() -> diagramController.createNodeView((AbstractNode)object, true)); - } - else if (object instanceof AbstractEdge) { - server.sendToAllExceptTCP(connection.getID(), object); - Platform.runLater(() -> diagramController.addEdgeView((AbstractEdge)object, true)); - } - else if (object instanceof String[]){ - server.sendToAllExceptTCP(connection.getID(), object); - Platform.runLater(() -> diagramController.remoteCommand((String[])object)); - } + else if (dataArray[0] instanceof String) { + String request = (String) dataArray[0]; + if(request.equals(Constants.requestGraph)){ + Object[] sendDataArray = {diagramController.getGraphModel(), "server"}; + connection.sendTCP(sendDataArray); + } + else if (object instanceof String[]) { + server.sendToAllExceptTCP(connection.getID(), object); + Platform.runLater(() -> diagramController.remoteCommand((String[])object)); + } + } + else if (dataArray[0] instanceof AbstractNode) { + server.sendToAllExceptTCP(connection.getID(), dataArray[0]); + Platform.runLater(() -> diagramController.createNodeView((AbstractNode)dataArray[0], true)); + } + else if (dataArray[0] instanceof AbstractEdge) { + server.sendToAllExceptTCP(connection.getID(), dataArray[0]); + Platform.runLater(() -> diagramController.addEdgeView((AbstractEdge)dataArray[0], true)); + } + } } public void connected(Connection c){ @@ -94,79 +98,84 @@ public void disconnected(Connection c){ public void propertyChange(PropertyChangeEvent evt) { String propertyName = evt.getPropertyName(); if(propertyName.equals(Constants.sketchAdd)){ - String[] dataArray = {Constants.sketchAdd}; + String[] dataArray = {Constants.sketchAdd, "server"}; server.sendToAllTCP(dataArray); } else if (propertyName.equals(Constants.changeSketchPoint)){ Sketch sketch = (Sketch) evt.getSource(); Point2D point = (Point2D) evt.getNewValue(); String[] dataArray = {Constants.changeSketchPoint, sketch.getId(), - Double.toString(point.getX()), Double.toString(point.getY())}; + Double.toString(point.getX()), Double.toString(point.getY()), "server"}; server.sendToAllTCP(dataArray); } else if (propertyName.equals(Constants.changeSketchStart)) { Sketch sketch = (Sketch) evt.getSource(); Point2D point = (Point2D) evt.getNewValue(); String[] dataArray = {Constants.changeSketchStart, sketch.getId(), - Double.toString(point.getX()), Double.toString(point.getY()), sketch.getColor().toString()}; + Double.toString(point.getX()), Double.toString(point.getY()), sketch.getColor().toString(), "server"}; server.sendToAllTCP(dataArray); } else if (propertyName.equals(Constants.sketchRemove)){ - String[] dataArray = {Constants.sketchRemove, (String)evt.getNewValue()}; + String[] dataArray = {Constants.sketchRemove, (String)evt.getNewValue(), "server"}; server.sendToAllTCP(dataArray); } else if(propertyName.equals(Constants.NodeAdd)) { AbstractNode node = (AbstractNode) evt.getNewValue(); - server.sendToAllTCP(node); + Object[] dataArray = {node, "server"}; + server.sendToAllTCP(dataArray); } else if (propertyName.equals(Constants.NodeRemove)){ - String[] dataArray = {Constants.NodeRemove, (String)evt.getNewValue()}; + String[] dataArray = {Constants.NodeRemove, (String)evt.getNewValue(), "server"}; server.sendToAllTCP(dataArray); } else if (propertyName.equals(Constants.EdgeAdd)){ AbstractEdge edge = (AbstractEdge) evt.getNewValue(); - server.sendToAllTCP(edge); + Object[] dataArray = {edge, "server"}; + server.sendToAllTCP(dataArray); } else if(propertyName.equals(Constants.EdgeRemove)) { - String [] dataArray = {Constants.EdgeRemove, (String)evt.getNewValue()}; + String [] dataArray = {Constants.EdgeRemove, (String)evt.getNewValue(), "server"}; server.sendToAllTCP(dataArray); } else if (propertyName.equals(Constants.changeNodeTranslateX) || propertyName.equals(Constants.changeNodeTranslateY)) { //NodeX/Y not needed AbstractNode node = (AbstractNode) evt.getSource(); - String[] dataArray = {propertyName, node.getId(), Double.toString(node.getTranslateX()), Double.toString(node.getTranslateY())}; + String[] dataArray = {propertyName, node.getId(), Double.toString(node.getTranslateX()), + Double.toString(node.getTranslateY()), "server"}; server.sendToAllTCP(dataArray); } else if (propertyName.equals(Constants.changeNodeWidth) || propertyName.equals(Constants.changeNodeHeight)){ AbstractNode node = (AbstractNode) evt.getSource(); - String[] dataArray = {propertyName, node.getId(), Double.toString(node.getWidth()), Double.toString(node.getHeight())}; + String[] dataArray = {propertyName, node.getId(), Double.toString(node.getWidth()), + Double.toString(node.getHeight()), "server"}; server.sendToAllTCP(dataArray); } else if (propertyName.equals(Constants.changeNodeTitle)) { AbstractNode node = (AbstractNode) evt.getSource(); - String[] dataArray = {propertyName, node.getId(), node.getTitle()}; + String[] dataArray = {propertyName, node.getId(), node.getTitle(), "server"}; server.sendToAllTCP(dataArray); } else if (propertyName.equals(Constants.changeClassNodeAttributes) || propertyName.equals(Constants.changeClassNodeOperations)){ ClassNode node = (ClassNode) evt.getSource(); - String[] dataArray = {propertyName, node.getId(), node.getAttributes(), node.getOperations()}; + String[] dataArray = {propertyName, node.getId(), node.getAttributes(), node.getOperations(), "server"}; server.sendToAllTCP(dataArray); } else if(propertyName.equals(Constants.changeEdgeStartMultiplicity) || propertyName.equals(Constants.changeEdgeEndMultiplicity)){ AbstractEdge edge = (AbstractEdge) evt.getSource(); - String[] dataArray = {propertyName, edge.getId(), edge.getStartMultiplicity(), edge.getEndMultiplicity()}; + String[] dataArray = {propertyName, edge.getId(), edge.getStartMultiplicity(), + edge.getEndMultiplicity(), "server"}; server.sendToAllTCP(dataArray); } else if(propertyName.equals(Constants.changeLabel)){ AbstractEdge edge = (AbstractEdge) evt.getSource(); - String[] dataArray = {propertyName, edge.getId(), edge.getLabel()}; + String[] dataArray = {propertyName, edge.getId(), edge.getLabel(), "server"}; server.sendToAllTCP(dataArray); } else if (propertyName.equals(Constants.changeSketchTranslateX)) { Sketch sketch = (Sketch) evt.getSource(); - String[] dataArray = {propertyName, sketch.getId(), Double.toString(sketch.getTranslateX())}; + String[] dataArray = {propertyName, sketch.getId(), Double.toString(sketch.getTranslateX()), "server"}; server.sendToAllTCP(dataArray); } else if (propertyName.equals(Constants.changeSketchTranslateY)) { Sketch sketch = (Sketch) evt.getSource(); - String[] dataArray = {propertyName, sketch.getId(), Double.toString(sketch.getTranslateY())}; + String[] dataArray = {propertyName, sketch.getId(), Double.toString(sketch.getTranslateY()), "server"}; server.sendToAllTCP(dataArray); } } @@ -184,6 +193,7 @@ private void initKryo(Kryo kryo){ kryo.register(ArrayList.class); kryo.register(AbstractEdge.Direction.class); kryo.register(String[].class); + kryo.register(Object[].class); } public void closeServer(){ diff --git a/src/util/GlobalVariables.java b/src/util/GlobalVariables.java new file mode 100644 index 0000000..6c51e21 --- /dev/null +++ b/src/util/GlobalVariables.java @@ -0,0 +1,14 @@ +package util; + +public class GlobalVariables { + + private static String userName; + + public static String getUserName() { + return userName; + } + + public static void setUserName(String userName) { + GlobalVariables.userName = userName; + } +} diff --git a/src/util/NetworkUtils.java b/src/util/NetworkUtils.java index f056b2c..da22672 100644 --- a/src/util/NetworkUtils.java +++ b/src/util/NetworkUtils.java @@ -17,7 +17,7 @@ public class NetworkUtils { public static String[] queryServerPort() { // Create the custom dialog. - Dialog> dialog = new Dialog<>(); + Dialog dialog = new Dialog<>(); dialog.setTitle("Connect to server"); dialog.setHeaderText("Enter server IP and port number"); @@ -33,6 +33,8 @@ public static String[] queryServerPort() { serverIP.setText("127.0.0.1"); TextField port = new TextField(); port.setText("54555"); + TextField userName = new TextField(); + userName.setText(System.getProperty("user.name")); Platform.runLater(() -> serverIP.requestFocus()); @@ -40,23 +42,31 @@ public static String[] queryServerPort() { grid.add(serverIP, 1, 0); grid.add(new Label("Port number:"), 0, 1); grid.add(port, 1, 1); + grid.add(new Label("User name:"), 0, 2); + grid.add(userName, 1, 2); dialog.getDialogPane().setContent(grid); // Convert the result to a username-password-pair when the login button is clicked. dialog.setResultConverter(dialogButton -> { if (dialogButton == okButtonType) { - return new Pair<>(serverIP.getText(), port.getText()); + return new String[] { + serverIP.getText(), port.getText(), userName.getText() + }; } return null; }); - Optional> result = dialog.showAndWait(); - - String[] s = new String[2]; - if (result.isPresent() && validateIP(result.get().getKey()) && Integer.parseInt(result.get().getValue()) >= 1024 && Integer.parseInt(result.get().getValue()) <= 65535) { - s[0] = result.get().getKey(); - s[1] = result.get().getValue(); + Optional result = dialog.showAndWait(); + String[] s = new String[3]; + if (result.isPresent() + && validateIP(result.get()[0]) + && Integer.parseInt(result.get()[1]) >= 1024 + && Integer.parseInt(result.get()[1]) <= 65535 + && !(result.get()[2].isEmpty())) { + s[0] = result.get()[0]; + s[1] = result.get()[1]; + s[2] = result.get()[2]; } else { s = null; Alert alert = new Alert(Alert.AlertType.WARNING); diff --git a/src/view/nodes/ClassNodeView.java b/src/view/nodes/ClassNodeView.java index fb43836..8ecd760 100644 --- a/src/view/nodes/ClassNodeView.java +++ b/src/view/nodes/ClassNodeView.java @@ -1,7 +1,5 @@ package view.nodes; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Bounds; @@ -30,6 +28,7 @@ import model.nodes.IdentifiedTextField; import model.nodes.Operation; import util.Constants; +import util.GlobalVariables; import java.beans.PropertyChangeEvent; import java.util.UUID; @@ -134,7 +133,8 @@ private void createHandles(){ title.setOnKeyReleased(new EventHandler() { public void handle(KeyEvent ke) { - System.out.println("Title '" + title.getText() + "' updated. Broadcasting...\n"); + System.out.println(GlobalVariables.getUserName() + + ": Title '" + title.getText() + "' updated. Broadcasting...\n"); ((ClassNode)getRefNode()).setTitle(title.getText()); } }); @@ -276,10 +276,12 @@ private void createHandlesAttributesOperations(IdentifiedTextField textfield) { textfield.setOnKeyReleased(new EventHandler() { public void handle(KeyEvent ke) { if (textfield instanceof Attribute) { - System.out.println("'"+textfield+"' updated. Broadcasting...\n"); + System.out.println(GlobalVariables.getUserName() + + ": '"+textfield+"' updated. Broadcasting...\n"); ((ClassNode)getRefNode()).setAttributes(extractAttributesFromVBox()); } else if (textfield instanceof Operation) { - System.out.println("'"+textfield+"' updated. Broadcasting...\n"); + System.out.println(GlobalVariables.getUserName() + + ": '"+textfield+"' updated. Broadcasting...\n"); ((ClassNode)getRefNode()).setOperations(extractOperationsFromVBox()); } } @@ -296,13 +298,15 @@ public void handle(ActionEvent e) { index--; vbox.getChildren().remove(modifiedTextField); vbox.getChildren().add(index,modifiedTextField); - System.out.println("'"+modifiedTextField+"' Moved Up. Broadcasting...\n"); + System.out.println(GlobalVariables.getUserName() + + ": '"+modifiedTextField+"' Moved Up. Broadcasting...\n"); ((ClassNode)getRefNode()).setAttributes(extractAttributesFromVBox()); } else if (textfield instanceof Operation && index > (3+attributesSize())) { index--; vbox.getChildren().remove(modifiedTextField); vbox.getChildren().add(index,modifiedTextField); - System.out.println("'"+modifiedTextField+"' Moved Up. Broadcasting...\n"); + System.out.println(GlobalVariables.getUserName() + + ": '"+modifiedTextField+"' Moved Up. Broadcasting...\n"); ((ClassNode)getRefNode()).setOperations(extractOperationsFromVBox()); } } @@ -318,13 +322,15 @@ public void handle(ActionEvent e) { index++; vbox.getChildren().remove(modifiedTextField); vbox.getChildren().add(index,modifiedTextField); - System.out.println("'"+modifiedTextField+"' Moved Down. Broadcasting...\n"); + System.out.println(GlobalVariables.getUserName() + + ":'"+modifiedTextField+"' Moved Down. Broadcasting...\n"); ((ClassNode)getRefNode()).setAttributes(extractAttributesFromVBox()); } else if (textfield instanceof Operation && index < (2+attributesSize()+operationsSize())) { index++; vbox.getChildren().remove(modifiedTextField); vbox.getChildren().add(index,modifiedTextField); - System.out.println("'"+modifiedTextField+"' Moved Down. Broadcasting...\n"); + System.out.println(GlobalVariables.getUserName() + + ": '"+modifiedTextField+"' Moved Down. Broadcasting...\n"); ((ClassNode)getRefNode()).setOperations(extractOperationsFromVBox()); } } @@ -341,7 +347,8 @@ public void handle(ActionEvent e) { public void handle(ActionEvent e) { IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); vbox.getChildren().remove(modifiedTextField); - System.out.println("'"+modifiedTextField+"' deleted. Broadcasting...\n"); + System.out.println(GlobalVariables.getUserName() + + ": '"+modifiedTextField+"' deleted. Broadcasting...\n"); broadcastingAttributesWithOperations(); } }); @@ -416,7 +423,8 @@ public void propertyChange(PropertyChangeEvent evt) { String newValue = (String) evt.getNewValue(); // Update text if it was altered if (!title.getText().equals(newValue)) { - System.out.println("Received title '" + newValue + "'. Updating...\n"); + System.out.println(GlobalVariables.getUserName() + + ": Received title '" + newValue + "'. Updating...\n"); title.setText(newValue); } if (title.getText() == null || title.getText().equals("")) { @@ -432,7 +440,8 @@ public void propertyChange(PropertyChangeEvent evt) { if ( node instanceof Attribute ) { Attribute localTextField = (Attribute) node; if (!newValue.contains(localTextField.getXmiId())) { - System.out.println("Received '"+localTextField+"'. Deleting...\n"); + System.out.println(GlobalVariables.getUserName() + + ": Received '"+localTextField+"'. Deleting...\n"); vbox.getChildren().remove(localTextField); } } @@ -453,7 +462,8 @@ public void propertyChange(PropertyChangeEvent evt) { } } if (!found) { - System.out.println("Received '"+remoteTextField+"'. Adding...\n"); + System.out.println(GlobalVariables.getUserName() + + ": Received '"+remoteTextField+"'. Adding...\n"); createHandlesAttributesOperations(remoteTextField); vbox.getChildren().add(index,remoteTextField); } @@ -469,12 +479,14 @@ public void propertyChange(PropertyChangeEvent evt) { if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { // Update text if it was altered if (!localTextField.getText().equals(remoteTextField.getText())) { - System.out.println("Received '"+remoteTextField+"'. Updating text...\n"); + System.out.println(GlobalVariables.getUserName() + + ": Received '"+remoteTextField+"'. Updating text...\n"); localTextField.setText(remoteTextField.getText()); } // If moved upper or down if (vbox.getChildren().indexOf(localTextField) != index) { - System.out.println("Received '"+localTextField+"'. Updating index to " + index + "\n"); + System.out.println(GlobalVariables.getUserName() + + ": Received '"+localTextField+"'. Updating index to " + index + "\n"); vbox.getChildren().remove(localTextField); vbox.getChildren().add(index,localTextField); } @@ -497,7 +509,8 @@ public void propertyChange(PropertyChangeEvent evt) { if ( node instanceof Operation ) { Operation localTextField = (Operation) node; if (!newValue.contains(localTextField.getXmiId())) { - System.out.println("Received '"+localTextField+"'. Deleting...\n"); + System.out.println(GlobalVariables.getUserName() + + ": Received '"+localTextField+"'. Deleting...\n"); vbox.getChildren().remove(localTextField); } } @@ -518,7 +531,8 @@ public void propertyChange(PropertyChangeEvent evt) { } } if (!found) { - System.out.println("Received '"+remoteTextField+"'. Adding...\n"); + System.out.println(GlobalVariables.getUserName() + + ": Received '"+remoteTextField+"'. Adding...\n"); createHandlesAttributesOperations(remoteTextField); vbox.getChildren().add(index,remoteTextField); } @@ -534,12 +548,14 @@ public void propertyChange(PropertyChangeEvent evt) { if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { // Update text if it was altered if (!localTextField.getText().equals(remoteTextField.getText())) { - System.out.println("Received '"+remoteTextField+"'. Updating text...\n"); + System.out.println(GlobalVariables.getUserName() + + ": Received '"+remoteTextField+"'. Updating text...\n"); localTextField.setText(remoteTextField.getText()); } // If moved upper or down if (vbox.getChildren().indexOf(localTextField) != index) { - System.out.println("Received '"+localTextField+"'. Updating index to " + index+ "\n"); + System.out.println(GlobalVariables.getUserName() + + ": Received '"+localTextField+"'. Updating index to " + index+ "\n"); vbox.getChildren().remove(localTextField); vbox.getChildren().add(index,localTextField); } From 713e601691f18a8825c25b671988b4dd5faf0ee3 Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Fri, 10 Aug 2018 14:07:57 -0300 Subject: [PATCH 27/88] Imporoving log --- src/controller/AbstractDiagramController.java | 2 +- src/model/nodes/AbstractNode.java | 5 +- src/view/nodes/ClassNodeView.java | 52 +++++++------------ 3 files changed, 22 insertions(+), 37 deletions(-) diff --git a/src/controller/AbstractDiagramController.java b/src/controller/AbstractDiagramController.java index afea102..83bef4b 100644 --- a/src/controller/AbstractDiagramController.java +++ b/src/controller/AbstractDiagramController.java @@ -739,7 +739,7 @@ else if(dataArray[0].equals(Constants.changeNodeTranslateY) || dataArray[0].equa } else if (dataArray[0].equals(Constants.changeNodeTitle)){ for(AbstractNode node : graph.getAllNodes()){ if(dataArray[1].equals(node.getId())){ - node.remoteSetTitle(dataArray[2]); + node.remoteSetTitle(dataArray); break; } } diff --git a/src/model/nodes/AbstractNode.java b/src/model/nodes/AbstractNode.java index 4ed9cc7..634c457 100644 --- a/src/model/nodes/AbstractNode.java +++ b/src/model/nodes/AbstractNode.java @@ -2,6 +2,7 @@ import javafx.geometry.Rectangle2D; import util.Constants; +import util.GlobalVariables; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; @@ -139,8 +140,8 @@ public void remoteSetWidth(double width){ changes.firePropertyChange(Constants.changeNodeWidth, null, this.width); } - public void remoteSetTitle(String pTitle) { - this.aTitle = pTitle; + public void remoteSetTitle(String[] dataArray) { + aTitle = dataArray[2]; changes.firePropertyChange(Constants.changeNodeTitle, null, aTitle); } diff --git a/src/view/nodes/ClassNodeView.java b/src/view/nodes/ClassNodeView.java index 8ecd760..a5d0bc6 100644 --- a/src/view/nodes/ClassNodeView.java +++ b/src/view/nodes/ClassNodeView.java @@ -133,8 +133,6 @@ private void createHandles(){ title.setOnKeyReleased(new EventHandler() { public void handle(KeyEvent ke) { - System.out.println(GlobalVariables.getUserName() - + ": Title '" + title.getText() + "' updated. Broadcasting...\n"); ((ClassNode)getRefNode()).setTitle(title.getText()); } }); @@ -276,12 +274,8 @@ private void createHandlesAttributesOperations(IdentifiedTextField textfield) { textfield.setOnKeyReleased(new EventHandler() { public void handle(KeyEvent ke) { if (textfield instanceof Attribute) { - System.out.println(GlobalVariables.getUserName() + - ": '"+textfield+"' updated. Broadcasting...\n"); ((ClassNode)getRefNode()).setAttributes(extractAttributesFromVBox()); } else if (textfield instanceof Operation) { - System.out.println(GlobalVariables.getUserName() + - ": '"+textfield+"' updated. Broadcasting...\n"); ((ClassNode)getRefNode()).setOperations(extractOperationsFromVBox()); } } @@ -298,15 +292,11 @@ public void handle(ActionEvent e) { index--; vbox.getChildren().remove(modifiedTextField); vbox.getChildren().add(index,modifiedTextField); - System.out.println(GlobalVariables.getUserName() + - ": '"+modifiedTextField+"' Moved Up. Broadcasting...\n"); ((ClassNode)getRefNode()).setAttributes(extractAttributesFromVBox()); } else if (textfield instanceof Operation && index > (3+attributesSize())) { index--; vbox.getChildren().remove(modifiedTextField); vbox.getChildren().add(index,modifiedTextField); - System.out.println(GlobalVariables.getUserName() + - ": '"+modifiedTextField+"' Moved Up. Broadcasting...\n"); ((ClassNode)getRefNode()).setOperations(extractOperationsFromVBox()); } } @@ -322,15 +312,11 @@ public void handle(ActionEvent e) { index++; vbox.getChildren().remove(modifiedTextField); vbox.getChildren().add(index,modifiedTextField); - System.out.println(GlobalVariables.getUserName() + - ":'"+modifiedTextField+"' Moved Down. Broadcasting...\n"); ((ClassNode)getRefNode()).setAttributes(extractAttributesFromVBox()); } else if (textfield instanceof Operation && index < (2+attributesSize()+operationsSize())) { index++; vbox.getChildren().remove(modifiedTextField); vbox.getChildren().add(index,modifiedTextField); - System.out.println(GlobalVariables.getUserName() + - ": '"+modifiedTextField+"' Moved Down. Broadcasting...\n"); ((ClassNode)getRefNode()).setOperations(extractOperationsFromVBox()); } } @@ -347,8 +333,6 @@ public void handle(ActionEvent e) { public void handle(ActionEvent e) { IdentifiedTextField modifiedTextField = (IdentifiedTextField) ((MenuItem) e.getSource()).getUserData(); vbox.getChildren().remove(modifiedTextField); - System.out.println(GlobalVariables.getUserName() + - ": '"+modifiedTextField+"' deleted. Broadcasting...\n"); broadcastingAttributesWithOperations(); } }); @@ -423,8 +407,8 @@ public void propertyChange(PropertyChangeEvent evt) { String newValue = (String) evt.getNewValue(); // Update text if it was altered if (!title.getText().equals(newValue)) { - System.out.println(GlobalVariables.getUserName() + - ": Received title '" + newValue + "'. Updating...\n"); + System.out.println("ClassNodeView.propertyChange() " + GlobalVariables.getUserName() + "\n" + + "Received title '" + newValue + "'. Updating...\n"); title.setText(newValue); } if (title.getText() == null || title.getText().equals("")) { @@ -440,8 +424,8 @@ public void propertyChange(PropertyChangeEvent evt) { if ( node instanceof Attribute ) { Attribute localTextField = (Attribute) node; if (!newValue.contains(localTextField.getXmiId())) { - System.out.println(GlobalVariables.getUserName() + - ": Received '"+localTextField+"'. Deleting...\n"); + System.out.println("ClassNodeView.propertyChange() " + GlobalVariables.getUserName() + "\n" + + "Received '"+localTextField+"'. Deleting...\n"); vbox.getChildren().remove(localTextField); } } @@ -462,8 +446,8 @@ public void propertyChange(PropertyChangeEvent evt) { } } if (!found) { - System.out.println(GlobalVariables.getUserName() + - ": Received '"+remoteTextField+"'. Adding...\n"); + System.out.println("ClassNodeView.propertyChange() " + GlobalVariables.getUserName() + "\n" + + "Received '"+remoteTextField+"'. Adding...\n"); createHandlesAttributesOperations(remoteTextField); vbox.getChildren().add(index,remoteTextField); } @@ -479,14 +463,14 @@ public void propertyChange(PropertyChangeEvent evt) { if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { // Update text if it was altered if (!localTextField.getText().equals(remoteTextField.getText())) { - System.out.println(GlobalVariables.getUserName() + - ": Received '"+remoteTextField+"'. Updating text...\n"); + System.out.println("ClassNodeView.propertyChange() " + GlobalVariables.getUserName() + "\n" + + "Received '"+remoteTextField+"'. Updating text...\n"); localTextField.setText(remoteTextField.getText()); } // If moved upper or down if (vbox.getChildren().indexOf(localTextField) != index) { - System.out.println(GlobalVariables.getUserName() + - ": Received '"+localTextField+"'. Updating index to " + index + "\n"); + System.out.println("ClassNodeView.propertyChange() " + GlobalVariables.getUserName() + "\n" + + "Received '"+localTextField+"'. Updating index to " + index + "\n"); vbox.getChildren().remove(localTextField); vbox.getChildren().add(index,localTextField); } @@ -509,8 +493,8 @@ public void propertyChange(PropertyChangeEvent evt) { if ( node instanceof Operation ) { Operation localTextField = (Operation) node; if (!newValue.contains(localTextField.getXmiId())) { - System.out.println(GlobalVariables.getUserName() + - ": Received '"+localTextField+"'. Deleting...\n"); + System.out.println("ClassNodeView.propertyChange() " + GlobalVariables.getUserName() + "\n" + + "Received '"+localTextField+"'. Deleting...\n"); vbox.getChildren().remove(localTextField); } } @@ -531,8 +515,8 @@ public void propertyChange(PropertyChangeEvent evt) { } } if (!found) { - System.out.println(GlobalVariables.getUserName() + - ": Received '"+remoteTextField+"'. Adding...\n"); + System.out.println("ClassNodeView.propertyChange() " + GlobalVariables.getUserName() + "\n" + + "Received '"+remoteTextField+"'. Adding...\n"); createHandlesAttributesOperations(remoteTextField); vbox.getChildren().add(index,remoteTextField); } @@ -548,14 +532,14 @@ public void propertyChange(PropertyChangeEvent evt) { if (localTextField.getXmiId().equals(remoteTextField.getXmiId())) { // Update text if it was altered if (!localTextField.getText().equals(remoteTextField.getText())) { - System.out.println(GlobalVariables.getUserName() + - ": Received '"+remoteTextField+"'. Updating text...\n"); + System.out.println("ClassNodeView.propertyChange() " + GlobalVariables.getUserName() + "\n" + + "Received '"+remoteTextField+"'. Updating text...\n"); localTextField.setText(remoteTextField.getText()); } // If moved upper or down if (vbox.getChildren().indexOf(localTextField) != index) { - System.out.println(GlobalVariables.getUserName() + - ": Received '"+localTextField+"'. Updating index to " + index+ "\n"); + System.out.println("ClassNodeView.propertyChange() " + GlobalVariables.getUserName() + "\n" + + "Received '"+localTextField+"'. Updating index to " + index+ "\n"); vbox.getChildren().remove(localTextField); vbox.getChildren().add(index,localTextField); } From 5d256fe4b7ade6f55206486e1a3f0e0d3b6645fc Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Tue, 14 Aug 2018 01:21:13 -0300 Subject: [PATCH 28/88] Fix of log framwork --- .gitignore | 3 +- conf/ladder.conf | 18 +++ logging/ladderLoggingConfig.lcf | 230 ++++++++++++++++++++++++++++++++ 3 files changed, 250 insertions(+), 1 deletion(-) create mode 100644 conf/ladder.conf create mode 100644 logging/ladderLoggingConfig.lcf diff --git a/.gitignore b/.gitignore index 2ac8426..7ffee92 100755 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ hs_err_pid* /JetUML-0.9/* /JetUML-0.9/.idea/workspace.xml *.iml -logging +*.log +.fuse* META-INF diff --git a/conf/ladder.conf b/conf/ladder.conf new file mode 100644 index 0000000..8fa552d --- /dev/null +++ b/conf/ladder.conf @@ -0,0 +1,18 @@ +# Where should the Ladder system look for the configuration file to configure +# the logging system? +loggingConfigFile = logging/ladderLoggingConfig.lcf + +# What folder are any domain descriptions stored in? +domainDescriptions = ../LadderDomains/domainDescriptions/domains/ + +# What folder are the shape descriptions stored in? +shapeDescriptions = ../LadderDomains/domainDescriptions/shapes/ + +# What folder is testData stored in? +testData = ../LadderData/testData517 + +# This configuration property is the default domain to load +defaultLoadDomain = COA.xml + +# What folder are the various models stored in? +modelDir = model diff --git a/logging/ladderLoggingConfig.lcf b/logging/ladderLoggingConfig.lcf new file mode 100644 index 0000000..d54c4d2 --- /dev/null +++ b/logging/ladderLoggingConfig.lcf @@ -0,0 +1,230 @@ +# The root category uses the appender called ROOT_APP. You can comment/uncomment +# a given line to change the default level of debugging for the entire +# application. For development, you probably want DEBUG. For Deployment, you +# probably don't want anything but ERROR by default. This can always be changed +# by editing this file if you need more/less, and you don't have to modify +# the logging code within the application itself. + + +###################### Root Logger +## For development +#log4j.rootCategory=DEBUG, ROOT_APP +## For deployment +log4j.rootCategory=ERROR, ROOT_APP + + +###################### ROOT_APP appender +# APP is set to be a RollingFileAppender which outputs to the file +# "ladder.log". If the file gets above a specified size limit, create a new +# log file, up to a certain number of log files. +log4j.appender.ROOT_APP=org.apache.log4j.RollingFileAppender +log4j.appender.ROOT_APP.File=logging/ladder.log +# 5MB log size limit +log4j.appender.ROOT_APP.MaxFileSize=5000KB +# just one other file, then start to recycle +log4j.appender.ROOT_APP.MaxBackupIndex=1 +log4j.appender.ROOT_APP.layout=org.apache.log4j.PatternLayout +# Format to use when logging entries in the ROOT_APP log. +# See org.apache.log4j.PatternLayout for field details +# Date, priority, thread, logger location (SLOW), message, endline +log4j.appender.ROOT_APP.layout.ConversionPattern=%-35d{dd MMM yyyy, HH:mm:ss:SSS} %-5p [%t] %l -- %m%n + + +###################### Class Loggers +#Examples adding loggers for specific classes/packages +# +# Adding a logger to a class +# log4j.logger.=DEBUG, +# +# Multiple loggers +# log4j.logger.=DEBUG, , , ... +# +# Currently the available logs are: +# HIGH_LEVEL - For high level recognition +# LOW_LEVEL - For low level recognition +# SEGS - For segmentations +# CON - Console logging + +# These go to both Console (short version) and to the Test file appender +log4j.logger.test.functional.ladder.recognition.constraint.domains.ShapeDefinitionAccuracyFactory=DEBUG, CONSHORT, TEST +log4j.logger.test.functional.ladder.recognition.constraint.domains.DomainDescriptionAccuracyTest=DEBUG, CONSHORT, TEST + + +log4j.logger.org.ladder.recognition.constraint.CALVIN=ERROR, HIGH_LEVEL, CON +log4j.logger.org.ladder.recognition.constraint.builders.ShapeBuilderTracy=ERROR, HIGH_LEVEL, CON +log4j.logger.org.ladder.recognition.constraint.grouping.PostMidLevelGrouper=ERROR, HIGH_LEVEL, CON +log4j.logger.org.ladder.recognition.paleo=ERROR, LOW_LEVEL, PALEO +log4j.logger.org.ladder.recognition.profiling.RunTimeLogger=DEBUG, RUNTIME +log4j.logger.org.ladder.segmentation=ERROR, LOW_LEVEL, SEGS + +log4j.logger.org.ladder.recognition.constraint.domains.compiler.DomainDefinitionCompiler=WARN,CON +#log4j.logger.org.ladder.recognition.handwriting.HandwritingRecognizer=ERROR, CON +#log4j.logger.test.functional.ladder.recognition.constraint.domains=INFO, CON +#log4j.logger.test.functional.ladder.recognition.shapes.SingleShapeAccuracy=INFO, CON +log4j.logger.org.ladder.recognition.RecognitionManager=ERROR, CON +#log4j.logger.edu.tamu.deepGreen.recognition.area.AreaRecognizer=DEBUG, CON + +## I want to see all the recognition package stuff on the console. +#log4j.logger.org.ladder.recognition=DEBUG, CON +## turn constraints off +#log4j.logger.org.ladder.recognition.constraint.confidence=OFF +#log4j.logger.org.ladder.recognition.constraint.ConstraintFactory=OFF +## turn paleo off, except for actual PaleoRecognizer +#log4j.logger.org.ladder.recognition.paleo=OFF +#log4j.logger.org.ladder.recognition.paleo.PaleoSketchRecognizer=DEBUG, CON +## COA TestPanel DEBUG and to the console +#log4j.logger.edu.tamu.deepGreen.test.COATestPanel=DEBUG, CON +#log4j.logger.edu.tamu.deepGreen.SIDCLookup=DEBUG, CON +#log4j.logger.test.ladder.recognition.constraint.domains.SingleExampleShapeAccuracyTest=INFO, CON + +###################### LADDER appenders +# To create an appender, copy one of the ones below and replace the name and file name +# For example, copy HIGH_LEVEL, replace all instances of HIGH_LEVEL with the new name +# and change highLevel.log to the name for your log file + + +###################### CON appender +# CON is set to be a ConsoleAppender which outputs to the file +# "ladder.log". If the file gets above a specified size limit, create a new +# log file, up to a certain number of log files. +log4j.appender.CON=org.apache.log4j.ConsoleAppender +log4j.appender.CON.layout=org.apache.log4j.PatternLayout +# Format to use when logging entries in the CON log. +# See org.apache.log4j.PatternLayout for field details +# priority, thread, logger location (SLOW) -- message, endline +log4j.appender.CON.layout.ConversionPattern=%-5p [%t] %F.%M:%L -- %m%n + + + +###################### CONSHORT appender +# CON is set to be a ConsoleAppender which outputs to the file +# "ladder.log". If the file gets above a specified size limit, create a new +# log file, up to a certain number of log files. +log4j.appender.CONSHORT=org.apache.log4j.ConsoleAppender +log4j.appender.CONSHORT.layout=org.apache.log4j.PatternLayout +# Format to use when logging entries in the CON log. +# See org.apache.log4j.PatternLayout for field details +# priority, thread, logger location (SLOW) -- message, endline +log4j.appender.CONSHORT.layout.ConversionPattern=%m%n + + +###################### HIGH_LEVEL appender +# HIGH_LEVEL is set to be a RollingFileAppender which outputs to the file +# "highLevel.log". If the file gets above a specified size limit, create a new +# log file, up to a certain number of log files. +log4j.appender.HIGH_LEVEL=org.apache.log4j.RollingFileAppender +log4j.appender.HIGH_LEVEL.File=logging/highLevel.log +# 5MB log size limit +log4j.appender.HIGH_LEVEL.MaxFileSize=5000KB +# just one other file, then start to recycle +log4j.appender.HIGH_LEVEL.MaxBackupIndex=1 +log4j.appender.HIGH_LEVEL.layout=org.apache.log4j.PatternLayout +# Format to use when logging entries in the HIGH_LEVEL log. +# See org.apache.log4j.PatternLayout for field details +# Date, priority, thread, logger location (SLOW), message, endline +log4j.appender.HIGH_LEVEL.layout.ConversionPattern=%-35d{dd MMM yyyy, HH:mm:ss:SSS} %-5p [%t] %l -- %m%n%n + +###################### LOW_LEVEL appender +# LOW_LEVEL is set to be a RollingFileAppender which outputs to the file +# "lowLevel.log". If the file gets above a specified size limit, create a new +# log file, up to a certain number of log files. +log4j.appender.LOW_LEVEL=org.apache.log4j.RollingFileAppender +log4j.appender.LOW_LEVEL.File=logging/lowLevel.log +# 5MB log size limit +log4j.appender.LOW_LEVEL.MaxFileSize=5000KB +# just one other file, then start to recycle +log4j.appender.LOW_LEVEL.MaxBackupIndex=1 +log4j.appender.LOW_LEVEL.layout=org.apache.log4j.PatternLayout +# Format to use when logging entries in the LOW_LEVEL log. +# See org.apache.log4j.PatternLayout for field details +# Date, priority, thread, logger location (SLOW), message, endline +log4j.appender.LOW_LEVEL.layout.ConversionPattern=%-35d{dd MMM yyyy, HH:mm:ss:SSS} %-5p [%t] %l -- %m%n%n + + +###################### PALEO appender +# PALEO is set to be a RollingFileAppender which outputs to the file +# "paleo.log". If the file gets above a specified size limit, create a new +# log file, up to a certain number of log files. +log4j.appender.PALEO=org.apache.log4j.RollingFileAppender +log4j.appender.PALEO.File=logging/paleo.log +# 5MB log size limit +log4j.appender.PALEO.MaxFileSize=5000KB +# just one other file, then start to recycle +log4j.appender.PALEO.MaxBackupIndex=1 +log4j.appender.PALEO.layout=org.apache.log4j.PatternLayout +# Format to use when logging entries in the PALEO log. +# See org.apache.log4j.PatternLayout for field details +# Date, priority, thread, logger location (SLOW), message, endline +log4j.appender.PALEO.layout.ConversionPattern=%-35d{dd MMM yyyy, HH:mm:ss:SSS} %-5p [%t] %l -- %m%n%n + + +###################### SEGS appender +# SEGS is set to be a RollingFileAppender which outputs to the file +# "segs.log". If the file gets above a specified size limit, create a new +# log file, up to a certain number of log files. +log4j.appender.SEGS=org.apache.log4j.RollingFileAppender +log4j.appender.SEGS.File=logging/segmentation.log +# 5MB log size limit +log4j.appender.SEGS.MaxFileSize=5000KB +# just one other file, then start to recycle +log4j.appender.SEGS.MaxBackupIndex=1 +log4j.appender.SEGS.layout=org.apache.log4j.PatternLayout +# Format to use when logging entries in the SEGS log. +# See org.apache.log4j.PatternLayout for field details +# Date, priority, thread, logger location (SLOW), message, endline +log4j.appender.SEGS.layout.ConversionPattern=%-35d{dd MMM yyyy, HH:mm:ss:SSS} %-5p [%t] %l -- %m%n%n + + +###################### CONSTR appender +# CONSTR is set to be a RollingFileAppender which outputs to the file +# "constraint.log". If the file gets above a specified size limit, create a new +# log file, up to a certain number of log files. +log4j.appender.CONSTR=org.apache.log4j.RollingFileAppender +log4j.appender.CONSTR.File=logging/constraint.log +# 5MB log size limit +log4j.appender.CONSTR.MaxFileSize=5000KB +# just one other file, then start to recycle +log4j.appender.CONSTR.MaxBackupIndex=1 +log4j.appender.CONSTR.layout=org.apache.log4j.PatternLayout +# Format to use when logging entries in the SEGS log. +# See org.apache.log4j.PatternLayout for field details +# Date, priority, thread, logger location (SLOW), message, endline +log4j.appender.CONSTR.layout.ConversionPattern=%-35d{dd MMM yyyy, HH:mm:ss:SSS} %-5p [%t] %l -- %m%n%n + +###################### RUNTIME appender +# RUNTIME is set to be a RollingFileAppender which outputs to the file +# "runtime.log". If the file gets above a specified size limit, create a new +# log file, up to a certain number of log files. +log4j.appender.RUNTIME=org.apache.log4j.RollingFileAppender +log4j.appender.RUNTIME.File=logging/runtime.log +# 5MB log size limit +log4j.appender.RUNTIME.MaxFileSize=5000KB +# just one other file, then start to recycle +log4j.appender.RUNTIME.MaxBackupIndex=1 +log4j.appender.RUNTIME.layout=org.apache.log4j.PatternLayout +# Format to use when logging entries in the SEGS log. +# See org.apache.log4j.PatternLayout for field details +# Date, priority, thread, logger location (SLOW), message, endline +log4j.appender.RUNTIME.layout.ConversionPattern=%-5p [%t]: %m%n + +###################### TEST appender +# TEST is set to be a FileAppender which outputs to the file +# "test.log". The logger does NOT append, but overwrites with a new file each +# time +log4j.appender.TEST=org.apache.log4j.FileAppender +# Do not append, start a new file each time +log4j.appender.TEST.append=false +log4j.appender.TEST.File=logging/test.log +log4j.appender.TEST.layout=org.apache.log4j.PatternLayout +# Format to use when logging entries in the TEST log. +# See org.apache.log4j.PatternLayout for field details +# Date, priority, thread, logger location (SLOW), message, endline +log4j.appender.TEST.layout.ConversionPattern=%m%n + + + +# We can create different appenders and files for different parts of LADDER. +# These loggers will log their information in their local appenders, PLUS all +# that information will also be present in the root logger. But, these +# sub-loggers can have different priorities, etc. +# For example, here's a logger for objects in org.ladder.core From c3f11a6e51549f9fcd14044b7ad3ea235271bc32 Mon Sep 17 00:00:00 2001 From: McLyndon Xavier Date: Tue, 14 Aug 2018 23:03:38 -0300 Subject: [PATCH 29/88] Added log for debug --- src/controller/AbstractDiagramController.java | 65 +++++++++++++++++-- src/controller/ClientController.java | 16 ++++- src/controller/ServerController.java | 10 +++ src/model/Graph.java | 22 +++++++ src/model/nodes/AbstractNode.java | 41 +++++++++++- src/model/nodes/ClassNode.java | 33 ++++++++-- src/view/nodes/ClassNodeView.java | 45 ++++++------- 7 files changed, 196 insertions(+), 36 deletions(-) diff --git a/src/controller/AbstractDiagramController.java b/src/controller/AbstractDiagramController.java index 83bef4b..09be2c0 100644 --- a/src/controller/AbstractDiagramController.java +++ b/src/controller/AbstractDiagramController.java @@ -1,6 +1,7 @@ package controller; import javafx.application.Platform; + import javafx.embed.swing.SwingFXUtils; import javafx.fxml.FXML; import javafx.geometry.Bounds; @@ -41,16 +42,19 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import org.slf4j.LoggerFactory; + import java.io.IOException; import java.io.File; -import java.util.logging.Level; -import java.util.logging.Logger; + +import org.slf4j.Logger; /** * Controls all user inputs and delegates work to other controllers. */ public abstract class AbstractDiagramController { + private static Logger logger = LoggerFactory.getLogger(AbstractDiagramController.class); protected Graph graph; protected Stage aStage; @@ -118,6 +122,7 @@ protected enum ToolEnum { public void initialize() { + logger.debug("initialize()"); initDrawPaneActions(); initContextMenu(); initZoomSlider(); @@ -141,6 +146,7 @@ public void initialize() { } private void initDrawPaneActions() { + logger.debug("initDrawPaneActions()"); //Makes sure the pane doesn't scroll when using a touch screen. drawPane.setOnScroll(event -> event.consume()); @@ -159,6 +165,7 @@ private void initDrawPaneActions() { * Deletes all selected nodes, edges and sketches. */ void deleteSelected() { + logger.debug("deleteSelected()"); CompoundCommand command = new CompoundCommand(); for (AbstractNodeView nodeView : selectedNodes) { deleteNode(nodeView, command, false, false); @@ -190,6 +197,7 @@ void deleteSelected() { * @param remote, If true this command was received from a remote server. */ public void deleteNode(AbstractNodeView nodeView, CompoundCommand pCommand, boolean undo, boolean remote) { + logger.debug("deleteNode()"); CompoundCommand command = null; if (pCommand == null && !undo) { command = new CompoundCommand(); @@ -221,6 +229,7 @@ public void deleteNode(AbstractNodeView nodeView, CompoundCommand pCommand, bool * @param undo If true this is an undo and no command should be created */ public void deleteEdgeView(AbstractEdgeView edgeView, CompoundCommand pCommand, boolean undo, boolean remote) { + logger.debug("deleteEdgeView()"); CompoundCommand command = null; if (pCommand == null && !undo) { //If this is not part of a compoundcommand command = new CompoundCommand(); @@ -244,6 +253,7 @@ public void deleteEdgeView(AbstractEdgeView edgeView, CompoundCommand pCommand, } public void addSketch(Sketch sketch, boolean isImport, boolean remote){ + logger.debug("addSketch()"); initSketchActions(sketch); drawPane.getChildren().add(sketch.getPath()); if(!isImport){ @@ -253,6 +263,7 @@ public void addSketch(Sketch sketch, boolean isImport, boolean remote){ } public void deleteSketch(Sketch sketch, CompoundCommand pCommand, boolean remote) { + logger.debug("deleteSketch()"); CompoundCommand command; if (pCommand == null) { command = new CompoundCommand(); @@ -273,6 +284,7 @@ public void deleteSketch(Sketch sketch, CompoundCommand pCommand, boolean remote * @param remote, true if change comes from a remote server */ public void deleteNodeEdges(AbstractNode node, CompoundCommand command, boolean undo, boolean remote) { + logger.debug("deleteNodeEdges()"); AbstractEdge edge; ArrayList edgeViewsToBeDeleted = new ArrayList<>(); for (AbstractEdgeView edgeView : allEdgeViews) { @@ -296,6 +308,7 @@ public void deleteNodeEdges(AbstractNode node, CompoundCommand command, boolean * @param sketch */ private void initSketchActions(Sketch sketch) { + logger.debug("initSketchActions()"); sketch.getPath().setOnMousePressed(event -> { if (mouseCreationActivated) { handleOnSketchPressedEvents(sketch); @@ -354,6 +367,7 @@ private void initSketchActions(Sketch sketch) { } private void handleOnSketchPressedEvents(Sketch sketch) { + logger.debug("handleOnSketchPressedEvents()"); if (sketch.isSelected()) { selectedSketches.remove(sketch); sketch.setSelected(false); @@ -374,6 +388,7 @@ public ArrayList getSelectedEdges() { //---------------------- MENU HANDLERS --------------------------------- public void handleMenuActionUML() { + logger.debug("handleMenuActionUML()"); List