private void setComboBoxModels() { ArrayList<User> users = main.getPersons(); userComboModel = new UserComboBoxModel(users); personsCombo.setModel(userComboModel); ArrayList<Group> groups = main.getGroups(); groupComboModel = new GroupComboBoxModel(groups); groupCombo.setModel(groupComboModel); }
private void addListModelsNull() { personListModel = new DefaultListModel(); groupListModel = new DefaultListModel(); roomListModel = new DefaultListModel(); personsList.setModel(personListModel); groupList.setModel(groupListModel); roomList.setModel(roomListModel); ArrayList<Room> rooms = main.getRooms(); // fyll inn romlisten med rom for (int i = 0; i < rooms.size(); i++) { roomListModel.addElement(rooms.get(i)); } }
private void addListModelsNotNull() { personListModel = new DefaultListModel(); groupListModel = new DefaultListModel(); roomListModel = new DefaultListModel(); personsList.setModel(personListModel); groupList.setModel(groupListModel); roomList.setModel(roomListModel); // fyll inn personlisten med participants for (int i = 0; i < model.getParticipantLength(); i++) { personListModel.addElement(model.getParticipant(i).getUser()); } ArrayList<Room> rooms = main.getRooms(); // fyll inn romlisten med rom for (int i = 0; i < rooms.size(); i++) { roomListModel.addElement(rooms.get(i)); } roomList.setSelectedValue(model.getRoom(), true); }
private void saveAppointment() { String title = titleField.getText(); String descr = descriptionField.getText(); // construct starttime int syear = startTime.getDate().getYear(); int smonth = startTime.getDate().getMonth(); int sddate = startTime.getDate().getDate(); int sh = (Integer) startHourSpinner.getValue(); int sm = (Integer) startMinuteSpinner.getValue(); Date sDate = new Date(syear, smonth, sddate, sh, sm); // set startTime Calendar start = new GregorianCalendar(); start.setTime(sDate); // construct endTime int eyear = endTime.getDate().getYear(); int emonth = endTime.getDate().getMonth(); int eddate = endTime.getDate().getDate(); int eh = (Integer) endHourSpinner.getValue(); int em = (Integer) endMinuteSpinner.getValue(); Date eDate = new Date(eyear, emonth, eddate, eh, em); // set endTime Calendar finish = new GregorianCalendar(); finish.setTime(eDate); User owner = main.getUser(); Room r = (Room) roomList.getSelectedValue(); Appointment saveApp; if (isNull) { saveApp = new Appointment(0, title, start, finish, owner); } else { saveApp = new Appointment(model.getAppointmentId(), title, start, finish, owner); } // legg til participants ArrayList<Participant> deletablePart = new ArrayList<Participant>(); Map<String, User> userMap = new HashMap<String, User>(); userMap.put(owner.getUsername(), owner); for (int i = 0; i < personListModel.getSize(); i++) { userMap.put(((User) personListModel.get(i)).getUsername(), ((User) personListModel.get(i))); } // fra gruppe for (int i = 0; i < groupListModel.getSize(); i++) { ArrayList<Member> members = ((Group) groupListModel.get(i)).getMembers(); for (int j = 0; j < members.size(); j++) { userMap.put(members.get(j).getUser().getUserName(), members.get(j).getUser()); } } ArrayList<User> allPart = new ArrayList<User>(userMap.values()); for (int i = 0; i < allPart.size(); i++) { deletablePart.add(new Participant(saveApp, allPart.get(i))); } saveApp.setRoom(r); saveApp.setDescription(descr); if (isNull) { main.getServer().insertAppointment(saveApp); } else { main.getServer().updateAppointment(saveApp, model); } // delete participants for (int i = 0; i < deletablePart.size(); i++) { deletablePart.get(i).remove(); } saveApp.remove(); }