Browse Source

Merge branch 'Ohne_Drag_and_Drop' of https://git.tk.informatik.tu-darmstadt.de/carlos.garcia/praktikum-holons.git into Ohne_Drag_and_Drop

Kevin Trometer 8 years ago
parent
commit
aa476ee37c
1 changed files with 10 additions and 7 deletions
  1. 10 7
      src/ui/view/GUI.java

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

@@ -276,7 +276,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(),
@@ -287,7 +288,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());
 				}
@@ -296,11 +297,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;
+					}
 				}
 			}
 		});