Exemplo n.º 1
0
  /** Prepares the SMTP form */
  private Tab setupSmtp(final ValuesManager vm) {
    // Prepare the SMTP connection tab
    Tab smtpTab = new Tab();
    smtpTab.setTitle(I18N.message("smtpserver"));
    final DynamicForm smtpForm = new DynamicForm();
    smtpForm.setDisabled(true);
    smtpForm.setID("smtpForm");
    smtpForm.setTitleOrientation(TitleOrientation.TOP);
    smtpForm.setValuesManager(vm);
    smtpTab.setPane(smtpForm);

    TextItem smtpHost = ItemFactory.newTextItem(SMTP_HOST, "host", null);
    smtpHost.setValue("localhost");
    smtpHost.setWrapTitle(false);

    IntegerItem smtpPort = ItemFactory.newIntegerItem(SMTP_PORT, "port", null);
    smtpPort.setValue(25);
    smtpPort.setWrapTitle(false);

    TextItem smtpUsername = ItemFactory.newTextItem(SMTP_USERNAME, "username", null);
    smtpUsername.setWrapTitle(false);

    PasswordItem smtpPassword = new PasswordItem();
    smtpPassword.setTitle(I18N.message("password"));
    smtpPassword.setName(SMTP_PASSWORD);
    smtpPassword.setWrapTitle(false);

    BooleanItem smtpSecureAuth = new BooleanItem();
    smtpSecureAuth.setTitle(I18N.message("secureauth"));
    smtpSecureAuth.setName(SMTP_SECURE_AUTH);
    smtpSecureAuth.setWrapTitle(false);
    smtpSecureAuth.setDefaultValue(false);

    SelectItem smtpConnectionSecurity = new SelectItem();
    smtpConnectionSecurity.setTitle(I18N.message("connectionsecurity"));
    smtpConnectionSecurity.setName("smtpConnectionSecurity");
    smtpConnectionSecurity.setDefaultValue(Constants.SMTP_SECURITY_NONE);
    smtpConnectionSecurity.setWrapTitle(false);
    LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>();
    valueMap.put(Constants.SMTP_SECURITY_NONE, I18N.message("none"));
    valueMap.put(Constants.SMTP_SECURITY_SSL, I18N.message("ssl"));
    valueMap.put(Constants.SMTP_SECURITY_TLS, I18N.message("tls"));
    valueMap.put(Constants.SMTP_SECURITY_TLS_IF_AVAILABLE, I18N.message("tlsavailable"));
    smtpConnectionSecurity.setValueMap(valueMap);

    TextItem smtpSender = ItemFactory.newEmailItem(SMTP_SENDER, "sender", false);
    smtpSender.setWrapTitle(false);
    smtpSender.setValue("*****@*****.**");

    smtpForm.setFields(
        smtpHost,
        smtpPort,
        smtpUsername,
        smtpPassword,
        smtpSender,
        smtpConnectionSecurity,
        smtpSecureAuth);
    return smtpTab;
  }
  private void initExportButton() {
    setHeight(30);
    exportButton.setShowRollOver(false);
    exportButton.setIcon(GWT.getHostPageBaseURL() + "images/icons/32/woofunction/export_32.png");
    exportButton.setIconOrientation("right");

    final DynamicForm exportForm = new DynamicForm();
    exportForm.setNumCols(4);
    // exportForm.setWidth(300);

    SelectItem exportTypeItem = new SelectItem("exportType", "Exporteer als");
    //    exportTypeItem.setWidth(150);
    exportTypeItem.setDefaultToFirstOption(true);
    LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>();
    valueMap.put("ooxml", "XLSX (Excel2007+/OOXML)");
    valueMap.put("xls", "XLS (Excel97)");
    valueMap.put("csv", "CSV (Excel)");
    // valueMap.put("xml", "XML");
    // valueMap.put("json", "JSON");
    exportTypeItem.setValueMap(valueMap);

    BooleanItem showInWindowItem = new BooleanItem();
    showInWindowItem.setName("showInWindow");
    showInWindowItem.setTitle("Toon Export in nieuw venster");
    showInWindowItem.setAlign(Alignment.LEFT);

    exportForm.setFields(exportTypeItem, showInWindowItem);

    exportButton.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            String exportAs = (String) exportForm.getField("exportType").getValue();
            FormItem item = exportForm.getField("showInWindow");
            boolean showInWindow = item.getValue() == null ? false : (Boolean) item.getValue();
            DSRequest dsRequestProperties = new DSRequest();

            // set all fields, also from joined models. If they don't appear in the DS.xml file,
            // they will be ignored. Adding foreign fields to ds.xml automatically makes them being
            // exported as well.
            // (just make sure the query does some joins correctly, as is normal!)
            String[] f = fields == null ? ds.getFieldNames() : fields;

            if (hideInvisibleFieldsFromExport) {
              f = ListGridUtil.getVisibleFields(grid);
            }

            dsRequestProperties.setExportFields(f);

            if (fetchOperation != null) {
              dsRequestProperties.setOperationId(fetchOperation);
            }

            if (criteria != null) {
              dsRequestProperties.setCriteria(criteria);
              dsRequestProperties.setTextMatchStyle(TextMatchStyle.EXACT);
            }

            if (exportAs.equals("json")) {
              // JSON exports are server-side only, so use the OperationBinding on the DataSource
              dsRequestProperties.setOperationId("customJSONExport");
              dsRequestProperties.setExportDisplay(
                  showInWindow ? ExportDisplay.WINDOW : ExportDisplay.DOWNLOAD);

              grid.exportData(dsRequestProperties);
            } else {
              // exportAs is either XML or CSV, which we can do with requestProperties
              dsRequestProperties.setExportAs(
                  (ExportFormat) EnumUtil.getEnum(ExportFormat.values(), exportAs));
              dsRequestProperties.setExportDisplay(
                  showInWindow ? ExportDisplay.WINDOW : ExportDisplay.DOWNLOAD);

              grid.exportData(dsRequestProperties);
            }
          }
        });
    addMember(exportButton);
    addMember(exportForm);
  }