@ -19,10 +19,14 @@ import javax.swing.JLabel;
import javax.swing.JOptionPane ;
import javax.swing.JPanel ;
import javax.swing.JScrollPane ;
import javax.swing.JTextArea ;
import javax.swing.JTextField ;
import javax.swing.JTree ;
import javax.swing.event.CaretEvent ;
import javax.swing.event.CaretListener ;
import javax.swing.event.TreeSelectionEvent ;
import javax.swing.event.TreeSelectionListener ;
import javax.swing.text.AbstractDocument.LeafElement ;
import javax.swing.tree.DefaultMutableTreeNode ;
import javax.swing.tree.DefaultTreeModel ;
import javax.swing.tree.TreePath ;
@ -30,7 +34,7 @@ import javax.swing.tree.TreeSelectionModel;
import leaf.data.Validator ;
import leaf.ui.LeafButton ;
import leaf.ui.Leaf Error ;
import leaf.ui.Leaf Dialog ;
import leaf.ui.LeafIconButton ;
import leaf.ui.LeafTextAreaEditor ;
import leaf.ui.LeafUIConstants ;
@ -38,7 +42,7 @@ import leaf.ui.TreeTools;
import siprp.database.cayenne.objects.HsNormalizacao ;
import siprp.logic.HigieneSegurancaLogic ;
public class GerirNormalizacaoPanel extends JPanel implements LeafUIConstants
public class GerirNormalizacaoPanel extends JPanel implements LeafUIConstants , CaretListener
{
private static final long serialVersionUID = 1L ;
@ -62,6 +66,10 @@ public class GerirNormalizacaoPanel extends JPanel implements LeafUIConstants
private final LeafButton buttonInternacionalEditar = LeafIconButton . createDefaultEditButton ( ) ;
private final LeafButton buttonInternacionalRemover = LeafIconButton . createDefaultRemoveButton ( ) ;
private final LeafButton buttonSave = LeafIconButton . createButton ( ICON_NAME_SAVE ) ;
private final LeafButton buttonRevert = LeafIconButton . createButton ( ICON_NAME_REVERT ) ;
private final DefaultMutableTreeNode rootPortuguesa = new DefaultMutableTreeNode ( ) ;
@ -87,14 +95,7 @@ public class GerirNormalizacaoPanel extends JPanel implements LeafUIConstants
private final JTextField textCodigo = new JTextField ( 10 ) ;
private final LeafTextAreaEditor textDescricao = new LeafTextAreaEditor ( new Validator < String > ( )
{
@Override
public boolean isValid ( String object )
{
return true ;
}
} ) ;
private final JTextArea textAreaDescricao = new JTextArea ( ) ;
public GerirNormalizacaoPanel ( )
{
@ -118,6 +119,9 @@ public class GerirNormalizacaoPanel extends JPanel implements LeafUIConstants
treePortuguesa . getSelectionModel ( ) . setSelectionMode ( TreeSelectionModel . SINGLE_TREE_SELECTION ) ;
textCodigo . setEnabled ( false ) ;
buttonSave . setEnabled ( false ) ;
buttonRevert . setEnabled ( false ) ;
}
private void startupLayout ( )
@ -155,9 +159,9 @@ public class GerirNormalizacaoPanel extends JPanel implements LeafUIConstants
panelButtonsInternacional . setLayout ( layout ) ;
layout = new TableLayout ( new double [ ] {
TableLayout . MINIMUM , TableLayout . PREFERRED , TableLayout . FILL
TableLayout . MINIMUM , TableLayout . PREFERRED , TableLayout . FILL , TableLayout . MINIMUM , TableLayout . MINIMUM
} , new double [ ] {
TableLayout . MINIMUM , TableLayout . FILL
TableLayout . MINIMUM , TableLayout . MINIMUM, TableLayout . FILL
} ) ;
( ( TableLayout ) layout ) . setHGap ( 5 ) ;
( ( TableLayout ) layout ) . setVGap ( 5 ) ;
@ -180,9 +184,11 @@ public class GerirNormalizacaoPanel extends JPanel implements LeafUIConstants
panelInternacional . add ( panelButtonsInternacional , new TableLayoutConstraints ( 0 , 0 ) ) ;
panelInternacional . add ( scrollInternacional , new TableLayoutConstraints ( 0 , 1 , 1 , 1 ) ) ;
panelData . add ( new JLabel ( "C" + oacute + "digo" ) , new TableLayoutConstraints ( 0 , 0 ) ) ;
panelData . add ( textCodigo , new TableLayoutConstraints ( 1 , 0 ) ) ;
panelData . add ( textDescricao , new TableLayoutConstraints ( 0 , 1 , 2 , 1 ) ) ;
panelData . add ( buttonSave , new TableLayoutConstraints ( 3 , 0 ) ) ;
panelData . add ( buttonRevert , new TableLayoutConstraints ( 4 , 0 ) ) ;
panelData . add ( new JLabel ( "C" + oacute + "digo" ) , new TableLayoutConstraints ( 0 , 1 ) ) ;
panelData . add ( textCodigo , new TableLayoutConstraints ( 1 , 1 ) ) ;
panelData . add ( textAreaDescricao , new TableLayoutConstraints ( 0 , 2 , 4 , 2 ) ) ;
this . add ( panelPortuguesa , new TableLayoutConstraints ( 0 , 0 ) ) ;
this . add ( panelInternacional , new TableLayoutConstraints ( 0 , 1 ) ) ;
@ -247,31 +253,8 @@ public class GerirNormalizacaoPanel extends JPanel implements LeafUIConstants
setEnable ( ) ;
}
} ) ;
textDescricao . addPropertyChangeListener ( LeafTextAreaEditor . ACTION_SAVE , new PropertyChangeListener ( )
{
@Override
public void propertyChange ( PropertyChangeEvent evt )
{
try
{
String newValue = ( String ) evt . getNewValue ( ) ;
if ( selectedInternacional ! = null )
{
selectedInternacional . setDescricao ( newValue ) ;
selectedInternacional . save ( ) ;
}
else if ( selectedPortuguesa ! = null )
{
selectedPortuguesa . setDescricao ( newValue ) ;
selectedPortuguesa . save ( ) ;
}
reload ( ) ;
} catch ( Exception e )
{
LeafError . error ( e ) ;
}
}
} ) ;
textCodigo . addCaretListener ( this ) ;
textAreaDescricao . addCaretListener ( this ) ;
buttonPortuguesaCriar . addActionListener ( new ActionListener ( )
{
@Override
@ -320,6 +303,61 @@ public class GerirNormalizacaoPanel extends JPanel implements LeafUIConstants
removerInternacional ( ) ;
}
} ) ;
buttonSave . addActionListener ( new ActionListener ( )
{
@Override
public void actionPerformed ( ActionEvent e )
{
try
{
save ( ) ;
} catch ( Exception e1 )
{
LeafDialog . error ( e1 ) ;
}
}
} ) ;
buttonRevert . addActionListener ( new ActionListener ( )
{
@Override
public void actionPerformed ( ActionEvent e )
{
if ( selectedInternacional ! = null )
{
textAreaDescricao . setText ( selectedInternacional . getDescricao ( ) ) ;
textAreaDescricao . setEnabled ( true ) ;
textCodigo . setText ( selectedInternacional . getCodigo ( ) ) ;
}
else if ( selectedPortuguesa ! = null )
{
textAreaDescricao . setText ( selectedPortuguesa . getDescricao ( ) ) ;
textAreaDescricao . setEnabled ( true ) ;
textCodigo . setText ( selectedPortuguesa . getCodigo ( ) ) ;
}
else
{
textAreaDescricao . setText ( "" ) ;
textCodigo . setText ( "" ) ;
}
}
} ) ;
}
private void save ( ) throws Exception
{
if ( selectedInternacional ! = null )
{
selectedInternacional . setCodigo ( textCodigo . getText ( ) ) ;
selectedInternacional . setDescricao ( textAreaDescricao . getText ( ) ) ;
selectedInternacional . save ( ) ;
}
else if ( selectedPortuguesa ! = null )
{
selectedPortuguesa . setCodigo ( textCodigo . getText ( ) ) ;
selectedPortuguesa . setDescricao ( textAreaDescricao . getText ( ) ) ;
selectedPortuguesa . save ( ) ;
}
reload ( ) ;
}
private String getCodigoForNormalizacao ( boolean criar , boolean portuguesa )
@ -362,7 +400,7 @@ public class GerirNormalizacaoPanel extends JPanel implements LeafUIConstants
}
} catch ( Exception e )
{
Leaf Error . error ( e ) ;
Leaf Dialog . error ( e ) ;
}
}
@ -382,7 +420,7 @@ public class GerirNormalizacaoPanel extends JPanel implements LeafUIConstants
}
} catch ( Exception e )
{
Leaf Error . error ( e ) ;
Leaf Dialog . error ( e ) ;
}
}
@ -390,7 +428,7 @@ public class GerirNormalizacaoPanel extends JPanel implements LeafUIConstants
{
try
{
if ( selectedPortuguesa ! = null )
if ( selectedPortuguesa ! = null && LeafDialog . confirmDelete ( false , false , "normaliza" + ccedil + atilde + "o" ) )
{
selectedPortuguesa . setDeletedDate ( new Date ( ) ) ;
selectedPortuguesa . save ( ) ;
@ -398,7 +436,7 @@ public class GerirNormalizacaoPanel extends JPanel implements LeafUIConstants
}
} catch ( Exception e )
{
Leaf Error . error ( e ) ;
Leaf Dialog . error ( e ) ;
}
}
@ -418,7 +456,7 @@ public class GerirNormalizacaoPanel extends JPanel implements LeafUIConstants
}
} catch ( Exception e )
{
Leaf Error . error ( e ) ;
Leaf Dialog . error ( e ) ;
}
}
@ -438,7 +476,7 @@ public class GerirNormalizacaoPanel extends JPanel implements LeafUIConstants
}
} catch ( Exception e )
{
Leaf Error . error ( e ) ;
Leaf Dialog . error ( e ) ;
}
}
@ -446,15 +484,16 @@ public class GerirNormalizacaoPanel extends JPanel implements LeafUIConstants
{
try
{
if ( selectedInternacional ! = null )
if ( selectedInternacional ! = null && LeafDialog . confirmDelete ( false , false , "normaliza" + ccedil + atilde + "o" ) )
{
selectedInternacional . setDeletedDate ( new Date ( ) ) ;
selectedInternacional . save ( ) ;
reload ( ) ;
}
} catch ( Exception e )
}
catch ( Exception e )
{
Leaf Error . error ( e ) ;
Leaf Dialog . error ( e ) ;
}
}
@ -476,22 +515,26 @@ public class GerirNormalizacaoPanel extends JPanel implements LeafUIConstants
buttonPortuguesaRemover . setEnabled ( false ) ;
buttonInternacionalEditar . setEnabled ( false ) ;
buttonPortuguesaEditar . setEnabled ( false ) ;
textDescricao . setEnabled ( false ) ;
textAreaDescricao . setEnabled ( false ) ;
buttonSave . setEnabled ( false ) ;
buttonRevert . setEnabled ( false ) ;
if ( selectedInternacional ! = null )
{
text Descricao. setValue ( selectedInternacional . getDescricao ( ) ) ;
text Descricao. setEnabled ( true ) ;
text AreaDescricao. setText ( selectedInternacional . getDescricao ( ) ) ;
text Area Descricao. setEnabled ( true ) ;
textCodigo . setText ( selectedInternacional . getCodigo ( ) ) ;
textCodigo . setEnabled ( true ) ;
}
else if ( selectedPortuguesa ! = null )
{
text Descricao. setValue ( selectedPortuguesa . getDescricao ( ) ) ;
text Descricao. setEnabled ( true ) ;
text AreaDescricao. setText ( selectedPortuguesa . getDescricao ( ) ) ;
text Area Descricao. setEnabled ( true ) ;
textCodigo . setText ( selectedPortuguesa . getCodigo ( ) ) ;
textCodigo . setEnabled ( true ) ;
}
else
{
text Descricao. setValue ( null ) ;
text AreaDescricao. setText ( "" ) ;
textCodigo . setText ( "" ) ;
}
}
@ -504,4 +547,11 @@ public class GerirNormalizacaoPanel extends JPanel implements LeafUIConstants
buttonInternacionalRemover . setEnabled ( selectedInternacional ! = null ) ;
}
@Override
public void caretUpdate ( CaretEvent e )
{
buttonSave . setEnabled ( true ) ;
buttonRevert . setEnabled ( true ) ;
}
}