diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/GerirEmpresaPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/GerirEmpresaPanel.java index 1f1cb27f..71202cb3 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/gestao/GerirEmpresaPanel.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/GerirEmpresaPanel.java @@ -9,6 +9,7 @@ import javax.swing.BorderFactory; import javax.swing.JPanel; import siprp.database.cayenne.objects.Empresas; +import siprp.higiene.gestao.legislacao.AdicionarLegislacaoPanel; import siprp.higiene.gestao.postos.GerirAreasPanel; import siprp.higiene.gestao.riscos.AdicionarRiscosPanel; diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/GerirEstabelecimentosPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/GerirEstabelecimentosPanel.java index fa9f18ba..ae4d7e70 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/gestao/GerirEstabelecimentosPanel.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/GerirEstabelecimentosPanel.java @@ -18,6 +18,7 @@ import javax.swing.JPanel; 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.postos.AdicionarAreasPanel; import siprp.higiene.gestao.riscos.AdicionarRiscosPanel; diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/GlobalPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/GlobalPanel.java index 19efb880..077fc8aa 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/gestao/GlobalPanel.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/GlobalPanel.java @@ -2,14 +2,19 @@ package siprp.higiene.gestao; import javax.swing.JTabbedPane; +import siprp.higiene.gestao.legislacao.GerirLegislacaoPanel; import siprp.higiene.gestao.riscos.GerirRiscosPanel; +import static com.evolute.utils.strings.UnicodeLatin1Map.*; + public class GlobalPanel extends JTabbedPane { private static final long serialVersionUID = 1L; private final GerirRiscosPanel panelRiscos = new GerirRiscosPanel(); + + private final GerirLegislacaoPanel panelLegislacao = new GerirLegislacaoPanel(); public GlobalPanel() { @@ -22,6 +27,7 @@ public class GlobalPanel extends JTabbedPane private void startupComponents() { addTab( "Riscos", panelRiscos ); + addTab( "Legisla" + ccedil + atilde + "o", panelLegislacao ); } private void setupLayout() diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/AdicionarLegislacaoPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/legislacao/AdicionarLegislacaoPanel.java similarity index 98% rename from trunk/SIPRPSoft/src/siprp/higiene/gestao/AdicionarLegislacaoPanel.java rename to trunk/SIPRPSoft/src/siprp/higiene/gestao/legislacao/AdicionarLegislacaoPanel.java index 5db7bd97..7ff88667 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/gestao/AdicionarLegislacaoPanel.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/legislacao/AdicionarLegislacaoPanel.java @@ -1,4 +1,4 @@ -package siprp.higiene.gestao; +package siprp.higiene.gestao.legislacao; import info.clearthought.layout.TableLayout; import info.clearthought.layout.TableLayoutConstraints; diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/legislacao/GerirLegislacaoPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/legislacao/GerirLegislacaoPanel.java new file mode 100644 index 00000000..69375652 --- /dev/null +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/legislacao/GerirLegislacaoPanel.java @@ -0,0 +1,442 @@ +package siprp.higiene.gestao.legislacao; + +import static com.evolute.utils.strings.UnicodeLatin1Map.atilde; +import static com.evolute.utils.strings.UnicodeLatin1Map.ccedil; +import static com.evolute.utils.strings.UnicodeLatin1Map.iacute; +import info.clearthought.layout.TableLayout; +import info.clearthought.layout.TableLayoutConstraints; + +import java.awt.GridLayout; +import java.awt.LayoutManager; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +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.TreePath; +import javax.swing.tree.TreeSelectionModel; + +import leaf.data.Validator; +import leaf.ui.LeafButton; +import leaf.ui.LeafTextAreaEditor; +import leaf.ui.TreeTools; +import siprp.database.cayenne.objects.HsLegislacao; +import siprp.database.cayenne.objects.HsLegislacaoCategoria; +import siprp.logic.HigieneSegurancaLogic; + +public class GerirLegislacaoPanel extends JPanel +{ + + private static final long serialVersionUID = 1L; + + private final JPanel panelGeral = new JPanel(); + + private final JPanel panelCategorias = new JPanel(); + + private final JPanel panelButtonsGeral = new JPanel(); + + private final LeafButton buttonGeralCriar = new LeafButton( "Criar" ); + + private final LeafButton buttonGeralRemover = new LeafButton( "Remover" ); + + private final JPanel panelButtonsCategoriasCategoria = new JPanel(); + + private final LeafButton buttonCategoriaCriar = new LeafButton( "Criar" ); + + private final LeafButton buttonCategoriaEditar = new LeafButton( "Editar" ); + + private final LeafButton buttonCategoriaRemover = new LeafButton( "Remover" ); + + private final JPanel panelButtonsCategoriasLegislacao = new JPanel(); + + private final LeafButton buttonCategoriasLegislacaoCriar = new LeafButton( "Criar" ); + + private final LeafButton buttonCategoriasLegislacaoRemover = new LeafButton( "Remover" ); + + private final DefaultMutableTreeNode rootGeral = new DefaultMutableTreeNode(); + + private final DefaultTreeModel modelGeral = new DefaultTreeModel( rootGeral ); + + private final JTree treeGeral = new JTree( modelGeral ); + + private final JScrollPane scrollGeral = new JScrollPane( treeGeral ); + + private final DefaultMutableTreeNode rootCategorias = new DefaultMutableTreeNode(); + + private final DefaultTreeModel modelCategorias = new DefaultTreeModel( rootCategorias ); + + private final JTree treeCategorias = new JTree(modelCategorias); + + private final JScrollPane scrollCategorias = new JScrollPane( treeCategorias ); + + private HsLegislacao selectedLegislacaoGeral = null; + + private HsLegislacao selectedLegislacaoEspecifica = null; + + private HsLegislacaoCategoria selectedCategoria = null; + + private final LeafTextAreaEditor panelData = new LeafTextAreaEditor( new Validator() + { + @Override + public boolean isValid( String object ) + { + return true; + } + } ); + + public GerirLegislacaoPanel() + { + startupComponents(); + startupLayout(); + placeComponents(); + setupListeners(); + reload(); + } + + private void startupComponents() + { + panelGeral.setBorder( BorderFactory.createTitledBorder( "Legisla" + ccedil + atilde + "o de aplica" + ccedil + atilde + "o geral" ) ); + panelButtonsGeral.setBorder( BorderFactory.createTitledBorder( "Legisla" + ccedil + atilde + "o" ) ); + + panelCategorias.setBorder( BorderFactory.createTitledBorder( "Legisla" + ccedil + atilde + "o espec" + iacute + "fica" ) ); + panelButtonsCategoriasCategoria.setBorder( BorderFactory.createTitledBorder( "Categoria" ) ); + panelButtonsCategoriasLegislacao.setBorder( BorderFactory.createTitledBorder( "Legisla" + ccedil + atilde + "o" ) ); + + treeCategorias.setRootVisible( false ); + treeGeral.setRootVisible( false ); + treeCategorias.getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION ); + treeGeral.getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION ); + } + + private void startupLayout() + { + LayoutManager layout = new TableLayout( new double[] { + TableLayout.FILL, TableLayout.FILL + }, new double[] { + TableLayout.FILL, TableLayout.FILL + } ); + this.setLayout( layout ); + + layout = new TableLayout( new double[] { + TableLayout.MINIMUM, TableLayout.FILL + }, new double[] { + TableLayout.MINIMUM, TableLayout.FILL + } ); + panelGeral.setLayout( layout ); + + layout = new TableLayout( new double[] { + TableLayout.MINIMUM, TableLayout.FILL + }, new double[] { + TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL + } ); + panelCategorias.setLayout( layout ); + + layout = new GridLayout( 2, 1, 5, 5 ); + panelButtonsGeral.setLayout( layout ); + + layout = new GridLayout( 3, 1, 5, 5 ); + panelButtonsCategoriasCategoria.setLayout( layout ); + + layout = new GridLayout( 2, 1, 5, 5 ); + panelButtonsCategoriasLegislacao.setLayout( layout ); + } + + private void placeComponents() + { + + panelButtonsGeral.add( buttonGeralCriar ); + panelButtonsGeral.add( buttonGeralRemover ); + + panelButtonsCategoriasCategoria.add( buttonCategoriaCriar ); + panelButtonsCategoriasCategoria.add( buttonCategoriaEditar ); + panelButtonsCategoriasCategoria.add( buttonCategoriaRemover ); + + panelButtonsCategoriasLegislacao.add( buttonCategoriasLegislacaoCriar ); + panelButtonsCategoriasLegislacao.add( buttonCategoriasLegislacaoRemover ); + + panelGeral.add( panelButtonsGeral, new TableLayoutConstraints( 0, 0 ) ); + panelGeral.add( scrollGeral, new TableLayoutConstraints( 1, 0, 1, 1 ) ); + + panelCategorias.add( panelButtonsCategoriasCategoria, new TableLayoutConstraints( 0, 0 ) ); + panelCategorias.add( panelButtonsCategoriasLegislacao, new TableLayoutConstraints( 0, 1 ) ); + panelCategorias.add( scrollCategorias, new TableLayoutConstraints( 1, 0, 1, 2 ) ); + + this.add( panelGeral, new TableLayoutConstraints( 0, 0 ) ); + this.add( panelCategorias, new TableLayoutConstraints( 0, 1 ) ); + this.add( panelData, new TableLayoutConstraints( 1, 0, 1, 1 ) ); + } + + private void setupListeners() + { + treeCategorias.getSelectionModel().addTreeSelectionListener( new TreeSelectionListener() + { + @Override + public void valueChanged( TreeSelectionEvent e ) + { + TreePath selectionPath = e.getNewLeadSelectionPath(); + if( selectionPath != null ) + { + Object last = selectionPath.getLastPathComponent(); + if( last instanceof DefaultMutableTreeNode ) + { + Object userObject = ((DefaultMutableTreeNode)last).getUserObject(); + if( userObject instanceof HsLegislacao ) + { + selectedLegislacaoEspecifica = (HsLegislacao) userObject; + } + else if( userObject instanceof HsLegislacaoCategoria ) + { + selectedCategoria = (HsLegislacaoCategoria) userObject; + } + } + treeGeral.clearSelection(); + selectedLegislacaoGeral = null; + } + else + { + selectedLegislacaoEspecifica = null; + selectedCategoria = null; + } + refreshData(); + setEnable(); + } + } ); + treeGeral.getSelectionModel().addTreeSelectionListener( new TreeSelectionListener() + { + @Override + public void valueChanged( TreeSelectionEvent e ) + { + TreePath selectionPath = e.getNewLeadSelectionPath(); + if( selectionPath != null ) + { + Object last = selectionPath.getLastPathComponent(); + if( last instanceof DefaultMutableTreeNode ) + { + Object userObject = ((DefaultMutableTreeNode)last).getUserObject(); + if( userObject instanceof HsLegislacao ) + { + selectedLegislacaoGeral = (HsLegislacao) userObject; + } + } + treeCategorias.clearSelection(); + selectedLegislacaoEspecifica = null; + selectedCategoria = null; + } + else + { + selectedLegislacaoGeral = null; + } + refreshData(); + setEnable(); + } + } ); + panelData.addPropertyChangeListener( LeafTextAreaEditor.ACTION_SAVE, new PropertyChangeListener() + { + @Override + public void propertyChange( PropertyChangeEvent evt ) + { + String newValue = (String) evt.getNewValue(); + if( selectedLegislacaoEspecifica != null ) + { + selectedLegislacaoEspecifica.setDescription( newValue ); + selectedLegislacaoEspecifica.save(); + } + else if( selectedLegislacaoGeral != null ) + { + selectedLegislacaoGeral.setDescription( newValue ); + selectedLegislacaoGeral.save(); + } + reload(); + } + } ); + buttonCategoriaCriar.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + criarCategoria(); + } + } ); + buttonCategoriaEditar.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + editarCategoria(); + } + } ); + buttonCategoriaRemover.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + removerCategoria(); + } + } ); + buttonCategoriasLegislacaoCriar.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + criarCategoriaLegislacao(); + } + } ); + buttonCategoriasLegislacaoRemover.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + removerCategoriaLegislacao(); + } + } ); + buttonGeralCriar.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + criarGeral(); + } + } ); + buttonGeralRemover.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + removerGeral(); + } + } ); + } + + private void criarCategoria() + { + String categoriaString = JOptionPane.showInputDialog( this, "Nova categoria", "" ); + if( categoriaString != null ) + { + HsLegislacaoCategoria novaCategoria = new HsLegislacaoCategoria(); + novaCategoria.setDescription( categoriaString ); + novaCategoria.save(); + reload(); + } + } + + private void editarCategoria() + { + if( selectedCategoria != null ) + { + String categoriaString = JOptionPane.showInputDialog( this, "Nova categoria", selectedCategoria.getDescription() ); + if( categoriaString != null ) + { + selectedCategoria.setDescription( categoriaString ); + selectedCategoria.save(); + reload(); + } + } + } + + private void removerCategoria() + { + if( selectedCategoria != null ) + { + selectedCategoria.setDeletedDate( new Date() ); + } + } + + private void criarCategoriaLegislacao() + { + if( selectedCategoria != null ) + { + HsLegislacao novaLegislacao = new HsLegislacao(); + novaLegislacao.setDescription( "" ); + novaLegislacao.setToHsLegislacaoCategoria( selectedCategoria ); + novaLegislacao.save(); + reload(); + } + } + + private void removerCategoriaLegislacao() + { + if( selectedLegislacaoEspecifica != null ) + { + selectedLegislacaoEspecifica.setDeletedDate( new Date() ); + selectedLegislacaoEspecifica.save(); + reload(); + } + } + + private void removerGeral() + { + if( selectedLegislacaoGeral != null ) + { + selectedLegislacaoGeral.setDeletedDate( new Date() ); + selectedLegislacaoGeral.save(); + reload(); + } + } + + private void criarGeral() + { + HsLegislacao legislacao = new HsLegislacao(); + legislacao.setDescription( "" ); + legislacao.save(); + reload(); + } + + private void reload() + { + rootGeral.removeAllChildren(); + rootCategorias.removeAllChildren(); + TreeTools.merge( rootGeral, HigieneSegurancaLogic.getLegislacaoGeral() ); + TreeTools.merge( rootCategorias, HigieneSegurancaLogic.getLegislacaoEspecifica() ); + TreeTools.refreshTree( treeGeral, rootGeral ); + TreeTools.refreshTree( treeCategorias, rootCategorias ); + } + + private void refreshData() + { + buttonCategoriaEditar.setEnabled( false ); + buttonCategoriaRemover.setEnabled( false ); + buttonCategoriasLegislacaoCriar.setEnabled( false ); + buttonCategoriasLegislacaoRemover.setEnabled( false ); + buttonGeralRemover.setEnabled( false ); + panelData.setEnabled( false ); + if( selectedLegislacaoEspecifica != null ) + { + panelData.setValue( selectedLegislacaoEspecifica.getDescription() ); + panelData.setEnabled( true ); + } + else if( selectedLegislacaoGeral != null ) + { + panelData.setValue( selectedLegislacaoGeral.getDescription() ); + panelData.setEnabled( true ); + } + else + { + panelData.setValue( null ); + } + if( selectedCategoria != null ) + { + buttonCategoriaEditar.setEnabled( true ); + buttonCategoriaRemover.setEnabled( true ); + } + } + + private void setEnable() + { + buttonCategoriaEditar.setEnabled( selectedCategoria != null ); + buttonCategoriaRemover.setEnabled( selectedCategoria != null ); + buttonCategoriasLegislacaoCriar.setEnabled( selectedCategoria != null ); + buttonCategoriasLegislacaoRemover.setEnabled( selectedLegislacaoEspecifica != null ); + buttonGeralRemover.setEnabled( selectedLegislacaoGeral != null ); + } + +} diff --git a/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/GerirRiscosPanel.java b/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/GerirRiscosPanel.java index 9f966042..444b5123 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/GerirRiscosPanel.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/gestao/riscos/GerirRiscosPanel.java @@ -58,10 +58,14 @@ public class GerirRiscosPanel extends JPanel private final LeafButton buttonTemaCriar = new LeafButton( "Criar" ); + private final LeafButton buttonTemaEditar = new LeafButton( "Editar" ); + private final LeafButton buttonTemaRemover = new LeafButton( "Remover" ); private final LeafButton buttonRiscoCriar = new LeafButton( "Criar" ); + private final LeafButton buttonRiscoEditar = new LeafButton( "Editar" ); + private final LeafButton buttonRiscoRemover = new LeafButton( "Remover" ); private final LeafButton buttonMedidaCriar = new LeafButton( "Criar" ); @@ -97,6 +101,14 @@ public class GerirRiscosPanel extends JPanel criarTema(); } } ); + buttonTemaEditar.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + editarTema(); + } + } ); buttonTemaRemover.addActionListener( new ActionListener() { @Override @@ -113,6 +125,14 @@ public class GerirRiscosPanel extends JPanel criarRisco(); } } ); + buttonRiscoEditar.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + editarRisco(); + } + } ); buttonRiscoRemover.addActionListener( new ActionListener() { @Override @@ -170,6 +190,21 @@ public class GerirRiscosPanel extends JPanel } } + private void editarTema() + { + HsRiscoTema tema = getSelectedTema(); + if( tema != null ) + { + String temaString = JOptionPane.showInputDialog( this, "Editar tema", tema.getDescription() ); + if( temaString != null ) + { + tema.setDescription( temaString ); + tema.save(); + refresh(); + } + } + } + private void removerTema() { HsRiscoTema tema = getSelectedTema(); @@ -213,6 +248,21 @@ public class GerirRiscosPanel extends JPanel } } + private void editarRisco() + { + HsRisco risco = getSelectedRisco(); + if( risco != null ) + { + String riscoString = JOptionPane.showInputDialog( this, "Editar risco", risco.getDescription() ); + if( riscoString != null ) + { + risco.setDescription( riscoString ); + risco.save(); + refresh(); + } + } + } + private void removerRisco() { HsRisco risco = getSelectedRisco(); @@ -303,6 +353,10 @@ public class GerirRiscosPanel extends JPanel HsRiscoMedida medida = getSelectedMedida(); buttonMedidaCriar.setEnabled( risco != null || medida != null ); buttonRiscoCriar.setEnabled( tema != null || risco != null || medida != null ); + + buttonTemaEditar.setEnabled( tema != null ); + buttonRiscoEditar.setEnabled( risco != null ); + buttonMedidaRemover.setEnabled( medida != null ); buttonRiscoRemover.setEnabled( risco != null ); buttonTemaRemover.setEnabled( tema != null ); @@ -357,14 +411,16 @@ public class GerirRiscosPanel extends JPanel { JPanel panel = new JPanel(); panel.setBorder( BorderFactory.createTitledBorder( "Tema" ) ); - panel.setLayout( new GridLayout( 2, 1 ) ); + panel.setLayout( new GridLayout( 3, 1 ) ); panel.add( buttonTemaCriar ); + panel.add( buttonTemaEditar ); panel.add( buttonTemaRemover ); panelButtons.add( panel, new TableLayoutConstraints( 0, 0 ) ); panel = new JPanel(); panel.setBorder( BorderFactory.createTitledBorder( "Risco" ) ); - panel.setLayout( new GridLayout( 2, 1 ) ); + panel.setLayout( new GridLayout( 3, 1 ) ); panel.add( buttonRiscoCriar ); + panel.add( buttonRiscoEditar ); panel.add( buttonRiscoRemover ); panelButtons.add( panel, new TableLayoutConstraints( 0, 1 ) ); panel = new JPanel(); diff --git a/trunk/common/src/leaf/data/Validator.java b/trunk/common/src/leaf/data/Validator.java new file mode 100644 index 00000000..158e062a --- /dev/null +++ b/trunk/common/src/leaf/data/Validator.java @@ -0,0 +1,13 @@ +package leaf.data; + +public interface Validator +{ + + /** + * Tests if given object is valid + * @param object + * @return + */ + public boolean isValid(OBJECT_CLASS object); + +} diff --git a/trunk/common/src/leaf/ui/LeafTextAreaEditor.java b/trunk/common/src/leaf/ui/LeafTextAreaEditor.java new file mode 100644 index 00000000..9803227b --- /dev/null +++ b/trunk/common/src/leaf/ui/LeafTextAreaEditor.java @@ -0,0 +1,143 @@ +package leaf.ui; + +import info.clearthought.layout.TableLayout; +import info.clearthought.layout.TableLayoutConstraints; + +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.event.CaretEvent; +import javax.swing.event.CaretListener; + +import leaf.data.Validator; + +public class LeafTextAreaEditor extends JPanel +{ + + public static final String ACTION_SAVE = "ACTION_SAVE"; + + public static final String ACTION_REVERT = "ACTION_REVERT"; + + private static final long serialVersionUID = 1L; + + private static final String ICON_NAME_SAVE = "leaf/ui/icons/save.png"; + + private static final String ICON_NAME_REVERT = "leaf/ui/icons/revert.png"; + + private final LeafButton buttonSave = LeafIconButton.createButton( ICON_NAME_SAVE ); + + private final LeafButton buttonRevert = LeafIconButton.createButton( ICON_NAME_REVERT ); + + private final JTextArea fieldText = new JTextArea(); + + private final JScrollPane scroll = new JScrollPane(fieldText); + + private final Validator validator; + + private String initialValue = ""; + + public LeafTextAreaEditor( Validator validator ) + { + + this.validator = validator; + startupComponents(); + startupLayout(); + placeComponents(); + setupListeners(); + enableButtons( false ); + } + + public void setValue( String value ) + { + this.initialValue = value == null ? "" : value; + fieldText.setText( initialValue ); + } + + private void startupComponents() + { + fieldText.setWrapStyleWord( true ); + fieldText.setLineWrap( true ); + scroll.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); + scroll.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS ); + buttonSave.setMargin( new Insets(0,0,0,0) ); + buttonRevert.setMargin( new Insets(0,0,0,0) ); + } + + private void startupLayout() + { + TableLayout layout = new TableLayout( + new double[]{ TableLayout.FILL, TableLayout.MINIMUM, TableLayout.MINIMUM }, + new double[]{ TableLayout.MINIMUM, TableLayout.FILL } ); + this.setLayout( layout ); + } + + private void placeComponents() + { + this.add( scroll, new TableLayoutConstraints( 0, 1, 2, 1) ); + this.add( buttonSave, new TableLayoutConstraints( 1, 0 ) ); + this.add( buttonRevert, new TableLayoutConstraints( 2, 0 ) ); + } + + private void setupListeners() + { + buttonSave.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + save(); + } + } ); + buttonRevert.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + revert(); + } + } ); + fieldText.addCaretListener( new CaretListener() + { + @Override + public void caretUpdate( CaretEvent e ) + { + enableButtons( !initialValue.equals( fieldText.getText() ) && ( validator == null || validator.isValid( fieldText.getText() ) ) ); + } + } ); + } + + private void enableButtons( boolean enable ) + { + buttonRevert.setEnabled( enable ); + buttonSave.setEnabled( enable ); + } + + private void save() + { + enableButtons( false ); + firePropertyChange( ACTION_SAVE, initialValue, fieldText.getText() ); + initialValue = fieldText.getText(); + } + + private void revert() + { + fieldText.setText( initialValue ); + enableButtons( false ); + firePropertyChange( ACTION_REVERT, fieldText.getText(), initialValue ); + } + + @Override + public void setEnabled( boolean enabled ) + { + fieldText.setEnabled( enabled ); + if( enabled ) + { + fieldText.requestFocusInWindow(); + } + } + +} diff --git a/trunk/common/src/leaf/ui/icons/revert.png b/trunk/common/src/leaf/ui/icons/revert.png new file mode 100644 index 00000000..bd1d011a Binary files /dev/null and b/trunk/common/src/leaf/ui/icons/revert.png differ diff --git a/trunk/common/src/leaf/ui/icons/save.png b/trunk/common/src/leaf/ui/icons/save.png new file mode 100644 index 00000000..d2d0d6e1 Binary files /dev/null and b/trunk/common/src/leaf/ui/icons/save.png differ diff --git a/trunk/common/src/siprp/database/cayenne/objects/HsLegislacao.java b/trunk/common/src/siprp/database/cayenne/objects/HsLegislacao.java index 2ef7d752..75bfae4f 100644 --- a/trunk/common/src/siprp/database/cayenne/objects/HsLegislacao.java +++ b/trunk/common/src/siprp/database/cayenne/objects/HsLegislacao.java @@ -4,4 +4,24 @@ import siprp.database.cayenne.objects.auto._HsLegislacao; public class HsLegislacao extends _HsLegislacao { + private static final long serialVersionUID = 1L; + + @Override + public String getDescription() + { + return parseFromUnicode( super.getDescription() ); + } + + @Override + public void setDescription( String nome ) + { + super.setDescription( parseToUnicode( nome ) ); + } + + @Override + public String toString() + { + return getDescription(); + } + } diff --git a/trunk/common/src/siprp/database/cayenne/objects/HsLegislacaoCategoria.java b/trunk/common/src/siprp/database/cayenne/objects/HsLegislacaoCategoria.java index 6f0a9b6c..dcfbc2b3 100644 --- a/trunk/common/src/siprp/database/cayenne/objects/HsLegislacaoCategoria.java +++ b/trunk/common/src/siprp/database/cayenne/objects/HsLegislacaoCategoria.java @@ -4,4 +4,23 @@ import siprp.database.cayenne.objects.auto._HsLegislacaoCategoria; public class HsLegislacaoCategoria extends _HsLegislacaoCategoria { + private static final long serialVersionUID = 1L; + + @Override + public String getDescription() + { + return parseFromUnicode( super.getDescription() ); + } + + @Override + public void setDescription( String nome ) + { + super.setDescription( parseToUnicode( nome ) ); + } + + @Override + public String toString() + { + return getDescription(); + } } diff --git a/trunk/common/src/siprp/database/cayenne/providers/PlanoActuacaoDAO.java b/trunk/common/src/siprp/database/cayenne/providers/PlanoActuacaoDAO.java index 62f4cd93..882eaea4 100644 --- a/trunk/common/src/siprp/database/cayenne/providers/PlanoActuacaoDAO.java +++ b/trunk/common/src/siprp/database/cayenne/providers/PlanoActuacaoDAO.java @@ -10,6 +10,8 @@ import org.apache.cayenne.query.SelectQuery; import siprp.database.cayenne.objects.EmailPlanoDeActuacao; import siprp.database.cayenne.objects.Estabelecimentos; +import siprp.database.cayenne.objects.HsLegislacao; +import siprp.database.cayenne.objects.HsLegislacaoCategoria; import siprp.database.cayenne.objects.HsPosto; import siprp.database.cayenne.objects.HsPostoRisco; import siprp.database.cayenne.objects.HsRelatorio; @@ -306,4 +308,19 @@ public class PlanoActuacaoDAO extends MainDAO // return context.performQuery( query ); // } + public List getAllLegislacaoGeral() + { + SelectQuery query = new SelectQuery( HsLegislacao.class ); + query.andQualifier( ExpressionFactory.matchExp( HsLegislacao.DELETED_DATE_PROPERTY, null ) ); + query.andQualifier( ExpressionFactory.matchExp( HsLegislacao.TO_HS_LEGISLACAO_CATEGORIA_PROPERTY, null ) ); + return context.performQuery( query ); + } + + public List getAllLegislacaoCategorias() + { + SelectQuery query = new SelectQuery( HsLegislacaoCategoria.class ); + query.andQualifier( ExpressionFactory.matchExp( HsLegislacaoCategoria.DELETED_DATE_PROPERTY, null ) ); + return context.performQuery( query ); + } + } diff --git a/trunk/common/src/siprp/logic/HigieneSegurancaLogic.java b/trunk/common/src/siprp/logic/HigieneSegurancaLogic.java index bdd21c1f..2fd66eee 100644 --- a/trunk/common/src/siprp/logic/HigieneSegurancaLogic.java +++ b/trunk/common/src/siprp/logic/HigieneSegurancaLogic.java @@ -9,6 +9,8 @@ import leaf.ui.TreeTools; import siprp.database.cayenne.objects.Empresas; import siprp.database.cayenne.objects.Estabelecimentos; import siprp.database.cayenne.objects.HsArea; +import siprp.database.cayenne.objects.HsLegislacao; +import siprp.database.cayenne.objects.HsLegislacaoCategoria; import siprp.database.cayenne.objects.HsPosto; import siprp.database.cayenne.objects.HsPostoEstabelecimento; import siprp.database.cayenne.objects.HsPostoRisco; @@ -38,6 +40,7 @@ public class HigieneSegurancaLogic { private static final PlanoActuacaoDAO planoProvider = new PlanoActuacaoDAO(); + private static final MedicinaDAO medicinaProvider = new MedicinaDAO(); public static DefaultMutableTreeNode getRiscosTree() @@ -252,5 +255,32 @@ public class HigieneSegurancaLogic } return hasQual || hasQuant; } + + public static DefaultMutableTreeNode getLegislacaoGeral() + { + DefaultMutableTreeNode result = new DefaultMutableTreeNode(); + for( HsLegislacao legislacao : planoProvider.getAllLegislacaoGeral() ) + { + DefaultMutableTreeNode legislacaoNode = new DefaultMutableTreeNode( legislacao ); + result.add( legislacaoNode ); + } + return result; + } + + public static DefaultMutableTreeNode getLegislacaoEspecifica() + { + DefaultMutableTreeNode result = new DefaultMutableTreeNode(); + for( HsLegislacaoCategoria categoria : planoProvider.getAllLegislacaoCategorias() ) + { + DefaultMutableTreeNode categoriaNode = new DefaultMutableTreeNode( categoria ); + for( HsLegislacao legislacao: categoria.getHsLegislacaoArray() ) + { + DefaultMutableTreeNode legislacaoNode = new DefaultMutableTreeNode( legislacao ); + categoriaNode.add( legislacaoNode ); + } + result.add( categoriaNode ); + } + return result; + } }