From 7a985cc91afde0d2ecfa133ddf88f210c0b85417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tiago=20Sim=C3=A3o?= Date: Wed, 26 Nov 2008 21:38:56 +0000 Subject: [PATCH] git-svn-id: https://svn.coded.pt/svn/SIPRP@801 bb69d46d-e84e-40c8-a05a-06db0d633741 --- trunk/SIPRPSoft/src/siprp/SIPRPTracker.java | 2 +- .../companydataloaders/SIPRPDataLoader.java | 16 +- .../higiene/gestao/AdicionarEmailsPanel.java | 91 +++++ .../gestao/AdicionarLegislacaoPanel.java | 89 +++++ .../siprp/higiene/gestao/EmpresaPanel.java | 102 ++++++ .../higiene/gestao/GerirEmpresaPanel.java | 75 +++++ .../gestao/GerirEstabelecimentosPanel.java | 105 ++++++ .../higiene/gestao/GestaoRelatorioWindow.java | 80 +++++ .../src/siprp/higiene/gestao/GlobalPanel.java | 38 +++ .../higiene/gestao/TreeInserterDialog.java | 262 +++++++++++++++ .../gestao/postos/AdicionarAreasPanel.java | 149 ++++++++ .../siprp/higiene/gestao/postos/AreaNode.java | 17 + .../gestao/postos/GerirAreasPanel.java | 317 ++++++++++++++++++ .../higiene/gestao/postos/PostoNode.java | 17 + .../gestao/riscos/AdicionarRiscosPanel.java | 256 ++++++++++++++ .../riscos/GestaoRiscosLogic.java | 2 +- .../riscos/GestaoRiscosWindow.java | 28 +- .../{ => gestao}/riscos/NodeMedida.java | 2 +- .../{ => gestao}/riscos/NodeRisco.java | 2 +- .../{ => gestao}/riscos/NodeRiscoTema.java | 2 +- .../SIPRPSoft/src/siprp/printer/Printer.java | 1 - .../src/siprp/update/UpdateList.java | 2 +- .../siprp/update/updates/V9_8_To_V9_9.java | 71 ++++ trunk/common/src/SIPRPMap.map.xml | 129 +++++-- trunk/common/src/leaf/ui/TreeTools.java | 62 ++++ .../database/cayenne/objects/BaseObject.java | 12 +- .../database/cayenne/objects/HsEmail.java | 7 + .../cayenne/objects/HsEmailEmpresa.java | 7 + .../objects/HsEmailEstabelecimento.java | 7 + .../cayenne/objects/HsPostoRisco.java | 8 + .../cayenne/objects/HsRiscoEmpresa.java | 15 + .../cayenne/objects/auto/_Empresas.java | 28 ++ .../objects/auto/_Estabelecimentos.java | 14 + .../cayenne/objects/auto/_HsEmail.java | 54 +++ .../cayenne/objects/auto/_HsEmailEmpresa.java | 39 +++ .../objects/auto/_HsEmailEstabelecimento.java | 39 +++ .../cayenne/objects/auto/_HsPostoRisco.java | 5 +- .../cayenne/objects/auto/_HsRiscoEmpresa.java | 39 +++ 38 files changed, 2132 insertions(+), 59 deletions(-) create mode 100644 trunk/SIPRPSoft/src/siprp/higiene/gestao/AdicionarEmailsPanel.java create mode 100644 trunk/SIPRPSoft/src/siprp/higiene/gestao/AdicionarLegislacaoPanel.java create mode 100644 trunk/SIPRPSoft/src/siprp/higiene/gestao/EmpresaPanel.java create mode 100644 trunk/SIPRPSoft/src/siprp/higiene/gestao/GerirEmpresaPanel.java create mode 100644 trunk/SIPRPSoft/src/siprp/higiene/gestao/GerirEstabelecimentosPanel.java create mode 100644 trunk/SIPRPSoft/src/siprp/higiene/gestao/GestaoRelatorioWindow.java create mode 100644 trunk/SIPRPSoft/src/siprp/higiene/gestao/GlobalPanel.java create mode 100644 trunk/SIPRPSoft/src/siprp/higiene/gestao/TreeInserterDialog.java create mode 100644 trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/AdicionarAreasPanel.java create mode 100644 trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/AreaNode.java create mode 100644 trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/GerirAreasPanel.java create mode 100644 trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/PostoNode.java create mode 100644 trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/AdicionarRiscosPanel.java rename trunk/SIPRPSoft/src/siprp/higiene/{ => gestao}/riscos/GestaoRiscosLogic.java (98%) rename trunk/SIPRPSoft/src/siprp/higiene/{ => gestao}/riscos/GestaoRiscosWindow.java (92%) rename trunk/SIPRPSoft/src/siprp/higiene/{ => gestao}/riscos/NodeMedida.java (88%) rename trunk/SIPRPSoft/src/siprp/higiene/{ => gestao}/riscos/NodeRisco.java (87%) rename trunk/SIPRPSoft/src/siprp/higiene/{ => gestao}/riscos/NodeRiscoTema.java (88%) create mode 100644 trunk/SIPRPSoft/src/siprp/update/updates/V9_8_To_V9_9.java create mode 100644 trunk/common/src/leaf/ui/TreeTools.java create mode 100644 trunk/common/src/siprp/database/cayenne/objects/HsEmail.java create mode 100644 trunk/common/src/siprp/database/cayenne/objects/HsEmailEmpresa.java create mode 100644 trunk/common/src/siprp/database/cayenne/objects/HsEmailEstabelecimento.java create mode 100644 trunk/common/src/siprp/database/cayenne/objects/HsRiscoEmpresa.java create mode 100644 trunk/common/src/siprp/database/cayenne/objects/auto/_HsEmail.java create mode 100644 trunk/common/src/siprp/database/cayenne/objects/auto/_HsEmailEmpresa.java create mode 100644 trunk/common/src/siprp/database/cayenne/objects/auto/_HsEmailEstabelecimento.java create mode 100644 trunk/common/src/siprp/database/cayenne/objects/auto/_HsRiscoEmpresa.java diff --git a/trunk/SIPRPSoft/src/siprp/SIPRPTracker.java b/trunk/SIPRPSoft/src/siprp/SIPRPTracker.java index fca18607..55d31f64 100644 --- a/trunk/SIPRPSoft/src/siprp/SIPRPTracker.java +++ b/trunk/SIPRPSoft/src/siprp/SIPRPTracker.java @@ -14,10 +14,10 @@ import siprp.clientes.AvisosPanel; import siprp.clientes.ClientesWindow; import siprp.estatistica.EstatisticaWindow; import siprp.ficha.FichaWindow; +import siprp.higiene.gestao.riscos.GestaoRiscosWindow; import siprp.higiene.legislacoes.GestaoLegislacoesWindow; import siprp.higiene.mapa.MapaHigieneWindow; import siprp.higiene.marcacoes.MarcacoesHigieneWindow; -import siprp.higiene.riscos.GestaoRiscosWindow; import siprp.impressaofichas.ImpressaoFichasWindow; import siprp.lembretes.LembretesWindow; import siprp.medicina.MedicinaWindow; diff --git a/trunk/SIPRPSoft/src/siprp/companydataloaders/SIPRPDataLoader.java b/trunk/SIPRPSoft/src/siprp/companydataloaders/SIPRPDataLoader.java index 90bcd313..298f46ae 100644 --- a/trunk/SIPRPSoft/src/siprp/companydataloaders/SIPRPDataLoader.java +++ b/trunk/SIPRPSoft/src/siprp/companydataloaders/SIPRPDataLoader.java @@ -98,19 +98,19 @@ public class SIPRPDataLoader implements CompanyDataLoader // Singleton.setInstance( SingletonConstants.LOCAL_DB_NAME, "siprp_local_3" ); // Singleton.setInstance( SingletonConstants.LOCAL_DRIVER_NAME, "org.postgresql.Driver" ); - Singleton.setInstance( SingletonConstants.LOCAL_USER, "postgres" ); - Singleton.setInstance( SingletonConstants.LOCAL_PASSWORD, "Typein" ); - Singleton.setInstance( SingletonConstants.LOCAL_URL_PREFIX, "jdbc:postgresql://" ); - Singleton.setInstance( SingletonConstants.LOCAL_URL, "10.158.2.2:5432" ); - Singleton.setInstance( SingletonConstants.LOCAL_DB_NAME, "siprp_local" ); - Singleton.setInstance( SingletonConstants.LOCAL_DRIVER_NAME, "org.postgresql.Driver" ); - // Singleton.setInstance( SingletonConstants.LOCAL_USER, "postgres" ); // Singleton.setInstance( SingletonConstants.LOCAL_PASSWORD, "Typein" ); // Singleton.setInstance( SingletonConstants.LOCAL_URL_PREFIX, "jdbc:postgresql://" ); -// Singleton.setInstance( SingletonConstants.LOCAL_URL, "dbserver:5432" ); +// Singleton.setInstance( SingletonConstants.LOCAL_URL, "10.158.2.2:5432" ); // Singleton.setInstance( SingletonConstants.LOCAL_DB_NAME, "siprp_local" ); // Singleton.setInstance( SingletonConstants.LOCAL_DRIVER_NAME, "org.postgresql.Driver" ); +// + Singleton.setInstance( SingletonConstants.LOCAL_USER, "postgres" ); + Singleton.setInstance( SingletonConstants.LOCAL_PASSWORD, "Typein" ); + Singleton.setInstance( SingletonConstants.LOCAL_URL_PREFIX, "jdbc:postgresql://" ); + Singleton.setInstance( SingletonConstants.LOCAL_URL, "dbserver:5432" ); + Singleton.setInstance( SingletonConstants.LOCAL_DB_NAME, "siprp_local" ); + Singleton.setInstance( SingletonConstants.LOCAL_DRIVER_NAME, "org.postgresql.Driver" ); // // Singleton.setInstance( SingletonConstants.LOCAL_USER, "postgres" ); diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/AdicionarEmailsPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/AdicionarEmailsPanel.java new file mode 100644 index 00000000..39bb8920 --- /dev/null +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/AdicionarEmailsPanel.java @@ -0,0 +1,91 @@ +package siprp.higiene.gestao; + +import info.clearthought.layout.TableLayout; +import info.clearthought.layout.TableLayoutConstraints; + +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTree; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionListener; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeSelectionModel; + +import siprp.database.cayenne.objects.Empresas; + +import com.evolute.utils.tables.VectorTableModel; + +import leaf.ui.LeafButton; + +public class AdicionarEmailsPanel extends JPanel +{ + + private static final long serialVersionUID = 1L; + + private final LeafButton buttonAdicionar = new LeafButton("Adicionar"); + + private final LeafButton buttonRemover = new LeafButton("Remover"); + + private final VectorTableModel model = new VectorTableModel( new String[]{ "" } ); + + private final JTable table = new JTable( model ); + + private final JScrollPane scroll = new JScrollPane( table ); + + public AdicionarEmailsPanel() + { + startupComponents(); + setupLayout(); + placeComponents(); + startupListeners(); + } + + private void startupComponents() + { + buttonAdicionar.setEnabled( false ); + buttonRemover.setEnabled( false ); + table.getSelectionModel().setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); + } + + private void setupLayout() + { + TableLayout layout = new TableLayout( + new double[]{ TableLayout.FILL }, + new double[]{ TableLayout.MINIMUM, TableLayout.FILL } + ); + layout.setHGap( 5 ); + layout.setVGap( 5 ); + setLayout( layout ); + } + + private void placeComponents() + { + JPanel panel = new JPanel(); + TableLayout layout = new TableLayout( + new double[]{ TableLayout.MINIMUM, TableLayout.FILL, TableLayout.MINIMUM }, + new double[]{ TableLayout.MINIMUM } + ); + layout.setHGap( 5 ); + layout.setVGap( 5 ); + panel.setLayout( layout ); + panel.add( buttonAdicionar, new TableLayoutConstraints( 0, 0 ) ); + panel.add( buttonRemover, new TableLayoutConstraints( 2, 0 ) ); + + add( panel, new TableLayoutConstraints( 0, 0 ) ); + add( scroll, new TableLayoutConstraints( 0, 1 ) ); + } + + private void startupListeners() + { + + } + + public void setEmpresa( Empresas empresa ) + { + // TODO Auto-generated method stub + + } + +} diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/AdicionarLegislacaoPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/AdicionarLegislacaoPanel.java new file mode 100644 index 00000000..5db7bd97 --- /dev/null +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/AdicionarLegislacaoPanel.java @@ -0,0 +1,89 @@ +package siprp.higiene.gestao; + +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.TreeSelectionModel; + +import siprp.database.cayenne.objects.Empresas; + +import leaf.ui.LeafButton; + +public class AdicionarLegislacaoPanel extends JPanel +{ + + private static final long serialVersionUID = 1L; + + private final LeafButton buttonAdicionar = new LeafButton("Adicionar"); + + private final LeafButton buttonRemover = new LeafButton("Remover"); + + private final DefaultMutableTreeNode root = new DefaultMutableTreeNode(); + + private final DefaultTreeModel model = new DefaultTreeModel( root ); + + public final JTree tree = new JTree( model ); + + private final JScrollPane scroll = new JScrollPane( tree ); + + public AdicionarLegislacaoPanel() + { + startupComponents(); + setupLayout(); + placeComponents(); + startupListeners(); + } + + private void startupComponents() + { + buttonAdicionar.setEnabled( false ); + buttonRemover.setEnabled( false ); + tree.setRootVisible( false ); + tree.getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION ); + } + + private void setupLayout() + { + TableLayout layout = new TableLayout( + new double[]{ TableLayout.FILL }, + new double[]{ TableLayout.MINIMUM, TableLayout.FILL } + ); + layout.setHGap( 5 ); + layout.setVGap( 5 ); + setLayout( layout ); + } + + private void placeComponents() + { + JPanel panel = new JPanel(); + TableLayout layout = new TableLayout( + new double[]{ TableLayout.MINIMUM, TableLayout.FILL, TableLayout.MINIMUM }, + new double[]{ TableLayout.MINIMUM } + ); + layout.setHGap( 5 ); + layout.setVGap( 5 ); + panel.setLayout( layout ); + panel.add( buttonAdicionar, new TableLayoutConstraints( 0, 0 ) ); + panel.add( buttonRemover, new TableLayoutConstraints( 2, 0 ) ); + + add( panel, new TableLayoutConstraints( 0, 0 ) ); + add( scroll, new TableLayoutConstraints( 0, 1 ) ); + } + + private void startupListeners() + { + + } + + public void setEmpresa( Empresas empresa ) + { + // TODO Auto-generated method stub + + } + +} diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/EmpresaPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/EmpresaPanel.java new file mode 100644 index 00000000..74d0ec4b --- /dev/null +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/EmpresaPanel.java @@ -0,0 +1,102 @@ +package siprp.higiene.gestao; + +import info.clearthought.layout.TableLayout; +import info.clearthought.layout.TableLayoutConstraints; + +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.List; + +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTabbedPane; + +import siprp.database.cayenne.objects.Empresas; +import siprp.database.cayenne.providers.MedicinaDAO; + +public class EmpresaPanel extends JPanel +{ + + private static final long serialVersionUID = 1L; + + private final JComboBox comboEmpresa = new JComboBox(); + + private final GerirEmpresaPanel panelEmpresa = new GerirEmpresaPanel(); + + private final GerirEstabelecimentosPanel panelEstabelecimentos = new GerirEstabelecimentosPanel(); + + private final JTabbedPane tabs = new JTabbedPane(); + + public EmpresaPanel() + { + startupComponents(); + setupLayout(); + placeComponents(); + startupListeners(); + } + + private void startupComponents() + { + List empresas = new MedicinaDAO().getAllEmpresas(); + if( empresas != null ) + { + for( Empresas empresa : empresas ) + { + comboEmpresa.addItem( empresa ); + } + if( comboEmpresa.getItemCount() > 0 ) + { + comboEmpresa.setSelectedIndex( 0 ); + } + } + tabs.addTab( "Empresa", panelEmpresa ); + tabs.addTab( "Estabelecimentos", panelEstabelecimentos ); + } + + private void setupLayout() + { + double[] cols = new double[]{ + TableLayout.MINIMUM, TableLayout.FILL, + }; + double[] rows = new double[]{ + TableLayout.MINIMUM, TableLayout.FILL, + }; + TableLayout layout = new TableLayout(cols,rows); + layout.setHGap( 10 ); + layout.setVGap( 10 ); + this.setLayout( layout ); + } + + private void placeComponents() + { + this.add( new JLabel( "Empresa" ), new TableLayoutConstraints(0,0) ); + this.add( comboEmpresa, new TableLayoutConstraints(1,0) ); + this.add( tabs, new TableLayoutConstraints(0,1,1,1) ); + } + + private void startupListeners() + { + comboEmpresa.addItemListener( new ItemListener(){ + @Override + public void itemStateChanged( ItemEvent e ) + { + Object item = e.getItem(); + if( item != null && ItemEvent.SELECTED == e.getStateChange() ) + { + if( item instanceof Empresas ) + { + panelEmpresa.setEmpresa( (Empresas) item ); + panelEstabelecimentos.setEmpresa( (Empresas) item ); + } + } + else if( ItemEvent.DESELECTED == e.getStateChange() ) + { + panelEmpresa.setEmpresa( null ); + panelEstabelecimentos.setEmpresa( null ); + } + } + }); + } + +} diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/GerirEmpresaPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/GerirEmpresaPanel.java new file mode 100644 index 00000000..1f1cb27f --- /dev/null +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/GerirEmpresaPanel.java @@ -0,0 +1,75 @@ +package siprp.higiene.gestao; + +import java.awt.Dimension; + +import info.clearthought.layout.TableLayout; +import info.clearthought.layout.TableLayoutConstraints; + +import javax.swing.BorderFactory; +import javax.swing.JPanel; + +import siprp.database.cayenne.objects.Empresas; +import siprp.higiene.gestao.postos.GerirAreasPanel; +import siprp.higiene.gestao.riscos.AdicionarRiscosPanel; + +import static com.evolute.utils.strings.UnicodeLatin1Map.*; + +public class GerirEmpresaPanel extends JPanel +{ + + private static final long serialVersionUID = 1L; + + private final GerirAreasPanel panelAreas = new GerirAreasPanel(); + private final AdicionarRiscosPanel panelRiscos = new AdicionarRiscosPanel(); + private final AdicionarEmailsPanel panelEmails = new AdicionarEmailsPanel(); + private final AdicionarLegislacaoPanel panelLegislacao = new AdicionarLegislacaoPanel(); + + public GerirEmpresaPanel() + { + startupComponents(); + setupLayout(); + placeComponents(); + startupListeners(); + } + + private void startupComponents() + { + panelAreas.setBorder( BorderFactory.createTitledBorder( "Postos 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.FILL, TableLayout.PREFERRED }; + TableLayout layout = new TableLayout( cols, rows ); + layout.setHGap( 5 ); + layout.setVGap( 5 ); + this.setLayout( layout ); + } + + private void placeComponents() + { + this.add( panelAreas, new TableLayoutConstraints( 0, 0, 0, 1 ) ); + this.add( panelRiscos, new TableLayoutConstraints( 1, 0, 1, 1 ) ); + this.add( panelLegislacao, new TableLayoutConstraints( 2, 0 ) ); + this.add( panelEmails, new TableLayoutConstraints( 2, 1 ) ); + } + + private void startupListeners() + { + + } + + public void setEmpresa( Empresas empresa ) + { + panelAreas.setEmpresa( empresa ); + panelEmails.setEmpresa( empresa ); + panelLegislacao.setEmpresa( empresa ); + panelRiscos.setEmpresa( empresa ); + } + +} diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/GerirEstabelecimentosPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/GerirEstabelecimentosPanel.java new file mode 100644 index 00000000..73bbebc7 --- /dev/null +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/GerirEstabelecimentosPanel.java @@ -0,0 +1,105 @@ +package siprp.higiene.gestao; + +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 java.awt.Dimension; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; + +import javax.swing.BorderFactory; +import javax.swing.JComboBox; +import javax.swing.JPanel; + +import siprp.database.cayenne.objects.Empresas; +import siprp.database.cayenne.objects.Estabelecimentos; +import siprp.higiene.gestao.postos.AdicionarAreasPanel; +import siprp.higiene.gestao.riscos.AdicionarRiscosPanel; + +public class GerirEstabelecimentosPanel extends JPanel +{ + + private static final long serialVersionUID = 1L; + + private final JComboBox comboEstabelecimentos = new JComboBox(); + private final AdicionarAreasPanel panelAreas = new AdicionarAreasPanel(); + private final AdicionarRiscosPanel panelRiscos = new AdicionarRiscosPanel(); + private final AdicionarEmailsPanel panelEmails = new AdicionarEmailsPanel(); + private final AdicionarLegislacaoPanel panelLegislacao = new AdicionarLegislacaoPanel(); + + public GerirEstabelecimentosPanel() + { + startupComponents(); + setupLayout(); + placeComponents(); + startupListeners(); + } + + private void startupComponents() + { + panelAreas.setBorder( BorderFactory.createTitledBorder( "Postos 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 }; + TableLayout layout = new TableLayout( cols, rows ); + layout.setHGap( 5 ); + layout.setVGap( 5 ); + this.setLayout( layout ); + } + + private void placeComponents() + { + 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( panelLegislacao, new TableLayoutConstraints( 2, 1 ) ); + this.add( panelEmails, new TableLayoutConstraints( 2, 2 ) ); + } + + private void startupListeners() + { + comboEstabelecimentos.addItemListener( new ItemListener() + { + @Override + public void itemStateChanged( ItemEvent e ) + { + if( e.getItem() != null && ItemEvent.SELECTED == e.getStateChange() ) + { + if( e.getItem() instanceof Estabelecimentos ) + { + panelAreas.setEstabelecimento( (Estabelecimentos) e.getItem() ); + } + } + } + } ); + } + + public void setEmpresa( Empresas empresa ) + { + comboEstabelecimentos.removeAllItems(); + if( empresa != null ) + { + for( Estabelecimentos estabelecimento : empresa.getEstabelecimentosArray() ) + { + comboEstabelecimentos.addItem( estabelecimento ); + } + if( comboEstabelecimentos.getItemCount() > 0 ) + { + comboEstabelecimentos.setSelectedIndex( 0 ); + } + } + panelEmails.setEmpresa( empresa ); + panelLegislacao.setEmpresa( empresa ); + } + +} diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/GestaoRelatorioWindow.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/GestaoRelatorioWindow.java new file mode 100644 index 00000000..7f564c21 --- /dev/null +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/GestaoRelatorioWindow.java @@ -0,0 +1,80 @@ +package siprp.higiene.gestao; + +import java.awt.Dimension; + +import javax.swing.JFrame; +import javax.swing.JTabbedPane; +import javax.swing.SwingUtilities; + +import com.evolute.utils.tracker.TrackableWindow; + +import static com.evolute.utils.strings.UnicodeLatin1Map.*; + +public class GestaoRelatorioWindow extends JFrame implements TrackableWindow +{ + + public static final String TITLE = "Gest" + atilde + "o de Relat" + oacute + "rio de Higiene e Seguran" + ccedil + "a"; + + private static final Dimension SIZE = new Dimension( 800, 600 ); + + private static final long serialVersionUID = 1L; + + private final JTabbedPane tabs = new JTabbedPane(); + + private final GlobalPanel panelGlobal = new GlobalPanel(); + + private final EmpresaPanel panelEmpresa = new EmpresaPanel(); + + public static void main( String[] args ) + { + GestaoRelatorioWindow window = new GestaoRelatorioWindow(); + window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); + window.open(); + } + + public GestaoRelatorioWindow() + { + this.setTitle( TITLE ); + this.setSize( SIZE ); + placeComponents(); + } + + private void placeComponents() + { + tabs.addTab( "Global", panelGlobal ); + tabs.addTab( "Por Empresa", panelEmpresa ); + this.setContentPane( tabs ); + } + + @Override + public void open() + { + setVisible( true ); + } + + public void close() + { + SwingUtilities.invokeLater( new Runnable() + { + public void run() + { + setVisible( false ); + dispose(); + } + } ); + } + + @Override + public boolean closeIfPossible() + { + close(); + return true; + } + + @Override + public void refresh() + { + } + + +} diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/GlobalPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/GlobalPanel.java new file mode 100644 index 00000000..bb3a820f --- /dev/null +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/GlobalPanel.java @@ -0,0 +1,38 @@ +package siprp.higiene.gestao; + +import javax.swing.JPanel; + +public class GlobalPanel extends JPanel +{ + + private static final long serialVersionUID = 1L; + + public GlobalPanel() + { + startupComponents(); + setupLayout(); + placeComponents(); + startupListeners(); + } + + private void startupComponents() + { + + } + + private void setupLayout() + { + + } + + private void placeComponents() + { + + } + + private void startupListeners() + { + + } + +} diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/TreeInserterDialog.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/TreeInserterDialog.java new file mode 100644 index 00000000..20b1644d --- /dev/null +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/TreeInserterDialog.java @@ -0,0 +1,262 @@ +package siprp.higiene.gestao; + +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 javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JScrollPane; +import javax.swing.JTree; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreePath; +import javax.swing.tree.TreeSelectionModel; + +import leaf.ui.LeafButton; +import leaf.ui.TreeTools; + + +public class TreeInserterDialog extends JDialog +{ + + private static final long serialVersionUID = 1L; + + private static final Dimension allDimension = new Dimension(300,500); + + private static final Dimension newDimension = new Dimension(300,400); + + private final DefaultMutableTreeNode newRoot = new DefaultMutableTreeNode(); + + private final DefaultTreeModel newModel = new DefaultTreeModel( newRoot ); + + private final JTree newTree = new JTree(newModel); + + private final JScrollPane newScroll = new JScrollPane( newTree ); + + private final DefaultMutableTreeNode allRoot; + + private final DefaultTreeModel allModel; + + private final JTree allTree; + + private final JScrollPane allScroll; + + private final LeafButton buttonAdd = new LeafButton( "->" ); + + private final LeafButton buttonRemove = new LeafButton( "<-" ); + + private final LeafButton buttonOK = new LeafButton( "OK" ); + + private final LeafButton buttonCancel = new LeafButton( "Cancelar" ); + + public TreeInserterDialog( String title, DefaultMutableTreeNode root ) + { + this.allRoot = root; + this.allModel = new DefaultTreeModel( allRoot ); + this.allTree = new JTree(allModel); + this.allScroll = new JScrollPane( allTree ); + this.setTitle( title ); + startupComponents(); + setupLayout(); + placeComponents(); + startupListeners(); + TreeTools.refreshTree(allTree, allRoot); + setEnabled(); + this.setLocationRelativeTo( null ); + this.setSize( 680, 400 ); + this.setModal( true ); + this.setVisible( true ); + } + + private void startupComponents() + { + newTree.setRootVisible( false ); + newTree.getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION ); + allTree.setRootVisible( false ); + allTree.getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION ); + allScroll.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS ); + allScroll.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); + newScroll.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS ); + newScroll.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); + allScroll.setPreferredSize( allDimension ); + newScroll.setPreferredSize( newDimension ); + } + + private void setupLayout() + { + TableLayout layout = new TableLayout( + new double[]{ TableLayout.FILL, TableLayout.MINIMUM, TableLayout.PREFERRED, TableLayout.MINIMUM, TableLayout.MINIMUM }, + new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL, TableLayout.MINIMUM, TableLayout.MINIMUM } + ); + layout.setHGap( 5 ); + layout.setVGap( 5 ); + getContentPane().setLayout( layout ); + } + + private void placeComponents() + { + getContentPane().add( new JLabel("Todos"), new TableLayoutConstraints( 0,0 ) ); + getContentPane().add( new JLabel("a adicionar..."), new TableLayoutConstraints( 2,0,4,0 ) ); + getContentPane().add( allScroll, new TableLayoutConstraints( 0,1,0,4 ) ); + getContentPane().add( buttonAdd, new TableLayoutConstraints( 1,1 ) ); + getContentPane().add( buttonRemove, new TableLayoutConstraints( 1,3 ) ); + getContentPane().add( newScroll, new TableLayoutConstraints( 2,1,4,3 ) ); + getContentPane().add( buttonOK, new TableLayoutConstraints( 3,4 ) ); + getContentPane().add( buttonCancel, new TableLayoutConstraints( 4,4 ) ); + } + + private void startupListeners() + { + buttonAdd.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + move( allTree, newTree ); + } + } ); + buttonRemove.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + move( newTree, allTree ); + } + } ); + buttonOK.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + ok(); + } + } ); + buttonCancel.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + cancel(); + } + } ); + allTree.getSelectionModel().addTreeSelectionListener( new TreeSelectionListener(){ + @Override + public void valueChanged( TreeSelectionEvent e ) + { + setEnabled(); + } + } ); + newTree.getSelectionModel().addTreeSelectionListener( new TreeSelectionListener(){ + @Override + public void valueChanged( TreeSelectionEvent e ) + { + setEnabled(); + } + } ); + } + + private void move( JTree from, JTree to ) + { + TreePath path = from.getSelectionPath(); + DefaultMutableTreeNode fromRoot = (DefaultMutableTreeNode) from.getModel().getRoot(); + DefaultMutableTreeNode toRoot = (DefaultMutableTreeNode) to.getModel().getRoot(); + if( path != null ) + { + for( int i = 1; i < path.getPathCount(); ++i ) + { + DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getPathComponent( i ); + DefaultMutableTreeNode parent = (DefaultMutableTreeNode) path.getPathComponent( i-1 ); + if( node != null && parent != null ) + { + DefaultMutableTreeNode exists = TreeTools.findNodeWithUserObject( node.getUserObject(), toRoot ); + if( exists == null ) + { + add(node, parent.getUserObject(), toRoot, path.getPathCount() == i + 1 ); + } + else + { + merge( exists, node ); + } + } + } + removeNode( (DefaultMutableTreeNode) path.getLastPathComponent(), fromRoot ); + } + TreeTools.refreshTree( from, fromRoot ); + TreeTools.refreshTree( to, toRoot ); + } + + private void merge( DefaultMutableTreeNode with, DefaultMutableTreeNode what ) + { + for( int i = 0; i < what.getChildCount(); ++i ) + { + DefaultMutableTreeNode child = (DefaultMutableTreeNode) what.getChildAt( i ); + DefaultMutableTreeNode exists = TreeTools.findNodeWithUserObject( child.getUserObject(), with ); + if( exists == null ) + { + with.add( TreeTools.cloneFullNode( child ) ); + } + else + { + merge( exists, child ); + } + } + } + + private void removeNode( DefaultMutableTreeNode node, DefaultMutableTreeNode root ) + { + DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); + node.removeFromParent(); + if( parent != null && parent.getChildCount() == 0 ) + { + removeNode( parent, root ); + } + } + + private void add( DefaultMutableTreeNode node, Object parent, DefaultMutableTreeNode where, boolean fullClone ) + { + DefaultMutableTreeNode parentNode = TreeTools.findNodeWithUserObject( parent, where ); + if( parentNode == null ) + { + parentNode = where; + } + parentNode.add( fullClone ? TreeTools.cloneFullNode(node) : (DefaultMutableTreeNode) node.clone() ); + } + + private void ok() + { + close(); + } + + private void cancel() + { + newRoot.removeAllChildren(); + close(); + } + + private void close() + { + setVisible( false ); + } + + private void setEnabled() + { + boolean allSelected = allTree.getSelectionPath() != null; + boolean newSelected = newTree.getSelectionPath() != null; + boolean somethingToAdd = newRoot.getChildCount() > 0; + buttonAdd.setEnabled( allSelected ); + buttonRemove.setEnabled( newSelected ); + buttonOK.setEnabled( somethingToAdd ); + } + + public DefaultMutableTreeNode getResult() + { + return newRoot; + } + +} diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/AdicionarAreasPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/AdicionarAreasPanel.java new file mode 100644 index 00000000..6382321e --- /dev/null +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/AdicionarAreasPanel.java @@ -0,0 +1,149 @@ +package siprp.higiene.gestao.postos; + +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.TreeSelectionModel; + +import leaf.ui.LeafButton; +import siprp.database.cayenne.objects.Estabelecimentos; +import siprp.database.cayenne.objects.HsArea; +import siprp.database.cayenne.objects.HsPosto; +import siprp.database.cayenne.objects.HsPostoEstabelecimento; + +public class AdicionarAreasPanel extends JPanel +{ + + private static final long serialVersionUID = 1L; + + private final LeafButton buttonAdicionar = new LeafButton("Adicionar"); + + private final LeafButton buttonRemover = new LeafButton("Remover"); + + private final DefaultMutableTreeNode root = new DefaultMutableTreeNode(); + + private final DefaultTreeModel model = new DefaultTreeModel( root ); + + public final JTree tree = new JTree( model ); + + private final JScrollPane scroll = new JScrollPane( tree ); + + private Estabelecimentos estabelecimento = null; + + public AdicionarAreasPanel() + { + startupComponents(); + setupLayout(); + placeComponents(); + startupListeners(); + } + + private void startupComponents() + { + buttonAdicionar.setEnabled( false ); + buttonRemover.setEnabled( false ); + tree.setRootVisible( false ); + tree.getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION ); + } + + private void setupLayout() + { + TableLayout layout = new TableLayout( + new double[]{ TableLayout.FILL }, + new double[]{ TableLayout.MINIMUM, TableLayout.FILL } + ); + layout.setHGap( 5 ); + layout.setVGap( 5 ); + setLayout( layout ); + } + + private void placeComponents() + { + JPanel panel = new JPanel(); + TableLayout layout = new TableLayout( + new double[]{ TableLayout.MINIMUM, TableLayout.FILL, TableLayout.MINIMUM }, + new double[]{ TableLayout.MINIMUM } + ); + layout.setHGap( 5 ); + layout.setVGap( 5 ); + panel.setLayout( layout ); + panel.add( buttonAdicionar, new TableLayoutConstraints( 0, 0 ) ); + panel.add( buttonRemover, new TableLayoutConstraints( 2, 0 ) ); + + add( panel, new TableLayoutConstraints( 0, 0 ) ); + add( scroll, new TableLayoutConstraints( 0, 1 ) ); + } + + private void startupListeners() + { + + } + + private void setEnabled() + { + buttonAdicionar.setEnabled( estabelecimento != null ); + buttonRemover.setEnabled( tree.getSelectionCount() > 0 ); + } + + public void refresh() + { + root.removeAllChildren(); + if( estabelecimento != null ) + { + for( HsPostoEstabelecimento rel : estabelecimento.getHsPostoEstabelecimentoArray() ) + { + addPosto( rel.getToHsPosto() ); + } + } + setEnabled(); + ((DefaultTreeModel) tree.getModel()).nodeStructureChanged( root ); + for( int i = 0; i < tree.getRowCount(); ++i) + { + tree.expandPath( tree.getPathForRow( i ) ); + } + } + + private void addPosto( HsPosto posto ) + { + if( posto != null ) + { + HsArea area = posto.getToHsArea(); + AreaNode areaNode = getAreaNodeWith( area ); + if( areaNode == null ) + { + areaNode = new AreaNode( area ); + root.add( areaNode ); + } + areaNode.add( new PostoNode( posto ) ); + } + } + + private AreaNode getAreaNodeWith( HsArea area ) + { + AreaNode result = null; + if( area != null ) + { + for( int i = 0; i < root.getChildCount(); ++i ) + { + if( area.equals( ( (AreaNode) root.getChildAt( i )).getUserObject() ) ) + { + result = (AreaNode) root.getChildAt( i ); + } + } + } + return result; + } + + + public void setEstabelecimento( Estabelecimentos estabelecimento ) + { + this.estabelecimento = estabelecimento; + refresh(); + } + +} diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/AreaNode.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/AreaNode.java new file mode 100644 index 00000000..282250a3 --- /dev/null +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/AreaNode.java @@ -0,0 +1,17 @@ +package siprp.higiene.gestao.postos; + +import javax.swing.tree.DefaultMutableTreeNode; + +import siprp.database.cayenne.objects.HsArea; + +public class AreaNode extends DefaultMutableTreeNode +{ + + private static final long serialVersionUID = 1L; + + public AreaNode( HsArea risco ) + { + super( risco ); + } + +} diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/GerirAreasPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/GerirAreasPanel.java new file mode 100644 index 00000000..7e0c7ff1 --- /dev/null +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/GerirAreasPanel.java @@ -0,0 +1,317 @@ +package siprp.higiene.gestao.postos; + +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 info.clearthought.layout.TableLayout; +import info.clearthought.layout.TableLayoutConstraints; + +import java.awt.Dimension; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Date; + +import javax.swing.BorderFactory; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTree; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeNode; +import javax.swing.tree.TreePath; +import javax.swing.tree.TreeSelectionModel; + +import leaf.ui.LeafButton; +import leaf.ui.TreeTools; +import siprp.database.cayenne.objects.Empresas; +import siprp.database.cayenne.objects.HsArea; +import siprp.database.cayenne.objects.HsPosto; + +public class GerirAreasPanel extends JPanel +{ + + private static final long serialVersionUID = 1L; + + private final JPanel panelButtons = new JPanel(); + + private final JPanel panelTree = new JPanel(); + + public final LeafButton buttonAreaCriar = new LeafButton( "Criar" ); + + public final LeafButton buttonAreaRemover = new LeafButton( "Remover" ); + + public final LeafButton buttonPostoCriar = new LeafButton( "Criar" ); + + public final LeafButton buttonPostoRemover = new LeafButton( "Remover" ); + + private final DefaultMutableTreeNode root = new DefaultMutableTreeNode(); + + private final DefaultTreeModel model = new DefaultTreeModel( root ); + + public final JTree tree = new JTree( model ); + + private final JScrollPane scroll = new JScrollPane( tree ); + + private Empresas empresa = null; + + public GerirAreasPanel() + { + startupComponents(); + startupLayout(); + placeComponents(); + setupListeners(); + } + + + private void startupComponents() + { + panelButtons.setPreferredSize( new Dimension( 150, 0 ) ); + panelTree.setPreferredSize( new Dimension( 300, 0 ) ); + tree.setRootVisible( false ); + tree.getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION ); + } + + private void startupLayout() + { + TableLayout layout = new TableLayout( + new double[]{ TableLayout.FILL }, + new double[]{ TableLayout.MINIMUM, TableLayout.FILL } + ); + layout.setHGap( 5 ); + layout.setVGap( 5 ); + setLayout( layout ); + + layout = new TableLayout( + new double[]{ TableLayout.MINIMUM, TableLayout.FILL, TableLayout.MINIMUM }, + new double[]{ TableLayout.MINIMUM } + ); + 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 ); + } + + private void placeComponents() + { + JPanel panel = new JPanel(); + panel.setBorder( BorderFactory.createTitledBorder( "Area" ) ); + panel.setLayout( new GridLayout( 2, 1 ) ); + panel.add( buttonAreaCriar ); + panel.add( buttonAreaRemover ); + panelButtons.add( panel, new TableLayoutConstraints( 0, 0 ) ); + + panel = new JPanel(); + panel.setBorder( BorderFactory.createTitledBorder( "Posto" ) ); + panel.setLayout( new GridLayout( 2, 1 ) ); + panel.add( buttonPostoCriar ); + panel.add( buttonPostoRemover ); + panelButtons.add( panel, new TableLayoutConstraints( 2, 0 ) ); + + panelTree.add( scroll, new TableLayoutConstraints( 0,0 ) ); + + add( panelButtons, new TableLayoutConstraints( 0, 0 ) ); + add( panelTree, new TableLayoutConstraints( 0, 1 ) ); + } + + private void setupListeners() + { + tree.getSelectionModel().addTreeSelectionListener( new TreeSelectionListener(){ + @Override + public void valueChanged( TreeSelectionEvent e ) + { + setEnabled(); + } + } ); + buttonAreaCriar.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + criarArea(); + } + } ); + buttonAreaRemover.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + removerArea(); + } + } ); + buttonPostoCriar.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + criarPosto(); + } + } ); + buttonPostoRemover.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + removerPosto(); + } + } ); + } + + private void criarArea() + { + if( empresa != null ) + { + String areaString = JOptionPane.showInputDialog( this, "Descri" + ccedil + atilde + "o", "Criar nova " + aacute + "rea", JOptionPane.QUESTION_MESSAGE ); + if( areaString != null ) + { + HsArea area = new HsArea(); + area.setToEmpresas( empresa ); + area.setDescription( areaString ); + area.save(); + refresh(); + } + } + } + + private void removerArea() + { + HsArea area = getSelectedArea(); + if( area != null ) + { + area.delete(); + refresh(); + } + } + + private void criarPosto() + { + HsArea area = getSelectedArea(); + if( area != null ) + { + String postoString = JOptionPane.showInputDialog( this, "Descri" + ccedil + atilde + "o", "Criar novo posto de trabalho", JOptionPane.QUESTION_MESSAGE ); + if( postoString != null ) + { + HsPosto posto = new HsPosto(); + posto.setToHsArea( area ); + posto.setDescription( postoString ); + posto.save(); + refresh(); + } + refresh(); + } + } + + private void removerPosto() + { + HsPosto posto = getSelectedPosto(); + if( posto != null ) + { + posto.setDeletedDate( new Date() ); + posto.save(); + refresh(); + } + } + + private HsArea getSelectedArea() + { + HsArea result = null; + TreePath path = tree.getSelectionPath(); + if( path != null ) + { + Object leaf = path.getLastPathComponent(); + if( leaf != null ) + { + if(leaf instanceof AreaNode) + { + result = (HsArea) ((AreaNode)leaf).getUserObject(); + } + else if(leaf instanceof PostoNode) + { + result = (HsArea) ((HsPosto)((PostoNode)leaf).getUserObject()).getToHsArea(); + } + } + } + return result; + } + + private HsPosto getSelectedPosto() + { + HsPosto result = null; + TreePath path = tree.getSelectionPath(); + if( path != null ) + { + Object leaf = path.getLastPathComponent(); + if( leaf != null && ( leaf instanceof PostoNode ) ) + { + result = (HsPosto) ((PostoNode)leaf).getUserObject(); + } + } + return result; + } + + + private void setEnabled() + { + TreePath path = tree.getSelectionPath(); + TreeNode node = path == null ? null : (TreeNode) path.getLastPathComponent(); + boolean areaSelected = node != null && ( node instanceof AreaNode ); + boolean postoSelected = node != null && ( node instanceof PostoNode ); + buttonPostoCriar.setEnabled( areaSelected || postoSelected ); + buttonPostoRemover.setEnabled( postoSelected ); + buttonAreaRemover.setEnabled( areaSelected ); + buttonAreaCriar.setEnabled( empresa != null ); + } + + public void refresh() + { + root.removeAllChildren(); + if( empresa != null ) + { + for( HsArea area : empresa.getHsAreaArray()) + { + addArea( area ); + } + } + setEnabled(); + TreeTools.refreshTree(tree, root); + } + + private void addArea( HsArea area ) + { + if( area != null ) + { + AreaNode areaNode = new AreaNode( area ); + for ( HsPosto posto : area.getHsPostoArray() ) + { + addPosto( posto, areaNode ); + } + root.add( areaNode ); + } + } + + private void addPosto( HsPosto posto, AreaNode areaNode ) + { + if( posto != null && posto.getDeletedDate() == null ) + { + PostoNode postoNode = new PostoNode( posto ); + areaNode.add( postoNode ); + } + } + + public void setEmpresa( Empresas empresa ) + { + this.empresa = empresa; + refresh(); + } + +} diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/PostoNode.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/PostoNode.java new file mode 100644 index 00000000..d57071cd --- /dev/null +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/postos/PostoNode.java @@ -0,0 +1,17 @@ +package siprp.higiene.gestao.postos; + +import javax.swing.tree.DefaultMutableTreeNode; + +import siprp.database.cayenne.objects.HsPosto; + +public class PostoNode extends DefaultMutableTreeNode +{ + + private static final long serialVersionUID = 1L; + + public PostoNode( HsPosto risco ) + { + super( risco ); + } + +} diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/AdicionarRiscosPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/AdicionarRiscosPanel.java new file mode 100644 index 00000000..722d7f9c --- /dev/null +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/AdicionarRiscosPanel.java @@ -0,0 +1,256 @@ +package siprp.higiene.gestao.riscos; + +import info.clearthought.layout.TableLayout; +import info.clearthought.layout.TableLayoutConstraints; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.List; + +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTree; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreePath; +import javax.swing.tree.TreeSelectionModel; + +import leaf.ui.LeafButton; +import leaf.ui.TreeTools; +import siprp.database.cayenne.objects.BaseObject; +import siprp.database.cayenne.objects.Empresas; +import siprp.database.cayenne.objects.HsMedida; +import siprp.database.cayenne.objects.HsPosto; +import siprp.database.cayenne.objects.HsPostoRisco; +import siprp.database.cayenne.objects.HsRisco; +import siprp.database.cayenne.objects.HsRiscoEmpresa; +import siprp.database.cayenne.objects.HsRiscoMedida; +import siprp.database.cayenne.objects.HsRiscoTema; +import siprp.database.cayenne.providers.PlanoActuacaoDAO; +import siprp.higiene.gestao.TreeInserterDialog; + +public class AdicionarRiscosPanel extends JPanel +{ + + private static final long serialVersionUID = 1L; + + private final LeafButton buttonAdicionar = new LeafButton("Adicionar"); + + private final LeafButton buttonRemover = new LeafButton("Remover"); + + private final DefaultMutableTreeNode root = new DefaultMutableTreeNode(); + + private final DefaultTreeModel model = new DefaultTreeModel( root ); + + public final JTree tree = new JTree( model ); + + private final JScrollPane scroll = new JScrollPane( tree ); + + private Empresas empresa = null; + + private HsPosto posto = null; + + public AdicionarRiscosPanel() + { + startupComponents(); + setupLayout(); + placeComponents(); + startupListeners(); + } + + private void startupComponents() + { + buttonAdicionar.setEnabled( false ); + buttonRemover.setEnabled( false ); + tree.setRootVisible( false ); + tree.getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION ); + } + + private void setupLayout() + { + TableLayout layout = new TableLayout( + new double[]{ TableLayout.FILL }, + new double[]{ TableLayout.MINIMUM, TableLayout.FILL } + ); + layout.setHGap( 5 ); + layout.setVGap( 5 ); + setLayout( layout ); + } + + private void placeComponents() + { + JPanel panel = new JPanel(); + TableLayout layout = new TableLayout( + new double[]{ TableLayout.MINIMUM, TableLayout.FILL, TableLayout.MINIMUM }, + new double[]{ TableLayout.MINIMUM } + ); + layout.setHGap( 5 ); + layout.setVGap( 5 ); + panel.setLayout( layout ); + panel.add( buttonAdicionar, new TableLayoutConstraints( 0, 0 ) ); + panel.add( buttonRemover, new TableLayoutConstraints( 2, 0 ) ); + + add( panel, new TableLayoutConstraints( 0, 0 ) ); + add( scroll, new TableLayoutConstraints( 0, 1 ) ); + } + + private void startupListeners() + { + buttonAdicionar.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + add(); + } + } ); + buttonRemover.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + rem(); + } + } ); + tree.getSelectionModel().addTreeSelectionListener( new TreeSelectionListener(){ + @Override + public void valueChanged( TreeSelectionEvent e ) + { + setEnabled(); + } + } ); + } + + private void add() + { + List temas = new PlanoActuacaoDAO().getAllRiscoTemas(); + if( temas != null ) + { + DefaultMutableTreeNode allRiscos = new DefaultMutableTreeNode(); + allRiscos.removeAllChildren(); + for( HsRiscoTema tema : temas ) + { + NodeRiscoTema temaNode = new NodeRiscoTema( tema ); + for( HsRisco risco : tema.getHsRiscoArray() ) + { + NodeRisco riscoNode = new NodeRisco( risco ); + for( HsRiscoMedida rel : risco.getHsRiscoMedidaArray() ) + { + riscoNode.add( new NodeMedida( rel ) ); + } + temaNode.add( riscoNode ); + } + allRiscos.add( temaNode ); + } + TreeInserterDialog dialog = new TreeInserterDialog("Adicionar Riscos",allRiscos); + DefaultMutableTreeNode result = dialog.getResult(); + if( result != null ) + { + addResult(result); + refresh(); + } + } + setEnabled(); + } + + private void addResult( DefaultMutableTreeNode root ) + { + if( root != null ) + { + if( root instanceof NodeRisco ) + { + HsRisco risco = (HsRisco) root.getUserObject(); + if( empresa != null ) + { + HsRiscoEmpresa rel = new HsRiscoEmpresa(); + rel.setToEmpresa( empresa ); + rel.setToHsRisco( risco ); + rel.save(); + } + else if( posto != null ) + { + HsPostoRisco rel = new HsPostoRisco(); + rel.setToHsPosto( posto); + rel.setToHsRisco( risco ); + rel.save(); + } + } + for( int i = 0; i < root.getChildCount(); ++i ) + { + DefaultMutableTreeNode child = (DefaultMutableTreeNode) root.getChildAt( i ); + addResult( child ); + } + } + } + + + private void rem() + { + TreePath path = tree.getSelectionPath(); + if (path != null) + { + DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); + Object obj = node.getUserObject(); + if( obj != null ) + { + ((BaseObject) obj).delete(); + refresh(); + } + } + } + + private void setEnabled() + { + if( empresa != null ) + { + buttonAdicionar.setEnabled( true ); + } + else if( posto != null ) + { + buttonAdicionar.setEnabled( true ); + } + else + { + buttonAdicionar.setEnabled( false ); + } + buttonRemover.setEnabled( tree.getSelectionCount() > 0 ); + } + + public void refresh() + { + root.removeAllChildren(); + if( empresa != null ) + { + for( HsRiscoEmpresa rel : empresa.getHsRiscoEmpresaArray() ) + { + root.add( new DefaultMutableTreeNode( rel ) ); + } + } + else if( posto != null ) + { + for( HsPostoRisco rel : posto.getHsPostoRiscoArray() ) + { + root.add( new DefaultMutableTreeNode( rel ) ); + } + } + setEnabled(); + TreeTools.refreshTree( tree, root ); + } + + public void setEmpresa( Empresas empresa ) + { + this.empresa = empresa; + this.posto = null; + refresh(); + } + + public void setPosto( HsPosto posto ) + { + this.posto = posto; + this.empresa = null; + refresh(); + } + +} diff --git a/trunk/SIPRPSoft/src/siprp/higiene/riscos/GestaoRiscosLogic.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/GestaoRiscosLogic.java similarity index 98% rename from trunk/SIPRPSoft/src/siprp/higiene/riscos/GestaoRiscosLogic.java rename to trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/GestaoRiscosLogic.java index 012e0b8b..ce528319 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/riscos/GestaoRiscosLogic.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/GestaoRiscosLogic.java @@ -1,4 +1,4 @@ -package siprp.higiene.riscos; +package siprp.higiene.gestao.riscos; import java.util.Date; diff --git a/trunk/SIPRPSoft/src/siprp/higiene/riscos/GestaoRiscosWindow.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/GestaoRiscosWindow.java similarity index 92% rename from trunk/SIPRPSoft/src/siprp/higiene/riscos/GestaoRiscosWindow.java rename to trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/GestaoRiscosWindow.java index e3f7d781..14b9ea1b 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/riscos/GestaoRiscosWindow.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/GestaoRiscosWindow.java @@ -1,22 +1,22 @@ -package siprp.higiene.riscos; +package siprp.higiene.gestao.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 static siprp.higiene.gestao.riscos.GestaoRiscosLogic.ACTION_CLEAR_SELECTION; +import static siprp.higiene.gestao.riscos.GestaoRiscosLogic.ACTION_LOAD; +import static siprp.higiene.gestao.riscos.GestaoRiscosLogic.ACTION_MEDIDA_CRIAR; +import static siprp.higiene.gestao.riscos.GestaoRiscosLogic.ACTION_MEDIDA_REMOVER; +import static siprp.higiene.gestao.riscos.GestaoRiscosLogic.ACTION_RISCO_CRIAR; +import static siprp.higiene.gestao.riscos.GestaoRiscosLogic.ACTION_RISCO_REMOVER; +import static siprp.higiene.gestao.riscos.GestaoRiscosLogic.ACTION_SAVE; +import static siprp.higiene.gestao.riscos.GestaoRiscosLogic.ACTION_SELECTION; +import static siprp.higiene.gestao.riscos.GestaoRiscosLogic.ACTION_SELECT_MEDIDA; +import static siprp.higiene.gestao.riscos.GestaoRiscosLogic.ACTION_SELECT_RISCO; +import static siprp.higiene.gestao.riscos.GestaoRiscosLogic.ACTION_SELECT_TEMA; +import static siprp.higiene.gestao.riscos.GestaoRiscosLogic.ACTION_TEMA_CRIAR; +import static siprp.higiene.gestao.riscos.GestaoRiscosLogic.ACTION_TEMA_REMOVER; import info.clearthought.layout.TableLayout; import info.clearthought.layout.TableLayoutConstraints; diff --git a/trunk/SIPRPSoft/src/siprp/higiene/riscos/NodeMedida.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/NodeMedida.java similarity index 88% rename from trunk/SIPRPSoft/src/siprp/higiene/riscos/NodeMedida.java rename to trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/NodeMedida.java index 3ef81b3c..7f6ec982 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/riscos/NodeMedida.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/NodeMedida.java @@ -1,4 +1,4 @@ -package siprp.higiene.riscos; +package siprp.higiene.gestao.riscos; import javax.swing.tree.DefaultMutableTreeNode; diff --git a/trunk/SIPRPSoft/src/siprp/higiene/riscos/NodeRisco.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/NodeRisco.java similarity index 87% rename from trunk/SIPRPSoft/src/siprp/higiene/riscos/NodeRisco.java rename to trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/NodeRisco.java index 0298267a..21108438 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/riscos/NodeRisco.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/NodeRisco.java @@ -1,4 +1,4 @@ -package siprp.higiene.riscos; +package siprp.higiene.gestao.riscos; import javax.swing.tree.DefaultMutableTreeNode; diff --git a/trunk/SIPRPSoft/src/siprp/higiene/riscos/NodeRiscoTema.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/NodeRiscoTema.java similarity index 88% rename from trunk/SIPRPSoft/src/siprp/higiene/riscos/NodeRiscoTema.java rename to trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/NodeRiscoTema.java index fa21e461..99a589cf 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/riscos/NodeRiscoTema.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/NodeRiscoTema.java @@ -1,4 +1,4 @@ -package siprp.higiene.riscos; +package siprp.higiene.gestao.riscos; import javax.swing.tree.DefaultMutableTreeNode; diff --git a/trunk/SIPRPSoft/src/siprp/printer/Printer.java b/trunk/SIPRPSoft/src/siprp/printer/Printer.java index bf6a086c..788cd162 100644 --- a/trunk/SIPRPSoft/src/siprp/printer/Printer.java +++ b/trunk/SIPRPSoft/src/siprp/printer/Printer.java @@ -1,7 +1,6 @@ package siprp.printer; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; diff --git a/trunk/SIPRPSoft/src/siprp/update/UpdateList.java b/trunk/SIPRPSoft/src/siprp/update/UpdateList.java index baebef61..db7fbae1 100644 --- a/trunk/SIPRPSoft/src/siprp/update/UpdateList.java +++ b/trunk/SIPRPSoft/src/siprp/update/UpdateList.java @@ -37,7 +37,7 @@ public class UpdateList 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(), new siprp.update.updates.V9_4_To_V9_5(), new siprp.update.updates.V9_5_To_V9_6(), new siprp.update.updates.V9_6_To_V9_7(), - new siprp.update.updates.V9_7_To_V9_8() }; + new siprp.update.updates.V9_7_To_V9_8(), new siprp.update.updates.V9_8_To_V9_9() }; protected static Executer EXECUTER; protected static double version = -1; diff --git a/trunk/SIPRPSoft/src/siprp/update/updates/V9_8_To_V9_9.java b/trunk/SIPRPSoft/src/siprp/update/updates/V9_8_To_V9_9.java new file mode 100644 index 00000000..a0443d8e --- /dev/null +++ b/trunk/SIPRPSoft/src/siprp/update/updates/V9_8_To_V9_9.java @@ -0,0 +1,71 @@ +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_8_To_V9_9 + implements siprp.update.Update +{ + + public V9_8_To_V9_9() + { + } + + public String []listChanges() + { + return new String[]{ + "Criacao de tabelas para associacao de emails e riscos a empresas" + }; + } + + public double getStartVersion() + { + return 9.8; + } + + public double getEndVersion() + { + return 9.9; + } + + 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_posto_medida add column is_plano_actuacao char(1); " + + "create table hs_email( " + + " id serial PRIMARY KEY, " + + " email varchar(128) " + + "); " + + "create table hs_email_estabelecimento( " + + " email_id int4 REFERENCES hs_email(id), " + + " estabelecimento_id int4 REFERENCES estabelecimentos(id), " + + " constraint hs_email_estabelecimento_pkey PRIMARY KEY(email_id,estabelecimento_id) " + + "); " + + "create table hs_email_empresa( " + + " email_id int4 REFERENCES hs_email(id), " + + " empresa_id int4 REFERENCES empresas(id), " + + " constraint hs_email_empresa_pkey PRIMARY KEY(email_id,empresa_id) " + + "); " + + "create table hs_risco_empresa( " + + " risco_id int4 REFERENCES hs_risco(id), " + + " empresa_id int4 REFERENCES empresas(id), " + + " constraint hs_risco_empresa_pkey PRIMARY KEY(risco_id,empresa_id) " + + ");" + ); + executer.executeQuery( update ); + } + + public String toString() + { + return "v" + getStartVersion() + " para v" + getEndVersion(); + } +} diff --git a/trunk/common/src/SIPRPMap.map.xml b/trunk/common/src/SIPRPMap.map.xml index ecd07a30..d88e903f 100644 --- a/trunk/common/src/SIPRPMap.map.xml +++ b/trunk/common/src/SIPRPMap.map.xml @@ -191,6 +191,23 @@ 1 + + + + + ORACLE + hs_email_id_seq + 1 + + + + + + + + + + @@ -362,6 +379,10 @@ 1 + + + + @@ -859,6 +880,13 @@ + + + + + + + @@ -894,7 +922,7 @@ - + @@ -936,6 +964,8 @@ + + @@ -1169,6 +1199,12 @@ + + + + + + @@ -1196,6 +1232,9 @@ + + + @@ -1241,6 +1280,24 @@ + + + + + + + + + + + + + + + + + + @@ -1355,12 +1412,21 @@ + + + + + + + + + @@ -1648,6 +1714,8 @@ + + @@ -1657,6 +1725,7 @@ + @@ -1670,27 +1739,33 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1709,12 +1784,14 @@ - - - + + + + + - + diff --git a/trunk/common/src/leaf/ui/TreeTools.java b/trunk/common/src/leaf/ui/TreeTools.java new file mode 100644 index 00000000..48f8c33b --- /dev/null +++ b/trunk/common/src/leaf/ui/TreeTools.java @@ -0,0 +1,62 @@ +package leaf.ui; + +import javax.swing.JTree; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; + +public class TreeTools +{ + + + public static void refreshTree( JTree tree, DefaultMutableTreeNode node ) + { + ((DefaultTreeModel) tree.getModel()).nodeStructureChanged( node ); + for( int i = 0; i < tree.getRowCount(); ++i) + { + tree.expandPath( tree.getPathForRow( i ) ); + } + } + + + public static boolean userObjectExistsOn( Object object, DefaultMutableTreeNode on ) + { + boolean result = false; + if( object != null && on != null ) + { + result = object.equals( on.getUserObject() ); + for( int i = 0; i < on.getChildCount() && !result; ++i ) + { + result |= userObjectExistsOn( object, (DefaultMutableTreeNode) on.getChildAt( i ) ); + } + } + return result; + } + + + public static DefaultMutableTreeNode findNodeWithUserObject( Object object, DefaultMutableTreeNode on ) + { + DefaultMutableTreeNode result = null; + if( object != null && on != null ) + { + result = object.equals( on.getUserObject() ) ? on : null; + for( int i = 0; i < on.getChildCount() && result == null; ++i ) + { + result = object.equals(((DefaultMutableTreeNode) on.getChildAt( i )).getUserObject()) ? (DefaultMutableTreeNode) on.getChildAt( i ) : findNodeWithUserObject( object, (DefaultMutableTreeNode) on.getChildAt( i ) ); + } + } + return result; + } + + + public static DefaultMutableTreeNode cloneFullNode( DefaultMutableTreeNode node ) + { + DefaultMutableTreeNode result = (DefaultMutableTreeNode) node.clone(); + for( int i = 0; i < node.getChildCount(); ++i ) + { + DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt( i ); + result.add( cloneFullNode(child) ); + } + return result; + } + +} diff --git a/trunk/common/src/siprp/database/cayenne/objects/BaseObject.java b/trunk/common/src/siprp/database/cayenne/objects/BaseObject.java index 9981ed62..ee131223 100644 --- a/trunk/common/src/siprp/database/cayenne/objects/BaseObject.java +++ b/trunk/common/src/siprp/database/cayenne/objects/BaseObject.java @@ -45,7 +45,17 @@ public class BaseObject extends CayenneDataObject return getPersistenceState() == PersistenceState.MODIFIED; } - + public void save() + { + medicinaProvider.saveObject( this ); + medicinaProvider.commit(); + } + + public void delete() + { + medicinaProvider.deleteObject( this ); + medicinaProvider.commit(); + } protected String parseToUnicode( String string ) { diff --git a/trunk/common/src/siprp/database/cayenne/objects/HsEmail.java b/trunk/common/src/siprp/database/cayenne/objects/HsEmail.java new file mode 100644 index 00000000..3f98c75d --- /dev/null +++ b/trunk/common/src/siprp/database/cayenne/objects/HsEmail.java @@ -0,0 +1,7 @@ +package siprp.database.cayenne.objects; + +import siprp.database.cayenne.objects.auto._HsEmail; + +public class HsEmail extends _HsEmail { + +} diff --git a/trunk/common/src/siprp/database/cayenne/objects/HsEmailEmpresa.java b/trunk/common/src/siprp/database/cayenne/objects/HsEmailEmpresa.java new file mode 100644 index 00000000..f2bc61cf --- /dev/null +++ b/trunk/common/src/siprp/database/cayenne/objects/HsEmailEmpresa.java @@ -0,0 +1,7 @@ +package siprp.database.cayenne.objects; + +import siprp.database.cayenne.objects.auto._HsEmailEmpresa; + +public class HsEmailEmpresa extends _HsEmailEmpresa { + +} diff --git a/trunk/common/src/siprp/database/cayenne/objects/HsEmailEstabelecimento.java b/trunk/common/src/siprp/database/cayenne/objects/HsEmailEstabelecimento.java new file mode 100644 index 00000000..addeaca1 --- /dev/null +++ b/trunk/common/src/siprp/database/cayenne/objects/HsEmailEstabelecimento.java @@ -0,0 +1,7 @@ +package siprp.database.cayenne.objects; + +import siprp.database.cayenne.objects.auto._HsEmailEstabelecimento; + +public class HsEmailEstabelecimento extends _HsEmailEstabelecimento { + +} diff --git a/trunk/common/src/siprp/database/cayenne/objects/HsPostoRisco.java b/trunk/common/src/siprp/database/cayenne/objects/HsPostoRisco.java index aced397e..0a2c2cf3 100644 --- a/trunk/common/src/siprp/database/cayenne/objects/HsPostoRisco.java +++ b/trunk/common/src/siprp/database/cayenne/objects/HsPostoRisco.java @@ -4,4 +4,12 @@ import siprp.database.cayenne.objects.auto._HsPostoRisco; public class HsPostoRisco extends _HsPostoRisco { + private static final long serialVersionUID = 1L; + + @Override + public String toString() + { + return super.getToHsRisco().getDescription(); + } + } diff --git a/trunk/common/src/siprp/database/cayenne/objects/HsRiscoEmpresa.java b/trunk/common/src/siprp/database/cayenne/objects/HsRiscoEmpresa.java new file mode 100644 index 00000000..7d25801e --- /dev/null +++ b/trunk/common/src/siprp/database/cayenne/objects/HsRiscoEmpresa.java @@ -0,0 +1,15 @@ +package siprp.database.cayenne.objects; + +import siprp.database.cayenne.objects.auto._HsRiscoEmpresa; + +public class HsRiscoEmpresa extends _HsRiscoEmpresa { + + private static final long serialVersionUID = 1L; + + @Override + public String toString() + { + return super.getToHsRisco().getDescription(); + } + +} diff --git a/trunk/common/src/siprp/database/cayenne/objects/auto/_Empresas.java b/trunk/common/src/siprp/database/cayenne/objects/auto/_Empresas.java index e106f549..d2157aef 100644 --- a/trunk/common/src/siprp/database/cayenne/objects/auto/_Empresas.java +++ b/trunk/common/src/siprp/database/cayenne/objects/auto/_Empresas.java @@ -8,6 +8,8 @@ import siprp.database.cayenne.objects.BaseObject; import siprp.database.cayenne.objects.Contactos; import siprp.database.cayenne.objects.Estabelecimentos; import siprp.database.cayenne.objects.HsArea; +import siprp.database.cayenne.objects.HsEmailEmpresa; +import siprp.database.cayenne.objects.HsRiscoEmpresa; import siprp.database.cayenne.objects.Image; import siprp.database.cayenne.objects.Lembretes; import siprp.database.cayenne.objects.MarcacoesEmpresa; @@ -65,6 +67,8 @@ public abstract class _Empresas extends BaseObject { public static final String AVISOS_ARRAY_PROPERTY = "avisosArray"; public static final String ESTABELECIMENTOS_ARRAY_PROPERTY = "estabelecimentosArray"; public static final String HS_AREA_ARRAY_PROPERTY = "hsAreaArray"; + public static final String HS_EMAIL_EMPRESA_PROPERTY = "hsEmailEmpresa"; + public static final String HS_RISCO_EMPRESA_ARRAY_PROPERTY = "hsRiscoEmpresaArray"; public static final String LEMBRETES_ARRAY_PROPERTY = "lembretesArray"; public static final String MARCACOES_EMPRESA_ARRAY_PROPERTY = "marcacoesEmpresaArray"; public static final String PRT_ELEMENTOS_PROTOCOLO_ARRAY_PROPERTY = "prtElementosProtocoloArray"; @@ -397,6 +401,30 @@ public abstract class _Empresas extends BaseObject { } + public void addToHsEmailEmpresa(HsEmailEmpresa obj) { + addToManyTarget("hsEmailEmpresa", obj, true); + } + public void removeFromHsEmailEmpresa(HsEmailEmpresa obj) { + removeToManyTarget("hsEmailEmpresa", obj, true); + } + @SuppressWarnings("unchecked") + public List getHsEmailEmpresa() { + return (List)readProperty("hsEmailEmpresa"); + } + + + public void addToHsRiscoEmpresaArray(HsRiscoEmpresa obj) { + addToManyTarget("hsRiscoEmpresaArray", obj, true); + } + public void removeFromHsRiscoEmpresaArray(HsRiscoEmpresa obj) { + removeToManyTarget("hsRiscoEmpresaArray", obj, true); + } + @SuppressWarnings("unchecked") + public List getHsRiscoEmpresaArray() { + return (List)readProperty("hsRiscoEmpresaArray"); + } + + public void addToLembretesArray(Lembretes obj) { addToManyTarget("lembretesArray", obj, true); } diff --git a/trunk/common/src/siprp/database/cayenne/objects/auto/_Estabelecimentos.java b/trunk/common/src/siprp/database/cayenne/objects/auto/_Estabelecimentos.java index c35c0c0b..e6f2efd8 100644 --- a/trunk/common/src/siprp/database/cayenne/objects/auto/_Estabelecimentos.java +++ b/trunk/common/src/siprp/database/cayenne/objects/auto/_Estabelecimentos.java @@ -9,6 +9,7 @@ import siprp.database.cayenne.objects.Contactos; import siprp.database.cayenne.objects.EmailPlanoDeActuacao; import siprp.database.cayenne.objects.Empresas; import siprp.database.cayenne.objects.HistoricoEstabelecimento; +import siprp.database.cayenne.objects.HsEmailEstabelecimento; import siprp.database.cayenne.objects.HsPostoEstabelecimento; import siprp.database.cayenne.objects.Lembretes; import siprp.database.cayenne.objects.MarcacoesEstabelecimento; @@ -37,6 +38,7 @@ public abstract class _Estabelecimentos extends BaseObject { public static final String AVISOS_ARRAY_PROPERTY = "avisosArray"; public static final String EMAIL_PLANO_DE_ACTUACAO_ARRAY_PROPERTY = "emailPlanoDeActuacaoArray"; public static final String HISTORICO_ESTABELECIMENTO_ARRAY_PROPERTY = "historicoEstabelecimentoArray"; + public static final String HS_EMAIL_ESTABELECIMENTO_PROPERTY = "hsEmailEstabelecimento"; public static final String HS_POSTO_ESTABELECIMENTO_ARRAY_PROPERTY = "hsPostoEstabelecimentoArray"; public static final String LEMBRETES_ARRAY_PROPERTY = "lembretesArray"; public static final String MARCACOES_ESTABELECIMENTO_ARRAY_PROPERTY = "marcacoesEstabelecimentoArray"; @@ -155,6 +157,18 @@ public abstract class _Estabelecimentos extends BaseObject { } + public void addToHsEmailEstabelecimento(HsEmailEstabelecimento obj) { + addToManyTarget("hsEmailEstabelecimento", obj, true); + } + public void removeFromHsEmailEstabelecimento(HsEmailEstabelecimento obj) { + removeToManyTarget("hsEmailEstabelecimento", obj, true); + } + @SuppressWarnings("unchecked") + public List getHsEmailEstabelecimento() { + return (List)readProperty("hsEmailEstabelecimento"); + } + + public void addToHsPostoEstabelecimentoArray(HsPostoEstabelecimento obj) { addToManyTarget("hsPostoEstabelecimentoArray", obj, true); } diff --git a/trunk/common/src/siprp/database/cayenne/objects/auto/_HsEmail.java b/trunk/common/src/siprp/database/cayenne/objects/auto/_HsEmail.java new file mode 100644 index 00000000..58b132dc --- /dev/null +++ b/trunk/common/src/siprp/database/cayenne/objects/auto/_HsEmail.java @@ -0,0 +1,54 @@ +package siprp.database.cayenne.objects.auto; + +import java.util.List; + +import siprp.database.cayenne.objects.BaseObject; +import siprp.database.cayenne.objects.HsEmailEmpresa; +import siprp.database.cayenne.objects.HsEmailEstabelecimento; + +/** + * Class _HsEmail was generated by Cayenne. + * It is probably a good idea to avoid changing this class manually, + * since it may be overwritten next time code is regenerated. + * If you need to make any customizations, please use subclass. + */ +public abstract class _HsEmail extends BaseObject { + + public static final String EMAIL_PROPERTY = "email"; + public static final String HS_EMAIL_EMPRESA_ARRAY_PROPERTY = "hsEmailEmpresaArray"; + public static final String HS_EMAIL_ESTABELECIMENTO_ARRAY_PROPERTY = "hsEmailEstabelecimentoArray"; + + public static final String ID_PK_COLUMN = "id"; + + public void setEmail(String email) { + writeProperty("email", email); + } + public String getEmail() { + return (String)readProperty("email"); + } + + public void addToHsEmailEmpresaArray(HsEmailEmpresa obj) { + addToManyTarget("hsEmailEmpresaArray", obj, true); + } + public void removeFromHsEmailEmpresaArray(HsEmailEmpresa obj) { + removeToManyTarget("hsEmailEmpresaArray", obj, true); + } + @SuppressWarnings("unchecked") + public List getHsEmailEmpresaArray() { + return (List)readProperty("hsEmailEmpresaArray"); + } + + + public void addToHsEmailEstabelecimentoArray(HsEmailEstabelecimento obj) { + addToManyTarget("hsEmailEstabelecimentoArray", obj, true); + } + public void removeFromHsEmailEstabelecimentoArray(HsEmailEstabelecimento obj) { + removeToManyTarget("hsEmailEstabelecimentoArray", obj, true); + } + @SuppressWarnings("unchecked") + public List getHsEmailEstabelecimentoArray() { + return (List)readProperty("hsEmailEstabelecimentoArray"); + } + + +} diff --git a/trunk/common/src/siprp/database/cayenne/objects/auto/_HsEmailEmpresa.java b/trunk/common/src/siprp/database/cayenne/objects/auto/_HsEmailEmpresa.java new file mode 100644 index 00000000..c45d96e0 --- /dev/null +++ b/trunk/common/src/siprp/database/cayenne/objects/auto/_HsEmailEmpresa.java @@ -0,0 +1,39 @@ +package siprp.database.cayenne.objects.auto; + +import siprp.database.cayenne.objects.BaseObject; +import siprp.database.cayenne.objects.Empresas; +import siprp.database.cayenne.objects.HsEmail; + +/** + * Class _HsEmailEmpresa was generated by Cayenne. + * It is probably a good idea to avoid changing this class manually, + * since it may be overwritten next time code is regenerated. + * If you need to make any customizations, please use subclass. + */ +public abstract class _HsEmailEmpresa extends BaseObject { + + public static final String TO_EMPRESA_PROPERTY = "toEmpresa"; + public static final String TO_HS_EMAIL_PROPERTY = "toHsEmail"; + + public static final String EMAIL_ID_PK_COLUMN = "email_id"; + public static final String EMPRESA_ID_PK_COLUMN = "empresa_id"; + + public void setToEmpresa(Empresas toEmpresa) { + setToOneTarget("toEmpresa", toEmpresa, true); + } + + public Empresas getToEmpresa() { + return (Empresas)readProperty("toEmpresa"); + } + + + public void setToHsEmail(HsEmail toHsEmail) { + setToOneTarget("toHsEmail", toHsEmail, true); + } + + public HsEmail getToHsEmail() { + return (HsEmail)readProperty("toHsEmail"); + } + + +} diff --git a/trunk/common/src/siprp/database/cayenne/objects/auto/_HsEmailEstabelecimento.java b/trunk/common/src/siprp/database/cayenne/objects/auto/_HsEmailEstabelecimento.java new file mode 100644 index 00000000..bb6fd529 --- /dev/null +++ b/trunk/common/src/siprp/database/cayenne/objects/auto/_HsEmailEstabelecimento.java @@ -0,0 +1,39 @@ +package siprp.database.cayenne.objects.auto; + +import siprp.database.cayenne.objects.BaseObject; +import siprp.database.cayenne.objects.Estabelecimentos; +import siprp.database.cayenne.objects.HsEmail; + +/** + * Class _HsEmailEstabelecimento was generated by Cayenne. + * It is probably a good idea to avoid changing this class manually, + * since it may be overwritten next time code is regenerated. + * If you need to make any customizations, please use subclass. + */ +public abstract class _HsEmailEstabelecimento extends BaseObject { + + public static final String TO_ESTABELECIMENTO_PROPERTY = "toEstabelecimento"; + public static final String TO_HS_EMAIL_PROPERTY = "toHsEmail"; + + public static final String EMAIL_ID_PK_COLUMN = "email_id"; + public static final String ESTABELECIMENTO_ID_PK_COLUMN = "estabelecimento_id"; + + public void setToEstabelecimento(Estabelecimentos toEstabelecimento) { + setToOneTarget("toEstabelecimento", toEstabelecimento, true); + } + + public Estabelecimentos getToEstabelecimento() { + return (Estabelecimentos)readProperty("toEstabelecimento"); + } + + + public void setToHsEmail(HsEmail toHsEmail) { + setToOneTarget("toHsEmail", toHsEmail, true); + } + + public HsEmail getToHsEmail() { + return (HsEmail)readProperty("toHsEmail"); + } + + +} diff --git a/trunk/common/src/siprp/database/cayenne/objects/auto/_HsPostoRisco.java b/trunk/common/src/siprp/database/cayenne/objects/auto/_HsPostoRisco.java index 4d23e438..1bfe584c 100644 --- a/trunk/common/src/siprp/database/cayenne/objects/auto/_HsPostoRisco.java +++ b/trunk/common/src/siprp/database/cayenne/objects/auto/_HsPostoRisco.java @@ -1,7 +1,6 @@ package siprp.database.cayenne.objects.auto; -import org.apache.cayenne.CayenneDataObject; - +import siprp.database.cayenne.objects.BaseObject; import siprp.database.cayenne.objects.HsPosto; import siprp.database.cayenne.objects.HsRelatorioRiscoValorQualitativo; import siprp.database.cayenne.objects.HsRisco; @@ -12,7 +11,7 @@ import siprp.database.cayenne.objects.HsRisco; * since it may be overwritten next time code is regenerated. * If you need to make any customizations, please use subclass. */ -public abstract class _HsPostoRisco extends CayenneDataObject { +public abstract class _HsPostoRisco extends BaseObject { public static final String IS_PLANO_ACTUACAO_PROPERTY = "isPlanoActuacao"; public static final String PROBABILIDADE_PROPERTY = "probabilidade"; diff --git a/trunk/common/src/siprp/database/cayenne/objects/auto/_HsRiscoEmpresa.java b/trunk/common/src/siprp/database/cayenne/objects/auto/_HsRiscoEmpresa.java new file mode 100644 index 00000000..f62cd7c8 --- /dev/null +++ b/trunk/common/src/siprp/database/cayenne/objects/auto/_HsRiscoEmpresa.java @@ -0,0 +1,39 @@ +package siprp.database.cayenne.objects.auto; + +import siprp.database.cayenne.objects.BaseObject; +import siprp.database.cayenne.objects.Empresas; +import siprp.database.cayenne.objects.HsRisco; + +/** + * Class _HsRiscoEmpresa was generated by Cayenne. + * It is probably a good idea to avoid changing this class manually, + * since it may be overwritten next time code is regenerated. + * If you need to make any customizations, please use subclass. + */ +public abstract class _HsRiscoEmpresa extends BaseObject { + + public static final String TO_EMPRESA_PROPERTY = "toEmpresa"; + public static final String TO_HS_RISCO_PROPERTY = "toHsRisco"; + + public static final String EMPRESA_ID_PK_COLUMN = "empresa_id"; + public static final String RISCO_ID_PK_COLUMN = "risco_id"; + + public void setToEmpresa(Empresas toEmpresa) { + setToOneTarget("toEmpresa", toEmpresa, true); + } + + public Empresas getToEmpresa() { + return (Empresas)readProperty("toEmpresa"); + } + + + public void setToHsRisco(HsRisco toHsRisco) { + setToOneTarget("toHsRisco", toHsRisco, true); + } + + public HsRisco getToHsRisco() { + return (HsRisco)readProperty("toHsRisco"); + } + + +}