Example usage for java.awt Cursor WAIT_CURSOR

List of usage examples for java.awt Cursor WAIT_CURSOR

Introduction

In this page you can find the example usage for java.awt Cursor WAIT_CURSOR.

Prototype

int WAIT_CURSOR

To view the source code for java.awt Cursor WAIT_CURSOR.

Click Source Link

Document

The wait cursor type.

Usage

From source file:org.javaswift.cloudie.CloudiePanel.java

@Override
public void onStart() {
    if (busyCnt == 0) {
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        statusPanel.onStart();//from w  w  w. ja  v  a  2 s .  co  m
    }
    busyCnt++;
}

From source file:uk.ac.ucl.cs.cmic.giftcloud.uploadapp.ConfigurationDialog.java

private void applyProperties() {

    // Extract out all the new values (this makes the code a little clearer below)
    final int newListeningPortValue = Integer.parseInt(listeningPortField.getText());
    final String newListeningAeTitle = listeningAETitleField.getText();
    final String newGiftCloudUrl = giftCloudServerText.getText();
    final String newGiftCloudUserName = giftCloudUsernameText.getText();
    final char[] newGiftCloudPassword = giftCloudPasswordText.getPassword();
    final char[] newPatientListPassword = patientListSpreadsheetPasswordField.getPassword();
    final String newPatientListExportFolder = patientListExportFolderField.getText();
    final String newSubjectPrefix = subjectPrefixField.getText();
    final int newPacsPort = Integer.parseInt(remoteAEPortField.getText());
    final String newPacsAeTitle = remoteAETitleField.getText();
    final String newPacsHostName = remoteAEHostName.getText();

    // Determine whether to restart the listener service based on changes to the listener or PACS properties
    final boolean restartDicomNode = giftCloudProperties.getListeningPort() != newListeningPortValue
            || !newListeningAeTitle.equals(giftCloudProperties.getListenerAETitle())
            || giftCloudProperties.getPacsPort() != newPacsPort
            || !newPacsAeTitle.equals(giftCloudProperties.getPacsAeTitle().orElse(""))
            || !newPacsHostName.equals(giftCloudProperties.getPacsHostName().orElse(""));

    final boolean restartUploader = !newGiftCloudUrl.equals(giftCloudProperties.getGiftCloudUrl().orElse(""))
            || !newGiftCloudUserName.equals(giftCloudProperties.getLastUserName().orElse(""))
            || !newGiftCloudPassword.equals(giftCloudProperties.getLastPassword().orElse("".toCharArray()))
            || !temporaryDropDownListModel.getSelectedItem().equals(projectListModel.getSelectedItem());

    final boolean forcePatientListExport = StringUtils.isNotBlank(newPatientListExportFolder)
            && (!giftCloudProperties.getPatientListExportFolder().isPresent()
                    || !newPatientListExportFolder
                            .equals(giftCloudProperties.getPatientListExportFolder().get())
                    || !newPatientListPassword
                            .equals(giftCloudProperties.getPatientListPassword().orElse("".toCharArray())));

    // Change the properties (must be done after we access the current values to check for changes)
    giftCloudProperties.setListeningPort(newListeningPortValue);
    giftCloudProperties.setListenerAETitle(newListeningAeTitle);
    giftCloudProperties.setPatientListExportFolder(newPatientListExportFolder);
    giftCloudProperties.setGiftCloudUrl(newGiftCloudUrl);
    giftCloudProperties.setLastUserName(newGiftCloudUserName);
    giftCloudProperties.setLastPassword(newGiftCloudPassword);
    giftCloudProperties.setPatientListPassword(newPatientListPassword);
    giftCloudProperties.setSubjectPrefix(newSubjectPrefix);
    giftCloudProperties.setPacsPort(newPacsPort);
    giftCloudProperties.setPacsAeTitle(newPacsAeTitle);
    giftCloudProperties.setPacsHostName(newPacsHostName);

    // We only update the last project with a valid value. A null value may indicate the project list hasn't been
    // set because the server login details are incorrect or some communication error
    final Object selectedProjectItem = temporaryDropDownListModel.getSelectedItem();
    if (selectedProjectItem instanceof String) {
        final String newProject = (String) selectedProjectItem;
        if (StringUtils.isNotBlank(newProject)) {
            giftCloudProperties.setLastProject(newProject);
        }/*from  www  .jav  a 2  s  .  c  o m*/
    }

    giftCloudProperties.save();

    if (restartDicomNode || restartUploader || forcePatientListExport) {
        Cursor was = dialog.getCursor();
        dialog.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

        if (restartDicomNode) {
            controller.restartDicomService();
        }
        if (restartUploader) {
            controller.invalidateServerAndRestartUploader();
        }
        if (forcePatientListExport) {
            controller.exportPatientList(false);
        }

        dialog.setCursor(was);
    }

}

From source file:com.ixora.rms.ui.RMSFrame.java

/**
 * Compares two logs./*from www.j  ava 2 s  . co  m*/
 */
private void handleCompareLogs() {
    try {
        if (resetCurrentView()) {
            return;
        }
        DataLogCompareAndReplayConfigurationDialog dlg = new DataLogCompareAndReplayConfigurationDialog(this);
        fCurrentView = new LogPlaybackView(RMSFrame.this, RMS.getDataLogReplay(), dlg.getScanningService());
        UIUtils.centerDialogAndShow(this, dlg);
        DataLogCompareAndReplayConfiguration conf = dlg.getResult();
        if (conf != null) {
            try {
                ((LogPlaybackView) fCurrentView).setReplayConfiguration(conf);
                getAppWorker().runJobSynch(new UIWorkerJobDefault(this, Cursor.WAIT_CURSOR,
                        MessageRepository.get(Msg.TEXT_LOADING_LOG_VIEW)) {
                    public void finished(Throwable ex) throws Throwable {
                        if (ex != null) {
                            resetCurrentView();
                        }
                    }

                    public void work() throws Throwable {
                        fCurrentView.initialize();
                    }
                });
            } catch (Throwable e) {
                resetCurrentView();
                UIExceptionMgr.userException(e);
            }
        }
    } catch (Exception e) {
        UIExceptionMgr.userException(e);
    }
}

From source file:com.signalcollect.sna.visualization.SignalCollectSNATopComponent.java

/**
 * Gets and visualizes the chart of the Local Cluster Coefficient
 * Distribution/*ww  w .  jav  a2  s  .  com*/
 *
 * @param evt
 */
private void clusterDistributionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clusterDistributionButtonActionPerformed

    try {
        mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        if (jTextArea1.getText() == null) {
            throw new IllegalArgumentException("No file was chosen!\nPlease choose a valid .gml file");
        }
        if (!jTextArea1.getText().contains(".gml")) {
            throw new IllegalArgumentException(
                    "The chosen file doesn't have the right format!\nPlease choose a valid .gml file");
        }
        distributionFrame.setVisible(false);
        distributionFrame = new JFrame();

        scgc = new LocalClusterCoefficientSignalCollectGephiConnectorImpl(fileName);
        JFreeChart chart = scgc.createClusterDistributionChart(scgc.getClusterDistribution());
        ChartPanel chartPanel = new ChartPanel(chart);
        Dimension dim = new Dimension(750, 450);
        distributionFrame.setMinimumSize(dim);
        chartPanel.setVisible(true);
        chartPanel.validate();

        distributionFrame.add(chartPanel);

        distributionFrame.pack();
        distributionFrame.setVisible(true);
    } catch (IllegalArgumentException exception) {

        messageFrame = new JFrame();
        JOptionPane.showMessageDialog(messageFrame, exception.getMessage(), "Signal/Collect Error",
                JOptionPane.ERROR_MESSAGE);

    } catch (Exception exception) {
        messageFrame = new JFrame();
        exception.printStackTrace();
        JOptionPane.showMessageDialog(messageFrame,
                "Technical exception happened (" + exception.getCause() + ")", "Signal/Collect Error",
                JOptionPane.ERROR_MESSAGE);
    } finally {
        mainPanel.setCursor(Cursor.getDefaultCursor());
    }
}

From source file:au.com.jwatmuff.eventmanager.gui.main.MainWindow.java

private void manualAddPeerMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_manualAddPeerMenuItemActionPerformed
    String hostname = JOptionPane
            .showInputDialog("Enter an IP Address, Host or Computer Name on which EventManager is running.");

    if (!StringUtils.isBlank(hostname)) {
        try {//from  ww w  .j  a v a 2 s .  c  o m
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            InetAddress.getByName(hostname);
            GUIUtils.displayMessage(null, "The computer '" + hostname
                    + "' was successfully added.\nIf EventManager is able to connect to this computer, it will appear under the chat user list shortly",
                    "Computer added");
            manuallyAddHost(hostname);
        } catch (UnknownHostException e) {
            GUIUtils.displayError(null,
                    "EventManager was unable to identify any computer named '" + hostname + "' (Unknown host)");
        } finally {
            setCursor(Cursor.getDefaultCursor());
        }
    }
}

From source file:de.bfs.radon.omsimulation.gui.OMPanelResults.java

/**
 * Initialises the interface of the results panel.
 */// ww  w.  ja  v  a 2s  .  co m
protected void initialize() {
    setLayout(null);

    lblExportChartTo = new JLabel("Export chart to ...");
    lblExportChartTo.setBounds(436, 479, 144, 14);
    lblExportChartTo.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    lblExportChartTo.setVisible(false);
    add(lblExportChartTo);

    btnMaximize = new JButton("Fullscreen");
    btnMaximize.setBounds(10, 475, 124, 23);
    btnMaximize.setFont(new Font("SansSerif", Font.PLAIN, 11));
    btnMaximize.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (comboBoxSimulations.isEnabled()) {
                if (comboBoxSimulations.getSelectedItem() != null) {
                    JFrame chartFrame = new JFrame();
                    OMSimulation simulation = (OMSimulation) comboBoxSimulations.getSelectedItem();
                    String title = simulation.toString();
                    DescriptiveStatistics statistics = null;
                    OMStatistics statisticsType = (OMStatistics) comboBoxStatistics.getSelectedItem();
                    OMRoomType roomType = null;
                    switch (statisticsType) {
                    case RoomArithmeticMeans:
                        title = "R_AM, " + title;
                        statistics = simulation.getRoomAmDescriptiveStats();
                        roomType = OMRoomType.Room;
                        break;
                    case RoomGeometricMeans:
                        title = "R_GM, " + title;
                        statistics = simulation.getRoomGmDescriptiveStats();
                        roomType = OMRoomType.Room;
                        break;
                    case RoomMedianQ50:
                        title = "R_MED, " + title;
                        statistics = simulation.getRoomMedDescriptiveStats();
                        roomType = OMRoomType.Room;
                        break;
                    case RoomMaxima:
                        title = "R_MAX, " + title;
                        statistics = simulation.getRoomMaxDescriptiveStats();
                        roomType = OMRoomType.Room;
                        break;
                    case CellarArithmeticMeans:
                        title = "C_AM, " + title;
                        statistics = simulation.getCellarAmDescriptiveStats();
                        roomType = OMRoomType.Cellar;
                        break;
                    case CellarGeometricMeans:
                        title = "C_GM, " + title;
                        statistics = simulation.getCellarGmDescriptiveStats();
                        roomType = OMRoomType.Cellar;
                        break;
                    case CellarMedianQ50:
                        title = "C_MED, " + title;
                        statistics = simulation.getCellarMedDescriptiveStats();
                        roomType = OMRoomType.Cellar;
                        break;
                    case CellarMaxima:
                        title = "C_MAX, " + title;
                        statistics = simulation.getCellarMaxDescriptiveStats();
                        roomType = OMRoomType.Cellar;
                        break;
                    default:
                        title = "R_AM, " + title;
                        statistics = simulation.getRoomAmDescriptiveStats();
                        roomType = OMRoomType.Misc;
                        break;
                    }
                    JPanel chartPanel = createDistributionPanel(title, statistics, roomType, false, true, true);
                    chartFrame.getContentPane().add(chartPanel);
                    chartFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
                    chartFrame.setBounds(0, 0, (int) dim.getWidth(), (int) dim.getHeight());
                    chartFrame.setTitle("OM Simulation Tool: " + title);
                    chartFrame.setResizable(true);
                    chartFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
                    chartFrame.setVisible(true);
                }
            }
        }
    });
    add(btnMaximize);

    btnCsv = new JButton("CSV");
    btnCsv.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileDialog = new JFileChooser();
            fileDialog.setFileFilter(new FileNameExtensionFilter("*.csv", "csv"));
            fileDialog.showSaveDialog(getParent());
            final File file = fileDialog.getSelectedFile();
            if (file != null) {
                String csv;
                String[] tmpFileName = file.getAbsolutePath().split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("csv")) {
                    csv = "";
                } else {
                    csv = ".csv";
                }
                String csvPath = file.getAbsolutePath() + csv;
                OMSimulation simulation = (OMSimulation) comboBoxSimulations.getSelectedItem();
                OMCampaign[] campaigns = simulation.getCampaigns();
                File csvFile = new File(csvPath);
                try {
                    FileWriter logWriter = new FileWriter(csvFile);
                    BufferedWriter csvOutput = new BufferedWriter(logWriter);
                    OMStatistics statisticsType = (OMStatistics) comboBoxStatistics.getSelectedItem();
                    String head = "";
                    switch (statisticsType) {
                    case RoomArithmeticMeans:
                        head = "R_AM";
                        break;
                    case RoomGeometricMeans:
                        head = "R_GM";
                        break;
                    case RoomMedianQ50:
                        head = "R_MED";
                        break;
                    case RoomMaxima:
                        head = "R_MAX";
                        break;
                    case CellarArithmeticMeans:
                        head = "C_AM";
                        break;
                    case CellarGeometricMeans:
                        head = "C_GM";
                        break;
                    case CellarMedianQ50:
                        head = "C_MED";
                        break;
                    case CellarMaxima:
                        head = "C_MAX";
                        break;
                    default:
                        head = "R_AM";
                        break;
                    }
                    csvOutput.write("\"ID\";\"CAMPAIGN\";\"START\";\"" + head + "\"");
                    csvOutput.newLine();
                    int value = 0;
                    for (int i = 0; i < campaigns.length; i++) {
                        switch (statisticsType) {
                        case RoomArithmeticMeans:
                            value = (int) campaigns[i].getRoomAverage();
                            break;
                        case RoomGeometricMeans:
                            value = (int) campaigns[i].getRoomLogAverage();
                            break;
                        case RoomMedianQ50:
                            value = (int) campaigns[i].getRoomMedian();
                            break;
                        case RoomMaxima:
                            value = (int) campaigns[i].getRoomMaximum();
                            break;
                        case CellarArithmeticMeans:
                            value = (int) campaigns[i].getCellarAverage();
                            break;
                        case CellarGeometricMeans:
                            value = (int) campaigns[i].getCellarLogAverage();
                            break;
                        case CellarMedianQ50:
                            value = (int) campaigns[i].getCellarMedian();
                            break;
                        case CellarMaxima:
                            value = (int) campaigns[i].getCellarMaximum();
                            break;
                        default:
                            value = (int) campaigns[i].getRoomAverage();
                            break;
                        }
                        csvOutput.write("\"" + i + "\";\"" + campaigns[i].getVariation() + "\";\""
                                + campaigns[i].getStart() + "\";\"" + value + "\"");
                        csvOutput.newLine();
                    }
                    JOptionPane.showMessageDialog(null, "CSV saved successfully!\n" + csvPath, "Success",
                            JOptionPane.INFORMATION_MESSAGE);
                    csvOutput.close();
                } catch (IOException ioe) {
                    JOptionPane.showMessageDialog(null,
                            "Failed to write CSV. Please check permissions!\n" + ioe.getMessage(), "Failed",
                            JOptionPane.ERROR_MESSAGE);
                    ioe.printStackTrace();
                }
            } else {
                JOptionPane.showMessageDialog(null, "Failed to write CSV. Please check the file path!",
                        "Failed", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    btnCsv.setBounds(590, 475, 70, 23);
    btnCsv.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    btnCsv.setVisible(false);
    add(btnCsv);

    btnPdf = new JButton("PDF");
    btnPdf.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileDialog = new JFileChooser();
            fileDialog.setFileFilter(new FileNameExtensionFilter("*.pdf", "pdf"));
            fileDialog.showSaveDialog(getParent());
            final File file = fileDialog.getSelectedFile();
            if (file != null) {
                String pdf;
                String[] tmpFileName = file.getAbsolutePath().split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("pdf")) {
                    pdf = "";
                } else {
                    pdf = ".pdf";
                }
                String pdfPath = file.getAbsolutePath() + pdf;
                OMSimulation simulation = (OMSimulation) comboBoxSimulations.getSelectedItem();
                String title = simulation.toString();
                DescriptiveStatistics statistics = null;
                OMStatistics statisticsType = (OMStatistics) comboBoxStatistics.getSelectedItem();
                OMRoomType roomType = null;
                switch (statisticsType) {
                case RoomArithmeticMeans:
                    title = "R_AM, " + title;
                    statistics = simulation.getRoomAmDescriptiveStats();
                    roomType = OMRoomType.Room;
                    break;
                case RoomGeometricMeans:
                    title = "R_GM, " + title;
                    statistics = simulation.getRoomGmDescriptiveStats();
                    roomType = OMRoomType.Room;
                    break;
                case RoomMedianQ50:
                    title = "R_MED, " + title;
                    statistics = simulation.getRoomMedDescriptiveStats();
                    roomType = OMRoomType.Room;
                    break;
                case RoomMaxima:
                    title = "R_MAX, " + title;
                    statistics = simulation.getRoomMaxDescriptiveStats();
                    roomType = OMRoomType.Room;
                    break;
                case CellarArithmeticMeans:
                    title = "C_AM, " + title;
                    statistics = simulation.getCellarAmDescriptiveStats();
                    roomType = OMRoomType.Cellar;
                    break;
                case CellarGeometricMeans:
                    title = "C_GM, " + title;
                    statistics = simulation.getCellarGmDescriptiveStats();
                    roomType = OMRoomType.Cellar;
                    break;
                case CellarMedianQ50:
                    title = "C_MED, " + title;
                    statistics = simulation.getCellarMedDescriptiveStats();
                    roomType = OMRoomType.Cellar;
                    break;
                case CellarMaxima:
                    title = "C_MAX, " + title;
                    statistics = simulation.getCellarMaxDescriptiveStats();
                    roomType = OMRoomType.Cellar;
                    break;
                default:
                    title = "R_AM, " + title;
                    statistics = simulation.getRoomAmDescriptiveStats();
                    roomType = OMRoomType.Misc;
                    break;
                }
                JFreeChart chart = OMCharts.createDistributionChart(title, statistics, roomType, false);
                int height = (int) PageSize.A4.getWidth();
                int width = (int) PageSize.A4.getHeight();
                try {
                    OMExports.exportPdf(pdfPath, chart, width, height, new DefaultFontMapper(), title);
                    JOptionPane.showMessageDialog(null, "PDF saved successfully!\n" + pdfPath, "Success",
                            JOptionPane.INFORMATION_MESSAGE);
                } catch (IOException ioe) {
                    JOptionPane.showMessageDialog(null,
                            "Failed to write PDF. Please check permissions!\n" + ioe.getMessage(), "Failed",
                            JOptionPane.ERROR_MESSAGE);
                    ioe.printStackTrace();
                }
            } else {
                JOptionPane.showMessageDialog(null, "Failed to write PDF. Please check the file path!",
                        "Failed", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    btnPdf.setBounds(670, 475, 70, 23);
    btnPdf.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    btnPdf.setVisible(false);
    add(btnPdf);

    lblSelectSimulation = new JLabel("Select Simulation");
    lblSelectSimulation.setFont(new Font("SansSerif", Font.PLAIN, 11));
    lblSelectSimulation.setBounds(10, 65, 132, 14);
    add(lblSelectSimulation);

    lblSelectStatistics = new JLabel("Select Statistics");
    lblSelectStatistics.setFont(new Font("SansSerif", Font.PLAIN, 11));
    lblSelectStatistics.setBounds(10, 94, 132, 14);
    add(lblSelectStatistics);

    comboBoxSimulations = new JComboBox<OMSimulation>();
    comboBoxSimulations.setFont(new Font("SansSerif", Font.PLAIN, 11));
    comboBoxSimulations.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent arg0) {
            boolean b = false;
            if (comboBoxSimulations.isEnabled()) {
                if (comboBoxSimulations.getSelectedItem() != null) {
                    b = true;
                    comboBoxStatistics.removeAllItems();
                    comboBoxStatistics.setModel(new DefaultComboBoxModel<OMStatistics>(OMStatistics.values()));
                } else {
                    b = false;
                    comboBoxStatistics.removeAllItems();
                }
            } else {
                b = false;
                comboBoxStatistics.removeAllItems();
            }
            progressBar.setEnabled(b);
            btnPdf.setVisible(b);
            btnCsv.setVisible(b);
            btnMaximize.setVisible(b);
            lblExportChartTo.setVisible(b);
            comboBoxStatistics.setEnabled(b);
            lblSelectStatistics.setEnabled(b);
        }
    });
    comboBoxSimulations.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            boolean b = false;
            if (comboBoxSimulations.isEnabled()) {
                if (comboBoxSimulations.getSelectedItem() != null) {
                    b = true;
                    comboBoxStatistics.removeAllItems();
                    comboBoxStatistics.setModel(new DefaultComboBoxModel<OMStatistics>(OMStatistics.values()));
                    comboBoxStatistics.setSelectedIndex(0);
                } else {
                    b = false;
                    comboBoxStatistics.removeAllItems();
                }
            } else {
                b = false;
                comboBoxStatistics.removeAllItems();
            }
            progressBar.setEnabled(b);
            btnPdf.setVisible(b);
            btnCsv.setVisible(b);
            btnMaximize.setVisible(b);
            lblExportChartTo.setVisible(b);
            comboBoxStatistics.setEnabled(b);
            lblSelectStatistics.setEnabled(b);
        }
    });
    comboBoxSimulations.setBounds(152, 61, 454, 22);
    add(comboBoxSimulations);

    btnRefresh = new JButton("Load");
    btnRefresh.setFont(new Font("SansSerif", Font.PLAIN, 11));
    btnRefresh.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (txtOmsFile.getText() != null && !txtOmsFile.getText().equals("")
                    && !txtOmsFile.getText().equals(" ")) {
                txtOmsFile.setBackground(Color.WHITE);
                String omsPath = txtOmsFile.getText();
                String oms;
                String[] tmpFileName = omsPath.split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("oms")) {
                    oms = "";
                } else {
                    oms = ".oms";
                }
                txtOmsFile.setText(omsPath + oms);
                setOmsFile(omsPath + oms);
                File omsFile = new File(omsPath + oms);
                if (omsFile.exists()) {
                    txtOmsFile.setBackground(Color.WHITE);
                    btnRefresh.setEnabled(false);
                    comboBoxSimulations.setEnabled(false);
                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    progressBar.setStringPainted(true);
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                    btnPdf.setVisible(false);
                    btnCsv.setVisible(false);
                    btnMaximize.setVisible(false);
                    lblExportChartTo.setVisible(false);
                    refreshSimulationsTask = new RefreshSimulations();
                    refreshSimulationsTask.execute();
                } else {
                    txtOmsFile.setBackground(new Color(255, 222, 222, 128));
                    JOptionPane.showMessageDialog(null, "OMS-file not found, please check the file path!",
                            "Error", JOptionPane.ERROR_MESSAGE);
                }
            } else {
                txtOmsFile.setBackground(new Color(255, 222, 222, 128));
                JOptionPane.showMessageDialog(null, "Please select an OMS-file!", "Warning",
                        JOptionPane.WARNING_MESSAGE);
            }
        }
    });

    comboBoxStatistics = new JComboBox<OMStatistics>();
    comboBoxStatistics.setFont(new Font("SansSerif", Font.PLAIN, 11));
    comboBoxStatistics.setBounds(152, 90, 454, 22);
    comboBoxStatistics.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            updateDistribution();
        }
    });
    add(comboBoxStatistics);

    btnRefresh.setBounds(616, 61, 124, 23);
    add(btnRefresh);

    panelDistribution = new JPanel();
    panelDistribution.setBounds(10, 118, 730, 347);
    add(panelDistribution);

    progressBar = new JProgressBar();
    progressBar.setFont(new Font("SansSerif", Font.PLAIN, 11));
    progressBar.setBounds(10, 475, 730, 23);
    add(progressBar);

    progressBar.setEnabled(false);
    comboBoxStatistics.setEnabled(false);
    lblSelectStatistics.setEnabled(false);
    btnPdf.setVisible(false);
    btnCsv.setVisible(false);
    btnMaximize.setVisible(false);
    lblExportChartTo.setVisible(false);

    lblHelp = new JLabel("Select an OMS-Simulation file to analyse the simulation results and "
            + "display the distribution chart.");
    lblHelp.setForeground(Color.GRAY);
    lblHelp.setFont(new Font("SansSerif", Font.PLAIN, 11));
    lblHelp.setBounds(10, 10, 730, 14);
    add(lblHelp);

    lblSelectOms = new JLabel("Open OMS-File");
    lblSelectOms.setFont(new Font("SansSerif", Font.PLAIN, 11));
    lblSelectOms.setBounds(10, 36, 132, 14);
    add(lblSelectOms);

    txtOmsFile = new JTextField();
    txtOmsFile.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            setOmsFile(txtOmsFile.getText());
        }
    });
    txtOmsFile.setFont(new Font("SansSerif", Font.PLAIN, 11));
    txtOmsFile.setColumns(10);
    txtOmsFile.setBounds(152, 33, 454, 20);
    add(txtOmsFile);

    buttonBrowse = new JButton("Browse");
    buttonBrowse.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            JFileChooser fileDialog = new JFileChooser();
            fileDialog.setFileFilter(new FileNameExtensionFilter("*.oms", "oms"));
            fileDialog.showOpenDialog(getParent());
            final File file = fileDialog.getSelectedFile();
            if (file != null) {
                String oms;
                String[] tmpFileName = file.getAbsolutePath().split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("oms")) {
                    oms = "";
                } else {
                    oms = ".oms";
                }
                txtOmsFile.setText(file.getAbsolutePath() + oms);
                setOmsFile(file.getAbsolutePath() + oms);
            }
        }
    });
    buttonBrowse.setFont(new Font("SansSerif", Font.PLAIN, 11));
    buttonBrowse.setBounds(616, 32, 124, 23);
    add(buttonBrowse);
    progressBar.setVisible(false);
}

From source file:it.imtech.metadata.MetaUtility.java

/**
 * Metodo adibito alla creazione dinamica ricorsiva dell'interfaccia dei
 * metadati//from   w w  w  . ja v a  2s  .  c o m
 *
 * @param submetadatas Map contente i metadati e i sottolivelli di metadati
 * @param vocabularies Map contenente i dati contenuti nel file xml
 * vocabulary.xml
 * @param parent Jpanel nel quale devono venir inseriti i metadati
 * @param level Livello corrente
 */
public void create_metadata_view(Map<Object, Metadata> submetadatas, JPanel parent, int level,
        final String panelname) throws Exception {
    ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE, Globals.loader);
    int lenght = submetadatas.size();
    int labelwidth = 220;
    int i = 0;
    JButton addcontribute = null;

    for (Map.Entry<Object, Metadata> kv : submetadatas.entrySet()) {
        ArrayList<Component> tabobjects = new ArrayList<Component>();

        if (kv.getValue().MID == 17 || kv.getValue().MID == 23 || kv.getValue().MID == 18
                || kv.getValue().MID == 137) {
            continue;
        }

        //Crea un jpanel nuovo e fa appen su parent
        JPanel innerPanel = new JPanel(new MigLayout("fillx, insets 1 1 1 1"));
        innerPanel.setName("pannello" + level + i);

        i++;
        String datatype = kv.getValue().datatype.toString();

        if (kv.getValue().MID == 45) {
            JPanel choice = new JPanel(new MigLayout());

            JComboBox combo = addClassificationChoice(choice, kv.getValue().sequence, panelname);

            JLabel labelc = new JLabel();
            labelc.setText(Utility.getBundleString("selectclassif", bundle));
            labelc.setPreferredSize(new Dimension(100, 20));

            choice.add(labelc);

            findLastClassification(panelname);
            if (last_classification != 0 && classificationRemoveButton == null) {
                logger.info("Removing last clasification");
                classificationRemoveButton = new JButton("-");

                classificationRemoveButton.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent event) {
                        BookImporter.getInstance().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                        removeClassificationToMetadata(panelname);
                        BookImporter.getInstance().refreshMetadataTab(false, panelname);
                        findLastClassification(panelname); //update last_classification
                        BookImporter.getInstance().setCursor(null);
                    }
                });
                if (Integer.parseInt(kv.getValue().sequence) == last_classification) {
                    choice.add(classificationRemoveButton, "wrap, width :50:");
                }
            }

            if (classificationAddButton == null) {
                logger.info("Adding a new classification");
                choice.add(combo, "width 100:600:600");

                classificationAddButton = new JButton("+");

                classificationAddButton.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent event) {
                        BookImporter.getInstance().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                        addClassificationToMetadata(panelname);
                        BookImporter.getInstance().refreshMetadataTab(false, panelname);
                        BookImporter.getInstance().setCursor(null);
                    }
                });

                choice.add(classificationAddButton, "width :50:");
            } else {
                //choice.add(combo, "wrap,width 100:700:700");
                choice.add(combo, "width 100:700:700");
                if (Integer.parseInt(kv.getValue().sequence) == last_classification) {
                    choice.add(classificationRemoveButton, "wrap, width :50");
                }
            }
            parent.add(choice, "wrap,width 100:700:700");
            classificationMID = kv.getValue().MID;

            innerPanel.setName(panelname + "---ImPannelloClassif---" + kv.getValue().sequence);
            try {

                addClassification(innerPanel, classificationMID, kv.getValue().sequence, panelname);
            } catch (Exception ex) {
                logger.error("Errore nell'aggiunta delle classificazioni");
            }
            parent.add(innerPanel, "wrap, growx");
            BookImporter.policy.addIndexedComponent(combo);

            continue;
        }

        if (datatype.equals("Node")) {
            JLabel label = new JLabel();
            label.setText(kv.getValue().description);
            label.setPreferredSize(new Dimension(100, 20));

            int size = 16 - (level * 2);
            Font myFont = new Font("MS Sans Serif", Font.PLAIN, size);
            label.setFont(myFont);

            if (Integer.toString(kv.getValue().MID).equals("11")) {
                JPanel temppanel = new JPanel(new MigLayout());

                //update last_contribute
                findLastContribute(panelname);

                if (last_contribute != 0 && removeContribute == null) {
                    logger.info("Removing last contribute");
                    removeContribute = new JButton("-");

                    removeContribute.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent event) {
                            BookImporter.getInstance()
                                    .setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                            removeContributorToMetadata(panelname);
                            BookImporter.getInstance().refreshMetadataTab(false, panelname);
                            BookImporter.getInstance().setCursor(null);
                        }
                    });

                    if (!kv.getValue().sequence.equals("")) {
                        if (Integer.parseInt(kv.getValue().sequence) == last_contribute) {
                            innerPanel.add(removeContribute, "width :50:");
                        }
                    }
                }

                if (addcontribute == null) {
                    logger.info("Adding a new contribute");
                    addcontribute = new JButton("+");

                    addcontribute.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent event) {
                            BookImporter.getInstance()
                                    .setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                            addContributorToMetadata(panelname);
                            BookImporter.getInstance().refreshMetadataTab(false, panelname);
                            BookImporter.getInstance().setCursor(null);
                        }
                    });

                    temppanel.add(label, " width :200:");
                    temppanel.add(addcontribute, "width :50:");
                    innerPanel.add(temppanel, "wrap, growx");
                } else {
                    temppanel.add(label, " width :200:");
                    findLastContribute(panelname);
                    if (!kv.getValue().sequence.equals("")) {
                        if (Integer.parseInt(kv.getValue().sequence) == last_contribute) {
                            temppanel.add(removeContribute, "width :50:");
                        }
                    }
                    innerPanel.add(temppanel, "wrap, growx");
                }
            } else if (Integer.toString(kv.getValue().MID).equals("115")) {
                logger.info("Devo gestire una provenience!");
            }
        } else {
            String title = "";

            if (kv.getValue().mandatory.equals("Y") || kv.getValue().MID == 14 || kv.getValue().MID == 15) {
                title = kv.getValue().description + " *";
            } else {
                title = kv.getValue().description;
            }

            innerPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), title,
                    TitledBorder.LEFT, TitledBorder.TOP));

            if (datatype.equals("Vocabulary")) {
                TreeMap<String, String> entryCombo = new TreeMap<String, String>();
                int index = 0;
                String selected = null;

                if (!Integer.toString(kv.getValue().MID).equals("8"))
                    entryCombo.put(Utility.getBundleString("comboselect", bundle),
                            Utility.getBundleString("comboselect", bundle));

                for (Map.Entry<String, TreeMap<String, VocEntry>> vc : vocabularies.entrySet()) {
                    String tempmid = Integer.toString(kv.getValue().MID);

                    if (Integer.toString(kv.getValue().MID_parent).equals("11")
                            || Integer.toString(kv.getValue().MID_parent).equals("13")) {
                        String[] testmid = tempmid.split("---");
                        tempmid = testmid[0];
                    }

                    if (vc.getKey().equals(tempmid)) {
                        TreeMap<String, VocEntry> iEntry = vc.getValue();

                        for (Map.Entry<String, VocEntry> ivc : iEntry.entrySet()) {
                            entryCombo.put(ivc.getValue().description, ivc.getValue().ID);
                            if (kv.getValue().value != null) {
                                if (kv.getValue().value.equals(ivc.getValue().ID)) {
                                    selected = ivc.getValue().ID;
                                }
                            }
                            index++;
                        }
                    }
                }

                final ComboMapImpl model = new ComboMapImpl();
                model.setVocabularyCombo(true);
                model.putAll(entryCombo);

                final JComboBox voc = new javax.swing.JComboBox(model);
                model.specialRenderCombo(voc);

                if (Integer.toString(kv.getValue().MID_parent).equals("11")
                        || Integer.toString(kv.getValue().MID_parent).equals("13")) {
                    voc.setName("MID_" + Integer.toString(kv.getValue().MID) + "---" + kv.getValue().sequence);
                } else {
                    voc.setName("MID_" + Integer.toString(kv.getValue().MID));
                }

                if (Integer.toString(kv.getValue().MID).equals("8") && selected == null)
                    selected = "44";

                selected = (selected == null) ? Utility.getBundleString("comboselect", bundle) : selected;

                for (int k = 0; k < voc.getItemCount(); k++) {
                    Map.Entry<String, String> el = (Map.Entry<String, String>) voc.getItemAt(k);
                    if (el.getValue().equals(selected))
                        voc.setSelectedIndex(k);
                }

                voc.setPreferredSize(new Dimension(150, 30));
                innerPanel.add(voc, "wrap, width :400:");
                tabobjects.add(voc);
            } else if (datatype.equals("CharacterString") || datatype.equals("GPS")) {
                final JTextArea textField = new javax.swing.JTextArea();

                if (Integer.toString(kv.getValue().MID_parent).equals("11")
                        || Integer.toString(kv.getValue().MID_parent).equals("13")) {
                    textField.setName(
                            "MID_" + Integer.toString(kv.getValue().MID) + "---" + kv.getValue().sequence);
                } else {
                    textField.setName("MID_" + Integer.toString(kv.getValue().MID));
                }

                textField.setPreferredSize(new Dimension(230, 0));
                textField.setText(kv.getValue().value);
                textField.setLineWrap(true);
                textField.setWrapStyleWord(true);

                innerPanel.add(textField, "wrap, width :300:");

                textField.addKeyListener(new KeyAdapter() {
                    @Override
                    public void keyPressed(KeyEvent e) {
                        if (e.getKeyCode() == KeyEvent.VK_TAB) {
                            if (e.getModifiers() > 0) {
                                textField.transferFocusBackward();
                            } else {
                                textField.transferFocus();
                            }
                            e.consume();
                        }
                    }
                });

                tabobjects.add(textField);
            } else if (datatype.equals("LangString")) {
                JScrollPane inner_scroll = new javax.swing.JScrollPane();
                inner_scroll.setHorizontalScrollBarPolicy(
                        javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
                inner_scroll.setVerticalScrollBarPolicy(
                        javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
                inner_scroll.setPreferredSize(new Dimension(240, 80));
                inner_scroll.setName("langStringScroll");
                final JTextArea jTextArea1 = new javax.swing.JTextArea();
                jTextArea1.setName("MID_" + Integer.toString(kv.getValue().MID));
                jTextArea1.setText(kv.getValue().value);

                jTextArea1.setSize(new Dimension(350, 70));
                jTextArea1.setLineWrap(true);
                jTextArea1.setWrapStyleWord(true);

                inner_scroll.setViewportView(jTextArea1);
                innerPanel.add(inner_scroll, "width :300:");

                //Add combo language box
                JComboBox voc = getComboLangBox(kv.getValue().language);
                voc.setName("MID_" + Integer.toString(kv.getValue().MID) + "_lang");

                voc.setPreferredSize(new Dimension(200, 20));
                innerPanel.add(voc, "wrap, width :300:");

                jTextArea1.addKeyListener(new KeyAdapter() {
                    @Override
                    public void keyPressed(KeyEvent e) {
                        if (e.getKeyCode() == KeyEvent.VK_TAB) {
                            if (e.getModifiers() > 0) {
                                jTextArea1.transferFocusBackward();
                            } else {
                                jTextArea1.transferFocus();
                            }
                            e.consume();
                        }
                    }
                });
                tabobjects.add(jTextArea1);
                tabobjects.add(voc);
            } else if (datatype.equals("Language")) {
                final JComboBox voc = getComboLangBox(kv.getValue().value);
                voc.setName("MID_" + Integer.toString(kv.getValue().MID));

                voc.setPreferredSize(new Dimension(150, 20));
                voc.setBounds(5, 5, 150, 20);
                innerPanel.add(voc, "wrap, width :500:");

                //BookImporter.policy.addIndexedComponent(voc);
                tabobjects.add(voc);

            } else if (datatype.equals("Boolean")) {
                int selected = 0;
                TreeMap bin = new TreeMap<String, String>();
                bin.put("yes", Utility.getBundleString("voc1", bundle));
                bin.put("no", Utility.getBundleString("voc2", bundle));

                if (kv.getValue().value == null) {
                    switch (kv.getValue().MID) {
                    case 35:
                        selected = 0;
                        break;
                    case 36:
                        selected = 1;
                        break;
                    }
                } else if (kv.getValue().value.equals("yes")) {
                    selected = 1;
                } else {
                    selected = 0;
                }

                final ComboMapImpl model = new ComboMapImpl();
                model.putAll(bin);

                final JComboBox voc = new javax.swing.JComboBox(model);
                model.specialRenderCombo(voc);

                voc.setName("MID_" + Integer.toString(kv.getValue().MID));
                voc.setSelectedIndex(selected);

                voc.setPreferredSize(new Dimension(150, 20));
                voc.setBounds(5, 5, 150, 20);
                innerPanel.add(voc, "wrap, width :300:");
                //BookImporter.policy.addIndexedComponent(voc);
                tabobjects.add(voc);
            } else if (datatype.equals("License")) {
                String selectedIndex = null;
                int vindex = 0;
                int defaultIndex = 0;

                TreeMap<String, String> entryCombo = new TreeMap<String, String>();

                for (Map.Entry<String, TreeMap<String, VocEntry>> vc : vocabularies.entrySet()) {
                    if (vc.getKey().equals(Integer.toString(kv.getValue().MID))) {
                        TreeMap<String, VocEntry> iEntry = vc.getValue();

                        for (Map.Entry<String, VocEntry> ivc : iEntry.entrySet()) {
                            entryCombo.put(ivc.getValue().description, ivc.getValue().ID);

                            if (ivc.getValue().ID.equals("1"))
                                defaultIndex = vindex;

                            if (kv.getValue().value != null) {
                                if (ivc.getValue().ID.equals(kv.getValue().value)) {
                                    selectedIndex = Integer.toString(vindex);
                                }
                            }
                            vindex++;
                        }
                    }
                }

                if (selectedIndex == null)
                    selectedIndex = Integer.toString(defaultIndex);

                ComboMapImpl model = new ComboMapImpl();
                model.putAll(entryCombo);
                model.setVocabularyCombo(true);

                JComboBox voc = new javax.swing.JComboBox(model);
                model.specialRenderCombo(voc);

                voc.setName("MID_" + Integer.toString(kv.getValue().MID));
                voc.setSelectedIndex(Integer.parseInt(selectedIndex));
                voc.setPreferredSize(new Dimension(150, 20));

                voc.setBounds(5, 5, 150, 20);
                innerPanel.add(voc, "wrap, width :500:");
                //BookImporter.policy.addIndexedComponent(voc);
                tabobjects.add(voc);
            } else if (datatype.equals("DateTime")) {
                //final JXDatePicker datePicker = new JXDatePicker();
                JDateChooser datePicker = new JDateChooser();
                datePicker.setName("MID_" + Integer.toString(kv.getValue().MID));

                JPanel test = new JPanel(new MigLayout());
                JLabel lbefore = new JLabel(Utility.getBundleString("beforechristlabel", bundle));
                JCheckBox beforechrist = new JCheckBox();
                beforechrist.setName("MID_" + Integer.toString(kv.getValue().MID) + "_check");

                if (kv.getValue().value != null) {
                    try {
                        if (kv.getValue().value.charAt(0) == '-') {
                            beforechrist.setSelected(true);
                        }

                        Date date1 = new Date();
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                        if (kv.getValue().value.charAt(0) == '-') {
                            date1 = sdf.parse(adjustDate(kv.getValue().value));
                        } else {
                            date1 = sdf.parse(kv.getValue().value);
                        }
                        datePicker.setDate(date1);
                    } catch (Exception e) {
                        //Console.WriteLine("ERROR import date:" + ex.Message);
                    }
                }

                test.add(datePicker, "width :200:");
                test.add(lbefore, "gapleft 30");
                test.add(beforechrist, "wrap");

                innerPanel.add(test, "wrap");
            }
        }

        //Recursive call
        create_metadata_view(kv.getValue().submetadatas, innerPanel, level + 1, panelname);

        if (kv.getValue().editable.equals("Y")
                || (datatype.equals("Node") && kv.getValue().hidden.equals("0"))) {
            parent.add(innerPanel, "wrap, growx");

            for (Component tabobject : tabobjects) {
                BookImporter.policy.addIndexedComponent(tabobject);
            }
        }
    }
}

From source file:edu.harvard.i2b2.previousquery.QueryPreviousRunsPanel.java

public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equalsIgnoreCase("Rename ...")) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();
        QueryMasterData ndata = (QueryMasterData) node.getUserObject();
        Object inputValue = JOptionPane.showInputDialog(this, "Rename this query to: ", "Rename Query Dialog",
                JOptionPane.PLAIN_MESSAGE, null, null,
                ndata.name().substring(0, ndata.name().lastIndexOf("[") - 1));

        if (inputValue != null) {
            String newQueryName = (String) inputValue;
            String requestXml = ndata.writeRenameQueryXML(newQueryName);
            lastRequestMessage = requestXml;

            setCursor(new Cursor(Cursor.WAIT_CURSOR));

            String response = QueryListNamesClient.sendQueryRequestREST(requestXml);
            if (response.equalsIgnoreCase("CellDown")) {
                final JPanel parent = this;
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        JOptionPane.showMessageDialog(parent,
                                "Trouble with connection to the remote server, "
                                        + "this is often a network error, please try again",
                                "Network Error", JOptionPane.INFORMATION_MESSAGE);
                    }//from  w  ww.  j ava 2s . c o m
                });
                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                return;
            }
            lastResponseMessage = response;

            if (response != null) {
                JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();

                try {
                    JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response);
                    ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
                    StatusType statusType = messageType.getResponseHeader().getResultStatus().getStatus();
                    String status = statusType.getType();

                    if (status.equalsIgnoreCase("DONE")) {
                        ndata.name(newQueryName + " [" + ndata.userId() + "]");
                        node.setUserObject(ndata);
                        //DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();

                        jTree1.repaint();
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
    } else if (e.getActionCommand().equalsIgnoreCase("Delete")) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();
        QueryMasterData ndata = (QueryMasterData) node.getUserObject();
        Object selectedValue = JOptionPane.showConfirmDialog(this, "Delete Query \"" + ndata.name() + "\"?",
                "Delete Query Dialog", JOptionPane.YES_NO_OPTION);
        if (selectedValue.equals(JOptionPane.YES_OPTION)) {
            System.out.println("delete " + ndata.name());
            String requestXml = ndata.writeDeleteQueryXML();
            lastRequestMessage = requestXml;
            //System.out.println(requestXml);

            setCursor(new Cursor(Cursor.WAIT_CURSOR));

            String response = QueryListNamesClient.sendQueryRequestREST(requestXml);
            if (response.equalsIgnoreCase("CellDown")) {
                final JPanel parent = this;
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        JOptionPane.showMessageDialog(parent,
                                "Trouble with connection to the remote server, "
                                        + "this is often a network error, please try again",
                                "Network Error", JOptionPane.INFORMATION_MESSAGE);
                    }
                });
                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                return;
            }
            lastResponseMessage = response;

            if (response != null) {
                JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();

                try {
                    JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response);
                    ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
                    StatusType statusType = messageType.getResponseHeader().getResultStatus().getStatus();
                    String status = statusType.getType();

                    if (status.equalsIgnoreCase("DONE")) {
                        treeModel.removeNodeFromParent(node);

                        //jTree1.repaint();
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
    } else if (e.getActionCommand().equalsIgnoreCase("Refresh All")) {
        String status = loadPreviousQueries(false);
        if (status.equalsIgnoreCase("")) {
            reset(200, false);
        } else if (status.equalsIgnoreCase("CellDown")) {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JOptionPane.showMessageDialog(parent,
                            "Trouble with connection to the remote server, "
                                    + "this is often a network error, please try again",
                            "Network Error", JOptionPane.INFORMATION_MESSAGE);
                }
            });
        }
    }
}

From source file:com.ixora.rms.ui.RMSFrame.java

/**
 * Handles the load log event./* ww  w.j  a v  a 2 s.  c o  m*/
 */
private void handleLoadLogForPlayback() {
    try {
        if (resetCurrentView()) {
            return;
        }
        DataLogReplayConfigurationDialog dlg = new DataLogReplayConfigurationDialog(this);
        fCurrentView = new LogPlaybackView(RMSFrame.this, RMS.getDataLogReplay(), dlg.getScanningService());
        UIUtils.centerDialogAndShow(this, dlg);
        DataLogCompareAndReplayConfiguration conf = dlg.getResult();
        if (conf != null) {
            try {
                ((LogPlaybackView) fCurrentView).setReplayConfiguration(conf);
                getAppWorker().runJobSynch(new UIWorkerJobDefault(this, Cursor.WAIT_CURSOR,
                        MessageRepository.get(Msg.TEXT_LOADING_LOG_VIEW)) {
                    public void finished(Throwable ex) throws Throwable {
                        if (ex != null) {
                            resetCurrentView();
                        }
                    }

                    public void work() throws Throwable {
                        fCurrentView.initialize();
                    }
                });
            } catch (Throwable e) {
                resetCurrentView();
                UIExceptionMgr.userException(e);
            }
        }
    } catch (Throwable e) {
        resetCurrentView();
        UIExceptionMgr.userException(e);
    }
}

From source file:com._17od.upm.gui.DatabaseActions.java

public boolean syncWithRemoteDatabase() throws TransportException, ProblemReadingDatabaseFile, IOException,
        CryptoException, PasswordDatabaseException {

    boolean syncSuccessful = false;

    try {// w  w w  .  jav  a  2 s. c o m
        fileMonitor.pause();

        mainWindow.getContentPane().setCursor(new Cursor(Cursor.WAIT_CURSOR));

        // Get the remote database options
        String remoteLocation = database.getDbOptions().getRemoteLocation();
        String authDBEntry = database.getDbOptions().getAuthDBEntry();
        String httpUsername = null;
        String httpPassword = null;
        if (!authDBEntry.equals("")) {
            httpUsername = database.getAccount(authDBEntry).getUserId();
            httpPassword = database.getAccount(authDBEntry).getPassword();
        }

        // Download the database that's already at the remote location
        Transport transport = Transport.getTransportForURL(new URL(remoteLocation));
        File remoteDatabaseFile = transport.getRemoteFile(remoteLocation, database.getDatabaseFile().getName(),
                httpUsername, httpPassword);

        // Attempt to decrypt the database using the password the user entered
        PasswordDatabase remoteDatabase = null;
        char[] password = null;
        boolean successfullyDecryptedDb = false;
        try {
            remoteDatabase = dbPers.load(remoteDatabaseFile);
            successfullyDecryptedDb = true;
        } catch (InvalidPasswordException e) {
            // The password for the downloaded database is different to that of the open database
            // (most likely the user changed the local database's master password)
            boolean okClicked = false;
            do {
                password = askUserForPassword(Translator.translate("enterPaswordForRemoteDB"));
                if (password == null) {
                    okClicked = false;
                } else {
                    okClicked = true;
                    try {
                        remoteDatabase = dbPers.load(remoteDatabaseFile, password);
                        successfullyDecryptedDb = true;
                    } catch (InvalidPasswordException invalidPassword) {
                        JOptionPane.showMessageDialog(mainWindow, Translator.translate("incorrectPassword"));
                    }
                }
            } while (okClicked && !successfullyDecryptedDb);
        }

        /* If the local database revision > remote database version => upload local database 
           If the local database revision < remote database version => replace local database with remote database
           If the local database revision = remote database version => do nothing */
        if (successfullyDecryptedDb) {
            if (database.getRevision() > remoteDatabase.getRevision()) {
                transport.delete(remoteLocation, database.getDatabaseFile().getName(), httpUsername,
                        httpPassword);
                transport.put(remoteLocation, database.getDatabaseFile(), httpUsername, httpPassword);
                syncSuccessful = true;
            } else if (database.getRevision() < remoteDatabase.getRevision()) {
                Util.copyFile(remoteDatabaseFile, database.getDatabaseFile());
                database = new PasswordDatabase(remoteDatabase.getRevisionObj(), remoteDatabase.getDbOptions(),
                        remoteDatabase.getAccountsHash(), database.getDatabaseFile());
                doOpenDatabaseActions();
                syncSuccessful = true;
            } else {
                syncSuccessful = true;
            }

            if (syncSuccessful) {
                setLocalDatabaseDirty(false);

                // Create a thread that will mark the database dirty after
                // a short period. Without this the database would remain
                // in a synced state until the user makes a change. The
                // longer we wait before syncing up the greater chance there
                // is that we'll miss changes made elsewhere and end up
                // with a conflicting version of the database.
                final long dirtyThreadStartTime = System.currentTimeMillis();
                runSetDBDirtyThread = true;
                Thread setDBDirtyThread = new Thread(new Runnable() {
                    public void run() {
                        while (runSetDBDirtyThread) {
                            try {
                                Thread.sleep(1000);
                            } catch (InterruptedException e1) {
                            }
                            long currentTime = System.currentTimeMillis();
                            if (currentTime - dirtyThreadStartTime > 5 * 60 * 1000) {
                                LOG.info("SetDBDirtyThread setting database dirty");
                                setLocalDatabaseDirty(true);
                                runSetDBDirtyThread = false;
                            }
                        }
                    }
                });
                setDBDirtyThread.setName("SetDBDirty");
                setDBDirtyThread.start();
                LOG.info("Started SetDBDirtyThread thread");

            }
        }

    } finally {
        mainWindow.getContentPane().setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        fileMonitor.start();
    }

    return syncSuccessful;

}