|
|
|
|
@ -5,7 +5,11 @@ import info.clearthought.layout.TableLayoutConstraints;
|
|
|
|
|
|
|
|
|
|
import java.awt.Color;
|
|
|
|
|
import java.awt.Component;
|
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
|
import java.awt.event.ActionListener;
|
|
|
|
|
|
|
|
|
|
import javax.swing.JButton;
|
|
|
|
|
import javax.swing.JOptionPane;
|
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
|
import javax.swing.JScrollPane;
|
|
|
|
|
import javax.swing.JTree;
|
|
|
|
|
@ -19,11 +23,14 @@ import javax.swing.tree.TreeSelectionModel;
|
|
|
|
|
|
|
|
|
|
import leaf.ui.LeafTree;
|
|
|
|
|
import siprp.database.cayenne.objects.HsRelatorio;
|
|
|
|
|
import siprp.database.cayenne.objects.HsRelatorioArea;
|
|
|
|
|
import siprp.database.cayenne.objects.HsRelatorioPosto;
|
|
|
|
|
import siprp.database.cayenne.objects.HsRelatorioPostoRisco;
|
|
|
|
|
import siprp.logic.HigieneSegurancaLogic;
|
|
|
|
|
import siprp.logic.node.PostoRelatorioNode;
|
|
|
|
|
|
|
|
|
|
import com.evolute.utils.error.ErrorLogger;
|
|
|
|
|
import com.evolute.utils.images.ImageIconLoader;
|
|
|
|
|
import com.evolute.utils.ui.trees.TreeTools;
|
|
|
|
|
|
|
|
|
|
public class VerAreasRelatorioPanel extends JPanel
|
|
|
|
|
@ -33,6 +40,8 @@ public class VerAreasRelatorioPanel extends JPanel
|
|
|
|
|
|
|
|
|
|
public static final String SELECTION_CHANGED = "SELECTION_CHANGED";
|
|
|
|
|
|
|
|
|
|
private final JButton buttonEdit = new JButton( "Editar Nome", ImageIconLoader.loadImageIconSilent( "siprp/higiene/relatorio/edit.png" ) );
|
|
|
|
|
|
|
|
|
|
private final DefaultMutableTreeNode root = new DefaultMutableTreeNode();
|
|
|
|
|
|
|
|
|
|
private final DefaultTreeModel model = new DefaultTreeModel( root );
|
|
|
|
|
@ -43,6 +52,8 @@ public class VerAreasRelatorioPanel extends JPanel
|
|
|
|
|
|
|
|
|
|
private HsRelatorio relatorio = null;
|
|
|
|
|
|
|
|
|
|
private DefaultMutableTreeNode selectedNode = null;
|
|
|
|
|
|
|
|
|
|
public VerAreasRelatorioPanel()
|
|
|
|
|
{
|
|
|
|
|
startupComponents();
|
|
|
|
|
@ -53,6 +64,7 @@ public class VerAreasRelatorioPanel extends JPanel
|
|
|
|
|
|
|
|
|
|
private void startupComponents()
|
|
|
|
|
{
|
|
|
|
|
buttonEdit.setEnabled( false );
|
|
|
|
|
tree.setRootVisible( false );
|
|
|
|
|
tree.getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION );
|
|
|
|
|
tree.setCellRenderer(new DefaultTreeCellRenderer()
|
|
|
|
|
@ -60,9 +72,10 @@ public class VerAreasRelatorioPanel extends JPanel
|
|
|
|
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
|
|
|
|
public Component getTreeCellRendererComponent(JTree pTree, Object pValue, boolean pIsSelected, boolean pIsExpanded, boolean pIsLeaf, int pRow, boolean pHasFocus)
|
|
|
|
|
@Override
|
|
|
|
|
public Component getTreeCellRendererComponent( JTree pTree, Object pValue, boolean pIsSelected, boolean pIsExpanded, boolean pIsLeaf, int pRow, boolean pHasFocus )
|
|
|
|
|
{
|
|
|
|
|
super.getTreeCellRendererComponent(pTree, pValue, pIsSelected, pIsExpanded, pIsLeaf, pRow, pHasFocus);
|
|
|
|
|
super.getTreeCellRendererComponent( pTree, pValue, pIsSelected, pIsExpanded, pIsLeaf, pRow, pHasFocus );
|
|
|
|
|
boolean highlight= false;
|
|
|
|
|
Color highColor = null;
|
|
|
|
|
Color lowColor = null;
|
|
|
|
|
@ -94,12 +107,13 @@ public class VerAreasRelatorioPanel extends JPanel
|
|
|
|
|
return(this);
|
|
|
|
|
}
|
|
|
|
|
} );
|
|
|
|
|
TreeTools.registerTreeKeepExpandState( tree );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setupLayout()
|
|
|
|
|
{
|
|
|
|
|
TableLayout layout = new TableLayout(
|
|
|
|
|
new double[]{ TableLayout.FILL },
|
|
|
|
|
new double[]{ TableLayout.MINIMUM, TableLayout.FILL },
|
|
|
|
|
new double[]{ TableLayout.MINIMUM, TableLayout.FILL }
|
|
|
|
|
);
|
|
|
|
|
layout.setHGap( 5 );
|
|
|
|
|
@ -109,21 +123,13 @@ public class VerAreasRelatorioPanel extends JPanel
|
|
|
|
|
|
|
|
|
|
private void placeComponents()
|
|
|
|
|
{
|
|
|
|
|
JPanel panel = new JPanel();
|
|
|
|
|
TableLayout layout = new TableLayout(
|
|
|
|
|
new double[]{ TableLayout.MINIMUM, TableLayout.FILL, TableLayout.MINIMUM },
|
|
|
|
|
new double[]{ TableLayout.MINIMUM }
|
|
|
|
|
);
|
|
|
|
|
layout.setHGap( 5 );
|
|
|
|
|
layout.setVGap( 5 );
|
|
|
|
|
panel.setLayout( layout );
|
|
|
|
|
|
|
|
|
|
add( panel, new TableLayoutConstraints( 0, 0 ) );
|
|
|
|
|
add( scroll, new TableLayoutConstraints( 0, 1 ) );
|
|
|
|
|
add( buttonEdit, new TableLayoutConstraints( 0, 0 ) );
|
|
|
|
|
add( scroll, new TableLayoutConstraints( 0, 1, 1, 1 ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void startupListeners()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
tree.getSelectionModel().addTreeSelectionListener( new TreeSelectionListener(){
|
|
|
|
|
@Override
|
|
|
|
|
public void valueChanged( TreeSelectionEvent e )
|
|
|
|
|
@ -131,9 +137,48 @@ public class VerAreasRelatorioPanel extends JPanel
|
|
|
|
|
TreePath path = tree.getSelectionPath();
|
|
|
|
|
Object object = path == null ? null : path.getLastPathComponent();
|
|
|
|
|
HsRelatorioPosto posto = object == null ? null : ( (object instanceof PostoRelatorioNode) ? (HsRelatorioPosto) ((PostoRelatorioNode) object).getUserObject() : null);
|
|
|
|
|
selectedNode = (object instanceof DefaultMutableTreeNode) ? (DefaultMutableTreeNode) object : null;
|
|
|
|
|
buttonEdit.setEnabled( selectedNode != null );
|
|
|
|
|
firePropertyChange( SELECTION_CHANGED, null, posto );
|
|
|
|
|
}
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
buttonEdit.addActionListener( new ActionListener()
|
|
|
|
|
{
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e)
|
|
|
|
|
{
|
|
|
|
|
Object object = selectedNode == null ? null : selectedNode.getUserObject();
|
|
|
|
|
if( object != null )
|
|
|
|
|
{
|
|
|
|
|
String message = "Novo valor";
|
|
|
|
|
String title = "Editar nome";
|
|
|
|
|
String result = JOptionPane.showInputDialog( VerAreasRelatorioPanel.this, message, title, JOptionPane.QUESTION_MESSAGE );
|
|
|
|
|
if( result != null && !result.trim().isEmpty() )
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if( object instanceof HsRelatorioArea )
|
|
|
|
|
{
|
|
|
|
|
((HsRelatorioArea) object).setDescription( result );
|
|
|
|
|
((HsRelatorioArea) object).save();
|
|
|
|
|
refresh();
|
|
|
|
|
}
|
|
|
|
|
else if( object instanceof HsRelatorioPosto )
|
|
|
|
|
{
|
|
|
|
|
((HsRelatorioPosto) object).setDescription( result );
|
|
|
|
|
((HsRelatorioPosto) object).save();
|
|
|
|
|
refresh();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch( Exception ex )
|
|
|
|
|
{
|
|
|
|
|
ErrorLogger.logException( ex );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void refresh()
|
|
|
|
|
@ -146,7 +191,6 @@ public class VerAreasRelatorioPanel extends JPanel
|
|
|
|
|
TreeTools.refreshTree( tree, root, false );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setRelatorio( HsRelatorio relatorio )
|
|
|
|
|
{
|
|
|
|
|
this.relatorio = relatorio;
|
|
|
|
|
|