Example usage for javax.swing SwingWorker SwingWorker

List of usage examples for javax.swing SwingWorker SwingWorker

Introduction

In this page you can find the example usage for javax.swing SwingWorker SwingWorker.

Prototype

public SwingWorker() 

Source Link

Document

Constructs this SwingWorker .

Usage

From source file:com.mirth.connect.client.ui.Frame.java

public void doEnableExtension() {
    final String workingId = startWorking("Enabling extension...");

    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
        private boolean success = true;

        public Void doInBackground() {
            try {
                mirthClient.setExtensionEnabled(extensionsPanel.getSelectedExtension().getName(), true);
            } catch (ClientException e) {
                success = false;//w w  w  .  j  a va 2s  .c o m
                alertThrowable(PlatformUI.MIRTH_FRAME, e);
            }

            return null;
        }

        public void done() {
            if (success) {
                extensionsPanel.setSelectedExtensionEnabled(true);
                extensionsPanel.setRestartRequired(true);
            }
            stopWorking(workingId);
        }
    };

    worker.execute();
}

From source file:com.mirth.connect.client.ui.Frame.java

public void doDisableExtension() {
    final String workingId = startWorking("Disabling extension...");

    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
        private boolean success = true;

        public Void doInBackground() {
            try {
                mirthClient.setExtensionEnabled(extensionsPanel.getSelectedExtension().getName(), false);
            } catch (ClientException e) {
                success = false;/*from w  w w .j  a  v a  2s  .com*/
                alertThrowable(PlatformUI.MIRTH_FRAME, e);
            }

            return null;
        }

        public void done() {
            if (success) {
                extensionsPanel.setSelectedExtensionEnabled(false);
                extensionsPanel.setRestartRequired(true);
            }
            stopWorking(workingId);
        }
    };

    worker.execute();
}

From source file:com.mirth.connect.client.ui.Frame.java

public void doUninstallExtension() {
    final String workingId = startWorking("Uninstalling extension...");

    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
        private boolean success = true;

        public Void doInBackground() {
            String packageName = extensionsPanel.getSelectedExtension().getPath();

            if (alertOkCancel(PlatformUI.MIRTH_FRAME,
                    "Uninstalling this extension will remove all plugins and/or connectors\nin the following extension folder: "
                            + packageName)) {
                try {
                    mirthClient.uninstallExtension(packageName);
                } catch (ClientException e) {
                    success = false;//w  w w  .  j  a  v a2s. com
                    alertThrowable(PlatformUI.MIRTH_FRAME, e);
                }
            }

            return null;
        }

        public void done() {
            if (success) {
                extensionsPanel.setRestartRequired(true);
            }
            stopWorking(workingId);
        }
    };

    worker.execute();
}

From source file:com.cch.aj.entryrecorder.frame.MainJFrame.java

private void btnReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReportActionPerformed
    BusyJFrame bf = new BusyJFrame();
    bf.setVisible(true);//  ww w .ja v a  2s  .c o m
    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {

        @Override
        protected Void doInBackground() throws Exception {
            try {

                final File batchFile = new File(AppHelper.currentDir + "\\pdfs\\genReport.bat");
                List cmd = new ArrayList();
                cmd.add(batchFile.getAbsolutePath());
                cmd.add("-f");
                cmd.add("PDF");
                cmd.add("-p");
                cmd.add("\"entryId=" + AppHelper.currentEntry.getId() + "\"");
                cmd.add("-o");
                final String pdfFileName = AppHelper.currentDir + "\\pdfs\\report_"
                        + AppHelper.currentEntry.getShift().replace(' ', '-') + "_"
                        + AppHelper.currentEntry.getMachineId().getMachineNo().replace(' ', '-') + "_"
                        + AppHelper.currentEntry.getProductId().getCode().replace(' ', '-') + "_"
                        + (new SimpleDateFormat("yyyyMMdd")).format(new Date()) + ".pdf";
                cmd.add("\"" + pdfFileName + "\"");
                cmd.add("-F");
                cmd.add("\"" + AppHelper.currentDir + "\\pdfs\\entry.rptdesign\"");

                ProcessBuilderWrapper pbd = new ProcessBuilderWrapper(
                        new File(AppHelper.currentDir + "\\pdfs\\"), cmd);
                System.out.println("Command has terminated with status: " + pbd.getStatus());
                System.out.println("Output:\n" + pbd.getInfos());
                System.out.println("Error: " + pbd.getErrors());

                //open
                File pdfFile = new File(pdfFileName);
                if (pdfFile.exists()) {

                    if (Desktop.isDesktopSupported()) {
                        Desktop.getDesktop().open(pdfFile);
                    } else {
                        System.out.println("Awt Desktop is not supported!");
                    }

                } else {
                    System.out.println("File is not exists!");
                }

                this.setProgress(100);

            } catch (Exception ex) {
                ex.printStackTrace();
            }
            return null;
        }

        @Override
        protected void done() {
            bf.setVisible(false);
        }
    };
    worker.execute();

}

From source file:edu.ku.brc.specify.dbsupport.SpecifySchemaUpdateService.java

/**
 * Changes all the contents of the Geography 'Name' field from the geonames 'name' to 'acsiiname' to 
 * get rid of the unprintable ascii characters.
 *//*www . j  a v  a 2 s . c o  m*/
public void updateGeographyNames() {
    final String FIXED_GEO = "FIXED.GEOGRAPHY";

    if (AppPreferences.getGlobalPrefs().getBoolean(FIXED_GEO, false)) {
        //return;
    }

    String sql = String.format(
            "SELECT COUNT(*) FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE TABLE_SCHEMA = '%s' AND TABLE_NAME = 'geoname'",
            DBConnection.getInstance().getDatabaseName());
    if (BasicSQLUtils.getCount(sql) == 0) {
        AppPreferences.getGlobalPrefs().putBoolean(FIXED_GEO, true);
        return;
    }

    final int numRecs = BasicSQLUtils.getCountAsInt(
            "SELECT COUNT(*) FROM geoname ge INNER JOIN geography g ON ge.name = g.Name WHERE ge.Name <> ge.asciiname");
    if (BasicSQLUtils.getCount(sql) == 0) {
        AppPreferences.getGlobalPrefs().putBoolean(FIXED_GEO, true);
        return;
    }

    final ProgressFrame prefProgFrame = new ProgressFrame(getResourceString("UPDATE_SCHEMA_TITLE"));
    prefProgFrame.adjustProgressFrame();
    prefProgFrame.getCloseBtn().setVisible(false);
    prefProgFrame.getProcessProgress().setIndeterminate(true);
    prefProgFrame.setDesc(UIRegistry.getLocalizedMessage("UPDATE_GEO"));
    UIHelper.centerAndShow(prefProgFrame);

    prefProgFrame.setProcess(0, 100);

    SwingWorker<Boolean, Boolean> worker = new SwingWorker<Boolean, Boolean>() {
        @Override
        protected Boolean doInBackground() throws Exception {
            Statement stmt = null;
            PreparedStatement pStmt = null;
            try {
                Connection currDBConn = DBConnection.getInstance().getConnection();

                pStmt = currDBConn.prepareStatement("UPDATE geography SET Name=? WHERE GeographyID=?");
                stmt = currDBConn.createStatement();

                int cnt = 0;
                String sqlStr = "SELECT ge.asciiname, g.GeographyID FROM geoname ge INNER JOIN geography g ON ge.name = g.Name WHERE ge.Name <> ge.asciiname";
                ResultSet rs = stmt.executeQuery(sqlStr);
                while (rs.next()) {
                    pStmt.setString(1, rs.getString(1));
                    pStmt.setInt(2, rs.getInt(2));
                    if (pStmt.executeUpdate() != 1) {

                    }

                    cnt++;
                    if (prefProgFrame != null && cnt % 100 == 0) {
                        setProgress((int) (cnt / numRecs * 100.0));
                    }
                }
                rs.close();

                if (prefProgFrame != null) {
                    prefProgFrame.setProcess(numRecs);
                }

                AppPreferences.getGlobalPrefs().putBoolean(FIXED_GEO, true);

            } catch (Exception ex) {
                ex.printStackTrace();
                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(BuildFromGeonames.class, ex);

            } finally {
                try {
                    if (stmt != null) {
                        stmt.close();
                    }
                    if (pStmt != null) {
                        pStmt.close();
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            return true;
        }

        /* (non-Javadoc)
         * @see javax.swing.SwingWorker#done()
         */
        @Override
        protected void done() {
            super.done();

            prefProgFrame.setVisible(false);
            prefProgFrame.dispose();
        }

    };

    worker.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(final PropertyChangeEvent evt) {
            if ("progress".equals(evt.getPropertyName())) {
                prefProgFrame.setProcess((Integer) evt.getNewValue());
            }
        }
    });
    worker.execute();
}

From source file:net.technicpack.launcher.ui.LauncherFrame.java

protected void pasteUpdated(Transferable transferable) {
    String text;//from   w ww .jav a 2 s. c  o  m

    if (!transferable.isDataFlavorSupported(DataFlavor.stringFlavor))
        return;

    try {
        text = transferable.getTransferData(DataFlavor.stringFlavor).toString();
    } catch (IOException ex) {
        Utils.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
        return;
    } catch (UnsupportedFlavorException ex) {
        Utils.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
        return;
    }

    try {
        final URL platformUrl = new URL(text);
        new SwingWorker<PlatformPackInfo, Void>() {
            @Override
            protected PlatformPackInfo doInBackground() throws Exception {
                PlatformPackInfo info = RestObject.getRestObject(PlatformPackInfo.class,
                        platformUrl.toString());

                //Don't let people jerk us around with non-platform sites- make sure this is a real pack
                //on the technic platform
                return platformApi.getPlatformPackInfo(info.getName());
            }

            @Override
            public void done() {
                PlatformPackInfo result;
                try {
                    result = get();

                    if (result == null)
                        return;
                } catch (ExecutionException ex) {
                    //We eat these two exceptions because they are almost certainly caused by
                    //the pasted text not being relevant to this program
                    return;
                } catch (InterruptedException ex) {
                    return;
                }

                if (!packRepo.getInstalledPacks().containsKey(result.getName())) {
                    packRepo.put(new InstalledPack(result.getName(), true, InstalledPack.RECOMMENDED));
                }

                packRepo.setSelectedSlug(result.getName());
                modpackSelector.forceRefresh();

                LauncherFrame.this.setExtendedState(JFrame.ICONIFIED);

                EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        LauncherFrame.this.setExtendedState(JFrame.NORMAL);
                        EventQueue.invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                LauncherFrame.this.selectTab("modpacks");
                            }
                        });
                    }
                });
            }
        }.execute();
    } catch (MalformedURLException ex) {
        return;
    }
}

From source file:nz.ac.waikato.cms.supernova.gui.Supernova.java

/**
 * Creates the panel for batch generation.
 *
 * @return      the panel//from  w w  w  .  j  a v  a2s.c  o  m
 */
protected BasePanel createBatchPanel() {
    BasePanel result;
    JPanel params;
    JPanel left1;
    JPanel left2;
    JPanel panel;

    result = new BasePanel(new BorderLayout());
    m_BatchLog = new JTextArea(20, 40);
    m_BatchLog.setFont(Font.decode("Monospaced-PLAIN-12"));
    result.add(new BaseScrollPane(m_BatchLog), BorderLayout.CENTER);

    left1 = new JPanel(new BorderLayout());
    result.add(left1, BorderLayout.WEST);

    // params with height 2
    params = new JPanel(new GridLayout(0, 1));
    left1.add(params, BorderLayout.NORTH);

    m_BatchColors = new ColorTable();
    left1.add(new BaseScrollPane(m_BatchColors), BorderLayout.NORTH);

    // params with height 1
    panel = new JPanel(new BorderLayout());
    left1.add(panel, BorderLayout.CENTER);
    left2 = new JPanel(new BorderLayout());
    panel.add(left2, BorderLayout.NORTH);
    params = new JPanel(new GridLayout(0, 1));
    left2.add(params, BorderLayout.NORTH);

    // background
    m_BatchBackground = new ColorButton(Color.BLACK);
    params.add(createParameter("Background", m_BatchBackground));

    // opacity
    m_BatchOpacity = new JSpinner();
    m_BatchOpacity.setValue(10);
    ((SpinnerNumberModel) m_BatchOpacity.getModel()).setMinimum(0);
    ((SpinnerNumberModel) m_BatchOpacity.getModel()).setMaximum(100);
    ((SpinnerNumberModel) m_BatchOpacity.getModel()).setStepSize(10);
    ((JSpinner.DefaultEditor) m_BatchOpacity.getEditor()).getTextField().setColumns(5);
    params.add(createParameter("Opacity %", m_BatchOpacity));

    // margin
    m_BatchMargin = new JSpinner();
    m_BatchMargin.setValue(20);
    ((SpinnerNumberModel) m_BatchMargin.getModel()).setMinimum(0);
    ((SpinnerNumberModel) m_BatchMargin.getModel()).setMaximum(100);
    ((SpinnerNumberModel) m_BatchMargin.getModel()).setStepSize(10);
    ((JSpinner.DefaultEditor) m_BatchMargin.getEditor()).getTextField().setColumns(5);
    params.add(createParameter("Margin %", m_BatchMargin));

    // width
    m_BatchWidth = new JSpinner();
    m_BatchWidth.setValue(400);
    ((SpinnerNumberModel) m_BatchWidth.getModel()).setMinimum(1);
    ((SpinnerNumberModel) m_BatchWidth.getModel()).setStepSize(100);
    ((JSpinner.DefaultEditor) m_BatchWidth.getEditor()).getTextField().setColumns(5);
    params.add(createParameter("Width", m_BatchWidth));

    // height
    m_BatchHeight = new JSpinner();
    m_BatchHeight.setValue(400);
    ((SpinnerNumberModel) m_BatchHeight.getModel()).setMinimum(1);
    ((SpinnerNumberModel) m_BatchHeight.getModel()).setStepSize(100);
    ((JSpinner.DefaultEditor) m_BatchHeight.getEditor()).getTextField().setColumns(5);
    params.add(createParameter("Height", m_BatchHeight));

    // generator
    m_BatchGenerator = new JComboBox<>(Registry.toStringArray(Registry.getGenerators(), true));
    params.add(createParameter("Generator", m_BatchGenerator));

    // center
    m_BatchCenter = new JComboBox<>(Registry.toStringArray(Registry.getCenters(), true));
    params.add(createParameter("Center", m_BatchCenter));

    // csv
    m_BatchCSV = new FileChooserPanel();
    m_BatchCSV.addChoosableFileFilter(new ExtensionFileFilter("CSV files", "csv"));
    m_BatchCSV.setPreferredSize(new Dimension(170, (int) m_BatchCSV.getPreferredSize().getHeight()));
    params.add(createParameter("CSV", m_BatchCSV));

    // output
    m_BatchOutput = new DirectoryChooserPanel();
    m_BatchOutput.setPreferredSize(new Dimension(170, (int) m_BatchOutput.getPreferredSize().getHeight()));
    params.add(createParameter("Output", m_BatchOutput));

    // generate
    panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    m_BatchGenerate = new JButton("Generate");
    m_BatchGenerate.addActionListener((ActionEvent e) -> {
        SwingWorker worker = new SwingWorker() {
            @Override
            protected Object doInBackground() throws Exception {
                generateBatchOutput();
                return null;
            }
        };
        worker.execute();
    });
    panel.add(m_BatchGenerate);
    params.add(panel);

    adjustLabels();

    return result;
}

From source file:op.allowance.PnlAllowance.java

private void reloadDisplay() {
    /***/*from www .j  a v  a2 s .  com*/
     *               _                 _ ____  _           _
     *      _ __ ___| | ___   __ _  __| |  _ \(_)___ _ __ | | __ _ _   _
     *     | '__/ _ \ |/ _ \ / _` |/ _` | | | | / __| '_ \| |/ _` | | | |
     *     | | |  __/ | (_) | (_| | (_| | |_| | \__ \ |_) | | (_| | |_| |
     *     |_|  \___|_|\___/ \__,_|\__,_|____/|_|___/ .__/|_|\__,_|\__, |
     *                                              |_|            |___/
     */

    final boolean withworker = false;
    cpsCash.removeAll();
    cashmap.clear();
    cpMap.clear();
    contentmap.clear();
    carrySums.clear();
    minmax.clear();

    if (withworker) {

        OPDE.getMainframe().setBlocked(true);
        OPDE.getDisplayManager()
                .setProgressBarMessage(new DisplayMessage(SYSTools.xx("misc.msg.wait"), -1, 100));

        SwingWorker worker = new SwingWorker() {

            @Override
            protected Object doInBackground() throws Exception {
                int progress = 0;
                OPDE.getDisplayManager().setProgressBarMessage(
                        new DisplayMessage(SYSTools.xx("misc.msg.wait"), progress, lstResidents.size()));

                for (Resident resident : lstResidents) {
                    progress++;
                    createCP4(resident);
                    OPDE.getDisplayManager().setProgressBarMessage(
                            new DisplayMessage(SYSTools.xx("misc.msg.wait"), progress, lstResidents.size()));
                }
                return null;
            }

            @Override
            protected void done() {
                OPDE.getDisplayManager().setMainMessage(SYSTools.xx(internalClassID));
                buildPanel();
                OPDE.getDisplayManager().setProgressBarMessage(null);
                OPDE.getMainframe().setBlocked(false);
            }
        };
        worker.execute();

    } else {

        for (Resident resident : lstResidents) {
            createCP4(resident);
        }

        OPDE.getDisplayManager().setMainMessage(SYSTools.xx(internalClassID));

        //            if (currentResident != null) {
        //                OPDE.getDisplayManager().setMainMessage(ResidentTools.getLabelText(currentResident));
        //            } else {
        //                OPDE.getDisplayManager().setMainMessage(SYSTools.xx(internalClassID));
        //            }
        buildPanel();
    }

}

From source file:op.care.bhp.PnlBHP.java

private void reloadDisplay() {
    /***//from ww w.  j a va2 s .  c o  m
     *               _                 _ ____  _           _
     *      _ __ ___| | ___   __ _  __| |  _ \(_)___ _ __ | | __ _ _   _
     *     | '__/ _ \ |/ _ \ / _` |/ _` | | | | / __| '_ \| |/ _` | | | |
     *     | | |  __/ | (_) | (_| | (_| | |_| | \__ \ |_) | | (_| | |_| |
     *     |_|  \___|_|\___/ \__,_|\__,_|____/|_|___/ .__/|_|\__,_|\__, |
     *                                              |_|            |___/
     */
    initPhase = true;

    final boolean withworker = true;
    if (withworker) {

        OPDE.getMainframe().setBlocked(true);
        OPDE.getDisplayManager()
                .setProgressBarMessage(new DisplayMessage(SYSTools.xx("misc.msg.wait"), -1, 100));

        synchronized (mapPrescription2Stock) {
            SYSTools.clear(mapPrescription2Stock);
        }
        synchronized (mapBHP2Pane) {
            SYSTools.clear(mapBHP2Pane);
        }

        synchronized (mapShift2BHP) {
            if (mapShift2BHP != null) {
                for (Byte key : mapShift2BHP.keySet()) {
                    mapShift2BHP.get(key).clear();
                }
                mapShift2BHP.clear();
            }
        }
        synchronized (mapShift2Pane) {
            if (mapShift2Pane != null) {
                for (Byte key : mapShift2Pane.keySet()) {
                    mapShift2Pane.get(key).removeAll();
                }
                mapShift2Pane.clear();
            }
        }

        SwingWorker worker = new SwingWorker() {

            @Override
            protected Object doInBackground() throws Exception {

                try {

                    int progress = 0;
                    OPDE.getDisplayManager()
                            .setProgressBarMessage(new DisplayMessage(SYSTools.xx("misc.msg.wait"), -1, 100));

                    synchronized (mapShift2BHP) {
                        for (BHP bhp : BHPTools.getBHPs(resident, jdcDatum.getDate())) {
                            if (!mapShift2BHP.containsKey(bhp.getShift())) {
                                mapShift2BHP.put(bhp.getShift(), new ArrayList<BHP>());
                            }
                            mapShift2BHP.get(bhp.getShift()).add(bhp);
                        }

                        if (!mapShift2BHP.containsKey(BHPTools.SHIFT_ON_DEMAND)) {
                            mapShift2BHP.put(BHPTools.SHIFT_ON_DEMAND, new ArrayList<BHP>());
                        }
                        mapShift2BHP.get(BHPTools.SHIFT_ON_DEMAND)
                                .addAll(BHPTools.getBHPsOnDemand(resident, jdcDatum.getDate()));
                        if (!mapShift2BHP.containsKey(BHPTools.SHIFT_OUTCOMES)) {
                            mapShift2BHP.put(BHPTools.SHIFT_OUTCOMES, new ArrayList<BHP>());
                        }
                        mapShift2BHP.get(BHPTools.SHIFT_OUTCOMES)
                                .addAll(BHPTools.getOutcomeBHPs(resident, new LocalDate(jdcDatum.getDate())));
                    }

                    synchronized (mapShift2Pane) {
                        for (Byte shift : new Byte[] { BHPTools.SHIFT_ON_DEMAND, BHPTools.SHIFT_OUTCOMES,
                                BHPTools.SHIFT_VERY_EARLY, BHPTools.SHIFT_EARLY, BHPTools.SHIFT_LATE,
                                BHPTools.SHIFT_VERY_LATE }) {
                            mapShift2Pane.put(shift, createCP4(shift));
                            try {
                                mapShift2Pane.get(shift)
                                        .setCollapsed(shift == BHPTools.SHIFT_ON_DEMAND
                                                || shift == BHPTools.SHIFT_OUTCOMES
                                                || shift != SYSCalendar.whatShiftIs(new Date()));
                            } catch (PropertyVetoException e) {
                                OPDE.debug(e);
                            }
                            progress += 20;
                            OPDE.getDisplayManager().setProgressBarMessage(
                                    new DisplayMessage(SYSTools.xx("misc.msg.wait"), progress, 100));
                        }
                    }
                } catch (Exception exc) {
                    OPDE.fatal(exc);
                }

                return null;
            }

            @Override
            protected void done() {
                buildPanel(true);
                initPhase = false;
                OPDE.getDisplayManager().setProgressBarMessage(null);
                OPDE.getMainframe().setBlocked(false);
            }
        };
        worker.execute();

    } else {

        mapBHP2Pane.clear();
        if (mapShift2BHP != null) {
            for (Byte key : mapShift2BHP.keySet()) {
                mapShift2BHP.get(key).clear();
            }
            mapShift2BHP.clear();
        }
        if (mapShift2Pane != null) {
            for (Byte key : mapShift2Pane.keySet()) {
                mapShift2Pane.get(key).removeAll();
            }
            mapShift2Pane.clear();
        }

        for (BHP bhp : BHPTools.getBHPs(resident, jdcDatum.getDate())) {
            if (!mapShift2BHP.containsKey(bhp.getShift())) {
                mapShift2BHP.put(bhp.getShift(), new ArrayList<BHP>());
            }
            mapShift2BHP.get(bhp.getShift()).add(bhp);
        }

        if (!mapShift2BHP.containsKey(BHPTools.SHIFT_ON_DEMAND)) {
            mapShift2BHP.put(BHPTools.SHIFT_ON_DEMAND, new ArrayList<BHP>());
        }
        mapShift2BHP.get(BHPTools.SHIFT_ON_DEMAND)
                .addAll(BHPTools.getBHPsOnDemand(resident, jdcDatum.getDate()));
        if (!mapShift2BHP.containsKey(BHPTools.SHIFT_OUTCOMES)) {
            mapShift2BHP.put(BHPTools.SHIFT_OUTCOMES, new ArrayList<BHP>());
        }
        mapShift2BHP.get(BHPTools.SHIFT_OUTCOMES)
                .addAll(BHPTools.getOutcomeBHPs(resident, new LocalDate(jdcDatum.getDate())));

        for (Byte shift : new Byte[] { BHPTools.SHIFT_ON_DEMAND, BHPTools.SHIFT_OUTCOMES,
                BHPTools.SHIFT_VERY_EARLY, BHPTools.SHIFT_EARLY, BHPTools.SHIFT_LATE,
                BHPTools.SHIFT_VERY_LATE }) {
            mapShift2Pane.put(shift, createCP4(shift));
            try {
                mapShift2Pane.get(shift).setCollapsed(shift == BHPTools.SHIFT_ON_DEMAND
                        || shift == BHPTools.SHIFT_OUTCOMES || shift != SYSCalendar.whatShiftIs(new Date()));
            } catch (PropertyVetoException e) {
                OPDE.debug(e);
            }
        }

        buildPanel(true);

    }
    initPhase = false;
}

From source file:op.care.dfn.PnlDFN.java

private void reloadDisplay() {
    /***/* w  w w.j ava 2s  . c om*/
     *               _                 _ ____  _           _
     *      _ __ ___| | ___   __ _  __| |  _ \(_)___ _ __ | | __ _ _   _
     *     | '__/ _ \ |/ _ \ / _` |/ _` | | | | / __| '_ \| |/ _` | | | |
     *     | | |  __/ | (_) | (_| | (_| | |_| | \__ \ |_) | | (_| | |_| |
     *     |_|  \___|_|\___/ \__,_|\__,_|____/|_|___/ .__/|_|\__,_|\__, |
     *                                              |_|            |___/
     */
    initPhase = true;
    synchronized (mapDFN2Pane) {
        SYSTools.clear(mapDFN2Pane);
    }

    synchronized (mapShift2DFN) {
        for (Byte key : mapShift2DFN.keySet()) {
            mapShift2DFN.get(key).clear();
        }
    }

    synchronized (mapShift2Pane) {
        for (Byte key : mapShift2Pane.keySet()) {
            mapShift2Pane.get(key).removeAll();
        }
        mapShift2Pane.clear();
    }

    final boolean withworker = true;
    if (withworker) {

        OPDE.getMainframe().setBlocked(true);
        OPDE.getDisplayManager()
                .setProgressBarMessage(new DisplayMessage(SYSTools.xx("misc.msg.wait"), -1, 100));

        cpDFN.removeAll();

        SwingWorker worker = new SwingWorker() {

            @Override
            protected Object doInBackground() throws Exception {

                int progress = 0;
                OPDE.getDisplayManager()
                        .setProgressBarMessage(new DisplayMessage(SYSTools.xx("misc.msg.wait"), progress, 100));

                ArrayList<DFN> listDFNs = DFNTools.getDFNs(resident, jdcDate.getDate());

                synchronized (mapShift2DFN) {
                    for (DFN dfn : listDFNs) {
                        mapShift2DFN.get(dfn.getShift()).add(dfn);
                    }
                }

                // now build the CollapsiblePanes
                for (Byte shift : new Byte[] { DFNTools.SHIFT_ON_DEMAND, DFNTools.SHIFT_VERY_EARLY,
                        DFNTools.SHIFT_EARLY, DFNTools.SHIFT_LATE, DFNTools.SHIFT_VERY_LATE }) {
                    CollapsiblePane cp = createCP4(shift);
                    synchronized (mapShift2Pane) {
                        mapShift2Pane.put(shift, cp);
                        try {
                            mapShift2Pane.get(shift).setCollapsed(shift == DFNTools.SHIFT_ON_DEMAND
                                    || shift != SYSCalendar.whatShiftIs(new Date()));
                        } catch (PropertyVetoException e) {
                            OPDE.debug(e);
                        }
                        progress += 20;
                        OPDE.getDisplayManager().setProgressBarMessage(
                                new DisplayMessage(SYSTools.xx("misc.msg.wait"), progress, 100));
                    }
                }
                return null;
            }

            @Override
            protected void done() {
                buildPanel(true);
                initPhase = false;
                OPDE.getDisplayManager().setProgressBarMessage(null);
                OPDE.getMainframe().setBlocked(false);
                OPDE.getDisplayManager().addSubMessage(
                        new DisplayMessage(DateFormat.getDateInstance().format(jdcDate.getDate())));
            }
        };
        worker.execute();

    } else {
        //           buildPanel(true);
    }
    initPhase = false;
}