private void setSpinnerModelsNotNull() {
    startHourSpinner.setModel(new SpinnerNumberModel(model.getStartHour(), 00, 23, 1));
    startMinuteSpinner.setModel(new SpinnerNumberModel(model.getStartMinute(), 00, 59, 1));

    endHourSpinner.setModel(new SpinnerNumberModel(model.getFinishedHour(), 00, 23, 1));
    endMinuteSpinner.setModel(new SpinnerNumberModel(model.getFinishedMinute(), 00, 59, 1));
  }
 private void updateNotNullGUI() {
   if (!isNull) {
     titleField.setText(model.getTitle());
     descriptionField.setText(model.getDescription());
     startTime.setDate(model.getStartTime().getTime());
     endTime.setDate(model.getFinishTime().getTime());
     setSpinnerModelsNotNull();
     setComboBoxModels();
     setButtonListeners();
     addListModelsNotNull();
   }
 }
  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);
  }
示例#4
0
  private Event makeEvent(Properties p, boolean fetchAlarm) {
    Event event = null;
    String id = p.getProperty("eventID");
    String start = p.getProperty("startDateTime");
    String end = p.getProperty("endDateTime");
    String location = p.getProperty("location");
    String description = p.getProperty("description");
    String isMeeting = p.getProperty("isMeeting");

    if (isMeeting.equals(BIT_FALSE)) {
      event = new Appointment();
    } else if (isMeeting.equals(BIT_TRUE)) {
      event = new Meeting();
    }
    event.setId(Integer.parseInt(id));
    event.setStartDateTime(start);
    event.setEndDateTime(end);
    event.setLocation(location);
    event.setDescription(description);
    if (fetchAlarm) {
      event.setAlarm(queryAlarm(currentUser, Integer.parseInt(id)));
    }
    event.setRoom(queryReservedRoom(Integer.parseInt(id)));
    if (event instanceof Appointment) {
      ((Appointment) event).setOwner(queryOwner(Integer.parseInt(id)));
    } else if (event instanceof Meeting) {
      ((Meeting) event).setLeader(queryOwner(Integer.parseInt(id)));
      ArrayList<User> invited = queryParticipants(Integer.parseInt(id), PARTICIPANT_STATUS_INVITED);
      ArrayList<User> accepted =
          queryParticipants(Integer.parseInt(id), PARTICIPANT_STATUS_ACCEPTED);
      ArrayList<User> declined =
          queryParticipants(Integer.parseInt(id), PARTICIPANT_STATUS_DECLINED);
      ((Meeting) event).setUsersInvited(invited);
      ((Meeting) event).setUsersAccepted(accepted);
      ((Meeting) event).setUsersDeclined(declined);
    }
    return event;
  }
  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();
  }