Exemplo n.º 1
0
  @Override
  public void actionPerformed(ActionEvent e) {

    if (e.getSource() instanceof WebComboBox) {

      if (((WebComboBox) e.getSource()).getActionCommand().equals("crewSelectedChanged")) {
        if (cmbCrew.getSelectedItem() instanceof Crew) {

          autoSave();

          currentCrew = (Crew) cmbCrew.getSelectedItem();

          if (currentCrew != null) {

            // calendar = null;
            // calendar = new ExWebCalendar(currentDate, currentCrew.getSignOnDate());

            calendar.refresh(currentCrew.getSignOnDate());

            errorReportEntry = new ErrorReportEntry();
            errorReportEntry.setEntryDate(getDate(currentDate));
            errorReportEntry.setCrew(currentCrew);
          }

          getSchedule(currentDate);
        }
      }

    } else {
      WebButton btnSource = (WebButton) e.getSource();

      if (btnSource.getClientProperty("command").equals("saveAndNext")) {

        if (currentCrew == null) {
          NotificationManager.showPopup(getOwner(), cmbCrew, new String[] {"Please select crew"});
          return;
        }

        // saveRestingHour();
        // calendar.moveToNext();
        // Calendar calNext = Calendar.getInstance();
        // calNext.setTime(currentDate);
        // calNext.add(Calendar.DAY_OF_MONTH, 1);

        // calendar.setDate(calNext.getTime());

      } else if (btnSource.getClientProperty("command").equals("new")) {

      } else if (btnSource.getClientProperty("command").equals("save")) {

        if (currentCrew == null) {
          NotificationManager.showPopup(getOwner(), cmbCrew, new String[] {"Please select crew"});
          return;
        }

        saveRestingHour();
      }
    }
  }
Exemplo n.º 2
0
  @SuppressWarnings({"serial", "unchecked"})
  private Component getForm() {

    calendar.addDateSelectionListener(this);

    cmbCrew = new WebComboBox();
    cmbCrew.setActionCommand("crewSelectedChanged");
    cmbCrew.addActionListener(this);
    chkOnPort = new WebCheckBox("on Port?");
    chkOnPort.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            getSchedule(currentDate);
          }
        });

    chkAutoSave = new WebCheckBox("Auto save on change date");

    chkAutoSave.setSelected(true);
    chkAutoSave.setEnabled(false);

    refreshData();
    bindData();

    GroupPanel leftPanel =
        new GroupPanel(
            false,
            new GroupPanel(10, cmbCrew, chkOnPort),
            new GroupPanel(10, false, calendar, chkAutoSave));

    timeSheet = new TimeSheet(20);
    timeSheet.setChangeListener(this);

    txtComments = new WebTextArea();
    txtComments.setLineWrap(true);
    txtComments.setWrapStyleWord(true);

    AbstractDocument pDoc = (AbstractDocument) txtComments.getDocument();
    pDoc.setDocumentFilter(new DocumentSizeFilter(45));

    WebScrollPane areaScroll = new WebScrollPane(txtComments);
    areaScroll.setPreferredSize(new Dimension(300, 50));

    WebTextArea txtNonConformities = new WebTextArea();
    txtNonConformities.setLineWrap(true);
    txtNonConformities.setWrapStyleWord(true);

    WebScrollPane ncScroll = new WebScrollPane(txtNonConformities);
    ncScroll.setPreferredSize(new Dimension(200, 150));

    cmbCommentList = new WebComboBox();
    cmbCommentList.addItem("Select quick comment ...");

    final QuickCommentDAO qCommentDao = new QuickCommentDAO();
    final List<QuickComment> qCommentsList = qCommentDao.getAll();

    for (QuickComment qComment : qCommentsList) {
      cmbCommentList.addItem(qComment);
    }

    cmbCommentList.addItem("...or add new quick comment");

    cmbCommentList.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            if (cmbCommentList.getSelectedIndex() == cmbCommentList.getItemCount() - 1) {
              Object value =
                  WebOptionPane.showInputDialog(
                      getOwner(),
                      "Add new quick comment:",
                      "Quick Comment",
                      JOptionPane.QUESTION_MESSAGE,
                      null,
                      null,
                      "");

              if (value != null && value.toString().trim().length() > 0) {
                txtComments.setText(value.toString());

                if (qCommentsList.size() > 0) {
                  boolean bFound = false;

                  for (int i = 0; i < qCommentsList.size(); i++) {
                    QuickComment q = qCommentsList.get(i);

                    if (q.getQuickComment().equalsIgnoreCase(value.toString()) == true) {
                      bFound = true;
                      break;
                    }
                  }

                  if (!bFound) {
                    qCommentDao.addQuickComment(value.toString());

                    QuickComment newQuickComment = new QuickComment();
                    newQuickComment.setQuickComment(value.toString());

                    qCommentsList.add(newQuickComment);

                    cmbCommentList.insertItemAt(newQuickComment, cmbCommentList.getItemCount() - 1);
                  }

                } else {
                  QuickComment newQuickComment = new QuickComment();
                  newQuickComment.setQuickComment(value.toString());

                  qCommentsList.add(newQuickComment);

                  cmbCommentList.insertItemAt(newQuickComment, cmbCommentList.getItemCount() - 2);
                }
              }
            } else if (cmbCommentList.getSelectedIndex() > 0) {
              txtComments.setText(cmbCommentList.getSelectedItem().toString());
            }
          }
        });

    lblNonConformities = new WebLabel();

    GroupPanel panelNonConformity =
        new GroupPanel(false, new WebLabel("Non-Conformities:"), lblNonConformities);

    GroupPanel rightPanel =
        new GroupPanel(
            false,
            new WebLabel("Resting Hours") {
              {
                setDrawShade(true);
              }
            },
            timeSheet.getView(),
            new GroupPanel(
                30,
                getGrid(),
                new GroupPanel(false, new WebLabel("Comments: "), areaScroll, cmbCommentList)),
            panelNonConformity);

    return new GroupPanel(GroupingType.fillLast, 20, leftPanel, rightPanel).setMargin(10);
  }