瀏覽代碼

Finish sorting of HolegElements

Toni Schneider 7 年之前
父節點
當前提交
698ea685e1
共有 2 個文件被更改,包括 57 次插入12 次删除
  1. 52 7
      src/ui/controller/UpdateController.java
  2. 5 5
      src/ui/view/GUI.java

+ 52 - 7
src/ui/controller/UpdateController.java

@@ -14,7 +14,12 @@ import java.util.LinkedList;
 
 import ElementComparator.ElemCompOnEleName;
 import ElementComparator.ElemCompOnEnergy;
+import ElementComparator.ElemCompOnFlexible;
 import ElementComparator.ElemCompOnId;
+import ElementComparator.ElemCompOnIsActivated;
+import ElementComparator.ElemCompOnIsFlexible;
+import ElementComparator.ElemCompOnObj;
+import ElementComparator.ElemCompOnQuantity;
 import ElementComparator.ElementComparator;
 
 /**
@@ -27,10 +32,12 @@ public class UpdateController {
 
 	Model model;
 	Control controller;
+	private String sortBy;
 
 	public UpdateController(Model model, Control control) {
 		this.model = model;
 		this.controller = control;
+		sortBy="Nr.";
 	}
 
 	/**
@@ -63,17 +70,14 @@ public class UpdateController {
 	 */
 	public void fillElementTable(ArrayList<AbstractCpsObject> objects, PropertyTable table) {
 		LinkedList<HolonElement> elemList = new LinkedList<HolonElement>();
-		ElementComparator compEnergy = new ElemCompOnEnergy();
-		//ElementComparator compId = new ElemCompOnId();
-		ElementComparator compEleName = new ElemCompOnEleName();
+		
 		if (objects.size() > 1) {
 			for (AbstractCpsObject o : objects) {
 				if (o instanceof HolonObject) {
 					for (HolonElement he : ((HolonObject) o).getElements()) {
 						he.setObjName(o.getName() + ", " + o.getId());
 						elemList.add(he);
-						elemList.sort(compEleName);
-						elemList.sort(compEnergy);
+						elemList=sortElemList(elemList);
 					}
 				}
 			}
@@ -88,9 +92,9 @@ public class UpdateController {
 			if (o instanceof HolonObject) {
 				for (HolonElement he : ((HolonObject) o).getElements()) {
 					elemList.add(he);
-					elemList.sort(compEleName);
-					elemList.sort(compEnergy);
+					elemList=sortElemList(elemList);
 				}
+				
 				for (HolonElement e1 : elemList) {
 					Object[] temp2 = { e1.getId(), e1.getEleName(), e1.getEnergyPerElement(),
 							e1.getFlexibleEnergyAvailablePerElement(), e1.getAmount(), e1.isActive(), e1.isFlexible() };
@@ -99,6 +103,39 @@ public class UpdateController {
 			}
 		}
 	}
+	
+	/**
+	 * @param elemList - HolonElement-List (unsorted)
+	 * @return sorted HolonElement-List! 
+	 */
+	public LinkedList<HolonElement> sortElemList(LinkedList<HolonElement> elemList) {
+		switch(sortBy) {
+		case "Object": 
+			elemList.sort(new ElemCompOnObj());
+			break;
+		case "Device": 
+			elemList.sort(new ElemCompOnEleName());
+			break;
+		case "Energy": elemList.sort(new ElemCompOnEnergy());
+			break;
+		case "Flexible Energy Available": 
+			elemList.sort(new ElemCompOnFlexible());
+			break;
+		case "Quantity": 
+			elemList.sort(new ElemCompOnQuantity());
+			break;
+		case "Activated": 
+			elemList.sort(new ElemCompOnIsActivated());
+			break;
+		case "Flexible": 
+			elemList.sort(new ElemCompOnIsFlexible());
+			break;
+		default: 
+			elemList.sort(new ElemCompOnId());
+			break;
+		}
+		return elemList;
+	};
 
 	/**
 	 * Update the HolonElement Table, that means erase all rows and add the new
@@ -411,4 +448,12 @@ public class UpdateController {
 			}
 		}
 	}
+
+	public String getSortBy() {
+		return sortBy;
+	}
+
+	public void setSortBy(String sortBy) {
+		this.sortBy = sortBy;
+	}
 }

+ 5 - 5
src/ui/view/GUI.java

@@ -1017,11 +1017,11 @@ public class GUI implements CategoryListener {
 						//clicked column
 						int col = model.getTableHolonElement().columnAtPoint(
 								e.getPoint());
-						//name of the column
-						String name = model.getTableHolonElement()
-								.getColumnName(col);
-						System.out.println("Column index selected " + col + " "
-								+ name);
+						//insert name of the column into UpdateController
+						updCon.setSortBy(model.getTableHolonElement()
+								.getColumnName(col));
+						//refresh HolonElementTable
+						updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
 					}
 				});