public Canvas getViewPanel() {

    VLayout layout = new VLayout(15);
    layout.setWidth(650);
    layout.setAutoHeight();

    final ListGrid countryGrid = new ListGrid();
    countryGrid.setLeaveScrollbarGap(true);
    countryGrid.setCanFreezeFields(false);
    countryGrid.setCanGroupBy(false);
    countryGrid.setWidth100();
    countryGrid.setHeight(224);
    countryGrid.setDataSource(CountryXmlDS.getInstance());
    countryGrid.setAutoFetchData(true);

    // allow users to add formula and summary fields
    // accessible in the grid header context menu
    countryGrid.setCanAddFormulaFields(true);
    countryGrid.setCanAddSummaryFields(true);

    ListGridField countryCodeField = new ListGridField("countryCode", "Flag", 50);
    countryCodeField.setAlign(Alignment.CENTER);
    countryCodeField.setType(ListGridFieldType.IMAGE);
    countryCodeField.setImageURLPrefix("flags/16/");
    countryCodeField.setImageURLSuffix(".png");
    countryCodeField.setCanSort(false);

    ListGridField nameField = new ListGridField("countryName", "Country");
    ListGridField capitalField = new ListGridField("capital", "Capital");

    ListGridField populationField = new ListGridField("population", "Population");
    populationField.setCellFormatter(
        new CellFormatter() {
          public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
            if (value == null) return null;
            try {
              NumberFormat nf = NumberFormat.getFormat("0,000");
              return nf.format(((Number) value).longValue());
            } catch (Exception e) {
              return value.toString();
            }
          }
        });

    ListGridField areaField = new ListGridField("area", "Area (km²)");
    areaField.setType(ListGridFieldType.INTEGER);
    areaField.setCellFormatter(
        new CellFormatter() {
          public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
            if (value == null) return null;
            String val = null;
            try {
              NumberFormat nf = NumberFormat.getFormat("0,000");
              val = nf.format(((Number) value).longValue());
            } catch (Exception e) {
              return value.toString();
            }
            return val + "km&sup2";
          }
        });
    countryGrid.setFields(countryCodeField, nameField, capitalField, populationField, areaField);

    ToolStripButton formulaButton =
        new ToolStripButton("Formula Builder", "crystal/oo/sc_insertformula.png");
    formulaButton.setAutoFit(true);
    formulaButton.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            countryGrid.addFormulaField();
          }
        });

    ToolStripButton summaryBuilder =
        new ToolStripButton("Summary Builder", "crystal/16/apps/tooloptions.png");
    summaryBuilder.setAutoFit(true);
    summaryBuilder.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            countryGrid.addSummaryField();
          }
        });

    ToolStripButton savePreference = new ToolStripButton("Persist State", "silk/database_gear.png");
    savePreference.setAutoFit(true);
    savePreference.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            String viewState = countryGrid.getViewState();
            Offline.put("exampleState", viewState);
            SC.say("Preferences persisted.");
          }
        });

    // toolstrip to attach to the country grid
    ToolStrip countryGridToolStrip = new ToolStrip();
    countryGridToolStrip.setWidth100();
    countryGridToolStrip.addFill();
    countryGridToolStrip.addButton(formulaButton);
    countryGridToolStrip.addButton(summaryBuilder);
    countryGridToolStrip.addSeparator();
    countryGridToolStrip.addButton(savePreference);

    VLayout countryGridLayout = new VLayout(0);
    countryGridLayout.setWidth(650);
    countryGridLayout.addMember(countryGridToolStrip);
    countryGridLayout.addMember(countryGrid);
    layout.addMember(countryGridLayout);

    final String previouslySavedState = (String) Offline.get("exampleState");
    if (previouslySavedState != null) {
      countryGrid.addDrawHandler(
          new DrawHandler() {
            @Override
            public void onDraw(DrawEvent event) {
              // restore any previously saved view state for this grid
              countryGrid.setViewState(previouslySavedState);
            }
          });
    }

    return layout;
  }
Exemple #2
0
  private void onSubmit(final GUIInfo info) {
    vm.validate();
    Tab tab = tabs.getSelectedTab();
    int tabIndex = tabs.getSelectedTabNumber();
    DynamicForm form = (DynamicForm) tab.getPane();
    if (form.hasErrors()) {

    } else {
      if (step == 4) {
        if (!vm.validate()) SC.warn("invalidfields");

        SetupInfo data = new SetupInfo();
        data.setDbDriver(vm.getValueAsString(DB_DRIVER));
        data.setDbUrl(vm.getValueAsString(DB_URL));
        data.setDbUsername(vm.getValueAsString(DB_USERNAME));
        data.setDbPassword(vm.getValueAsString(DB_PASSWORD));
        data.setDbEngine(vm.getValueAsString(DB_ENGINE));
        data.setDbType(vm.getValueAsString(DB_TYPE));
        data.setLanguage(vm.getValueAsString(LANGUAGE));
        data.setSmtpHost(vm.getValueAsString(SMTP_HOST));
        data.setSmtpPort((Integer) vm.getValues().get(SMTP_PORT));
        data.setSmtpUsername(vm.getValueAsString(SMTP_USERNAME));
        data.setSmtpPassword(vm.getValueAsString(SMTP_PASSWORD));
        data.setSmtpSender(vm.getValueAsString(SMTP_SENDER));
        data.setSmtpSecureAuth((Boolean) vm.getValues().get(SMTP_SECURE_AUTH));
        data.setSmtpSecuryConntection(vm.getValueAsString(SMTP_SECURITY_CONNECTION));
        data.setRepositoryFolder(vm.getValueAsString(REPOSITORY_FOLDER));
        data.setDbDialect(engines.get(data.getDbEngine())[3]);
        data.setDbValidationQuery(engines.get(data.getDbEngine())[4]);
        data.setRegEmail(vm.getValueAsString(REG_EMAIL));
        data.setRegName(vm.getValueAsString(REG_NAME));
        data.setRegOrganization(vm.getValueAsString(REG_ORGANIZATION));
        data.setRegWebsite(vm.getValueAsString(REG_WEBSITE));
        if (data.getDbType().equals(I18N.message(INTERNAL))) {
          data.setDbEngine("Hsqldb");
          data.setDbDriver("org.hsqldb.jdbcDriver");
          data.setDbUrl(
              ("jdbc:hsqldb:" + data.getRepositoryFolder() + "/db/").replaceAll("//", "/"));
          data.setDbUsername("sa");
          data.setDbPassword("");
          data.setDbValidationQuery("SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS");
          data.setDbDialect("org.hibernate.dialect.HSQLDialect");
        }

        SetupServiceAsync setupService = (SetupServiceAsync) GWT.create(SetupService.class);
        setupService.setup(
            data,
            new AsyncCallback<Void>() {
              @Override
              public void onFailure(Throwable caught) {
                SC.warn(caught.getMessage());
                submit.setDisabled(false);
              }

              @Override
              public void onSuccess(Void arg) {
                SC.say(
                    I18N.message("installationperformed"),
                    I18N.message("installationend", info.getProductName()),
                    new BooleanCallback() {
                      @Override
                      public void execute(Boolean value) {
                        Util.redirect(Util.contextPath() + "frontend.jsp");
                      }
                    });
                submit.setDisabled(false);
              }
            });
        submit.setDisabled(true);

        // Clear an eventually saved documents list grid settings.
        Offline.put("doclist", "");
      } else {
        // Go to the next tab and enable the contained panel
        tabs.selectTab(tabIndex + 1);
        tabs.getSelectedTab().getPane().setDisabled(false);
        if (step < tabs.getSelectedTabNumber()) step++;
        if (step == 4) submit.setTitle(I18N.message("setup"));
      }
    }
  }