forked from Coded/SIPRP
git-svn-id: https://svn.coded.pt/svn/SIPRP@802 bb69d46d-e84e-40c8-a05a-06db0d633741
parent
7a985cc91a
commit
a407b0920b
@ -0,0 +1,578 @@
|
|||||||
|
package siprp.higiene.gestao.riscos;
|
||||||
|
|
||||||
|
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.CardLayout;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.GridLayout;
|
||||||
|
import java.awt.Insets;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.JTextArea;
|
||||||
|
import javax.swing.JTree;
|
||||||
|
import javax.swing.event.CaretEvent;
|
||||||
|
import javax.swing.event.CaretListener;
|
||||||
|
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.HsMedida;
|
||||||
|
import siprp.database.cayenne.objects.HsRisco;
|
||||||
|
import siprp.database.cayenne.objects.HsRiscoMedida;
|
||||||
|
import siprp.database.cayenne.objects.HsRiscoTema;
|
||||||
|
import siprp.logic.HigieneSegurancaLogic;
|
||||||
|
|
||||||
|
import com.evolute.utils.images.ImageException;
|
||||||
|
import com.evolute.utils.images.ImageIconLoader;
|
||||||
|
|
||||||
|
public class GerirRiscosPanel extends JPanel
|
||||||
|
{
|
||||||
|
|
||||||
|
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 static final String PANEL_TEMA = "PANEL_TEMA";
|
||||||
|
|
||||||
|
private static final String PANEL_RISCO = "PANEL_RISCO";
|
||||||
|
|
||||||
|
private static final String PANEL_MEDIDA = "PANEL_MEDIDA";
|
||||||
|
|
||||||
|
private final JPanel panelButtons = new JPanel();
|
||||||
|
|
||||||
|
private final JPanel panelTree = new JPanel();
|
||||||
|
|
||||||
|
private final JPanel panelData = new JPanel();
|
||||||
|
|
||||||
|
private final JPanel panelDataTema = new JPanel();
|
||||||
|
|
||||||
|
private final JPanel panelDataRisco = new JPanel();
|
||||||
|
|
||||||
|
private final JPanel panelDataMedida = new JPanel();
|
||||||
|
|
||||||
|
private final LeafButton buttonTemaCriar = new LeafButton( "Criar" );
|
||||||
|
|
||||||
|
private final LeafButton buttonTemaRemover = new LeafButton( "Remover" );
|
||||||
|
|
||||||
|
private final LeafButton buttonRiscoCriar = new LeafButton( "Criar" );
|
||||||
|
|
||||||
|
private final LeafButton buttonRiscoRemover = new LeafButton( "Remover" );
|
||||||
|
|
||||||
|
private final LeafButton buttonMedidaCriar = new LeafButton( "Criar" );
|
||||||
|
|
||||||
|
private final LeafButton buttonMedidaRemover = new LeafButton( "Remover" );
|
||||||
|
|
||||||
|
private LeafButton buttonSaveMedida;
|
||||||
|
|
||||||
|
private LeafButton buttonRevertMedida;
|
||||||
|
|
||||||
|
private LeafButton buttonSaveRequesito;
|
||||||
|
|
||||||
|
private LeafButton buttonRevertRequesito;
|
||||||
|
|
||||||
|
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 final DefaultMutableTreeNode root = new DefaultMutableTreeNode();
|
||||||
|
|
||||||
|
private final DefaultTreeModel model = new DefaultTreeModel( root );
|
||||||
|
|
||||||
|
private final JTree tree = new JTree( model );
|
||||||
|
|
||||||
|
private final JScrollPane scroll = new JScrollPane( tree );
|
||||||
|
|
||||||
|
private final CardLayout cardLayout = new CardLayout();
|
||||||
|
|
||||||
|
public GerirRiscosPanel()
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupListeners()
|
||||||
|
{
|
||||||
|
buttonTemaCriar.addActionListener( new ActionListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void actionPerformed( ActionEvent e )
|
||||||
|
{
|
||||||
|
criarTema();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
buttonTemaRemover.addActionListener( new ActionListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void actionPerformed( ActionEvent e )
|
||||||
|
{
|
||||||
|
removerTema();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
buttonRiscoCriar.addActionListener( new ActionListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void actionPerformed( ActionEvent e )
|
||||||
|
{
|
||||||
|
criarRisco();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
buttonRiscoRemover.addActionListener( new ActionListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void actionPerformed( ActionEvent e )
|
||||||
|
{
|
||||||
|
removerRisco();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
buttonMedidaCriar.addActionListener( new ActionListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void actionPerformed( ActionEvent e )
|
||||||
|
{
|
||||||
|
criarMedida();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
buttonMedidaRemover.addActionListener( new ActionListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void actionPerformed( ActionEvent e )
|
||||||
|
{
|
||||||
|
removerMedida();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
tree.getSelectionModel().addTreeSelectionListener( new TreeSelectionListener(){
|
||||||
|
@Override
|
||||||
|
public void valueChanged( TreeSelectionEvent e )
|
||||||
|
{
|
||||||
|
setEnabled();
|
||||||
|
selectCard();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
fieldTextRequisitosLegais.addCaretListener( new CaretListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void caretUpdate( CaretEvent e )
|
||||||
|
{
|
||||||
|
enableEditButtons();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
fieldTextMedida.addCaretListener( new CaretListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void caretUpdate( CaretEvent e )
|
||||||
|
{
|
||||||
|
enableEditButtons();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
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 saveMedida()
|
||||||
|
{
|
||||||
|
HsRiscoMedida rel = getSelectedMedida();
|
||||||
|
if( rel != null )
|
||||||
|
{
|
||||||
|
rel.getToHsMedida().setDescription( fieldTextMedida.getText() );
|
||||||
|
rel.save();
|
||||||
|
}
|
||||||
|
enableEditButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveRequesito()
|
||||||
|
{
|
||||||
|
HsRiscoMedida rel = getSelectedMedida();
|
||||||
|
if( rel != null )
|
||||||
|
{
|
||||||
|
rel.getToHsMedida().setRequesitosLegais(fieldTextRequisitosLegais.getText() );
|
||||||
|
rel.save();
|
||||||
|
}
|
||||||
|
enableEditButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void revertMedida()
|
||||||
|
{
|
||||||
|
HsRiscoMedida rel = getSelectedMedida();
|
||||||
|
if( rel != null )
|
||||||
|
{
|
||||||
|
fieldTextMedida.setText( rel.getToHsMedida().getDescription() );
|
||||||
|
}
|
||||||
|
enableEditButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void revertRequesito()
|
||||||
|
{
|
||||||
|
HsRiscoMedida rel = getSelectedMedida();
|
||||||
|
if( rel != null )
|
||||||
|
{
|
||||||
|
fieldTextRequisitosLegais.setText( rel.getToHsMedida().getRequesitosLegais() );
|
||||||
|
}
|
||||||
|
enableEditButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void criarTema()
|
||||||
|
{
|
||||||
|
String temaString = JOptionPane.showInputDialog( this, "Criar tema", "Descri" + ccedil + atilde + "o", JOptionPane.QUESTION_MESSAGE );
|
||||||
|
if( temaString != null )
|
||||||
|
{
|
||||||
|
HsRiscoTema tema = new HsRiscoTema();
|
||||||
|
tema.setDescription( temaString );
|
||||||
|
tema.save();
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removerTema()
|
||||||
|
{
|
||||||
|
HsRiscoTema tema = getSelectedTema();
|
||||||
|
if( tema != null )
|
||||||
|
{
|
||||||
|
tema.delete();
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void criarRisco()
|
||||||
|
{
|
||||||
|
HsRiscoTema tema = getSelectedTema();
|
||||||
|
if( tema == null )
|
||||||
|
{
|
||||||
|
HsRisco risco = getSelectedRisco();
|
||||||
|
if( risco != null )
|
||||||
|
{
|
||||||
|
tema = risco.getToHsRiscoTema();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HsRiscoMedida medida = getSelectedMedida();
|
||||||
|
if( medida != null )
|
||||||
|
{
|
||||||
|
tema = medida.getToHsRisco().getToHsRiscoTema();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( tema != null )
|
||||||
|
{
|
||||||
|
String riscoString = JOptionPane.showInputDialog( this, "Criar risco", "Descri" + ccedil + atilde + "o", JOptionPane.QUESTION_MESSAGE );
|
||||||
|
if( riscoString != null )
|
||||||
|
{
|
||||||
|
HsRisco risco = new HsRisco();
|
||||||
|
risco.setDescription( riscoString );
|
||||||
|
risco.setToHsRiscoTema( tema );
|
||||||
|
tema.save();
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removerRisco()
|
||||||
|
{
|
||||||
|
HsRisco risco = getSelectedRisco();
|
||||||
|
if( risco != null )
|
||||||
|
{
|
||||||
|
risco.delete();
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void criarMedida()
|
||||||
|
{
|
||||||
|
HsRisco risco = getSelectedRisco();
|
||||||
|
if( risco == null )
|
||||||
|
{
|
||||||
|
HsRiscoMedida medida = getSelectedMedida();
|
||||||
|
if( medida != null )
|
||||||
|
{
|
||||||
|
risco = medida.getToHsRisco();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( risco != null )
|
||||||
|
{
|
||||||
|
HsMedida medida = new HsMedida();
|
||||||
|
medida.setDescription( "(medida)" );
|
||||||
|
medida.setRequesitosLegais( "(requesitos legais)" );
|
||||||
|
medida.save();
|
||||||
|
HsRiscoMedida rel = new HsRiscoMedida();
|
||||||
|
rel.setToHsRisco( risco );
|
||||||
|
rel.setToHsMedida( medida );
|
||||||
|
rel.save();
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removerMedida()
|
||||||
|
{
|
||||||
|
HsRiscoMedida medida = getSelectedMedida();
|
||||||
|
if( medida != null )
|
||||||
|
{
|
||||||
|
medida.delete();
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private HsRiscoTema getSelectedTema()
|
||||||
|
{
|
||||||
|
Object object = getSelectedObject();
|
||||||
|
return object == null ? null : ((object instanceof HsRiscoTema) ? (HsRiscoTema) object : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private HsRisco getSelectedRisco()
|
||||||
|
{
|
||||||
|
Object object = getSelectedObject();
|
||||||
|
return object == null ? null : ((object instanceof HsRisco) ? (HsRisco) object : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private HsRiscoMedida getSelectedMedida()
|
||||||
|
{
|
||||||
|
Object object = getSelectedObject();
|
||||||
|
return object == null ? null : ((object instanceof HsRiscoMedida) ? (HsRiscoMedida) object : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object getSelectedObject()
|
||||||
|
{
|
||||||
|
DefaultMutableTreeNode node = getSelectedNode();
|
||||||
|
return node == null ? null : node.getUserObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
private DefaultMutableTreeNode getSelectedNode()
|
||||||
|
{
|
||||||
|
TreePath path = tree.getSelectionPath();
|
||||||
|
return path == null ? null : (DefaultMutableTreeNode) path.getLastPathComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
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 );
|
||||||
|
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 setEnabled()
|
||||||
|
{
|
||||||
|
HsRiscoTema tema = getSelectedTema();
|
||||||
|
HsRisco risco = getSelectedRisco();
|
||||||
|
HsRiscoMedida medida = getSelectedMedida();
|
||||||
|
buttonMedidaCriar.setEnabled( risco != null || medida != null );
|
||||||
|
buttonRiscoCriar.setEnabled( tema != null || risco != null || medida != null );
|
||||||
|
buttonMedidaRemover.setEnabled( medida != null );
|
||||||
|
buttonRiscoRemover.setEnabled( risco != null );
|
||||||
|
buttonTemaRemover.setEnabled( tema != null );
|
||||||
|
enableEditButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enableEditButtons()
|
||||||
|
{
|
||||||
|
HsRiscoMedida rel = getSelectedMedida();
|
||||||
|
if( rel != null )
|
||||||
|
{
|
||||||
|
boolean medidaChanged = !fieldTextMedida.getText().equals( rel.getToHsMedida().getDescription() );
|
||||||
|
boolean requesitoChanged = !fieldTextRequisitosLegais.getText().equals( rel.getToHsMedida().getRequesitosLegais() );
|
||||||
|
buttonSaveMedida.setEnabled( medidaChanged );
|
||||||
|
buttonSaveRequesito.setEnabled( requesitoChanged );
|
||||||
|
buttonRevertMedida.setEnabled( medidaChanged );
|
||||||
|
buttonRevertRequesito.setEnabled( requesitoChanged );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startupLayout()
|
||||||
|
{
|
||||||
|
TableLayout layout = new TableLayout(
|
||||||
|
new double[]{ TableLayout.MINIMUM, TableLayout.PREFERRED, TableLayout.FILL },
|
||||||
|
new double[]{ TableLayout.FILL }
|
||||||
|
);
|
||||||
|
layout.setHGap( 5 );
|
||||||
|
layout.setVGap( 5 );
|
||||||
|
setLayout( layout );
|
||||||
|
|
||||||
|
layout = new TableLayout(
|
||||||
|
new double[]{ TableLayout.MINIMUM },
|
||||||
|
new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL }
|
||||||
|
);
|
||||||
|
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 );
|
||||||
|
|
||||||
|
layout = new TableLayout(
|
||||||
|
new double[]{ TableLayout.FILL },
|
||||||
|
new double[]{ TableLayout.FILL }
|
||||||
|
);
|
||||||
|
layout.setHGap( 5 );
|
||||||
|
layout.setVGap( 5 );
|
||||||
|
panelDataTema.setLayout( layout );
|
||||||
|
|
||||||
|
layout = new TableLayout(
|
||||||
|
new double[]{ TableLayout.FILL },
|
||||||
|
new double[]{ TableLayout.FILL }
|
||||||
|
);
|
||||||
|
layout.setHGap( 5 );
|
||||||
|
layout.setVGap( 5 );
|
||||||
|
panelDataRisco.setLayout( layout );
|
||||||
|
|
||||||
|
layout = new TableLayout(
|
||||||
|
new double[]{ TableLayout.FILL, TableLayout.MINIMUM, TableLayout.MINIMUM },
|
||||||
|
new double[]{ TableLayout.MINIMUM, TableLayout.FILL, TableLayout.MINIMUM, TableLayout.FILL }
|
||||||
|
);
|
||||||
|
layout.setHGap( 5 );
|
||||||
|
layout.setVGap( 5 );
|
||||||
|
panelDataMedida.setLayout( layout );
|
||||||
|
|
||||||
|
panelData.setLayout( cardLayout );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void placeComponents()
|
||||||
|
{
|
||||||
|
JPanel panel = new JPanel();
|
||||||
|
panel.setBorder( BorderFactory.createTitledBorder( "Tema" ) );
|
||||||
|
panel.setLayout( new GridLayout( 2, 1 ) );
|
||||||
|
panel.add( buttonTemaCriar );
|
||||||
|
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.add( buttonRiscoCriar );
|
||||||
|
panel.add( buttonRiscoRemover );
|
||||||
|
panelButtons.add( panel, new TableLayoutConstraints( 0, 1 ) );
|
||||||
|
panel = new JPanel();
|
||||||
|
panel.setBorder( BorderFactory.createTitledBorder( "Medida" ) );
|
||||||
|
panel.setLayout( new GridLayout( 2, 1 ) );
|
||||||
|
panel.add( buttonMedidaCriar );
|
||||||
|
panel.add( buttonMedidaRemover );
|
||||||
|
panelButtons.add( panel, new TableLayoutConstraints( 0, 2 ) );
|
||||||
|
|
||||||
|
panelTree.add( scroll, new TableLayoutConstraints( 0, 0 ) );
|
||||||
|
|
||||||
|
panelDataMedida.add( new JLabel("Requesitos legais"), new TableLayoutConstraints(0,0) );
|
||||||
|
panelDataMedida.add( buttonSaveRequesito, new TableLayoutConstraints(1,0) );
|
||||||
|
panelDataMedida.add( buttonRevertRequesito, new TableLayoutConstraints(2,0) );
|
||||||
|
panelDataMedida.add( scrollRequesitos, new TableLayoutConstraints(0,1,2,1) );
|
||||||
|
panelDataMedida.add( new JLabel("Medida"), new TableLayoutConstraints(0,2) );
|
||||||
|
panelDataMedida.add( buttonSaveMedida, new TableLayoutConstraints(1,2) );
|
||||||
|
panelDataMedida.add( buttonRevertMedida, new TableLayoutConstraints(2,2) );
|
||||||
|
panelDataMedida.add( scrollMedida, new TableLayoutConstraints(0,3,2,3) );
|
||||||
|
|
||||||
|
panelData.add( panelDataTema, PANEL_TEMA );
|
||||||
|
panelData.add( panelDataRisco, PANEL_RISCO );
|
||||||
|
panelData.add( panelDataMedida, PANEL_MEDIDA );
|
||||||
|
|
||||||
|
add( panelButtons, new TableLayoutConstraints( 0, 0 ) );
|
||||||
|
add( panelTree, new TableLayoutConstraints( 1, 0 ) );
|
||||||
|
add( panelData, new TableLayoutConstraints( 2, 0 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void selectCard()
|
||||||
|
{
|
||||||
|
HsRiscoTema tema = getSelectedTema();
|
||||||
|
HsRisco risco = getSelectedRisco();
|
||||||
|
HsRiscoMedida medida = getSelectedMedida();
|
||||||
|
if( tema != null )
|
||||||
|
{
|
||||||
|
cardLayout.show( panelData, PANEL_TEMA );
|
||||||
|
}
|
||||||
|
else if( risco != null )
|
||||||
|
{
|
||||||
|
cardLayout.show( panelData, PANEL_RISCO );
|
||||||
|
}
|
||||||
|
else if( medida != null )
|
||||||
|
{
|
||||||
|
cardLayout.show( panelData, PANEL_MEDIDA );
|
||||||
|
fieldTextMedida.setText( medida.getToHsMedida().getDescription() );
|
||||||
|
fieldTextRequisitosLegais.setText( medida.getToHsMedida().getRequesitosLegais() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void refresh()
|
||||||
|
{
|
||||||
|
root.removeAllChildren();
|
||||||
|
TreeTools.merge( root, HigieneSegurancaLogic.getRiscosTree() );
|
||||||
|
TreeTools.refreshTree( tree, root );
|
||||||
|
setEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,120 +0,0 @@
|
|||||||
package siprp.higiene.gestao.riscos;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import javax.swing.tree.DefaultMutableTreeNode;
|
|
||||||
|
|
||||||
import leaf.ui.LeafLogic;
|
|
||||||
import siprp.database.cayenne.objects.BaseObject;
|
|
||||||
import siprp.database.cayenne.objects.HsMedida;
|
|
||||||
import siprp.database.cayenne.objects.HsRisco;
|
|
||||||
import siprp.database.cayenne.objects.HsRiscoMedida;
|
|
||||||
import siprp.database.cayenne.objects.HsRiscoTema;
|
|
||||||
import siprp.database.cayenne.providers.PlanoActuacaoDAO;
|
|
||||||
|
|
||||||
public class GestaoRiscosLogic extends LeafLogic
|
|
||||||
{
|
|
||||||
|
|
||||||
@Action(isSave = true)
|
|
||||||
public static final String ACTION_SAVE = "ACTION_SAVE";
|
|
||||||
|
|
||||||
@Action(isSave = true)
|
|
||||||
public static final String ACTION_REMOVE = "ACTION_SAVE";
|
|
||||||
|
|
||||||
@Action(isSave = false)
|
|
||||||
public static final String ACTION_LOAD = "ACTION_LOAD";
|
|
||||||
|
|
||||||
@Action(isSave = false)
|
|
||||||
public static final String ACTION_SELECTION = "ACTION_SELECTION";
|
|
||||||
|
|
||||||
@Action(isSave = true)
|
|
||||||
public static final String ACTION_TEMA_CRIAR = "ACTION_TEMA_CRIAR";
|
|
||||||
|
|
||||||
@Action(isSave = true)
|
|
||||||
public static final String ACTION_TEMA_REMOVER = "ACTION_TEMA_REMOVER";
|
|
||||||
|
|
||||||
@Action(isSave = true)
|
|
||||||
public static final String ACTION_RISCO_CRIAR = "ACTION_RISCO_CRIAR";
|
|
||||||
|
|
||||||
@Action(isSave = true)
|
|
||||||
public static final String ACTION_RISCO_REMOVER = "ACTION_RISCO_REMOVER";
|
|
||||||
|
|
||||||
@Action(isSave = true)
|
|
||||||
public static final String ACTION_MEDIDA_CRIAR = "ACTION_MEDIDA_CRIAR";
|
|
||||||
|
|
||||||
@Action(isSave = true)
|
|
||||||
public static final String ACTION_MEDIDA_REMOVER = "ACTION_MEDIDA_REMOVER";
|
|
||||||
|
|
||||||
@Action(isSave = false)
|
|
||||||
public static final String ACTION_CLEAR_SELECTION = "ACTION_CLEAR_SELECTION";
|
|
||||||
|
|
||||||
@Action(isSave = false)
|
|
||||||
public static final String ACTION_SELECT_TEMA = "ACTION_SELECT_TEMA";
|
|
||||||
|
|
||||||
@Action(isSave = false)
|
|
||||||
public static final String ACTION_SELECT_RISCO = "ACTION_SELECT_RISCO";
|
|
||||||
|
|
||||||
@Action(isSave = false)
|
|
||||||
public static final String ACTION_SELECT_MEDIDA = "ACTION_SELECT_MEDIDA";
|
|
||||||
|
|
||||||
public final PlanoActuacaoDAO provider = new PlanoActuacaoDAO();
|
|
||||||
|
|
||||||
@LeafLogicActionBinding(actions=ACTION_STARTUP)
|
|
||||||
public void load()
|
|
||||||
{
|
|
||||||
runAction( ACTION_LOAD, provider.getAllRiscoTemas() );
|
|
||||||
runActionLater( ACTION_REFRESH );
|
|
||||||
}
|
|
||||||
|
|
||||||
@LeafLogicActionBinding( actions = ACTION_TEMA_REMOVER )
|
|
||||||
public void removeTema( HsRiscoTema tema )
|
|
||||||
{
|
|
||||||
tema.setDeletedDate( new Date() );
|
|
||||||
provider.commit();
|
|
||||||
load();
|
|
||||||
}
|
|
||||||
|
|
||||||
@LeafLogicActionBinding( actions = ACTION_RISCO_REMOVER )
|
|
||||||
public void removeRisco( HsRisco risco )
|
|
||||||
{
|
|
||||||
risco.setDeletedDate( new Date() );
|
|
||||||
provider.commit();
|
|
||||||
load();
|
|
||||||
}
|
|
||||||
|
|
||||||
@LeafLogicActionBinding( actions = ACTION_MEDIDA_REMOVER )
|
|
||||||
public void removeMedida( HsRiscoMedida rel )
|
|
||||||
{
|
|
||||||
provider.deleteObject( rel );
|
|
||||||
load();
|
|
||||||
}
|
|
||||||
|
|
||||||
@LeafLogicActionBinding( actions = { ACTION_SAVE, ACTION_TEMA_CRIAR, ACTION_RISCO_CRIAR, ACTION_MEDIDA_CRIAR } )
|
|
||||||
public void saveObject( BaseObject object )
|
|
||||||
{
|
|
||||||
provider.saveObject( object );
|
|
||||||
load();
|
|
||||||
}
|
|
||||||
|
|
||||||
@LeafLogicActionBinding(actions=ACTION_SELECTION)
|
|
||||||
public void selectionChanged( DefaultMutableTreeNode object )
|
|
||||||
{
|
|
||||||
if( object == null )
|
|
||||||
{
|
|
||||||
runAction( ACTION_CLEAR_SELECTION );
|
|
||||||
}
|
|
||||||
else if( object instanceof NodeRiscoTema )
|
|
||||||
{
|
|
||||||
runAction( ACTION_SELECT_TEMA, object );
|
|
||||||
}
|
|
||||||
else if( object instanceof NodeRisco )
|
|
||||||
{
|
|
||||||
runAction( ACTION_SELECT_RISCO, object );
|
|
||||||
}
|
|
||||||
else if( object instanceof NodeMedida )
|
|
||||||
{
|
|
||||||
runAction( ACTION_SELECT_MEDIDA, object );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,494 +0,0 @@
|
|||||||
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.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;
|
|
||||||
|
|
||||||
import java.awt.CardLayout;
|
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.GridLayout;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.swing.BorderFactory;
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JScrollPane;
|
|
||||||
import javax.swing.JTextArea;
|
|
||||||
import javax.swing.JTree;
|
|
||||||
import javax.swing.tree.DefaultMutableTreeNode;
|
|
||||||
import javax.swing.tree.DefaultTreeModel;
|
|
||||||
import javax.swing.tree.TreePath;
|
|
||||||
import javax.swing.tree.TreeSelectionModel;
|
|
||||||
|
|
||||||
import leaf.data.OrderedMap;
|
|
||||||
import leaf.ui.LeafButton;
|
|
||||||
import leaf.ui.LeafInputField;
|
|
||||||
import leaf.ui.LeafWindow;
|
|
||||||
import leaf.ui.LeafLogic.LeafUIActionBinding;
|
|
||||||
import siprp.database.cayenne.objects.BaseObject;
|
|
||||||
import siprp.database.cayenne.objects.HsMedida;
|
|
||||||
import siprp.database.cayenne.objects.HsMedidaClassificacao;
|
|
||||||
import siprp.database.cayenne.objects.HsRisco;
|
|
||||||
import siprp.database.cayenne.objects.HsRiscoMedida;
|
|
||||||
import siprp.database.cayenne.objects.HsRiscoTema;
|
|
||||||
|
|
||||||
import com.evolute.utils.tracker.TrackableWindow;
|
|
||||||
|
|
||||||
public class GestaoRiscosWindow extends LeafWindow implements TrackableWindow
|
|
||||||
{
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public static final String TITLE = "Gest" + atilde + "o de Riscos";
|
|
||||||
|
|
||||||
private static final Dimension SIZE = new Dimension( 700, 500 );
|
|
||||||
|
|
||||||
private static final String PANEL_TEMA = "PANEL_TEMA";
|
|
||||||
|
|
||||||
private static final String PANEL_RISCO = "PANEL_RISCO";
|
|
||||||
|
|
||||||
private static final String PANEL_MEDIDA = "PANEL_MEDIDA";
|
|
||||||
|
|
||||||
private final JPanel panelButtons = new JPanel();
|
|
||||||
|
|
||||||
private final JPanel panelTree = new JPanel();
|
|
||||||
|
|
||||||
private final JPanel panelData = new JPanel();
|
|
||||||
|
|
||||||
private final JPanel panelDataTema = new JPanel();
|
|
||||||
|
|
||||||
private final JPanel panelDataRisco = new JPanel();
|
|
||||||
|
|
||||||
private final JPanel panelDataMedida = new JPanel();
|
|
||||||
|
|
||||||
@ActionActivation(onChange="",onSelect=ACTION_TEMA_CRIAR)
|
|
||||||
public final LeafButton buttonTemaCriar = new LeafButton( "Criar" );
|
|
||||||
|
|
||||||
@ActionActivation(onChange="",onSelect=ACTION_TEMA_REMOVER)
|
|
||||||
public final LeafButton buttonTemaRemover = new LeafButton( "Remover" );
|
|
||||||
|
|
||||||
@ActionActivation(onChange="",onSelect=ACTION_RISCO_CRIAR)
|
|
||||||
public final LeafButton buttonRiscoCriar = new LeafButton( "Criar" );
|
|
||||||
|
|
||||||
@ActionActivation(onChange="",onSelect=ACTION_RISCO_REMOVER)
|
|
||||||
public final LeafButton buttonRiscoRemover = new LeafButton( "Remover" );
|
|
||||||
|
|
||||||
@ActionActivation(onChange="",onSelect=ACTION_MEDIDA_CRIAR)
|
|
||||||
public final LeafButton buttonMedidaCriar = new LeafButton( "Criar" );
|
|
||||||
|
|
||||||
@ActionActivation(onChange="",onSelect=ACTION_MEDIDA_REMOVER)
|
|
||||||
public final LeafButton buttonMedidaRemover = new LeafButton( "Remover" );
|
|
||||||
|
|
||||||
public final LeafInputField<OrderedMap<HsMedidaClassificacao>> fieldMedidaClassificacao = new LeafInputField<OrderedMap<HsMedidaClassificacao>>();
|
|
||||||
|
|
||||||
public final JTextArea fieldTextMedida = new JTextArea();
|
|
||||||
|
|
||||||
public final JTextArea fieldTextRequisitosLegais = new JTextArea();
|
|
||||||
|
|
||||||
private final DefaultMutableTreeNode root = new DefaultMutableTreeNode();
|
|
||||||
|
|
||||||
private final DefaultTreeModel model = new DefaultTreeModel( root );
|
|
||||||
|
|
||||||
@ActionActivation(onChange="", onSelect=ACTION_SELECTION)
|
|
||||||
public final JTree tree = new JTree( model );
|
|
||||||
|
|
||||||
private final JScrollPane scroll = new JScrollPane( tree );
|
|
||||||
|
|
||||||
private final CardLayout cardLayout = new CardLayout();
|
|
||||||
|
|
||||||
private BaseObject selection = null;
|
|
||||||
|
|
||||||
public static void main( String[] args )
|
|
||||||
{
|
|
||||||
GestaoRiscosWindow window = new GestaoRiscosWindow();
|
|
||||||
window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
|
|
||||||
window.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
public GestaoRiscosWindow()
|
|
||||||
{
|
|
||||||
super( new GestaoRiscosLogic() );
|
|
||||||
this.setTitle( TITLE );
|
|
||||||
this.setSize( SIZE );
|
|
||||||
startupComponents();
|
|
||||||
startupLayout();
|
|
||||||
placeComponents();
|
|
||||||
completeSetup();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startupComponents()
|
|
||||||
{
|
|
||||||
panelButtons.setPreferredSize( new Dimension( 150, 0 ) );
|
|
||||||
panelTree.setPreferredSize( new Dimension( 300, 0 ) );
|
|
||||||
buttonMedidaCriar.setEnabled( false );
|
|
||||||
buttonMedidaRemover.setEnabled( false );
|
|
||||||
buttonRiscoCriar.setEnabled( false );
|
|
||||||
buttonRiscoRemover.setEnabled( false );
|
|
||||||
buttonTemaRemover.setEnabled( false );
|
|
||||||
tree.setRootVisible( false );
|
|
||||||
tree.getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION );
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startupLayout()
|
|
||||||
{
|
|
||||||
TableLayout layout = new TableLayout(
|
|
||||||
new double[]{ TableLayout.MINIMUM, TableLayout.PREFERRED, TableLayout.FILL },
|
|
||||||
new double[]{ TableLayout.FILL }
|
|
||||||
);
|
|
||||||
layout.setHGap( 5 );
|
|
||||||
layout.setVGap( 5 );
|
|
||||||
this.getContentPane().setLayout( layout );
|
|
||||||
|
|
||||||
layout = new TableLayout(
|
|
||||||
new double[]{ TableLayout.MINIMUM },
|
|
||||||
new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL }
|
|
||||||
);
|
|
||||||
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 );
|
|
||||||
|
|
||||||
layout = new TableLayout(
|
|
||||||
new double[]{ TableLayout.FILL },
|
|
||||||
new double[]{ TableLayout.FILL }
|
|
||||||
);
|
|
||||||
layout.setHGap( 5 );
|
|
||||||
layout.setVGap( 5 );
|
|
||||||
panelDataTema.setLayout( layout );
|
|
||||||
|
|
||||||
layout = new TableLayout(
|
|
||||||
new double[]{ TableLayout.FILL },
|
|
||||||
new double[]{ TableLayout.FILL }
|
|
||||||
);
|
|
||||||
layout.setHGap( 5 );
|
|
||||||
layout.setVGap( 5 );
|
|
||||||
panelDataRisco.setLayout( layout );
|
|
||||||
|
|
||||||
layout = new TableLayout(
|
|
||||||
new double[]{ TableLayout.FILL },
|
|
||||||
new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL, TableLayout.MINIMUM, TableLayout.FILL }
|
|
||||||
);
|
|
||||||
layout.setHGap( 5 );
|
|
||||||
layout.setVGap( 5 );
|
|
||||||
panelDataMedida.setLayout( layout );
|
|
||||||
|
|
||||||
panelData.setLayout( cardLayout );
|
|
||||||
}
|
|
||||||
|
|
||||||
private void placeComponents()
|
|
||||||
{
|
|
||||||
JPanel panel = new JPanel();
|
|
||||||
panel.setBorder( BorderFactory.createTitledBorder( "Tema" ) );
|
|
||||||
panel.setLayout( new GridLayout( 2, 1 ) );
|
|
||||||
panel.add( buttonTemaCriar );
|
|
||||||
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.add( buttonRiscoCriar );
|
|
||||||
panel.add( buttonRiscoRemover );
|
|
||||||
panelButtons.add( panel, new TableLayoutConstraints( 0, 1 ) );
|
|
||||||
panel = new JPanel();
|
|
||||||
panel.setBorder( BorderFactory.createTitledBorder( "Medida" ) );
|
|
||||||
panel.setLayout( new GridLayout( 2, 1 ) );
|
|
||||||
panel.add( buttonMedidaCriar );
|
|
||||||
panel.add( buttonMedidaRemover );
|
|
||||||
panelButtons.add( panel, new TableLayoutConstraints( 0, 2 ) );
|
|
||||||
|
|
||||||
panelTree.add( scroll, new TableLayoutConstraints( 0, 0 ) );
|
|
||||||
|
|
||||||
panelDataMedida.add( new JLabel("Classifica"+ccedil+atilde+"o"), new TableLayoutConstraints(0,0) );
|
|
||||||
panelDataMedida.add( fieldMedidaClassificacao, new TableLayoutConstraints(0,1) );
|
|
||||||
panelDataMedida.add( new JLabel("Medida"), new TableLayoutConstraints(0,2) );
|
|
||||||
panelDataMedida.add( fieldTextMedida, new TableLayoutConstraints(0,3) );
|
|
||||||
panelDataMedida.add( new JLabel("Requisitos legais"), new TableLayoutConstraints(0,4) );
|
|
||||||
panelDataMedida.add( fieldTextRequisitosLegais, new TableLayoutConstraints(0,5) );
|
|
||||||
|
|
||||||
panelData.add( panelDataTema, PANEL_TEMA );
|
|
||||||
panelData.add( panelDataRisco, PANEL_RISCO );
|
|
||||||
panelData.add( panelDataMedida, PANEL_MEDIDA );
|
|
||||||
|
|
||||||
this.getContentPane().add( panelButtons, new TableLayoutConstraints( 0, 0 ) );
|
|
||||||
this.getContentPane().add( panelTree, new TableLayoutConstraints( 1, 0 ) );
|
|
||||||
this.getContentPane().add( panelData, new TableLayoutConstraints( 2, 0 ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@LeafUIActionBinding(action=ACTION_LOAD)
|
|
||||||
public void load( List<HsRiscoTema> temas )
|
|
||||||
{
|
|
||||||
root.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 );
|
|
||||||
}
|
|
||||||
root.add( temaNode );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@LeafUIActionBinding(action=ACTION_REFRESH)
|
|
||||||
public void refresh()
|
|
||||||
{
|
|
||||||
((DefaultTreeModel) tree.getModel()).nodeStructureChanged( root );
|
|
||||||
for( int i = 0; i < tree.getRowCount(); ++i)
|
|
||||||
{
|
|
||||||
tree.expandPath( tree.getPathForRow( i ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@LeafUIActionBinding(action=ACTION_TEMA_CRIAR)
|
|
||||||
public HsRiscoTema createTema()
|
|
||||||
{
|
|
||||||
HsRiscoTema tema = null;
|
|
||||||
String nome = JOptionPane.showInputDialog( "Criar tema" );
|
|
||||||
if( nome != null )
|
|
||||||
{
|
|
||||||
if( nome.trim().length() > 0 )
|
|
||||||
{
|
|
||||||
tema = new HsRiscoTema();
|
|
||||||
tema.setDescription( nome.trim() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
JOptionPane.showMessageDialog( this, "Tema inv" + aacute + "lido" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tema;
|
|
||||||
}
|
|
||||||
|
|
||||||
@LeafUIActionBinding(action=ACTION_MEDIDA_CRIAR)
|
|
||||||
public HsRiscoMedida createMedida()
|
|
||||||
{
|
|
||||||
HsRiscoMedida rel = null;
|
|
||||||
HsRisco risco = getSelectedRisco();
|
|
||||||
if( risco != null )
|
|
||||||
{
|
|
||||||
HsMedida medida = new HsMedida();
|
|
||||||
medida.setDescription( " " );
|
|
||||||
medida.setRequesitosLegais( " " );
|
|
||||||
runAction( ACTION_SAVE, medida );
|
|
||||||
rel = new HsRiscoMedida();
|
|
||||||
rel.setToHsMedida( medida );
|
|
||||||
rel.setToHsRisco( risco );
|
|
||||||
}
|
|
||||||
return rel;
|
|
||||||
}
|
|
||||||
|
|
||||||
private HsRiscoTema getSelectedTema()
|
|
||||||
{
|
|
||||||
HsRiscoTema result = null;
|
|
||||||
if( selection != null )
|
|
||||||
{
|
|
||||||
if( selection instanceof HsRiscoTema )
|
|
||||||
{
|
|
||||||
result = ( (HsRiscoTema) selection );
|
|
||||||
}
|
|
||||||
else if( selection instanceof HsRisco )
|
|
||||||
{
|
|
||||||
result = ( (HsRisco) selection ).getToHsRiscoTema();
|
|
||||||
}
|
|
||||||
else if( selection instanceof HsMedida )
|
|
||||||
{
|
|
||||||
result = ( (HsRiscoMedida) selection ).getToHsRisco().getToHsRiscoTema();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private HsRisco getSelectedRisco()
|
|
||||||
{
|
|
||||||
HsRisco result = null;
|
|
||||||
if( selection != null )
|
|
||||||
{
|
|
||||||
if( selection instanceof HsRisco )
|
|
||||||
{
|
|
||||||
result = (HsRisco) selection;
|
|
||||||
}
|
|
||||||
else if( selection instanceof HsRiscoMedida )
|
|
||||||
{
|
|
||||||
result = ( (HsRiscoMedida) selection ).getToHsRisco();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@LeafUIActionBinding(action=ACTION_RISCO_CRIAR)
|
|
||||||
public HsRisco createRisco()
|
|
||||||
{
|
|
||||||
HsRisco risco = null;
|
|
||||||
HsRiscoTema tema = getSelectedTema();
|
|
||||||
if( tema != null )
|
|
||||||
{
|
|
||||||
String nome = JOptionPane.showInputDialog( "Criar risco" );
|
|
||||||
if( nome != null )
|
|
||||||
{
|
|
||||||
|
|
||||||
if( nome.trim().length() > 0 && tema != null )
|
|
||||||
{
|
|
||||||
risco = new HsRisco();
|
|
||||||
risco.setDescription( nome.trim() );
|
|
||||||
risco.setToHsRiscoTema( tema );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
JOptionPane.showMessageDialog( this, "Nome inv" + aacute + "lido" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return risco;
|
|
||||||
}
|
|
||||||
|
|
||||||
@LeafUIActionBinding(action=ACTION_TEMA_REMOVER)
|
|
||||||
public HsRiscoTema removerTema()
|
|
||||||
{
|
|
||||||
HsRiscoTema tema = null;
|
|
||||||
if( selection != null )
|
|
||||||
{
|
|
||||||
if( selection instanceof HsRiscoTema )
|
|
||||||
{
|
|
||||||
tema = (HsRiscoTema) selection;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tema;
|
|
||||||
}
|
|
||||||
|
|
||||||
@LeafUIActionBinding(action=ACTION_RISCO_REMOVER)
|
|
||||||
public HsRisco removerRisco()
|
|
||||||
{
|
|
||||||
HsRisco risco = null;
|
|
||||||
if( selection != null )
|
|
||||||
{
|
|
||||||
if( selection instanceof HsRisco )
|
|
||||||
{
|
|
||||||
risco = (HsRisco) selection;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return risco;
|
|
||||||
}
|
|
||||||
|
|
||||||
@LeafUIActionBinding(action=ACTION_MEDIDA_REMOVER)
|
|
||||||
public HsRiscoMedida removerMedida()
|
|
||||||
{
|
|
||||||
HsRiscoMedida medida = null;
|
|
||||||
if( selection != null )
|
|
||||||
{
|
|
||||||
if( selection instanceof HsRiscoMedida )
|
|
||||||
{
|
|
||||||
medida = (HsRiscoMedida) selection;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return medida;
|
|
||||||
}
|
|
||||||
|
|
||||||
@LeafUIActionBinding(action=ACTION_SELECTION)
|
|
||||||
public BaseObject selectionChanged()
|
|
||||||
{
|
|
||||||
BaseObject result = null;
|
|
||||||
TreePath selection = tree.getSelectionPath();
|
|
||||||
if( selection != null )
|
|
||||||
{
|
|
||||||
DefaultMutableTreeNode node = (DefaultMutableTreeNode) selection.getLastPathComponent();
|
|
||||||
result = (BaseObject) node.getUserObject();
|
|
||||||
}
|
|
||||||
this.selection = result;
|
|
||||||
updateCardLayout();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateCardLayout()
|
|
||||||
{
|
|
||||||
if( selection != null )
|
|
||||||
{
|
|
||||||
if( selection instanceof HsRiscoTema )
|
|
||||||
{
|
|
||||||
cardLayout.show( panelData, PANEL_TEMA );
|
|
||||||
}
|
|
||||||
else if( selection instanceof HsRisco )
|
|
||||||
{
|
|
||||||
cardLayout.show( panelData, PANEL_RISCO );
|
|
||||||
}
|
|
||||||
else if( selection instanceof HsRiscoMedida )
|
|
||||||
{
|
|
||||||
cardLayout.show( panelData, PANEL_MEDIDA );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@LeafUIActionBinding(action=ACTION_CLEAR_SELECTION)
|
|
||||||
public void clear()
|
|
||||||
{
|
|
||||||
buttonMedidaCriar.setEnabled( false );
|
|
||||||
buttonMedidaRemover.setEnabled( false );
|
|
||||||
buttonRiscoCriar.setEnabled( false );
|
|
||||||
buttonRiscoRemover.setEnabled( false );
|
|
||||||
buttonTemaCriar.setEnabled( true );
|
|
||||||
buttonTemaRemover.setEnabled( false );
|
|
||||||
}
|
|
||||||
|
|
||||||
@LeafUIActionBinding(action=ACTION_SELECT_TEMA)
|
|
||||||
public void selectTema()
|
|
||||||
{
|
|
||||||
buttonMedidaCriar.setEnabled( false );
|
|
||||||
buttonMedidaRemover.setEnabled( false );
|
|
||||||
buttonRiscoCriar.setEnabled( true );
|
|
||||||
buttonRiscoRemover.setEnabled( false );
|
|
||||||
buttonTemaCriar.setEnabled( true );
|
|
||||||
buttonTemaRemover.setEnabled( true );
|
|
||||||
}
|
|
||||||
|
|
||||||
@LeafUIActionBinding(action=ACTION_SELECT_RISCO)
|
|
||||||
public void selectRisco()
|
|
||||||
{
|
|
||||||
buttonMedidaCriar.setEnabled( true );
|
|
||||||
buttonMedidaRemover.setEnabled( false );
|
|
||||||
buttonRiscoCriar.setEnabled( false );
|
|
||||||
buttonRiscoRemover.setEnabled( true );
|
|
||||||
buttonTemaCriar.setEnabled( true );
|
|
||||||
buttonTemaRemover.setEnabled( false );
|
|
||||||
}
|
|
||||||
|
|
||||||
@LeafUIActionBinding(action=ACTION_SELECT_MEDIDA)
|
|
||||||
public void selectMedida()
|
|
||||||
{
|
|
||||||
buttonMedidaCriar.setEnabled( false );
|
|
||||||
buttonMedidaRemover.setEnabled( true );
|
|
||||||
buttonRiscoCriar.setEnabled( false );
|
|
||||||
buttonRiscoRemover.setEnabled( false );
|
|
||||||
buttonTemaCriar.setEnabled( true );
|
|
||||||
buttonTemaRemover.setEnabled( false );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
After Width: | Height: | Size: 936 B |
|
After Width: | Height: | Size: 876 B |
|
After Width: | Height: | Size: 2.2 KiB |
Loading…
Reference in new issue