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

lxbfYeaa
Tiago Simão 17 years ago
parent 4aefdb48d6
commit 97c1e62c00

@ -3,6 +3,7 @@ package siprp.higiene.gestao.postos;
import static com.evolute.utils.strings.UnicodeLatin1Map.aacute; import static com.evolute.utils.strings.UnicodeLatin1Map.aacute;
import static com.evolute.utils.strings.UnicodeLatin1Map.atilde; import static com.evolute.utils.strings.UnicodeLatin1Map.atilde;
import static com.evolute.utils.strings.UnicodeLatin1Map.ccedil; import static com.evolute.utils.strings.UnicodeLatin1Map.ccedil;
import static com.evolute.utils.strings.UnicodeLatin1Map.eacute;
import info.clearthought.layout.TableLayout; import info.clearthought.layout.TableLayout;
import info.clearthought.layout.TableLayoutConstraints; import info.clearthought.layout.TableLayoutConstraints;
@ -10,11 +11,14 @@ import java.awt.Dimension;
import java.awt.GridLayout; import java.awt.GridLayout;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
@ -59,6 +63,8 @@ public class GerirAreasPanel extends JPanel implements LeafUIConstants
public final LeafButton buttonPostoRemover = LeafIconButton.createDefaultRemoveButton(); public final LeafButton buttonPostoRemover = LeafIconButton.createDefaultRemoveButton();
private final JCheckBox checkGenerico = new JCheckBox( "Gen"+eacute+"rico" );
private final DefaultMutableTreeNode root = new DefaultMutableTreeNode(); private final DefaultMutableTreeNode root = new DefaultMutableTreeNode();
private final DefaultTreeModel model = new DefaultTreeModel( root ); private final DefaultTreeModel model = new DefaultTreeModel( root );
@ -97,7 +103,7 @@ public class GerirAreasPanel extends JPanel implements LeafUIConstants
setLayout( layout ); setLayout( layout );
layout = new TableLayout( new double[] { layout = new TableLayout( new double[] {
TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL
}, new double[] { }, new double[] {
TableLayout.MINIMUM TableLayout.MINIMUM
} ); } );
@ -133,6 +139,8 @@ public class GerirAreasPanel extends JPanel implements LeafUIConstants
panel.add( buttonPostoRemover ); panel.add( buttonPostoRemover );
panelButtons.add( panel, new TableLayoutConstraints( 1, 0 ) ); panelButtons.add( panel, new TableLayoutConstraints( 1, 0 ) );
panelButtons.add( checkGenerico, new TableLayoutConstraints(2,0));
panelTree.add( scroll, new TableLayoutConstraints( 0, 0 ) ); panelTree.add( scroll, new TableLayoutConstraints( 0, 0 ) );
add( panelButtons, new TableLayoutConstraints( 0, 0 ) ); add( panelButtons, new TableLayoutConstraints( 0, 0 ) );
@ -146,7 +154,7 @@ public class GerirAreasPanel extends JPanel implements LeafUIConstants
@Override @Override
public void valueChanged( TreeSelectionEvent e ) public void valueChanged( TreeSelectionEvent e )
{ {
setEnabled(); setSelected();
} }
} ); } );
buttonAreaCriar.addActionListener( new ActionListener() buttonAreaCriar.addActionListener( new ActionListener()
@ -197,6 +205,25 @@ public class GerirAreasPanel extends JPanel implements LeafUIConstants
removerPosto(); removerPosto();
} }
} ); } );
checkGenerico.addItemListener( new ItemListener()
{
@Override
public void itemStateChanged( ItemEvent e )
{
HsPosto posto = getSelectedPosto();
if( posto != null )
{
posto.setIsPrincipal( checkGenerico.isSelected() );
try
{
posto.save();
} catch( Exception e1 )
{
e1.printStackTrace();
}
}
}
} );
} }
private void criarArea() private void criarArea()
@ -357,7 +384,7 @@ public class GerirAreasPanel extends JPanel implements LeafUIConstants
return result; return result;
} }
private void setEnabled() private void setSelected()
{ {
TreePath path = tree.getSelectionPath(); TreePath path = tree.getSelectionPath();
TreeNode node = path == null ? null : (TreeNode) path.getLastPathComponent(); TreeNode node = path == null ? null : (TreeNode) path.getLastPathComponent();
@ -369,6 +396,14 @@ public class GerirAreasPanel extends JPanel implements LeafUIConstants
buttonAreaRemover.setEnabled( areaSelected ); buttonAreaRemover.setEnabled( areaSelected );
buttonAreaCriar.setEnabled( empresa != null ); buttonAreaCriar.setEnabled( empresa != null );
buttonAreaEditar.setEnabled( areaSelected ); buttonAreaEditar.setEnabled( areaSelected );
checkGenerico.setEnabled( postoSelected );
boolean generico = false;
if( postoSelected && node != null)
{
HsPosto posto = (HsPosto) ((PostoNode) node).getUserObject();
generico = posto != null && (posto.getIsPrincipal() ==null ? false : posto.getIsPrincipal() );
}
checkGenerico.setSelected(generico);
} }
public void refresh() public void refresh()
@ -383,7 +418,7 @@ public class GerirAreasPanel extends JPanel implements LeafUIConstants
addArea( area ); addArea( area );
} }
} }
setEnabled(); setSelected();
TreeTools.refreshTree( tree, root, false ); TreeTools.refreshTree( tree, root, false );
} }

@ -315,6 +315,17 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
if( JOptionPane.YES_OPTION == ret ) if( JOptionPane.YES_OPTION == ret )
{ {
HigieneSegurancaLogic.reverterRelatorio(relatorio); HigieneSegurancaLogic.reverterRelatorio(relatorio);
if( relatorio != null )
{
try
{
relatorio.save();
}
catch( Exception e )
{
e.printStackTrace();
}
}
setRelatorio( relatorio, false ); setRelatorio( relatorio, false );
} }
} }

@ -141,7 +141,6 @@ public class VerAreasRelatorioPanel extends JPanel
{ {
TreeTools.merge( root, HigieneSegurancaLogic.getAreasRelatorioTree( relatorio ) ); TreeTools.merge( root, HigieneSegurancaLogic.getAreasRelatorioTree( relatorio ) );
} }
// TreeTools.sort( root );
TreeTools.refreshTree( tree, root, false ); TreeTools.refreshTree( tree, root, false );
} }

@ -24,6 +24,7 @@ import siprp.update.updates.V10_9_To_V11_0;
import siprp.update.updates.V11_0_To_V11_1; import siprp.update.updates.V11_0_To_V11_1;
import siprp.update.updates.V11_1_To_V11_2; import siprp.update.updates.V11_1_To_V11_2;
import siprp.update.updates.V11_2_To_V11_3; import siprp.update.updates.V11_2_To_V11_3;
import siprp.update.updates.V11_3_To_V11_4;
import siprp.update.updates.V6_1_To_V7_0; import siprp.update.updates.V6_1_To_V7_0;
import siprp.update.updates.V7_0_To_V7_2; import siprp.update.updates.V7_0_To_V7_2;
import siprp.update.updates.V7_2_To_V7_4; import siprp.update.updates.V7_2_To_V7_4;
@ -92,7 +93,8 @@ public class UpdateList
new V10_5_To_V10_6(), new V10_6_To_V10_7(), new V10_5_To_V10_6(), new V10_6_To_V10_7(),
new V10_7_To_V10_8(), new V10_8_To_V10_9(), new V10_7_To_V10_8(), new V10_8_To_V10_9(),
new V10_9_To_V11_0(), new V11_0_To_V11_1(), new V10_9_To_V11_0(), new V11_0_To_V11_1(),
new V11_1_To_V11_2(), new V11_2_To_V11_3() new V11_1_To_V11_2(), new V11_2_To_V11_3(),
new V11_3_To_V11_4()
}; };
protected static Executer EXECUTER; protected static Executer EXECUTER;

@ -0,0 +1,51 @@
package siprp.update.updates;
import siprp.higiene.gestao.importacao.Importador;
import com.evolute.utils.Singleton;
import com.evolute.utils.db.DBManager;
import com.evolute.utils.db.Executer;
public class V11_3_To_V11_4 implements siprp.update.Update
{
public V11_3_To_V11_4()
{
}
public String []listChanges()
{
return new String[]{
"Higiene e seguranca: restruturacao"
};
}
public double getStartVersion()
{
return 11.3;
}
public double getEndVersion()
{
return 11.4;
}
public void doUpdate() throws Exception
{
DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER );
Executer executer = dbm.getSharedExecuter();
com.evolute.utils.sql.Update update =
new com.evolute.utils.sql.Update(
"alter table hs_legislacao_estabelecimento add column ordem int4; " +
"alter table hs_relatorio_legislacao add column ordem int4; "
);
executer.executeQuery( update );
new Importador( executer ).importar();
}
public String toString()
{
return "v" + getStartVersion() + " para v" + getEndVersion();
}
}

@ -254,6 +254,7 @@
<db-entity name="hs_legislacao_estabelecimento" schema="public"> <db-entity name="hs_legislacao_estabelecimento" schema="public">
<db-attribute name="estabelecimento_id" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> <db-attribute name="estabelecimento_id" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/>
<db-attribute name="legislacao_id" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> <db-attribute name="legislacao_id" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/>
<db-attribute name="ordem" type="INTEGER" length="10"/>
</db-entity> </db-entity>
<db-entity name="hs_medida" schema="public"> <db-entity name="hs_medida" schema="public">
<db-attribute name="deleted_date" type="TIMESTAMP"/> <db-attribute name="deleted_date" type="TIMESTAMP"/>
@ -366,6 +367,7 @@
<db-attribute name="hs_legislacao_id" type="INTEGER" isMandatory="true" length="10"/> <db-attribute name="hs_legislacao_id" type="INTEGER" isMandatory="true" length="10"/>
<db-attribute name="hs_relatorio_id" type="INTEGER" isMandatory="true" length="10"/> <db-attribute name="hs_relatorio_id" type="INTEGER" isMandatory="true" length="10"/>
<db-attribute name="id" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> <db-attribute name="id" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/>
<db-attribute name="ordem" type="INTEGER" length="10"/>
<db-key-generator> <db-key-generator>
<db-generator-type>ORACLE</db-generator-type> <db-generator-type>ORACLE</db-generator-type>
<db-generator-name>hs_relatorio_legislacao_id_seq</db-generator-name> <db-generator-name>hs_relatorio_legislacao_id_seq</db-generator-name>
@ -985,6 +987,7 @@
<obj-entity name="HsLegislacaoEmpresa" className="siprp.database.cayenne.objects.HsLegislacaoEmpresa" dbEntityName="hs_legislacao_empresa" superClassName="siprp.database.cayenne.objects.BaseObject"> <obj-entity name="HsLegislacaoEmpresa" className="siprp.database.cayenne.objects.HsLegislacaoEmpresa" dbEntityName="hs_legislacao_empresa" superClassName="siprp.database.cayenne.objects.BaseObject">
</obj-entity> </obj-entity>
<obj-entity name="HsLegislacaoEstabelecimento" className="siprp.database.cayenne.objects.HsLegislacaoEstabelecimento" dbEntityName="hs_legislacao_estabelecimento" superClassName="siprp.database.cayenne.objects.BaseObject"> <obj-entity name="HsLegislacaoEstabelecimento" className="siprp.database.cayenne.objects.HsLegislacaoEstabelecimento" dbEntityName="hs_legislacao_estabelecimento" superClassName="siprp.database.cayenne.objects.BaseObject">
<obj-attribute name="ordem" type="java.lang.Integer" db-attribute-path="ordem"/>
</obj-entity> </obj-entity>
<obj-entity name="HsMedida" className="siprp.database.cayenne.objects.HsMedida" dbEntityName="hs_medida" superClassName="siprp.database.cayenne.objects.BaseObject"> <obj-entity name="HsMedida" className="siprp.database.cayenne.objects.HsMedida" dbEntityName="hs_medida" superClassName="siprp.database.cayenne.objects.BaseObject">
<obj-attribute name="deletedDate" type="java.util.Date" db-attribute-path="deleted_date"/> <obj-attribute name="deletedDate" type="java.util.Date" db-attribute-path="deleted_date"/>
@ -1048,6 +1051,7 @@
<obj-attribute name="categoria" type="java.lang.String" db-attribute-path="categoria"/> <obj-attribute name="categoria" type="java.lang.String" db-attribute-path="categoria"/>
<obj-attribute name="descricao" type="java.lang.String" db-attribute-path="descricao"/> <obj-attribute name="descricao" type="java.lang.String" db-attribute-path="descricao"/>
<obj-attribute name="hsLegislacaoId" type="java.lang.Integer" db-attribute-path="hs_legislacao_id"/> <obj-attribute name="hsLegislacaoId" type="java.lang.Integer" db-attribute-path="hs_legislacao_id"/>
<obj-attribute name="ordem" type="java.lang.Integer" db-attribute-path="ordem"/>
</obj-entity> </obj-entity>
<obj-entity name="HsRelatorioMedida" className="siprp.database.cayenne.objects.HsRelatorioMedida" dbEntityName="hs_relatorio_medida" superClassName="siprp.database.cayenne.objects.BaseObject"> <obj-entity name="HsRelatorioMedida" className="siprp.database.cayenne.objects.HsRelatorioMedida" dbEntityName="hs_relatorio_medida" superClassName="siprp.database.cayenne.objects.BaseObject">
<obj-attribute name="deletedDate" type="java.util.Date" db-attribute-path="deleted_date"/> <obj-attribute name="deletedDate" type="java.util.Date" db-attribute-path="deleted_date"/>
@ -1970,17 +1974,17 @@
<obj-relationship name="toHsRisco" source="HsPostoRisco" target="HsRisco" deleteRule="Nullify" db-relationship-path="toHsRisco"/> <obj-relationship name="toHsRisco" source="HsPostoRisco" target="HsRisco" deleteRule="Nullify" db-relationship-path="toHsRisco"/>
<obj-relationship name="hsRelatorioArea" source="HsRelatorio" target="HsRelatorioArea" deleteRule="Cascade" db-relationship-path="hsRelatorioArea"/> <obj-relationship name="hsRelatorioArea" source="HsRelatorio" target="HsRelatorioArea" deleteRule="Cascade" db-relationship-path="hsRelatorioArea"/>
<obj-relationship name="hsRelatorioEquipamentoArray" source="HsRelatorio" target="HsRelatorioEquipamento" db-relationship-path="hsRelatorioEquipamentoArray"/> <obj-relationship name="hsRelatorioEquipamentoArray" source="HsRelatorio" target="HsRelatorioEquipamento" db-relationship-path="hsRelatorioEquipamentoArray"/>
<obj-relationship name="hsRelatorioLegislacaoArray" source="HsRelatorio" target="HsRelatorioLegislacao" db-relationship-path="hsRelatorioLegislacaoArray"/> <obj-relationship name="hsRelatorioLegislacaoArray" source="HsRelatorio" target="HsRelatorioLegislacao" deleteRule="Cascade" db-relationship-path="hsRelatorioLegislacaoArray"/>
<obj-relationship name="hsRelatorioNormalizacaoArray" source="HsRelatorio" target="HsRelatorioNormalizacao" db-relationship-path="hsRelatorioNormalizacaoArray"/> <obj-relationship name="hsRelatorioNormalizacaoArray" source="HsRelatorio" target="HsRelatorioNormalizacao" deleteRule="Cascade" db-relationship-path="hsRelatorioNormalizacaoArray"/>
<obj-relationship name="hsRelatorioRiscoArray" source="HsRelatorio" target="HsRelatorioRisco" deleteRule="Cascade" db-relationship-path="hsRelatorioRiscoArray"/> <obj-relationship name="hsRelatorioRiscoArray" source="HsRelatorio" target="HsRelatorioRisco" deleteRule="Cascade" db-relationship-path="hsRelatorioRiscoArray"/>
<obj-relationship name="toHsMarcacoesEstabelecimento" source="HsRelatorio" target="MarcacoesEstabelecimento" db-relationship-path="toHsMarcacoesEstabelecimento"/> <obj-relationship name="toHsMarcacoesEstabelecimento" source="HsRelatorio" target="MarcacoesEstabelecimento" db-relationship-path="toHsMarcacoesEstabelecimento"/>
<obj-relationship name="hsRelatorioPostoArray" source="HsRelatorioArea" target="HsRelatorioPosto" deleteRule="Cascade" db-relationship-path="hsRelatorioPostoArray"/> <obj-relationship name="hsRelatorioPostoArray" source="HsRelatorioArea" target="HsRelatorioPosto" deleteRule="Cascade" db-relationship-path="hsRelatorioPostoArray"/>
<obj-relationship name="toHsRelatorio" source="HsRelatorioArea" target="HsRelatorio" deleteRule="Nullify" db-relationship-path="toHsRelatorio"/> <obj-relationship name="toHsRelatorio" source="HsRelatorioArea" target="HsRelatorio" deleteRule="Nullify" db-relationship-path="toHsRelatorio"/>
<obj-relationship name="toHsRelatorio" source="HsRelatorioEquipamento" target="HsRelatorio" deleteRule="Nullify" db-relationship-path="toHsRelatorio"/> <obj-relationship name="toHsRelatorio" source="HsRelatorioEquipamento" target="HsRelatorio" deleteRule="Nullify" db-relationship-path="toHsRelatorio"/>
<obj-relationship name="toHsRelatorio" source="HsRelatorioLegislacao" target="HsRelatorio" db-relationship-path="toHsRelatorio"/> <obj-relationship name="toHsRelatorio" source="HsRelatorioLegislacao" target="HsRelatorio" deleteRule="Nullify" db-relationship-path="toHsRelatorio"/>
<obj-relationship name="hsRelatorioPostoMedidaArray" source="HsRelatorioMedida" target="HsRelatorioPostoMedida" deleteRule="Cascade" db-relationship-path="hsRelatorioPostoMedidaArray"/> <obj-relationship name="hsRelatorioPostoMedidaArray" source="HsRelatorioMedida" target="HsRelatorioPostoMedida" deleteRule="Cascade" db-relationship-path="hsRelatorioPostoMedidaArray"/>
<obj-relationship name="toHsRelatorioRisco" source="HsRelatorioMedida" target="HsRelatorioRisco" deleteRule="Nullify" db-relationship-path="toHsRelatorioRisco"/> <obj-relationship name="toHsRelatorioRisco" source="HsRelatorioMedida" target="HsRelatorioRisco" deleteRule="Nullify" db-relationship-path="toHsRelatorioRisco"/>
<obj-relationship name="toHsRelatorio" source="HsRelatorioNormalizacao" target="HsRelatorio" db-relationship-path="toHsRelatorio"/> <obj-relationship name="toHsRelatorio" source="HsRelatorioNormalizacao" target="HsRelatorio" deleteRule="Nullify" db-relationship-path="toHsRelatorio"/>
<obj-relationship name="hsRelatorioPostoMedidaArray" source="HsRelatorioPosto" target="HsRelatorioPostoMedida" deleteRule="Cascade" db-relationship-path="hsRelatorioPostoMedidaArray"/> <obj-relationship name="hsRelatorioPostoMedidaArray" source="HsRelatorioPosto" target="HsRelatorioPostoMedida" deleteRule="Cascade" db-relationship-path="hsRelatorioPostoMedidaArray"/>
<obj-relationship name="hsRelatorioPostoRiscoArray" source="HsRelatorioPosto" target="HsRelatorioPostoRisco" deleteRule="Cascade" db-relationship-path="hsRelatorioPostoRiscoArray"/> <obj-relationship name="hsRelatorioPostoRiscoArray" source="HsRelatorioPosto" target="HsRelatorioPostoRisco" deleteRule="Cascade" db-relationship-path="hsRelatorioPostoRiscoArray"/>
<obj-relationship name="toHsRelatorioArea" source="HsRelatorioPosto" target="HsRelatorioArea" deleteRule="Nullify" db-relationship-path="toHsRelatorioArea"/> <obj-relationship name="toHsRelatorioArea" source="HsRelatorioPosto" target="HsRelatorioArea" deleteRule="Nullify" db-relationship-path="toHsRelatorioArea"/>

@ -25,6 +25,10 @@ public class TreeTools
{ {
return o2 == null ? 0 : -1; return o2 == null ? 0 : -1;
} }
else if( (o1 instanceof Comparable ) && (o2 instanceof Comparable))
{
return ((Comparable)o1).compareTo( (Comparable) o2 );
}
else else
{ {
return o2 == null ? 1 : StringPlainer.convertString( o1.toString() ).compareTo( StringPlainer.convertString( o2.toString() ) ); return o2 == null ? 1 : StringPlainer.convertString( o1.toString() ).compareTo( StringPlainer.convertString( o2.toString() ) );
@ -157,7 +161,7 @@ public class TreeTools
} }
} }
public static void sort( DefaultMutableTreeNode result ) public static void sort( DefaultMutableTreeNode result, boolean useDefaultComparator )
{ {
if( result != null ) if( result != null )
{ {
@ -167,7 +171,10 @@ public class TreeTools
children.add( (DefaultMutableTreeNode) result.getChildAt( i ) ); children.add( (DefaultMutableTreeNode) result.getChildAt( i ) );
} }
result.removeAllChildren(); result.removeAllChildren();
if( useDefaultComparator )
{
Collections.sort( children, comparator ); Collections.sort( children, comparator );
}
for( DefaultMutableTreeNode child : children ) for( DefaultMutableTreeNode child : children )
{ {
sort( child ); sort( child );
@ -175,6 +182,10 @@ public class TreeTools
} }
} }
} }
public static void sort( DefaultMutableTreeNode result )
{
sort( result, true );
}
public static void sort( DefaultMutableTreeNode result, Comparator<DefaultMutableTreeNode> comparator ) public static void sort( DefaultMutableTreeNode result, Comparator<DefaultMutableTreeNode> comparator )
{ {

@ -89,18 +89,20 @@ public class BaseObject extends CayenneDataObject implements Comparable<BaseObje
if( dao.hasOrder( this ) && dao.hasOrder( object ) ) if( dao.hasOrder( this ) && dao.hasOrder( object ) )
{ {
Object o1 = this.readProperty( "ordem" ); Object o1 = this.readProperty( "ordem" );
o1 = o1 != null ? o1 : this.readProperty( "order" );
if( o1 != null && (o1 instanceof Integer) ) if( o1 != null && (o1 instanceof Integer) )
{ {
Object o2 = this.readProperty( "ordem" ); Object o2 = object.readProperty( "ordem" );
o2 = o2 != null ? o2 : object.readProperty( "order" );
if( o2 != null && (o2 instanceof Integer) ) if( o2 != null && (o2 instanceof Integer) )
{ {
result = ((Integer)o1).compareTo( (Integer)o2 ); result = ((Integer)o1).compareTo( (Integer)o2 );
} }
} }
} }
else if( result == 0 )
{ {
StringPlainer.convertString( this.toString() ).compareTo( object == null ? null : StringPlainer.convertString( object.toString() ) ); result = StringPlainer.convertString( this.toString() ).compareTo( object == null ? null : StringPlainer.convertString( object.toString() ) );
} }
return result; return result;
} }

@ -18,6 +18,26 @@ public class HsArea extends _HsArea {
super.setDescription( parseToUnicode( nome ) ); super.setDescription( parseToUnicode( nome ) );
} }
@Override
public void save() throws Exception
{
Empresas empresa = getToEmpresas();
if( empresa != null )
{
Integer maxOrder = 0;
for( HsArea area : empresa.getHsAreaArray() )
{
Integer currentOrder = area.getOrder();
if( currentOrder != null )
{
maxOrder = Math.max( currentOrder, maxOrder );
}
}
this.setOrder( maxOrder + 1 );
}
super.save();
}
@Override @Override
public String toString() public String toString()
{ {

@ -4,4 +4,26 @@ import siprp.database.cayenne.objects.auto._HsLegislacaoEstabelecimento;
public class HsLegislacaoEstabelecimento extends _HsLegislacaoEstabelecimento { public class HsLegislacaoEstabelecimento extends _HsLegislacaoEstabelecimento {
private static final long serialVersionUID = 1L;
@Override
public void save() throws Exception
{
Estabelecimentos estabelecimento = getToHsEstabelecimento();
if( estabelecimento != null )
{
Integer maxOrder = 0;
for( HsLegislacaoEstabelecimento rel : estabelecimento.getHsLegislacaoEstabelecimentoArray() )
{
Integer currentOrder = rel.getOrdem();
if( currentOrder != null )
{
maxOrder = Math.max( currentOrder, maxOrder );
}
}
this.setOrdem( maxOrder + 1 );
}
super.save();
}
} }

@ -11,5 +11,24 @@ public class HsPostoRisco extends _HsPostoRisco {
{ {
return super.getToHsRisco().getDescription(); return super.getToHsRisco().getDescription();
} }
@Override
public void save() throws Exception
{
HsPosto posto = getToHsPosto();
if( posto != null )
{
Integer maxOrder = 0;
for( HsPostoRisco rel : posto.getHsPostoRiscoArray() )
{
Integer currentOrder = rel.getOrder();
if( currentOrder != null )
{
maxOrder = Math.max( currentOrder, maxOrder );
}
}
this.setOrder( maxOrder + 1 );
}
super.save();
}
} }

@ -12,12 +12,20 @@ import siprp.database.cayenne.objects.HsLegislacao;
*/ */
public abstract class _HsLegislacaoEstabelecimento extends BaseObject { public abstract class _HsLegislacaoEstabelecimento extends BaseObject {
public static final String ORDEM_PROPERTY = "ordem";
public static final String TO_HS_ESTABELECIMENTO_PROPERTY = "toHsEstabelecimento"; public static final String TO_HS_ESTABELECIMENTO_PROPERTY = "toHsEstabelecimento";
public static final String TO_HS_LEGISLACAO_PROPERTY = "toHsLegislacao"; public static final String TO_HS_LEGISLACAO_PROPERTY = "toHsLegislacao";
public static final String ESTABELECIMENTO_ID_PK_COLUMN = "estabelecimento_id"; public static final String ESTABELECIMENTO_ID_PK_COLUMN = "estabelecimento_id";
public static final String LEGISLACAO_ID_PK_COLUMN = "legislacao_id"; public static final String LEGISLACAO_ID_PK_COLUMN = "legislacao_id";
public void setOrdem(Integer ordem) {
writeProperty("ordem", ordem);
}
public Integer getOrdem() {
return (Integer)readProperty("ordem");
}
public void setToHsEstabelecimento(Estabelecimentos toHsEstabelecimento) { public void setToHsEstabelecimento(Estabelecimentos toHsEstabelecimento) {
setToOneTarget("toHsEstabelecimento", toHsEstabelecimento, true); setToOneTarget("toHsEstabelecimento", toHsEstabelecimento, true);
} }

@ -14,6 +14,7 @@ public abstract class _HsRelatorioLegislacao extends BaseObject {
public static final String CATEGORIA_PROPERTY = "categoria"; public static final String CATEGORIA_PROPERTY = "categoria";
public static final String DESCRICAO_PROPERTY = "descricao"; public static final String DESCRICAO_PROPERTY = "descricao";
public static final String HS_LEGISLACAO_ID_PROPERTY = "hsLegislacaoId"; public static final String HS_LEGISLACAO_ID_PROPERTY = "hsLegislacaoId";
public static final String ORDEM_PROPERTY = "ordem";
public static final String TO_HS_RELATORIO_PROPERTY = "toHsRelatorio"; public static final String TO_HS_RELATORIO_PROPERTY = "toHsRelatorio";
public static final String ID_PK_COLUMN = "id"; public static final String ID_PK_COLUMN = "id";
@ -39,6 +40,13 @@ public abstract class _HsRelatorioLegislacao extends BaseObject {
return (Integer)readProperty("hsLegislacaoId"); return (Integer)readProperty("hsLegislacaoId");
} }
public void setOrdem(Integer ordem) {
writeProperty("ordem", ordem);
}
public Integer getOrdem() {
return (Integer)readProperty("ordem");
}
public void setToHsRelatorio(HsRelatorio toHsRelatorio) { public void setToHsRelatorio(HsRelatorio toHsRelatorio) {
setToOneTarget("toHsRelatorio", toHsRelatorio, true); setToOneTarget("toHsRelatorio", toHsRelatorio, true);
} }

@ -34,7 +34,14 @@ public class MainDAO
public boolean hasOrder( BaseObject baseObject ) public boolean hasOrder( BaseObject baseObject )
{ {
return baseObject == null ? false : (null != baseObject.getObjEntity().getAttribute( "ordem" ) ); if( baseObject == null || baseObject.getObjEntity() == null )
{
return false;
}
else
{
return baseObject == null ? false : ( null != baseObject.getObjEntity().getAttribute( "ordem" ) || null != baseObject.getObjEntity().getAttribute( "order" ));
}
} }
} }

@ -4,6 +4,7 @@ import static com.evolute.utils.strings.UnicodeLatin1Map.atilde;
import static com.evolute.utils.strings.UnicodeLatin1Map.ccedil; import static com.evolute.utils.strings.UnicodeLatin1Map.ccedil;
import static com.evolute.utils.strings.UnicodeLatin1Map.iacute; import static com.evolute.utils.strings.UnicodeLatin1Map.iacute;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -169,7 +170,8 @@ public class HigieneSegurancaLogic
DefaultMutableTreeNode result = new DefaultMutableTreeNode(); DefaultMutableTreeNode result = new DefaultMutableTreeNode();
if( relatorio != null ) if( relatorio != null )
{ {
for( HsRelatorioArea area : relatorio.getHsRelatorioArea() ) List<HsRelatorioArea> areas = relatorio.getHsRelatorioArea();
for( HsRelatorioArea area : areas )
{ {
AreaRelatorioNode areaNode = new AreaRelatorioNode(area); AreaRelatorioNode areaNode = new AreaRelatorioNode(area);
for( HsRelatorioPosto posto : area.getHsRelatorioPostoArray() ) for( HsRelatorioPosto posto : area.getHsRelatorioPostoArray() )
@ -196,7 +198,8 @@ public class HigieneSegurancaLogic
reverterNormalizacao( relatorio, estabelecimento ); reverterNormalizacao( relatorio, estabelecimento );
} }
} }
} catch( Exception e ) }
catch( Exception e )
{ {
LeafDialog.error(e); LeafDialog.error(e);
} }
@ -230,6 +233,7 @@ public class HigieneSegurancaLogic
{ {
rArea = new HsRelatorioArea(); rArea = new HsRelatorioArea();
rArea.setDescription( area.getDescription() ); rArea.setDescription( area.getDescription() );
rArea.setOrder( area.getOrder() );
rArea.setToHsRelatorio( relatorio ); rArea.setToHsRelatorio( relatorio );
areasInserted.put(area,rArea); areasInserted.put(area,rArea);
} }
@ -248,6 +252,7 @@ public class HigieneSegurancaLogic
HsRelatorioPostoRisco rPostoRisco = new HsRelatorioPostoRisco(); HsRelatorioPostoRisco rPostoRisco = new HsRelatorioPostoRisco();
rPostoRisco.setToHsRelatorioPosto( rPosto ); rPostoRisco.setToHsRelatorioPosto( rPosto );
rPostoRisco.setToHsRelatorioRisco( rRelatorioRisco ); rPostoRisco.setToHsRelatorioRisco( rRelatorioRisco );
rPostoRisco.setOrder( postoRisco.getOrder() );
for( HsRiscoMedida riscoMedida : postoRisco.getToHsRisco().getHsRiscoMedidaArray() ) for( HsRiscoMedida riscoMedida : postoRisco.getToHsRisco().getHsRiscoMedidaArray() )
{ {
HsRelatorioMedida rMedida = new HsRelatorioMedida(); HsRelatorioMedida rMedida = new HsRelatorioMedida();
@ -264,14 +269,16 @@ public class HigieneSegurancaLogic
private static void reverterLegislacao( HsRelatorio relatorio, Estabelecimentos estabelecimento ) throws Exception private static void reverterLegislacao( HsRelatorio relatorio, Estabelecimentos estabelecimento ) throws Exception
{ {
for(HsRelatorioLegislacao legislacao : relatorio.getHsRelatorioLegislacaoArray()) int legislacaoSize = relatorio.getHsRelatorioLegislacaoArray().size();
for(int i = 0; i < legislacaoSize; ++i )
{ {
legislacao.delete(); relatorio.getHsRelatorioLegislacaoArray().get( 0 ).delete();
} }
for( HsLegislacaoEstabelecimento rel : estabelecimento.getHsLegislacaoEstabelecimentoArray() ) for( HsLegislacaoEstabelecimento rel : estabelecimento.getHsLegislacaoEstabelecimentoArray() )
{ {
HsLegislacao legislacao = rel.getToHsLegislacao(); HsLegislacao legislacao = rel.getToHsLegislacao();
HsRelatorioLegislacao relatorioLegislacao = criarRelatorioLegislacao( relatorio, legislacao ); HsRelatorioLegislacao relatorioLegislacao = criarRelatorioLegislacao( relatorio, legislacao );
relatorioLegislacao.setOrdem( rel.getOrdem() );
relatorioLegislacao.save(); relatorioLegislacao.save();
} }
} }
@ -292,9 +299,10 @@ public class HigieneSegurancaLogic
private static void reverterNormalizacao( HsRelatorio relatorio, Estabelecimentos estabelecimento ) throws Exception private static void reverterNormalizacao( HsRelatorio relatorio, Estabelecimentos estabelecimento ) throws Exception
{ {
for(HsRelatorioNormalizacao normalizacao : relatorio.getHsRelatorioNormalizacaoArray() ) int normalizacaoSize = relatorio.getHsRelatorioNormalizacaoArray().size();
for(int i = 0; i < normalizacaoSize; ++i )
{ {
normalizacao.delete(); relatorio.getHsRelatorioNormalizacaoArray().get( 0 ).delete();
} }
for( HsNormalizacaoEstabelecimento rel : estabelecimento.getHsNormalizacaoEstabelecimentoArray() ) for( HsNormalizacaoEstabelecimento rel : estabelecimento.getHsNormalizacaoEstabelecimentoArray() )
{ {
@ -527,31 +535,31 @@ public class HigieneSegurancaLogic
DefaultMutableTreeNode result = new DefaultMutableTreeNode(); DefaultMutableTreeNode result = new DefaultMutableTreeNode();
DefaultMutableTreeNode geral = new DefaultMutableTreeNode( "Legisla" + ccedil + atilde + "o de aplica" + ccedil + atilde + "o geral" ); DefaultMutableTreeNode geral = new DefaultMutableTreeNode( "Legisla" + ccedil + atilde + "o de aplica" + ccedil + atilde + "o geral" );
DefaultMutableTreeNode especifica = new DefaultMutableTreeNode( "Legisla" + ccedil + atilde + "o espec" + iacute + "fica" ); DefaultMutableTreeNode especifica = new DefaultMutableTreeNode( "Legisla" + ccedil + atilde + "o espec" + iacute + "fica" );
for( HsLegislacao legislacao : planoProvider.getAllLegislacaoGeral() ) if( estabelecimento != null )
{ {
if( estabelecimento == null || hasEstabelecimento( legislacao, estabelecimento ) ) for( HsLegislacaoEstabelecimento rel : estabelecimento.getHsLegislacaoEstabelecimentoArray() )
{ {
DefaultMutableTreeNode legislacaoNode = new DefaultMutableTreeNode( legislacao ); HsLegislacao legislacao = rel.getToHsLegislacao();
if( legislacao != null )
{
HsLegislacaoCategoria categoria = legislacao.getToHsLegislacaoCategoria();
if( categoria == null )
{
DefaultMutableTreeNode legislacaoNode = new DefaultMutableTreeNode( rel.getToHsLegislacao() );
geral.add( legislacaoNode ); geral.add( legislacaoNode );
} }
} else
for( HsLegislacaoCategoria categoria : planoProvider.getAllLegislacaoCategorias( ) )
{ {
boolean addCategory = false; DefaultMutableTreeNode categoriaNode = TreeTools.findNodeWithUserObject( categoria, especifica );
DefaultMutableTreeNode categoriaNode = new DefaultMutableTreeNode( categoria ); if( categoriaNode == null )
for( HsLegislacao legislacao : categoria.getHsLegislacaoArray() )
{ {
if( estabelecimento == null || hasEstabelecimento( legislacao, estabelecimento ) ) categoriaNode = new DefaultMutableTreeNode(categoria);
{ especifica.add(categoriaNode);
DefaultMutableTreeNode legislacaoNode = new DefaultMutableTreeNode( legislacao ); }
DefaultMutableTreeNode legislacaoNode = new DefaultMutableTreeNode( rel.getToHsLegislacao() );
categoriaNode.add( legislacaoNode ); categoriaNode.add( legislacaoNode );
addCategory = true;
} }
} }
if( addCategory)
{
especifica.add( categoriaNode );
} }
} }
result.add( geral ); result.add( geral );
@ -559,23 +567,6 @@ public class HigieneSegurancaLogic
return result; return result;
} }
private static boolean hasEstabelecimento( HsLegislacao legislacao, Estabelecimentos estabelecimento )
{
boolean result = false;
if( legislacao != null && estabelecimento != null )
{
for( HsLegislacaoEstabelecimento rel : legislacao.getHsLegislacaoEstabelecimentoArray() )
{
result = estabelecimento.equals( rel.getToHsEstabelecimento());
if( result )
{
break;
}
}
}
return result;
}
public static DefaultMutableTreeNode getEquipamentosTree() public static DefaultMutableTreeNode getEquipamentosTree()
{ {
DefaultMutableTreeNode result = new DefaultMutableTreeNode(); DefaultMutableTreeNode result = new DefaultMutableTreeNode();

Loading…
Cancel
Save