From 9aaaf53f18b54254e5c23d6662ee2bf70d54f2a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tiago=20Sim=C3=A3o?= Date: Fri, 9 Jan 2009 13:18:45 +0000 Subject: [PATCH] git-svn-id: https://svn.coded.pt/svn/SIPRP@895 bb69d46d-e84e-40c8-a05a-06db0d633741 --- .../higiene/gestao/AdicionarEmailsPanel.java | 7 ++ .../gestao/GerirEstabelecimentosPanel.java | 28 +++-- .../legislacao/AdicionarLegislacaoPanel.java | 111 +++++++++--------- .../AdicionarNormalizacaoPanel.java | 12 +- trunk/common/src/leaf/ui/TreeTools.java | 14 +++ .../siprp/logic/HigieneSegurancaLogic.java | 103 +++++++++++++++- 6 files changed, 202 insertions(+), 73 deletions(-) diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/AdicionarEmailsPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/AdicionarEmailsPanel.java index 39bb8920..1189cac6 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/gestao/AdicionarEmailsPanel.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/AdicionarEmailsPanel.java @@ -14,6 +14,7 @@ import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeSelectionModel; import siprp.database.cayenne.objects.Empresas; +import siprp.database.cayenne.objects.Estabelecimentos; import com.evolute.utils.tables.VectorTableModel; @@ -87,5 +88,11 @@ public class AdicionarEmailsPanel extends JPanel // TODO Auto-generated method stub } + + public void setEstabelecimento( Estabelecimentos estabelecimento ) + { + // TODO Auto-generated method stub + + } } diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/GerirEstabelecimentosPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/GerirEstabelecimentosPanel.java index ae4d7e70..13494e1a 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/gestao/GerirEstabelecimentosPanel.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/GerirEstabelecimentosPanel.java @@ -6,6 +6,7 @@ import info.clearthought.layout.TableLayout; import info.clearthought.layout.TableLayoutConstraints; import java.awt.Dimension; +import java.awt.GridLayout; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.beans.PropertyChangeEvent; @@ -19,6 +20,7 @@ import siprp.database.cayenne.objects.Empresas; import siprp.database.cayenne.objects.Estabelecimentos; import siprp.database.cayenne.objects.HsPosto; import siprp.higiene.gestao.legislacao.AdicionarLegislacaoPanel; +import siprp.higiene.gestao.normalizacao.AdicionarNormalizacaoPanel; import siprp.higiene.gestao.postos.AdicionarAreasPanel; import siprp.higiene.gestao.riscos.AdicionarRiscosPanel; @@ -28,10 +30,12 @@ public class GerirEstabelecimentosPanel extends JPanel private static final long serialVersionUID = 1L; private final JComboBox comboEstabelecimentos = new JComboBox(); + private final JPanel panelAreasRiscos = new JPanel(); private final AdicionarAreasPanel panelAreas = new AdicionarAreasPanel(); private final AdicionarRiscosPanel panelRiscos = new AdicionarRiscosPanel(); private final AdicionarEmailsPanel panelEmails = new AdicionarEmailsPanel(); private final AdicionarLegislacaoPanel panelLegislacao = new AdicionarLegislacaoPanel(); + private final AdicionarNormalizacaoPanel panelNormalizacao = new AdicionarNormalizacaoPanel(); public GerirEstabelecimentosPanel() { @@ -43,31 +47,35 @@ public class GerirEstabelecimentosPanel extends JPanel private void startupComponents() { - panelAreas.setBorder( BorderFactory.createTitledBorder( "Postos de trabalho" ) ); + panelAreasRiscos.setBorder( BorderFactory.createTitledBorder( "Riscos por posto de trabalho" ) ); panelRiscos.setBorder( BorderFactory.createTitledBorder( "Riscos" ) ); panelEmails.setBorder( BorderFactory.createTitledBorder( "Emails" ) ); panelLegislacao.setBorder( BorderFactory.createTitledBorder( "Legisla" + ccedil + atilde + "o" ) ); - panelEmails.setPreferredSize( new Dimension(0,150) ); } private void setupLayout() { double [] cols = new double[]{ TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, }; - double [] rows = new double[]{ TableLayout.MINIMUM, TableLayout.FILL, TableLayout.PREFERRED }; + double [] rows = new double[]{ TableLayout.MINIMUM, TableLayout.FILL,TableLayout.FILL, TableLayout.PREFERRED }; TableLayout layout = new TableLayout( cols, rows ); layout.setHGap( 5 ); layout.setVGap( 5 ); this.setLayout( layout ); + + panelAreasRiscos.setLayout( new GridLayout( 1, 2 ) ); } private void placeComponents() { + panelAreasRiscos.add( panelAreas ); + panelAreasRiscos.add( panelRiscos ); + this.add( comboEstabelecimentos, new TableLayoutConstraints( 0, 0, 2, 0 ) ); - this.add( panelAreas, new TableLayoutConstraints( 0, 1, 0, 2 ) ); - this.add( panelRiscos, new TableLayoutConstraints( 1, 1, 1, 2 ) ); + this.add( panelAreasRiscos, new TableLayoutConstraints( 0, 1, 1, 3 ) ); this.add( panelLegislacao, new TableLayoutConstraints( 2, 1 ) ); - this.add( panelEmails, new TableLayoutConstraints( 2, 2 ) ); + this.add( panelNormalizacao, new TableLayoutConstraints( 2, 2 ) ); + this.add( panelEmails, new TableLayoutConstraints( 2, 3 ) ); } private void startupListeners() @@ -81,7 +89,11 @@ public class GerirEstabelecimentosPanel extends JPanel { if( e.getItem() instanceof Estabelecimentos ) { - panelAreas.setEstabelecimento( (Estabelecimentos) e.getItem() ); + Estabelecimentos estabelecimento = (Estabelecimentos) e.getItem(); + panelAreas.setEstabelecimento( estabelecimento ); + panelEmails.setEstabelecimento( estabelecimento ); + panelLegislacao.setEstabelecimento( estabelecimento ); + panelNormalizacao.setEstabelecimento( estabelecimento ); } } } @@ -118,8 +130,6 @@ public class GerirEstabelecimentosPanel extends JPanel comboEstabelecimentos.setSelectedIndex( 0 ); } } - panelEmails.setEmpresa( empresa ); - panelLegislacao.setEmpresa( empresa ); } } diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/legislacao/AdicionarLegislacaoPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/legislacao/AdicionarLegislacaoPanel.java index 1906ef31..da8bf4e1 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/gestao/legislacao/AdicionarLegislacaoPanel.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/legislacao/AdicionarLegislacaoPanel.java @@ -2,17 +2,13 @@ package siprp.higiene.gestao.legislacao; import static com.evolute.utils.strings.UnicodeLatin1Map.atilde; import static com.evolute.utils.strings.UnicodeLatin1Map.ccedil; -import info.clearthought.layout.TableLayout; -import info.clearthought.layout.TableLayoutConstraints; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -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 leaf.ui.LeafError; +import leaf.ui.TreeInserterDialog; +import leaf.ui.TreeTools; import siprp.database.cayenne.objects.Empresas; import siprp.database.cayenne.objects.Estabelecimentos; import siprp.database.cayenne.objects.HsLegislacao; @@ -21,11 +17,6 @@ import siprp.database.cayenne.objects.HsLegislacaoEstabelecimento; import siprp.higiene.gestao.AdicionarPanel; import siprp.logic.HigieneSegurancaLogic; -import leaf.ui.LeafButton; -import leaf.ui.LeafError; -import leaf.ui.TreeInserterDialog; -import leaf.ui.TreeTools; - public class AdicionarLegislacaoPanel extends AdicionarPanel { @@ -69,72 +60,76 @@ private static final long serialVersionUID = 1L; DefaultMutableTreeNode result = new DefaultMutableTreeNode(); if( empresa != null ) { - result = HigieneSegurancaLogic.getLegislacaoTree( null ); + result = HigieneSegurancaLogic.getLegislacaoTreeForEmpresa( null ); } else if( estabelecimento != null ) { - result = HigieneSegurancaLogic.getLegislacaoTree( estabelecimento.getToEmpresas() ); + result = HigieneSegurancaLogic.getLegislacaoTreeForEmpresa( estabelecimento.getToEmpresas() ); } return result; } private void removeCurrent( DefaultMutableTreeNode all ) { -// if( all != null && root.getChildCount() == 2 && all.getChildCount() == 2 ) -// { -// DefaultMutableTreeNode portuguesaAll = (DefaultMutableTreeNode) all.getChildAt( 0 ); -// DefaultMutableTreeNode internacionalAll = (DefaultMutableTreeNode) all.getChildAt( 1 ); -// DefaultMutableTreeNode portuguesaCurrent = (DefaultMutableTreeNode) root.getChildAt( 0 ); -// DefaultMutableTreeNode internacionalCurrent = (DefaultMutableTreeNode) root.getChildAt( 1 ); -// TreeTools.remove( portuguesaAll, portuguesaCurrent ); -// TreeTools.remove( internacionalAll, internacionalCurrent ); -// } + if( all != null && root.getChildCount() == 2 && all.getChildCount() == 2 ) + { + DefaultMutableTreeNode geralAll = (DefaultMutableTreeNode) all.getChildAt( 0 ); + DefaultMutableTreeNode especificaAll = (DefaultMutableTreeNode) all.getChildAt( 1 ); + DefaultMutableTreeNode geralCurrent = (DefaultMutableTreeNode) root.getChildAt( 0 ); + DefaultMutableTreeNode especificaCurrent = (DefaultMutableTreeNode) root.getChildAt( 1 ); + TreeTools.remove( geralAll, geralCurrent ); + TreeTools.removeAllLeafs( especificaAll, especificaCurrent ); + } } private void addResult( DefaultMutableTreeNode root ) { -// try -// { -// if( root != null ) -// { -// Object userObject = root.getUserObject(); -// if( userObject instanceof HsNormalizacao ) -// { -// if( empresa != null ) -// { -// HsNormalizacaoEmpresa rel = new HsNormalizacaoEmpresa(); -// rel.setToEmpresa( empresa ); -// rel.setToHsNormalizacao( ((HsNormalizacao) userObject ) ); -// rel.save(); -// } -// else if( estabelecimento != null ) -// { -// HsNormalizacaoEstabelecimento rel = new HsNormalizacaoEstabelecimento(); -// rel.setToEstabelecimento( estabelecimento ); -// rel.setToHsNormalizacao( ((HsNormalizacao) userObject ) ); -// rel.save(); -// } -// } -// } -// for( int i = 0; i < root.getChildCount(); ++i ) -// { -// DefaultMutableTreeNode child = (DefaultMutableTreeNode) root.getChildAt( i ); -// addResult( child ); -// } -// } -// catch( Exception e ) -// { -// LeafError.error( e ); -// } + try + { + if( root != null ) + { + Object userObject = root.getUserObject(); + if( userObject instanceof HsLegislacao ) + { + if( empresa != null ) + { + HsLegislacaoEmpresa rel = new HsLegislacaoEmpresa(); + rel.setToHsEmpresa( empresa ); + rel.setToHsLegislacao( ((HsLegislacao) userObject ) ); + rel.save(); + } + else if( estabelecimento != null ) + { + HsLegislacaoEstabelecimento rel = new HsLegislacaoEstabelecimento(); + rel.setToHsEstabelecimento( estabelecimento ); + rel.setToHsLegislacao( ((HsLegislacao) userObject ) ); + rel.save(); + } + } + } + for( int i = 0; i < root.getChildCount(); ++i ) + { + DefaultMutableTreeNode child = (DefaultMutableTreeNode) root.getChildAt( i ); + addResult( child ); + } + } + catch( Exception e ) + { + LeafError.error( e ); + } } @Override public void refresh() { root.removeAllChildren(); - if( empresa != null || estabelecimento != null ) + if( empresa != null ) + { + TreeTools.merge( root, HigieneSegurancaLogic.getLegislacaoTreeForEmpresa( empresa ) ); + } + else if( estabelecimento != null ) { - TreeTools.merge( root, HigieneSegurancaLogic.getLegislacaoTree( empresa != null ? empresa : estabelecimento.getToEmpresas() ) ); + TreeTools.merge( root, HigieneSegurancaLogic.getLegislacaoTreeForEstabelecimento( estabelecimento ) ); } setEnabled(); TreeTools.refreshTree( tree, root ); diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/normalizacao/AdicionarNormalizacaoPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/normalizacao/AdicionarNormalizacaoPanel.java index c21eadd4..10632611 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/gestao/normalizacao/AdicionarNormalizacaoPanel.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/normalizacao/AdicionarNormalizacaoPanel.java @@ -60,11 +60,11 @@ public class AdicionarNormalizacaoPanel extends AdicionarPanel DefaultMutableTreeNode result = new DefaultMutableTreeNode(); if( empresa != null ) { - result = HigieneSegurancaLogic.getNormalizacaoTree( null ); + result = HigieneSegurancaLogic.getNormalizacaoTreeForEmpresa( null ); } else if( estabelecimento != null ) { - result = HigieneSegurancaLogic.getNormalizacaoTree( estabelecimento.getToEmpresas() ); + result = HigieneSegurancaLogic.getNormalizacaoTreeForEmpresa( estabelecimento.getToEmpresas() ); } return result; } @@ -123,9 +123,13 @@ public class AdicionarNormalizacaoPanel extends AdicionarPanel public void refresh() { root.removeAllChildren(); - if( empresa != null || estabelecimento != null ) + if( empresa != null) { - TreeTools.merge( root, HigieneSegurancaLogic.getNormalizacaoTree( empresa != null ? empresa : estabelecimento.getToEmpresas() ) ); + TreeTools.merge( root, HigieneSegurancaLogic.getNormalizacaoTreeForEmpresa( empresa ) ); + } + if( estabelecimento != null ) + { + TreeTools.merge( root, HigieneSegurancaLogic.getNormalizacaoTreeForEstabelecimento( estabelecimento ) ); } setEnabled(); TreeTools.refreshTree( tree, root ); diff --git a/trunk/common/src/leaf/ui/TreeTools.java b/trunk/common/src/leaf/ui/TreeTools.java index cd6572a7..25cb6ea3 100644 --- a/trunk/common/src/leaf/ui/TreeTools.java +++ b/trunk/common/src/leaf/ui/TreeTools.java @@ -98,5 +98,19 @@ public class TreeTools } } } + + public static void removeAllLeafs( DefaultMutableTreeNode from, DefaultMutableTreeNode what ) + { + for( int i = 0; i < what.getChildCount(); ++i ) + { + DefaultMutableTreeNode child = (DefaultMutableTreeNode) what.getChildAt( i ); + removeAllLeafs( from, child ); + } + DefaultMutableTreeNode exists = TreeTools.findNodeWithUserObject( what.getUserObject(), from ); + if( exists != null && exists.getChildCount() == 0 ) + { + exists.removeFromParent(); + } + } } diff --git a/trunk/common/src/siprp/logic/HigieneSegurancaLogic.java b/trunk/common/src/siprp/logic/HigieneSegurancaLogic.java index f2340000..deed73f0 100644 --- a/trunk/common/src/siprp/logic/HigieneSegurancaLogic.java +++ b/trunk/common/src/siprp/logic/HigieneSegurancaLogic.java @@ -13,8 +13,10 @@ import siprp.database.cayenne.objects.HsArea; import siprp.database.cayenne.objects.HsLegislacao; import siprp.database.cayenne.objects.HsLegislacaoCategoria; import siprp.database.cayenne.objects.HsLegislacaoEmpresa; +import siprp.database.cayenne.objects.HsLegislacaoEstabelecimento; import siprp.database.cayenne.objects.HsNormalizacao; import siprp.database.cayenne.objects.HsNormalizacaoEmpresa; +import siprp.database.cayenne.objects.HsNormalizacaoEstabelecimento; import siprp.database.cayenne.objects.HsPosto; import siprp.database.cayenne.objects.HsPostoEstabelecimento; import siprp.database.cayenne.objects.HsPostoRisco; @@ -306,7 +308,7 @@ public class HigieneSegurancaLogic return result; } - public static DefaultMutableTreeNode getNormalizacaoTree( Empresas empresa ) + public static DefaultMutableTreeNode getNormalizacaoTreeForEmpresa( Empresas empresa ) { DefaultMutableTreeNode result = new DefaultMutableTreeNode(); DefaultMutableTreeNode portuguesa = new DefaultMutableTreeNode("Normaliza" + ccedil + atilde + "o Portuguesa" ); @@ -349,7 +351,50 @@ public class HigieneSegurancaLogic return result; } - public static DefaultMutableTreeNode getLegislacaoTree( Empresas empresa ) + public static DefaultMutableTreeNode getNormalizacaoTreeForEstabelecimento( Estabelecimentos estabelecimento ) + { + DefaultMutableTreeNode result = new DefaultMutableTreeNode(); + DefaultMutableTreeNode portuguesa = new DefaultMutableTreeNode("Normaliza" + ccedil + atilde + "o Portuguesa" ); + DefaultMutableTreeNode internacional = new DefaultMutableTreeNode("Normaliza" + ccedil + atilde + "o Internacional" ); + for( HsNormalizacao normalizacao : planoProvider.getNormalizacao( true ) ) + { + if( estabelecimento == null || hasEstabelecimento( normalizacao, estabelecimento ) ) + { + DefaultMutableTreeNode normalizacaoNode = new DefaultMutableTreeNode( normalizacao ); + portuguesa.add( normalizacaoNode ); + } + } + for( HsNormalizacao normalizacao : planoProvider.getNormalizacao( false ) ) + { + if( estabelecimento == null || hasEstabelecimento( normalizacao, estabelecimento ) ) + { + DefaultMutableTreeNode normalizacaoNode = new DefaultMutableTreeNode( normalizacao ); + internacional.add( normalizacaoNode ); + } + } + result.add( portuguesa ); + result.add( internacional ); + return result; + } + + private static boolean hasEstabelecimento( HsNormalizacao normalizacao, Estabelecimentos estabelecimento ) + { + boolean result = false; + if( normalizacao != null && estabelecimento != null ) + { + for( HsNormalizacaoEstabelecimento rel : normalizacao.getHsNormalizacaoEstabelecimentoArray()) + { + result = estabelecimento.equals( rel.getToEstabelecimento() ); + if( result ) + { + break; + } + } + } + return result; + } + + public static DefaultMutableTreeNode getLegislacaoTreeForEmpresa( Empresas empresa ) { DefaultMutableTreeNode result = new DefaultMutableTreeNode(); DefaultMutableTreeNode geral = new DefaultMutableTreeNode( "Legisla" + ccedil + atilde + "o de aplica" + ccedil + atilde + "o geral" ); @@ -402,5 +447,59 @@ public class HigieneSegurancaLogic } return result; } + + public static DefaultMutableTreeNode getLegislacaoTreeForEstabelecimento( Estabelecimentos estabelecimento ) + { + DefaultMutableTreeNode result = new DefaultMutableTreeNode(); + DefaultMutableTreeNode geral = new DefaultMutableTreeNode( "Legisla" + ccedil + atilde + "o de aplica" + ccedil + atilde + "o geral" ); + DefaultMutableTreeNode especifica = new DefaultMutableTreeNode( "Legisla" + ccedil + atilde + "o espec" + iacute + "fica" ); + for( HsLegislacao legislacao : planoProvider.getAllLegislacaoGeral() ) + { + if( estabelecimento == null || hasEstabelecimento( legislacao, estabelecimento ) ) + { + DefaultMutableTreeNode legislacaoNode = new DefaultMutableTreeNode( legislacao ); + geral.add( legislacaoNode ); + } + } + for( HsLegislacaoCategoria categoria : planoProvider.getAllLegislacaoCategorias( ) ) + { + boolean addCategory = false; + DefaultMutableTreeNode categoriaNode = new DefaultMutableTreeNode( categoria ); + for( HsLegislacao legislacao : categoria.getHsLegislacaoArray() ) + { + if( estabelecimento == null || hasEstabelecimento( legislacao, estabelecimento ) ) + { + DefaultMutableTreeNode legislacaoNode = new DefaultMutableTreeNode( legislacao ); + categoriaNode.add( legislacaoNode ); + addCategory = true; + } + + } + if( addCategory) + { + especifica.add( categoriaNode ); + } + } + result.add( geral ); + result.add( especifica ); + return result; + } + + private static boolean hasEstabelecimento( HsLegislacao legislacao, Estabelecimentos estabelecimento ) + { + boolean result = false; + if( legislacao != null && estabelecimento != null ) + { + for( HsLegislacaoEstabelecimento rel : legislacao.getHsLegislacaoEstabelecimentoArray() ) + { + result = estabelecimento.equals( rel.getToHsEstabelecimento()); + if( result ) + { + break; + } + } + } + return result; + } }