@Override
  public void action() {
    final WebSiteExporter wsExporter = new WebSiteExporter();
    settings.load(wsExporter);

    WebSiteSettingsPanel wsPanelSettings = new WebSiteSettingsPanel();
    wsPanelSettings.setup(wsExporter);

    ValidationPanel validationPanel = WebSiteSettingsPanel.createValidationPanel(wsPanelSettings);

    final DialogDescriptor dialogDescriptor =
        new DialogDescriptor(
            validationPanel, getMessage("WebSiteExporterUI.dialogdescriptor.description"));

    validationPanel.addChangeListener(
        new ChangeListener() {

          @Override
          public void stateChanged(ChangeEvent e) {
            dialogDescriptor.setValid(!((ValidationPanel) e.getSource()).isProblem());
          }
        });
    Object result = DialogDisplayer.getDefault().notify(dialogDescriptor);
    if (result == NotifyDescriptor.OK_OPTION) {
      wsPanelSettings.unsetup(true);
      settings.save(wsExporter);
      filePath = wsExporter.getPath().getAbsolutePath();
      if (wsPanelSettings.getSelectedWorkspaces().length > 0) {
        wsExporter.setSelectedWorkspaces(wsPanelSettings.getSelectedWorkspaces());

        LongTaskExecutor executor = new LongTaskExecutor(true, "WebSiteExporter");
        executor.setLongTaskListener(longTaskListener);
        executor.setDefaultErrorHandler(errorHandler);
        executor.execute(
            wsExporter,
            new Runnable() {

              @Override
              public void run() {

                cancelled = !wsExporter.execute();
              }
            });
      } else {
        JOptionPane.showMessageDialog(
            validationPanel,
            getMessage("WebSiteExporterUI.Errormsg.WSSelected.Description"),
            getMessage("WebSiteExporterUI.Errormsg.WSSelected.Title"),
            JOptionPane.ERROR_MESSAGE);
      }
    } else {
      wsPanelSettings.unsetup(false);
    }
  }
  private void buildValidationPanel() {
    validationPanel = new ValidationPanel();
    validationPanel.setInnerComponent(this);

    ValidationGroup group = validationPanel.getValidationGroup();

    group.add(titleTextField, new ColumnTitleValidator(table));
    group.add(timestampText, new IntervalBoundValidator());

    validationPanel.addChangeListener(
        new ChangeListener() {
          @Override
          public void stateChanged(ChangeEvent e) {
            dialogControls.setOkButtonEnabled(!validationPanel.isProblem());
          }
        });
  }
示例#3
0
  public static ValidationPanel createValidationPanel(final EqualStringPanel innerPanel) {
    final ValidationPanel validationPanel = new ValidationPanel();
    validationPanel.setInnerComponent(innerPanel);

    ValidationGroup group = validationPanel.getValidationGroup();
    validationPanel.addChangeListener(
        new ChangeListener() {

          @Override
          public void stateChanged(ChangeEvent e) {
            innerPanel.okButton.setEnabled(!validationPanel.isProblem());
          }
        });
    // Node field
    group.add(innerPanel.textField, new RegexValidator(innerPanel));

    return validationPanel;
  }
  @Override
  public void unSetup() {
    String timestampString = timestampText.getText();
    boolean replaceColumn = replaceColumnCheckbox.isSelected();

    NbPreferences.forModule(ConvertColumnToDynamicTimestampsUI.class)
        .put(TIMESTAMP_PREFERENCE, timestampString);
    NbPreferences.forModule(ConvertColumnToDynamicTimestampsUI.class)
        .putBoolean(REPLACE_COLUMN_PREFERENCE, replaceColumn);

    if (!validationPanel.isProblem()) {
      manipulator.setTitle(titleTextField.getText());
      manipulator.setReplaceColumn(replaceColumn);

      double timestamp = AttributeUtils.parseDateTimeOrTimestamp(timestampString);

      manipulator.setLow(timestamp);
      manipulator.setHigh(timestamp);
    }
  }
  @Override
  public void importWizard(final WizardImporter importer) {
    try {
      if (importer == null) {
        NotifyDescriptor.Message msg =
            new NotifyDescriptor.Message(
                NbBundle.getMessage(
                    DesktopImportControllerUI.class,
                    "DesktopImportControllerUI.error_no_matching_db_importer"),
                NotifyDescriptor.WARNING_MESSAGE);
        DialogDisplayer.getDefault().notify(msg);
        return;
      }

      String containerSource =
          NbBundle.getMessage(
              DesktopImportControllerUI.class, "DesktopImportControllerUI.wizardSource", "");
      ImporterUI ui = controller.getUI(importer);
      if (ui != null) {
        String title =
            NbBundle.getMessage(
                DesktopImportControllerUI.class,
                "DesktopImportControllerUI.wizard.ui.dialog.title",
                ui.getDisplayName());
        JPanel panel = ui.getPanel();
        ui.setup(new WizardImporter[] {importer});
        final DialogDescriptor dd = new DialogDescriptor(panel, title);
        if (panel instanceof ValidationPanel) {
          ValidationPanel vp = (ValidationPanel) panel;
          vp.addChangeListener(
              new ChangeListener() {
                @Override
                public void stateChanged(ChangeEvent e) {
                  dd.setValid(!((ValidationPanel) e.getSource()).isProblem());
                }
              });
        }

        Object result = DialogDisplayer.getDefault().notify(dd);
        if (result.equals(NotifyDescriptor.CANCEL_OPTION)
            || result.equals(NotifyDescriptor.CLOSED_OPTION)) {
          ui.unsetup(false);
          return;
        }
        ui.unsetup(true);
        containerSource = ui.getDisplayName();
      }
      ImporterWizardUI wizardUI = controller.getWizardUI(importer);
      if (wizardUI != null) {
        containerSource = wizardUI.getCategory() + ":" + wizardUI.getDisplayName();
      }

      LongTask task = null;
      if (importer instanceof LongTask) {
        task = (LongTask) importer;
      }

      // Execute task
      final String source = containerSource;
      String taskName =
          NbBundle.getMessage(
              DesktopImportControllerUI.class,
              "DesktopImportControllerUI.taskName",
              containerSource);
      executor.execute(
          task,
          new Runnable() {
            @Override
            public void run() {
              try {
                Container container = controller.importWizard(importer);
                if (container != null) {
                  container.setSource(source);
                  finishImport(container);
                }
              } catch (Exception ex) {
                throw new RuntimeException(ex);
              }
            }
          },
          taskName,
          errorHandler);
    } catch (Exception ex) {
      Logger.getLogger("").log(Level.WARNING, "", ex);
    }
  }
  @Override
  public void importFile(final Reader reader, String importerName) {
    try {
      final FileImporter importer = controller.getFileImporter(importerName);
      if (importer == null) {
        NotifyDescriptor.Message msg =
            new NotifyDescriptor.Message(
                NbBundle.getMessage(
                    getClass(), "DesktopImportControllerUI.error_no_matching_file_importer"),
                NotifyDescriptor.WARNING_MESSAGE);
        DialogDisplayer.getDefault().notify(msg);
        return;
      }

      ImporterUI ui = controller.getUI(importer);
      if (ui != null) {
        ui.setup(new FileImporter[] {importer});
        String title =
            NbBundle.getMessage(
                DesktopImportControllerUI.class,
                "DesktopImportControllerUI.file.ui.dialog.title",
                ui.getDisplayName());
        JPanel panel = ui.getPanel();
        final DialogDescriptor dd = new DialogDescriptor(panel, title);
        if (panel instanceof ValidationPanel) {
          ValidationPanel vp = (ValidationPanel) panel;
          vp.addChangeListener(
              new ChangeListener() {
                @Override
                public void stateChanged(ChangeEvent e) {
                  dd.setValid(!((ValidationPanel) e.getSource()).isProblem());
                }
              });
        }

        Object result = DialogDisplayer.getDefault().notify(dd);
        if (!result.equals(NotifyDescriptor.OK_OPTION)) {
          ui.unsetup(false);
          return;
        }
        ui.unsetup(true);
      }

      LongTask task = null;
      if (importer instanceof LongTask) {
        task = (LongTask) importer;
      }

      // Execute task
      final String containerSource =
          NbBundle.getMessage(
              DesktopImportControllerUI.class,
              "DesktopImportControllerUI.streamSource",
              importerName);
      String taskName =
          NbBundle.getMessage(
              DesktopImportControllerUI.class,
              "DesktopImportControllerUI.taskName",
              containerSource);
      executor.execute(
          task,
          new Runnable() {
            @Override
            public void run() {
              try {
                Container container = controller.importFile(reader, importer);
                if (container != null) {
                  container.setSource(containerSource);
                  finishImport(container);
                }
              } catch (Exception ex) {
                throw new RuntimeException(ex);
              }
            }
          },
          taskName,
          errorHandler);
    } catch (Exception ex) {
      Logger.getLogger("").log(Level.WARNING, "", ex);
    }
  }
  @Override
  public void importFiles(FileObject[] fileObjects) {
    try {
      Map<ImporterUI, List<FileImporter>> importerUIs =
          new HashMap<ImporterUI, List<FileImporter>>();
      List<FileImporter> importers = new ArrayList<FileImporter>();
      for (FileObject fileObject : fileObjects) {
        FileImporter importer = controller.getFileImporter(FileUtil.toFile(fileObject));
        if (importer == null) {
          NotifyDescriptor.Message msg =
              new NotifyDescriptor.Message(
                  NbBundle.getMessage(
                      getClass(), "DesktopImportControllerUI.error_no_matching_file_importer"),
                  NotifyDescriptor.WARNING_MESSAGE);
          DialogDisplayer.getDefault().notify(msg);
          return;
        }
        importers.add(importer);
        ImporterUI ui = controller.getUI(importer);
        if (ui != null) {
          List<FileImporter> l = importerUIs.get(ui);
          if (l == null) {
            l = new ArrayList<FileImporter>();
            importerUIs.put(ui, l);
          }
          l.add(importer);
        }

        // MRU
        MostRecentFiles mostRecentFiles = Lookup.getDefault().lookup(MostRecentFiles.class);
        mostRecentFiles.addFile(fileObject.getPath());
      }

      for (Map.Entry<ImporterUI, List<FileImporter>> entry : importerUIs.entrySet()) {
        ImporterUI ui = entry.getKey();
        String title =
            NbBundle.getMessage(
                DesktopImportControllerUI.class,
                "DesktopImportControllerUI.file.ui.dialog.title",
                ui.getDisplayName());
        JPanel panel = ui.getPanel();
        ui.setup(entry.getValue().toArray(new FileImporter[0]));
        final DialogDescriptor dd = new DialogDescriptor(panel, title);
        if (panel instanceof ValidationPanel) {
          ValidationPanel vp = (ValidationPanel) panel;
          vp.addChangeListener(
              new ChangeListener() {
                @Override
                public void stateChanged(ChangeEvent e) {
                  dd.setValid(!((ValidationPanel) e.getSource()).isProblem());
                }
              });
        }

        Object result = DialogDisplayer.getDefault().notify(dd);
        if (!result.equals(NotifyDescriptor.OK_OPTION)) {
          ui.unsetup(false);
          return;
        }
        ui.unsetup(true);
      }

      final List<Container> result = new ArrayList<Container>();
      for (int i = 0; i < importers.size(); i++) {
        final FileImporter importer = importers.get(i);
        FileObject fileObject = fileObjects[i];
        LongTask task = null;
        if (importer instanceof LongTask) {
          task = (LongTask) importer;
        }

        // Execute task
        fileObject = getArchivedFile(fileObject);
        final String containerSource = fileObject.getNameExt();
        final InputStream stream = fileObject.getInputStream();
        String taskName =
            NbBundle.getMessage(
                DesktopImportControllerUI.class,
                "DesktopImportControllerUI.taskName",
                containerSource);
        executor.execute(
            task,
            new Runnable() {
              @Override
              public void run() {
                try {
                  Container container = controller.importFile(stream, importer);
                  if (container != null) {
                    container.setSource(containerSource);
                    result.add(container);
                  }
                } catch (Exception ex) {
                  throw new RuntimeException(ex);
                }
              }
            },
            taskName,
            errorHandler);
      }
      executor.execute(
          null,
          new Runnable() {

            @Override
            public void run() {
              if (!result.isEmpty()) {
                finishImport(result.toArray(new Container[0]));
              }
            }
          });
    } catch (Exception ex) {
      Logger.getLogger("").log(Level.WARNING, "", ex);
    }
  }