Forked from
DM / dm-docs
261 commits behind, 385 commits ahead of the upstream repository.
-
Barbara B. Frosik authoredBarbara B. Frosik authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
LoginWindow.java 3.59 KiB
package gov.anl.dm.esafsync;
import gov.anl.dm.esafsync.serviceconn.DaqServiceConnection;
import gov.anl.dm.esafsync.serviceconn.ServiceConnection;
import gov.anl.dm.esafsync.serviceconn.StorageServiceConnection;
import javax.swing.*;
import java.awt.event.*;
public final class LoginWindow extends JFrame {
private static final long serialVersionUID = 1L;
StorageServiceConnection sconnection;
OracleConnection oconnection;
JPanel panel;
LoginWindow(final StorageServiceConnection sconnection, final OracleConnection oconnection, final DaqServiceConnection dconnection, final DaqServiceConnection drconnection) {
this.sconnection = sconnection;
this.oconnection = oconnection;
setTitle("Experiment Import Login");
JPanel panel = new JPanel();
add(panel);
panel.setLayout(null);
JLabel userLabel = new JLabel("User");
userLabel.setBounds(10, 10, 80, 25);
panel.add(userLabel);
final JTextField userText = new JTextField(20);
userText.setBounds(100, 10, 160, 25);
panel.add(userText);
JLabel passwordLabel = new JLabel("Password");
passwordLabel.setBounds(10, 40, 80, 25);
panel.add(passwordLabel);
final JPasswordField passwordText = new JPasswordField(20);
passwordText.setBounds(100, 40, 160, 25);
panel.add(passwordText);
JLabel sectorLabel = new JLabel("Sector");
sectorLabel.setBounds(10, 70, 80, 25);
panel.add(sectorLabel);
final JTextField sectorText = new JTextField(20);
sectorText.setBounds(100, 70, 160, 25);
panel.add(sectorText);
JButton submitButton = new JButton("submit");
submitButton.setBounds(10, 120, 80, 25);
panel.add(submitButton);
submitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// String user = userText.getText().trim();
// String pass = new String(passwordText.getPassword());
String user = "dm";
String pass = "dbUser";
if ((user == null) || (user.isEmpty()) || (pass == null) || (pass.isEmpty())) {
JOptionPane.showMessageDialog(null,"enter login and password",
"Error",JOptionPane.ERROR_MESSAGE);
} else {
// sconnection.setLogin(user, pass);
// dconnection.setLogin(user, pass);
int aaResult = sconnection.login(user, pass);
if ((dconnection.login(user, pass) != aaResult) || (dconnection.login(user, pass) != aaResult)) {
JOptionPane.showMessageDialog(null,"inconsistent login response",
"Error",JOptionPane.ERROR_MESSAGE);
return;
}
switch (aaResult) {
case ServiceConnection.ServiceConnectionStatus.SUCCESS:
setVisible(false);
ExperimentList page=new ExperimentList(sectorText.getText().trim(), oconnection, sconnection, dconnection, drconnection);
page.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
page.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
sconnection.close();
oconnection.close();
System.exit(0);
}
});
page.setVisible(true);
break;
case ServiceConnection.ServiceConnectionStatus.AUTHORIZATION_ERROR:
userText.setText("");
passwordText.setText("");
JOptionPane.showMessageDialog(null,"not authorized user",
"Error",JOptionPane.ERROR_MESSAGE);
break;
case ServiceConnection.ServiceConnectionStatus.AUTHENTICATION_ERROR:
userText.setText("");
passwordText.setText("");
JOptionPane.showMessageDialog(null,"Incorrect login or password",
"Error",JOptionPane.ERROR_MESSAGE);
break;
default:
// error message generated from exception
}
}
}
});
}
}