git-svn-id: https://svn.coded.pt/svn/SIPRP@802 bb69d46d-e84e-40c8-a05a-06db0d633741

lxbfYeaa
Tiago Simão 17 years ago
parent 7a985cc91a
commit a407b0920b

@ -30,7 +30,7 @@
<classpathentry kind="lib" path="common/lib/log4j-1.2.8.jar"/>
<classpathentry kind="lib" path="common/lib/mail.jar"/>
<classpathentry kind="lib" path="common/lib/TableLayout.jar"/>
<classpathentry kind="lib" path="common/lib/cayenne-server-3.0M2.jar"/>
<classpathentry kind="lib" path="common/lib/cayenne-server-3.0M2.jar" sourcepath="/home/tsimao/Desktop/cayenne-3.0M4/src"/>
<classpathentry kind="lib" path="common/lib/commons-collections-3.1.jar"/>
<classpathentry kind="lib" path="common/lib/commons-lang-2.1.jar"/>
<classpathentry kind="lib" path="common/lib/commons-logging-1.1.jar"/>

@ -14,7 +14,8 @@ import siprp.clientes.AvisosPanel;
import siprp.clientes.ClientesWindow;
import siprp.estatistica.EstatisticaWindow;
import siprp.ficha.FichaWindow;
import siprp.higiene.gestao.riscos.GestaoRiscosWindow;
import siprp.higiene.gestao.GestaoRelatorioWindow;
import siprp.higiene.gestao.riscos.GerirRiscosPanel;
import siprp.higiene.legislacoes.GestaoLegislacoesWindow;
import siprp.higiene.mapa.MapaHigieneWindow;
import siprp.higiene.marcacoes.MarcacoesHigieneWindow;
@ -255,12 +256,12 @@ public class SIPRPTracker extends WindowTracker
return new GestaoLegislacoesWindow();
}
} );
higieneNode.add( new DefaultMutableTreeNode( GestaoRiscosWindow.TITLE) );
creators.put( GestaoRiscosWindow.TITLE, new WindowCreator() {
higieneNode.add( new DefaultMutableTreeNode( GestaoRelatorioWindow.TITLE ) );
creators.put( GestaoRelatorioWindow.TITLE, new WindowCreator() {
public TrackableWindow create()
throws Exception
{
return new GestaoRiscosWindow();
return new GestaoRelatorioWindow();
}
} );
rootNode.add( higieneNode );

@ -30,10 +30,11 @@ public class EmpresaPanel extends JPanel
public EmpresaPanel()
{
startupListeners();
startupComponents();
setupLayout();
placeComponents();
startupListeners();
}
private void startupComponents()
@ -45,10 +46,6 @@ public class EmpresaPanel extends JPanel
{
comboEmpresa.addItem( empresa );
}
if( comboEmpresa.getItemCount() > 0 )
{
comboEmpresa.setSelectedIndex( 0 );
}
}
tabs.addTab( "Empresa", panelEmpresa );
tabs.addTab( "Estabelecimentos", panelEstabelecimentos );
@ -90,12 +87,7 @@ public class EmpresaPanel extends JPanel
panelEstabelecimentos.setEmpresa( (Empresas) item );
}
}
else if( ItemEvent.DESELECTED == e.getStateChange() )
{
panelEmpresa.setEmpresa( null );
panelEstabelecimentos.setEmpresa( null );
}
}
}
});
}

@ -8,6 +8,8 @@ import info.clearthought.layout.TableLayoutConstraints;
import java.awt.Dimension;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.BorderFactory;
import javax.swing.JComboBox;
@ -15,6 +17,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.postos.AdicionarAreasPanel;
import siprp.higiene.gestao.riscos.AdicionarRiscosPanel;
@ -82,6 +85,22 @@ public class GerirEstabelecimentosPanel extends JPanel
}
}
} );
panelAreas.addPropertyChangeListener( AdicionarAreasPanel.SELECTION_CHANGED, new PropertyChangeListener()
{
@Override
public void propertyChange( PropertyChangeEvent evt )
{
Object obj = evt.getNewValue();
if( obj != null && (obj instanceof HsPosto) )
{
panelRiscos.setPosto( (HsPosto) obj );
}
else
{
panelRiscos.setPosto( null );
}
}
} );
}
public void setEmpresa( Empresas empresa )

@ -36,6 +36,7 @@ public class GestaoRelatorioWindow extends JFrame implements TrackableWindow
{
this.setTitle( TITLE );
this.setSize( SIZE );
this.setLocationRelativeTo( null );
placeComponents();
}

@ -1,11 +1,15 @@
package siprp.higiene.gestao;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
public class GlobalPanel extends JPanel
import siprp.higiene.gestao.riscos.GerirRiscosPanel;
public class GlobalPanel extends JTabbedPane
{
private static final long serialVersionUID = 1L;
private final GerirRiscosPanel panelRiscos = new GerirRiscosPanel();
public GlobalPanel()
{
@ -17,7 +21,7 @@ public class GlobalPanel extends JPanel
private void startupComponents()
{
addTab( "Riscos", panelRiscos );
}
private void setupLayout()

@ -3,23 +3,33 @@ package siprp.higiene.gestao.postos;
import info.clearthought.layout.TableLayout;
import info.clearthought.layout.TableLayoutConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
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.TreeInserterDialog;
import leaf.ui.TreeTools;
import siprp.database.cayenne.objects.Estabelecimentos;
import siprp.database.cayenne.objects.HsArea;
import siprp.database.cayenne.objects.HsPosto;
import siprp.database.cayenne.objects.HsPostoEstabelecimento;
import siprp.logic.HigieneSegurancaLogic;
public class AdicionarAreasPanel extends JPanel
{
private static final long serialVersionUID = 1L;
public static final String SELECTION_CHANGED = "SELECTION_CHANGED";
private final LeafButton buttonAdicionar = new LeafButton("Adicionar");
@ -81,62 +91,118 @@ public class AdicionarAreasPanel extends JPanel
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();
HsPosto posto = object == null ? null : ( (object instanceof PostoNode) ? (HsPosto) ((PostoNode) object).getUserObject() : null);
firePropertyChange( SELECTION_CHANGED, null, posto );
}
} );
buttonAdicionar.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
add();
}
} );
buttonRemover.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
rem();
}
} );
}
private void setEnabled()
private void add()
{
buttonAdicionar.setEnabled( estabelecimento != null );
buttonRemover.setEnabled( tree.getSelectionCount() > 0 );
DefaultMutableTreeNode allPostos = HigieneSegurancaLogic.getAreasTree( estabelecimento.getToEmpresas() );
TreeTools.removeAll( allPostos, HigieneSegurancaLogic.getPostosTree( estabelecimento ) );
TreeInserterDialog dialog = new TreeInserterDialog("Adicionar Postos de Trabalho", allPostos );
save( dialog.getResult() );
refresh();
}
public void refresh()
private void save( DefaultMutableTreeNode toadd )
{
root.removeAllChildren();
if( estabelecimento != null )
Object obj = toadd.getUserObject();
if( obj instanceof HsPosto )
{
for( HsPostoEstabelecimento rel : estabelecimento.getHsPostoEstabelecimentoArray() )
{
addPosto( rel.getToHsPosto() );
}
HsPostoEstabelecimento rel = new HsPostoEstabelecimento();
rel.setToEstabelecimentos( estabelecimento );
rel.setToHsPosto( (HsPosto) obj );
rel.save();
}
setEnabled();
((DefaultTreeModel) tree.getModel()).nodeStructureChanged( root );
for( int i = 0; i < tree.getRowCount(); ++i)
else
{
tree.expandPath( tree.getPathForRow( i ) );
for( int i = 0; i < toadd.getChildCount(); ++i )
{
save( (DefaultMutableTreeNode) toadd.getChildAt( i ) );
}
}
}
private void addPosto( HsPosto posto )
private void rem()
{
if( posto != null )
TreePath path = tree.getSelectionPath();
if( path != null )
{
HsArea area = posto.getToHsArea();
AreaNode areaNode = getAreaNodeWith( area );
if( areaNode == null )
Object object = path.getLastPathComponent();
if( object instanceof PostoNode )
{
HsPosto posto = ((HsPosto)((PostoNode) object).getUserObject());
remPosto( posto );
}
else if( object instanceof AreaNode )
{
areaNode = new AreaNode( area );
root.add( areaNode );
for( int i = 0; i < ((AreaNode)object).getChildCount(); ++i )
{
PostoNode postoNode = (PostoNode) ((AreaNode)object).getChildAt( i );
remPosto( (HsPosto) postoNode.getUserObject() );
}
}
areaNode.add( new PostoNode( posto ) );
}
refresh();
}
private AreaNode getAreaNodeWith( HsArea area )
private void remPosto( HsPosto posto )
{
AreaNode result = null;
if( area != null )
HsPostoEstabelecimento toDelete = null;
for( HsPostoEstabelecimento rel : posto.getHsPostoEstabelecimentoArray() )
{
for( int i = 0; i < root.getChildCount(); ++i )
if( rel.getToEstabelecimentos().equals( estabelecimento ) )
{
if( area.equals( ( (AreaNode) root.getChildAt( i )).getUserObject() ) )
{
result = (AreaNode) root.getChildAt( i );
}
toDelete = rel;
break;
}
}
return result;
if( toDelete != null )
{
toDelete.delete();
}
}
private void setEnabled()
{
buttonAdicionar.setEnabled( estabelecimento != null );
buttonRemover.setEnabled( tree.getSelectionCount() > 0 );
}
public void refresh()
{
root.removeAllChildren();
if( estabelecimento != null )
{
TreeTools.merge( root, HigieneSegurancaLogic.getAreasTree( estabelecimento ) );
}
setEnabled();
TreeTools.refreshTree( tree, root );
}

@ -5,7 +5,6 @@ import info.clearthought.layout.TableLayoutConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
@ -18,18 +17,15 @@ import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;
import leaf.ui.LeafButton;
import leaf.ui.TreeInserterDialog;
import leaf.ui.TreeTools;
import siprp.database.cayenne.objects.BaseObject;
import siprp.database.cayenne.objects.Empresas;
import siprp.database.cayenne.objects.HsMedida;
import siprp.database.cayenne.objects.HsPosto;
import siprp.database.cayenne.objects.HsPostoRisco;
import siprp.database.cayenne.objects.HsRisco;
import siprp.database.cayenne.objects.HsRiscoEmpresa;
import siprp.database.cayenne.objects.HsRiscoMedida;
import siprp.database.cayenne.objects.HsRiscoTema;
import siprp.database.cayenne.providers.PlanoActuacaoDAO;
import siprp.higiene.gestao.TreeInserterDialog;
import siprp.logic.HigieneSegurancaLogic;
public class AdicionarRiscosPanel extends JPanel
{
@ -125,34 +121,53 @@ public class AdicionarRiscosPanel extends JPanel
private void add()
{
List<HsRiscoTema> temas = new PlanoActuacaoDAO().getAllRiscoTemas();
if( temas != null )
DefaultMutableTreeNode allRiscos = getAllRiscos();
TreeTools.removeAll( allRiscos, getRiscosTree( ) );
TreeInserterDialog dialog = new TreeInserterDialog( "Adicionar Riscos", allRiscos );
DefaultMutableTreeNode result = dialog.getResult();
if( result != null )
{
DefaultMutableTreeNode allRiscos = new DefaultMutableTreeNode();
allRiscos.removeAllChildren();
for( HsRiscoTema tema : temas )
addResult(result);
refresh();
}
setEnabled();
}
private DefaultMutableTreeNode getAllRiscos()
{
DefaultMutableTreeNode result = new DefaultMutableTreeNode();
if( posto == null )
{
result = HigieneSegurancaLogic.getRiscosTree();
}
else
{
result = HigieneSegurancaLogic.getRiscosTree( posto.getToHsArea().getToEmpresas() );
}
return result;
}
private DefaultMutableTreeNode getRiscosTree()
{
DefaultMutableTreeNode result = new DefaultMutableTreeNode();
for( int i = 0; i < root.getChildCount(); ++i )
{
DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) root.getChildAt( i );
BaseObject userObject = (BaseObject) childNode.getUserObject();
HsRisco risco = null;
if( userObject instanceof HsRiscoEmpresa )
{
NodeRiscoTema temaNode = new NodeRiscoTema( tema );
for( HsRisco risco : tema.getHsRiscoArray() )
{
NodeRisco riscoNode = new NodeRisco( risco );
for( HsRiscoMedida rel : risco.getHsRiscoMedidaArray() )
{
riscoNode.add( new NodeMedida( rel ) );
}
temaNode.add( riscoNode );
}
allRiscos.add( temaNode );
risco = ((HsRiscoEmpresa) userObject).getToHsRisco();
}
TreeInserterDialog dialog = new TreeInserterDialog("Adicionar Riscos",allRiscos);
DefaultMutableTreeNode result = dialog.getResult();
if( result != null )
else if( userObject instanceof HsPostoRisco )
{
addResult(result);
refresh();
risco = ((HsPostoRisco) userObject).getToHsRisco();
}
if( risco != null )
{
result.add( new NodeRisco( risco ) );
}
}
setEnabled();
return result;
}
private void addResult( DefaultMutableTreeNode root )

@ -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 );
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 936 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 876 B

@ -6,17 +6,27 @@ import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.ImageIcon;
import javax.swing.JButton;
public class LeafButton extends JButton
{
private static final long serialVersionUID = 1L;
private ImageIcon icon = null;
public LeafButton(String text)
{
super( text );
setOpaque( false );
}
public LeafButton( ImageIcon icon )
{
super( icon );
this.icon = icon;
setOpaque( false );
}
protected void paintComponent( Graphics g )
{
@ -57,6 +67,9 @@ public class LeafButton extends JButton
y -= 1;
g2.setColor( textColor );
g2.drawString( getText(), x, y );
// super.paintComponent( g );
if( icon != null )
{
super.paintComponent( g );
}
}
}

@ -1,9 +1,10 @@
package siprp.higiene.gestao;
package leaf.ui;
import info.clearthought.layout.TableLayout;
import info.clearthought.layout.TableLayoutConstraints;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@ -18,8 +19,9 @@ import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;
import leaf.ui.LeafButton;
import leaf.ui.TreeTools;
import com.evolute.utils.images.ImageException;
import com.evolute.utils.images.ImageIconLoader;
public class TreeInserterDialog extends JDialog
@ -31,6 +33,10 @@ public class TreeInserterDialog extends JDialog
private static final Dimension newDimension = new Dimension(300,400);
private static final String ICON_NAME_ADD = "leaf/ui/icons/add.png";
private static final String ICON_NAME_REM = "leaf/ui/icons/rem.png";
private final DefaultMutableTreeNode newRoot = new DefaultMutableTreeNode();
private final DefaultTreeModel newModel = new DefaultTreeModel( newRoot );
@ -47,9 +53,9 @@ public class TreeInserterDialog extends JDialog
private final JScrollPane allScroll;
private final LeafButton buttonAdd = new LeafButton( "->" );
private LeafButton buttonAdd = null;
private final LeafButton buttonRemove = new LeafButton( "<-" );
private LeafButton buttonRemove = null;
private final LeafButton buttonOK = new LeafButton( "OK" );
@ -62,6 +68,14 @@ public class TreeInserterDialog extends JDialog
this.allTree = new JTree(allModel);
this.allScroll = new JScrollPane( allTree );
this.setTitle( title );
try
{
buttonAdd = new LeafButton( ImageIconLoader.loadImageIcon( ICON_NAME_ADD ) );
buttonRemove = new LeafButton( ImageIconLoader.loadImageIcon( ICON_NAME_REM ) );
} catch( ImageException e )
{
e.printStackTrace();
}
startupComponents();
setupLayout();
placeComponents();
@ -86,6 +100,10 @@ public class TreeInserterDialog extends JDialog
newScroll.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
allScroll.setPreferredSize( allDimension );
newScroll.setPreferredSize( newDimension );
buttonAdd.setToolTipText( "Adicionar" );
buttonRemove.setToolTipText( "Remover" );
buttonAdd.setMargin( new Insets(4,4,4,4) );
buttonRemove.setMargin( new Insets(4,4,4,4) );
}
private void setupLayout()
@ -181,7 +199,7 @@ public class TreeInserterDialog extends JDialog
}
else
{
merge( exists, node );
TreeTools.merge( exists, node );
}
}
}
@ -191,23 +209,6 @@ public class TreeInserterDialog extends JDialog
TreeTools.refreshTree( to, toRoot );
}
private void merge( DefaultMutableTreeNode with, DefaultMutableTreeNode what )
{
for( int i = 0; i < what.getChildCount(); ++i )
{
DefaultMutableTreeNode child = (DefaultMutableTreeNode) what.getChildAt( i );
DefaultMutableTreeNode exists = TreeTools.findNodeWithUserObject( child.getUserObject(), with );
if( exists == null )
{
with.add( TreeTools.cloneFullNode( child ) );
}
else
{
merge( exists, child );
}
}
}
private void removeNode( DefaultMutableTreeNode node, DefaultMutableTreeNode root )
{
DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();

@ -7,7 +7,6 @@ import javax.swing.tree.DefaultTreeModel;
public class TreeTools
{
public static void refreshTree( JTree tree, DefaultMutableTreeNode node )
{
((DefaultTreeModel) tree.getModel()).nodeStructureChanged( node );
@ -17,7 +16,6 @@ public class TreeTools
}
}
public static boolean userObjectExistsOn( Object object, DefaultMutableTreeNode on )
{
boolean result = false;
@ -32,7 +30,6 @@ public class TreeTools
return result;
}
public static DefaultMutableTreeNode findNodeWithUserObject( Object object, DefaultMutableTreeNode on )
{
DefaultMutableTreeNode result = null;
@ -47,7 +44,6 @@ public class TreeTools
return result;
}
public static DefaultMutableTreeNode cloneFullNode( DefaultMutableTreeNode node )
{
DefaultMutableTreeNode result = (DefaultMutableTreeNode) node.clone();
@ -59,4 +55,35 @@ public class TreeTools
return result;
}
public static void merge( DefaultMutableTreeNode with, DefaultMutableTreeNode what )
{
for( int i = 0; i < what.getChildCount(); ++i )
{
DefaultMutableTreeNode child = (DefaultMutableTreeNode) what.getChildAt( i );
DefaultMutableTreeNode exists = TreeTools.findNodeWithUserObject( child.getUserObject(), with );
if( exists == null )
{
with.add( TreeTools.cloneFullNode( child ) );
}
else
{
merge( exists, child );
}
}
}
public static void removeAll( DefaultMutableTreeNode from, DefaultMutableTreeNode what )
{
for( int i = 0; i < what.getChildCount(); ++i )
{
DefaultMutableTreeNode child = (DefaultMutableTreeNode) what.getChildAt( i );
removeAll( from, child );
}
DefaultMutableTreeNode exists = TreeTools.findNodeWithUserObject( what.getUserObject(), from );
if( exists != null )
{
exists.removeFromParent();
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Loading…
Cancel
Save