forked from Coded/SIPRP
git-svn-id: https://svn.coded.pt/svn/SIPRP@809 bb69d46d-e84e-40c8-a05a-06db0d633741
parent
dd5412e5e4
commit
08b9f2c410
@ -0,0 +1,126 @@
|
|||||||
|
package siprp.higiene.relatorio;
|
||||||
|
|
||||||
|
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.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.HsRelatorio;
|
||||||
|
import siprp.database.cayenne.objects.HsRelatorioPosto;
|
||||||
|
import siprp.logic.HigieneSegurancaLogic;
|
||||||
|
|
||||||
|
public class AdicionarAreasRelatorioPanel extends JPanel
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public static final String SELECTION_CHANGED = "SELECTION_CHANGED";
|
||||||
|
|
||||||
|
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 HsRelatorio relatorio = null;
|
||||||
|
|
||||||
|
public AdicionarAreasRelatorioPanel()
|
||||||
|
{
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
tree.getSelectionModel().addTreeSelectionListener( new TreeSelectionListener(){
|
||||||
|
@Override
|
||||||
|
public void valueChanged( TreeSelectionEvent e )
|
||||||
|
{
|
||||||
|
setEnabled();
|
||||||
|
TreePath path = tree.getSelectionPath();
|
||||||
|
Object object = path == null ? null : path.getLastPathComponent();
|
||||||
|
HsRelatorioPosto posto = object == null ? null : ( (object instanceof PostoRelatorioNode) ? (HsRelatorioPosto) ((PostoRelatorioNode) object).getUserObject() : null);
|
||||||
|
firePropertyChange( SELECTION_CHANGED, null, posto );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setEnabled()
|
||||||
|
{
|
||||||
|
buttonAdicionar.setEnabled( false );
|
||||||
|
buttonRemover.setEnabled( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refresh()
|
||||||
|
{
|
||||||
|
root.removeAllChildren();
|
||||||
|
if( relatorio != null )
|
||||||
|
{
|
||||||
|
TreeTools.merge( root, HigieneSegurancaLogic.getAreasRelatorioTree( relatorio ) );
|
||||||
|
}
|
||||||
|
setEnabled();
|
||||||
|
TreeTools.refreshTree( tree, root );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setRelatorio( HsRelatorio relatorio )
|
||||||
|
{
|
||||||
|
this.relatorio = relatorio;
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,148 @@
|
|||||||
|
package siprp.higiene.relatorio;
|
||||||
|
|
||||||
|
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.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.HsRelatorioPostoMedida;
|
||||||
|
import siprp.database.cayenne.objects.HsRelatorioPosto;
|
||||||
|
import siprp.database.cayenne.objects.HsRelatorioPostoRisco;
|
||||||
|
|
||||||
|
public class AdicionarRiscosRelatorioPanel extends JPanel
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public static final String SELECTION_CHANGED = "RISCOS_SELECTION_CHANGED";
|
||||||
|
|
||||||
|
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 HsRelatorioPosto posto = null;
|
||||||
|
|
||||||
|
public AdicionarRiscosRelatorioPanel()
|
||||||
|
{
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
tree.getSelectionModel().addTreeSelectionListener( new TreeSelectionListener(){
|
||||||
|
@Override
|
||||||
|
public void valueChanged( TreeSelectionEvent e )
|
||||||
|
{
|
||||||
|
setEnabled();
|
||||||
|
Object object = null;
|
||||||
|
TreePath path = tree.getSelectionPath();
|
||||||
|
if( path != null )
|
||||||
|
{
|
||||||
|
Object selection = path.getLastPathComponent();
|
||||||
|
if( selection instanceof RiscoRelatorioNode )
|
||||||
|
{
|
||||||
|
object = selection == null ? null : ((RiscoRelatorioNode)selection).getUserObject();
|
||||||
|
}
|
||||||
|
else if( selection instanceof MedidaRelatorioNode )
|
||||||
|
{
|
||||||
|
object = selection == null ? null : ((MedidaRelatorioNode)selection).getUserObject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
firePropertyChange( SELECTION_CHANGED, null, object );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setEnabled()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refresh()
|
||||||
|
{
|
||||||
|
root.removeAllChildren();
|
||||||
|
if( posto != null )
|
||||||
|
{
|
||||||
|
for( HsRelatorioPostoRisco rel : posto.getHsRelatorioPostoRiscoArray() )
|
||||||
|
{
|
||||||
|
RiscoRelatorioNode node = new RiscoRelatorioNode( rel );
|
||||||
|
if( rel.getToHsRelatorioRisco() != null )
|
||||||
|
{
|
||||||
|
for( HsRelatorioPostoMedida medida : posto.getHsRelatorioPostoMedidaArray() )
|
||||||
|
{
|
||||||
|
if( rel.getToHsRelatorioPosto().equals( medida.getToHsRelatorioPosto() ) )
|
||||||
|
{
|
||||||
|
node.add( new MedidaRelatorioNode(medida) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
root.add( node );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setEnabled();
|
||||||
|
TreeTools.refreshTree( tree, root );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPosto( HsRelatorioPosto posto )
|
||||||
|
{
|
||||||
|
this.posto = posto;
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package siprp.higiene.relatorio;
|
||||||
|
|
||||||
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
|
|
||||||
|
import siprp.database.cayenne.objects.HsRelatorioArea;
|
||||||
|
|
||||||
|
public class AreaRelatorioNode extends DefaultMutableTreeNode
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public AreaRelatorioNode( HsRelatorioArea risco )
|
||||||
|
{
|
||||||
|
super( risco );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,263 @@
|
|||||||
|
package siprp.higiene.relatorio;
|
||||||
|
|
||||||
|
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.Insets;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
import javax.swing.JCheckBox;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.JTextArea;
|
||||||
|
import javax.swing.event.CaretEvent;
|
||||||
|
import javax.swing.event.CaretListener;
|
||||||
|
|
||||||
|
import leaf.ui.LeafButton;
|
||||||
|
import siprp.database.cayenne.objects.HsRelatorioPostoMedida;
|
||||||
|
|
||||||
|
import com.evolute.utils.images.ImageException;
|
||||||
|
import com.evolute.utils.images.ImageIconLoader;
|
||||||
|
|
||||||
|
public class GerirMedidaRelatorioPanel extends JPanel
|
||||||
|
{
|
||||||
|
|
||||||
|
public static final String MEDIDA_CHANGED = "MEDIDA_CHANGED";
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private static final String ICON_NAME_SAVE = "siprp/higiene/gestao/riscos/save.png";
|
||||||
|
|
||||||
|
private static final String ICON_NAME_REVERT = "siprp/higiene/gestao/riscos/revert.png";
|
||||||
|
|
||||||
|
private LeafButton buttonSaveMedida;
|
||||||
|
|
||||||
|
private LeafButton buttonRevertMedida;
|
||||||
|
|
||||||
|
private LeafButton buttonSaveRequesito;
|
||||||
|
|
||||||
|
private LeafButton buttonRevertRequesito;
|
||||||
|
|
||||||
|
private final JCheckBox checkPlanoActuacao = new JCheckBox("Plano de actua" + ccedil + atilde + "o");
|
||||||
|
|
||||||
|
private final JTextArea fieldTextMedida = new JTextArea();
|
||||||
|
|
||||||
|
private final JScrollPane scrollMedida = new JScrollPane(fieldTextMedida);
|
||||||
|
|
||||||
|
private final JTextArea fieldTextRequisitosLegais = new JTextArea();
|
||||||
|
|
||||||
|
private final JScrollPane scrollRequesitos = new JScrollPane(fieldTextRequisitosLegais);
|
||||||
|
|
||||||
|
private HsRelatorioPostoMedida relacao = null;
|
||||||
|
|
||||||
|
public GerirMedidaRelatorioPanel()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
buttonSaveMedida = new LeafButton( ImageIconLoader.loadImageIcon( ICON_NAME_SAVE ) );
|
||||||
|
buttonRevertMedida = new LeafButton( ImageIconLoader.loadImageIcon( ICON_NAME_REVERT ) );
|
||||||
|
buttonSaveRequesito = new LeafButton( ImageIconLoader.loadImageIcon( ICON_NAME_SAVE ) );
|
||||||
|
buttonRevertRequesito = new LeafButton( ImageIconLoader.loadImageIcon( ICON_NAME_REVERT ) );
|
||||||
|
} catch( ImageException e )
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
startupComponents();
|
||||||
|
startupLayout();
|
||||||
|
placeComponents();
|
||||||
|
setupListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startupComponents()
|
||||||
|
{
|
||||||
|
fieldTextMedida.setWrapStyleWord( true );
|
||||||
|
fieldTextMedida.setLineWrap( true );
|
||||||
|
fieldTextRequisitosLegais.setWrapStyleWord( true );
|
||||||
|
fieldTextRequisitosLegais.setLineWrap( true );
|
||||||
|
scrollMedida.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
|
||||||
|
scrollMedida.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS );
|
||||||
|
scrollRequesitos.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
|
||||||
|
scrollRequesitos.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS );
|
||||||
|
buttonSaveMedida.setMargin( new Insets(0,0,0,0) );
|
||||||
|
buttonSaveRequesito.setMargin( new Insets(0,0,0,0) );
|
||||||
|
buttonRevertMedida.setMargin( new Insets(0,0,0,0) );
|
||||||
|
buttonRevertRequesito.setMargin( new Insets(0,0,0,0) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupListeners()
|
||||||
|
{
|
||||||
|
checkPlanoActuacao.addActionListener( new ActionListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void actionPerformed( ActionEvent e )
|
||||||
|
{
|
||||||
|
savePlano();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
fieldTextRequisitosLegais.addCaretListener( new CaretListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void caretUpdate( CaretEvent e )
|
||||||
|
{
|
||||||
|
setEnabled();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
fieldTextMedida.addCaretListener( new CaretListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void caretUpdate( CaretEvent e )
|
||||||
|
{
|
||||||
|
setEnabled();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
buttonSaveMedida.addActionListener( new ActionListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void actionPerformed( ActionEvent e )
|
||||||
|
{
|
||||||
|
saveMedida();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
buttonSaveRequesito.addActionListener( new ActionListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void actionPerformed( ActionEvent e )
|
||||||
|
{
|
||||||
|
saveRequesito();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
buttonRevertMedida.addActionListener( new ActionListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void actionPerformed( ActionEvent e )
|
||||||
|
{
|
||||||
|
revertMedida();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
buttonRevertRequesito.addActionListener( new ActionListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void actionPerformed( ActionEvent e )
|
||||||
|
{
|
||||||
|
revertRequesito();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startupLayout()
|
||||||
|
{
|
||||||
|
TableLayout layout = new TableLayout(
|
||||||
|
new double[]{ TableLayout.FILL, TableLayout.MINIMUM, TableLayout.MINIMUM },
|
||||||
|
new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL, 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 },
|
||||||
|
new double[]{ TableLayout.MINIMUM }
|
||||||
|
);
|
||||||
|
layout.setHGap( 5 );
|
||||||
|
layout.setVGap( 5 );
|
||||||
|
panel.setLayout( layout );
|
||||||
|
panel.add( checkPlanoActuacao, new TableLayoutConstraints(0,0) );
|
||||||
|
add( panel, new TableLayoutConstraints(0,0,2,0) );
|
||||||
|
add( new JLabel("Requesitos legais"), new TableLayoutConstraints(0,1) );
|
||||||
|
add( buttonSaveRequesito, new TableLayoutConstraints(1,1) );
|
||||||
|
add( buttonRevertRequesito, new TableLayoutConstraints(2,1) );
|
||||||
|
add( scrollRequesitos, new TableLayoutConstraints(0,2,2,2) );
|
||||||
|
add( new JLabel("Medida"), new TableLayoutConstraints(0,3) );
|
||||||
|
add( buttonSaveMedida, new TableLayoutConstraints(1,3) );
|
||||||
|
add( buttonRevertMedida, new TableLayoutConstraints(2,3) );
|
||||||
|
add( scrollMedida, new TableLayoutConstraints(0,4,2,4) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setEnabled()
|
||||||
|
{
|
||||||
|
boolean medidaChanged = false;
|
||||||
|
boolean requesitoChanged = false;
|
||||||
|
if( relacao != null )
|
||||||
|
{
|
||||||
|
medidaChanged = !fieldTextMedida.getText().equals( relacao.getToHsRelatorioMedida().getDescription() );
|
||||||
|
requesitoChanged = !fieldTextRequisitosLegais.getText().equals( relacao.getToHsRelatorioMedida().getRequesitosLegais() );
|
||||||
|
}
|
||||||
|
buttonSaveMedida.setEnabled( medidaChanged );
|
||||||
|
buttonSaveRequesito.setEnabled( requesitoChanged );
|
||||||
|
buttonRevertMedida.setEnabled( medidaChanged );
|
||||||
|
buttonRevertRequesito.setEnabled( requesitoChanged );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void savePlano()
|
||||||
|
{
|
||||||
|
if( relacao != null )
|
||||||
|
{
|
||||||
|
relacao.setIsPlanoActuacao( checkPlanoActuacao.isSelected() );
|
||||||
|
relacao.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveMedida()
|
||||||
|
{
|
||||||
|
if( relacao != null )
|
||||||
|
{
|
||||||
|
relacao.getToHsRelatorioMedida().setDescription( fieldTextMedida.getText() );
|
||||||
|
relacao.save();
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
setEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveRequesito()
|
||||||
|
{
|
||||||
|
if( relacao != null )
|
||||||
|
{
|
||||||
|
relacao.getToHsRelatorioMedida().setRequesitosLegais(fieldTextRequisitosLegais.getText() );
|
||||||
|
relacao.save();
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
setEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void revertMedida()
|
||||||
|
{
|
||||||
|
if( relacao != null )
|
||||||
|
{
|
||||||
|
fieldTextMedida.setText( relacao.getToHsRelatorioMedida().getDescription() );
|
||||||
|
}
|
||||||
|
setEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void revertRequesito()
|
||||||
|
{
|
||||||
|
if( relacao != null )
|
||||||
|
{
|
||||||
|
fieldTextRequisitosLegais.setText( relacao.getToHsRelatorioMedida().getRequesitosLegais() );
|
||||||
|
}
|
||||||
|
setEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refresh()
|
||||||
|
{
|
||||||
|
firePropertyChange( MEDIDA_CHANGED, null, relacao );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMedida( HsRelatorioPostoMedida medida )
|
||||||
|
{
|
||||||
|
this.relacao = medida;
|
||||||
|
fieldTextMedida.setText( medida == null ? null : medida.getToHsRelatorioMedida().getDescription() );
|
||||||
|
fieldTextRequisitosLegais.setText( medida == null ? null : medida.getToHsRelatorioMedida().getRequesitosLegais() );
|
||||||
|
checkPlanoActuacao.setSelected( medida == null ? false : ( medida.getIsPlanoActuacao() == null ? false : medida.getIsPlanoActuacao() ) );
|
||||||
|
setEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,275 @@
|
|||||||
|
package siprp.higiene.relatorio;
|
||||||
|
|
||||||
|
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.AbstractButton;
|
||||||
|
import javax.swing.ButtonGroup;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JRadioButton;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.event.CaretEvent;
|
||||||
|
import javax.swing.event.CaretListener;
|
||||||
|
import javax.swing.event.ChangeEvent;
|
||||||
|
import javax.swing.event.ChangeListener;
|
||||||
|
|
||||||
|
import leaf.ui.LeafButton;
|
||||||
|
import leaf.ui.LeafIconButton;
|
||||||
|
import siprp.database.cayenne.objects.HsRelatorioPostoRisco;
|
||||||
|
import siprp.database.cayenne.objects.HsRelatorioRiscoValorQualitativo;
|
||||||
|
import siprp.logic.HigieneSegurancaLogic;
|
||||||
|
|
||||||
|
public class GerirValoresRiscoPanel extends JPanel implements ActionListener, CaretListener
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private static final String ICON_NAME_SAVE = "siprp/higiene/gestao/riscos/save.png";
|
||||||
|
|
||||||
|
private static final String ICON_NAME_REVERT = "siprp/higiene/gestao/riscos/revert.png";
|
||||||
|
|
||||||
|
private final JRadioButton radioValorQuantitativo = new JRadioButton();
|
||||||
|
|
||||||
|
private final JRadioButton radioValorQualitativo = new JRadioButton();
|
||||||
|
|
||||||
|
private final JTextField textSeveridade = new JTextField();
|
||||||
|
|
||||||
|
private final JTextField textProbabilidade = new JTextField();
|
||||||
|
|
||||||
|
private final JComboBox comboValorQualitativo = new JComboBox();
|
||||||
|
|
||||||
|
private final LeafButton buttonSave = LeafIconButton.createButton( ICON_NAME_SAVE );
|
||||||
|
|
||||||
|
private final LeafButton buttonRevert = LeafIconButton.createButton( ICON_NAME_REVERT);
|
||||||
|
|
||||||
|
private final ButtonGroup bg = new ButtonGroup();
|
||||||
|
|
||||||
|
private HsRelatorioPostoRisco valoresRisco = null;
|
||||||
|
|
||||||
|
public GerirValoresRiscoPanel()
|
||||||
|
{
|
||||||
|
startupListeners();
|
||||||
|
startupComponents();
|
||||||
|
startupLayout();
|
||||||
|
placeComponents();
|
||||||
|
loadValoresQualitativos();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startupListeners()
|
||||||
|
{
|
||||||
|
radioValorQualitativo.addActionListener( this );
|
||||||
|
radioValorQuantitativo.addActionListener( this );
|
||||||
|
comboValorQualitativo.addActionListener( this );
|
||||||
|
textProbabilidade.addCaretListener( this );
|
||||||
|
textSeveridade.addCaretListener( this );
|
||||||
|
buttonSave.addActionListener( new ActionListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void actionPerformed( ActionEvent e )
|
||||||
|
{
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
buttonRevert.addActionListener( new ActionListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void actionPerformed( ActionEvent e )
|
||||||
|
{
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startupComponents()
|
||||||
|
{
|
||||||
|
textSeveridade.setPreferredSize( new Dimension( 30, 0 ) );
|
||||||
|
textProbabilidade.setPreferredSize( new Dimension( 30, 0 ) );
|
||||||
|
buttonSave.setEnabled( false );
|
||||||
|
buttonRevert.setEnabled( false );
|
||||||
|
bg.add( radioValorQualitativo );
|
||||||
|
bg.add( radioValorQuantitativo );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startupLayout()
|
||||||
|
{
|
||||||
|
TableLayout layout = new TableLayout(
|
||||||
|
new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.PREFERRED, TableLayout.FILL, TableLayout.MINIMUM, TableLayout.PREFERRED, TableLayout.FILL },
|
||||||
|
new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM }
|
||||||
|
);
|
||||||
|
layout.setVGap( 5 );
|
||||||
|
layout.setHGap( 5 );
|
||||||
|
setLayout( layout );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void placeComponents()
|
||||||
|
{
|
||||||
|
TableLayout layout = new TableLayout(
|
||||||
|
new double[]{ TableLayout.FILL, TableLayout.MINIMUM, TableLayout.MINIMUM },
|
||||||
|
new double[]{ TableLayout.MINIMUM }
|
||||||
|
);
|
||||||
|
layout.setVGap( 5 );
|
||||||
|
layout.setHGap( 5 );
|
||||||
|
JPanel panel = new JPanel();
|
||||||
|
panel.setLayout( layout );
|
||||||
|
panel.add( buttonSave, new TableLayoutConstraints( 1, 0 ) );
|
||||||
|
panel.add( buttonRevert, new TableLayoutConstraints( 2, 0 ) );
|
||||||
|
|
||||||
|
add( panel, new TableLayoutConstraints(1,0,6,0) );
|
||||||
|
add( radioValorQuantitativo, new TableLayoutConstraints( 0, 1 ) );
|
||||||
|
add( new JLabel("Severidade"), new TableLayoutConstraints( 1, 1 ) );
|
||||||
|
add( textSeveridade, new TableLayoutConstraints( 2, 1 ) );
|
||||||
|
add( new JLabel("Probabilidade"), new TableLayoutConstraints( 4, 1 ) );
|
||||||
|
add( textProbabilidade, new TableLayoutConstraints( 5, 1 ) );
|
||||||
|
add( radioValorQualitativo, new TableLayoutConstraints( 0, 2 ) );
|
||||||
|
add( comboValorQualitativo, new TableLayoutConstraints( 1, 2, 5, 2 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadValoresQualitativos()
|
||||||
|
{
|
||||||
|
comboValorQualitativo.removeAllItems();
|
||||||
|
for( HsRelatorioRiscoValorQualitativo valor : HigieneSegurancaLogic.getAllValoresQualitativos() )
|
||||||
|
{
|
||||||
|
comboValorQualitativo.addItem( valor );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refresh()
|
||||||
|
{
|
||||||
|
if( valoresRisco != null )
|
||||||
|
{
|
||||||
|
boolean qualitativo = valoresRisco.getToHsRelatorioRiscoValorQualitativo() != null;
|
||||||
|
radioValorQuantitativo.setSelected( !qualitativo );
|
||||||
|
radioValorQualitativo.setSelected( qualitativo );
|
||||||
|
String severidade = (valoresRisco.getSeveridade() == null ? null : valoresRisco.getSeveridade() + "");
|
||||||
|
String probabilidade = (valoresRisco.getProbabilidade() == null ? null : valoresRisco.getProbabilidade() + "");
|
||||||
|
textSeveridade.setText( severidade );
|
||||||
|
textProbabilidade.setText( probabilidade );
|
||||||
|
if( valoresRisco.getToHsRelatorioRiscoValorQualitativo() != null )
|
||||||
|
{
|
||||||
|
comboValorQualitativo.setSelectedItem( valoresRisco.getToHsRelatorioRiscoValorQualitativo() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bg.clearSelection();
|
||||||
|
textSeveridade.setText( null );
|
||||||
|
textProbabilidade.setText( null );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setEnabled()
|
||||||
|
{
|
||||||
|
textProbabilidade.setEnabled( valoresRisco != null && radioValorQuantitativo.isSelected() );
|
||||||
|
textSeveridade.setEnabled( valoresRisco != null && radioValorQuantitativo.isSelected() );
|
||||||
|
radioValorQualitativo.setEnabled( valoresRisco != null );
|
||||||
|
radioValorQuantitativo.setEnabled( valoresRisco != null );
|
||||||
|
comboValorQualitativo.setEnabled( valoresRisco != null && radioValorQualitativo.isSelected() );
|
||||||
|
if( valoresRisco != null )
|
||||||
|
{
|
||||||
|
boolean changes = false;
|
||||||
|
boolean wasQual = valoresRisco.getToHsRelatorioRiscoValorQualitativo() != null;
|
||||||
|
boolean isQual = radioValorQualitativo.isSelected();
|
||||||
|
if(!isQual)
|
||||||
|
{
|
||||||
|
changes = wasQual;
|
||||||
|
if(!changes)
|
||||||
|
{
|
||||||
|
boolean probChanged = false;
|
||||||
|
boolean sevChanged = false;
|
||||||
|
String prob = textProbabilidade.getText();
|
||||||
|
String sev = textSeveridade.getText();
|
||||||
|
if( prob == null )
|
||||||
|
{
|
||||||
|
probChanged = valoresRisco.getProbabilidade() != null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
probChanged = !prob.equals(valoresRisco.getProbabilidade() == null ? "" : valoresRisco.getProbabilidade() + "");
|
||||||
|
}
|
||||||
|
if( sev == null )
|
||||||
|
{
|
||||||
|
sevChanged = valoresRisco.getSeveridade() != null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sevChanged = !sev.equals(valoresRisco.getSeveridade() == null ? "" : valoresRisco.getSeveridade() + "" );
|
||||||
|
}
|
||||||
|
changes = probChanged || sevChanged;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
changes = !wasQual;
|
||||||
|
if(!changes)
|
||||||
|
{
|
||||||
|
changes = !comboValorQualitativo.getSelectedItem().equals( valoresRisco.getToHsRelatorioRiscoValorQualitativo() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buttonSave.setEnabled( changes );
|
||||||
|
buttonRevert.setEnabled( changes );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRelatorioPostoRisco( HsRelatorioPostoRisco rel )
|
||||||
|
{
|
||||||
|
this.valoresRisco = rel;
|
||||||
|
refresh();
|
||||||
|
setEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void save()
|
||||||
|
{
|
||||||
|
if( valoresRisco != null )
|
||||||
|
{
|
||||||
|
if( radioValorQualitativo.isSelected() )
|
||||||
|
{
|
||||||
|
valoresRisco.setToHsRelatorioRiscoValorQualitativo( (HsRelatorioRiscoValorQualitativo) comboValorQualitativo.getSelectedItem() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
valoresRisco.setToHsRelatorioRiscoValorQualitativo( null );
|
||||||
|
Integer probabilidade = 0;
|
||||||
|
Integer severidade = 0;
|
||||||
|
try{
|
||||||
|
probabilidade = new Integer(textProbabilidade.getText() != null ? textProbabilidade.getText() : "0" );
|
||||||
|
}
|
||||||
|
catch (NumberFormatException e1)
|
||||||
|
{
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
try{
|
||||||
|
severidade = new Integer(textSeveridade.getText() != null ? textSeveridade.getText() : "0" );
|
||||||
|
}
|
||||||
|
catch (NumberFormatException e2)
|
||||||
|
{
|
||||||
|
e2.printStackTrace();
|
||||||
|
}
|
||||||
|
valoresRisco.setProbabilidade( probabilidade );
|
||||||
|
valoresRisco.setSeveridade( severidade );
|
||||||
|
}
|
||||||
|
valoresRisco.save();
|
||||||
|
refresh();
|
||||||
|
setEnabled();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void caretUpdate( CaretEvent e )
|
||||||
|
{
|
||||||
|
setEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed( ActionEvent e )
|
||||||
|
{
|
||||||
|
setEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package siprp.higiene.relatorio;
|
||||||
|
|
||||||
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
|
|
||||||
|
import siprp.database.cayenne.objects.HsRelatorioPostoMedida;
|
||||||
|
|
||||||
|
public class MedidaRelatorioNode extends DefaultMutableTreeNode
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public MedidaRelatorioNode( HsRelatorioPostoMedida medida )
|
||||||
|
{
|
||||||
|
super( medida );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package siprp.higiene.relatorio;
|
||||||
|
|
||||||
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
|
|
||||||
|
import siprp.database.cayenne.objects.HsRelatorioPosto;
|
||||||
|
|
||||||
|
public class PostoRelatorioNode extends DefaultMutableTreeNode
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public PostoRelatorioNode( HsRelatorioPosto risco )
|
||||||
|
{
|
||||||
|
super( risco );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package siprp.higiene.relatorio;
|
||||||
|
|
||||||
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
|
|
||||||
|
import siprp.database.cayenne.objects.HsRelatorioPostoRisco;
|
||||||
|
|
||||||
|
public class RiscoRelatorioNode extends DefaultMutableTreeNode
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public RiscoRelatorioNode( HsRelatorioPostoRisco risco )
|
||||||
|
{
|
||||||
|
super( risco );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in new issue