Commit 717be679 authored by SAPONE Alann's avatar SAPONE Alann

corrected bug : no action on some dialogs close

parent 69a585e2
......@@ -43,126 +43,126 @@ import org.cnrs.lam.dis.etc.ui.swing.SplashScreen;
/**
*/
public class Main {
private static final Logger logger = Logger.getLogger(ETC42.class);
private static final long MAX_HEAP_REQUIRED = 1400000000L;
public static void main(String[] args) {
SplashScreen.getInstance().setVisible(true);
SplashScreen.getInstance().setProgression("Initialization");
// First we initialize the logger configuration
ETC42.initializeLogger();
logger.info("Starting ETC-42...");
boolean enoughMemory = false;
// Check if the user wants to skip the memory test
if (System.getProperty("etc.allowSmallHeap") != null) {
logger.info("Skipping the memory check because user gave the etc.allowSmallHeap parameter...");
enoughMemory = true;
}
// We check the memory size
if (!enoughMemory && Runtime.getRuntime().maxMemory() >= MAX_HEAP_REQUIRED) {
enoughMemory = true;
}
// Now we run ETC in this process or in a new one if we need more memory
if (enoughMemory) {
ETC42.main(args);
} else {
logger.info("ETC-42 was launched with insufficient max heap size ("
+ Runtime.getRuntime().maxMemory() + "). Trying to relaunch with more memory.");
launchInNewProcess(args);
}
SplashScreen.getInstance().setVisible(false);
}
private static void launchInNewProcess(String[] args) {
// Get the class path
String classPath = System.getProperty("java.class.path");
classPath.replaceAll(" ", "\\ ");
// Get the parameters the user gave. Note that we do that ONLY for the ETC parameters
StringBuilder parameters = new StringBuilder();
if (System.getProperty("etc.uiMode") != null) {
parameters.append(" ").append("-Detc.uiMode=").append(System.getProperty("etc.uiMode"));
}
//Load defaults xml file if database is empty
if (System.getProperty("etc.fixtures") != null) {
parameters.append(" ").append("-Detc.fixtures=").append(System.getProperty("etc.fixtures"));
}
if (System.getProperty("etc.server") != null) {
parameters.append(" ").append("-Detc.server=").append(System.getProperty("etc.server"));
}
if (System.getProperty("etc.instrument") != null) {
parameters.append(" ").append("-Detc.instrument=").append(System.getProperty("etc.instrument"));
}
if (System.getProperty("etc.site") != null) {
parameters.append(" ").append("-Detc.site=").append(System.getProperty("etc.site"));
}
if (System.getProperty("etc.home") != null) {
parameters.append(" ").append("-Detc.home=").append(System.getProperty("etc.home"));
}
if (System.getProperty("calculator.disable.cache") != null) {
parameters.append(" ").append("-Dcalculator.disable.cache");
}
StringBuilder arguments = new StringBuilder();
for (String arg : args) {
arguments.append(arg).append(" ");
}
String execCommand = "java -cp " + classPath + " -Xmx1536m "
+ parameters + " org.cnrs.lam.dis.etc.controller.ETC42 " + arguments;
logger.info("Restarting ETC-42 with command:");
logger.info(execCommand);
try {
Process process = Runtime.getRuntime().exec(execCommand);
new PrintToStreamThread(process.getInputStream(), System.out).start();
new PrintToStreamThread(process.getErrorStream(), System.err).start();
new RedirectStandardInputThread(process.getOutputStream()).start();
} catch (IOException ex) {
logger.error("Failed to relaunch ETC-42.", ex);
}
}
private static class PrintToStreamThread extends Thread {
private InputStream streamToRead;
private PrintStream streamToWrite;
private static final Logger logger = Logger.getLogger(ETC42.class);
private static final long MAX_HEAP_REQUIRED = 1400000000L;
public PrintToStreamThread(InputStream streamToRead, PrintStream streamToWrite) {
this.streamToRead = streamToRead;
this.streamToWrite = streamToWrite;
}
@Override
public void run() {
try {
int charRed = 0;
byte[] buffer = new byte[1024];
while ((charRed = streamToRead.read(buffer)) != -1) {
streamToWrite.write(buffer, 0, charRed);
}
} catch (IOException ex) {
}
}
}
private static class RedirectStandardInputThread extends Thread {
private OutputStream streamToWrite;
public static void main(String[] args) {
public RedirectStandardInputThread(OutputStream streamToWrite) {
this.streamToWrite = streamToWrite;
}
SplashScreen.getInstance().setVisible(true);
SplashScreen.getInstance().setProgression("Initialization");
// First we initialize the logger configuration
ETC42.initializeLogger();
logger.info("Starting ETC-42...");
boolean enoughMemory = false;
// Check if the user wants to skip the memory test
if (System.getProperty("etc.allowSmallHeap") != null) {
logger.info("Skipping the memory check because user gave the etc.allowSmallHeap parameter...");
enoughMemory = true;
}
// We check the memory size
if (!enoughMemory && Runtime.getRuntime().maxMemory() >= MAX_HEAP_REQUIRED) {
enoughMemory = true;
}
// Now we run ETC in this process or in a new one if we need more memory
if (enoughMemory) {
ETC42.main(args);
} else {
logger.info("ETC-42 was launched with insufficient max heap size ("
+ Runtime.getRuntime().maxMemory() + "). Trying to relaunch with more memory.");
launchInNewProcess(args);
}
SplashScreen.getInstance().setVisible(false);
}
private static void launchInNewProcess(String[] args) {
// Get the class path
String classPath = System.getProperty("java.class.path");
classPath.replaceAll(" ", "\\ ");
// Get the parameters the user gave. Note that we do that ONLY for the ETC parameters
StringBuilder parameters = new StringBuilder();
if (System.getProperty("etc.uiMode") != null) {
parameters.append(" ").append("-Detc.uiMode=").append(System.getProperty("etc.uiMode"));
}
//Load defaults xml file if database is empty
if (System.getProperty("etc.fixtures") != null) {
parameters.append(" ").append("-Detc.fixtures=").append(System.getProperty("etc.fixtures"));
}
if (System.getProperty("etc.server") != null) {
parameters.append(" ").append("-Detc.server=").append(System.getProperty("etc.server"));
}
if (System.getProperty("etc.instrument") != null) {
parameters.append(" ").append("-Detc.instrument=").append(System.getProperty("etc.instrument"));
}
if (System.getProperty("etc.site") != null) {
parameters.append(" ").append("-Detc.site=").append(System.getProperty("etc.site"));
}
if (System.getProperty("etc.home") != null) {
parameters.append(" ").append("-Detc.home=").append(System.getProperty("etc.home"));
}
if (System.getProperty("calculator.disable.cache") != null) {
parameters.append(" ").append("-Dcalculator.disable.cache");
}
StringBuilder arguments = new StringBuilder();
for (String arg : args) {
arguments.append(arg).append(" ");
}
String execCommand = "java -cp " + classPath + " -Xmx1536m "
+ parameters + " org.cnrs.lam.dis.etc.controller.ETC42 " + arguments;
logger.info("Restarting ETC-42 with command:");
logger.info(execCommand);
try {
Process process = Runtime.getRuntime().exec(execCommand);
new PrintToStreamThread(process.getInputStream(), System.out).start();
new PrintToStreamThread(process.getErrorStream(), System.err).start();
new RedirectStandardInputThread(process.getOutputStream()).start();
} catch (IOException ex) {
logger.error("Failed to relaunch ETC-42.", ex);
}
}
private static class PrintToStreamThread extends Thread {
private InputStream streamToRead;
private PrintStream streamToWrite;
public PrintToStreamThread(InputStream streamToRead, PrintStream streamToWrite) {
this.streamToRead = streamToRead;
this.streamToWrite = streamToWrite;
}
@Override
public void run() {
try {
int charRed = 0;
byte[] buffer = new byte[1024];
while ((charRed = streamToRead.read(buffer)) != -1) {
streamToWrite.write(buffer, 0, charRed);
}
} catch (IOException ex) {
}
}
}
private static class RedirectStandardInputThread extends Thread {
private OutputStream streamToWrite;
public RedirectStandardInputThread(OutputStream streamToWrite) {
this.streamToWrite = streamToWrite;
}
@Override
public void run() {
try {
int c = -1;
while ((c = System.in.read()) != -1) {
streamToWrite.write(c);
streamToWrite.flush();
}
} catch (IOException ex) {
}
}
}
@Override
public void run() {
try {
int c = -1;
while ((c = System.in.read()) != -1) {
streamToWrite.write(c);
streamToWrite.flush();
}
} catch (IOException ex) {
}
}
}
}
......@@ -261,7 +261,6 @@ public class SessionManagerImpl implements SessionManager {
@Override
public void saveSite(Site site) throws PersistenceDeviceException, NameExistsException {
SiteEntity oldEntity = (SiteEntity) site;
SiteEntity entity = (SiteEntity) site;
SiteEntityJpaController siteController = new SiteEntityJpaController();
if (entity.getId() == null) {
......
......@@ -33,6 +33,9 @@
*/
package org.cnrs.lam.dis.etc.ui.swing.instrument;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import org.cnrs.lam.dis.etc.datamodel.ComponentInfo;
import org.cnrs.lam.dis.etc.ui.generic.InstrumentListenerHolder;
......@@ -41,8 +44,9 @@ import org.cnrs.lam.dis.etc.ui.generic.InstrumentListenerHolder;
* @author Nikolaos Apostolakos
*/
public class NewInstrumentDialog extends javax.swing.JDialog {
/** Creates new form NewInstrumentDialog */
private static final long serialVersionUID = 4124119490194282525L;
/** Creates new form NewInstrumentDialog */
public NewInstrumentDialog() {
super();
initComponents();
......@@ -54,7 +58,6 @@ public class NewInstrumentDialog extends javax.swing.JDialog {
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
......@@ -66,7 +69,7 @@ public class NewInstrumentDialog extends javax.swing.JDialog {
cancelButton = new javax.swing.JButton();
createButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/cnrs/lam/dis/etc/ui/swing/messages"); // NOI18N
setTitle(bundle.getString("NEW_INSTRUMENT_DIALOG_TITLE")); // NOI18N
......@@ -160,12 +163,22 @@ public class NewInstrumentDialog extends javax.swing.JDialog {
);
pack();
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
clean();
}
});
}// </editor-fold>//GEN-END:initComponents
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
nameTextField.setText("");
private void clean() {
nameTextField.setText("");
descriptionTextField.setText("");
setVisible(false);
}
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
clean();
}//GEN-LAST:event_cancelButtonActionPerformed
private void createButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createButtonActionPerformed
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment