/******************************************************************* Copyright (c) 2001-2007 Apprisant Technologies Inc. All rights reserved. Apprisant Technologies permits non-exclusive royalty free use, copying and modification of this demo program source code for the purposes of evaluating the Apprisant Toolkit or building applications that use it. This software and documentation is provided "AS IS". APPRISANT TECHNOLOGIES DISCLAIMS ANY REPRESENTATIONS AND WARRANTIES, INCLUDING BUT NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY AND FITNESS OF THIS PRODUCT FOR ANY PARTICULAR PURPOSE. APPRISANT TECHNOLOGIES SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY ANY PARTY, INCLUDING LOST PROFITS, ARISING FROM THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ITS DERIVATIONS. ********************************************************************/ package schedule; import java.io.*; import java.util.*; import apprisant.diagram.*; import apprisant.diagram.data.*; import apprisant.diagram.env.AGLog; import schedule.Booking.Day; // enum class /* Data model class for the Schedule demo. Each room booking is represented by a Booking instance. Some data objects are stored in a separate pool for use with the Add and Remove buttons. */ public class ScheduleData extends SimpleDataModel { transient ArrayList pool = new ArrayList(); // Variables for the Change button transient boolean makeLonger = true; transient Booking econ427M; transient Booking econ427W; transient Booking mgmt303; transient Booking cpsc503; transient Booking geol255T; transient Booking geol255R; public ScheduleData() { super("ScheduleData"); initBookings(); } /* Creates all the data objects, adding most to the data model, the rest to the pool. Saves references to some Bookings for use with the Change button. */ public void initBookings() { super.clear(); pool.clear(); int key = 1; ArrayList d = new ArrayList(); d.add(new Booking (key, "CPSC 201", "Smith", Day.MON, 9, 60)); key++; d.add(new Booking (key, "CPSC 201", "Smith", Day.WED, 9, 60)); key++; d.add(new Booking (key, "CPSC 201", "Smith", Day.FRI, 9, 60)); key++; d.add(new Booking (key, "CPSC 304", "Fargo", Day.MON, 14, 60)); key++; d.add(new Booking (key, "CPSC 304", "Fargo", Day.WED, 14, 60)); key++; d.add(new Booking (key, "CPSC 304", "Fargo", Day.FRI, 14, 60)); key++; d.add(new Booking (key, "CPSC 454", "Brown", Day.TUES, 10.5f, 90)); key++; d.add(new Booking (key, "CPSC 454", "Brown", Day.THUR, 10.5f, 90)); key++; d.add(new Booking (key, "CPSC 501", "Alexander", Day.TUES, 13, 120)); key++; d.add(new Booking (key, "MGMT 203", "Blakely", Day.MON, 15, 60)); key++; d.add(new Booking (key, "MGMT 203", "Blakely", Day.WED, 15, 60)); key++; d.add(new Booking (key, "MGMT 203", "Blakely", Day.FRI, 15, 60)); key++; d.add(new Booking (key, "MGMT 395", "Sanchez", Day.MON, 8, 60)); key++; d.add(new Booking (key, "MGMT 395", "Sanchez", Day.WED, 8, 60)); key++; d.add(new Booking (key, "MGMT 395", "Sanchez", Day.FRI, 8, 60)); key++; d.add(new Booking (key, "ECON 205", "Edwards", Day.MON, 10, 60)); key++; d.add(new Booking (key, "ECON 205", "Edwards", Day.WED, 10, 60)); key++; d.add(new Booking (key, "ECON 205", "Edwards", Day.FRI, 10, 60)); key++; d.add(new Booking (key, "ECON 503", "Moore", Day.MON, 11, 90)); key++; d.add(new Booking (key, "ECON 503", "Moore", Day.WED, 11, 90)); key++; d.add(new Booking (key, "MGMT 204", "White", Day.MON, 13, 60)); key++; d.add(new Booking (key, "MGMT 204", "White", Day.WED, 13, 60)); key++; d.add(new Booking (key, "MGMT 204", "White", Day.FRI, 13, 60)); key++; d.add(new Booking (key, "CPSC 451", "Smith", Day.MON, 16, 60)); key++; d.add(new Booking (key, "CPSC 451", "Smith", Day.WED, 16, 60)); key++; d.add(new Booking (key, "CPSC 451", "Smith", Day.FRI, 16, 60)); key++; econ427M = new Booking (key, "ECON 427", "Farrell", Day.MON, 17, 90); pool.add(econ427M); key++; econ427W = new Booking (key, "ECON 427", "Farrell", Day.WED, 17, 90); pool.add(econ427W); key++; pool.add(new Booking (key, "PSYC 451", "Phipps", Day.FRI, 11, 60)); key++; pool.add(new Booking (key, "MGMT 303", "Adams", Day.TUES, 15, 90)); key++; mgmt303 = new Booking (key, "MGMT 303", "Adams", Day.THUR, 15, 90); pool.add(mgmt303); key++; pool.add(new Booking (key, "CPSC 501", "Hampton", Day.TUES, 17, 90)); key++; pool.add(new Booking (key, "CPSC 501", "Hampton", Day.THUR, 17, 90)); key++; cpsc503 = new Booking (key, "CPSC 503", "Wylie", Day.THUR, 13, 60); pool.add(cpsc503); key++; geol255T = new Booking (key, "GEOL 255", "Rockwell", Day.TUES, 9, 60); pool.add(geol255T); key++; geol255R = new Booking (key, "GEOL 255", "Rockwell", Day.THUR, 9, 60); pool.add(geol255R); key++; try { super.add(d); } catch (DataKeyException ae) { AGLog.log("ScheduleData", "initBookings", AGLog.ERROR, ae); } } /* Methods for the Add and Remove buttons. */ public void addBooking() { if (pool.size() > 0) { try { super.add(pool.remove(0)); } catch (DataKeyException ae) { AGLog.log("ScheduleData", "addBooking", AGLog.ERROR, ae); } } } public void removeBookings (Set keys) { for (Object key : keys) { pool.add((Booking) super.getDataObject(key)); } super.remove(keys); } public void removeSelectedBookings() { Set keys = diagram.getSelectionModel().getSelection(); removeBookings(keys); } /* Method for the Change button. Applies predefined changes to the data. */ public void changeBookings() { ArrayList keys = new ArrayList(); if (makeLonger) { // GEOL 255 geol255T.setStartTime(8.5f); geol255T.setDuration(90); keys.add(geol255T.getKey()); geol255R.setStartTime(8.5f); geol255R.setDuration(90); keys.add(geol255R.getKey()); // ECON 427 econ427M.setDuration(120); keys.add(econ427M.getKey()); econ427W.setDuration(120); keys.add(econ427W.getKey()); // CPSC 503 cpsc503.setProfName("Miller"); cpsc503.setDuration(90); keys.add(cpsc503.getKey()); // MGMT 303 mgmt303.setDay(Day.FRI); mgmt303.setStartTime(17); mgmt303.setDuration(90); keys.add(mgmt303.getKey()); makeLonger = false; } else { // GEOL 255 geol255T.setStartTime(9); geol255T.setDuration(60); keys.add(geol255T.getKey()); geol255R.setStartTime(9); geol255R.setDuration(60); keys.add(geol255R.getKey()); // ECON 427 econ427M.setDuration(90); keys.add(econ427M.getKey()); econ427W.setDuration(90); keys.add(econ427W.getKey()); // CPSC 503: 35 cpsc503.setProfName("Wylie"); cpsc503.setDuration(60); keys.add(cpsc503.getKey()); // MGMT 303 mgmt303.setDay(Day.THUR); mgmt303.setStartTime(15); mgmt303.setDuration(90); keys.add(mgmt303.getKey()); makeLonger = true; } super.update(keys); } /* Serialization support for IDEs that need it. */ private void readObject (ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); pool = new ArrayList(); makeLonger = true; initBookings(); } }