@ -7,18 +7,15 @@ import java.awt.Dimension;
import java.awt.event.ActionEvent ;
import java.awt.event.ActionEvent ;
import java.awt.event.ActionListener ;
import java.awt.event.ActionListener ;
import javax.swing.AbstractButton ;
import javax.swing.ButtonGroup ;
import javax.swing.ButtonGroup ;
import javax.swing.JComboBox ;
import javax.swing.JComboBox ;
import javax.swing.J Component ;
import javax.swing.J FormattedTextField ;
import javax.swing.JLabel ;
import javax.swing.JLabel ;
import javax.swing.JOptionPane ;
import javax.swing.JPanel ;
import javax.swing.JPanel ;
import javax.swing.JRadioButton ;
import javax.swing.JRadioButton ;
import javax.swing.JTextField ;
import javax.swing.event.CaretEvent ;
import javax.swing.event.CaretEvent ;
import javax.swing.event.CaretListener ;
import javax.swing.event.CaretListener ;
import javax.swing.event.ChangeEvent ;
import javax.swing.event.ChangeListener ;
import leaf.ui.LeafButton ;
import leaf.ui.LeafButton ;
import leaf.ui.LeafIconButton ;
import leaf.ui.LeafIconButton ;
@ -26,31 +23,35 @@ import siprp.database.cayenne.objects.HsRelatorioPostoRisco;
import siprp.database.cayenne.objects.HsRelatorioRiscoValorQualitativo ;
import siprp.database.cayenne.objects.HsRelatorioRiscoValorQualitativo ;
import siprp.logic.HigieneSegurancaLogic ;
import siprp.logic.HigieneSegurancaLogic ;
import static com.evolute.utils.strings.UnicodeLatin1Map.* ;
public class GerirValoresRiscoPanel extends JPanel implements ActionListener , CaretListener
public class GerirValoresRiscoPanel extends JPanel implements ActionListener , CaretListener
{
{
private static final long serialVersionUID = 1L ;
private static final long serialVersionUID = 1L ;
private static final String ICON_NAME_SAVE = "siprp/higiene/gestao/riscos/save.png" ;
private static final String ICON_NAME_SAVE = "siprp/higiene/gestao/riscos/save.png" ;
private static final String ICON_NAME_REVERT = "siprp/higiene/gestao/riscos/revert.png" ;
private static final String ICON_NAME_REVERT = "siprp/higiene/gestao/riscos/revert.png" ;
public static final String VALUE_CHANGED = "VALUE_CHANGED" ;
private final JRadioButton radioValorQuantitativo = new JRadioButton ( ) ;
private final JRadioButton radioValorQuantitativo = new JRadioButton ( ) ;
private final JRadioButton radioValorQualitativo = new JRadioButton ( ) ;
private final JRadioButton radioValorQualitativo = new JRadioButton ( ) ;
private final J TextField textSeveridade = new J TextField( ) ;
private final J Formatted TextField textSeveridade = new J Formatted TextField( ) ;
private final J TextField textProbabilidade = new J TextField( ) ;
private final J Formatted TextField textProbabilidade = new J Formatted TextField( ) ;
private final JComboBox comboValorQualitativo = new JComboBox ( ) ;
private final JComboBox comboValorQualitativo = new JComboBox ( ) ;
private final LeafButton buttonSave = LeafIconButton . createButton ( ICON_NAME_SAVE ) ;
private final LeafButton buttonSave = LeafIconButton . createButton ( ICON_NAME_SAVE ) ;
private final LeafButton buttonRevert = LeafIconButton . createButton ( ICON_NAME_REVERT ) ;
private final LeafButton buttonRevert = LeafIconButton . createButton ( ICON_NAME_REVERT ) ;
private final ButtonGroup bg = new ButtonGroup ( ) ;
private final ButtonGroup bg = new ButtonGroup ( ) ;
private HsRelatorioPostoRisco valoresRisco = null ;
private HsRelatorioPostoRisco valoresRisco = null ;
public GerirValoresRiscoPanel ( )
public GerirValoresRiscoPanel ( )
@ -61,7 +62,7 @@ public class GerirValoresRiscoPanel extends JPanel implements ActionListener, Ca
placeComponents ( ) ;
placeComponents ( ) ;
loadValoresQualitativos ( ) ;
loadValoresQualitativos ( ) ;
}
}
private void startupListeners ( )
private void startupListeners ( )
{
{
radioValorQualitativo . addActionListener ( this ) ;
radioValorQualitativo . addActionListener ( this ) ;
@ -85,8 +86,9 @@ public class GerirValoresRiscoPanel extends JPanel implements ActionListener, Ca
refresh ( ) ;
refresh ( ) ;
}
}
} ) ;
} ) ;
}
}
private void startupComponents ( )
private void startupComponents ( )
{
{
textSeveridade . setPreferredSize ( new Dimension ( 30 , 0 ) ) ;
textSeveridade . setPreferredSize ( new Dimension ( 30 , 0 ) ) ;
@ -96,41 +98,43 @@ public class GerirValoresRiscoPanel extends JPanel implements ActionListener, Ca
bg . add ( radioValorQualitativo ) ;
bg . add ( radioValorQualitativo ) ;
bg . add ( radioValorQuantitativo ) ;
bg . add ( radioValorQuantitativo ) ;
}
}
private void startupLayout ( )
private void startupLayout ( )
{
{
TableLayout layout = new TableLayout (
TableLayout layout = new TableLayout ( new double [ ] {
new double [ ] { TableLayout . MINIMUM , TableLayout . MINIMUM , TableLayout . PREFERRED , TableLayout . FILL , TableLayout . MINIMUM , TableLayout . PREFERRED , TableLayout . FILL } ,
TableLayout . MINIMUM , TableLayout . MINIMUM , TableLayout . PREFERRED , TableLayout . FILL , TableLayout . MINIMUM , TableLayout . PREFERRED , TableLayout . FILL
new double [ ] { TableLayout . MINIMUM , TableLayout . MINIMUM , TableLayout . MINIMUM }
} , new double [ ] {
) ;
TableLayout . MINIMUM , TableLayout . MINIMUM , TableLayout . MINIMUM
} ) ;
layout . setVGap ( 5 ) ;
layout . setVGap ( 5 ) ;
layout . setHGap ( 5 ) ;
layout . setHGap ( 5 ) ;
setLayout ( layout ) ;
setLayout ( layout ) ;
}
}
private void placeComponents ( )
private void placeComponents ( )
{
{
TableLayout layout = new TableLayout (
TableLayout layout = new TableLayout ( new double [ ] {
new double [ ] { TableLayout . FILL , TableLayout . MINIMUM , TableLayout . MINIMUM } ,
TableLayout . FILL , TableLayout . MINIMUM , TableLayout . MINIMUM
new double [ ] { TableLayout . MINIMUM }
} , new double [ ] {
) ;
TableLayout . MINIMUM
} ) ;
layout . setVGap ( 5 ) ;
layout . setVGap ( 5 ) ;
layout . setHGap ( 5 ) ;
layout . setHGap ( 5 ) ;
JPanel panel = new JPanel ( ) ;
JPanel panel = new JPanel ( ) ;
panel . setLayout ( layout ) ;
panel . setLayout ( layout ) ;
panel . add ( buttonSave , new TableLayoutConstraints ( 1 , 0 ) ) ;
panel . add ( buttonSave , new TableLayoutConstraints ( 1 , 0 ) ) ;
panel . add ( buttonRevert , new TableLayoutConstraints ( 2 , 0 ) ) ;
panel . add ( buttonRevert , new TableLayoutConstraints ( 2 , 0 ) ) ;
add ( panel , new TableLayoutConstraints ( 1 , 0 , 6 , 0 ) ) ;
add ( panel , new TableLayoutConstraints ( 1 , 0 , 6 , 0 ) ) ;
add ( radioValorQuantitativo , new TableLayoutConstraints ( 0 , 1 ) ) ;
add ( radioValorQuantitativo , new TableLayoutConstraints ( 0 , 1 ) ) ;
add ( new JLabel ( "Severidade" ) , new TableLayoutConstraints ( 1 , 1 ) ) ;
add ( new JLabel ( "Severidade" ) , new TableLayoutConstraints ( 1 , 1 ) ) ;
add ( textSeveridade , new TableLayoutConstraints ( 2 , 1 ) ) ;
add ( textSeveridade , new TableLayoutConstraints ( 2 , 1 ) ) ;
add ( new JLabel ( "Probabilidade" ) , new TableLayoutConstraints ( 4 , 1 ) ) ;
add ( new JLabel ( "Probabilidade" ) , new TableLayoutConstraints ( 4 , 1 ) ) ;
add ( textProbabilidade , new TableLayoutConstraints ( 5 , 1 ) ) ;
add ( textProbabilidade , new TableLayoutConstraints ( 5 , 1 ) ) ;
add ( radioValorQualitativo , new TableLayoutConstraints ( 0 , 2 ) ) ;
add ( radioValorQualitativo , new TableLayoutConstraints ( 0 , 2 ) ) ;
add ( comboValorQualitativo , new TableLayoutConstraints ( 1 , 2 , 5 , 2 ) ) ;
add ( comboValorQualitativo , new TableLayoutConstraints ( 1 , 2 , 5 , 2 ) ) ;
}
}
private void loadValoresQualitativos ( )
private void loadValoresQualitativos ( )
{
{
comboValorQualitativo . removeAllItems ( ) ;
comboValorQualitativo . removeAllItems ( ) ;
@ -140,7 +144,7 @@ public class GerirValoresRiscoPanel extends JPanel implements ActionListener, Ca
}
}
}
}
private void refresh ( )
void refresh ( )
{
{
if ( valoresRisco ! = null )
if ( valoresRisco ! = null )
{
{
@ -149,7 +153,7 @@ public class GerirValoresRiscoPanel extends JPanel implements ActionListener, Ca
radioValorQualitativo . setSelected ( qualitativo ) ;
radioValorQualitativo . setSelected ( qualitativo ) ;
String severidade = ( valoresRisco . getSeveridade ( ) = = null ? null : valoresRisco . getSeveridade ( ) + "" ) ;
String severidade = ( valoresRisco . getSeveridade ( ) = = null ? null : valoresRisco . getSeveridade ( ) + "" ) ;
String probabilidade = ( valoresRisco . getProbabilidade ( ) = = null ? null : valoresRisco . getProbabilidade ( ) + "" ) ;
String probabilidade = ( valoresRisco . getProbabilidade ( ) = = null ? null : valoresRisco . getProbabilidade ( ) + "" ) ;
textSeveridade . setText ( severidade ) ;
textSeveridade . setText ( severidade ) ;
textProbabilidade . setText ( probabilidade ) ;
textProbabilidade . setText ( probabilidade ) ;
if ( valoresRisco . getToHsRelatorioRiscoValorQualitativo ( ) ! = null )
if ( valoresRisco . getToHsRelatorioRiscoValorQualitativo ( ) ! = null )
{
{
@ -163,7 +167,7 @@ public class GerirValoresRiscoPanel extends JPanel implements ActionListener, Ca
textProbabilidade . setText ( null ) ;
textProbabilidade . setText ( null ) ;
}
}
}
}
private void setEnabled ( )
private void setEnabled ( )
{
{
if ( isEnabled ( ) )
if ( isEnabled ( ) )
@ -178,11 +182,11 @@ public class GerirValoresRiscoPanel extends JPanel implements ActionListener, Ca
boolean changes = false ;
boolean changes = false ;
boolean wasQual = valoresRisco . getToHsRelatorioRiscoValorQualitativo ( ) ! = null ;
boolean wasQual = valoresRisco . getToHsRelatorioRiscoValorQualitativo ( ) ! = null ;
boolean isQual = radioValorQualitativo . isSelected ( ) ;
boolean isQual = radioValorQualitativo . isSelected ( ) ;
if ( ! isQual )
if ( ! isQual )
{
{
changes = wasQual ;
changes = wasQual ;
if ( ! changes )
if ( ! changes )
{
{
boolean probChanged = false ;
boolean probChanged = false ;
boolean sevChanged = false ;
boolean sevChanged = false ;
String prob = textProbabilidade . getText ( ) ;
String prob = textProbabilidade . getText ( ) ;
@ -193,7 +197,7 @@ public class GerirValoresRiscoPanel extends JPanel implements ActionListener, Ca
}
}
else
else
{
{
probChanged = ! prob . equals ( valoresRisco . getProbabilidade ( ) = = null ? "" : valoresRisco . getProbabilidade ( ) + "" ) ;
probChanged = ! prob . equals ( valoresRisco . getProbabilidade ( ) = = null ? "" : valoresRisco . getProbabilidade ( ) + "" ) ;
}
}
if ( sev = = null )
if ( sev = = null )
{
{
@ -201,7 +205,7 @@ public class GerirValoresRiscoPanel extends JPanel implements ActionListener, Ca
}
}
else
else
{
{
sevChanged = ! sev . equals ( valoresRisco . getSeveridade ( ) = = null ? "" : valoresRisco . getSeveridade ( ) + "" ) ;
sevChanged = ! sev . equals ( valoresRisco . getSeveridade ( ) = = null ? "" : valoresRisco . getSeveridade ( ) + "" ) ;
}
}
changes = probChanged | | sevChanged ;
changes = probChanged | | sevChanged ;
}
}
@ -209,8 +213,8 @@ public class GerirValoresRiscoPanel extends JPanel implements ActionListener, Ca
else
else
{
{
changes = ! wasQual ;
changes = ! wasQual ;
if ( ! changes )
if ( ! changes )
{
{
changes = ! comboValorQualitativo . getSelectedItem ( ) . equals ( valoresRisco . getToHsRelatorioRiscoValorQualitativo ( ) ) ;
changes = ! comboValorQualitativo . getSelectedItem ( ) . equals ( valoresRisco . getToHsRelatorioRiscoValorQualitativo ( ) ) ;
}
}
}
}
@ -229,14 +233,19 @@ public class GerirValoresRiscoPanel extends JPanel implements ActionListener, Ca
textSeveridade . setEnabled ( false ) ;
textSeveridade . setEnabled ( false ) ;
}
}
}
}
public void setRelatorioPostoRisco ( HsRelatorioPostoRisco rel )
public void setRelatorioPostoRisco ( HsRelatorioPostoRisco rel )
{
{
this . valoresRisco = rel ;
this . valoresRisco = rel ;
refresh ( ) ;
refresh ( ) ;
setEnabled ( ) ;
setEnabled ( ) ;
}
}
private void error ( boolean probabilidade )
{
JOptionPane . showMessageDialog ( this , "Valor inv" + aacute + "lido para " + ( probabilidade ? "'Probabilidade'" : "'Severidade'" ) + "." , "Erro" , JOptionPane . ERROR_MESSAGE , null ) ;
}
private void save ( )
private void save ( )
{
{
if ( valoresRisco ! = null )
if ( valoresRisco ! = null )
@ -248,26 +257,48 @@ public class GerirValoresRiscoPanel extends JPanel implements ActionListener, Ca
else
else
{
{
valoresRisco . setToHsRelatorioRiscoValorQualitativo ( null ) ;
valoresRisco . setToHsRelatorioRiscoValorQualitativo ( null ) ;
Integer probabilidade = 0 ;
Integer probabilidade = null ;
Integer severidade = 0 ;
Integer severidade = null ;
try {
boolean ok = true ;
probabilidade = new Integer ( textProbabilidade . getText ( ) ! = null ? textProbabilidade . getText ( ) : "0" ) ;
if ( textProbabilidade . getText ( ) ! = null & & ! textProbabilidade . getText ( ) . trim ( ) . equals ( "" ) )
}
catch ( NumberFormatException e1 )
{
{
e1 . printStackTrace ( ) ;
try
}
{
try {
probabilidade = new Integer ( textProbabilidade . getText ( ) ) ;
severidade = new Integer ( textSeveridade . getText ( ) ! = null ? textSeveridade . getText ( ) : "0" ) ;
} catch ( NumberFormatException e1 )
{
ok = false ;
}
if ( ! ok | | ! HigieneSegurancaLogic . isProbabilidadeValida ( probabilidade ) )
{
error ( true ) ;
}
}
}
catch ( NumberFormatException e2 )
if( textSeveridade . getText ( ) ! = null & & ! textSeveridade . getText ( ) . trim ( ) . equals ( "" ) )
{
{
e2 . printStackTrace ( ) ;
if ( ok )
{
try
{
severidade = new Integer ( textSeveridade . getText ( ) ) ;
} catch ( NumberFormatException e2 )
{
ok = false ;
}
if ( ! ok | | ! HigieneSegurancaLogic . isSeveridadeValida ( severidade ) )
{
error ( false ) ;
}
}
}
}
valoresRisco . setProbabilidade ( probabilidade ) ;
boolean pvalid = HigieneSegurancaLogic . isProbabilidadeValida ( probabilidade ) ;
valoresRisco . setSeveridade ( severidade ) ;
boolean svalid = HigieneSegurancaLogic . isSeveridadeValida ( severidade ) ;
valoresRisco . setProbabilidade ( pvalid & & svalid ? probabilidade : null ) ;
valoresRisco . setSeveridade ( pvalid & & svalid ? severidade : null ) ;
}
}
valoresRisco . save ( ) ;
valoresRisco . save ( ) ;
firePropertyChange ( VALUE_CHANGED , null , valoresRisco ) ;
refresh ( ) ;
refresh ( ) ;
setEnabled ( ) ;
setEnabled ( ) ;
}
}