@ -1,6 +1,6 @@
package siprp.higiene.gestao.riscos ;
package siprp.higiene.gestao.riscos ;
import static com.evolute.utils.strings.UnicodeLatin1Map. atilde ;
import static com.evolute.utils.strings.UnicodeLatin1Map. * ;
import static com.evolute.utils.strings.UnicodeLatin1Map.ccedil ;
import static com.evolute.utils.strings.UnicodeLatin1Map.ccedil ;
import info.clearthought.layout.TableLayout ;
import info.clearthought.layout.TableLayout ;
import info.clearthought.layout.TableLayoutConstraints ;
import info.clearthought.layout.TableLayoutConstraints ;
@ -26,6 +26,7 @@ import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel ;
import javax.swing.tree.TreeSelectionModel ;
import leaf.ui.LeafButton ;
import leaf.ui.LeafButton ;
import leaf.ui.LeafError ;
import leaf.ui.TreeTools ;
import leaf.ui.TreeTools ;
import siprp.database.cayenne.objects.HsMedida ;
import siprp.database.cayenne.objects.HsMedida ;
import siprp.database.cayenne.objects.HsRisco ;
import siprp.database.cayenne.objects.HsRisco ;
@ -157,14 +158,15 @@ public class GerirRiscosPanel extends JPanel
removerMedida ( ) ;
removerMedida ( ) ;
}
}
} ) ;
} ) ;
tree . getSelectionModel ( ) . addTreeSelectionListener ( new TreeSelectionListener ( ) {
tree . getSelectionModel ( ) . addTreeSelectionListener ( new TreeSelectionListener ( )
{
@Override
@Override
public void valueChanged ( TreeSelectionEvent e )
public void valueChanged ( TreeSelectionEvent e )
{
{
setEnabled ( ) ;
setEnabled ( ) ;
selectCard ( ) ;
selectCard ( ) ;
}
}
} ) ;
} ) ;
panelDataMedida . addPropertyChangeListener ( GerirMedidaPanel . MEDIDA_CHANGED , new PropertyChangeListener ( )
panelDataMedida . addPropertyChangeListener ( GerirMedidaPanel . MEDIDA_CHANGED , new PropertyChangeListener ( )
{
{
@Override
@Override
@ -175,136 +177,198 @@ public class GerirRiscosPanel extends JPanel
refresh ( ) ;
refresh ( ) ;
}
}
}
}
} ) ;
} ) ;
}
}
private void criarTema ( )
private void criarTema ( )
{
{
String temaString = JOptionPane . showInputDialog ( this , "Criar tema" , "Descri" + ccedil + atilde + "o" , JOptionPane . QUESTION_MESSAGE ) ;
try
if ( temaString ! = null )
{
{
HsRiscoTema tema = new HsRiscoTema ( ) ;
String temaString = JOptionPane . showInputDialog ( this , "Criar tema" , "Descri" + ccedil + atilde + "o" , JOptionPane . QUESTION_MESSAGE ) ;
tema . setDescription ( temaString ) ;
if ( temaString ! = null )
tema . save ( ) ;
{
refresh ( ) ;
HsRiscoTema tema = new HsRiscoTema ( ) ;
tema . setDescription ( temaString ) ;
tema . save ( ) ;
refresh ( ) ;
}
} catch ( Exception e )
{
LeafError . error ( e ) ;
}
}
}
}
private void editarTema ( )
private void editarTema ( )
{
{
HsRiscoTema tema = getSelectedTema ( ) ;
try
if ( tema ! = null )
{
{
String temaString = JOptionPane . showInputDialog ( this , "Editar tema" , tema . getDescription ( ) ) ;
HsRiscoTema tema = getSelectedTema ( ) ;
if ( tema String ! = null )
if ( tema ! = null )
{
{
tema . setDescription ( temaString ) ;
String temaString = JOptionPane . showInputDialog ( this , "Editar tema" , tema . getDescription ( ) ) ;
tema . save ( ) ;
if ( temaString ! = null )
refresh ( ) ;
{
tema . setDescription ( temaString ) ;
tema . save ( ) ;
refresh ( ) ;
}
}
}
} catch ( Exception e )
{
LeafError . error ( e ) ;
}
}
}
}
private void removerTema ( )
private void removerTema ( )
{
{
HsRiscoTema tema = getSelectedTema ( ) ;
try
if ( tema ! = null )
{
{
tema . delete ( ) ;
HsRiscoTema tema = getSelectedTema ( ) ;
refresh ( ) ;
if ( tema ! = null )
{
tema . delete ( ) ;
refresh ( ) ;
}
} catch ( Exception e )
{
LeafError . error ( e ) ;
}
}
}
}
private void criarRisco ( )
private void criarRisco ( )
{
{
HsRiscoTema tema = getSelectedTema ( ) ;
try
if ( tema = = null )
{
{
HsRisco risco = getSelectedRisco ( ) ;
HsRisco Tema tema = getSelectedTema ( ) ;
if ( risco ! = null )
if ( tema = = null )
{
{
tema = risco . getToHsRiscoTema ( ) ;
HsRisco risco = getSelectedRisco ( ) ;
if ( risco ! = null )
{
tema = risco . getToHsRiscoTema ( ) ;
}
else
{
HsRiscoMedida medida = getSelectedMedida ( ) ;
if ( medida ! = null )
{
tema = medida . getToHsRisco ( ) . getToHsRiscoTema ( ) ;
}
}
}
}
else
if( tema ! = null )
{
{
HsRiscoMedida medida = getSelectedMedida ( ) ;
String riscoString = JOptionPane . showInputDialog ( this , "Criar risco" , "Descri" + ccedil + atilde + "o" , JOptionPane . QUESTION_MESSAGE ) ;
if ( medida ! = null )
if ( riscoString ! = null )
{
{
tema = medida . getToHsRisco ( ) . getToHsRiscoTema ( ) ;
HsRisco risco = new HsRisco ( ) ;
risco . setDescription ( riscoString ) ;
risco . setToHsRiscoTema ( tema ) ;
tema . save ( ) ;
refresh ( ) ;
}
}
}
}
} catch ( Exception e )
{
LeafError . error ( e ) ;
}
}
if ( tema ! = null )
}
private void editarRisco ( )
{
try
{
{
String riscoString = JOptionPane . showInputDialog ( this , "Criar risco" , "Descri" + ccedil + atilde + "o" , JOptionPane . QUESTION_MESSAGE ) ;
HsRisco risco = getSelectedRisco ( ) ;
if ( riscoString ! = null )
if ( risco ! = null )
{
{
HsRisco risco = new HsRisco ( ) ;
String riscoString = JOptionPane . showInputDialog ( this , "Editar risco" , risco . getDescription ( ) ) ;
risco . setDescription ( riscoString ) ;
if ( riscoString ! = null )
risco . setToHsRiscoTema ( tema ) ;
{
tema . save ( ) ;
risco . setDescription ( riscoString ) ;
refresh ( ) ;
risco . save ( ) ;
refresh ( ) ;
}
}
}
} catch ( Exception e )
{
LeafError . error ( e ) ;
}
}
}
}
private void edita rRisco( )
private void remov erRisco( )
{
{
HsRisco risco = getSelectedRisco ( ) ;
try
if ( risco ! = null )
{
{
String riscoString = JOptionPane . showInputDialog ( this , "Editar risco" , risco . getDescription ( ) ) ;
HsRisco risco = getSelectedRisco ( ) ;
if ( risco String ! = null )
if ( risco ! = null & & removerRiscoOK ( risco ) )
{
{
risco . setDescription ( riscoString ) ;
risco . delete ( ) ;
risco . save ( ) ;
refresh ( ) ;
refresh ( ) ;
}
}
}
}
catch ( Exception e )
{
LeafError . error ( e ) ;
}
}
}
private void removerRisco ( )
private boolean removerRiscoOK ( HsRisco risco )
{
{
HsRisco risco = getSelectedRisco ( ) ;
boolean result = true ;
if ( risco ! = null )
if ( risco . getHsRiscoEmpresaArray ( ) . size ( ) > 0 )
{
{
risco . delete ( ) ;
if ( JOptionPane . NO_OPTION = = JOptionPane . showConfirmDialog ( this , "Este risco est" + aacute + " associado a uma ou mais empresas, \n tem a certeza que o deseja remover?" , "Aviso" , JOptionPane . YES_NO_OPTION , JOptionPane . WARNING_MESSAGE ) )
refresh ( ) ;
{
result = false ;
}
}
}
return result ;
}
}
private void criarMedida ( )
private void criarMedida ( )
{
{
HsRisco risco = getSelectedRisco ( ) ;
try
if ( risco = = null )
{
{
HsRisco Medida medida = getSelectedMedida ( ) ;
HsRisco risco = getSelectedRisco ( ) ;
if ( medida ! = null )
if ( risco = = null )
{
{
risco = medida . getToHsRisco ( ) ;
HsRiscoMedida medida = getSelectedMedida ( ) ;
if ( medida ! = null )
{
risco = medida . getToHsRisco ( ) ;
}
}
}
}
if ( risco ! = null )
if ( risco ! = null )
{
HsMedida medida = new HsMedida ( ) ;
medida . setDescription ( "" ) ;
medida . setRequesitosLegais ( "" ) ;
medida . save ( ) ;
HsRiscoMedida rel = new HsRiscoMedida ( ) ;
rel . setToHsRisco ( risco ) ;
rel . setToHsMedida ( medida ) ;
rel . save ( ) ;
refresh ( ) ;
}
} catch ( Exception e )
{
{
HsMedida medida = new HsMedida ( ) ;
LeafError . error ( e ) ;
medida . setDescription ( "" ) ;
medida . setRequesitosLegais ( "" ) ;
medida . save ( ) ;
HsRiscoMedida rel = new HsRiscoMedida ( ) ;
rel . setToHsRisco ( risco ) ;
rel . setToHsMedida ( medida ) ;
rel . save ( ) ;
refresh ( ) ;
}
}
}
}
private void removerMedida ( )
private void removerMedida ( )
{
{
HsRiscoMedida medida = getSelectedMedida ( ) ;
try
if ( medida ! = null )
{
{
medida . delete ( ) ;
HsRiscoMedida medida = getSelectedMedida ( ) ;
refresh ( ) ;
if ( medida ! = null )
{
medida . delete ( ) ;
refresh ( ) ;
}
} catch ( Exception e )
{
LeafError . error ( e ) ;
}
}
}
}
@ -364,42 +428,47 @@ public class GerirRiscosPanel extends JPanel
private void startupLayout ( )
private void startupLayout ( )
{
{
TableLayout layout = new TableLayout (
TableLayout layout = new TableLayout ( new double [ ] {
new double [ ] { TableLayout . MINIMUM , TableLayout . PREFERRED , TableLayout . FILL } ,
TableLayout . MINIMUM , TableLayout . PREFERRED , TableLayout . FILL
new double [ ] { TableLayout . FILL }
} , new double [ ] {
) ;
TableLayout . FILL
} ) ;
layout . setHGap ( 5 ) ;
layout . setHGap ( 5 ) ;
layout . setVGap ( 5 ) ;
layout . setVGap ( 5 ) ;
setLayout ( layout ) ;
setLayout ( layout ) ;
layout = new TableLayout (
layout = new TableLayout ( new double [ ] {
new double [ ] { TableLayout . MINIMUM } ,
TableLayout . MINIMUM
new double [ ] { TableLayout . MINIMUM , TableLayout . MINIMUM , TableLayout . MINIMUM , TableLayout . FILL }
} , new double [ ] {
) ;
TableLayout . MINIMUM , TableLayout . MINIMUM , TableLayout . MINIMUM , TableLayout . FILL
} ) ;
layout . setHGap ( 5 ) ;
layout . setHGap ( 5 ) ;
layout . setVGap ( 5 ) ;
layout . setVGap ( 5 ) ;
panelButtons . setLayout ( layout ) ;
panelButtons . setLayout ( layout ) ;
layout = new TableLayout (
layout = new TableLayout ( new double [ ] {
new double [ ] { TableLayout . FILL } ,
TableLayout . FILL
new double [ ] { TableLayout . FILL }
} , new double [ ] {
) ;
TableLayout . FILL
} ) ;
layout . setHGap ( 5 ) ;
layout . setHGap ( 5 ) ;
layout . setVGap ( 5 ) ;
layout . setVGap ( 5 ) ;
panelTree . setLayout ( layout ) ;
panelTree . setLayout ( layout ) ;
layout = new TableLayout (
layout = new TableLayout ( new double [ ] {
new double [ ] { TableLayout . FILL } ,
TableLayout . FILL
new double [ ] { TableLayout . FILL }
} , new double [ ] {
) ;
TableLayout . FILL
} ) ;
layout . setHGap ( 5 ) ;
layout . setHGap ( 5 ) ;
layout . setVGap ( 5 ) ;
layout . setVGap ( 5 ) ;
panelDataTema . setLayout ( layout ) ;
panelDataTema . setLayout ( layout ) ;
layout = new TableLayout (
layout = new TableLayout ( new double [ ] {
new double [ ] { TableLayout . FILL } ,
TableLayout . FILL
new double [ ] { TableLayout . FILL }
} , new double [ ] {
) ;
TableLayout . FILL
} ) ;
layout . setHGap ( 5 ) ;
layout . setHGap ( 5 ) ;
layout . setVGap ( 5 ) ;
layout . setVGap ( 5 ) ;
panelDataRisco . setLayout ( layout ) ;
panelDataRisco . setLayout ( layout ) ;
@ -441,7 +510,6 @@ public class GerirRiscosPanel extends JPanel
add ( panelData , new TableLayoutConstraints ( 2 , 0 ) ) ;
add ( panelData , new TableLayoutConstraints ( 2 , 0 ) ) ;
}
}
private void selectCard ( )
private void selectCard ( )
{
{
HsRiscoTema tema = getSelectedTema ( ) ;
HsRiscoTema tema = getSelectedTema ( ) ;