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

0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
Tiago Simão 17 years ago
parent ac5bed0a3f
commit fae6aae398

@ -191,8 +191,9 @@
</db-key-generator>
</db-entity>
<db-entity name="legislacao" schema="public">
<db-attribute name="description" type="VARCHAR" isMandatory="true" length="1024"/>
<db-attribute name="description" type="VARCHAR" isMandatory="true" length="8192"/>
<db-attribute name="id" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/>
<db-attribute name="parent_id" type="INTEGER"/>
<db-key-generator>
<db-generator-type>ORACLE</db-generator-type>
<db-generator-name>legislacao_id_seq</db-generator-name>
@ -713,6 +714,7 @@
</obj-entity>
<obj-entity name="Legislacao" className="siprp.database.cayenne.objects.Legislacao" dbEntityName="legislacao">
<obj-attribute name="description" type="java.lang.String" db-attribute-path="description"/>
<obj-attribute name="parentID" type="java.lang.Integer" db-attribute-path="parent_id"/>
</obj-entity>
<obj-entity name="LegislacaoEstabelecimento" className="siprp.database.cayenne.objects.LegislacaoEstabelecimento" dbEntityName="legislacao_estabelecimento">
</obj-entity>
@ -1021,9 +1023,15 @@
<db-relationship name="empresasArray" source="image" target="empresas" toMany="true">
<db-attribute-pair source="id" target="empresa_logo_id"/>
</db-relationship>
<db-relationship name="childrenArray" source="legislacao" target="legislacao" toMany="true">
<db-attribute-pair source="id" target="parent_id"/>
</db-relationship>
<db-relationship name="legislacaoEstabelecimentoArray" source="legislacao" target="legislacao_estabelecimento" toDependentPK="true" toMany="true">
<db-attribute-pair source="id" target="legislacao_id"/>
</db-relationship>
<db-relationship name="toLegislacao" source="legislacao" target="legislacao" toMany="false">
<db-attribute-pair source="parent_id" target="id"/>
</db-relationship>
<db-relationship name="toEstabelecimentos" source="legislacao_estabelecimento" target="estabelecimentos" toMany="false">
<db-attribute-pair source="estabelecimento_id" target="id"/>
</db-relationship>
@ -1346,7 +1354,9 @@
<obj-relationship name="toTiposExamesComp" source="ExamesPerfis" target="TiposExamesComp" db-relationship-path="toTiposExamesComp"/>
<obj-relationship name="toEstabelecimentos" source="HistoricoEstabelecimento" target="Estabelecimentos" db-relationship-path="toEstabelecimentos"/>
<obj-relationship name="empresasArray" source="Image" target="Empresas" db-relationship-path="empresasArray"/>
<obj-relationship name="legislacaoEstabelecimentoArray" source="Legislacao" target="LegislacaoEstabelecimento" db-relationship-path="legislacaoEstabelecimentoArray"/>
<obj-relationship name="childrenArray" source="Legislacao" target="Legislacao" deleteRule="Cascade" db-relationship-path="childrenArray"/>
<obj-relationship name="legislacaoEstabelecimentoArray" source="Legislacao" target="LegislacaoEstabelecimento" deleteRule="Cascade" db-relationship-path="legislacaoEstabelecimentoArray"/>
<obj-relationship name="toLegislacao" source="Legislacao" target="Legislacao" deleteRule="Nullify" db-relationship-path="toLegislacao"/>
<obj-relationship name="toEstabelecimentos" source="LegislacaoEstabelecimento" target="Estabelecimentos" deleteRule="Nullify" db-relationship-path="toEstabelecimentos"/>
<obj-relationship name="toLegislacao" source="LegislacaoEstabelecimento" target="Legislacao" deleteRule="Nullify" db-relationship-path="toLegislacao"/>
<obj-relationship name="toEmpresas" source="Lembretes" target="Empresas" db-relationship-path="toEmpresas"/>

@ -14,12 +14,13 @@ import siprp.clientes.AvisosPanel;
import siprp.clientes.ClientesWindow;
import siprp.estatistica.EstatisticaWindow;
import siprp.ficha.FichaWindow;
import siprp.higiene.legislacoes.GestaoLegislacoesWindow;
import siprp.higiene.mapa.MapaHigieneWindow;
import siprp.higiene.marcacoes.MarcacoesHigieneWindow;
import siprp.higiene.riscos.GestaoRiscosWindow;
import siprp.impressaofichas.ImpressaoFichasWindow;
import siprp.lembretes.LembretesWindow;
import siprp.medicina.MedicinaWindow;
import siprp.medicina.exames.logic.RecepcaoExamesLogic;
import siprp.medicina.exames.ui.RecepcaoExamesWindow;
import siprp.medicina.locais_analise.EnviarAnalisesWindow;
import siprp.medicina.locais_realizacao.LocaisRealizacaoWindow;
@ -246,7 +247,22 @@ public class SIPRPTracker extends WindowTracker
return new MapaHigieneWindow();
}
} );
higieneNode.add( new DefaultMutableTreeNode( GestaoLegislacoesWindow.TITLE) );
creators.put( GestaoLegislacoesWindow.TITLE, new WindowCreator() {
public TrackableWindow create()
throws Exception
{
return new GestaoLegislacoesWindow();
}
} );
higieneNode.add( new DefaultMutableTreeNode( GestaoRiscosWindow.TITLE) );
creators.put( GestaoRiscosWindow.TITLE, new WindowCreator() {
public TrackableWindow create()
throws Exception
{
return new GestaoRiscosWindow();
}
} );
rootNode.add( higieneNode );
}

@ -72,12 +72,12 @@ public class EstabelecimentoPlanoActuacaoPanel extends JPanel implements Control
private final JButton buttonEmailAdicionar = new JButton("Adicionar");
private final JButton buttonLegislacaoCriar = new JButton("Criar");
private final JButton buttonLegislacaoAdicionar = new JButton("Adicionar");
private final JButton buttonPostoTrabalhoCriar = new JButton("Criar");
private final JButton buttonPostoTrabalhoEditar = new JButton("Editar");
private final JButton buttonPostoTrabalhoAdicionar = new JButton("Adicionar");
private final JButton buttonEmailRemover = new JButton("Remover");
@ -123,7 +123,7 @@ public class EstabelecimentoPlanoActuacaoPanel extends JPanel implements Control
private void startupPostoTrabalhoLayout()
{
double [] cols = new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL };
double [] cols = new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL };
double [] rows = new double[]{ TableLayout.FILL, TableLayout.MINIMUM };
TableLayout layout = new TableLayout(cols,rows);
layout.setHGap( 5 );
@ -133,7 +133,7 @@ public class EstabelecimentoPlanoActuacaoPanel extends JPanel implements Control
private void startupLegislacaoLayout()
{
double [] cols = new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL };
double [] cols = new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL };
double [] rows = new double[]{ TableLayout.FILL, TableLayout.MINIMUM };
TableLayout layout = new TableLayout(cols,rows);
layout.setHGap( 5 );
@ -155,11 +155,11 @@ public class EstabelecimentoPlanoActuacaoPanel extends JPanel implements Control
buttonEmailAdicionar.setEnabled( false );
buttonEmailRemover.setEnabled( false );
buttonLegislacaoCriar.setEnabled( false );
buttonLegislacaoAdicionar.setEnabled( false );
buttonLegislacaoRemover.setEnabled( false );
buttonPostoTrabalhoCriar.setEnabled( false );
buttonPostoTrabalhoEditar.setEnabled( false );
buttonPostoTrabalhoAdicionar.setEnabled( false );
buttonPostoTrabalhoRemover.setEnabled( false );
}
@ -171,15 +171,15 @@ public class EstabelecimentoPlanoActuacaoPanel extends JPanel implements Control
panelEmail.add( buttonEmailAdicionar, new TableLayoutConstraints( 0, 1 ) );
panelEmail.add( buttonEmailRemover, new TableLayoutConstraints( 1, 1 ) );
panelLegislacao.add( scrollLegislacao, new TableLayoutConstraints( 0, 0, 3, 0 ) );
panelLegislacao.add( buttonLegislacaoCriar, new TableLayoutConstraints( 0, 1 ) );
panelLegislacao.add( buttonLegislacaoAdicionar, new TableLayoutConstraints( 1, 1 ) );
panelLegislacao.add( buttonLegislacaoRemover, new TableLayoutConstraints( 2, 1 ) );
panelLegislacao.add( scrollLegislacao, new TableLayoutConstraints( 0, 0, 2, 0 ) );
panelLegislacao.add( buttonLegislacaoAdicionar, new TableLayoutConstraints( 0, 1 ) );
panelLegislacao.add( buttonLegislacaoRemover, new TableLayoutConstraints( 1, 1 ) );
panelPostoTrabalho.add( scrollPostoTrabalho, new TableLayoutConstraints( 0, 0, 3, 0 ) );
panelPostoTrabalho.add( scrollPostoTrabalho, new TableLayoutConstraints( 0, 0, 4, 0 ) );
panelPostoTrabalho.add( buttonPostoTrabalhoCriar, new TableLayoutConstraints( 0, 1 ) );
panelPostoTrabalho.add( buttonPostoTrabalhoAdicionar, new TableLayoutConstraints( 1, 1 ) );
panelPostoTrabalho.add( buttonPostoTrabalhoRemover, new TableLayoutConstraints( 2, 1 ) );
panelPostoTrabalho.add( buttonPostoTrabalhoEditar, new TableLayoutConstraints( 1, 1 ) );
panelPostoTrabalho.add( buttonPostoTrabalhoAdicionar, new TableLayoutConstraints( 2, 1 ) );
panelPostoTrabalho.add( buttonPostoTrabalhoRemover, new TableLayoutConstraints( 3, 1 ) );
this.add( panelLegislacao, new TableLayoutConstraints( 0,0 ) );
this.add( panelPostoTrabalho, new TableLayoutConstraints( 1,0 ) );
@ -221,14 +221,6 @@ public class EstabelecimentoPlanoActuacaoPanel extends JPanel implements Control
removeSelected(tableEmail);
}
} );
buttonLegislacaoCriar.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
criarLegislacao();
}
} );
buttonLegislacaoAdicionar.addActionListener( new ActionListener()
{
@Override
@ -253,6 +245,14 @@ public class EstabelecimentoPlanoActuacaoPanel extends JPanel implements Control
criarPostoTrabalho();
}
} );
buttonPostoTrabalhoEditar.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
alterarPostoTrabalho();
}
} );
buttonPostoTrabalhoAdicionar.addActionListener( new ActionListener()
{
@Override
@ -298,47 +298,20 @@ public class EstabelecimentoPlanoActuacaoPanel extends JPanel implements Control
{
if( !e.getValueIsAdjusting() )
{
buttonPostoTrabalhoEditar.setEnabled( tablePostoTrabalho.getSelectedRowCount() > 0 );
buttonPostoTrabalhoRemover.setEnabled( tablePostoTrabalho.getSelectedRowCount() > 0 );
}
}
} );
}
private void criarLegislacao()
{
String legislacao = JOptionPane.showInputDialog( "Criar legisla" + ccedil + atilde + "o" );
Legislacao legislacaoObject = criarLegislacao( legislacao );
if( legislacaoObject != null )
{
adicionarLegislacao( legislacaoObject );
}
}
private Legislacao criarLegislacao( String legislacao )
{
Legislacao result = null;
if( legislacao != null )
{
if( legislacao.trim().length() > 0 )
{
legislacao = legislacao.trim();
result = provider.createLegislacao( legislacao );
}
else
{
JOptionPane.showMessageDialog( this, "Legisla" + ccedil + atilde + "o inv" + aacute + "lida", "Erro", JOptionPane.ERROR_MESSAGE, null );
}
}
return result;
}
private void adicionarLegislacao()
{
Legislacao [] legislacoes = provider.getAllLegislacoesNotInEstabelecimento( estabelecimento );
Legislacao legislacao = (Legislacao) JOptionPane.showInputDialog(
this,
"Postos de trabalho",
"Adicionar posto de trabalho", JOptionPane.QUESTION_MESSAGE, null, legislacoes, null );
"Legisla" + ccedil + otilde + "es",
"Adicionar legisla" + ccedil + atilde + "o", JOptionPane.QUESTION_MESSAGE, null, legislacoes, null );
adicionarLegislacao( legislacao );
}
@ -379,13 +352,51 @@ public class EstabelecimentoPlanoActuacaoPanel extends JPanel implements Control
return result;
}
private PostoDeTrabalhoEstabelecimento getSelectedPostoTrabalhoRel()
{
PostoDeTrabalhoEstabelecimento result = null;
int index = tablePostoTrabalho.getSelectedRow();
if( index != -1 )
{
result = modelPostoTrabalho.getRowAt( index );
}
return result;
}
private void alterarPostoTrabalho()
{
PostoDeTrabalhoEstabelecimento rel = getSelectedPostoTrabalhoRel();
if( rel != null )
{
String newDescription = JOptionPane.showInputDialog( "Editar medida", rel.getToPostoDeTrabalho().getDescription() );
if( newDescription != null )
{
if( newDescription.trim().length() > 0 )
{
rel.getToPostoDeTrabalho().setDescription( newDescription );
provider.commit();
refresh();
}
else
{
JOptionPane.showMessageDialog( this, "Medida inv" + aacute + "lida", "Erro", JOptionPane.ERROR_MESSAGE, null );
}
}
}
}
private void adicionarPostoTrabalho()
{
PostoDeTrabalho [] postos = provider.getAllPostosNotInEstabelecimento( estabelecimento );
PostoDeTrabalho postoDeTrabalho = (PostoDeTrabalho) JOptionPane.showInputDialog(
this,
"Postos de trabalho",
"Adicionar posto de trabalho", JOptionPane.QUESTION_MESSAGE, null, postos, null );
"Adicionar posto de trabalho",
JOptionPane.QUESTION_MESSAGE,
null,
postos,
null
);
adicionarPostoTrabalho( postoDeTrabalho );
}
@ -461,6 +472,7 @@ public class EstabelecimentoPlanoActuacaoPanel extends JPanel implements Control
}
else
{
estabelecimento = null;
setEnabled( false );
}
refresh();
@ -481,7 +493,6 @@ public class EstabelecimentoPlanoActuacaoPanel extends JPanel implements Control
buttonEmailAdicionar.setEnabled( enabled );
buttonLegislacaoAdicionar.setEnabled( enabled );
buttonPostoTrabalhoAdicionar.setEnabled( enabled );
buttonLegislacaoCriar.setEnabled( enabled );
buttonPostoTrabalhoCriar.setEnabled( enabled );
tableEmail.clearSelection();
tableLegislacao.clearSelection();

@ -2,12 +2,61 @@ package siprp.database.cayenne.objects;
import siprp.database.cayenne.objects.auto._Legislacao;
import com.evolute.utils.strings.UnicodeChecker;
public class Legislacao extends _Legislacao {
private static final long serialVersionUID = 1L;
private String description = null;
private String convertedDescription = null;
@Override
public String toString()
{
return getDescription() == null ? "" : getDescription();
String result = getDescription() == null ? "" : getDescription();
if( result.contains( "\n" ) )
{
result = result.substring( 0, result.indexOf( "\n" ) ) + "...";
}
else if( result.contains( "\n\r" ) )
{
result = result.substring( 0, result.indexOf( "\n\r" ) ) + "...";
}
return result;
}
@Override
public String getDescription()
{
String currentName = super.getDescription();
if( description == null || !description.equals( currentName ))
{
description = currentName;
convertedDescription = null;
}
return convertName();
}
@Override
public void setDescription( String nome )
{
super.setDescription( nome != null ? UnicodeChecker.parseToUnicode( nome ).replaceAll( "\\\\\\\\", "\\\\" ) : null );
getDescription();
}
private String convertName()
{
if( description == null )
{
convertedDescription = null;
}
else
{
convertedDescription = UnicodeChecker.parseFromUnicode( description );
}
return convertedDescription;
}
}

@ -1,13 +1,53 @@
package siprp.database.cayenne.objects;
import com.evolute.utils.strings.UnicodeChecker;
import siprp.database.cayenne.objects.auto._Medida;
public class Medida extends _Medida {
private static final long serialVersionUID = 1L;
private String description = null;
private String convertedDescription = null;
@Override
public String toString()
{
return getDescription() == null ? "" : getDescription();
}
@Override
public String getDescription()
{
String currentName = super.getDescription();
if( description == null || !description.equals( currentName ))
{
description = currentName;
convertedDescription = null;
}
return convertName();
}
@Override
public void setDescription( String nome )
{
super.setDescription( nome != null ? UnicodeChecker.parseToUnicode( nome ).replaceAll( "\\\\\\\\", "\\\\" ) : null );
getDescription();
}
private String convertName()
{
if( description == null )
{
convertedDescription = null;
}
else
{
convertedDescription = UnicodeChecker.parseFromUnicode( description );
}
return convertedDescription;
}
}

@ -1,13 +1,53 @@
package siprp.database.cayenne.objects;
import com.evolute.utils.strings.UnicodeChecker;
import siprp.database.cayenne.objects.auto._PostoDeTrabalho;
public class PostoDeTrabalho extends _PostoDeTrabalho {
private static final long serialVersionUID = 1L;
private String description = null;
private String convertedDescription = null;
@Override
public String toString()
{
return getDescription() == null ? "" : getDescription();
}
@Override
public String getDescription()
{
String currentName = super.getDescription();
if( description == null || !description.equals( currentName ))
{
description = currentName;
convertedDescription = null;
}
return convertName();
}
@Override
public void setDescription( String nome )
{
super.setDescription( nome != null ? UnicodeChecker.parseToUnicode( nome ).replaceAll( "\\\\\\\\", "\\\\" ) : null );
getDescription();
}
private String convertName()
{
if( description == null )
{
convertedDescription = null;
}
else
{
convertedDescription = UnicodeChecker.parseFromUnicode( description );
}
return convertedDescription;
}
}

@ -4,6 +4,7 @@ import java.util.List;
import org.apache.cayenne.CayenneDataObject;
import siprp.database.cayenne.objects.Legislacao;
import siprp.database.cayenne.objects.LegislacaoEstabelecimento;
/**
@ -15,7 +16,10 @@ import siprp.database.cayenne.objects.LegislacaoEstabelecimento;
public abstract class _Legislacao extends CayenneDataObject {
public static final String DESCRIPTION_PROPERTY = "description";
public static final String PARENT_ID_PROPERTY = "parentID";
public static final String CHILDREN_ARRAY_PROPERTY = "childrenArray";
public static final String LEGISLACAO_ESTABELECIMENTO_ARRAY_PROPERTY = "legislacaoEstabelecimentoArray";
public static final String TO_LEGISLACAO_PROPERTY = "toLegislacao";
public static final String ID_PK_COLUMN = "id";
@ -26,6 +30,25 @@ public abstract class _Legislacao extends CayenneDataObject {
return (String)readProperty("description");
}
public void setParentID(Integer parentID) {
writeProperty("parentID", parentID);
}
public Integer getParentID() {
return (Integer)readProperty("parentID");
}
public void addToChildrenArray(Legislacao obj) {
addToManyTarget("childrenArray", obj, true);
}
public void removeFromChildrenArray(Legislacao obj) {
removeToManyTarget("childrenArray", obj, true);
}
@SuppressWarnings("unchecked")
public List<Legislacao> getChildrenArray() {
return (List<Legislacao>)readProperty("childrenArray");
}
public void addToLegislacaoEstabelecimentoArray(LegislacaoEstabelecimento obj) {
addToManyTarget("legislacaoEstabelecimentoArray", obj, true);
}
@ -38,4 +61,13 @@ public abstract class _Legislacao extends CayenneDataObject {
}
public void setToLegislacao(Legislacao toLegislacao) {
setToOneTarget("toLegislacao", toLegislacao, true);
}
public Legislacao getToLegislacao() {
return (Legislacao)readProperty("toLegislacao");
}
}

@ -7,6 +7,7 @@ import java.util.List;
import org.apache.cayenne.CayenneDataObject;
import org.apache.cayenne.DataObjectUtils;
import org.apache.cayenne.exp.ExpressionFactory;
import org.apache.cayenne.query.SelectQuery;
import siprp.database.cayenne.objects.EmailPlanoDeActuacao;
@ -50,11 +51,11 @@ public class PlanoActuacaoDAO extends MainDAO implements MedicinaConstants
context.commitChanges();
}
public Legislacao createLegislacao( String legislacao )
public Legislacao createNovaLegislacao( Legislacao parent )
{
Legislacao legislacaoObject = (Legislacao) context.newObject( Legislacao.class );
legislacaoObject.setDescription( legislacao );
context.commitChanges();
legislacaoObject.setToLegislacao( parent );
legislacaoObject.setDescription( "" );
return legislacaoObject;
}
@ -140,6 +141,7 @@ public class PlanoActuacaoDAO extends MainDAO implements MedicinaConstants
{
List<Legislacao> result = new LinkedList<Legislacao>();
SelectQuery query = new SelectQuery( Legislacao.class );
query.andQualifier( ExpressionFactory.matchExp( Legislacao.TO_LEGISLACAO_PROPERTY, null ) );
List<Legislacao> res = context.performQuery( query );
if( res != null )
{
@ -213,6 +215,7 @@ public class PlanoActuacaoDAO extends MainDAO implements MedicinaConstants
public List<Risco> getAllRiscos()
{
SelectQuery query = new SelectQuery(Risco.class);
query.addOrdering( Risco.DESCRIPTION_PROPERTY, true );
List<Risco> result = context.performQuery( query );
return result;
}
@ -233,4 +236,15 @@ public class PlanoActuacaoDAO extends MainDAO implements MedicinaConstants
context.commitChanges();
}
public List<Legislacao> getAllLegislacoes( Legislacao parent )
{
SelectQuery query = new SelectQuery( Legislacao.class );
query.andQualifier( ExpressionFactory.matchExp( Legislacao.TO_LEGISLACAO_PROPERTY, parent ) );
if( parent == null )
{
query.addOrdering( Legislacao.DESCRIPTION_PROPERTY, true );
}
return context.performQuery( query );
}
}

@ -19,6 +19,7 @@ import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.event.ListSelectionEvent;
@ -30,15 +31,16 @@ import siprp.database.cayenne.objects.RiscoMedida;
import siprp.database.cayenne.providers.PlanoActuacaoDAO;
import com.evolute.utils.tables.VectorTableModel;
import com.evolute.utils.tracker.TrackableWindow;
public class GestaoRiscosWindow extends JFrame
public class GestaoRiscosWindow extends JFrame implements TrackableWindow
{
private static final long serialVersionUID = 1L;
private static final String TITLE = "Gest" + atilde + "o de Riscos";
public static final String TITLE = "Gest" + atilde + "o de Riscos";
private static final Dimension SIZE = new Dimension( 640, 480 );
private static final Dimension SIZE = new Dimension( 700, 500 );
private final VectorTableModel<Risco> modelRiscos = new VectorTableModel<Risco>( new String[]{ "Riscos" } );
@ -54,12 +56,16 @@ public class GestaoRiscosWindow extends JFrame
private final JButton buttonRiscoCriar = new JButton("Criar");
private final JButton buttonRiscoEditar = new JButton("Editar");
private final JButton buttonRiscoRemover = new JButton("Remover");
private final JButton buttonValorGuardar = new JButton("Guardar");
private final JButton buttonMedidaCriar = new JButton("Criar");
private final JButton buttonMedidaEditar = new JButton("Editar");
private final JButton buttonMedidaAdicionar = new JButton("Adicionar");
private final JButton buttonMedidaRemover = new JButton("Remover");
@ -100,7 +106,9 @@ public class GestaoRiscosWindow extends JFrame
buttonMedidaRemover.setEnabled( false );
buttonMedidaAdicionar.setEnabled( false );
buttonMedidaCriar.setEnabled( false );
buttonMedidaEditar.setEnabled( false );
buttonRiscoRemover.setEnabled( false );
buttonRiscoEditar.setEnabled( false );
buttonValorGuardar.setEnabled( false );
fieldValor.setEnabled( false );
}
@ -122,7 +130,7 @@ public class GestaoRiscosWindow extends JFrame
private void startupPanelRiscosLayout()
{
TableLayout layout = new TableLayout(
new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL },
new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL },
new double[]{ TableLayout.FILL, TableLayout.MINIMUM }
);
layout.setHGap( 5 );
@ -133,7 +141,7 @@ public class GestaoRiscosWindow extends JFrame
private void startupPanelMedidasLayout()
{
TableLayout layout = new TableLayout(
new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL },
new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL },
new double[]{ TableLayout.FILL, TableLayout.MINIMUM }
);
layout.setHGap( 5 );
@ -186,6 +194,14 @@ public class GestaoRiscosWindow extends JFrame
removerMedidas();
}
} );
buttonMedidaEditar.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
alterarMedida();
}
} );
buttonRiscoCriar.addActionListener( new ActionListener()
{
@Override
@ -194,6 +210,14 @@ public class GestaoRiscosWindow extends JFrame
criarRisco();
}
} );
buttonRiscoEditar.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
alterarRisco();
}
} );
buttonRiscoRemover.addActionListener( new ActionListener()
{
@Override
@ -220,11 +244,13 @@ public class GestaoRiscosWindow extends JFrame
int [] indexes = tableMedidas.getSelectedRows();
if( indexes != null && indexes.length > 0 )
{
buttonMedidaCriar.setEnabled( true );
buttonMedidaRemover.setEnabled( true );
buttonMedidaEditar.setEnabled( indexes.length == 1 );
}
else
{
buttonMedidaRemover.setEnabled( false );
buttonMedidaEditar.setEnabled( false );
}
}
}
@ -240,17 +266,14 @@ public class GestaoRiscosWindow extends JFrame
if( indexes != null && indexes.length > 0 )
{
buttonRiscoRemover.setEnabled( true );
if( indexes.length == 1 )
{
buttonMedidaCriar.setEnabled( true );
buttonMedidaAdicionar.setEnabled( true );
buttonMedidaRemover.setEnabled( true );
buttonValorGuardar.setEnabled( true );
fieldValor.setEnabled( true );
}
buttonMedidaCriar.setEnabled( indexes.length == 1 );
buttonMedidaAdicionar.setEnabled( indexes.length == 1 );
buttonRiscoEditar.setEnabled( indexes.length == 1 );
fieldValor.setEnabled( indexes.length == 1 );
}
else
{
buttonRiscoEditar.setEnabled( false );
buttonMedidaCriar.setEnabled( false );
buttonRiscoRemover.setEnabled( false );
buttonMedidaAdicionar.setEnabled( false );
@ -275,14 +298,16 @@ public class GestaoRiscosWindow extends JFrame
private void placeComponents()
{
panelRiscos.add( scrollRiscos, new TableLayoutConstraints( 0, 0, 2, 0 ) );
panelRiscos.add( scrollRiscos, new TableLayoutConstraints( 0, 0, 3, 0 ) );
panelRiscos.add( buttonRiscoCriar, new TableLayoutConstraints( 0, 1 ) );
panelRiscos.add( buttonRiscoRemover, new TableLayoutConstraints( 1, 1 ) );
panelRiscos.add( buttonRiscoEditar, new TableLayoutConstraints( 1, 1 ) );
panelRiscos.add( buttonRiscoRemover, new TableLayoutConstraints( 2, 1 ) );
panelMedidas.add( scrollMedidas, new TableLayoutConstraints( 0, 0, 3, 0 ) );
panelMedidas.add( scrollMedidas, new TableLayoutConstraints( 0, 0, 4, 0 ) );
panelMedidas.add( buttonMedidaCriar, new TableLayoutConstraints( 0, 1 ) );
panelMedidas.add( buttonMedidaAdicionar, new TableLayoutConstraints( 1, 1 ) );
panelMedidas.add( buttonMedidaRemover, new TableLayoutConstraints( 2, 1 ) );
panelMedidas.add( buttonMedidaEditar, new TableLayoutConstraints( 1, 1 ) );
panelMedidas.add( buttonMedidaAdicionar, new TableLayoutConstraints( 2, 1 ) );
panelMedidas.add( buttonMedidaRemover, new TableLayoutConstraints( 3, 1 ) );
panelValor.add( labelValor, new TableLayoutConstraints( 0, 0 ) );
panelValor.add( fieldValor, new TableLayoutConstraints( 1, 0 ) );
@ -293,6 +318,50 @@ public class GestaoRiscosWindow extends JFrame
this.getContentPane().add( panelMedidas, new TableLayoutConstraints( 1, 1 ) );
}
private void alterarMedida()
{
Medida medida = getSelectedMedida();
if( medida != null )
{
String newDescription = JOptionPane.showInputDialog( "Editar medida", medida.getDescription() );
if( newDescription != null )
{
if( newDescription.trim().length() > 0 )
{
medida.setDescription( newDescription );
provider.commit();
refreshMedidas();
}
else
{
JOptionPane.showMessageDialog( this, "Medida inv" + aacute + "lida", "Erro", JOptionPane.ERROR_MESSAGE, null );
}
}
}
}
private void alterarRisco()
{
Risco risco = getSelectedRisco();
if( risco != null )
{
String newDescription = JOptionPane.showInputDialog( "Editar risco", risco.getDescription() );
if( newDescription != null )
{
if( newDescription.trim().length() > 0 )
{
risco.setDescription( newDescription );
provider.commit();
refreshRiscos();
}
else
{
JOptionPane.showMessageDialog( this, "Risco inv" + aacute + "lido", "Erro", JOptionPane.ERROR_MESSAGE, null );
}
}
}
}
private void alterarValor()
{
Risco risco = getSelectedRisco();
@ -407,6 +476,21 @@ public class GestaoRiscosWindow extends JFrame
return result;
}
private Medida getSelectedMedida()
{
Medida result = null;
int indexes[] = tableMedidas.getSelectedRows();
if( indexes != null && indexes.length == 1 )
{
RiscoMedida rel = modelMedidas.getRowAt( indexes[0] );
if( rel != null )
{
result = rel.getToMedida();
}
}
return result;
}
private void criarRisco()
{
String risco = JOptionPane.showInputDialog( "Criar risco" );
@ -495,5 +579,35 @@ public class GestaoRiscosWindow extends JFrame
}
}
@Override
public boolean closeIfPossible()
{
close();
return true;
}
private void close()
{
SwingUtilities.invokeLater( new Runnable() {
public void run()
{
setVisible( false );
dispose();
}
} );
}
@Override
public void open()
{
setVisible( true );
}
@Override
public void refresh()
{
refreshRiscos();
}
}

@ -69,7 +69,8 @@ public class V8_9_To_V9_0
");" +
"create table legislacao(" +
"id serial PRIMARY KEY," +
"description varchar(1024) NOT NULL" +
"parent_id int4 REFERENCES legislacao(id)," +
"description varchar(8192) NOT NULL" +
");" +
"create table posto_de_trabalho_estabelecimento(" +
"posto_de_trabalho_id int4 REFERENCES posto_de_trabalho(id) NOT NULL," +

Loading…
Cancel
Save