Beispiel #1
0
  public Window getEmptyWindow() {

    Window w = new Window();
    w.setMinimizable(false);
    w.setMaximizable(false);
    w.setBodyBorder(false);
    w.setBorders(false);
    w.setClosable(false);
    w.setHeaderVisible(false);
    return w;
  }
  private SageAlertViewport() {

    westPanel = new ContentPanel();
    westPanel.setScrollMode(Scroll.AUTOY);
    BorderLayoutData westData = new BorderLayoutData(LayoutRegion.WEST, 280);
    westPanel.add(new MenuTreePanel(new MenuDataStore()));
    westPanel.setHeaderVisible(false);
    westPanel.setBottomComponent(new SageAlertToolBar());

    centerPanel = new ContentPanel();
    centerPanel.setLayout(new FitLayout());
    BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
    centerPanel.setHeaderVisible(false);

    mainWindow = new Window();
    mainWindow.setDraggable(false);
    mainWindow.setHeading("SageAlert v" + Version.getFullVersion());
    mainWindow.setClosable(false);
    mainWindow.setResizable(false);
    mainWindow.setSize(600, 450);
    mainWindow.setLayout(new BorderLayout());
    mainWindow.add(westPanel, westData);
    mainWindow.add(centerPanel, centerData);
    add(mainWindow);
    SettingsServiceAsync rpc = GWT.create(SettingsService.class);
    rpc.isLicensed(
        new AsyncCallback<Boolean>() {

          public void onFailure(Throwable caught) {
            GWT.log("ERROR", caught);
          }

          public void onSuccess(Boolean result) {
            String newHeading = mainWindow.getHeading();
            if (!result) newHeading = newHeading.concat(" (Unlicensed)");
            else newHeading = newHeading.concat(" (Licensed)");
            mainWindow.setHeading(newHeading);
          }
        });
  }
  @Override
  public Widget asWidget() {

    // show window
    window.setSize(400, 310);
    window.setPlain(true);
    window.setModal(true);
    window.setClosable(false);
    window.setResizable(false);
    window.setHeading(AppController.Lang.AddNew(AppController.Lang.RunValue().toLowerCase()));
    window.setLayout(new FitLayout());

    // form
    final FormData formData = new FormData("-20");
    FormPanel simple = new FormPanel();
    simple.setHeaderVisible(false);
    simple.setFrame(true);
    simple.setAutoWidth(true);
    simple.setLabelWidth(100);
    // run
    cbName.setDisplayField("n");
    cbName.setFieldLabel(AppController.Lang.Run());
    cbName.setStore(storeName);
    cbName.setEnabled(false);
    cbName.setMinLength(Constants.LIMIT_NAME_MIN);
    cbName.setMaxLength(Constants.LIMIT_NAME_MAX);
    cbName.setAllowBlank(false);
    cbName.setTriggerAction(TriggerAction.ALL);
    simple.add(cbName, formData);
    // date
    final DateField tfDate = CommonUtils.getDateField(date);
    simple.add(tfDate, formData);
    // time
    final TimeSelectFieldView tfTime = new TimeSelectFieldView(0, null);
    tfTime.setFieldLabel(AppController.Lang.Time());
    simple.add(tfTime);

    // duration
    final MySpinnerField tfDuration = CommonUtils.getDurationSpinner();
    simple.add(tfDuration, formData);
    // pulse
    final SpinnerField tfPulse = CommonUtils.getPulseSpinner();
    simple.add(tfPulse, formData);
    // pulse max
    final SpinnerField tfPulseMax = CommonUtils.getPulseSpinner();
    tfPulseMax.setFieldLabel(AppController.Lang.MaxPulse());
    simple.add(tfPulseMax, formData);
    // calories
    final SpinnerField tfCalories = CommonUtils.getCaloriesSpinner();
    simple.add(tfCalories, formData);

    // info
    final TextArea tfInfo = new TextArea();
    tfInfo.setPreventScrollbars(true);
    tfInfo.setFieldLabel(AppController.Lang.Info());
    simple.add(tfInfo, formData);

    // buttons eventhandler
    Button btnAdd = new Button(AppController.Lang.Add());
    btnAdd.setScale(ButtonScale.MEDIUM);
    btnAdd.addSelectionListener(
        new SelectionListener<ButtonEvent>() {
          @SuppressWarnings("deprecation")
          @Override
          public void componentSelected(ButtonEvent ce) {
            try {
              // return model
              if (handler != null) {

                final int pulse = (int) tfPulse.getValue().doubleValue();
                final int pulseMax = (int) tfPulseMax.getValue().doubleValue();
                final int calories = (int) tfCalories.getValue().doubleValue();
                // date and time
                Date date = tfDate.getValue();
                final double time = CommonUtils.getTimeToSeconds(tfTime.getValue());
                date.setHours((int) (time / 3600));
                date.setMinutes((int) ((time % 3600) / 60));
                date = CommonUtils.trimDateToDatabase(date, false);
                final String info = tfInfo.getValue();
                final long duration = tfDuration.getValue().intValue();

                RunValueModel value = new RunValueModel();
                value.setCalories(calories);
                value.setDate(date);
                value.setDuration(duration);
                value.setInfo(info);
                value.setPulse(pulse);
                value.setPulseMax(pulseMax);

                // get run
                RunModel run = null;
                // if no values
                if (cbName.getValue() == null) {
                  final String str = cbName.getRawValue();
                  run = new RunModel(0L, str);
                }
                // if user typed new value
                else if (!cbName.getRawValue().equals(cbName.getValue().getNameClient())) {
                  final String str = cbName.getRawValue();
                  run = new RunModel(0L, str);
                }
                // value selected from list
                else {
                  run = cbName.getValue();
                }

                handler.newValue(run, value);
              }

            } catch (Exception e) {
              Motiver.showException(e);
            }
          }
        });
    simple.addButton(btnAdd);
    Button btnCancel = new Button(AppController.Lang.Cancel());
    btnCancel.setScale(ButtonScale.MEDIUM);
    // hide window
    btnCancel.addSelectionListener(
        new SelectionListener<ButtonEvent>() {
          @Override
          public void componentSelected(ButtonEvent ce) {
            handler.cancel();
          }
        });
    simple.addButton(btnCancel);
    simple.setButtonAlign(HorizontalAlignment.CENTER);
    FormButtonBinding binding = new FormButtonBinding(simple);
    binding.addButton(btnAdd);
    window.add(simple);

    window.show();

    return this;
  }
  public void initUserImportView() {
    final Window window = new Window();
    window.setBodyBorder(false);
    FormPanel reportPanel = new FormPanel();
    Label dLabel = new Label(I18nUtils.getMessages().user_userImportReports());

    reportPanel.add(dLabel);
    reportPanel.setHeight(120);
    reportPanel.setBodyBorder(false);
    reportPanel.setHeaderVisible(false);
    reportPanel.setHideLabels(true);
    Button close = new Button(I18nUtils.getMessages().user_userImportReports_close());
    close.addListener(
        Events.OnClick,
        new Listener<BaseEvent>() {

          public void handleEvent(BaseEvent be) {
            window.hide();
          }
        });

    window.setTitle(I18nUtils.getMessages().user_userImportReports_window());
    window.setWidth(560);
    window.setHeading(I18nUtils.getMessages().user_importUsersPanel_title());
    window.setClosable(true);
    MyFileUpload importUserTool =
        new MyFileUpload("importusers") {

          @SuppressWarnings("unchecked")
          @Override
          public void fireActionComplete(String responseText) {
            JSONObject json = (JSONObject) JSONParser.parseLenient(responseText);
            JSONValue number = json.get("reportId");
            JSONNumber sJsonNumber = number.isNumber();

            UserService.Util.getInstance()
                .importUsers(
                    (int) sJsonNumber.doubleValue(),
                    new AsyncCallback() {

                      public void onFailure(Throwable caught) {
                        MessageBox.alert(
                            I18nUtils.getMessages().user_importUsersPanel_title(),
                            caught.getMessage(),
                            null);
                        GWT.log("importing users failed");
                      }

                      public void onSuccess(final Object result) {
                        ImportUserReport[] reports = (ImportUserReport[]) result;
                        String msg = "";
                        for (ImportUserReport r : reports) {
                          msg += r + "<br/>";
                        }
                        Dialog report = new Dialog();
                        report.setHeight(300);
                        report.setWidth(480);
                        report.addText(msg);
                        report.setHideOnButtonClick(true);
                        report.show();

                        load();
                      }
                    });
          }

          @Override
          public void actionEnd() {
            GWT.log("importing users  end up");
          }
        };

    reportPanel.add(importUserTool);
    reportPanel.addButton(close);
    reportPanel.setButtonAlign(HorizontalAlignment.RIGHT);
    window.add(reportPanel);

    window.show();
  }