@ -15,6 +15,8 @@ import java.awt.Cursor;
import java.awt.Dimension ;
import java.awt.event.ActionEvent ;
import java.awt.event.ActionListener ;
import java.beans.PropertyChangeEvent ;
import java.beans.PropertyChangeListener ;
import java.io.File ;
import java.io.FileOutputStream ;
import java.text.SimpleDateFormat ;
@ -36,10 +38,13 @@ import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener ;
import javax.swing.event.ChangeEvent ;
import javax.swing.event.ChangeListener ;
import javax.swing.text.AbstractDocument.LeafElement ;
import leaf.data.Validator ;
import leaf.ui.LeafButton ;
import leaf.ui.LeafDialog ;
import leaf.ui.LeafIconButton ;
import leaf.ui.LeafTextAreaEditor ;
import siprp.database.cayenne.objects.HsEmailEstabelecimento ;
import siprp.database.cayenne.objects.HsRelatorio ;
import siprp.database.cayenne.objects.MarcacoesEstabelecimento ;
@ -55,6 +60,8 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
{
private static final long serialVersionUID = 1L ;
private static final String DEFAULT_FUNCIONARIOS_TEXT = "A empresa supracitada possui ? funcionários, sendo que ? destes exercem actividades na zona de produtos frescos." ;
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" ;
@ -84,9 +91,20 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
private final LeafIconButton buttonPdfRelatorio = LeafIconButton . createButton ( "Relat" + oacute + "rio" , ICON_NAME_PDF ) ;
private final LeafButton buttonRevertPlano = LeafIconButton . createButton ( "Recarregar" , ICON_NAME_UNDO ) ;
private final JTabbedPane tabsRelatorio = new JTabbedPane ( ) ;
private final AdicionarEquipamentosPanel panelEquipamentos = new AdicionarEquipamentosPanel ( ) ;
private final LeafTextAreaEditor panelFuncionarios = new LeafTextAreaEditor ( new Validator < String > ( )
{
@Override
public boolean isValid ( String text )
{
return ! DEFAULT_FUNCIONARIOS_TEXT . equals ( text ) ;
}
} ) ;
private final JTabbedPane tabs = new JTabbedPane ( ) ;
private final JTabbedPane tabs PlanoActuacao = new JTabbedPane ( ) ;
private final PlanoActuacaoPanel panelPlano = new PlanoActuacaoPanel ( ) ;
@ -114,10 +132,11 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
bg . add ( radioInicial ) ;
bg . add ( radioPeriodica ) ;
panelAcompanhantes . setBorder ( BorderFactory . createTitledBorder ( "Pessoas que acompanharam" ) ) ;
panelEquipamentos . setBorder ( BorderFactory . createTitledBorder ( "Equipamentos de medi" + ccedil + atilde + "o" ) ) ;
tabs . addTab ( "Plano de actua" + ccedil + atilde + "o" , panelPlano ) ;
tabs . addTab ( "Legisla" + ccedil + atilde + "o" , panelLegislacao ) ;
tabs . addTab ( "Normaliza" + ccedil + atilde + "o" , panelNormalizacao ) ;
tabsRelatorio . addTab ( "Funcion" + aacute + "rios" , panelFuncionarios ) ;
tabsRelatorio . addTab ( "Equipamentos de medi" + ccedil + atilde + "o" , panelEquipamentos ) ;
tabsPlanoActuacao . addTab ( "Plano de actua" + ccedil + atilde + "o" , panelPlano ) ;
tabsPlanoActuacao . addTab ( "Legisla" + ccedil + atilde + "o" , panelLegislacao ) ;
tabsPlanoActuacao . addTab ( "Normaliza" + ccedil + atilde + "o" , panelNormalizacao ) ;
buttonSave . setToolTipText ( "Guardar" ) ;
buttonRevertText . setToolTipText ( "Reverter" ) ;
buttonRevertPlano . setToolTipText ( "Carregar dados do estabelecimento" ) ;
@ -182,9 +201,9 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
add ( radioPeriodica , new TableLayoutConstraints ( 6 , 1 ) ) ;
add ( new JLabel ( "T" + eacute + "cnico Superior de H.S." ) , new TableLayoutConstraints ( 0 , 2 , 2 , 2 ) ) ;
add ( fieldTecnico , new TableLayoutConstraints ( 3 , 2 , 6 , 2 ) ) ;
add ( panelEquipamentos , new TableLayoutConstraints ( 7 , 1 , 7 , 3 ) ) ;
add ( tabsRelatorio , new TableLayoutConstraints ( 7 , 1 , 7 , 3 ) ) ;
add ( panelAcompanhantes , new TableLayoutConstraints ( 0 , 3 , 6 , 3 ) ) ;
add ( tabs , new TableLayoutConstraints ( 0 , 4 , 7 , 4 ) ) ;
add ( tabs PlanoActuacao , new TableLayoutConstraints ( 0 , 4 , 7 , 4 ) ) ;
}
private void setupListeners ( )
@ -242,6 +261,35 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
revert ( true ) ;
}
} ) ;
panelFuncionarios . addPropertyChangeListener ( LeafTextAreaEditor . ACTION_SAVE , new PropertyChangeListener ( )
{
@Override
public void propertyChange ( PropertyChangeEvent evt )
{
try
{
String text = ( String ) evt . getNewValue ( ) ;
if ( text ! = null & & relatorio ! = null )
{
text = text . trim ( ) ;
if ( text . length ( ) = = 0 )
{
text = null ;
}
else if ( text . equals ( DEFAULT_FUNCIONARIOS_TEXT ) )
{
text = null ;
}
}
relatorio . setFuncionarios ( text ) ;
relatorio . save ( ) ;
}
catch ( Exception e )
{
LeafDialog . error ( e ) ;
}
}
} ) ;
}
protected void revert ( boolean ask )
@ -521,6 +569,7 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
panelPlano . setRelatorio ( relatorio ) ;
panelLegislacao . setRelatorio ( relatorio ) ;
panelNormalizacao . setRelatorio ( relatorio ) ;
panelFuncionarios . setValue ( relatorio = = null ? null : ( relatorio . getFuncionarios ( ) = = null ? DEFAULT_FUNCIONARIOS_TEXT : relatorio . getFuncionarios ( ) ) ) ;
if ( create )
{
this . revert ( false ) ;