Forked from
DM / dm-docs
261 commits behind, 490 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.
Gui.java 3.43 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 java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.Properties;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
class Gui
{
public static void main(String arg[]) throws ParseException
{
String configFile = arg[0];
final Properties configProperties = new Properties();
setConfig(configFile, configProperties);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new Gui(configProperties);
}
});
}
private Gui(Properties configProperties) {
// System.setProperty("javax.net.ssl.trustStore", configProperties.getProperty("dm.truststore"));
final OracleConnection oconnection = new OracleConnection();
try {
oconnection.connect(configProperties);
} catch (SQLException e1) {
JOptionPane.showMessageDialog(null, e1.getMessage());
System.exit(0);
}
final StorageServiceConnection sconnection = new StorageServiceConnection();
if (sconnection.init(configProperties.getProperty("dm.storageServ.connection")) != ServiceConnection.ServiceConnectionStatus.SUCCESS) {
System.exit(0);
}
String daqurl = configProperties.getProperty("dm.daq.connection");
String dataDir = configProperties.getProperty("dm.daq.datadir");
DaqServiceConnection dconnection = new DaqServiceConnection(daqurl, dataDir);
if (dconnection.init() != ServiceConnection.ServiceConnectionStatus.SUCCESS) {
System.exit(0);
}
DaqServiceConnection drconnection = null;
try {
String daqReceiverurl = configProperties.getProperty("dm.daqReciver.connection");
String dataReceiverDir = configProperties.getProperty("dm.daqReceiver.datadir");
if ((daqReceiverurl != null) && (dataReceiverDir != null)) {
drconnection = new DaqServiceConnection(daqReceiverurl, dataReceiverDir);
if (drconnection.init() != ServiceConnection.ServiceConnectionStatus.SUCCESS) {
System.exit(0);
}
}
} catch (Exception e) {
// possible null exception if property not defined
}
try
{
LoginWindow frame = new LoginWindow(sconnection, oconnection, dconnection, drconnection);
frame.setSize(300,200);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
if (sconnection != null) {
sconnection.close();
}
if (oconnection != null) {
oconnection.close();
}
System.exit(0);
}
});
}
catch(Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
private static void setConfig(String config, Properties configProperties) {
InputStream configInputStream = null;
try {
configInputStream = new FileInputStream(config);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
System.exit(0);
}
if (configInputStream != null) {
try {
configProperties.load(configInputStream);
} catch (IOException e1) {
JOptionPane.showMessageDialog(null, e1.getMessage());
System.exit(0);
}
} else {
System.exit(-1);
}
}
}