Exemple #1
0
  protected void executeView(final Container f) {
    reportId = "";
    f.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    Image helpIcon = HILMain.getInstance().res.getImage("GeneralReportData_sel.png");

    final Label title = new Label(getName());
    title.getStyle().setFont(HILMain.getInstance().theme.getFont("titleFont"));
    title.setIcon(helpIcon);
    title.setAlignment(Label.LEFT);
    title.setHeight(14);
    title.setWidth(240);
    title.getStyle().setBgColor(0x7799bb);
    title.getStyle().setFgColor(0xFFFFFF);
    title.getStyle().setPadding(5, 5, 15, 0);
    title.getStyle().setBgTransparency(250);

    setTitle(title, f);
    f.setScrollable(true);
    FocusListener textFocus =
        new FocusListener() {
          public void focusGained(Component arg0) {
            arg0.getStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont"));
            arg0.getStyle().setBorder(Border.createEmpty());
          }

          public void focusLost(Component arg0) {}
        };

    TextArea shortHelpLabel = new TextArea(2, 10);
    shortHelpLabel.getStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont"));
    shortHelpLabel.getStyle().setBorder(Border.createEmpty(), true);
    shortHelpLabel.getStyle().setBgTransparency(0);
    shortHelpLabel.getStyle().setFgColor(0x000000);
    shortHelpLabel.setFocus(false);
    shortHelpLabel.setFocusable(false);
    shortHelpLabel.setText(
        (String) HILMain.getInstance().locale.get("short_help_general_report_data"));
    f.addComponent(shortHelpLabel);

    date = new Date();
    final Button dateLabel = new Button();
    dateLabel.getStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont"));
    dateLabel.getStyle().setBorder(Border.createEmpty());
    dateLabel.getStyle().setBgColor(0xCECECE);
    dateLabel.getStyle().setFgColor(0x81746B);
    dateLabel.setTextPosition(Label.LEFT);
    dateLabel.setText("");
    dateLabel.getSelectedStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont"));
    dateLabel.getSelectedStyle().setBorder(Border.createEmpty());
    dateLabel.getSelectedStyle().setBgColor(0xCECECE);
    dateLabel.getSelectedStyle().setFgColor(0x81746B);
    dateLabel.getSelectedStyle().setBgTransparency(100);
    dateLabel.getPressedStyle().setBorder(Border.createEmpty());
    dateLabel.getPressedStyle().setBgColor(0xCECECE);
    dateLabel.getPressedStyle().setFgColor(0x81746B);
    dateLabel.getPressedStyle().setBgTransparency(100);
    dateLabel.setText(DateUtil.getMonthYear(date, "/"));
    f.addComponent(createPair((String) HILMain.getInstance().locale.get("time"), dateLabel, 54));

    Container buttonContainer = new Container(new BoxLayout(BoxLayout.X_AXIS));
    buttonContainer.setWidth(Display.getInstance().getDisplayWidth());
    Button submit = new Button();
    submit.setText((String) HILMain.getInstance().locale.get("get_data"));
    submit.getStyle().setBgTransparency(255);
    submit.getStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont"));
    submit.getStyle().setBorder(Border.createRoundBorder(0, 0, 0xcadaf1));
    submit.getStyle().setBgColor(0xFAAC58, true);
    submit.getStyle().setAlignment(Label.CENTER);
    submit.getStyle().setFgColor(0xFFFFFF);
    submit.getSelectedStyle().setBgTransparency(255);
    submit.getSelectedStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont"));
    submit.getSelectedStyle().setBorder(Border.createRoundBorder(0, 0, 0xcadaf1));
    submit.getSelectedStyle().setBgColor(0xFAAC58);
    submit.getSelectedStyle().setAlignment(Label.CENTER);
    submit.getSelectedStyle().setFgColor(0x000000);
    submit.getPressedStyle().setBgTransparency(255);
    submit.getPressedStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont"));
    submit.getPressedStyle().setBorder(Border.createRoundBorder(0, 0, 0xcadaf1));
    submit.getPressedStyle().setBgColor(0xFAAC58);
    submit.getPressedStyle().setAlignment(Label.CENTER);
    submit.getPressedStyle().setFgColor(0x000000);

    final Button buttonEdit = new Button();
    buttonEdit.setText((String) HILMain.getInstance().locale.get("edit"));
    buttonEdit.getStyle().setBgTransparency(255);
    buttonEdit.getStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont"));
    buttonEdit.getStyle().setBorder(Border.createRoundBorder(0, 0, 0xcadaf1));
    buttonEdit.getStyle().setBgColor(0xFAAC58, true);
    buttonEdit.getStyle().setAlignment(Label.CENTER);
    buttonEdit.getStyle().setFgColor(0xFFFFFF);
    buttonEdit.getDisabledStyle().setBgTransparency(255);
    buttonEdit.getDisabledStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont"));
    buttonEdit.getDisabledStyle().setBorder(Border.createRoundBorder(0, 0, 0xcadaf1));
    buttonEdit.getDisabledStyle().setBgColor(0xBDBDBD);
    buttonEdit.getDisabledStyle().setAlignment(Label.CENTER);
    buttonEdit.getDisabledStyle().setFgColor(0xFFFFFF);
    buttonEdit.getSelectedStyle().setBgTransparency(255);
    buttonEdit.getSelectedStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont"));
    buttonEdit.getSelectedStyle().setBorder(Border.createRoundBorder(0, 0, 0xcadaf1));
    buttonEdit.getSelectedStyle().setBgColor(0xFAAC58);
    buttonEdit.getSelectedStyle().setAlignment(Label.CENTER);
    buttonEdit.getSelectedStyle().setFgColor(0x000000);
    buttonEdit.getPressedStyle().setBgTransparency(255);
    buttonEdit.getPressedStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont"));
    buttonEdit.getPressedStyle().setBorder(Border.createRoundBorder(0, 0, 0xcadaf1));
    buttonEdit.getPressedStyle().setBgColor(0xFAAC58);
    buttonEdit.getPressedStyle().setAlignment(Label.CENTER);
    buttonEdit.getPressedStyle().setFgColor(0x000000);
    buttonEdit.setEnabled(false);
    buttonContainer.addComponent(submit);
    buttonContainer.addComponent(buttonEdit);
    f.addComponent(buttonContainer);

    Label normalLabel = new Label((String) HILMain.getInstance().locale.get("normal_reaction"));
    normalLabel.getStyle().setBgTransparency(250);
    normalLabel.setWidth(240);
    normalLabel.getStyle().setBgColor(0xBFD6FF);
    f.addComponent(normalLabel);

    final TextField normalReaction = new TextField(10);
    normalReaction.getStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont"));
    normalReaction.setText("");
    normalReaction.getStyle().setBorder(Border.createEmpty(), true);
    normalReaction.addFocusListener(textFocus);
    normalReaction.getStyle().setBgColor(0xCECECE);
    normalReaction.getStyle().setBgTransparency(150);
    normalReaction.getStyle().setFgColor(0x81746B);
    normalReaction.getSelectedStyle().setBgColor(0xCECECE);
    normalReaction.getSelectedStyle().setBgTransparency(100);
    normalReaction.getSelectedStyle().setFgColor(0x81746B);
    normalReaction.setConstraint(TextField.NUMERIC);
    normalReaction.setInputModeOrder(new String[] {"123"});
    normalReaction.setEditable(false);
    f.addComponent(normalReaction);

    Label seriousLabel = new Label((String) HILMain.getInstance().locale.get("serious_reaction"));
    seriousLabel.getStyle().setBgTransparency(250);
    seriousLabel.setWidth(240);
    seriousLabel.getStyle().setBgColor(0xBFD6FF);
    f.addComponent(seriousLabel);

    final TextField seriousReaction = new TextField(10);
    seriousReaction.getStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont"));
    seriousReaction.setText("");
    seriousReaction.getStyle().setBorder(Border.createEmpty(), true);
    seriousReaction.addFocusListener(textFocus);
    seriousReaction.getStyle().setBgColor(0xCECECE);
    seriousReaction.getStyle().setBgTransparency(150);
    seriousReaction.getStyle().setFgColor(0x81746B);
    seriousReaction.getSelectedStyle().setBgColor(0xCECECE);
    seriousReaction.getSelectedStyle().setBgTransparency(100);
    seriousReaction.getSelectedStyle().setFgColor(0x81746B);
    seriousReaction.setConstraint(TextField.NUMERIC);
    seriousReaction.setInputModeOrder(new String[] {"123"});
    seriousReaction.setEditable(false);
    f.addComponent(seriousReaction);

    Label tetanusLabel = new Label((String) HILMain.getInstance().locale.get("tetanus_protection"));
    tetanusLabel.getStyle().setBgTransparency(250);
    tetanusLabel.setWidth(240);
    tetanusLabel.getStyle().setBgColor(0xBFD6FF);
    f.addComponent(tetanusLabel);

    final TextField tetanus = new TextField(10);
    tetanus.getStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont"));
    tetanus.setText("");
    tetanus.getStyle().setBorder(Border.createEmpty(), true);
    tetanus.addFocusListener(textFocus);
    tetanus.getStyle().setBgColor(0xCECECE);
    tetanus.getStyle().setBgTransparency(150);
    tetanus.getStyle().setFgColor(0x81746B);
    tetanus.getSelectedStyle().setBgColor(0xCECECE);
    tetanus.getSelectedStyle().setBgTransparency(100);
    tetanus.getSelectedStyle().setFgColor(0x81746B);
    tetanus.setConstraint(TextField.NUMERIC);
    tetanus.setInputModeOrder(new String[] {"123"});
    tetanus.setEditable(false);
    f.addComponent(tetanus);

    final Button buttonSave = new Button();
    buttonSave.setText((String) HILMain.getInstance().locale.get("save"));

    buttonSave.getStyle().setBgTransparency(255);
    buttonSave.getStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont"));
    buttonSave.getStyle().setBorder(Border.createRoundBorder(0, 0, 0xcadaf1));
    buttonSave.getStyle().setBgColor(0xFAAC58, true);
    buttonSave.getStyle().setAlignment(Label.CENTER);
    buttonSave.getStyle().setFgColor(0xFFFFFF);
    buttonSave.setWidth(100);
    buttonSave.getDisabledStyle().setBgTransparency(255);
    buttonSave.getDisabledStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont"));
    buttonSave.getDisabledStyle().setBorder(Border.createRoundBorder(0, 0, 0xcadaf1));
    buttonSave.getDisabledStyle().setBgColor(0xBDBDBD);
    buttonSave.getDisabledStyle().setAlignment(Label.CENTER);
    buttonSave.getDisabledStyle().setFgColor(0xFFFFFF);
    buttonSave.getSelectedStyle().setBgTransparency(255);
    buttonSave.getSelectedStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont"));
    buttonSave.getSelectedStyle().setBorder(Border.createRoundBorder(0, 0, 0xcadaf1));
    buttonSave.getSelectedStyle().setBgColor(0xFAAC58);
    buttonSave.getSelectedStyle().setAlignment(Label.CENTER);
    buttonSave.getSelectedStyle().setFgColor(0x000000);
    buttonSave.getPressedStyle().setBgTransparency(255);
    buttonSave.getPressedStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont"));
    buttonSave.getPressedStyle().setBorder(Border.createRoundBorder(0, 0, 0xcadaf1));
    buttonSave.getPressedStyle().setBgColor(0xFAAC58);
    buttonSave.getPressedStyle().setAlignment(Label.CENTER);
    buttonSave.getPressedStyle().setFgColor(0x000000);
    buttonSave.setEnabled(false);
    f.addComponent(buttonSave);

    buttonEdit.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            normalReaction.setEditable(true);
            seriousReaction.setEditable(true);
            tetanus.setEditable(true);
            buttonSave.setEnabled(true);
          }
        });

    buttonSave.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ev) {
            if (normalReaction.getText().trim().length() == 0
                && seriousReaction.getText().trim().length() == 0
                && tetanus.getText().trim().length() == 0) return;

            ConnectionRequest req =
                new ConnectionRequest() {
                  protected void readResponse(InputStream input) throws IOException {
                    JSONParser p = new JSONParser();

                    Hashtable result = p.parse(new InputStreamReader(input, "UTF-8"));
                    result = (Hashtable) result.get("ResultSet");

                    int total = ((Double) result.get("totalResultsReturned")).intValue();

                    if (total == 0) {
                      Dialog.show(
                          (String) HILMain.getInstance().locale.get("notice"),
                          (String) HILMain.getInstance().locale.get("upload_unsuccessful"),
                          (String) HILMain.getInstance().locale.get("ok"),
                          null);
                    } else {
                      Vector entries = (Vector) result.get("Result");
                      for (int iter = 0; iter < entries.size(); iter++) {
                        result = (Hashtable) entries.elementAt(iter);
                        reportId = (String) result.get("reportId");
                        normalReaction.setText((String) result.get("normal"));
                        seriousReaction.setText((String) result.get("serious"));
                        tetanus.setText((String) result.get("tetanus"));
                        normalReaction.setEditable(false);
                        seriousReaction.setEditable(false);
                        tetanus.setEditable(false);
                        buttonSave.setEnabled(false);
                      }
                      if (Dialog.show(
                          (String) HILMain.getInstance().locale.get("notice"),
                          (String) HILMain.getInstance().locale.get("upload_successful"),
                          (String) HILMain.getInstance().locale.get("ok"),
                          null)) {
                        buttonSave.setEnabled(false);
                        HILMain.getInstance().showMainMenu();
                      }
                    }
                  }
                };
            req.setPost(true);
            req.setUrl(HILMain.getInstance().SERVER_ADDRESS + "saveGeneralReportData");

            req.setContentType("text/plain");

            req.addArgumentNoEncoding(
                "sessionAuth", HILMain.getInstance().currentUser.getSessionAuth());
            req.addArgumentNoEncoding(
                "username", HILMain.getInstance().currentUser.getAccountName());
            req.addArgumentNoEncoding("password", HILMain.getInstance().currentUser.getPassword());
            req.addArgumentNoEncoding("reportId", reportId);
            req.addArgumentNoEncoding("cId", HILMain.getInstance().currentUser.getcId());
            req.addArgumentNoEncoding("timeData", DateUtil.getMonthYear(date, "/"));
            req.addArgumentNoEncoding("normal", normalReaction.getText().trim());
            req.addArgumentNoEncoding("serious", seriousReaction.getText().trim());
            req.addArgumentNoEncoding("tatanus", tetanus.getText().trim());

            NetworkManager.getInstance().addToQueue(req);
          }
        });

    dateLabel.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            TextArea noteLabel = new TextArea(2, 10);
            noteLabel.getStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont"));
            noteLabel.getStyle().setBorder(Border.createEmpty(), true);
            noteLabel.getStyle().setBgTransparency(0);
            noteLabel.getStyle().setFgColor(0x000000);
            noteLabel.setFocus(false);
            noteLabel.setFocusable(false);
            noteLabel.setText((String) HILMain.getInstance().locale.get("help_select_date"));

            Form calendarForm = new Form();
            calendarForm.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
            final Calendar aCalendar = new Calendar();

            Command okCommand =
                new Command((String) HILMain.getInstance().locale.get("ok")) {
                  public void actionPerformed(ActionEvent evt) {
                    showForm(f);
                  }
                };

            aCalendar.addActionListener(
                new ActionListener() {
                  public void actionPerformed(ActionEvent evt) {
                    date = aCalendar.getDate();
                    if (!DateUtil.getMonthYear(date, "/").equalsIgnoreCase(dateLabel.getText())) {
                      dateLabel.setText(DateUtil.getMonthYear(date, "/"));
                      reportId = "";
                      normalReaction.setText("");
                      seriousReaction.setText("");
                      tetanus.setText("");
                      normalReaction.setEditable(true);
                      seriousReaction.setEditable(true);
                      tetanus.setEditable(true);
                      buttonEdit.setEnabled(false);
                      buttonSave.setEnabled(false);
                    }
                  }
                });
            calendarForm.addComponent(noteLabel);
            Container tContainer = new Container();
            tContainer.setLayout(new BorderLayout());
            tContainer.addComponent(BorderLayout.CENTER, aCalendar);
            calendarForm.addComponent(tContainer);
            calendarForm.addCommand(okCommand);
            calendarForm.show();
          }
        });

    submit.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent ae) {
            ConnectionRequest req =
                new ConnectionRequest() {
                  protected void readResponse(InputStream input) throws IOException {
                    JSONParser p = new JSONParser();

                    Hashtable result = p.parse(new InputStreamReader(input, "UTF-8"));
                    result = (Hashtable) result.get("ResultSet");

                    int total = ((Double) result.get("totalResultsReturned")).intValue();

                    if (total == 0) {
                      Dialog.show(
                          (String) HILMain.getInstance().locale.get("notice"),
                          (String) HILMain.getInstance().locale.get("there_is_no_data"),
                          (String) HILMain.getInstance().locale.get("ok"),
                          null);
                      reportId = "";
                      normalReaction.setText("");
                      normalReaction.setEditable(true);
                      seriousReaction.setText("");
                      seriousReaction.setEditable(true);
                      tetanus.setText("");
                      tetanus.setEditable(true);
                      normalReaction.setEditable(true);
                      seriousReaction.setEditable(true);
                      tetanus.setEditable(true);
                      buttonEdit.setEnabled(false);
                      buttonSave.setEnabled(true);
                    } else {
                      Vector entries = (Vector) result.get("Result");
                      for (int iter = 0; iter < entries.size(); iter++) {
                        result = (Hashtable) entries.elementAt(iter);
                        reportId = (String) result.get("reportId");
                        normalReaction.setText((String) result.get("normal"));
                        normalReaction.setEditable(false);
                        seriousReaction.setText((String) result.get("serious"));
                        seriousReaction.setEditable(false);
                        tetanus.setText((String) result.get("tetanus"));
                        tetanus.setEditable(false);
                        normalReaction.setEditable(false);
                        seriousReaction.setEditable(false);
                        tetanus.setEditable(false);
                        buttonEdit.setEnabled(true);
                        buttonSave.setEnabled(false);
                      }
                      if (normalReaction.getText().length() == 0
                          && seriousReaction.getText().length() == 0
                          && tetanus.getText().length() == 0) {
                        Dialog.show(
                            (String) HILMain.getInstance().locale.get("notice"),
                            (String) HILMain.getInstance().locale.get("there_is_no_data"),
                            (String) HILMain.getInstance().locale.get("ok"),
                            null);
                        normalReaction.setEditable(true);
                        seriousReaction.setEditable(true);
                        tetanus.setEditable(true);
                        buttonEdit.setEnabled(false);
                        buttonSave.setEnabled(true);
                      }
                    }
                  }
                };
            req.setPost(true);
            req.setUrl(HILMain.getInstance().SERVER_ADDRESS + "generalReportData");

            req.setContentType("text/plain");
            req.addArgumentNoEncoding(
                "sessionAuth", HILMain.getInstance().currentUser.getSessionAuth());
            req.addArgumentNoEncoding(
                "username", HILMain.getInstance().currentUser.getAccountName());
            req.addArgumentNoEncoding("password", HILMain.getInstance().currentUser.getPassword());
            req.addArgumentNoEncoding("cId", HILMain.getInstance().currentUser.getcId());
            req.addArgumentNoEncoding("timeData", DateUtil.getMonthYear(date, "/"));
            NetworkManager.getInstance().addToQueue(req);
          }
        });
  }
Exemple #2
0
 public String getName() {
   return (String) HILMain.getInstance().locale.get("report_data");
 }