コード例 #1
0
 private ProcessorUI getProcessorUI(Processor processor) {
   for (ProcessorUI pui : Lookup.getDefault().lookupAll(ProcessorUI.class)) {
     if (pui.isUIFoProcessor(processor)) {
       return pui;
     }
   }
   return null;
 }
コード例 #2
0
  private void finishImport(Container[] containers) {
    Report finalReport = new Report();
    for (Container container : containers) {
      if (container.verify()) {
        Report report = container.getReport();
        report.close();
        finalReport.append(report);
      } else {
        // TODO
      }
    }
    finalReport.close();

    // Report panel
    ReportPanel reportPanel = new ReportPanel();
    reportPanel.setData(finalReport, containers);
    DialogDescriptor dd =
        new DialogDescriptor(
            reportPanel, NbBundle.getMessage(DesktopImportControllerUI.class, "ReportPanel.title"));
    Object response = DialogDisplayer.getDefault().notify(dd);
    reportPanel.destroy();
    finalReport.clean();
    for (Container c : containers) {
      c.getReport().clean();
    }
    if (!response.equals(NotifyDescriptor.OK_OPTION)) {
      return;
    }
    final Processor processor = reportPanel.getProcessor();

    // Project
    Workspace workspace = null;
    ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
    ProjectControllerUI pcui = Lookup.getDefault().lookup(ProjectControllerUI.class);
    if (pc.getCurrentProject() == null) {
      pcui.newProject();
      workspace = pc.getCurrentWorkspace();
    }

    // Process
    final ProcessorUI pui = getProcessorUI(processor);
    final ValidResult validResult = new ValidResult();
    if (pui != null) {
      try {
        final JPanel panel = pui.getPanel();
        if (panel != null) {
          SwingUtilities.invokeAndWait(
              new Runnable() {
                @Override
                public void run() {
                  String title =
                      NbBundle.getMessage(
                          DesktopImportControllerUI.class,
                          "DesktopImportControllerUI.processor.ui.dialog.title");

                  pui.setup(processor);
                  final DialogDescriptor dd2 = new DialogDescriptor(panel, title);
                  if (panel instanceof ValidationPanel) {
                    ValidationPanel vp = (ValidationPanel) panel;
                    vp.addChangeListener(
                        new ChangeListener() {
                          @Override
                          public void stateChanged(ChangeEvent e) {
                            dd2.setValid(!((ValidationPanel) e.getSource()).isProblem());
                          }
                        });
                    dd2.setValid(!vp.isProblem());
                  }
                  Object result = DialogDisplayer.getDefault().notify(dd2);
                  if (result.equals(NotifyDescriptor.CANCEL_OPTION)
                      || result.equals(NotifyDescriptor.CLOSED_OPTION)) {
                    validResult.setResult(false);
                  } else {
                    pui.unsetup(); // true
                    validResult.setResult(true);
                  }
                }
              });
        }
      } catch (InterruptedException ex) {
        Exceptions.printStackTrace(ex);
      } catch (InvocationTargetException ex) {
        Exceptions.printStackTrace(ex);
      }
    }
    if (validResult.isResult()) {
      controller.process(containers, processor, workspace);

      // StatusLine notify
      StatusDisplayer.getDefault()
          .setStatusText(
              NbBundle.getMessage(
                  DesktopImportControllerUI.class,
                  "DesktopImportControllerUI.status.multiImportSuccess",
                  containers.length));
    }
  }