From 07b9c89c19dad4dd294304124aefb7ea7b5f7ea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tiago=20Sim=C3=A3o?= Date: Fri, 28 Dec 2007 15:37:54 +0000 Subject: [PATCH] git-svn-id: https://svn.coded.pt/svn/SIPRP@631 bb69d46d-e84e-40c8-a05a-06db0d633741 --- .../cayenne/objects/TrabalhadoresEcds.java | 1 + .../objects/TrabalhadoresEcdsDatas.java | 1 + .../processo/logic/MedicinaProcessoLogic.java | 1 + .../medicina/processo/ui/LeafInputField.java | 8 +- .../processo/ui/LeafOptionDialog.java | 92 +++++++++---------- .../medicina/processo/ui/OrderedMap.java | 42 ++++++++- .../processo/ui/ProcessoAccoesPanel.java | 2 + .../processo/ui/ProcessoDadosPanel.java | 20 +++- 8 files changed, 112 insertions(+), 55 deletions(-) diff --git a/trunk/SIPRPSoft/src/siprp/database/cayenne/objects/TrabalhadoresEcds.java b/trunk/SIPRPSoft/src/siprp/database/cayenne/objects/TrabalhadoresEcds.java index 66fe5d21..61a6c02b 100755 --- a/trunk/SIPRPSoft/src/siprp/database/cayenne/objects/TrabalhadoresEcds.java +++ b/trunk/SIPRPSoft/src/siprp/database/cayenne/objects/TrabalhadoresEcds.java @@ -128,6 +128,7 @@ public class TrabalhadoresEcds extends _TrabalhadoresEcds implements MedicinaCon setEstado( ESTADO_POR_REALIZAR ); } } + grupos.order(); return grupos; } diff --git a/trunk/SIPRPSoft/src/siprp/database/cayenne/objects/TrabalhadoresEcdsDatas.java b/trunk/SIPRPSoft/src/siprp/database/cayenne/objects/TrabalhadoresEcdsDatas.java index 59cd44ee..e947a401 100755 --- a/trunk/SIPRPSoft/src/siprp/database/cayenne/objects/TrabalhadoresEcdsDatas.java +++ b/trunk/SIPRPSoft/src/siprp/database/cayenne/objects/TrabalhadoresEcdsDatas.java @@ -70,6 +70,7 @@ public class TrabalhadoresEcdsDatas extends _TrabalhadoresEcdsDatas implements M } } } + grupos.order(); return grupos; } diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/logic/MedicinaProcessoLogic.java b/trunk/SIPRPSoft/src/siprp/medicina/processo/logic/MedicinaProcessoLogic.java index 30eeb680..9a9cd059 100755 --- a/trunk/SIPRPSoft/src/siprp/medicina/processo/logic/MedicinaProcessoLogic.java +++ b/trunk/SIPRPSoft/src/siprp/medicina/processo/logic/MedicinaProcessoLogic.java @@ -489,6 +489,7 @@ public class MedicinaProcessoLogic extends SIPRPLogic currentExameMarcacao.setToPrestadores( getPrestador(false) ); currentExameMarcacao.setToAnalisador( getAnalisador() ); currentExameMarcacao.setEstado( MedicinaConstants.ESTADO_POR_REALIZAR ); + runActionLater( SAVE_EXAME_MARCACAO ); return currentExameMarcacao; } diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/ui/LeafInputField.java b/trunk/SIPRPSoft/src/siprp/medicina/processo/ui/LeafInputField.java index 139ca92c..5fe0ca02 100644 --- a/trunk/SIPRPSoft/src/siprp/medicina/processo/ui/LeafInputField.java +++ b/trunk/SIPRPSoft/src/siprp/medicina/processo/ui/LeafInputField.java @@ -172,10 +172,10 @@ public class LeafInputField extends JPanel implements F { startColor = getGradientStartColor(); endColor = getGradientEndColor( startColor ); - outerContour = new GradientPaint( width / 4, 0, Color.GRAY, width, height, this.getParent().getBackground() ); - outerReversedContour = new GradientPaint( 15, 0, this.getParent().getBackground(), width / 4, height, Color.GRAY ); - innerContour = new GradientPaint( width / 4, 0, Color.LIGHT_GRAY, width, height, this.getParent().getBackground() ); - innerReversedContour = new GradientPaint( 15, 0, this.getParent().getBackground(), width / 4, height, Color.LIGHT_GRAY ); + outerContour = new GradientPaint( width / 4, 0, Color.GRAY, width, 0, this.getParent().getBackground() ); + outerReversedContour = new GradientPaint( 15, 0, this.getParent().getBackground(), width / 4, 0, Color.GRAY ); + innerContour = new GradientPaint( width / 4, 0, Color.LIGHT_GRAY, width, 0, this.getParent().getBackground() ); + innerReversedContour = new GradientPaint( 15, 0, this.getParent().getBackground(), width / 4, 0, Color.LIGHT_GRAY ); gradient = new GradientPaint( 0, 0, startColor, width, height, endColor ); } diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/ui/LeafOptionDialog.java b/trunk/SIPRPSoft/src/siprp/medicina/processo/ui/LeafOptionDialog.java index 11ff0283..9fa04fe1 100644 --- a/trunk/SIPRPSoft/src/siprp/medicina/processo/ui/LeafOptionDialog.java +++ b/trunk/SIPRPSoft/src/siprp/medicina/processo/ui/LeafOptionDialog.java @@ -3,6 +3,7 @@ package siprp.medicina.processo.ui; import info.clearthought.layout.TableLayout; import info.clearthought.layout.TableLayoutConstraints; +import java.awt.Dimension; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.ArrayList; @@ -16,13 +17,17 @@ import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JLabel; +import javax.swing.JSeparator; public class LeafOptionDialog extends JDialog { + private static final Dimension OPTION_SIZE = new Dimension(0,20); + private static final Dimension BUTTON_SIZE = new Dimension(0,20); + private static final long serialVersionUID = 1L; private static final String CANCEL_LABEL = "Cancelar"; - + private static String okLabel = "Ok"; private final JLabel labelMessage = new JLabel(); @@ -37,64 +42,46 @@ public class LeafOptionDialog extends JDialog private List selected = new ArrayList(); + private Map mapEnabledForKey = new HashMap(); + + private Map mapChosenForKey = new HashMap(); + private String message = null; private boolean ordered = false; public LeafOptionDialog(Map map) { - super( ); - startup( map, null ); - } - - public LeafOptionDialog( Map map, String message, boolean cancelActive) - { - super( ); - this.cancelActive = cancelActive; - this.message = message; - startup( map, null ); - } - - public LeafOptionDialog( Map map, String message, String okButton, boolean cancelActive) - { - super( ); - this.cancelActive = cancelActive; - this.message = message; - this.okLabel = okButton; + super(); startup( map, null ); } public LeafOptionDialog(Map map, String message) { - super( ); + super(); this.message = message; startup( map, null ); } - public LeafOptionDialog(OrderedMap orderedMap, String message) + public LeafOptionDialog(OrderedMap orderedMap, Map chosen, Map enabled, String message, String okButton) { - super( ); - ordered = true; - this.message = message; - startup( null, orderedMap ); - } - - /** Creates a new instance of JCalendarDialog */ - public LeafOptionDialog(Map map, String message, String okButton) - { - super( ); - this.message = message; - this.okLabel = okButton; - startup( map, null ); - } - - /** Creates a new instance of JCalendarDialog */ - public LeafOptionDialog(OrderedMap orderedMap, String message, String okButton) - { - super( ); + super(); ordered = true; this.message = message; this.okLabel = okButton; + this.mapChosenForKey = chosen; + this.mapEnabledForKey = enabled; + if( chosen != null ) + { + for( KeyClass key : chosen.keySet() ) + { + Boolean isChosen = chosen.get( key ); + if( isChosen != null && isChosen ) + { + selected.add( key ); + } + } + } startup( null, orderedMap ); } @@ -116,24 +103,23 @@ public class LeafOptionDialog extends JDialog { this.orderedMap = orderedMap; } - setupComponents( map == null ? orderedMap.keySet() : map.keySet(), map == null ? true : false ); + setupComponents( map == null ? orderedMap.iterator() : map.keySet().iterator(), map == null ? orderedMap.rows() : map.keySet().size(), map == null ? true : false ); setModal( true ); setUndecorated( true ); setVisible( true ); } - private void setupComponents( Set keySet, boolean ordered ) + private void setupComponents( Iterator iterator, Integer size, boolean ordered ) { - Iterator iterator = keySet.iterator(); KeyClass current = null; double[] cols = new double[] { TableLayout.FILL }; - double[] rows = new double[(message == null ? 0 : 1) + keySet.size() + (cancelActive ? 1 : 0)]; + double[] rows = new double[(message == null ? 0 : 2) + size + (cancelActive ? 2 : 0)]; for( int i = 0; i < rows.length; ++i ) { - rows[i] = TableLayout.FILL; + rows[i] = TableLayout.PREFERRED; } TableLayout layout = new TableLayout( cols, rows ); layout.setVGap( 3 ); @@ -145,8 +131,9 @@ public class LeafOptionDialog extends JDialog { labelMessage.setText( message ); getContentPane().add( labelMessage, new TableLayoutConstraints( 0, shift++ ) ); + getContentPane().add( new JSeparator(), new TableLayoutConstraints( 0, shift++ ) ); } - for( int i = 0; i < keySet.size() && iterator.hasNext(); ++i ) + for( int i = 0; i < size && iterator.hasNext(); ++i ) { current = iterator.next(); LeafInputField component = new LeafInputField(); @@ -161,15 +148,24 @@ public class LeafOptionDialog extends JDialog value = map.get( current ); } component.setObject( value ); - component.setClickable( true ); + + Boolean isChosen = mapChosenForKey.get( current ); + component.setSelected( isChosen != null && isChosen ); + + Boolean isEnabled = mapEnabledForKey.get( current ); + component.setClickable( isEnabled != null && isEnabled ); + + component.setPreferredSize( OPTION_SIZE ); getContentPane().add( component, new TableLayoutConstraints( 0, i + shift ) ); addListenerToComponent( component ); } if( cancelActive ) { + getContentPane().add( new JSeparator(), new TableLayoutConstraints( 0, size + shift++ ) ); submitButton.setObject( ordered ? okLabel : CANCEL_LABEL ); submitButton.setClickable( true ); - getContentPane().add( submitButton, new TableLayoutConstraints( 0, keySet.size() + shift ) ); + submitButton.setPreferredSize( BUTTON_SIZE ); + getContentPane().add( submitButton, new TableLayoutConstraints( 0, size + shift ) ); addListenerToComponent( submitButton ); } ((JComponent) getContentPane()).setBorder( BorderFactory.createRaisedBevelBorder() ); diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/ui/OrderedMap.java b/trunk/SIPRPSoft/src/siprp/medicina/processo/ui/OrderedMap.java index 74c6b0dc..00ce257a 100644 --- a/trunk/SIPRPSoft/src/siprp/medicina/processo/ui/OrderedMap.java +++ b/trunk/SIPRPSoft/src/siprp/medicina/processo/ui/OrderedMap.java @@ -1,11 +1,16 @@ package siprp.medicina.processo.ui; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.Vector; +import com.evolute.utils.sql.expression.Or; + public class OrderedMap { private static final long serialVersionUID = 1L; @@ -75,9 +80,9 @@ public class OrderedMap return order.isEmpty() ? null : order.get( 0 ); } - public Set keySet() + public Iterator iterator() { - return map.keySet(); + return order.iterator(); } public boolean containsKey( KeyClass key ) @@ -111,5 +116,38 @@ public class OrderedMap order.remove( key ); return map.remove( key ); } + + /** + * Orders by first column (rows compared as strings) + */ + public void order() + { + if(order != null && order.size() > 0) + { + HashMap keyForObject = new HashMap(); + List sortedList = new ArrayList(); + for(KeyClass key : order) + { + List row = map.get( key ); + Object value = null; + if( row != null && row.size() > 0) + { + value = row.get( 0 ); + keyForObject.put( value.toString() , key ); + sortedList.add( value.toString() ); + } + } + if(sortedList.size() == order.size()) + { + Collections.sort( sortedList ); + Vector newOrder = new Vector(); + for(String value : sortedList) + { + newOrder.add( keyForObject.get( value ) ); + } + order = newOrder; + } + } + } } diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/ui/ProcessoAccoesPanel.java b/trunk/SIPRPSoft/src/siprp/medicina/processo/ui/ProcessoAccoesPanel.java index 3199d100..d035e93c 100755 --- a/trunk/SIPRPSoft/src/siprp/medicina/processo/ui/ProcessoAccoesPanel.java +++ b/trunk/SIPRPSoft/src/siprp/medicina/processo/ui/ProcessoAccoesPanel.java @@ -324,6 +324,8 @@ public class ProcessoAccoesPanel extends JPanel { if( exame != null ) { + boolean porMarcar = new Integer( MedicinaConstants.ESTADO_POR_MARCAR ).equals( exame.getEstado() ); + buttonNovoExameMarcacao.setEnabled( porMarcar ); cardLayout.show( cardPanel, PANEL_EXAME_NAME ); } else diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/ui/ProcessoDadosPanel.java b/trunk/SIPRPSoft/src/siprp/medicina/processo/ui/ProcessoDadosPanel.java index 0cb362f8..7ece6d52 100755 --- a/trunk/SIPRPSoft/src/siprp/medicina/processo/ui/ProcessoDadosPanel.java +++ b/trunk/SIPRPSoft/src/siprp/medicina/processo/ui/ProcessoDadosPanel.java @@ -39,6 +39,8 @@ import info.clearthought.layout.TableLayoutConstraints; import java.awt.CardLayout; import java.util.Date; import java.util.HashMap; +import java.util.List; +import java.util.Map; import javax.swing.BorderFactory; import javax.swing.JComponent; @@ -58,6 +60,7 @@ import siprp.database.cayenne.objects.TrabalhadoresEcdsDatasEmails; import siprp.database.cayenne.objects.TrabalhadoresEcdsDatasObservacoes; import siprp.database.cayenne.objects.TrabalhadoresProcesso; import siprp.logic.SIPRPLogic.LeafUIActionBinding; +import siprp.medicina.MedicinaConstants; import siprp.medicina.processo.mail.MailDialog; import siprp.ui.SIPRPWindow; import siprp.ui.SIPRPWindow.ActionActivation; @@ -470,7 +473,22 @@ public class ProcessoDadosPanel extends JPanel marcacao.setData( date ); OrderedMap grupos = marcacao.getToTrabalhadoresEcds().getGruposExamesForPerfil(); - LeafOptionDialog gruposChosen = new LeafOptionDialog( grupos, "Escolha os ECDs para esta marca" +ccedil + atilde + "o" , "Marcar »" ); + Map gruposSelected = new HashMap(); + Map gruposEnabled = new HashMap(); + for(int row = 0; row < grupos.rows(); ++row) + { + List grupo = grupos.getValuesAt( row ); + if( grupo != null && grupo.size() > 1) + { + String estado = grupo.get( 1 ).toString(); + if(MedicinaConstants.ESTADOS_EXAME_STR[MedicinaConstants.ESTADO_POR_MARCAR].equals( estado )) + { + gruposSelected.put( grupos.getKeyForValue( grupo ), true ); + gruposEnabled.put( grupos.getKeyForValue( grupo ), true ); + } + } + } + LeafOptionDialog gruposChosen = new LeafOptionDialog( grupos, gruposSelected, gruposEnabled, "Escolha os ECDs para esta marca" +ccedil + atilde + "o" , "Marcar »" ); for( PrtGruposProtocolo grupo : gruposChosen.getSelected() ) { marcacao.marcarGrupoExames( grupo );