|
|
|
|
@ -2,17 +2,13 @@ package siprp.higiene.gestao.legislacao;
|
|
|
|
|
|
|
|
|
|
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 javax.swing.JPanel;
|
|
|
|
|
import javax.swing.JScrollPane;
|
|
|
|
|
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.ui.LeafError;
|
|
|
|
|
import leaf.ui.TreeInserterDialog;
|
|
|
|
|
import leaf.ui.TreeTools;
|
|
|
|
|
import siprp.database.cayenne.objects.Empresas;
|
|
|
|
|
import siprp.database.cayenne.objects.Estabelecimentos;
|
|
|
|
|
import siprp.database.cayenne.objects.HsLegislacao;
|
|
|
|
|
@ -21,11 +17,6 @@ import siprp.database.cayenne.objects.HsLegislacaoEstabelecimento;
|
|
|
|
|
import siprp.higiene.gestao.AdicionarPanel;
|
|
|
|
|
import siprp.logic.HigieneSegurancaLogic;
|
|
|
|
|
|
|
|
|
|
import leaf.ui.LeafButton;
|
|
|
|
|
import leaf.ui.LeafError;
|
|
|
|
|
import leaf.ui.TreeInserterDialog;
|
|
|
|
|
import leaf.ui.TreeTools;
|
|
|
|
|
|
|
|
|
|
public class AdicionarLegislacaoPanel extends AdicionarPanel
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
@ -69,72 +60,76 @@ private static final long serialVersionUID = 1L;
|
|
|
|
|
DefaultMutableTreeNode result = new DefaultMutableTreeNode();
|
|
|
|
|
if( empresa != null )
|
|
|
|
|
{
|
|
|
|
|
result = HigieneSegurancaLogic.getLegislacaoTree( null );
|
|
|
|
|
result = HigieneSegurancaLogic.getLegislacaoTreeForEmpresa( null );
|
|
|
|
|
}
|
|
|
|
|
else if( estabelecimento != null )
|
|
|
|
|
{
|
|
|
|
|
result = HigieneSegurancaLogic.getLegislacaoTree( estabelecimento.getToEmpresas() );
|
|
|
|
|
result = HigieneSegurancaLogic.getLegislacaoTreeForEmpresa( estabelecimento.getToEmpresas() );
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void removeCurrent( DefaultMutableTreeNode all )
|
|
|
|
|
{
|
|
|
|
|
// if( all != null && root.getChildCount() == 2 && all.getChildCount() == 2 )
|
|
|
|
|
// {
|
|
|
|
|
// DefaultMutableTreeNode portuguesaAll = (DefaultMutableTreeNode) all.getChildAt( 0 );
|
|
|
|
|
// DefaultMutableTreeNode internacionalAll = (DefaultMutableTreeNode) all.getChildAt( 1 );
|
|
|
|
|
// DefaultMutableTreeNode portuguesaCurrent = (DefaultMutableTreeNode) root.getChildAt( 0 );
|
|
|
|
|
// DefaultMutableTreeNode internacionalCurrent = (DefaultMutableTreeNode) root.getChildAt( 1 );
|
|
|
|
|
// TreeTools.remove( portuguesaAll, portuguesaCurrent );
|
|
|
|
|
// TreeTools.remove( internacionalAll, internacionalCurrent );
|
|
|
|
|
// }
|
|
|
|
|
if( all != null && root.getChildCount() == 2 && all.getChildCount() == 2 )
|
|
|
|
|
{
|
|
|
|
|
DefaultMutableTreeNode geralAll = (DefaultMutableTreeNode) all.getChildAt( 0 );
|
|
|
|
|
DefaultMutableTreeNode especificaAll = (DefaultMutableTreeNode) all.getChildAt( 1 );
|
|
|
|
|
DefaultMutableTreeNode geralCurrent = (DefaultMutableTreeNode) root.getChildAt( 0 );
|
|
|
|
|
DefaultMutableTreeNode especificaCurrent = (DefaultMutableTreeNode) root.getChildAt( 1 );
|
|
|
|
|
TreeTools.remove( geralAll, geralCurrent );
|
|
|
|
|
TreeTools.removeAllLeafs( especificaAll, especificaCurrent );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addResult( DefaultMutableTreeNode root )
|
|
|
|
|
{
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// if( root != null )
|
|
|
|
|
// {
|
|
|
|
|
// Object userObject = root.getUserObject();
|
|
|
|
|
// if( userObject instanceof HsNormalizacao )
|
|
|
|
|
// {
|
|
|
|
|
// if( empresa != null )
|
|
|
|
|
// {
|
|
|
|
|
// HsNormalizacaoEmpresa rel = new HsNormalizacaoEmpresa();
|
|
|
|
|
// rel.setToEmpresa( empresa );
|
|
|
|
|
// rel.setToHsNormalizacao( ((HsNormalizacao) userObject ) );
|
|
|
|
|
// rel.save();
|
|
|
|
|
// }
|
|
|
|
|
// else if( estabelecimento != null )
|
|
|
|
|
// {
|
|
|
|
|
// HsNormalizacaoEstabelecimento rel = new HsNormalizacaoEstabelecimento();
|
|
|
|
|
// rel.setToEstabelecimento( estabelecimento );
|
|
|
|
|
// rel.setToHsNormalizacao( ((HsNormalizacao) userObject ) );
|
|
|
|
|
// rel.save();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// for( int i = 0; i < root.getChildCount(); ++i )
|
|
|
|
|
// {
|
|
|
|
|
// DefaultMutableTreeNode child = (DefaultMutableTreeNode) root.getChildAt( i );
|
|
|
|
|
// addResult( child );
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// catch( Exception e )
|
|
|
|
|
// {
|
|
|
|
|
// LeafError.error( e );
|
|
|
|
|
// }
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if( root != null )
|
|
|
|
|
{
|
|
|
|
|
Object userObject = root.getUserObject();
|
|
|
|
|
if( userObject instanceof HsLegislacao )
|
|
|
|
|
{
|
|
|
|
|
if( empresa != null )
|
|
|
|
|
{
|
|
|
|
|
HsLegislacaoEmpresa rel = new HsLegislacaoEmpresa();
|
|
|
|
|
rel.setToHsEmpresa( empresa );
|
|
|
|
|
rel.setToHsLegislacao( ((HsLegislacao) userObject ) );
|
|
|
|
|
rel.save();
|
|
|
|
|
}
|
|
|
|
|
else if( estabelecimento != null )
|
|
|
|
|
{
|
|
|
|
|
HsLegislacaoEstabelecimento rel = new HsLegislacaoEstabelecimento();
|
|
|
|
|
rel.setToHsEstabelecimento( estabelecimento );
|
|
|
|
|
rel.setToHsLegislacao( ((HsLegislacao) userObject ) );
|
|
|
|
|
rel.save();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for( int i = 0; i < root.getChildCount(); ++i )
|
|
|
|
|
{
|
|
|
|
|
DefaultMutableTreeNode child = (DefaultMutableTreeNode) root.getChildAt( i );
|
|
|
|
|
addResult( child );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch( Exception e )
|
|
|
|
|
{
|
|
|
|
|
LeafError.error( e );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void refresh()
|
|
|
|
|
{
|
|
|
|
|
root.removeAllChildren();
|
|
|
|
|
if( empresa != null || estabelecimento != null )
|
|
|
|
|
if( empresa != null )
|
|
|
|
|
{
|
|
|
|
|
TreeTools.merge( root, HigieneSegurancaLogic.getLegislacaoTreeForEmpresa( empresa ) );
|
|
|
|
|
}
|
|
|
|
|
else if( estabelecimento != null )
|
|
|
|
|
{
|
|
|
|
|
TreeTools.merge( root, HigieneSegurancaLogic.getLegislacaoTree( empresa != null ? empresa : estabelecimento.getToEmpresas() ) );
|
|
|
|
|
TreeTools.merge( root, HigieneSegurancaLogic.getLegislacaoTreeForEstabelecimento( estabelecimento ) );
|
|
|
|
|
}
|
|
|
|
|
setEnabled();
|
|
|
|
|
TreeTools.refreshTree( tree, root );
|
|
|
|
|
|