diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/AdicionarAreasPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/AdicionarAreasPanel.java index c844b68b..6619d500 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/AdicionarAreasPanel.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/AdicionarAreasPanel.java @@ -23,6 +23,8 @@ import siprp.database.cayenne.objects.Estabelecimentos; import siprp.database.cayenne.objects.HsPosto; import siprp.database.cayenne.objects.HsPostoEstabelecimento; import siprp.logic.HigieneSegurancaLogic; +import siprp.logic.node.AreaNode; +import siprp.logic.node.PostoNode; public class AdicionarAreasPanel extends JPanel { diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/GerirAreasPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/GerirAreasPanel.java index 7e0c7ff1..4b983649 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/GerirAreasPanel.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/GerirAreasPanel.java @@ -30,6 +30,8 @@ import leaf.ui.TreeTools; import siprp.database.cayenne.objects.Empresas; import siprp.database.cayenne.objects.HsArea; import siprp.database.cayenne.objects.HsPosto; +import siprp.logic.node.AreaNode; +import siprp.logic.node.PostoNode; public class GerirAreasPanel extends JPanel { diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/AdicionarRiscosPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/AdicionarRiscosPanel.java index af80f705..f603959f 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/AdicionarRiscosPanel.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/AdicionarRiscosPanel.java @@ -27,6 +27,7 @@ import siprp.database.cayenne.objects.HsRelatorioPosto; import siprp.database.cayenne.objects.HsRisco; import siprp.database.cayenne.objects.HsRiscoEmpresa; import siprp.logic.HigieneSegurancaLogic; +import siprp.logic.node.NodeRisco; public class AdicionarRiscosPanel extends JPanel { diff --git a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/AdicionarRiscosRelatorioPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/AdicionarRiscosRelatorioPanel.java index 14dee42e..b0c48ddd 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/AdicionarRiscosRelatorioPanel.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/AdicionarRiscosRelatorioPanel.java @@ -116,7 +116,7 @@ public class AdicionarRiscosRelatorioPanel extends JPanel public void refresh() { - root.removeAllChildren(); + root.removeAllChildren(); if( posto != null ) { for( HsRelatorioPostoRisco rel : posto.getHsRelatorioPostoRiscoArray() ) diff --git a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/GerirMedidaRelatorioPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/GerirMedidaRelatorioPanel.java index c3548c21..df9d9929 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/GerirMedidaRelatorioPanel.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/GerirMedidaRelatorioPanel.java @@ -183,17 +183,32 @@ public class GerirMedidaRelatorioPanel extends JPanel private void setEnabled() { - boolean medidaChanged = false; - boolean requesitoChanged = false; - if( relacao != null ) + if( isEnabled() ) + { + boolean medidaChanged = false; + boolean requesitoChanged = false; + if( relacao != null ) + { + medidaChanged = !fieldTextMedida.getText().equals( relacao.getToHsRelatorioMedida().getDescription() ); + requesitoChanged = !fieldTextRequisitosLegais.getText().equals( relacao.getToHsRelatorioMedida().getRequesitosLegais() ); + } + fieldTextMedida.setEnabled( relacao != null ); + fieldTextRequisitosLegais.setEnabled( relacao != null ); + buttonSaveMedida.setEnabled( medidaChanged ); + buttonSaveRequesito.setEnabled( requesitoChanged ); + buttonRevertMedida.setEnabled( medidaChanged ); + buttonRevertRequesito.setEnabled( requesitoChanged ); + } + else { - medidaChanged = !fieldTextMedida.getText().equals( relacao.getToHsRelatorioMedida().getDescription() ); - requesitoChanged = !fieldTextRequisitosLegais.getText().equals( relacao.getToHsRelatorioMedida().getRequesitosLegais() ); + buttonSaveMedida.setEnabled( false ); + buttonSaveRequesito.setEnabled( false ); + buttonRevertMedida.setEnabled( false ); + buttonRevertRequesito.setEnabled( false ); + fieldTextRequisitosLegais.setEnabled( false ); + fieldTextMedida.setEnabled( false ); } - buttonSaveMedida.setEnabled( medidaChanged ); - buttonSaveRequesito.setEnabled( requesitoChanged ); - buttonRevertMedida.setEnabled( medidaChanged ); - buttonRevertRequesito.setEnabled( requesitoChanged ); + } private void savePlano() diff --git a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/GerirValoresRiscoPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/GerirValoresRiscoPanel.java index e35303fd..e7bab94e 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/GerirValoresRiscoPanel.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/GerirValoresRiscoPanel.java @@ -166,54 +166,67 @@ public class GerirValoresRiscoPanel extends JPanel implements ActionListener, Ca private void setEnabled() { - textProbabilidade.setEnabled( valoresRisco != null && radioValorQuantitativo.isSelected() ); - textSeveridade.setEnabled( valoresRisco != null && radioValorQuantitativo.isSelected() ); - radioValorQualitativo.setEnabled( valoresRisco != null ); - radioValorQuantitativo.setEnabled( valoresRisco != null ); - comboValorQualitativo.setEnabled( valoresRisco != null && radioValorQualitativo.isSelected() ); - if( valoresRisco != null ) + if( isEnabled() ) { - boolean changes = false; - boolean wasQual = valoresRisco.getToHsRelatorioRiscoValorQualitativo() != null; - boolean isQual = radioValorQualitativo.isSelected(); - if(!isQual) + textProbabilidade.setEnabled( valoresRisco != null && radioValorQuantitativo.isSelected() ); + textSeveridade.setEnabled( valoresRisco != null && radioValorQuantitativo.isSelected() ); + radioValorQualitativo.setEnabled( valoresRisco != null ); + radioValorQuantitativo.setEnabled( valoresRisco != null ); + comboValorQualitativo.setEnabled( valoresRisco != null && radioValorQualitativo.isSelected() ); + if( valoresRisco != null ) { - changes = wasQual; - if(!changes) - { - boolean probChanged = false; - boolean sevChanged = false; - String prob = textProbabilidade.getText(); - String sev = textSeveridade.getText(); - if( prob == null ) - { - probChanged = valoresRisco.getProbabilidade() != null; - } - else - { - probChanged = !prob.equals(valoresRisco.getProbabilidade() == null ? "" : valoresRisco.getProbabilidade() + ""); - } - if( sev == null ) - { - sevChanged = valoresRisco.getSeveridade() != null; - } - else - { - sevChanged = !sev.equals(valoresRisco.getSeveridade() == null ? "" : valoresRisco.getSeveridade() + "" ); + boolean changes = false; + boolean wasQual = valoresRisco.getToHsRelatorioRiscoValorQualitativo() != null; + boolean isQual = radioValorQualitativo.isSelected(); + if(!isQual) + { + changes = wasQual; + if(!changes) + { + boolean probChanged = false; + boolean sevChanged = false; + String prob = textProbabilidade.getText(); + String sev = textSeveridade.getText(); + if( prob == null ) + { + probChanged = valoresRisco.getProbabilidade() != null; + } + else + { + probChanged = !prob.equals(valoresRisco.getProbabilidade() == null ? "" : valoresRisco.getProbabilidade() + ""); + } + if( sev == null ) + { + sevChanged = valoresRisco.getSeveridade() != null; + } + else + { + sevChanged = !sev.equals(valoresRisco.getSeveridade() == null ? "" : valoresRisco.getSeveridade() + "" ); + } + changes = probChanged || sevChanged; } - changes = probChanged || sevChanged; } - } - else - { - changes = !wasQual; - if(!changes) - { - changes = !comboValorQualitativo.getSelectedItem().equals( valoresRisco.getToHsRelatorioRiscoValorQualitativo() ); + else + { + changes = !wasQual; + if(!changes) + { + changes = !comboValorQualitativo.getSelectedItem().equals( valoresRisco.getToHsRelatorioRiscoValorQualitativo() ); + } } + buttonSave.setEnabled( changes ); + buttonRevert.setEnabled( changes ); } - buttonSave.setEnabled( changes ); - buttonRevert.setEnabled( changes ); + } + else + { + buttonRevert.setEnabled( false ); + buttonSave.setEnabled( false ); + radioValorQualitativo.setEnabled( false ); + radioValorQuantitativo.setEnabled( false ); + comboValorQualitativo.setEnabled( false ); + textProbabilidade.setEnabled( false ); + textSeveridade.setEnabled( false ); } } diff --git a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/PanelRelatorio.java b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/PanelRelatorio.java index eea0c998..f3db7a9a 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/PanelRelatorio.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/PanelRelatorio.java @@ -12,6 +12,7 @@ import java.awt.Component; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.Date; import java.util.EventObject; import javax.swing.BorderFactory; @@ -41,6 +42,7 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe 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_SUBMIT = "siprp/higiene/relatorio/submit.png"; private final JCalendarPanel dataRelatorio = new JCalendarPanel( null ); @@ -61,6 +63,7 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe private final LeafIconButton buttonSave = LeafIconButton.createButton( ICON_NAME_SAVE ); private final LeafIconButton buttonRevert = LeafIconButton.createButton( ICON_NAME_REVERT ); + private final LeafIconButton buttonSubmit = LeafIconButton.createButton( "Submeter plano de actua" + ccedil + atilde + "o", ICON_NAME_SUBMIT ); private final AdicionarEquipamentosPanel panelEquipamentos = new AdicionarEquipamentosPanel(); @@ -130,8 +133,22 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe panelAcompanhantes.add( fieldNome3, new TableLayoutConstraints( 1, 2 ) ); panelAcompanhantes.add( new JLabel( "Fun" + ccedil + atilde + "o" ), new TableLayoutConstraints( 2, 2 ) ); panelAcompanhantes.add( fieldFuncao3, new TableLayoutConstraints( 3, 2 ) ); - add( buttonSave, new TableLayoutConstraints( 0, 0 ) ); - add( buttonRevert, new TableLayoutConstraints( 1, 0 ) ); + + TableLayout layout = new TableLayout( new double[] { + TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL, TableLayout.MINIMUM + }, new double[] { + TableLayout.MINIMUM + } ); + layout.setVGap( 5 ); + layout.setHGap( 5 ); + JPanel panel = new JPanel(); + panel.setLayout( layout ); + + panel.add( buttonSave, new TableLayoutConstraints( 0, 0 ) ); + panel.add( buttonRevert, new TableLayoutConstraints( 1, 0 ) ); + panel.add( buttonSubmit, new TableLayoutConstraints( 3, 0 ) ); + + add( panel, new TableLayoutConstraints( 0, 0, 7, 0 ) ); add( new JLabel( "Data do relat" + oacute + "rio" ), new TableLayoutConstraints( 0, 1, 2, 1 ) ); add( dataRelatorio, new TableLayoutConstraints( 3, 1 ) ); add( new JLabel( "Avalia" + ccedil + atilde + "o" ), new TableLayoutConstraints( 4, 1 ) ); @@ -146,7 +163,6 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe private void setupListeners() { - fieldTecnico.addCaretListener( this ); fieldFuncao1.addCaretListener( this ); fieldFuncao2.addCaretListener( this ); fieldFuncao3.addCaretListener( this ); @@ -172,6 +188,24 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe revert(); } } ); + buttonSubmit.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + submit(); + } + } ); + } + + private void submit() + { + if( relatorio != null ) + { + relatorio.setIsSubmetido( new Date() ); + relatorio.save(); + refresh(); + } } private void save() @@ -180,15 +214,15 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe { relatorio.setData( dataRelatorio.getDate() ); relatorio.setAvaliacaoInicial( radioInicial.isSelected() ); - MarcacoesEstabelecimento marcacao = relatorio.getToHsMarcacoesEstabelecimento(); - if( marcacao != null ) - { - MarcacoesTecnicosHst tecnico = marcacao.getToMarcacoesTecnicosHst(); - if( tecnico != null ) - { - tecnico.setNome( fieldTecnico.getText() ); - } - } +// MarcacoesEstabelecimento marcacao = relatorio.getToHsMarcacoesEstabelecimento(); +// if( marcacao != null ) +// { +// MarcacoesTecnicosHst tecnico = marcacao.getToMarcacoesTecnicosHst(); +// if( tecnico != null ) +// { +// tecnico.setNome( fieldTecnico.getText() ); +// } +// } } relatorio.setAcompanhante1( fieldNome1.getText() ); relatorio.setAcompanhante2( fieldNome2.getText() ); @@ -197,6 +231,7 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe relatorio.setFuncaoAcompanhante1(fieldFuncao1.getText()); relatorio.setFuncaoAcompanhante2(fieldFuncao2.getText()); relatorio.setFuncaoAcompanhante3(fieldFuncao3.getText()); + relatorio.save(); refresh(); buttonRevert.setEnabled( false ); buttonSave.setEnabled( false ); @@ -249,13 +284,14 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe dataRelatorio.setEnabled( enabled ); radioInicial.setEnabled( enabled );; radioPeriodica.setEnabled( enabled ); - fieldTecnico.setEnabled( enabled ); + fieldTecnico.setEnabled( false ); fieldNome1.setEnabled( enabled ); fieldNome2.setEnabled( enabled ); fieldNome3.setEnabled( enabled ); fieldFuncao1.setEnabled( enabled ); fieldFuncao2.setEnabled( enabled ); fieldFuncao3.setEnabled( enabled ); + buttonSubmit.setEnabled( enabled ); } public void setRelatorio( HsRelatorio relatorio ) diff --git a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/PlanoActuacaoPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/PlanoActuacaoPanel.java index 23380a9e..86ee2c3c 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/PlanoActuacaoPanel.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/PlanoActuacaoPanel.java @@ -1,31 +1,34 @@ 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.*; import info.clearthought.layout.TableLayout; import info.clearthought.layout.TableLayoutConstraints; import java.awt.CardLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import javax.swing.BorderFactory; +import javax.swing.JOptionPane; import javax.swing.JPanel; -import com.evolute.utils.ui.image.ImagePanel; - import leaf.ui.LeafButton; +import leaf.ui.LeafIconButton; import siprp.database.cayenne.objects.HsRelatorio; -import siprp.database.cayenne.objects.HsRelatorioMedida; import siprp.database.cayenne.objects.HsRelatorioPosto; import siprp.database.cayenne.objects.HsRelatorioPostoMedida; import siprp.database.cayenne.objects.HsRelatorioPostoRisco; +import siprp.logic.HigieneSegurancaLogic; public class PlanoActuacaoPanel extends JPanel { private static final long serialVersionUID = 1L; + private static final String ICON_NAME_REVERT = "siprp/higiene/gestao/riscos/revert.png"; + private static final String RISCO_PANEL = "RISCO_PANEL"; private static final String MEDIDA_PANEL = "MEDIDA_PANEL"; @@ -46,7 +49,9 @@ public class PlanoActuacaoPanel extends JPanel private final CardLayout cards = new CardLayout(); - private final LeafButton submeterButton = new LeafButton( "Submeter plano de actua" + ccedil + atilde + "o" ); + private final LeafButton buttonRevert = LeafIconButton.createButton( ICON_NAME_REVERT ); + + private HsRelatorio relatorio = null; public PlanoActuacaoPanel() { @@ -97,6 +102,27 @@ public class PlanoActuacaoPanel extends JPanel } } } ); + buttonRevert.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + revert(); + } + } ); + } + + private void revert() + { + if( relatorio != null ) + { + int ret = JOptionPane.showConfirmDialog( this, "Todas as altera" + ccedil + otilde + "es ao plano de actua" + ccedil + atilde + "o ser" + atilde + "o perdidas\nTem a certeza?","Carregar configura"+ccedil+atilde+"o actual ",JOptionPane.YES_NO_OPTION); + if( JOptionPane.YES_OPTION == ret ) + { + HigieneSegurancaLogic.reverterRelatorio(relatorio); + setRelatorio( relatorio ); + } + } } private void startupComponents() @@ -108,7 +134,7 @@ public class PlanoActuacaoPanel extends JPanel private void startupLayout() { TableLayout layout = new TableLayout( - new double[]{ TableLayout.FILL, TableLayout.FILL, TableLayout.FILL }, + new double[]{ TableLayout.MINIMUM, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL }, new double[]{ TableLayout.MINIMUM, TableLayout.FILL } ); layout.setHGap( 5 ); @@ -122,17 +148,27 @@ public class PlanoActuacaoPanel extends JPanel valoresPanel.add( valoresRisco, RISCO_PANEL); valoresPanel.add( valoresMedida, MEDIDA_PANEL ); valoresPanel.add( emptyPanel, EMPTY_PANEL ); - add(areas,new TableLayoutConstraints(0,0,0,1)); - add(riscos,new TableLayoutConstraints(1,0,1,1)); - add(valoresPanel,new TableLayoutConstraints(2,0,2,1)); + add(buttonRevert,new TableLayoutConstraints(0,0)); + add(areas,new TableLayoutConstraints(1,0,1,1)); + add(riscos,new TableLayoutConstraints(2,0,2,1)); + add(valoresPanel,new TableLayoutConstraints(3,0,3,1)); } + private void setEnabled() + { + buttonRevert.setEnabled( relatorio != null && relatorio.getIsSubmetido() == null ); + } + public void setRelatorio( HsRelatorio relatorio ) { + this.relatorio = relatorio; areas.setRelatorio( relatorio ); riscos.setPosto( null ); valoresRisco.setRelatorioPostoRisco( null ); + valoresRisco.setEnabled( relatorio != null && relatorio.getIsSubmetido() == null ); valoresMedida.setMedida( null ); + valoresMedida.setEnabled( relatorio != null && relatorio.getIsSubmetido() == null ); + setEnabled( ); } } diff --git a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/submit.png b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/submit.png new file mode 100644 index 00000000..7cb1f515 Binary files /dev/null and b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/submit.png differ diff --git a/trunk/common/src/SIPRPMap.map.xml b/trunk/common/src/SIPRPMap.map.xml index 2fb46494..8d08e6d7 100644 --- a/trunk/common/src/SIPRPMap.map.xml +++ b/trunk/common/src/SIPRPMap.map.xml @@ -1836,31 +1836,31 @@ - + - + - - + + - - + + - - - - - - - - - - - + + + + + + + + + + + diff --git a/trunk/common/src/leaf/ui/LeafButton.java b/trunk/common/src/leaf/ui/LeafButton.java index 980c2ee4..45b947dd 100644 --- a/trunk/common/src/leaf/ui/LeafButton.java +++ b/trunk/common/src/leaf/ui/LeafButton.java @@ -30,6 +30,8 @@ public class LeafButton extends JButton protected void paintComponent( Graphics g ) { + if( icon == null ) + { boolean pushed = getModel().isPressed(); // Color borderColor = getBackground(); // Color highlightColor = getBackground(); @@ -67,7 +69,8 @@ public class LeafButton extends JButton y -= 1; g2.setColor( textColor ); g2.drawString( getText(), x, y ); - if( icon != null ) + } + else { super.paintComponent( g ); } diff --git a/trunk/common/src/leaf/ui/LeafIconButton.java b/trunk/common/src/leaf/ui/LeafIconButton.java index 8dc8753c..ec5dfe8c 100644 --- a/trunk/common/src/leaf/ui/LeafIconButton.java +++ b/trunk/common/src/leaf/ui/LeafIconButton.java @@ -31,4 +31,14 @@ public class LeafIconButton extends LeafButton return result; } + public static LeafIconButton createButton( String title, String imagePath ) + { + LeafIconButton result = createButton( imagePath ); + if( result != null ) + { + result.setText( title ); + } + return result; + } + } diff --git a/trunk/common/src/siprp/database/cayenne/objects/HsPosto.java b/trunk/common/src/siprp/database/cayenne/objects/HsPosto.java index 9385e778..d1006bcb 100644 --- a/trunk/common/src/siprp/database/cayenne/objects/HsPosto.java +++ b/trunk/common/src/siprp/database/cayenne/objects/HsPosto.java @@ -5,6 +5,19 @@ import siprp.database.cayenne.objects.auto._HsPosto; public class HsPosto extends _HsPosto { private static final long serialVersionUID = 1L; + + @Override + public String getDescription() + { + return parseFromUnicode( super.getDescription() ); + } + + + @Override + public void setDescription( String nome ) + { + super.setDescription( parseToUnicode( nome ) ); + } @Override public String toString() diff --git a/trunk/common/src/siprp/logic/HigieneSegurancaLogic.java b/trunk/common/src/siprp/logic/HigieneSegurancaLogic.java index 493d1d60..37ea735e 100644 --- a/trunk/common/src/siprp/logic/HigieneSegurancaLogic.java +++ b/trunk/common/src/siprp/logic/HigieneSegurancaLogic.java @@ -1,5 +1,6 @@ package siprp.logic; +import java.util.HashMap; import java.util.List; import javax.swing.tree.DefaultMutableTreeNode; @@ -10,9 +11,14 @@ import siprp.database.cayenne.objects.Estabelecimentos; import siprp.database.cayenne.objects.HsArea; import siprp.database.cayenne.objects.HsPosto; import siprp.database.cayenne.objects.HsPostoEstabelecimento; +import siprp.database.cayenne.objects.HsPostoRisco; import siprp.database.cayenne.objects.HsRelatorio; import siprp.database.cayenne.objects.HsRelatorioArea; +import siprp.database.cayenne.objects.HsRelatorioMedida; import siprp.database.cayenne.objects.HsRelatorioPosto; +import siprp.database.cayenne.objects.HsRelatorioPostoMedida; +import siprp.database.cayenne.objects.HsRelatorioPostoRisco; +import siprp.database.cayenne.objects.HsRelatorioRisco; import siprp.database.cayenne.objects.HsRelatorioRiscoValorQualitativo; import siprp.database.cayenne.objects.HsRisco; import siprp.database.cayenne.objects.HsRiscoEmpresa; @@ -20,13 +26,13 @@ import siprp.database.cayenne.objects.HsRiscoMedida; import siprp.database.cayenne.objects.HsRiscoTema; import siprp.database.cayenne.providers.MedicinaDAO; import siprp.database.cayenne.providers.PlanoActuacaoDAO; -import siprp.higiene.gestao.postos.AreaNode; -import siprp.higiene.gestao.postos.PostoNode; -import siprp.higiene.gestao.riscos.NodeMedida; -import siprp.higiene.gestao.riscos.NodeRisco; -import siprp.higiene.gestao.riscos.NodeRiscoTema; import siprp.higiene.relatorio.AreaRelatorioNode; import siprp.higiene.relatorio.PostoRelatorioNode; +import siprp.logic.node.AreaNode; +import siprp.logic.node.NodeMedida; +import siprp.logic.node.NodeRisco; +import siprp.logic.node.NodeRiscoTema; +import siprp.logic.node.PostoNode; public class HigieneSegurancaLogic { @@ -157,4 +163,72 @@ public class HigieneSegurancaLogic } return result; } + + public static void reverterRelatorio( HsRelatorio relatorio ) + { + if(relatorio != null) + { + List areas = relatorio.getHsRelatorioArea(); + int areasSize = areas == null ? 0 : areas.size(); + for( int i = 0; i < areasSize; ++i ) + { + areas.get( 0 ).delete(); + } + relatorio.save(); + Estabelecimentos estabelecimento = relatorio.getToHsMarcacoesEstabelecimento() == null ? null : relatorio.getToHsMarcacoesEstabelecimento().getToEstabelecimentos(); + if( estabelecimento != null ) + { + List postos = estabelecimento.getHsPostoEstabelecimentoArray(); + reverterPostos(relatorio,postos); + relatorio.save(); + } + } + } + + private static void reverterPostos( HsRelatorio relatorio, List postos ) + { + HashMap areasInserted = new HashMap(); + for( HsPostoEstabelecimento rel : postos ) + { + HsPosto posto = rel.getToHsPosto(); + HsRelatorioPosto rPosto = new HsRelatorioPosto(); + rPosto.setDescription( posto.getDescription() ); + HsArea area = posto.getToHsArea(); + HsRelatorioArea rArea = areasInserted.get( area ); + if( rArea == null ) + { + rArea = new HsRelatorioArea(); + rArea.setDescription( area.getDescription() ); + rArea.setToHsRelatorio( relatorio ); + areasInserted.put(area,rArea); + } + rPosto.setToHsRelatorioArea( rArea ); + addMedidasAndRiscos(posto,rPosto); + } + } + + private static void addMedidasAndRiscos(HsPosto posto, HsRelatorioPosto rPosto) + { + for( HsPostoRisco postoRisco : posto.getHsPostoRiscoArray() ) + { + HsRelatorioRisco rRelatorioRisco = new HsRelatorioRisco(); + rRelatorioRisco.setToHsRelatorio( rPosto.getToHsRelatorioArea().getToHsRelatorio() ); + rRelatorioRisco.setDescription( postoRisco.getToHsRisco().getDescription() ); + HsRelatorioPostoRisco rPostoRisco = new HsRelatorioPostoRisco(); + rPostoRisco.setToHsRelatorioPosto( rPosto ); + rPostoRisco.setToHsRelatorioRisco( rRelatorioRisco ); + for( HsRiscoMedida riscoMedida : postoRisco.getToHsRisco().getHsRiscoMedidaArray() ) + { + HsRelatorioMedida rMedida = new HsRelatorioMedida(); + rMedida.setDescription( riscoMedida.getToHsMedida().getDescription() ); + rMedida.setRequesitosLegais( riscoMedida.getToHsMedida().getRequesitosLegais() ); + rMedida.setToHsRelatorioRisco( rRelatorioRisco ); + HsRelatorioPostoMedida rPostoMedida = new HsRelatorioPostoMedida(); + rPostoMedida.setIsPlanoActuacao( false ); + rPostoMedida.setToHsRelatorioMedida( rMedida ); + rPostoMedida.setToHsRelatorioPosto( rPosto ); + } + } + } + } diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/AreaNode.java b/trunk/common/src/siprp/logic/node/AreaNode.java similarity index 87% rename from trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/AreaNode.java rename to trunk/common/src/siprp/logic/node/AreaNode.java index 282250a3..a8dd39ce 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/AreaNode.java +++ b/trunk/common/src/siprp/logic/node/AreaNode.java @@ -1,4 +1,4 @@ -package siprp.higiene.gestao.postos; +package siprp.logic.node; import javax.swing.tree.DefaultMutableTreeNode; diff --git a/trunk/common/src/siprp/logic/node/AreaRelatorioNode.java b/trunk/common/src/siprp/logic/node/AreaRelatorioNode.java new file mode 100644 index 00000000..aedf26bb --- /dev/null +++ b/trunk/common/src/siprp/logic/node/AreaRelatorioNode.java @@ -0,0 +1,17 @@ +package siprp.logic.node; + +import javax.swing.tree.DefaultMutableTreeNode; + +import siprp.database.cayenne.objects.HsRelatorioArea; + +public class AreaRelatorioNode extends DefaultMutableTreeNode +{ + + private static final long serialVersionUID = 1L; + + public AreaRelatorioNode( HsRelatorioArea risco ) + { + super( risco ); + } + +} diff --git a/trunk/common/src/siprp/logic/node/MedidaRelatorioNode.java b/trunk/common/src/siprp/logic/node/MedidaRelatorioNode.java new file mode 100644 index 00000000..3efebf3f --- /dev/null +++ b/trunk/common/src/siprp/logic/node/MedidaRelatorioNode.java @@ -0,0 +1,16 @@ +package siprp.logic.node; + +import javax.swing.tree.DefaultMutableTreeNode; + +import siprp.database.cayenne.objects.HsRelatorioPostoMedida; + +public class MedidaRelatorioNode extends DefaultMutableTreeNode +{ + private static final long serialVersionUID = 1L; + + public MedidaRelatorioNode( HsRelatorioPostoMedida medida ) + { + super( medida ); + } + +} diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/NodeMedida.java b/trunk/common/src/siprp/logic/node/NodeMedida.java similarity index 88% rename from trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/NodeMedida.java rename to trunk/common/src/siprp/logic/node/NodeMedida.java index 7f6ec982..a2e1bd16 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/NodeMedida.java +++ b/trunk/common/src/siprp/logic/node/NodeMedida.java @@ -1,4 +1,4 @@ -package siprp.higiene.gestao.riscos; +package siprp.logic.node; import javax.swing.tree.DefaultMutableTreeNode; diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/NodeRisco.java b/trunk/common/src/siprp/logic/node/NodeRisco.java similarity index 87% rename from trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/NodeRisco.java rename to trunk/common/src/siprp/logic/node/NodeRisco.java index 21108438..7a53beaa 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/NodeRisco.java +++ b/trunk/common/src/siprp/logic/node/NodeRisco.java @@ -1,4 +1,4 @@ -package siprp.higiene.gestao.riscos; +package siprp.logic.node; import javax.swing.tree.DefaultMutableTreeNode; diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/NodeRiscoTema.java b/trunk/common/src/siprp/logic/node/NodeRiscoTema.java similarity index 88% rename from trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/NodeRiscoTema.java rename to trunk/common/src/siprp/logic/node/NodeRiscoTema.java index 99a589cf..6de8eedf 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/NodeRiscoTema.java +++ b/trunk/common/src/siprp/logic/node/NodeRiscoTema.java @@ -1,4 +1,4 @@ -package siprp.higiene.gestao.riscos; +package siprp.logic.node; import javax.swing.tree.DefaultMutableTreeNode; diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/PostoNode.java b/trunk/common/src/siprp/logic/node/PostoNode.java similarity index 87% rename from trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/PostoNode.java rename to trunk/common/src/siprp/logic/node/PostoNode.java index d57071cd..757454c0 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/PostoNode.java +++ b/trunk/common/src/siprp/logic/node/PostoNode.java @@ -1,4 +1,4 @@ -package siprp.higiene.gestao.postos; +package siprp.logic.node; import javax.swing.tree.DefaultMutableTreeNode; diff --git a/trunk/common/src/siprp/logic/node/PostoRelatorioNode.java b/trunk/common/src/siprp/logic/node/PostoRelatorioNode.java new file mode 100644 index 00000000..eb2af7f5 --- /dev/null +++ b/trunk/common/src/siprp/logic/node/PostoRelatorioNode.java @@ -0,0 +1,17 @@ +package siprp.logic.node; + +import javax.swing.tree.DefaultMutableTreeNode; + +import siprp.database.cayenne.objects.HsRelatorioPosto; + +public class PostoRelatorioNode extends DefaultMutableTreeNode +{ + + private static final long serialVersionUID = 1L; + + public PostoRelatorioNode( HsRelatorioPosto risco ) + { + super( risco ); + } + +} diff --git a/trunk/common/src/siprp/logic/node/RiscoRelatorioNode.java b/trunk/common/src/siprp/logic/node/RiscoRelatorioNode.java new file mode 100644 index 00000000..2eaf37ea --- /dev/null +++ b/trunk/common/src/siprp/logic/node/RiscoRelatorioNode.java @@ -0,0 +1,16 @@ +package siprp.logic.node; + +import javax.swing.tree.DefaultMutableTreeNode; + +import siprp.database.cayenne.objects.HsRelatorioPostoRisco; + +public class RiscoRelatorioNode extends DefaultMutableTreeNode +{ + private static final long serialVersionUID = 1L; + + public RiscoRelatorioNode( HsRelatorioPostoRisco risco ) + { + super( risco ); + } + +}