/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2013 Ausenco Engineering Canada Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
package com.jaamsim.input;

import com.jaamsim.units.Unit;
import com.sandwell.JavaSimulation.Input;
import com.sandwell.JavaSimulation.InputErrorException;
import com.sandwell.JavaSimulation.ObjectType;
import com.sandwell.JavaSimulation.StringVector;

public class UnitTypeInput extends Input<Class<? extends Unit>>{
	public UnitTypeInput(String key, String cat) {
		super(key, cat, Unit.class);
	}

	@Override
	public void parse(StringVector input)
	throws InputErrorException {
		Input.assertCount(input, 1);
		if (value != Unit.class)
			throw new InputErrorException("Value has already been set to %s", value.getName());

		ObjectType t = Input.parseEntity(input.get(0), ObjectType.class);
		value = Input.checkCast(t.getJavaClass(), Unit.class);
		this.updateEditingFlags();
	}
}

@@ -634,30 +634,132 @@
 ort 
-com.jaamsim.units.Unit
+java.util.ArrayList;%0Aimport java.util.Collections;%0A%0Aimport com.jaamsim.units.Unit;%0Aimport com.sandwell.JavaSimulation.Entity
 ;%0Aim
@@ -901,16 +901,63 @@
 ctType;%0A
+import com.sandwell.JavaSimulation.Simulation;%0A
 import c
@@ -1043,31 +1043,76 @@
 put%3C
-Class%3C? extends Unit%3E%3E%7B
+ObjectType%3E %7B%0A%09private Class%3C? extends Unit%3E unitType = Unit.class;%0A
 %0A%09pu
@@ -1174,26 +1174,20 @@
 y, cat, 
-Unit.class
+null
 );%0A%09%7D%0A%0A%09
@@ -1311,26 +1311,20 @@
 alue != 
-Unit.class
+null
 )%0A%09%09%09thr
@@ -1395,16 +1395,21 @@
 alue.get
+Input
 Name());
@@ -1480,20 +1480,41 @@
 ass);%0A%09%09
-valu
+Class%3C? extends Unit%3E typ
 e = Inpu
@@ -1560,35 +1560,535 @@
 s);%0A
-%09%09this.updateEditingFlags()
+%0A%09%09value = t;%0A%09%09unitType = type;%0A%0A%09%09this.updateEditingFlags();%0A%09%7D%0A%0A%09@Override%0A%09public ArrayList%3CString%3E getValidOptions() %7B%0A%09%09ArrayList%3CString%3E list = new ArrayList%3CString%3E();%0A%09%09for (ObjectType each: Simulation.getClonesOf(ObjectType.class)) %7B%0A%09%09%09Class%3C? extends Entity%3E klass = each.getJavaClass();%0A%09%09%09if (klass == null)%0A%09%09%09%09continue;%0A%0A%09%09%09if (Unit.class.isAssignableFrom(klass))%0A%09%09%09%09list.add(each.getInputName());%0A%09%09%7D%0A%09%09Collections.sort(list);%0A%09%09return list;%0A%09%7D%0A%0A%09public Class%3C? extends Unit%3E getUnitType() %7B%0A%09%09return unitType
 ;%0A%09%7D

make UnitTypeInput return a valid list to enable drop-down boxes in the editbox