Skip to content
This repository has been archived by the owner on Nov 28, 2019. It is now read-only.

Commit

Permalink
Merge pull request #3 from xman40100/andres
Browse files Browse the repository at this point in the history
Añadida detección para cambios no guardados.
  • Loading branch information
xman40100 authored Feb 20, 2019
2 parents fa3cca0 + 2c16389 commit 2623227
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/technomotica/java/forms/Configuration.form
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<Events>
<EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="formWindowClosing"/>
</Events>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
Expand Down
31 changes: 29 additions & 2 deletions src/technomotica/java/forms/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ private void initComponents() {

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Configuración - Tech Domotica");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});

jButton1.setText("Cerrar");
jButton1.addActionListener(new java.awt.event.ActionListener() {
Expand Down Expand Up @@ -208,8 +213,7 @@ private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
}
}//GEN-LAST:event_jButton3ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
private void saveConfig() {
if(!tHostPort.getText().isEmpty() && !txtHostname.getText().isEmpty()) {
int confirm = JOptionPane.showConfirmDialog(null, "¿Estás seguro de que deseas guardar esta configuración?", "Guardar configuración", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if(confirm == JOptionPane.YES_OPTION) {
Expand All @@ -222,8 +226,31 @@ private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
}
}
else JOptionPane.showMessageDialog(null, "Uno de los campos de configuración está vacío.", "No se puede guardar", JOptionPane.ERROR_MESSAGE);
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
saveConfig();
}//GEN-LAST:event_jButton2ActionPerformed

private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
// TODO add your handling code here:
String daemonOG = cfg.getConfigKey("daemon");
String portOG = cfg.getConfigKey("port");
String hostnameOG = cfg.getConfigKey("hostname");

String currentDaemon = (tEjecucion2do.isSelected()) ? "true" : "false";
if(!txtHostname.getText().equalsIgnoreCase(hostnameOG) || !tHostPort.getText().equalsIgnoreCase(portOG) || !currentDaemon.equalsIgnoreCase(daemonOG)) {
int confirm = JOptionPane.showConfirmDialog(null, "Hay cambios pendientes para guardar. ¿Deseas guardarlos ahora?", "Configuración no guardada", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if(confirm == JOptionPane.YES_OPTION) {
saveConfig();
}
else {
this.dispose();
}
}
}//GEN-LAST:event_formWindowClosing

/**
* @param args the command line arguments
*/
Expand Down

0 comments on commit 2623227

Please sign in to comment.