public MonitoredTask(SwingWorker task, String msg, Component parentComponent) {
   this.task = task;
   // create the progress monitor
   progressMonitor = new ModalProgressMonitor(parentComponent, msg, "", 0, 100);
   progressMonitor.setProgress(0);
   // add ProgressMonitorExample as a listener on CopyFiles;
   // of specific interest is the bound property progress
   task.addPropertyChangeListener(this);
 }
Ejemplo n.º 2
0
  /** パースした検査結果を登録する。 */
  private void addLabtest() {

    final List<NLaboImportSummary> modules = getTableModel().getDataProvider();

    final javax.swing.SwingWorker worker =
        new javax.swing.SwingWorker<Void, Void>() {

          @Override
          protected Void doInBackground() throws Exception {

            LaboDelegater laboDelegater = new LaboDelegater();

            for (NLaboImportSummary summary : modules) {

              PatientModel pm = laboDelegater.putNLaboModule(summary.getModule());

              if (pm != null) {
                summary.setPatient(pm);
                summary.setResult(SUCCESS);

              } else {
                summary.setResult(ERROR);
              }

              // Table 更新
              Runnable awt =
                  new Runnable() {
                    @Override
                    public void run() {
                      getTableModel().fireTableDataChanged();
                    }
                  };
              EventQueue.invokeLater(awt);
            }

            return null;
          }
        };

    worker.addPropertyChangeListener(
        new PropertyChangeListener() {

          @Override
          public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getNewValue().equals(javax.swing.SwingWorker.StateValue.STARTED)) {
              getProgressBar().setIndeterminate(true);
            } else if (evt.getNewValue().equals(javax.swing.SwingWorker.StateValue.DONE)) {
              getProgressBar().setIndeterminate(false);
              getProgressBar().setValue(0);
              worker.removePropertyChangeListener(this);
            }
          }
        });

    worker.execute();
  }
  public boolean start() {
    makeBusy(true);

    worker = new SwingWorkerImpl();
    worker.addPropertyChangeListener(
        new PropertyChangeListener() {
          @Override
          public void propertyChange(PropertyChangeEvent evt) {
            firePropertyChange(STATE_PROPERTY, null, worker.getState());
          }
        });
    worker.execute();
    return true;
  }
Ejemplo n.º 4
0
 void showProgressMonitor() {
   progressMonitor =
       new ProgressMonitor(DBSettings.this, "Building internal data ...", "", 0, 100);
   progressMonitor.setProgress(0);
   if (dbURL.matches("(?i:.*oracle.*)")) {
     task = QueryManager.instance().initFinder(QueryManager.SearchEngine.ORACLE, this);
   }
   if (dbURL.matches("(?i:.*mysql.*)")) {
     task = QueryManager.instance().initFinder(QueryManager.SearchEngine.MYSQL, this);
   }
   if (task != null) {
     task.addPropertyChangeListener(this);
     task.execute();
   }
 }
Ejemplo n.º 5
0
  /** Create the dialog. */
  public WaitDialog(
      String title, String text, SwingWorker task, JDialog parent, boolean taskHasProgress) {
    super(parent, true);
    addWindowListener(
        new WindowAdapter() {

          @Override
          public void windowOpened(WindowEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            task.execute();
          }
        });
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    setModal(true);
    setResizable(false);
    setTitle(title);
    setBounds(100, 100, 328, 85);

    getContentPane().setLayout(new MigLayout("", "[320.00px]", "[14px][14px]"));
    lblDownloadInCorso = new JLabel(text);
    lblDownloadInCorso.setHorizontalAlignment(SwingConstants.CENTER);
    getContentPane().add(lblDownloadInCorso, "cell 0 0,growx,aligny center");

    progressBar = new JProgressBar();
    progressBar.setIndeterminate(!taskHasProgress);
    getContentPane().add(progressBar, "cell 0 1,growx,aligny center");

    task.addPropertyChangeListener(
        new PropertyChangeListener() {

          @Override
          public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("progress")) {
              int progress = task.getProgress();
              progressBar.setValue(progress);
            } else if (evt.getPropertyName().equals("state"))
              if (evt.getNewValue().toString().equalsIgnoreCase("done")) WaitDialog.this.dispose();
          }
        });
  }
 /**
  * Binds the given uninstallation worker to this dialogue.
  *
  * <p>The dialogue is disposed once the worker finishes the uninstallation.
  *
  * @param worker the uninstallation worker
  */
 public void bind(SwingWorker<?, UninstallationProgressEvent> worker) {
   worker.addPropertyChangeListener(new WaitForDoneWorkerCloseListener());
 }
Ejemplo n.º 7
0
  /** 検査結果ファイルを選択し、パースする。 */
  private void selectAndParseLabFile() {

    // 検査結果ファイルを選択する
    JFileChooser chooser = new JFileChooser();
    FileNameExtensionFilter filter =
        new FileNameExtensionFilter(
            "Lab Result File", "DAT", "dat", "DAT2", "dat2", "HL7", "hl7", "TXT", "txt");
    chooser.setFileFilter(filter);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    int returnVal = chooser.showOpenDialog(getUI());

    if (returnVal != JFileChooser.APPROVE_OPTION) {
      return;
    }

    // パースしてテーブルへ表示する
    // 登録ボタンをアクティブにする
    final File labFile = new File(chooser.getSelectedFile().getPath());

    final javax.swing.SwingWorker worker =
        new javax.swing.SwingWorker<List<NLaboImportSummary>, Void>() {

          @Override
          protected List<NLaboImportSummary> doInBackground() throws Exception {

            LabResultParser parse = LabParserFactory.getParser(labFile.getName());

            List<NLaboImportSummary> dataList = parse.parse(labFile);

            if (dataList != null && dataList.size() > 0) {

              List<String> idList = new ArrayList<String>(dataList.size());
              for (NLaboImportSummary sm : dataList) {
                idList.add(sm.getPatientId());
              }

              LaboDelegater laboDelegater = new LaboDelegater();
              List<PatientLiteModel> pList = laboDelegater.getConstrainedPatients(idList);

              // for (int i = 0; i < pList.size(); i++) {
              for (int i = 0; i < dataList.size(); i++) {
                NLaboImportSummary sm = dataList.get(i);
                PatientLiteModel pl = pList.get(i);
                if (pl != null) {
                  sm.setKarteId(pl.getPatientId());
                  sm.setKarteBirthday(pl.getBirthday());
                  sm.setKarteKanaName(pl.getKanaName());
                  sm.setKarteName(pl.getFullName());
                  sm.setKarteSex(pl.getGenderDesc());
                }
              }
            }

            return dataList;
          }

          @Override
          protected void done() {

            try {
              List<NLaboImportSummary> allModules = get();
              getTableModel().setDataProvider(allModules);

            } catch (Throwable e) {
              e.printStackTrace(System.err);
              String why = e.getMessage();
              Window parent = SwingUtilities.getWindowAncestor(getUI());
              StringBuilder sb = new StringBuilder();
              sb.append("登録できないファイルがあります。").append("\n");
              sb.append("検査結果ファイルに誤りがある可能性があります。").append("\n");
              sb.append(why);
              String message = sb.toString();
              String title = "ラボレシーバ";
              JOptionPane.showMessageDialog(
                  parent, message, ClientContext.getFrameTitle(title), JOptionPane.WARNING_MESSAGE);
            }
          }
        };

    worker.addPropertyChangeListener(
        new PropertyChangeListener() {

          @Override
          public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getNewValue().equals(javax.swing.SwingWorker.StateValue.STARTED)) {
              getProgressBar().setIndeterminate(true);
            } else if (evt.getNewValue().equals(javax.swing.SwingWorker.StateValue.DONE)) {
              getProgressBar().setIndeterminate(false);
              getProgressBar().setValue(0);
              worker.removePropertyChangeListener(this);
            }
          }
        });

    worker.execute();
  }