Ver Fonte

Fix some bugs im Add/Delete HolonElement

Edgardo Palza há 8 anos atrás
pai
commit
a1bb10560b
1 ficheiros alterados com 10 adições e 7 exclusões
  1. 10 7
      src/ui/view/GUI.java

+ 10 - 7
src/ui/view/GUI.java

@@ -281,7 +281,8 @@ public class GUI implements CategoryListener {
 		toolBarHolonEl.add(btnAddHolEL);
 		btnAddHolEL.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent arg0) {
-				if (tempCps != null && tempCps.getClass() == HolonObject.class) {
+				System.out.println(tempCps.getName() + " with ID: " + tempCps.getID());
+				if (tempCps != null && tempCps.getClass() == HolonObject.class && tempCps.getID() != 0) {
 					addElementPopUp = new AddElementPopUp();
 					addElementPopUp.setVisible(true);
 					controller.addElementCanvasObject(tempCps.getName(), addElementPopUp.getElement().getEleName(),
@@ -292,7 +293,7 @@ public class GUI implements CategoryListener {
 		toolBarHolonEl.add(btnDelHolEL);
 		btnDelHolEL.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent arg0) {
-				if (tempElement != null && tempCps.getClass() == HolonObject.class) {
+				if (tempElement != null && tempCps.getClass() == HolonObject.class && tempCps.getID() != 0) {
 					System.out.println(tempCps.getID());
 					controller.deleteElementCanvas(tempCps.getID(), tempElement.getEleName());
 				}
@@ -301,11 +302,13 @@ public class GUI implements CategoryListener {
 
 		tableHolonElement.addMouseListener(new MouseAdapter() {
 			public void mousePressed(MouseEvent e) {
-				int rowSelected = (int) Math.floor(e.getY() / 16);
-				if (tableHolonElement.getRowCount() > rowSelected) {
-					tempElement = ((HolonObject) tempCps).getElements().get(rowSelected);
-				} else {
-					tempElement = null;
+				if (tempCps != null) {
+					int rowSelected = (int) Math.floor(e.getY() / 16);
+					if (tableHolonElement.getRowCount() > rowSelected) {
+						tempElement = ((HolonObject) tempCps).getElements().get(rowSelected);
+					} else {
+						tempElement = null;
+					}
 				}
 			}
 		});