Example #1
0
  public AboutDialog() {
    // Use this opportunity to set the dialog's caption.
    setText(LocaleText.get("about") + " " + FormDesignerUtil.getTitle());

    // Create a VerticalPanel to contain the 'about' label and the 'OK' button.
    VerticalPanel outer = new VerticalPanel();

    // Create the 'about' text and set a style name so we can style it with CSS.

    HTML text = new HTML(LocaleText.get("aboutMessage"));
    text.setStyleName("formDesigner-AboutText");
    outer.add(text);

    // Create the 'OK' button, along with a listener that hides the dialog
    // when the button is clicked.
    Button btn =
        new Button(
            LocaleText.get("close"),
            new ClickHandler() {
              public void onClick(ClickEvent event) {
                hide();
              }
            });

    outer.add(btn);
    outer.setCellHorizontalAlignment(btn, HasAlignment.ALIGN_CENTER);

    setWidget(outer);
  }
Example #2
0
  /** Called when one selects the save button. */
  private void save() {
    try {
      // first see if the user is logged in.
      String user = UserInfo.getCurrentUser();
      if (user == null) {
        statusLabel.setText(LocaleText.get("mustLoginFirst"));
        DOM.setStyleAttribute(statusLabel.getElement(), "color", "red");
        return;
      }

      // check and see if this form already exists
      String form = UserInfo.getForm(user, txtFormName.getText());

      if (form != null) {
        // Window.alert("This form already exists and will be over written");
        if (!Window.confirm(
            "A form by this name is already saved in this browser. Do you want to overwrite it?")) {
          return;
        }
      }

      UserInfo.setForm(user, txtFormName.getText(), formXmlStr);
      // clear dirty flags
      FormDesignerController.clearIsDirty();

      hide();
    } catch (Exception e) // in case there's an error with storage
    {
      statusLabel.setText(e.getMessage());
      DOM.setStyleAttribute(statusLabel.getElement(), "color", "red");
    }
  }
Example #3
0
  /** Sets up the login widget. */
  private void setup() {

    setText(LocaleText.get("saveFormToBrowserTitle"));
    statusLabel = new Label();

    // first see if the user is logged in.
    String user = UserInfo.getCurrentUser();
    if (user == null) {
      statusLabel.setText(LocaleText.get("mustLoginFirst"));
      DOM.setStyleAttribute(statusLabel.getElement(), "color", "red");
    } else {

      Label label = new Label(LocaleText.get("formName"));
      table.setWidget(1, 0, label);

      txtFormName = new TextBox();
      txtFormName.setText(formDisplayText);

      // check and see if this form has already been saved
      String currentForm = UserInfo.getCurrentForm();
      if (currentForm != null) {
        txtFormName.setText(currentForm);
      }

      txtFormName.setWidth("50%");
      table.setWidget(1, 1, txtFormName);
      FormUtil.maximizeWidget(txtFormName);

      txtFormName.addKeyUpHandler(
          new KeyUpHandler() {
            public void onKeyUp(KeyUpEvent event) {
              if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) save();
            }
          });

      Button btnSave =
          new Button(
              LocaleText.get("save"),
              new ClickHandler() {
                public void onClick(ClickEvent event) {
                  save();
                }
              });

      table.setWidget(3, 0, btnSave);
    }

    Button btnCancel =
        new Button(
            LocaleText.get("cancel"),
            new ClickHandler() {
              public void onClick(ClickEvent event) {
                cancel();
              }
            });

    table.setWidget(2, 0, statusLabel);
    table.setWidget(3, 1, btnCancel);

    FlexCellFormatter formatter = table.getFlexCellFormatter();
    formatter.setColSpan(2, 0, 3);
    formatter.setColSpan(3, 0, 3);
    formatter.setColSpan(4, 0, 2);
    formatter.setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    formatter.setHorizontalAlignment(2, 0, HasHorizontalAlignment.ALIGN_CENTER);

    formatter.setWidth(1, 1, "50%");

    VerticalPanel panel = new VerticalPanel();
    FormUtil.maximizeWidget(panel);
    panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    panel.add(table);

    setWidget(panel);

    setWidth("300px");

    Scheduler.get()
        .scheduleDeferred(
            new Command() {
              public void execute() {
                if (txtFormName != null) {
                  txtFormName.setFocus(true);
                }
              }
            });
  }
Example #4
0
  /** Sets up the tool bar. */
  private void setupToolbar() {
    btnNewForm = new PushButton(FormUtil.createImage(images.newform()));
    btnOpenForm = new PushButton(FormUtil.createImage(images.open()));
    btnSaveForm = new PushButton(FormUtil.createImage(images.save()));

    btnAddNewItem = new PushButton(FormUtil.createImage(images.add()));
    btnAddNewChildItem = new PushButton(FormUtil.createImage(images.addchild()));
    btnDeleteItem = new PushButton(FormUtil.createImage(images.delete()));
    btnMoveItemUp = new PushButton(FormUtil.createImage(images.moveup()));
    btnMoveItemDown = new PushButton(FormUtil.createImage(images.movedown()));

    btnAlignLeft = new PushButton(FormUtil.createImage(images.justifyleft()));
    btnAlignRight = new PushButton(FormUtil.createImage(images.justifyright()));
    btnAlignTop = new PushButton(FormUtil.createImage(images.alignTop()));
    btnAlignBottom = new PushButton(FormUtil.createImage(images.alignBottom()));
    btnSameWidth = new PushButton(FormUtil.createImage(images.samewidth()));
    btnSameHeight = new PushButton(FormUtil.createImage(images.sameheight()));
    btnSameSize = new PushButton(FormUtil.createImage(images.samesize()));

    btnCut = new PushButton(FormUtil.createImage(images.cut()));
    btnCopy = new PushButton(FormUtil.createImage(images.copy()));
    btnPaste = new PushButton(FormUtil.createImage(images.paste()));
    btnRefresh = new PushButton(FormUtil.createImage(images.refresh()));

    btnUndo = new PushButton(FormUtil.createImage(images.undo()));
    btnRedo = new PushButton(FormUtil.createImage(images.redo()));

    btnNewForm.setTitle(LocaleText.get("newForm"));
    btnSaveForm.setTitle(LocaleText.get("save"));

    btnAddNewItem.setTitle(LocaleText.get("addNew"));
    btnAddNewChildItem.setTitle(LocaleText.get("addNewChild"));
    btnDeleteItem.setTitle(LocaleText.get("deleteSelected"));
    btnMoveItemUp.setTitle(LocaleText.get("moveUp"));
    btnMoveItemDown.setTitle(LocaleText.get("moveDown"));

    btnCut.setTitle(LocaleText.get("cut"));
    btnCopy.setTitle(LocaleText.get("copy"));
    btnPaste.setTitle(LocaleText.get("paste"));
    btnRefresh.setTitle(LocaleText.get("refresh"));

    btnAlignLeft.setTitle(LocaleText.get("alignLeft"));
    btnAlignRight.setTitle(LocaleText.get("alignRight"));
    btnAlignTop.setTitle(LocaleText.get("alignTop"));
    btnAlignBottom.setTitle(LocaleText.get("alignBottom"));
    btnSameWidth.setTitle(LocaleText.get("makeSameWidth"));
    btnSameHeight.setTitle(LocaleText.get("makeSameHeight"));
    btnSameSize.setTitle(LocaleText.get("makeSameSize"));

    btnUndo.setTitle(LocaleText.get("undo"));
    btnRedo.setTitle(LocaleText.get("redo"));

    if (Context.isOfflineMode()) panel.add(btnNewForm);

    panel.add(btnOpenForm);

    panel.add(btnSaveForm);

    panel.add(separatorWidget);

    panel.add(btnAddNewItem);
    panel.add(btnAddNewChildItem);
    panel.add(btnDeleteItem);
    panel.add(separatorWidget);
    panel.add(btnMoveItemUp);
    panel.add(btnMoveItemDown);

    panel.add(separatorWidget);
    panel.add(btnCut);
    panel.add(btnCopy);
    panel.add(btnPaste);

    panel.add(separatorWidget);
    panel.add(btnRefresh);

    panel.add(separatorWidget);
    panel.add(btnAlignLeft);
    panel.add(btnAlignRight);
    panel.add(btnAlignTop);
    panel.add(btnAlignBottom);

    panel.add(separatorWidget);
    panel.add(btnSameWidth);
    panel.add(btnSameHeight);
    panel.add(btnSameSize);

    panel.add(separatorWidget);
    panel.add(btnUndo);
    panel.add(btnRedo);

    Label label = new Label(FormDesignerUtil.getTitle());
    panel.add(label);
    panel.setCellWidth(label, "100%");
    panel.setCellHorizontalAlignment(label, HasHorizontalAlignment.ALIGN_CENTER);

    label = new Label(LocaleText.get("language"));
    panel.add(label);
    panel.setCellHorizontalAlignment(label, HasHorizontalAlignment.ALIGN_RIGHT);

    populateLocales();

    cbLanguages.addChangeHandler(
        new ChangeHandler() {
          public void onChange(ChangeEvent event) {
            int index = getLocaleIndex(Context.getLocale().getKey());
            ListBox listBox = (ListBox) event.getSource();
            Locale newLocale =
                new Locale(
                    listBox.getValue(listBox.getSelectedIndex()),
                    listBox.getItemText(listBox.getSelectedIndex()));
            if (!controller.changeLocale(newLocale)) cbLanguages.setSelectedIndex(index);
          }
        });

    panel.add(cbLanguages);
    panel.setCellHorizontalAlignment(cbLanguages, HasHorizontalAlignment.ALIGN_RIGHT);

    // Set a 3 pixels spacing between tool bar buttons.
    panel.setSpacing(3);
  }