示例#1
0
  /** This is the entry point method. */
  @Override
  public void onModuleLoad() {

    FormUtil.setupUncaughtExceptionHandler();

    FormUtil.retrieveUserDivParameters();

    Context.startup();

    // FormDesignerWidget designer = new FormDesignerWidget(true,true,true);

    // Hook the window resize event, so that we can adjust the UI.
    Window.addResizeHandler(this);

    // Get rid of scrollbars, and clear out the window's built-in margin,
    // because we want to take advantage of the entire client area.
    Window.enableScrolling(false);
    Window.setMargin("0px");

    // Different themes use different background colors for the body
    // element, but IE only changes the background of the visible content
    // on the page instead of changing the background color of the entire
    // page. By changing the display style on the body element, we force
    // IE to redraw the background correctly.
    RootPanel.getBodyElement().getStyle().setProperty("display", "none");
    RootPanel.getBodyElement().getStyle().setProperty("display", "");

    // Finally, add the designer widget to the RootPanel, so that it will be
    // displayed.
    RootPanel.get().add(loginView);

    FormUtil.dlg
        .hide(); // Temporary fix This comes from the form designer where it loads and never closes
  }
  /**
   * @see void
   *     org.openxdata.server.admin.client.view.treeview.StudiesTreeView#onSetFileContents(String)
   */
  public static void onSetFileContents(
      final Tree tree, final TreeItem item, String contents, final PopupPanel popup) {

    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, "formopen");

    try {
      builder.sendRequest(
          null,
          new RequestCallback() {
            @Override
            public void onResponseReceived(Request request, Response response) {

              FormUtil.dlg.setText("Importing.......");
              FormUtil.dlg.center();

              final Response resp = response;

              Scheduler.get()
                  .scheduleDeferred(
                      new ScheduledCommand() {
                        @Override
                        public void execute() {
                          try {
                            Editable editable = StudyImport.importStudyItem(resp.getText());
                            if (editable == null) {
                              FormUtil.dlg.hide();
                              Window.alert("Invalid Import File");
                              return;
                            }

                            if (editable instanceof StudyDef) {
                              setStudyContent(tree, popup, editable);
                            } else if (editable instanceof FormDef) {
                              setFormContents(tree, item, popup, editable);
                            } else if (editable instanceof FormDefVersion) {
                              setFormDefVersionContents(tree, item, popup, editable);
                            }

                            FormUtil.dlg.hide();

                            MainViewControllerFacade.saveData();
                          } catch (Exception ex) {
                            FormUtil.dlg.hide();
                            FormUtil.displayException(ex);
                          }
                        }
                      });
            }

            @Override
            public void onError(Request request, Throwable ex) {
              FormUtil.displayException(ex);
            }
          });
    } catch (RequestException ex) {
      FormUtil.displayException(ex);
    }
  }
示例#3
0
  /**
   * Converts a form definition object to XHTML.
   *
   * @param formDef the form definition object.
   * @return the xhtml.
   */
  public static String fromFormDef2Xhtml(FormDef formDef) {
    Document doc = fromFormDef2XhtmlDoc(formDef);
    formDef.setDoc(doc);
    formDef.setXformsNode(doc.getDocumentElement());

    if (FormUtil.isJavaRosaSaveFormat()) ItextBuilder.build(formDef);

    return XmlUtil.fromDoc2String(doc);
  }
示例#4
0
  /**
   * Creates a new instance of the form runner widget.
   *
   * @param images the images to load icons.
   */
  public FormRunnerWidget(Images images) {

    view = new FormRunnerView(/*images*/ );

    dockPanel.add(view, DockPanel.CENTER);

    FormUtil.maximizeWidget(dockPanel);

    initWidget(dockPanel);

    controller = new FormRunnerController(this);
    view.setSubmitListener(controller);

    // process key board events and pick Ctrl + S for saving.
    previewEvents();
  }
示例#5
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);
                }
              }
            });
  }
示例#6
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);
  }