diff --git a/trunk/.classpath b/trunk/.classpath
index 01df5748..3a5e13b0 100644
--- a/trunk/.classpath
+++ b/trunk/.classpath
@@ -3,11 +3,9 @@
-
-
@@ -25,10 +23,8 @@
-
-
@@ -36,5 +32,9 @@
+
+
+
+
diff --git a/trunk/SIPRPSoft/src/siprp/higiene/marcacoes/MarcacaoVisitaHSTPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/marcacoes/MarcacaoVisitaHSTPanel.java
index 9bb3b888..9c7f0862 100644
--- a/trunk/SIPRPSoft/src/siprp/higiene/marcacoes/MarcacaoVisitaHSTPanel.java
+++ b/trunk/SIPRPSoft/src/siprp/higiene/marcacoes/MarcacaoVisitaHSTPanel.java
@@ -28,7 +28,7 @@ public class MarcacaoVisitaHSTPanel
private final JLabel dataLabel = new JLabel( "Data da visita", JLabel.RIGHT );
private final JCalendarPanel dataPanel = new JCalendarPanel( null );
private final JButton emailButton = new JButton( "Enviar Email" );
- private final JLabel dataFichaLabel = new JLabel( "Data do Relat\u00f3rio", JLabel.RIGHT );
+ private final JLabel dataFichaLabel = new JLabel( "Data do Relat\u00f3rio(externo)", JLabel.RIGHT );
private final JCalendarPanel dataFichaPanel = new JCalendarPanel( null );
private final JLabel tecnicoLabel = new JLabel( "T\u00e9cnico", JLabel.RIGHT );
private final JComboBox tecnicoList = new JComboBox();
diff --git a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/RelatorioWindow.java b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/RelatorioWindow.java
new file mode 100644
index 00000000..8a3a7762
--- /dev/null
+++ b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/RelatorioWindow.java
@@ -0,0 +1,403 @@
+package siprp.higiene.relatorio;
+
+import static com.evolute.utils.strings.UnicodeLatin1Map.atilde;
+import static com.evolute.utils.strings.UnicodeLatin1Map.ccedil;
+import static com.evolute.utils.strings.UnicodeLatin1Map.oacute;
+import info.clearthought.layout.TableLayout;
+import info.clearthought.layout.TableLayoutConstraints;
+
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.util.List;
+import java.util.Vector;
+
+import javax.swing.BorderFactory;
+import javax.swing.ButtonGroup;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JRadioButton;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+import javax.swing.ListSelectionModel;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+
+import siprp.data.MarcacaoEstabelecimento;
+import siprp.database.cayenne.objects.Empresas;
+import siprp.database.cayenne.objects.Estabelecimentos;
+import siprp.database.cayenne.objects.HsRelatorio;
+import siprp.database.cayenne.objects.HsRelatorioMedida;
+import siprp.database.cayenne.objects.HsRelatorioRisco;
+import siprp.database.cayenne.objects.MarcacoesEstabelecimento;
+import siprp.database.cayenne.providers.MedicinaDAO;
+
+import com.evolute.utils.tables.VectorTableModel;
+import com.evolute.utils.ui.calendar.JCalendarPanel;
+
+public class RelatorioWindow extends JFrame
+{
+ private static final long serialVersionUID = 1L;
+
+ public static final String TITLE = "Relat" + oacute + "rios de Higiene e Seguran" + ccedil + "a no Trabalho";
+
+ public static final Dimension SIZE = new Dimension( 800, 600 );
+
+ private final JComboBox comboEmpresas = new JComboBox();
+
+ private final JComboBox comboEstabelecimentos = new JComboBox();
+
+ private final VectorTableModel modelVisitas = new VectorTableModel( new String[]{ "Data" } );
+
+ private final JTable tableVisitas = new JTable( modelVisitas );
+
+ private final JScrollPane scrollVisitas = new JScrollPane( tableVisitas );
+
+ private final JButton buttonCriarRelatorio = new JButton("Criar Relat"+oacute+"rio");
+
+ private final JPanel panelRelatorio = new JPanel();
+
+ private final JCalendarPanel dateRelatorio = new JCalendarPanel( this );
+
+ private final JPanel panelRiscos = new JPanel();
+
+ private final VectorTableModel modelRiscos = new VectorTableModel( new String[]{ "Riscos" } );
+
+ private final JTable tableRiscos = new JTable( modelRiscos );
+
+ private final JScrollPane scrollRiscos = new JScrollPane( tableRiscos );
+
+ private final JPanel panelRiscoValores = new JPanel();
+
+ private final JRadioButton radioValorQuantitativo = new JRadioButton();
+
+ private final JRadioButton radioValorQualitativo = new JRadioButton();
+
+ private final JTextField textSeveridade = new JTextField();
+
+ private final JTextField textProbabilidade = new JTextField();
+
+ private final JComboBox comboValorQualitativo = new JComboBox();
+
+ private final JCheckBox checkPlanoActuacao = new JCheckBox("Plano de actua" + ccedil + atilde + "o" );
+
+ private final JPanel panelMedidas = new JPanel();
+
+ private final VectorTableModel modelMedidas = new VectorTableModel( new String[]{ "Medidas" } );
+
+ private final JTable tableMedidas = new JTable( modelMedidas );
+
+ private final JScrollPane scrollMedidas = new JScrollPane( tableMedidas );
+
+ private final JTextArea textMedida = new JTextArea();
+
+ private final JTextArea textRequisitosLegais = new JTextArea();
+
+ private final JButton buttonMedidaAdd = new JButton("Adicionar");
+
+ private final JButton buttonMedidaRemove = new JButton("Remover");
+
+ private final JButton buttonSubmeterRelatorio = new JButton( "Submeter Plano de Actua" + ccedil + atilde + "o" );
+
+ public RelatorioWindow()
+ {
+ startupComponents();
+ startupLayout();
+ placeComponents();
+ setupListeners();
+ setTitle( TITLE );
+ setSize( SIZE );
+ loadEmpresas();
+ }
+
+ private void startupComponents()
+ {
+ scrollMedidas.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
+ scrollMedidas.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS );
+ scrollMedidas.setPreferredSize( new Dimension( 150, 0 ) );
+ scrollRiscos.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
+ scrollRiscos.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS );
+ scrollRiscos.setPreferredSize( new Dimension( 300, 0 ) );
+ scrollVisitas.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
+ scrollVisitas.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS );
+ scrollVisitas.setPreferredSize( new Dimension( 200, 0 ) );
+ panelRelatorio.setBorder( BorderFactory.createTitledBorder( "Relat" + oacute + "rio" ) );
+ panelRiscoValores.setBorder( BorderFactory.createTitledBorder( "Valores" ) );
+ panelRiscos.setBorder( BorderFactory.createEtchedBorder() );
+ panelMedidas.setBorder( BorderFactory.createEtchedBorder() );
+ dateRelatorio.setPreferredSize( new Dimension( 150, 0 ) );
+ textSeveridade.setPreferredSize( new Dimension( 30, 0 ) );
+ textProbabilidade.setPreferredSize( new Dimension( 30, 0 ) );
+ tableVisitas.getSelectionModel().setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
+ tableRiscos.getSelectionModel().setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
+ tableMedidas.getSelectionModel().setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
+ ButtonGroup bg = new ButtonGroup();
+ bg.add( radioValorQualitativo );
+ bg.add( radioValorQuantitativo );
+ }
+
+ private void disableAndClearRelatorio( )
+ {
+ dateRelatorio.setEnabled( false );
+ dateRelatorio.clear();
+ tableMedidas.setEnabled( false );
+ tableRiscos.setEnabled( false );
+ radioValorQualitativo.setEnabled( false );
+ radioValorQualitativo.setSelected( false );
+ radioValorQuantitativo.setEnabled( false );
+ radioValorQuantitativo.setSelected( false );
+ textSeveridade.setEnabled( false );
+ textSeveridade.setText( "" );
+ textProbabilidade.setEnabled( false );
+ textProbabilidade.setText( "" );
+ comboValorQualitativo.setEnabled( false );
+ checkPlanoActuacao.setEnabled( false );
+ checkPlanoActuacao.setSelected( false );
+ textMedida.setEnabled( false );
+ textMedida.setText( "" );
+ textRequisitosLegais.setEnabled( false );
+ textRequisitosLegais.setText( "" );
+ buttonMedidaAdd.setEnabled( false );
+ buttonMedidaRemove.setEnabled( false );
+ buttonSubmeterRelatorio.setEnabled( false );
+ modelMedidas.clearAll();
+ modelRiscos.clearAll();
+ }
+
+ private void startupLayout()
+ {
+ TableLayout layout = new TableLayout(
+ new double[]{ TableLayout.PREFERRED, TableLayout.FILL },
+ new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL, TableLayout.MINIMUM }
+ );
+ layout.setVGap( 5 );
+ layout.setHGap( 5 );
+ getContentPane().setLayout( layout );
+
+ layout = new TableLayout(
+ new double[]{ TableLayout.PREFERRED, TableLayout.FILL, TableLayout.PREFERRED },
+ new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL, TableLayout.FILL }
+ );
+ layout.setVGap( 5 );
+ layout.setHGap( 5 );
+ panelRelatorio.setLayout( layout );
+
+ layout = new TableLayout(
+ new double[]{ TableLayout.PREFERRED, TableLayout.FILL },
+ new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL }
+ );
+ layout.setVGap( 5 );
+ layout.setHGap( 5 );
+ panelRiscos.setLayout( layout );
+
+ layout = new TableLayout(
+ new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.PREFERRED, TableLayout.MINIMUM, TableLayout.PREFERRED },
+ new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM }
+ );
+ layout.setVGap( 5 );
+ layout.setHGap( 5 );
+ panelRiscoValores.setLayout( layout );
+
+ layout = new TableLayout(
+ new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.PREFERRED, TableLayout.FILL },
+ new double[]{ TableLayout.MINIMUM, TableLayout.FILL, TableLayout.MINIMUM, TableLayout.FILL, TableLayout.MINIMUM }
+ );
+ layout.setVGap( 5 );
+ layout.setHGap( 5 );
+ panelMedidas.setLayout( layout );
+
+ }
+
+ private void placeComponents()
+ {
+
+ panelRiscoValores.add( radioValorQuantitativo, new TableLayoutConstraints( 0, 0 ) );
+ panelRiscoValores.add( new JLabel("Severidade"), new TableLayoutConstraints( 1, 0 ) );
+ panelRiscoValores.add( textSeveridade, new TableLayoutConstraints( 2, 0 ) );
+ panelRiscoValores.add( new JLabel("Probabilidade"), new TableLayoutConstraints( 3, 0 ) );
+ panelRiscoValores.add( textProbabilidade, new TableLayoutConstraints( 4, 0 ) );
+ panelRiscoValores.add( radioValorQualitativo, new TableLayoutConstraints( 0, 1 ) );
+ panelRiscoValores.add( comboValorQualitativo, new TableLayoutConstraints( 1, 1, 4, 1 ) );
+
+ panelRiscos.add( panelRiscoValores, new TableLayoutConstraints( 1, 0 ) );
+ panelRiscos.add( checkPlanoActuacao, new TableLayoutConstraints( 1, 1 ) );
+ panelRiscos.add( scrollRiscos, new TableLayoutConstraints( 0, 0, 0, 2 ) );
+
+ panelMedidas.add( scrollMedidas, new TableLayoutConstraints( 0, 0, 2, 3 ) );
+ panelMedidas.add( buttonMedidaAdd, new TableLayoutConstraints( 0, 4 ) );
+ panelMedidas.add( buttonMedidaRemove, new TableLayoutConstraints( 1, 4 ) );
+ panelMedidas.add( new JLabel("Medidas"), new TableLayoutConstraints( 3, 0 ) );
+ panelMedidas.add( textMedida, new TableLayoutConstraints( 3, 1 ) );
+ panelMedidas.add( new JLabel("Requisitos Legais"), new TableLayoutConstraints( 3, 2 ) );
+ panelMedidas.add( textRequisitosLegais, new TableLayoutConstraints( 3, 3 ) );
+
+ panelRelatorio.add( new JLabel("Data") , new TableLayoutConstraints( 0, 0 ) );
+ panelRelatorio.add( dateRelatorio , new TableLayoutConstraints( 0, 1 ) );
+ panelRelatorio.add( buttonSubmeterRelatorio, new TableLayoutConstraints( 2, 0, 2, 1 ) );
+ panelRelatorio.add( panelRiscos , new TableLayoutConstraints( 0, 2, 2, 2 ) );
+ panelRelatorio.add( panelMedidas , new TableLayoutConstraints( 0, 3, 2, 3 ) );
+
+ getContentPane().add( new JLabel("Empresa"), new TableLayoutConstraints( 0, 0, 1, 0 ) );
+ getContentPane().add( comboEmpresas, new TableLayoutConstraints( 0, 1, 1, 1 ) );
+ getContentPane().add( new JLabel("Estabelecimento"), new TableLayoutConstraints( 0, 2, 1, 2 ) );
+ getContentPane().add( comboEstabelecimentos, new TableLayoutConstraints( 0, 3, 1, 3 ) );
+ getContentPane().add( scrollVisitas, new TableLayoutConstraints( 0, 4 ) );
+ getContentPane().add( buttonCriarRelatorio, new TableLayoutConstraints( 0, 5 ) );
+ getContentPane().add( panelRelatorio, new TableLayoutConstraints( 1, 4, 1, 5 ) );
+ }
+
+ private void setupListeners()
+ {
+ comboEmpresas.addItemListener( new ItemListener()
+ {
+ @Override
+ public void itemStateChanged( ItemEvent e )
+ {
+ selectedEmpresa();
+ }
+ } );
+ comboEstabelecimentos.addItemListener( new ItemListener()
+ {
+ @Override
+ public void itemStateChanged( ItemEvent e )
+ {
+ selectedEstabelecimento();
+ }
+ } );
+ tableVisitas.getSelectionModel().addListSelectionListener( new ListSelectionListener()
+ {
+ @Override
+ public void valueChanged( ListSelectionEvent e )
+ {
+ if( e.getValueIsAdjusting() )
+ {
+ selectedVisita();
+ }
+ }
+ } );
+ buttonCriarRelatorio.addActionListener( new ActionListener()
+ {
+ @Override
+ public void actionPerformed( ActionEvent e )
+ {
+ criarRelatorio();
+ }
+ } );
+ }
+
+ private void criarRelatorio()
+ {
+
+ }
+
+ private void selectedEmpresa()
+ {
+ disableAndClearRelatorio( );
+ buttonCriarRelatorio.setEnabled( false );
+ tableVisitas.setEnabled( false );
+ modelVisitas.clearAll();
+ comboEstabelecimentos.removeAllItems();
+ Empresas empresa = (Empresas) comboEmpresas.getSelectedItem();
+ if( empresa != null )
+ {
+ for( Estabelecimentos estabelecimento : empresa.getEstabelecimentosArray() )
+ {
+ comboEstabelecimentos.addItem( estabelecimento );
+ }
+ comboEstabelecimentos.setEnabled( true );
+ }
+ else
+ {
+ comboEstabelecimentos.setEnabled( false );
+ }
+ }
+
+ private void selectedEstabelecimento()
+ {
+ disableAndClearRelatorio( );
+ modelVisitas.clearAll();
+ buttonCriarRelatorio.setEnabled( false );
+ Estabelecimentos estabelecimento = (Estabelecimentos) comboEstabelecimentos.getSelectedItem();
+ if( estabelecimento != null )
+ {
+ List marcacoes = estabelecimento.getMarcacoesEstabelecimentoArray();
+ for( MarcacoesEstabelecimento marcacao : marcacoes )
+ {
+ if( !"y".equals( marcacao.getRealizada() ) )
+ {
+ marcacoes.remove( marcacao );
+ }
+ }
+ modelVisitas.setValues( new Vector( marcacoes ) );
+ tableVisitas.setEnabled( true );
+ }
+ }
+
+ private MarcacoesEstabelecimento getSelectedVisita()
+ {
+ MarcacoesEstabelecimento result = null;
+ int row = tableVisitas.getSelectedRow();
+ if( row > -1 )
+ {
+ result = modelVisitas.getRowAt( row );
+ }
+ return result;
+ }
+
+ private void selectedVisita()
+ {
+ disableAndClearRelatorio( );
+ MarcacoesEstabelecimento visita = getSelectedVisita();
+ List relatorios = visita.getHsRelatorioArray();
+ HsRelatorio relatorio = null;
+ for( HsRelatorio current : relatorios )
+ {
+ if( current.getDeletedDate() == null)
+ {
+ relatorio = current;
+ break;
+ }
+ }
+ if( relatorio == null )
+ {
+ buttonCriarRelatorio.setEnabled( true );
+ }
+ else
+ {
+ fillRelatorio( relatorio );
+ buttonCriarRelatorio.setEnabled( false );
+ }
+ }
+
+ private void fillRelatorio( HsRelatorio relatorio )
+ {
+ dateRelatorio.setDate( relatorio.getData() );
+ buttonSubmeterRelatorio.setEnabled( relatorio.getIsSubmetido() != null );
+ }
+
+ private void loadEmpresas()
+ {
+ comboEmpresas.removeAllItems();
+ for( Empresas empresa : new MedicinaDAO().getAllEmpresas() )
+ {
+ comboEmpresas.addItem( empresa );
+ }
+ }
+
+
+ public static void main( String[] args )
+ {
+ RelatorioWindow window = new RelatorioWindow();
+ window.setVisible( true );
+ window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
+ }
+
+}
diff --git a/trunk/SIPRPSoft/src/siprp/higiene/riscos/GestaoRiscosLogic.java b/trunk/SIPRPSoft/src/siprp/higiene/riscos/GestaoRiscosLogic.java
new file mode 100644
index 00000000..012e0b8b
--- /dev/null
+++ b/trunk/SIPRPSoft/src/siprp/higiene/riscos/GestaoRiscosLogic.java
@@ -0,0 +1,120 @@
+package siprp.higiene.riscos;
+
+import java.util.Date;
+
+import javax.swing.tree.DefaultMutableTreeNode;
+
+import leaf.ui.LeafLogic;
+import siprp.database.cayenne.objects.BaseObject;
+import siprp.database.cayenne.objects.HsMedida;
+import siprp.database.cayenne.objects.HsRisco;
+import siprp.database.cayenne.objects.HsRiscoMedida;
+import siprp.database.cayenne.objects.HsRiscoTema;
+import siprp.database.cayenne.providers.PlanoActuacaoDAO;
+
+public class GestaoRiscosLogic extends LeafLogic
+{
+
+ @Action(isSave = true)
+ public static final String ACTION_SAVE = "ACTION_SAVE";
+
+ @Action(isSave = true)
+ public static final String ACTION_REMOVE = "ACTION_SAVE";
+
+ @Action(isSave = false)
+ public static final String ACTION_LOAD = "ACTION_LOAD";
+
+ @Action(isSave = false)
+ public static final String ACTION_SELECTION = "ACTION_SELECTION";
+
+ @Action(isSave = true)
+ public static final String ACTION_TEMA_CRIAR = "ACTION_TEMA_CRIAR";
+
+ @Action(isSave = true)
+ public static final String ACTION_TEMA_REMOVER = "ACTION_TEMA_REMOVER";
+
+ @Action(isSave = true)
+ public static final String ACTION_RISCO_CRIAR = "ACTION_RISCO_CRIAR";
+
+ @Action(isSave = true)
+ public static final String ACTION_RISCO_REMOVER = "ACTION_RISCO_REMOVER";
+
+ @Action(isSave = true)
+ public static final String ACTION_MEDIDA_CRIAR = "ACTION_MEDIDA_CRIAR";
+
+ @Action(isSave = true)
+ public static final String ACTION_MEDIDA_REMOVER = "ACTION_MEDIDA_REMOVER";
+
+ @Action(isSave = false)
+ public static final String ACTION_CLEAR_SELECTION = "ACTION_CLEAR_SELECTION";
+
+ @Action(isSave = false)
+ public static final String ACTION_SELECT_TEMA = "ACTION_SELECT_TEMA";
+
+ @Action(isSave = false)
+ public static final String ACTION_SELECT_RISCO = "ACTION_SELECT_RISCO";
+
+ @Action(isSave = false)
+ public static final String ACTION_SELECT_MEDIDA = "ACTION_SELECT_MEDIDA";
+
+ public final PlanoActuacaoDAO provider = new PlanoActuacaoDAO();
+
+ @LeafLogicActionBinding(actions=ACTION_STARTUP)
+ public void load()
+ {
+ runAction( ACTION_LOAD, provider.getAllRiscoTemas() );
+ runActionLater( ACTION_REFRESH );
+ }
+
+ @LeafLogicActionBinding( actions = ACTION_TEMA_REMOVER )
+ public void removeTema( HsRiscoTema tema )
+ {
+ tema.setDeletedDate( new Date() );
+ provider.commit();
+ load();
+ }
+
+ @LeafLogicActionBinding( actions = ACTION_RISCO_REMOVER )
+ public void removeRisco( HsRisco risco )
+ {
+ risco.setDeletedDate( new Date() );
+ provider.commit();
+ load();
+ }
+
+ @LeafLogicActionBinding( actions = ACTION_MEDIDA_REMOVER )
+ public void removeMedida( HsRiscoMedida rel )
+ {
+ provider.deleteObject( rel );
+ load();
+ }
+
+ @LeafLogicActionBinding( actions = { ACTION_SAVE, ACTION_TEMA_CRIAR, ACTION_RISCO_CRIAR, ACTION_MEDIDA_CRIAR } )
+ public void saveObject( BaseObject object )
+ {
+ provider.saveObject( object );
+ load();
+ }
+
+ @LeafLogicActionBinding(actions=ACTION_SELECTION)
+ public void selectionChanged( DefaultMutableTreeNode object )
+ {
+ if( object == null )
+ {
+ runAction( ACTION_CLEAR_SELECTION );
+ }
+ else if( object instanceof NodeRiscoTema )
+ {
+ runAction( ACTION_SELECT_TEMA, object );
+ }
+ else if( object instanceof NodeRisco )
+ {
+ runAction( ACTION_SELECT_RISCO, object );
+ }
+ else if( object instanceof NodeMedida )
+ {
+ runAction( ACTION_SELECT_MEDIDA, object );
+ }
+ }
+
+}
diff --git a/trunk/SIPRPSoft/src/siprp/higiene/riscos/GestaoRiscosWindow.java b/trunk/SIPRPSoft/src/siprp/higiene/riscos/GestaoRiscosWindow.java
index c7ca1357..e3f7d781 100644
--- a/trunk/SIPRPSoft/src/siprp/higiene/riscos/GestaoRiscosWindow.java
+++ b/trunk/SIPRPSoft/src/siprp/higiene/riscos/GestaoRiscosWindow.java
@@ -1,587 +1,494 @@
package siprp.higiene.riscos;
+import static com.evolute.utils.strings.UnicodeLatin1Map.aacute;
+import static com.evolute.utils.strings.UnicodeLatin1Map.atilde;
+import static com.evolute.utils.strings.UnicodeLatin1Map.ccedil;
+import static leaf.ui.LeafLogic.ACTION_REFRESH;
+import static siprp.higiene.riscos.GestaoRiscosLogic.ACTION_CLEAR_SELECTION;
+import static siprp.higiene.riscos.GestaoRiscosLogic.ACTION_LOAD;
+import static siprp.higiene.riscos.GestaoRiscosLogic.ACTION_MEDIDA_CRIAR;
+import static siprp.higiene.riscos.GestaoRiscosLogic.ACTION_MEDIDA_REMOVER;
+import static siprp.higiene.riscos.GestaoRiscosLogic.ACTION_RISCO_CRIAR;
+import static siprp.higiene.riscos.GestaoRiscosLogic.ACTION_RISCO_REMOVER;
+import static siprp.higiene.riscos.GestaoRiscosLogic.ACTION_SAVE;
+import static siprp.higiene.riscos.GestaoRiscosLogic.ACTION_SELECTION;
+import static siprp.higiene.riscos.GestaoRiscosLogic.ACTION_SELECT_MEDIDA;
+import static siprp.higiene.riscos.GestaoRiscosLogic.ACTION_SELECT_RISCO;
+import static siprp.higiene.riscos.GestaoRiscosLogic.ACTION_SELECT_TEMA;
+import static siprp.higiene.riscos.GestaoRiscosLogic.ACTION_TEMA_CRIAR;
+import static siprp.higiene.riscos.GestaoRiscosLogic.ACTION_TEMA_REMOVER;
+import info.clearthought.layout.TableLayout;
+import info.clearthought.layout.TableLayoutConstraints;
+
+import java.awt.CardLayout;
+import java.awt.Dimension;
+import java.awt.GridLayout;
+import java.util.List;
+
+import javax.swing.BorderFactory;
import javax.swing.JFrame;
-import javax.swing.SwingUtilities;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.JTree;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.TreePath;
+import javax.swing.tree.TreeSelectionModel;
-import com.evolute.utils.tracker.TrackableWindow;
+import leaf.data.OrderedMap;
+import leaf.ui.LeafButton;
+import leaf.ui.LeafInputField;
+import leaf.ui.LeafWindow;
+import leaf.ui.LeafLogic.LeafUIActionBinding;
+import siprp.database.cayenne.objects.BaseObject;
+import siprp.database.cayenne.objects.HsMedida;
+import siprp.database.cayenne.objects.HsMedidaClassificacao;
+import siprp.database.cayenne.objects.HsRisco;
+import siprp.database.cayenne.objects.HsRiscoMedida;
+import siprp.database.cayenne.objects.HsRiscoTema;
-import static com.evolute.utils.strings.UnicodeLatin1Map.*;
+import com.evolute.utils.tracker.TrackableWindow;
-public class GestaoRiscosWindow extends JFrame implements TrackableWindow
+public class GestaoRiscosWindow extends LeafWindow implements TrackableWindow
{
private static final long serialVersionUID = 1L;
public static final String TITLE = "Gest" + atilde + "o de Riscos";
-// private static final Dimension SIZE = new Dimension( 700, 500 );
-//
-// private final VectorTableModel modelRiscos = new VectorTableModel( new String[]{ "Riscos" } );
-//
-// private final VectorTableModel modelMedidas = new VectorTableModel( new String[]{ "Medidas" } );
-//
-// private final JTable tableRiscos = new JTable( modelRiscos );
-//
-// private final JTable tableMedidas = new JTable( modelMedidas );
-//
-// private final JScrollPane scrollRiscos = new JScrollPane(tableRiscos, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
-//
-// private final JScrollPane scrollMedidas = new JScrollPane(tableMedidas, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
-//
-// private final JButton buttonRiscoCriar = new JButton("Criar");
-//
-// private final JButton buttonRiscoEditar = new JButton("Editar");
-//
-// private final JButton buttonRiscoRemover = new JButton("Remover");
-//
-// private final JButton buttonValorGuardar = new JButton("Guardar");
-//
-// private final JButton buttonMedidaCriar = new JButton("Criar");
-//
-// private final JButton buttonMedidaEditar = new JButton("Editar");
-//
-// private final JButton buttonMedidaAdicionar = new JButton("Adicionar");
-//
-// private final JButton buttonMedidaRemover = new JButton("Remover");
-//
-// private final JLabel labelValor = new JLabel("Valor");
-//
-// private final JTextField fieldValor = new JTextField();
-//
-// private final JPanel panelRiscos = new JPanel();
-//
-// private final JPanel panelMedidas = new JPanel();
-//
-// private final JPanel panelValor = new JPanel();
-//
-// private final PlanoActuacaoDAO provider = new PlanoActuacaoDAO();
+ private static final Dimension SIZE = new Dimension( 700, 500 );
+
+ private static final String PANEL_TEMA = "PANEL_TEMA";
+
+ private static final String PANEL_RISCO = "PANEL_RISCO";
+
+ private static final String PANEL_MEDIDA = "PANEL_MEDIDA";
+
+ private final JPanel panelButtons = new JPanel();
+
+ private final JPanel panelTree = new JPanel();
+
+ private final JPanel panelData = new JPanel();
+
+ private final JPanel panelDataTema = new JPanel();
+
+ private final JPanel panelDataRisco = new JPanel();
+
+ private final JPanel panelDataMedida = new JPanel();
+
+ @ActionActivation(onChange="",onSelect=ACTION_TEMA_CRIAR)
+ public final LeafButton buttonTemaCriar = new LeafButton( "Criar" );
+
+ @ActionActivation(onChange="",onSelect=ACTION_TEMA_REMOVER)
+ public final LeafButton buttonTemaRemover = new LeafButton( "Remover" );
+
+ @ActionActivation(onChange="",onSelect=ACTION_RISCO_CRIAR)
+ public final LeafButton buttonRiscoCriar = new LeafButton( "Criar" );
+
+ @ActionActivation(onChange="",onSelect=ACTION_RISCO_REMOVER)
+ public final LeafButton buttonRiscoRemover = new LeafButton( "Remover" );
+
+ @ActionActivation(onChange="",onSelect=ACTION_MEDIDA_CRIAR)
+ public final LeafButton buttonMedidaCriar = new LeafButton( "Criar" );
+
+ @ActionActivation(onChange="",onSelect=ACTION_MEDIDA_REMOVER)
+ public final LeafButton buttonMedidaRemover = new LeafButton( "Remover" );
+
+ public final LeafInputField> fieldMedidaClassificacao = new LeafInputField>();
+
+ public final JTextArea fieldTextMedida = new JTextArea();
+
+ public final JTextArea fieldTextRequisitosLegais = new JTextArea();
+
+ private final DefaultMutableTreeNode root = new DefaultMutableTreeNode();
+
+ private final DefaultTreeModel model = new DefaultTreeModel( root );
+
+ @ActionActivation(onChange="", onSelect=ACTION_SELECTION)
+ public final JTree tree = new JTree( model );
+
+ private final JScrollPane scroll = new JScrollPane( tree );
+
+ private final CardLayout cardLayout = new CardLayout();
+
+ private BaseObject selection = null;
public static void main( String[] args )
{
GestaoRiscosWindow window = new GestaoRiscosWindow();
window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
- window.setVisible( true );
+ window.open();
}
public GestaoRiscosWindow()
{
-// this.setTitle( TITLE );
-// this.setSize( SIZE );
-// startupComponents();
-// startupLayout();
-// startupListeners();
-// placeComponents();
-// refreshRiscos();
+ super( new GestaoRiscosLogic() );
+ this.setTitle( TITLE );
+ this.setSize( SIZE );
+ startupComponents();
+ startupLayout();
+ placeComponents();
+ completeSetup();
}
-// private void startupComponents()
-// {
-// panelMedidas.setBorder( BorderFactory.createEtchedBorder() );
-// buttonMedidaRemover.setEnabled( false );
-// buttonMedidaAdicionar.setEnabled( false );
-// buttonMedidaCriar.setEnabled( false );
-// buttonMedidaEditar.setEnabled( false );
-// buttonRiscoRemover.setEnabled( false );
-// buttonRiscoEditar.setEnabled( false );
-// buttonValorGuardar.setEnabled( false );
-// fieldValor.setEnabled( false );
-// }
-//
-// private void startupLayout()
-// {
-// startupPanelRiscosLayout();
-// startupPanelMedidasLayout();
-// startupPanelValorLayout();
-// TableLayout layout = new TableLayout(
-// new double[]{ TableLayout.FILL, TableLayout.FILL },
-// new double[]{ TableLayout.MINIMUM, TableLayout.FILL }
-// );
-// layout.setHGap( 5 );
-// layout.setVGap( 5 );
-// this.getContentPane().setLayout( layout );
-// }
-//
-// private void startupPanelRiscosLayout()
-// {
-// TableLayout layout = new TableLayout(
-// new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL },
-// new double[]{ TableLayout.FILL, TableLayout.MINIMUM }
-// );
-// layout.setHGap( 5 );
-// layout.setVGap( 5 );
-// panelRiscos.setLayout( layout );
-// }
-//
-// private void startupPanelMedidasLayout()
-// {
-// TableLayout layout = new TableLayout(
-// new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL },
-// new double[]{ TableLayout.FILL, TableLayout.MINIMUM }
-// );
-// layout.setHGap( 5 );
-// layout.setVGap( 5 );
-// panelMedidas.setLayout( layout );
-// }
-//
-// private void startupPanelValorLayout()
-// {
-// TableLayout layout = new TableLayout(
-// new double[]{ TableLayout.MINIMUM, TableLayout.FILL, TableLayout.MINIMUM },
-// new double[]{ TableLayout.MINIMUM }
-// );
-// layout.setHGap( 5 );
-// layout.setVGap( 5 );
-// panelValor.setLayout( layout );
-// }
-//
-// private void startupListeners()
-// {
-// buttonMedidaCriar.addActionListener( new ActionListener()
-// {
-// @Override
-// public void actionPerformed( ActionEvent e )
-// {
-// Risco risco = getSelectedRisco();
-// if( risco != null )
-// {
-// criarMedida( risco );
-// }
-// }
-// } );
-// buttonMedidaAdicionar.addActionListener( new ActionListener()
-// {
-// @Override
-// public void actionPerformed( ActionEvent e )
-// {
-// Risco risco = getSelectedRisco();
-// if( risco != null )
-// {
-// adicionarMedida( risco );
-// }
-// }
-// } );
-// buttonMedidaRemover.addActionListener( new ActionListener()
-// {
-// @Override
-// public void actionPerformed( ActionEvent e )
-// {
-// removerMedidas();
-// }
-// } );
-// buttonMedidaEditar.addActionListener( new ActionListener()
-// {
-// @Override
-// public void actionPerformed( ActionEvent e )
-// {
-// alterarMedida();
-// }
-// } );
-// buttonRiscoCriar.addActionListener( new ActionListener()
-// {
-// @Override
-// public void actionPerformed( ActionEvent e )
-// {
-// criarRisco();
-// }
-// } );
-// buttonRiscoEditar.addActionListener( new ActionListener()
-// {
-// @Override
-// public void actionPerformed( ActionEvent e )
-// {
-// alterarRisco();
-// }
-// } );
-// buttonRiscoRemover.addActionListener( new ActionListener()
-// {
-// @Override
-// public void actionPerformed( ActionEvent e )
-// {
-// removerRiscos();
-// }
-// } );
-// buttonValorGuardar.addActionListener( new ActionListener()
-// {
-// @Override
-// public void actionPerformed( ActionEvent e )
-// {
-// alterarValor();
-// }
-// } );
-// tableMedidas.getSelectionModel().addListSelectionListener( new ListSelectionListener()
-// {
-// @Override
-// public void valueChanged( ListSelectionEvent e )
-// {
-// if( !e.getValueIsAdjusting() )
-// {
-// int [] indexes = tableMedidas.getSelectedRows();
-// if( indexes != null && indexes.length > 0 )
-// {
-// buttonMedidaRemover.setEnabled( true );
-// buttonMedidaEditar.setEnabled( indexes.length == 1 );
-// }
-// else
-// {
-// buttonMedidaRemover.setEnabled( false );
-// buttonMedidaEditar.setEnabled( false );
-// }
-// }
-// }
-// } );
-// tableRiscos.getSelectionModel().addListSelectionListener( new ListSelectionListener()
-// {
-// @Override
-// public void valueChanged( ListSelectionEvent e )
-// {
-// if( !e.getValueIsAdjusting() )
-// {
-// int [] indexes = tableRiscos.getSelectedRows();
-// if( indexes != null && indexes.length > 0 )
-// {
-// buttonRiscoRemover.setEnabled( true );
-// buttonMedidaCriar.setEnabled( indexes.length == 1 );
-// buttonMedidaAdicionar.setEnabled( indexes.length == 1 );
-// buttonRiscoEditar.setEnabled( indexes.length == 1 );
-// fieldValor.setEnabled( indexes.length == 1 );
-// }
-// else
-// {
-// buttonRiscoEditar.setEnabled( false );
-// buttonMedidaCriar.setEnabled( false );
-// buttonRiscoRemover.setEnabled( false );
-// buttonMedidaAdicionar.setEnabled( false );
-// buttonMedidaRemover.setEnabled( false );
-// buttonValorGuardar.setEnabled( false );
-// fieldValor.setEnabled( false );
-// }
-// refreshValor();
-// refreshMedidas();
-// }
-// }
-// } );
-// fieldValor.addCaretListener( new CaretListener()
-// {
-// @Override
-// public void caretUpdate( CaretEvent e )
-// {
-// buttonValorGuardar.setEnabled( valueChanged() );
-// }
-// } );
-// }
-//
-// private void placeComponents()
-// {
-// panelRiscos.add( scrollRiscos, new TableLayoutConstraints( 0, 0, 3, 0 ) );
-// panelRiscos.add( buttonRiscoCriar, new TableLayoutConstraints( 0, 1 ) );
-// panelRiscos.add( buttonRiscoEditar, new TableLayoutConstraints( 1, 1 ) );
-// panelRiscos.add( buttonRiscoRemover, new TableLayoutConstraints( 2, 1 ) );
-//
-// panelMedidas.add( scrollMedidas, new TableLayoutConstraints( 0, 0, 4, 0 ) );
-// panelMedidas.add( buttonMedidaCriar, new TableLayoutConstraints( 0, 1 ) );
-// panelMedidas.add( buttonMedidaEditar, new TableLayoutConstraints( 1, 1 ) );
-// panelMedidas.add( buttonMedidaAdicionar, new TableLayoutConstraints( 2, 1 ) );
-// panelMedidas.add( buttonMedidaRemover, new TableLayoutConstraints( 3, 1 ) );
-//
-// panelValor.add( labelValor, new TableLayoutConstraints( 0, 0 ) );
-// panelValor.add( fieldValor, new TableLayoutConstraints( 1, 0 ) );
-// panelValor.add( buttonValorGuardar, new TableLayoutConstraints( 2, 0 ) );
-//
-// this.getContentPane().add( panelRiscos, new TableLayoutConstraints( 0, 0, 0, 1 ) );
-// this.getContentPane().add( panelValor, new TableLayoutConstraints( 1, 0 ) );
-// this.getContentPane().add( panelMedidas, new TableLayoutConstraints( 1, 1 ) );
-// }
-//
-// private void alterarMedida()
-// {
-// Medida medida = getSelectedMedida();
-// if( medida != null )
-// {
-// String newDescription = JOptionPane.showInputDialog( "Editar medida", medida.getDescription() );
-// if( newDescription != null )
-// {
-// if( newDescription.trim().length() > 0 )
-// {
-// medida.setDescription( newDescription );
-// provider.commit();
-// refreshMedidas();
-// }
-// else
-// {
-// JOptionPane.showMessageDialog( this, "Medida inv" + aacute + "lida", "Erro", JOptionPane.ERROR_MESSAGE, null );
-// }
-// }
-// }
-// }
-//
-// private void alterarRisco()
-// {
-// Risco risco = getSelectedRisco();
-// if( risco != null )
-// {
-// String newDescription = JOptionPane.showInputDialog( "Editar risco", risco.getDescription() );
-// if( newDescription != null )
-// {
-// if( newDescription.trim().length() > 0 )
-// {
-// risco.setDescription( newDescription );
-// provider.commit();
-// refreshRiscos();
-// }
-// else
-// {
-// JOptionPane.showMessageDialog( this, "Risco inv" + aacute + "lido", "Erro", JOptionPane.ERROR_MESSAGE, null );
-// }
-// }
-// }
-// }
-//
-// private void alterarValor()
-// {
-// Risco risco = getSelectedRisco();
-// if( risco != null )
-// {
-// String valorString = fieldValor.getText();
-// if( valorString != null )
-// {
-// if( valorString.trim().length() > 0 )
-// {
-// valorString = valorString.trim();
-// try
-// {
-// Integer valorInt = new Integer(valorString);
-// risco.setValue( valorInt );
-// provider.commit();
-// refreshValor();
-// }
-// catch (NumberFormatException e)
-// {
-// JOptionPane.showMessageDialog( this, "O valor tem de ser um n" + uacute + "mero", "Erro", JOptionPane.ERROR_MESSAGE, null );
-// }
-// }
-// else
-// {
-// JOptionPane.showMessageDialog( this, "O valor n" + atilde + "o pode ser nulo", "Erro", JOptionPane.ERROR_MESSAGE, null );
-// }
-// }
-// }
-// }
-//
-// private boolean valueChanged()
-// {
-// boolean result = false;
-// Risco risco = getSelectedRisco();
-// String valorString = fieldValor.getText();
-// if( valorString != null && valorString.trim().length() > 0 )
-// {
-// valorString = valorString.trim();
-// try
-// {
-// result = !risco.getValue().equals( new Integer(valorString) );
-// }
-// catch (NumberFormatException e)
-// {
-// }
-// }
-// return result;
-// }
-//
-// private void removerRiscos()
-// {
-// int indexes [] = tableRiscos.getSelectedRows();
-// if( indexes != null && indexes.length > 0 )
-// {
-// for( int i = 0; i < indexes.length; ++i )
-// {
-// provider.delete( modelRiscos.getRowAt( indexes[i] ) );
-// }
-// refreshRiscos();
-// }
-// }
-//
-// private void removerMedidas( )
-// {
-// int indexes [] = tableMedidas.getSelectedRows();
-// if( indexes != null && indexes.length > 0 )
-// {
-// for( int i = 0; i < indexes.length; ++i )
-// {
-// provider.delete( modelMedidas.getRowAt( indexes[i] ) );
-// }
-// refreshMedidas();
-// }
-// }
-//
-// private void refreshMedidas()
-// {
-// modelMedidas.clearAll();
-// Risco risco = getSelectedRisco();
-// if( risco != null )
-// {
-// modelMedidas.setValues( new Vector( risco.getRiscoMedidaArray() ) );
-// }
-// }
-//
-// private void refreshValor()
-// {
-// fieldValor.setText( "" );
-// Risco risco = getSelectedRisco();
-// if( risco != null )
-// {
-// fieldValor.setText( risco.getValue() + "" );
-// }
-// buttonValorGuardar.setEnabled( valueChanged() );
-// }
-//
-// private void refreshRiscos()
-// {
-// modelRiscos.clearAll();
-// modelRiscos.setValues( new Vector( provider.getAllRiscos() ) );
-// }
-//
-// private Risco getSelectedRisco()
-// {
-// Risco result = null;
-// int indexes[] = tableRiscos.getSelectedRows();
-// if( indexes != null && indexes.length == 1 )
-// {
-// result = modelRiscos.getRowAt( indexes[0] );
-// }
-// return result;
-// }
-//
-// private Medida getSelectedMedida()
-// {
-// Medida result = null;
-// int indexes[] = tableMedidas.getSelectedRows();
-// if( indexes != null && indexes.length == 1 )
-// {
-// RiscoMedida rel = modelMedidas.getRowAt( indexes[0] );
-// if( rel != null )
-// {
-// result = rel.getToMedida();
-// }
-// }
-// return result;
-// }
-//
-// private void criarRisco()
-// {
-// String risco = JOptionPane.showInputDialog( "Criar risco" );
-// String valor = JOptionPane.showInputDialog( "Valor" );
-// criarRisco( risco, valor );
-// refreshRiscos();
-// }
-//
-// private void criarRisco( String risco, String valor )
-// {
-// if( risco != null && valor != null )
-// {
-// if( risco.trim().length() > 0 )
-// {
-// if( valor.trim().length() > 0 )
-// {
-// risco = risco.trim();
-// valor = valor.trim();
-// try
-// {
-// Integer valorInt = new Integer(valor);
-// provider.createRisco( risco, valorInt );
-// }
-// catch (NumberFormatException e)
-// {
-// JOptionPane.showMessageDialog( this, "O valor tem de ser um n" + uacute + "mero", "Erro", JOptionPane.ERROR_MESSAGE, null );
-// }
-// }
-// else
-// {
-// JOptionPane.showMessageDialog( this, "O valor n" + atilde + "o pode ser nulo", "Erro", JOptionPane.ERROR_MESSAGE, null );
-// }
-// }
-// else
-// {
-// JOptionPane.showMessageDialog( this, "Risco inv" + aacute + "lido", "Erro", JOptionPane.ERROR_MESSAGE, null );
-// }
-// }
-// }
-//
-//
-// private void criarMedida( Risco risco )
-// {
-// String medida = JOptionPane.showInputDialog( "Criar medida" );
-// Medida medidaObject = criarMedida( medida );
-// if( medidaObject != null )
-// {
-// adicionarMedida( medidaObject, risco );
-// }
-// }
-//
-// private Medida criarMedida( String medida )
-// {
-// Medida result = null;
-// if( medida != null )
-// {
-// if( medida.trim().length() > 0 )
-// {
-// medida = medida.trim();
-// result = provider.createMedida( medida );
-// }
-// else
-// {
-// JOptionPane.showMessageDialog( this, "Medida inv" + aacute + "lida", "Erro", JOptionPane.ERROR_MESSAGE, null );
-// }
-// }
-// return result;
-// }
-//
-// private void adicionarMedida( Risco risco )
-// {
-// Medida [] medidas = provider.getAllMedidasNotInRisco( risco );
-// Medida medida = (Medida) JOptionPane.showInputDialog(
-// this,
-// "Medidas",
-// "Adicionar medida", JOptionPane.QUESTION_MESSAGE, null, medidas, null );
-// adicionarMedida( medida, risco );
-// }
-//
-// private void adicionarMedida( Medida medida, Risco risco )
-// {
-// if( medida != null )
-// {
-// provider.addMedidaToRisco( medida, risco );
-// refreshMedidas();
-// }
-// }
-
- @Override
- public boolean closeIfPossible()
+ private void startupComponents()
+ {
+ panelButtons.setPreferredSize( new Dimension( 150, 0 ) );
+ panelTree.setPreferredSize( new Dimension( 300, 0 ) );
+ buttonMedidaCriar.setEnabled( false );
+ buttonMedidaRemover.setEnabled( false );
+ buttonRiscoCriar.setEnabled( false );
+ buttonRiscoRemover.setEnabled( false );
+ buttonTemaRemover.setEnabled( false );
+ tree.setRootVisible( false );
+ tree.getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION );
+ }
+
+ private void startupLayout()
+ {
+ TableLayout layout = new TableLayout(
+ new double[]{ TableLayout.MINIMUM, TableLayout.PREFERRED, TableLayout.FILL },
+ new double[]{ TableLayout.FILL }
+ );
+ layout.setHGap( 5 );
+ layout.setVGap( 5 );
+ this.getContentPane().setLayout( layout );
+
+ layout = new TableLayout(
+ new double[]{ TableLayout.MINIMUM },
+ new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL }
+ );
+ layout.setHGap( 5 );
+ layout.setVGap( 5 );
+ panelButtons.setLayout( layout );
+
+ layout = new TableLayout(
+ new double[]{ TableLayout.FILL },
+ new double[]{ TableLayout.FILL }
+ );
+ layout.setHGap( 5 );
+ layout.setVGap( 5 );
+ panelTree.setLayout( layout );
+
+ layout = new TableLayout(
+ new double[]{ TableLayout.FILL },
+ new double[]{ TableLayout.FILL }
+ );
+ layout.setHGap( 5 );
+ layout.setVGap( 5 );
+ panelDataTema.setLayout( layout );
+
+ layout = new TableLayout(
+ new double[]{ TableLayout.FILL },
+ new double[]{ TableLayout.FILL }
+ );
+ layout.setHGap( 5 );
+ layout.setVGap( 5 );
+ panelDataRisco.setLayout( layout );
+
+ layout = new TableLayout(
+ new double[]{ TableLayout.FILL },
+ new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL, TableLayout.MINIMUM, TableLayout.FILL }
+ );
+ layout.setHGap( 5 );
+ layout.setVGap( 5 );
+ panelDataMedida.setLayout( layout );
+
+ panelData.setLayout( cardLayout );
+ }
+
+ private void placeComponents()
{
- close();
- return true;
+ JPanel panel = new JPanel();
+ panel.setBorder( BorderFactory.createTitledBorder( "Tema" ) );
+ panel.setLayout( new GridLayout( 2, 1 ) );
+ panel.add( buttonTemaCriar );
+ panel.add( buttonTemaRemover );
+ panelButtons.add( panel, new TableLayoutConstraints( 0, 0 ) );
+ panel = new JPanel();
+ panel.setBorder( BorderFactory.createTitledBorder( "Risco" ) );
+ panel.setLayout( new GridLayout( 2, 1 ) );
+ panel.add( buttonRiscoCriar );
+ panel.add( buttonRiscoRemover );
+ panelButtons.add( panel, new TableLayoutConstraints( 0, 1 ) );
+ panel = new JPanel();
+ panel.setBorder( BorderFactory.createTitledBorder( "Medida" ) );
+ panel.setLayout( new GridLayout( 2, 1 ) );
+ panel.add( buttonMedidaCriar );
+ panel.add( buttonMedidaRemover );
+ panelButtons.add( panel, new TableLayoutConstraints( 0, 2 ) );
+
+ panelTree.add( scroll, new TableLayoutConstraints( 0, 0 ) );
+
+ panelDataMedida.add( new JLabel("Classifica"+ccedil+atilde+"o"), new TableLayoutConstraints(0,0) );
+ panelDataMedida.add( fieldMedidaClassificacao, new TableLayoutConstraints(0,1) );
+ panelDataMedida.add( new JLabel("Medida"), new TableLayoutConstraints(0,2) );
+ panelDataMedida.add( fieldTextMedida, new TableLayoutConstraints(0,3) );
+ panelDataMedida.add( new JLabel("Requisitos legais"), new TableLayoutConstraints(0,4) );
+ panelDataMedida.add( fieldTextRequisitosLegais, new TableLayoutConstraints(0,5) );
+
+ panelData.add( panelDataTema, PANEL_TEMA );
+ panelData.add( panelDataRisco, PANEL_RISCO );
+ panelData.add( panelDataMedida, PANEL_MEDIDA );
+
+ this.getContentPane().add( panelButtons, new TableLayoutConstraints( 0, 0 ) );
+ this.getContentPane().add( panelTree, new TableLayoutConstraints( 1, 0 ) );
+ this.getContentPane().add( panelData, new TableLayoutConstraints( 2, 0 ) );
}
- private void close()
+ @LeafUIActionBinding(action=ACTION_LOAD)
+ public void load( List temas )
{
- SwingUtilities.invokeLater( new Runnable() {
- public void run()
+ root.removeAllChildren();
+ for( HsRiscoTema tema : temas )
+ {
+ NodeRiscoTema temaNode = new NodeRiscoTema( tema );
+ for( HsRisco risco : tema.getHsRiscoArray() )
{
- setVisible( false );
- dispose();
+ NodeRisco riscoNode = new NodeRisco( risco );
+ for( HsRiscoMedida rel : risco.getHsRiscoMedidaArray() )
+ {
+ riscoNode.add( new NodeMedida( rel ) );
+ }
+ temaNode.add( riscoNode );
}
- } );
+ root.add( temaNode );
+ }
}
-
- @Override
- public void open()
+
+ @LeafUIActionBinding(action=ACTION_REFRESH)
+ public void refresh()
{
- setVisible( true );
+ ((DefaultTreeModel) tree.getModel()).nodeStructureChanged( root );
+ for( int i = 0; i < tree.getRowCount(); ++i)
+ {
+ tree.expandPath( tree.getPathForRow( i ) );
+ }
}
-
- @Override
- public void refresh()
+
+ @LeafUIActionBinding(action=ACTION_TEMA_CRIAR)
+ public HsRiscoTema createTema()
{
-// refreshRiscos();
+ HsRiscoTema tema = null;
+ String nome = JOptionPane.showInputDialog( "Criar tema" );
+ if( nome != null )
+ {
+ if( nome.trim().length() > 0 )
+ {
+ tema = new HsRiscoTema();
+ tema.setDescription( nome.trim() );
+ }
+ else
+ {
+ JOptionPane.showMessageDialog( this, "Tema inv" + aacute + "lido" );
+ }
+ }
+ return tema;
+ }
+
+ @LeafUIActionBinding(action=ACTION_MEDIDA_CRIAR)
+ public HsRiscoMedida createMedida()
+ {
+ HsRiscoMedida rel = null;
+ HsRisco risco = getSelectedRisco();
+ if( risco != null )
+ {
+ HsMedida medida = new HsMedida();
+ medida.setDescription( " " );
+ medida.setRequesitosLegais( " " );
+ runAction( ACTION_SAVE, medida );
+ rel = new HsRiscoMedida();
+ rel.setToHsMedida( medida );
+ rel.setToHsRisco( risco );
+ }
+ return rel;
+ }
+
+ private HsRiscoTema getSelectedTema()
+ {
+ HsRiscoTema result = null;
+ if( selection != null )
+ {
+ if( selection instanceof HsRiscoTema )
+ {
+ result = ( (HsRiscoTema) selection );
+ }
+ else if( selection instanceof HsRisco )
+ {
+ result = ( (HsRisco) selection ).getToHsRiscoTema();
+ }
+ else if( selection instanceof HsMedida )
+ {
+ result = ( (HsRiscoMedida) selection ).getToHsRisco().getToHsRiscoTema();
+ }
+ }
+ return result;
+ }
+
+ private HsRisco getSelectedRisco()
+ {
+ HsRisco result = null;
+ if( selection != null )
+ {
+ if( selection instanceof HsRisco )
+ {
+ result = (HsRisco) selection;
+ }
+ else if( selection instanceof HsRiscoMedida )
+ {
+ result = ( (HsRiscoMedida) selection ).getToHsRisco();
+ }
+ }
+ return result;
+ }
+
+ @LeafUIActionBinding(action=ACTION_RISCO_CRIAR)
+ public HsRisco createRisco()
+ {
+ HsRisco risco = null;
+ HsRiscoTema tema = getSelectedTema();
+ if( tema != null )
+ {
+ String nome = JOptionPane.showInputDialog( "Criar risco" );
+ if( nome != null )
+ {
+
+ if( nome.trim().length() > 0 && tema != null )
+ {
+ risco = new HsRisco();
+ risco.setDescription( nome.trim() );
+ risco.setToHsRiscoTema( tema );
+ }
+ else
+ {
+ JOptionPane.showMessageDialog( this, "Nome inv" + aacute + "lido" );
+ }
+ }
+ }
+ return risco;
+ }
+
+ @LeafUIActionBinding(action=ACTION_TEMA_REMOVER)
+ public HsRiscoTema removerTema()
+ {
+ HsRiscoTema tema = null;
+ if( selection != null )
+ {
+ if( selection instanceof HsRiscoTema )
+ {
+ tema = (HsRiscoTema) selection;
+ }
+ }
+ return tema;
+ }
+
+ @LeafUIActionBinding(action=ACTION_RISCO_REMOVER)
+ public HsRisco removerRisco()
+ {
+ HsRisco risco = null;
+ if( selection != null )
+ {
+ if( selection instanceof HsRisco )
+ {
+ risco = (HsRisco) selection;
+ }
+ }
+ return risco;
+ }
+
+ @LeafUIActionBinding(action=ACTION_MEDIDA_REMOVER)
+ public HsRiscoMedida removerMedida()
+ {
+ HsRiscoMedida medida = null;
+ if( selection != null )
+ {
+ if( selection instanceof HsRiscoMedida )
+ {
+ medida = (HsRiscoMedida) selection;
+ }
+ }
+ return medida;
+ }
+
+ @LeafUIActionBinding(action=ACTION_SELECTION)
+ public BaseObject selectionChanged()
+ {
+ BaseObject result = null;
+ TreePath selection = tree.getSelectionPath();
+ if( selection != null )
+ {
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) selection.getLastPathComponent();
+ result = (BaseObject) node.getUserObject();
+ }
+ this.selection = result;
+ updateCardLayout();
+ return result;
+ }
+
+ private void updateCardLayout()
+ {
+ if( selection != null )
+ {
+ if( selection instanceof HsRiscoTema )
+ {
+ cardLayout.show( panelData, PANEL_TEMA );
+ }
+ else if( selection instanceof HsRisco )
+ {
+ cardLayout.show( panelData, PANEL_RISCO );
+ }
+ else if( selection instanceof HsRiscoMedida )
+ {
+ cardLayout.show( panelData, PANEL_MEDIDA );
+ }
+ }
+ }
+
+ @LeafUIActionBinding(action=ACTION_CLEAR_SELECTION)
+ public void clear()
+ {
+ buttonMedidaCriar.setEnabled( false );
+ buttonMedidaRemover.setEnabled( false );
+ buttonRiscoCriar.setEnabled( false );
+ buttonRiscoRemover.setEnabled( false );
+ buttonTemaCriar.setEnabled( true );
+ buttonTemaRemover.setEnabled( false );
+ }
+
+ @LeafUIActionBinding(action=ACTION_SELECT_TEMA)
+ public void selectTema()
+ {
+ buttonMedidaCriar.setEnabled( false );
+ buttonMedidaRemover.setEnabled( false );
+ buttonRiscoCriar.setEnabled( true );
+ buttonRiscoRemover.setEnabled( false );
+ buttonTemaCriar.setEnabled( true );
+ buttonTemaRemover.setEnabled( true );
+ }
+
+ @LeafUIActionBinding(action=ACTION_SELECT_RISCO)
+ public void selectRisco()
+ {
+ buttonMedidaCriar.setEnabled( true );
+ buttonMedidaRemover.setEnabled( false );
+ buttonRiscoCriar.setEnabled( false );
+ buttonRiscoRemover.setEnabled( true );
+ buttonTemaCriar.setEnabled( true );
+ buttonTemaRemover.setEnabled( false );
+ }
+
+ @LeafUIActionBinding(action=ACTION_SELECT_MEDIDA)
+ public void selectMedida()
+ {
+ buttonMedidaCriar.setEnabled( false );
+ buttonMedidaRemover.setEnabled( true );
+ buttonRiscoCriar.setEnabled( false );
+ buttonRiscoRemover.setEnabled( false );
+ buttonTemaCriar.setEnabled( true );
+ buttonTemaRemover.setEnabled( false );
}
-
}
diff --git a/trunk/SIPRPSoft/src/siprp/higiene/riscos/NodeMedida.java b/trunk/SIPRPSoft/src/siprp/higiene/riscos/NodeMedida.java
new file mode 100644
index 00000000..3ef81b3c
--- /dev/null
+++ b/trunk/SIPRPSoft/src/siprp/higiene/riscos/NodeMedida.java
@@ -0,0 +1,17 @@
+package siprp.higiene.riscos;
+
+import javax.swing.tree.DefaultMutableTreeNode;
+
+import siprp.database.cayenne.objects.HsRiscoMedida;
+
+public class NodeMedida extends DefaultMutableTreeNode
+{
+
+ private static final long serialVersionUID = 1L;
+
+ public NodeMedida( HsRiscoMedida rel )
+ {
+ super( rel );
+ }
+
+}
diff --git a/trunk/SIPRPSoft/src/siprp/higiene/riscos/NodeRisco.java b/trunk/SIPRPSoft/src/siprp/higiene/riscos/NodeRisco.java
new file mode 100644
index 00000000..0298267a
--- /dev/null
+++ b/trunk/SIPRPSoft/src/siprp/higiene/riscos/NodeRisco.java
@@ -0,0 +1,17 @@
+package siprp.higiene.riscos;
+
+import javax.swing.tree.DefaultMutableTreeNode;
+
+import siprp.database.cayenne.objects.HsRisco;
+
+public class NodeRisco extends DefaultMutableTreeNode
+{
+
+ private static final long serialVersionUID = 1L;
+
+ public NodeRisco( HsRisco risco )
+ {
+ super( risco );
+ }
+
+}
diff --git a/trunk/SIPRPSoft/src/siprp/higiene/riscos/NodeRiscoTema.java b/trunk/SIPRPSoft/src/siprp/higiene/riscos/NodeRiscoTema.java
new file mode 100644
index 00000000..fa21e461
--- /dev/null
+++ b/trunk/SIPRPSoft/src/siprp/higiene/riscos/NodeRiscoTema.java
@@ -0,0 +1,17 @@
+package siprp.higiene.riscos;
+
+import javax.swing.tree.DefaultMutableTreeNode;
+
+import siprp.database.cayenne.objects.HsRiscoTema;
+
+public class NodeRiscoTema extends DefaultMutableTreeNode
+{
+
+ private static final long serialVersionUID = 1L;
+
+ public NodeRiscoTema( HsRiscoTema tema )
+ {
+ super( tema );
+ }
+
+}
diff --git a/trunk/SIPRPSoft/src/siprp/update/UpdateList.java b/trunk/SIPRPSoft/src/siprp/update/UpdateList.java
index 5b7e1745..c1655bff 100644
--- a/trunk/SIPRPSoft/src/siprp/update/UpdateList.java
+++ b/trunk/SIPRPSoft/src/siprp/update/UpdateList.java
@@ -33,7 +33,9 @@ public class UpdateList
new siprp.update.updates.V8_3_To_V8_4(), new siprp.update.updates.V8_4_To_V8_5(),
new siprp.update.updates.V8_5_To_V8_6(), new siprp.update.updates.V8_6_To_V8_7(),
new siprp.update.updates.V8_7_To_V8_8(), new siprp.update.updates.V8_8_To_V8_9(),
- new siprp.update.updates.V8_9_To_V9_0(), new siprp.update.updates.V9_0To_V9_1() };
+ new siprp.update.updates.V8_9_To_V9_0(), new siprp.update.updates.V9_0_To_V9_1(),
+ new siprp.update.updates.V9_1_To_V9_2(), new siprp.update.updates.V9_2_To_V9_3(),
+ new siprp.update.updates.V9_3_To_V9_4() };
protected static Executer EXECUTER;
protected static double version = -1;
diff --git a/trunk/SIPRPSoft/src/siprp/update/updates/V9_0To_V9_1.java b/trunk/SIPRPSoft/src/siprp/update/updates/V9_0_To_V9_1.java
similarity index 98%
rename from trunk/SIPRPSoft/src/siprp/update/updates/V9_0To_V9_1.java
rename to trunk/SIPRPSoft/src/siprp/update/updates/V9_0_To_V9_1.java
index 719da602..2b43bcdc 100644
--- a/trunk/SIPRPSoft/src/siprp/update/updates/V9_0To_V9_1.java
+++ b/trunk/SIPRPSoft/src/siprp/update/updates/V9_0_To_V9_1.java
@@ -17,11 +17,11 @@ import com.evolute.utils.db.Executer;
*
* @author fpalma
*/
-public class V9_0To_V9_1
+public class V9_0_To_V9_1
implements siprp.update.Update
{
- public V9_0To_V9_1()
+ public V9_0_To_V9_1()
{
}
@@ -35,7 +35,7 @@ public class V9_0To_V9_1
public double getStartVersion()
{
- return 9.1;
+ return 9.0;
}
public double getEndVersion()
diff --git a/trunk/SIPRPSoft/src/siprp/update/updates/V9_1_To_V9_2.java b/trunk/SIPRPSoft/src/siprp/update/updates/V9_1_To_V9_2.java
new file mode 100644
index 00000000..1d80d77e
--- /dev/null
+++ b/trunk/SIPRPSoft/src/siprp/update/updates/V9_1_To_V9_2.java
@@ -0,0 +1,71 @@
+/*
+ * V8_1_To_V8_2.java
+ *
+ * Created on December 19, 2007, 3:12 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+package siprp.update.updates;
+
+import com.evolute.utils.Singleton;
+import com.evolute.utils.db.DBManager;
+import com.evolute.utils.db.Executer;
+
+/**
+ *
+ * @author fpalma
+ */
+public class V9_1_To_V9_2
+ implements siprp.update.Update
+{
+
+ public V9_1_To_V9_2()
+ {
+ }
+
+ public String []listChanges()
+ {
+ return new String[]{
+ "Soft-delete nas tabelas de higiene e saude"
+ };
+ }
+
+ public double getStartVersion()
+ {
+ return 9.1;
+ }
+
+ public double getEndVersion()
+ {
+ return 9.2;
+ }
+
+ public void doUpdate()
+ throws Exception
+ {
+ DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER );
+ Executer executer = dbm.getSharedExecuter();
+ com.evolute.utils.sql.Update update =
+ new com.evolute.utils.sql.Update(
+ "alter table hs_area add column deleted_date timestamp;" +
+ "alter table hs_equipamento_medicao add column deleted_date timestamp;" +
+ "alter table hs_legislacao add column deleted_date timestamp;" +
+ "alter table hs_legislacao_categoria add column deleted_date timestamp;" +
+ "alter table hs_medida add column deleted_date timestamp;" +
+ "alter table hs_normalizacao add column deleted_date timestamp;" +
+ "alter table hs_posto add column deleted_date timestamp;" +
+ "alter table hs_relatorio_medida add column deleted_date timestamp;" +
+ "alter table hs_relatorio_risco add column deleted_date timestamp;" +
+ "alter table hs_risco add column deleted_date timestamp;" +
+ "alter table hs_risco_tema add column deleted_date timestamp;"
+ );
+ executer.executeQuery( update );
+ }
+
+ public String toString()
+ {
+ return "v" + getStartVersion() + " para v" + getEndVersion();
+ }
+}
diff --git a/trunk/SIPRPSoft/src/siprp/update/updates/V9_2_To_V9_3.java b/trunk/SIPRPSoft/src/siprp/update/updates/V9_2_To_V9_3.java
new file mode 100644
index 00000000..54568cf7
--- /dev/null
+++ b/trunk/SIPRPSoft/src/siprp/update/updates/V9_2_To_V9_3.java
@@ -0,0 +1,75 @@
+/*
+ * V8_1_To_V8_2.java
+ *
+ * Created on December 19, 2007, 3:12 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+package siprp.update.updates;
+
+import com.evolute.utils.Singleton;
+import com.evolute.utils.db.DBManager;
+import com.evolute.utils.db.Executer;
+
+/**
+ *
+ * @author fpalma
+ */
+public class V9_2_To_V9_3
+ implements siprp.update.Update
+{
+
+ public V9_2_To_V9_3()
+ {
+ }
+
+ public String []listChanges()
+ {
+ return new String[]{
+ "Adicionados campos ao relatorio"
+ };
+ }
+
+ public double getStartVersion()
+ {
+ return 9.2;
+ }
+
+ public double getEndVersion()
+ {
+ return 9.3;
+ }
+
+ public void doUpdate()
+ throws Exception
+ {
+ DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER );
+ Executer executer = dbm.getSharedExecuter();
+ com.evolute.utils.sql.Update update =
+ new com.evolute.utils.sql.Update(
+ "alter table hs_relatorio_medida drop column severidade;" +
+ "alter table hs_relatorio_medida drop column probabilidade;" +
+ "alter table hs_relatorio_medida drop column classificacao_id;" +
+ "drop table hs_medida_classificacao;" +
+ "alter table hs_relatorio add column marcacao_id int4 REFERENCES marcacoes_estabelecimento;" +
+ "alter table hs_relatorio add column is_submetido timestamp;" +
+ "alter table hs_relatorio_risco add column probabilidade int4;" +
+ "alter table hs_relatorio_risco add column severidade int4;" +
+ "create table hs_relatorio_risco_valor_qualitativo" +
+ "(" +
+ " id serial PRIMARY KEY," +
+ " description varchar(64)" +
+ ");" +
+ "alter table hs_relatorio_risco add column valor_qualitativo_id int4 REFERENCES hs_relatorio_risco_valor_qualitativo;" +
+ "alter table hs_relatorio_risco add column is_plano_actuacao char(1);"
+ );
+ executer.executeQuery( update );
+ }
+
+ public String toString()
+ {
+ return "v" + getStartVersion() + " para v" + getEndVersion();
+ }
+}
diff --git a/trunk/SIPRPSoft/src/siprp/update/updates/V9_3_To_V9_4.java b/trunk/SIPRPSoft/src/siprp/update/updates/V9_3_To_V9_4.java
new file mode 100644
index 00000000..502bd432
--- /dev/null
+++ b/trunk/SIPRPSoft/src/siprp/update/updates/V9_3_To_V9_4.java
@@ -0,0 +1,71 @@
+/*
+ * V8_1_To_V8_2.java
+ *
+ * Created on December 19, 2007, 3:12 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+package siprp.update.updates;
+
+import com.evolute.utils.Singleton;
+import com.evolute.utils.db.DBManager;
+import com.evolute.utils.db.Executer;
+
+/**
+ *
+ * @author fpalma
+ */
+public class V9_3_To_V9_4
+ implements siprp.update.Update
+{
+
+ public V9_3_To_V9_4()
+ {
+ }
+
+ public String []listChanges()
+ {
+ return new String[]{
+ "Adicionados postos de trabalho relatorio"
+ };
+ }
+
+ public double getStartVersion()
+ {
+ return 9.3;
+ }
+
+ public double getEndVersion()
+ {
+ return 9.4;
+ }
+
+ public void doUpdate()
+ throws Exception
+ {
+ DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER );
+ Executer executer = dbm.getSharedExecuter();
+ com.evolute.utils.sql.Update update =
+ new com.evolute.utils.sql.Update(
+ "create table hs_relatorio_medida_area" +
+ "(" +
+ " id serial PRIMARY KEY," +
+ " description varchar(256) NOT NULL" +
+ ");" +
+ "create table hs_relatorio_medida_posto" +
+ "(" +
+ " id serial PRIMARY KEY," +
+ " description varchar(256) NOT NULL," +
+ " area_id int4 REFERENCES hs_relatorio_medida_area(id)" +
+ ");"
+ );
+ executer.executeQuery( update );
+ }
+
+ public String toString()
+ {
+ return "v" + getStartVersion() + " para v" + getEndVersion();
+ }
+}
diff --git a/trunk/build.xml b/trunk/build.xml
index bcb04381..5fcd52b1 100644
--- a/trunk/build.xml
+++ b/trunk/build.xml
@@ -1,7 +1,9 @@
-
+
+
+
@@ -9,10 +11,6 @@
-
-
-
-