From ab1261e651cb706ca8ef1e78811b92d53874ca88 Mon Sep 17 00:00:00 2001 From: Frederico Palma Date: Sun, 13 May 2007 23:59:45 +0000 Subject: [PATCH] no message git-svn-id: https://svn.coded.pt/svn/SIPRP@369 bb69d46d-e84e-40c8-a05a-06db0d633741 --- .../processo/EscolherMotivoDialog.java | 173 ++++++++++++++++++ .../medicina/processo/ProcessoController.java | 46 ++++- .../processo/ProcessoDataProvider.java | 4 +- .../medicina/processo/ProcessoEvent.java | 9 +- .../medicina/processo/ProcessoPanel.java | 48 +++-- .../medicina/processo/ProcessoWindow.java | 10 +- .../medicina/processo/detalhes/ECDsPanel.java | 35 ++++ .../EstruturaProcessoMutableTreeNode.java | 1 + .../estrutura/EstruturaProcessoPanel.java | 151 ++++++++++----- 9 files changed, 403 insertions(+), 74 deletions(-) create mode 100644 trunk/siprp/medicina/processo/EscolherMotivoDialog.java create mode 100644 trunk/siprp/medicina/processo/detalhes/ECDsPanel.java diff --git a/trunk/siprp/medicina/processo/EscolherMotivoDialog.java b/trunk/siprp/medicina/processo/EscolherMotivoDialog.java new file mode 100644 index 00000000..7e5a92f6 --- /dev/null +++ b/trunk/siprp/medicina/processo/EscolherMotivoDialog.java @@ -0,0 +1,173 @@ +/* + * EscolherMotivoDialog.java + * + * Created on 13 de Maio de 2007, 22:16 + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.medicina.processo; + +import com.evolute.utils.data.IDObject; +import com.evolute.utils.data.MappableObject; +import com.evolute.utils.ui.CustomJDialog; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.HashMap; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; + +/** + * + * @author Frederico + */ +public class EscolherMotivoDialog extends CustomJDialog + implements ActionListener +{ + protected IDObject MOTIVOS[] = + new IDObject[]{ + new MappableObject( new Integer( 1 ), "Admiss\u00e3o" ), + new MappableObject( new Integer( 2 ), "Peri\u00f3dico" ), + new MappableObject( new Integer( 5 ), "Peri\u00f3dico inicial" ), + new MappableObject( new Integer( 3 ), "Ocasional" ) + }; + + protected IDObject SUB_MOTIVOS[][] = + new IDObject[][]{ + {}, + {}, + {}, + { new MappableObject( new Integer( 1 ), "Ap\u00f3s doen\u00e7a" ), + new MappableObject( new Integer( 2 ), "Ap\u00f3s acidente" ), + new MappableObject( new Integer( 3 ), "A pedido do trabalhador" ), + new MappableObject( new Integer( 4 ), "A pedido do servi\u00e7o" ), + new MappableObject( new Integer( 5 ), "Por mudan\u00e7a de fun\u00e7\u00e3o" ), + new MappableObject( new Integer( 6 ), "Por altera\u00e7\u00e3o das condi\u00e7\u00f5es de trabalho" ), + new MappableObject( new Integer( 10 ), "Outro" ) + } + }; + + protected JButton motivoButtons[]; + protected HashMap subMotivoButtons; + protected HashMap motivoButtonIDs; + protected HashMap subMotivoButtonIDs; + protected JPanel motivoPanel; + protected JPanel subMotivoPanel; + + protected Integer motivo; + protected Integer subMotivo; + + /** Creates a new instance of EscolherMotivoDialog */ + public EscolherMotivoDialog( JFrame owner ) + { + super( owner, true ); + setupComponents(); + + if( owner != null ) + { + centerSuper(); + } + else + { + center(); + } + } + + private void setupComponents() + { + setTitle( "Escolher Motivo" ); + setLayout( new FlowLayout( FlowLayout.LEFT ) ); + motivoButtons = new JButton[ MOTIVOS.length ]; + subMotivoButtons = new HashMap(); + motivoButtonIDs = new HashMap(); + subMotivoButtonIDs = new HashMap(); + for( int m = 0; m < MOTIVOS.length; m++ ) + { + JButton motivoButton = new JButton( MOTIVOS[ m ].toString() ); + motivoButton.addActionListener( this ); + motivoButtonIDs.put( motivoButton, MOTIVOS[ m ].getID() ); + motivoButton.setPreferredSize( new Dimension( 250, 20 ) ); + motivoButtons[ m ] = motivoButton; + if( SUB_MOTIVOS[ m ].length > 0 ) + { + JButton subButtons[] = new JButton[ SUB_MOTIVOS[ m ].length ]; + for( int sm = 0; sm < SUB_MOTIVOS[ m ].length; sm++ ) + { + JButton subButton = new JButton( SUB_MOTIVOS[ m ][ sm ].toString() ); + subMotivoButtonIDs.put( subButton, SUB_MOTIVOS[ m ][ sm ].getID() ); + subButtons[ sm ] = subButton; + subButton.setPreferredSize( new Dimension( 300, 20 ) ); + subButton.addActionListener( this ); + } + subMotivoButtons.put( motivoButton, subButtons ); + } + else + { + subMotivoButtons.put( motivoButton, null ); + } + } + motivoPanel = new JPanel(); + subMotivoPanel = new JPanel(); + + motivoPanel.setLayout( new GridLayout( motivoButtons.length + 1, 1 ) ); + for( int n = 0; n < motivoButtons.length; n++ ) + { + motivoPanel.add( motivoButtons[ n ] ); + } + + add( motivoPanel ); + add( subMotivoPanel ); + + pack(); + } + + public void actionPerformed(ActionEvent e) + { + JButton source = ( JButton ) e.getSource(); + if( motivoButtonIDs.containsKey( source ) ) + { + motivo = motivoButtonIDs.get( source ); + } + else if( subMotivoButtonIDs.containsKey( source ) ) + { + subMotivo = subMotivoButtonIDs.get( source ); + close(); + } + if( subMotivoButtons.containsKey( source ) ) + { + JButton subButtons[] = subMotivoButtons.get( source ); + if( subButtons == null || subButtons.length == 0 ) + { + close(); + } + else + { + subMotivoPanel.removeAll(); + subMotivoPanel.setLayout( new GridLayout( 0, 1 ) ); + for( int n = 0; n < subButtons.length; n++ ) + { + subMotivoPanel.add( subButtons[ n ] ); + } + pack(); + } + } + } + + protected void close() + { + SwingUtilities.invokeLater( new Runnable(){ + public void run() + { + setVisible( false ); + dispose(); + } + } ); + } + +} diff --git a/trunk/siprp/medicina/processo/ProcessoController.java b/trunk/siprp/medicina/processo/ProcessoController.java index d49abc0e..9ec8be00 100644 --- a/trunk/siprp/medicina/processo/ProcessoController.java +++ b/trunk/siprp/medicina/processo/ProcessoController.java @@ -9,7 +9,13 @@ package siprp.medicina.processo; -import siprp.medicina.processo.data.TrabalhadoresProcessoData; +import com.evolute.utils.Singleton; +import com.evolute.utils.data.MappableObject; +import com.evolute.utils.jdo.JDOProvider; +import com.evolute.utils.ui.DialogException; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import siprp.data.TrabalhadorData; import siprp.medicina.processo.detalhes.DetalhesProcessoPanel; import siprp.medicina.processo.estrutura.EstruturaProcessoPanel; @@ -18,26 +24,34 @@ import siprp.medicina.processo.estrutura.EstruturaProcessoPanel; * @author Frederico */ public class ProcessoController - implements ProcessoListener + implements ProcessoListener, ListSelectionListener { + protected ProcessoUpperPanel processoUpperPanel; protected EstruturaProcessoPanel estruturaProcessoPanel; protected ProcessoPanel processoPanel; protected DetalhesProcessoPanel detalhesProcessoPanel; protected ProcessoDataProvider provider; + protected JDOProvider JDO; + protected Integer idProcesso; protected Integer idMarcacao; protected Integer idData; /** Creates a new instance of ProcessoController */ - public ProcessoController( EstruturaProcessoPanel estruturaProcessoPanel, ProcessoPanel processoPanel, - DetalhesProcessoPanel detalhesProcessoPanel ) + public ProcessoController( ProcessoUpperPanel processoUpperPanel, EstruturaProcessoPanel estruturaProcessoPanel, + ProcessoPanel processoPanel, DetalhesProcessoPanel detalhesProcessoPanel ) throws Exception { + this.processoUpperPanel = processoUpperPanel; this.estruturaProcessoPanel = estruturaProcessoPanel; this.processoPanel = processoPanel; this.detalhesProcessoPanel = detalhesProcessoPanel; + processoUpperPanel.addListSelectionListener( this ); + estruturaProcessoPanel.addProcessoListener( this ); + provider = ProcessoDataProvider.getProvider(); + JDO = ( JDOProvider ) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER ); } public void processoStateChanged(ProcessoEvent e) @@ -316,4 +330,28 @@ public class ProcessoController { } } + + public void valueChanged(ListSelectionEvent e) + { + try + { + Integer ids[] = ( Integer [] ) processoUpperPanel.save(); + Integer trabalhadorID = ids[ 2 ]; + if( trabalhadorID != null ) + { + TrabalhadorData trabalhador = ( TrabalhadorData ) JDO.load( TrabalhadorData.class, trabalhadorID ); + estruturaProcessoPanel.setTrabalhador( new MappableObject( trabalhadorID, trabalhador.get( TrabalhadorData.NOME ) ) ); + } + else + { + estruturaProcessoPanel.clear(); + } + processoPanel.clear(); + detalhesProcessoPanel.clear(); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar trabalhador", true ); + } + } } diff --git a/trunk/siprp/medicina/processo/ProcessoDataProvider.java b/trunk/siprp/medicina/processo/ProcessoDataProvider.java index f48e9aeb..e2fde2f9 100644 --- a/trunk/siprp/medicina/processo/ProcessoDataProvider.java +++ b/trunk/siprp/medicina/processo/ProcessoDataProvider.java @@ -85,11 +85,11 @@ public class ProcessoDataProvider throws Exception { Select select = - new Select2( new String[]{ "marcacoes_processo" }, + new Select2( new String[]{ "trabalhadores_processo" }, new Integer[ 0 ], new Expression[ 0 ], new String[]{ "id", "data_inicio" }, - new Field( "marcacoes_processo.trabalhador_id" ).isEqual( trabalhadorID ), + new Field( "trabalhadores_processo.trabalhador_id" ).isEqual( trabalhadorID ), new String[]{ "data_inicio DESC" }, null, null, diff --git a/trunk/siprp/medicina/processo/ProcessoEvent.java b/trunk/siprp/medicina/processo/ProcessoEvent.java index d6b7888b..eb983ebb 100644 --- a/trunk/siprp/medicina/processo/ProcessoEvent.java +++ b/trunk/siprp/medicina/processo/ProcessoEvent.java @@ -43,16 +43,23 @@ public class ProcessoEvent public static final Integer TIPO_MAIL = new Integer( 6 ); public static final Integer TIPO_FICHA_APTIDAO = new Integer( 7 ); + protected final Object source; protected final int accao; protected final HashMap idsObjectos; /** Creates a new instance of ProcessoEvent */ - public ProcessoEvent( int accao, HashMap idsObjectos ) + public ProcessoEvent( Object source, int accao, HashMap idsObjectos ) { + this.source = source; this.accao = accao; this.idsObjectos = idsObjectos; } + public Object getSource() + { + return source; + } + public int getAccao() { return accao; diff --git a/trunk/siprp/medicina/processo/ProcessoPanel.java b/trunk/siprp/medicina/processo/ProcessoPanel.java index e349c612..6a69ec8e 100644 --- a/trunk/siprp/medicina/processo/ProcessoPanel.java +++ b/trunk/siprp/medicina/processo/ProcessoPanel.java @@ -42,20 +42,22 @@ public class ProcessoPanel extends JPanel private JTextField inicioText; private JTextField fimText; private JButton motivoButton; - private JButton ocasionalMotivoButton; private JButton novoECDButton; private JButton novaConsultaButton; private JButton emitirFAButton; private JButton fecharButton; + protected JFrame owner; + private final Vector PROCESSO_LISTENERS = new Vector(); private ProcessoDataProvider provider; /** Creates a new instance of ProcessoPanel */ - public ProcessoPanel() + public ProcessoPanel( JFrame owner ) throws Exception { + this.owner = owner; provider = ProcessoDataProvider.getProvider(); setupComponents(); } @@ -64,7 +66,7 @@ public class ProcessoPanel extends JPanel private void setupComponents() { motivoButton = new JButton( "Motivo" ); - ocasionalMotivoButton = new JButton( " " ); + motivoButton.addActionListener( this ); JLabel estadoLabel = new JLabel( "Estado" ); estadoText = new JTextField(); estadoText.setPreferredSize( new Dimension( 120, 20 ) ); @@ -100,8 +102,7 @@ public class ProcessoPanel extends JPanel TableLayout tableLayout = new TableLayout( cols, rows ); setLayout( tableLayout ); - add( motivoButton, new TableLayoutConstraints( 0, 0, 1, 0 ) ); - add( ocasionalMotivoButton, new TableLayoutConstraints( 2, 0 ) ); + add( motivoButton, new TableLayoutConstraints( 0, 0, 2, 0 ) ); add( estadoLabel, new TableLayoutConstraints( 0, 1 ) ); add( estadoText, new TableLayoutConstraints( 1, 1 ) ); add( inicioLabel, new TableLayoutConstraints( 0, 2 ) ); @@ -120,7 +121,11 @@ public class ProcessoPanel extends JPanel public void actionPerformed(ActionEvent e) { Object source = e.getSource(); - if( source.equals( novoECDButton ) ) + if( source.equals( motivoButton ) ) + { + escolherMotivo(); + } + else if( source.equals( novoECDButton ) ) { novoECD(); } @@ -138,6 +143,11 @@ public class ProcessoPanel extends JPanel } } + protected void escolherMotivo() + { + new EscolherMotivoDialog( owner ).setVisible( true ); + } + protected void novoECD() { } @@ -160,7 +170,6 @@ public class ProcessoPanel extends JPanel inicioText.setText( "" ); fimText.setText( "" ); motivoButton.setText( "Motivo" ); - ocasionalMotivoButton.setText( " " ); } protected void enableButtons( boolean enable ) @@ -170,7 +179,6 @@ public class ProcessoPanel extends JPanel emitirFAButton.setEnabled( enable ); fecharButton.setEnabled( enable ); motivoButton.setEnabled( enable ); - ocasionalMotivoButton.setEnabled( enable ); } public void addProcessoListener( ProcessoListener listener ) @@ -214,18 +222,22 @@ public class ProcessoPanel extends JPanel try { TrabalhadoresProcessoData processo = provider.getProcessoByID( ( Integer ) value ); - enableButtons( false ); - Date dataInicio = ( Date ) processo.get( TrabalhadoresProcessoData.DATA_INICIO ); - if( dataInicio != null ) - { - inicioText.setText( D_F.format( dataInicio ) ); - } - Date dataFim = ( Date ) processo.get( TrabalhadoresProcessoData.DATA_FIM ); - if( dataFim != null ) + enableButtons( true ); + String estado = null; + if( processo != null ) { - fimText.setText( D_F.format( dataFim ) ); + Date dataInicio = ( Date ) processo.get( TrabalhadoresProcessoData.DATA_INICIO ); + if( dataInicio != null ) + { + inicioText.setText( D_F.format( dataInicio ) ); + } + Date dataFim = ( Date ) processo.get( TrabalhadoresProcessoData.DATA_FIM ); + if( dataFim != null ) + { + fimText.setText( D_F.format( dataFim ) ); + } + estado = ( String ) processo.get( TrabalhadoresProcessoData.ESTADO ); } - String estado = ( String ) processo.get( TrabalhadoresProcessoData.ESTADO ); if( estado == null ) { estadoText.setText( ProcessoDataProvider.PROCESSO_POR_ABRIR_DESCRIPTION ); diff --git a/trunk/siprp/medicina/processo/ProcessoWindow.java b/trunk/siprp/medicina/processo/ProcessoWindow.java index 3f9a86d3..e1fce2c1 100644 --- a/trunk/siprp/medicina/processo/ProcessoWindow.java +++ b/trunk/siprp/medicina/processo/ProcessoWindow.java @@ -15,8 +15,8 @@ import info.clearthought.layout.TableLayoutConstraints; import java.awt.Dimension; import javax.swing.BorderFactory; import javax.swing.JFrame; -import javax.swing.JPanel; import javax.swing.SwingUtilities; +import siprp.medicina.processo.detalhes.DetalhesProcessoPanel; import siprp.medicina.processo.estrutura.EstruturaProcessoPanel; /** @@ -31,7 +31,7 @@ public class ProcessoWindow extends JFrame private ProcessoUpperPanel upperPanel; private EstruturaProcessoPanel estruturaPanel; private ProcessoPanel processoPanel; - private JPanel detalhesPanel; + private DetalhesProcessoPanel detalhesPanel; /** Creates a new instance of ProcessoWindow */ public ProcessoWindow() @@ -49,9 +49,9 @@ public class ProcessoWindow extends JFrame upperPanel = new ProcessoUpperPanel(); upperPanel.setPreferredSize( new Dimension( 1024, 200 ) ); estruturaPanel = new EstruturaProcessoPanel(); - processoPanel = new ProcessoPanel(); + processoPanel = new ProcessoPanel( this ); processoPanel.setBorder( BorderFactory.createEtchedBorder() ); - detalhesPanel = new JPanel(); + detalhesPanel = new DetalhesProcessoPanel(); detalhesPanel.setBorder( BorderFactory.createEtchedBorder() ); double cols[] = new double[]{ TableLayout.FILL, TableLayout.PREFERRED }; @@ -65,6 +65,8 @@ public class ProcessoWindow extends JFrame add( estruturaPanel, new TableLayoutConstraints( 0, 1, 0, 2 ) ); add( processoPanel, new TableLayoutConstraints( 1, 1 ) ); add( detalhesPanel, new TableLayoutConstraints( 1, 2 ) ); + + new ProcessoController( upperPanel, estruturaPanel, processoPanel, detalhesPanel ); } public void refresh() diff --git a/trunk/siprp/medicina/processo/detalhes/ECDsPanel.java b/trunk/siprp/medicina/processo/detalhes/ECDsPanel.java new file mode 100644 index 00000000..da0a7c4e --- /dev/null +++ b/trunk/siprp/medicina/processo/detalhes/ECDsPanel.java @@ -0,0 +1,35 @@ +/* + * ECDsPanel.java + * + * Created on 13 de Maio de 2007, 17:07 + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.medicina.processo.detalhes; + +import javax.swing.JFrame; +import javax.swing.JPanel; + +/** + * + * @author Frederico + */ +public class ECDsPanel extends JPanel +{ + protected JFrame owner; + + /** + * Creates a new instance of ECDsPanel + */ + public ECDsPanel( JFrame owner ) + { + this.owner = owner; + setupComponents(); + } + + private void setupComponents() + { + } +} diff --git a/trunk/siprp/medicina/processo/estrutura/EstruturaProcessoMutableTreeNode.java b/trunk/siprp/medicina/processo/estrutura/EstruturaProcessoMutableTreeNode.java index b5723818..9388e101 100644 --- a/trunk/siprp/medicina/processo/estrutura/EstruturaProcessoMutableTreeNode.java +++ b/trunk/siprp/medicina/processo/estrutura/EstruturaProcessoMutableTreeNode.java @@ -51,6 +51,7 @@ abstract public class EstruturaProcessoMutableTreeNode extends DefaultMutableTre public void setDescricao( String descricao ) { this.descricao = descricao; + setUserObject( descricao ); } abstract protected String getIconPath(); diff --git a/trunk/siprp/medicina/processo/estrutura/EstruturaProcessoPanel.java b/trunk/siprp/medicina/processo/estrutura/EstruturaProcessoPanel.java index 49747c40..5a0baa08 100644 --- a/trunk/siprp/medicina/processo/estrutura/EstruturaProcessoPanel.java +++ b/trunk/siprp/medicina/processo/estrutura/EstruturaProcessoPanel.java @@ -36,7 +36,7 @@ public class EstruturaProcessoPanel extends JPanel protected static final DateFormat D_F = DateFormat.getDateInstance( DateFormat.SHORT, new Locale( "pt", "PT" ) ); protected JScrollPane mainScroll; - protected DefaultMutableTreeNode rootNode; + protected TrabalhadorMutableTreeNode rootNode; protected JTree mainTree; protected ProcessoDataProvider provider; @@ -74,48 +74,28 @@ public class EstruturaProcessoPanel extends JPanel public void setTrabalhador( IDObject trabalhador ) { + clear(); + if( trabalhador == null ) + { + return; + } this.trabalhador = trabalhador; // rootNode.removeAllChildren(); // PROCESSOS_POR_ID.clear(); -// rootNode.setUserObject( trabalhador ); -// DefaultMutableTreeNode nodes[] = -// loadProcessos( trabalhador.getID() ); -// rootNode.add( new DefaultMutableTreeNode( new MappableObject( new Integer( -1 ), "Novo Processo..." ) ) ); -// for( int n = 0; n < nodes.length; n++ ) -// { -// rootNode.add( nodes[ n ] ); -// } -// int count = mainTree.getRowCount(); -// for( int n = count - 1; n >= 0; n-- ) -// { -// mainTree.expandRow( n ); -// } - - ProcessoMutableTreeNode p1 = new ProcessoMutableTreeNode( new Integer( 1 ), "Ocasional" ); - rootNode.add( p1 ); - ECDsMutableTreeNode e1 = new ECDsMutableTreeNode( new Integer( 2 ), "ECDs" ); - p1.add( e1 ); - DataMutableTreeNode d1 = new DataMutableTreeNode( new Integer( 8 ), "2006/01/01" ); - e1.add( d1 ); - ObservacoesMutableTreeNode o1 = new ObservacoesMutableTreeNode( new Integer( 16 ), "N\u00e3o apareceu" ); - d1.add( o1 ); - MailMutableTreeNode m1 = new MailMutableTreeNode( new Integer( 35 ), "teste@123.com" ); - d1.add( m1 ); - - DataMutableTreeNode d2 = new DataMutableTreeNode( new Integer( 8 ), "2006/04/01" ); - e1.add( d2 ); - MailMutableTreeNode m2 = new MailMutableTreeNode( new Integer( 35 ), "teste@123.com" ); - d2.add( m2 ); - - ConsultaMutableTreeNode c1 = new ConsultaMutableTreeNode( new Integer( 2 ), "Consulta" ); - p1.add( c1 ); - DataMutableTreeNode d3 = new DataMutableTreeNode( new Integer( 8 ), "2006/05/01" ); - c1.add( d3 ); - MailMutableTreeNode m3 = new MailMutableTreeNode( new Integer( 35 ), "teste@123.com" ); - c1.add( m3 ); - - FichaAptidaoMutableTreeNode f1 = new FichaAptidaoMutableTreeNode( new Integer( 1 ), "Ficha de Aptid\u00e3o - Apto" ); - p1.add( f1 ); + rootNode.setID( trabalhador.getID() ); + rootNode.setDescricao( trabalhador.toString() ); + DefaultMutableTreeNode nodes[] = + loadProcessos( trabalhador.getID() ); + rootNode.add( new ProcessoMutableTreeNode( new Integer( -1 ), "Novo Processo..." ) ); + for( int n = 0; n < nodes.length; n++ ) + { + rootNode.add( nodes[ n ] ); + } + int count = mainTree.getRowCount(); + for( int n = count - 1; n >= 0; n-- ) + { + mainTree.expandRow( n ); + } repaint(); } @@ -139,9 +119,7 @@ public class EstruturaProcessoPanel extends JPanel desc += " - " + D_F.format( dataFim ); } desc += ": " + estado; - IDObject processoObject = - new MappableObject( ids[ n ], desc ); - nodes[ n ] = new DefaultMutableTreeNode( processoObject ); + nodes[ n ] = new ProcessoMutableTreeNode( ids[ n ], desc ); PROCESSOS_POR_ID.put( ids[ n ], processo ); } return nodes; @@ -153,9 +131,78 @@ public class EstruturaProcessoPanel extends JPanel } } - public void valueChanged(TreeSelectionEvent e) + public void valueChanged( TreeSelectionEvent e ) { - + Object components[] = e.getPath().getPath(); + int tipo = ProcessoEvent.ACCAO_ESCOLHER_PROCESSO; + if( components == null || components.length == 0 || + components[ components.length - 1 ] instanceof TrabalhadorMutableTreeNode || + components[ components.length - 1 ] instanceof ProcessoMutableTreeNode ) + { + tipo = ProcessoEvent.ACCAO_ESCOLHER_PROCESSO; + } + else if( components[ components.length - 1 ] instanceof ConsultaMutableTreeNode ) + { + tipo = ProcessoEvent.ACCAO_ESCOLHER_CONSULTA; + } + else if( components[ components.length - 1 ] instanceof ECDsMutableTreeNode ) + { + tipo = ProcessoEvent.ACCAO_ESCOLHER_ECDS; + } + else if( components[ components.length - 1 ] instanceof FichaAptidaoMutableTreeNode ) + { + tipo = ProcessoEvent.ACCAO_ESCOLHER_FA; + } + else if( components[ components.length - 1 ] instanceof DataMutableTreeNode ) + { + tipo = ProcessoEvent.ACCAO_ESCOLHER_DATA; + } + else if( components[ components.length - 1 ] instanceof ObservacoesMutableTreeNode ) + { + tipo = ProcessoEvent.ACCAO_ESCOLHER_OBSERVACOES; + } + else if( components[ components.length - 1 ] instanceof MailMutableTreeNode ) + { + tipo = ProcessoEvent.ACCAO_ESCOLHER_MAIL; + } + HashMap ids = new HashMap(); + for( int n = 0; components != null && n < components.length; n++ ) + { + Integer id = ( ( EstruturaProcessoMutableTreeNode ) components[ n ] ).getID(); + if( components[ components.length - 1 ] instanceof ProcessoMutableTreeNode ) + { + ids.put( ProcessoEvent.TIPO_PROCESSO, id ); + } + else if( components[ components.length - 1 ] instanceof ConsultaMutableTreeNode ) + { + ids.put( ProcessoEvent.TIPO_CONSULTA, id ); + } + else if( components[ components.length - 1 ] instanceof ECDsMutableTreeNode ) + { + ids.put( ProcessoEvent.TIPO_ECDS, id ); + } + else if( components[ components.length - 1 ] instanceof FichaAptidaoMutableTreeNode ) + { + ids.put( ProcessoEvent.TIPO_FICHA_APTIDAO, id ); + } + else if( components[ components.length - 1 ] instanceof DataMutableTreeNode ) + { + ids.put( ProcessoEvent.TIPO_DATA, id ); + } + else if( components[ components.length - 1 ] instanceof ObservacoesMutableTreeNode ) + { + ids.put( ProcessoEvent.TIPO_OBSERVACOES, id ); + } + else if( components[ components.length - 1 ] instanceof MailMutableTreeNode ) + { + ids.put( ProcessoEvent.TIPO_MAIL, id ); + } + } + ProcessoEvent event = new ProcessoEvent( this, tipo, ids ); + for( int n = 0; n < PROCESSO_LISTENERS.size(); n++ ) + { + PROCESSO_LISTENERS.get( n ).processoStateChanged( event ); + } } public TrabalhadoresProcessoData getProcessoEscolhido() @@ -184,6 +231,11 @@ public class EstruturaProcessoPanel extends JPanel PROCESSO_LISTENERS.add( listener ); } + public void removeProcessoListener( ProcessoListener listener ) + { + PROCESSO_LISTENERS.remove( listener ); + } + public IDObject getTrabalhador() { return trabalhador; @@ -192,4 +244,13 @@ public class EstruturaProcessoPanel extends JPanel public void reload() { } + + public void clear() + { + this.trabalhador = null; + rootNode.removeAllChildren(); + PROCESSOS_POR_ID.clear(); + rootNode.setID( null ); + rootNode.setDescricao( "" ); + } }