forked from Coded/SIPRP
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
205 lines
5.4 KiB
205 lines
5.4 KiB
package siprp.higiene.gestao.riscos;
|
|
|
|
import info.clearthought.layout.TableLayout;
|
|
import info.clearthought.layout.TableLayoutConstraints;
|
|
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
import java.io.IOException;
|
|
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JScrollPane;
|
|
import javax.swing.JTextArea;
|
|
import javax.swing.event.CaretEvent;
|
|
import javax.swing.event.CaretListener;
|
|
|
|
import leaf.ui.LeafButton;
|
|
import leaf.ui.LeafDialog;
|
|
import shst.data.outer.HsMedidaData;
|
|
import siprp.SIPRPSpellChecker;
|
|
import siprp.higiene.gestao.SIPRPLazyLoadedPanel;
|
|
|
|
import com.evolute.utils.error.ErrorLogger;
|
|
import com.evolute.utils.images.ImageException;
|
|
import com.evolute.utils.images.ImageIconLoader;
|
|
|
|
public class GerirMedidaPanel extends SIPRPLazyLoadedPanel
|
|
{
|
|
|
|
public static final String MEDIDA_CHANGED = "MEDIDA_CHANGED";
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private static final String ICON_NAME_SAVE = "leaf/ui/icons/save.png";
|
|
|
|
private static final String ICON_NAME_REVERT = "leaf/ui/icons/revert.png";
|
|
|
|
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 HsMedidaData medida = null;
|
|
|
|
public GerirMedidaPanel()
|
|
{
|
|
try
|
|
{
|
|
buttonSaveRequesito = new LeafButton( ImageIconLoader.loadImageIcon( ICON_NAME_SAVE ) );
|
|
buttonRevertRequesito = new LeafButton( ImageIconLoader.loadImageIcon( ICON_NAME_REVERT ) );
|
|
}
|
|
catch( ImageException e )
|
|
{
|
|
ErrorLogger.logException( e );
|
|
}
|
|
catch ( IOException e )
|
|
{
|
|
ErrorLogger.logException( e );
|
|
}
|
|
startupComponents();
|
|
startupLayout();
|
|
placeComponents();
|
|
setupListeners();
|
|
}
|
|
|
|
private void startupComponents()
|
|
{
|
|
fieldTextMedida.setWrapStyleWord( true );
|
|
fieldTextMedida.setLineWrap( true );
|
|
SIPRPSpellChecker.getInstance().attachSpellCheckToComponent( fieldTextMedida );
|
|
fieldTextRequisitosLegais.setWrapStyleWord( true );
|
|
fieldTextRequisitosLegais.setLineWrap( true );
|
|
SIPRPSpellChecker.getInstance().attachSpellCheckToComponent( fieldTextRequisitosLegais );
|
|
scrollMedida.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
|
|
scrollMedida.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS );
|
|
scrollRequesitos.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
|
|
scrollRequesitos.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS );
|
|
}
|
|
|
|
private void setupListeners()
|
|
{
|
|
fieldTextRequisitosLegais.addCaretListener( new CaretListener()
|
|
{
|
|
@Override
|
|
public void caretUpdate( CaretEvent e )
|
|
{
|
|
setEnabled();
|
|
}
|
|
} );
|
|
fieldTextMedida.addCaretListener( new CaretListener()
|
|
{
|
|
@Override
|
|
public void caretUpdate( CaretEvent e )
|
|
{
|
|
setEnabled();
|
|
}
|
|
} );
|
|
buttonSaveRequesito.addActionListener( new ActionListener()
|
|
{
|
|
@Override
|
|
public void actionPerformed( ActionEvent e )
|
|
{
|
|
saveRequesito();
|
|
}
|
|
} );
|
|
buttonRevertRequesito.addActionListener( new ActionListener()
|
|
{
|
|
@Override
|
|
public void actionPerformed( ActionEvent e )
|
|
{
|
|
revertRequesito();
|
|
}
|
|
} );
|
|
}
|
|
|
|
private void startupLayout()
|
|
{
|
|
TableLayout 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 );
|
|
setLayout( layout );
|
|
}
|
|
|
|
private void placeComponents()
|
|
{
|
|
add( new JLabel( "Requisitos legais" ), new TableLayoutConstraints( 0, 0 ) );
|
|
add( buttonSaveRequesito, new TableLayoutConstraints( 1, 0 ) );
|
|
add( buttonRevertRequesito, new TableLayoutConstraints( 2, 0 ) );
|
|
add( scrollRequesitos, new TableLayoutConstraints( 0, 1, 2, 1 ) );
|
|
add( new JLabel( "Medida" ), new TableLayoutConstraints( 0, 2 ) );
|
|
add( scrollMedida, new TableLayoutConstraints( 0, 3, 2, 3 ) );
|
|
}
|
|
|
|
private void setEnabled()
|
|
{
|
|
boolean medidaChanged = false;
|
|
boolean requesitoChanged = false;
|
|
if( medida != null )
|
|
{
|
|
medidaChanged = !fieldTextMedida.getText().equals( medida.getDescription() );
|
|
requesitoChanged = !fieldTextRequisitosLegais.getText().equals( medida.getRequesitos_legais() );
|
|
}
|
|
buttonSaveRequesito.setEnabled( requesitoChanged || medidaChanged );
|
|
buttonRevertRequesito.setEnabled( requesitoChanged || medidaChanged );
|
|
}
|
|
|
|
private void saveRequesito()
|
|
{
|
|
try
|
|
{
|
|
if( medida != null )
|
|
{
|
|
medida.setRequesitos_legais( fieldTextRequisitosLegais.getText() );
|
|
medida.setDescription( fieldTextMedida.getText() );
|
|
medida.save();
|
|
doRefresh();
|
|
}
|
|
setEnabled();
|
|
} catch( Exception e )
|
|
{
|
|
LeafDialog.error( e );
|
|
}
|
|
}
|
|
|
|
private void revertRequesito()
|
|
{
|
|
if( medida != null )
|
|
{
|
|
fieldTextRequisitosLegais.setText( medida.getRequesitos_legais() );
|
|
fieldTextMedida.setText( medida.getDescription() );
|
|
}
|
|
setEnabled();
|
|
}
|
|
|
|
@Override
|
|
public void refresh()
|
|
{
|
|
firePropertyChange( MEDIDA_CHANGED, null, medida );
|
|
}
|
|
|
|
public void setMedida( HsMedidaData medida )
|
|
{
|
|
this.medida = medida;
|
|
fieldTextMedida.setText( medida == null ? null : medida.getDescription() );
|
|
fieldTextRequisitosLegais.setText( medida == null ? null : medida.getRequesitos_legais() );
|
|
setEnabled();
|
|
}
|
|
|
|
public HsMedidaData getMedida()
|
|
{
|
|
return this.medida;
|
|
}
|
|
|
|
}
|