Search in sources :

Example 1 with ServerConnectionTest

use of org.opendatakit.briefcase.util.ServerConnectionTest in project briefcase by opendatakit.

the class ServerConnectionDialog method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (CONNECT.equals(e.getActionCommand())) {
        // do action...
        final ServerConnectionInfo info = new ServerConnectionInfo((textUrlField.getText()).trim(), textUsernameField.getText(), textPasswordField.getPassword());
        okButton.setEnabled(false);
        cancelButton.setEnabled(false);
        String errorString;
        Cursor saved = getCursor();
        try {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            paint(getGraphics());
            terminationFuture.reset();
            ServerConnectionTest backgroundAction = new ServerConnectionTest(info, terminationFuture, asTarget);
            backgroundAction.run();
            isSuccessful = backgroundAction.isSuccessful();
            errorString = backgroundAction.getErrorReason();
        } finally {
            setCursor(saved);
        }
        if (isSuccessful) {
            serverInfo = info;
            this.setVisible(false);
        } else {
            String errorMessage = errorString.trim();
            // with punctuation and some not
            if (!(errorMessage.endsWith("!") || errorMessage.endsWith("."))) {
                errorMessage += ". ";
            }
            ODKOptionPane.showErrorDialog(this, errorMessage + MessageStrings.PROXY_SET_ADVICE, "Invalid Server URL");
            okButton.setEnabled(true);
            cancelButton.setEnabled(true);
        }
    } else {
        // cancel...
        terminationFuture.markAsCancelled(new TransferAbortEvent("User cancels connection."));
        this.setVisible(false);
    }
}
Also used : ServerConnectionTest(org.opendatakit.briefcase.util.ServerConnectionTest) ServerConnectionInfo(org.opendatakit.briefcase.model.ServerConnectionInfo) Cursor(java.awt.Cursor) TransferAbortEvent(org.opendatakit.briefcase.model.TransferAbortEvent)

Aggregations

Cursor (java.awt.Cursor)1 ServerConnectionInfo (org.opendatakit.briefcase.model.ServerConnectionInfo)1 TransferAbortEvent (org.opendatakit.briefcase.model.TransferAbortEvent)1 ServerConnectionTest (org.opendatakit.briefcase.util.ServerConnectionTest)1