From e6ea2e43c48fcf672aa1e99b48722adc89efa5b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tiago=20Sim=C3=A3o?= Date: Thu, 25 Sep 2008 18:46:48 +0000 Subject: [PATCH] git-svn-id: https://svn.coded.pt/svn/SIPRP@750 bb69d46d-e84e-40c8-a05a-06db0d633741 --- .../src/siprp/FichaDataProvider.java | 5 +- .../src/siprp/clientes/ClientesWindow.java | 107 ++-- .../src/siprp/clientes/EmpresaPanel.java | 187 +++---- .../EstabelecimentoPlanoActuacaoPanel.java | 491 ++++++++++++++++++ .../src/siprp/clientes/ImagePanel.java | 215 ++++++++ 5 files changed, 877 insertions(+), 128 deletions(-) create mode 100644 trunk/SIPRPSoft/src/siprp/clientes/EstabelecimentoPlanoActuacaoPanel.java create mode 100644 trunk/SIPRPSoft/src/siprp/clientes/ImagePanel.java diff --git a/trunk/SIPRPSoft/src/siprp/FichaDataProvider.java b/trunk/SIPRPSoft/src/siprp/FichaDataProvider.java index 37d444cc..c401f7f9 100644 --- a/trunk/SIPRPSoft/src/siprp/FichaDataProvider.java +++ b/trunk/SIPRPSoft/src/siprp/FichaDataProvider.java @@ -724,14 +724,15 @@ public class FichaDataProvider Long result = 0L; try { - Select2 query = new Select2( new String[]{"trabalhadores", "estabelecimentos", "empresas" }, + Select2 query = new Select2( new String[]{ "trabalhadores", "estabelecimentos", "empresas" }, new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER }, new Expression[]{ new Field("estabelecimentos.id").isEqual(new Field("trabalhadores.estabelecimento_id")), new Field("empresas.id").isEqual( new Field("estabelecimentos.empresa_id") ) }, new String[]{"count(trabalhadores.id)" }, new Field("empresas.id").isEqual( empresaID ). - and( new Field("trabalhadores.inactivo").isEqual( "n" ) ), + and( new Field("trabalhadores.inactivo").isEqual( "n" ) ). + and( new Field("trabalhadores.data_demissao").isEqual( null )), null, null, null, null); Virtual2DArray returned = executer.executeQuery( query ); if( returned.columnLength() > 0 ) diff --git a/trunk/SIPRPSoft/src/siprp/clientes/ClientesWindow.java b/trunk/SIPRPSoft/src/siprp/clientes/ClientesWindow.java index 65f12e84..47c68cc5 100644 --- a/trunk/SIPRPSoft/src/siprp/clientes/ClientesWindow.java +++ b/trunk/SIPRPSoft/src/siprp/clientes/ClientesWindow.java @@ -6,32 +6,61 @@ package siprp.clientes; -import java.awt.*; -import java.io.*; -import java.text.*; -import java.util.*; -import javax.swing.*; -import javax.swing.event.*; +import static com.evolute.utils.strings.UnicodeLatin1Map.atilde; +import static com.evolute.utils.strings.UnicodeLatin1Map.ccedil; -import com.evolute.utils.*; -import com.evolute.utils.data.*; -import com.evolute.utils.dataui.*; -import com.evolute.utils.date.*; -import com.evolute.utils.fop.*; -import com.evolute.utils.jdo.*; -import com.evolute.utils.strings.*; -import com.evolute.utils.ui.*; -import com.evolute.utils.ui.dialog.*; -import com.evolute.utils.ui.panel.*; -import com.evolute.utils.ui.search.*; -import com.evolute.utils.ui.text.*; -import com.evolute.utils.ui.window.*; -import com.evolute.utils.xml.*; +import java.awt.Dimension; +import java.awt.FileDialog; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.io.File; +import java.io.FilenameFilter; +import java.text.DateFormat; +import java.util.Arrays; +import java.util.Date; +import java.util.Hashtable; +import java.util.Locale; +import java.util.Vector; -import siprp.*; -import siprp.data.*; -import siprp.ficha.*; -import siprp.importer.*; +import javax.swing.BorderFactory; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTabbedPane; +import javax.swing.JTextField; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +import siprp.FichaDataProvider; +import siprp.SIPRPTracker; +import siprp.SingletonConstants; +import siprp.data.AvisoConstants; +import siprp.data.ContactoData; +import siprp.data.EmpresaData; +import siprp.data.EstabelecimentoData; +import siprp.data.EtiquetaData; +import siprp.data.ExameData; +import siprp.data.SearchExecuterFactory; +import siprp.data.TrabalhadorData; +import siprp.ficha.ExamePDF; +import siprp.importer.Importer; + +import com.evolute.utils.Singleton; +import com.evolute.utils.data.IDObject; +import com.evolute.utils.dataui.ControllableComponent; +import com.evolute.utils.date.DateUtils; +import com.evolute.utils.jdo.JDOObject; +import com.evolute.utils.jdo.JDOProvider; +import com.evolute.utils.strings.StringPlainer; +import com.evolute.utils.ui.DialogException; +import com.evolute.utils.ui.dialog.ListAction; +import com.evolute.utils.ui.dialog.ListActionDialog; +import com.evolute.utils.ui.dialog.LongMessageDialog; +import com.evolute.utils.ui.search.SearchDialog; +import com.evolute.utils.ui.text.CopyPasteHandler; +import com.evolute.utils.ui.window.ActionHandler; +import com.evolute.utils.ui.window.EditorWindow; /** * @@ -40,10 +69,15 @@ import siprp.importer.*; public class ClientesWindow extends EditorWindow implements ListSelectionListener { + /** + * + */ + private static final long serialVersionUID = 1L; + private static final DateFormat DF = DateFormat.getDateInstance( DateFormat.SHORT, new Locale( "pt", "PT" ) ); - public static final Hashtable TR_IMPORT_NAMES_TO_TRAB = new Hashtable(); - public static final Hashtable TR_IMPORT_NAMES_TO_DEMISSOES = new Hashtable(); + public static final Hashtable TR_IMPORT_NAMES_TO_TRAB = new Hashtable(); + public static final Hashtable TR_IMPORT_NAMES_TO_DEMISSOES = new Hashtable(); static { @@ -74,6 +108,8 @@ public class ClientesWindow extends EditorWindow public static final int INDEX_ESTABELECIMENTO = 1; public static final int INDEX_TRABALHADOR = 2; + private static final String ESTABELECIMENTO_PLANO_ACTUACAO_TAB_NOME = "Plano de Actua"+ccedil+atilde+"o"; + private static int hierarchy[] = new int[]{0,0,1}; private static int permissions[][] = new int[][]{ { NEW_INDEX, EDIT_INDEX, CANCEL_INDEX, SAVE_INDEX, SELECT_BYNAME_INDEX, DELETE_INDEX }, @@ -100,6 +136,8 @@ public class ClientesWindow extends EditorWindow private AvisosPanel avisos; protected boolean webAware; + + private EstabelecimentoPlanoActuacaoPanel planoActuacaoPanel; // public static void main( String args[] ) // throws Exception @@ -119,7 +157,7 @@ public class ClientesWindow extends EditorWindow clientesProvider = ( ClientesDataProvider ) ClientesDataProvider.getProvider(); setEditorManagerHierarchy( hierarchy ); setupComponents(); - this.setExtendedState(this.getExtendedState() | this.MAXIMIZED_BOTH); + this.setExtendedState(this.getExtendedState() | ClientesWindow.MAXIMIZED_BOTH); } private void setupComponents() @@ -149,6 +187,8 @@ public class ClientesWindow extends EditorWindow trabalhadorPanel = new TrabalhadorPanel( toolbarTrabalhador, empresaPanel.getEstabelecimentosTable() ); + planoActuacaoPanel = new EstabelecimentoPlanoActuacaoPanel(); + GridBagLayout gridbag = new GridBagLayout(); getContentPane().setLayout( gridbag ); GridBagConstraints constraints = new GridBagConstraints(); @@ -194,6 +234,7 @@ public class ClientesWindow extends EditorWindow tabbedPane.add( "Dados", estabelecimentoPanel ); tabbedPane.add( "Trabalhadores", trabalhadorPanel ); + tabbedPane.add( ESTABELECIMENTO_PLANO_ACTUACAO_TAB_NOME, planoActuacaoPanel ); panels[ INDEX_EMPRESA ] = empresaPanel; panels[ INDEX_ESTABELECIMENTO ] = estabelecimentoPanel; @@ -436,25 +477,23 @@ public class ClientesWindow extends EditorWindow public void reload( int index ) { -//System.out.println( "RELOAD: " + index + " e: " + empresa + " e: " +estabelecimento + " t: " + trabalhador ); + // System.out.println( "RELOAD: " + index + " e: " + empresa + " e: " +estabelecimento + " t: " + trabalhador ); switch( index ) { case INDEX_EMPRESA: empresaPanel.fill( new Object[]{ empresa, elementosProtocolo } ); estabelecimentoPanel.setEmpresa( empresa ); break; - case INDEX_ESTABELECIMENTO: -// trabalhadorPanel.fill( null ); + // trabalhadorPanel.fill( null ); estabelecimentoPanel.fill( estabelecimento ); trabalhadorPanel.setEstabelecimento( estabelecimento ); + planoActuacaoPanel.fill( estabelecimento == null ? null : estabelecimento.get( EstabelecimentoData.ID ) ); break; - case INDEX_TRABALHADOR: trabalhadorPanel.fill( trabalhador ); -// trabalhadorPanel.reload(); + // trabalhadorPanel.reload(); break; - } } @@ -722,7 +761,7 @@ public class ClientesWindow extends EditorWindow { Importer importer = new Importer( this, filename, true, Importer.TYPE_ADMISSAO ); Hashtable hash[] = importer.getMultipleData(); - Vector activate = new Vector(); + Vector activate = new Vector(); if( hash != null ) { // load all (active) trabalhadores for this company diff --git a/trunk/SIPRPSoft/src/siprp/clientes/EmpresaPanel.java b/trunk/SIPRPSoft/src/siprp/clientes/EmpresaPanel.java index 1460214a..40fc872b 100644 --- a/trunk/SIPRPSoft/src/siprp/clientes/EmpresaPanel.java +++ b/trunk/SIPRPSoft/src/siprp/clientes/EmpresaPanel.java @@ -6,23 +6,59 @@ package siprp.clientes; -import java.awt.*; -import javax.swing.*; -import javax.swing.event.*; -import java.util.*; +import info.clearthought.layout.TableLayout; +import info.clearthought.layout.TableLayoutConstraints; -import com.evolute.utils.*; -import com.evolute.utils.data.*; -import com.evolute.utils.dataui.*; -import com.evolute.utils.documents.*; -import com.evolute.utils.jdo.*; -import com.evolute.utils.tables.*; -import com.evolute.utils.ui.*; -import com.evolute.utils.ui.calendar.*; -import com.evolute.utils.ui.text.*; +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.GridLayout; +import java.awt.Insets; +import java.util.Arrays; +import java.util.Collection; +import java.util.Hashtable; +import java.util.Vector; -import siprp.*; -import siprp.data.*; +import javax.swing.BorderFactory; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +import siprp.FichaDataProvider; +import siprp.SingletonConstants; +import siprp.data.EmpresaData; +import siprp.data.EstabelecimentoData; +import siprp.data.MarcacaoEmpresa; +import siprp.data.MarcacaoEmpresaData; +import siprp.database.cayenne.objects.Image; +import siprp.database.cayenne.providers.ImageDAO; + +import com.evolute.utils.Singleton; +import com.evolute.utils.data.IDObject; +import com.evolute.utils.data.MappableObject; +import com.evolute.utils.dataui.ComponentController; +import com.evolute.utils.dataui.ComponentsHashtable; +import com.evolute.utils.dataui.ControllableComponent; +import com.evolute.utils.documents.DoubleDocument; +import com.evolute.utils.documents.IntegerDocument; +import com.evolute.utils.documents.MaximumLengthDocument; +import com.evolute.utils.jdo.JDOProvider; +import com.evolute.utils.tables.BaseTable; +import com.evolute.utils.tables.ColumnizedObject; +import com.evolute.utils.tables.VectorTableModel; +import com.evolute.utils.ui.DialogException; +import com.evolute.utils.ui.calendar.JCalendarPanel; +import com.evolute.utils.ui.text.CopyPasteHandler; +import com.evolute.utils.ui.text.StateTextField; /** * @@ -78,7 +114,10 @@ public class EmpresaPanel extends JPanel private MarcacaoEmpresaPanel marcacaoPanel; private CardLayout marcacoesCardLayout; private ProtocoloPanel protocoloPanel; - private JLabel labelTrabalhadoresActivos = new JLabel( getTextForTrabalhadoresActivos(0) ); + + private final ImagePanel logotipo = new ImagePanel( true ); + private final JLabel labelTrabalhadoresActivos = new JLabel( getTextForTrabalhadoresActivos(0) ); + private final ImageDAO imageDAO = new ImageDAO(); // private UserPanel userPanel; private BaseTable estabelecimentosTable; @@ -235,86 +274,45 @@ public class EmpresaPanel extends JPanel JPanel pad; JPanel upperPanel = new JPanel(); - GridBagLayout gridbag = new GridBagLayout(); - upperPanel.setLayout( gridbag ); - GridBagConstraints constraints = new GridBagConstraints(); - constraints.insets = new Insets( 1, 1, 1, 1 ); - constraints.fill = GridBagConstraints.HORIZONTAL; - constraints.weighty = 0; - constraints.gridheight = 1; - - constraints.weightx = 0; - constraints.gridwidth = 1; - gridbag.setConstraints( designacaoSocialLabel, constraints ); - upperPanel.add( designacaoSocialLabel ); - - constraints.weightx = 0.9; - constraints.gridwidth = 5; - gridbag.setConstraints( designacaoSocialText, constraints ); - upperPanel.add( designacaoSocialText ); - - constraints.weightx = 0; - constraints.gridwidth = 1; - gridbag.setConstraints( codigoLabel, constraints ); - upperPanel.add( codigoLabel ); - - constraints.weightx = 0.1; - constraints.gridwidth = GridBagConstraints.REMAINDER; - gridbag.setConstraints( codigoPanel, constraints ); - upperPanel.add( codigoPanel ); - - constraints.weightx = 0; - constraints.gridwidth = 1; -// gridbag.setConstraints( moradaLabel, constraints ); -// upperPanel.add( moradaLabel ); - gridbag.setConstraints( caeLabel, constraints ); - upperPanel.add( caeLabel ); - constraints.weightx = 0.2; - constraints.gridwidth = 1; - gridbag.setConstraints( caeText, constraints ); - upperPanel.add( caeText ); - - constraints.weightx = 0; - constraints.gridwidth = 1; -// gridbag.setConstraints( moradaLabel, constraints ); -// upperPanel.add( moradaLabel ); - gridbag.setConstraints( actividadeLabel, constraints ); - upperPanel.add( actividadeLabel ); + TableLayout tableLayout = new TableLayout( + new double[] + { + TableLayout.PREFERRED, TableLayout.MINIMUM, TableLayout.MINIMUM, + TableLayout.PREFERRED, TableLayout.MINIMUM, TableLayout.FILL, + TableLayout.MINIMUM, TableLayout.PREFERRED, + TableLayout.MINIMUM, TableLayout.PREFERRED + }, + new double[] + { + TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.PREFERRED + } + ); + tableLayout.setHGap( 5 ); + tableLayout.setVGap( 3 ); + upperPanel.setLayout( tableLayout ); + + upperPanel.add( logotipo, new TableLayoutConstraints( 0, 0, 0, 2 ) ); + upperPanel.add( designacaoSocialLabel, new TableLayoutConstraints( 1, 0, 2, 0 ) ); + upperPanel.add( designacaoSocialText, new TableLayoutConstraints( 3, 0, 5, 0 ) ); + upperPanel.add( codigoLabel, new TableLayoutConstraints( 6, 0 ) ); + upperPanel.add( codigoPanel, new TableLayoutConstraints( 7, 0 ) ); + upperPanel.add( caeLabel, new TableLayoutConstraints( 1, 1 ) ); + caeText.setPreferredSize( new Dimension( 80, 0 ) ); + upperPanel.add( caeText, new TableLayoutConstraints( 2, 1, 3, 1 ) ); + upperPanel.add( actividadeLabel, new TableLayoutConstraints( 4, 1 ) ); + upperPanel.add( actividadeText, new TableLayoutConstraints( 5, 1 ) ); + upperPanel.add( contribuinteLabel, new TableLayoutConstraints( 6, 1 ) ); + contribuinteText.setPreferredSize( new Dimension( 120, 0 ) ); + upperPanel.add( contribuinteText, new TableLayoutConstraints( 7, 1 ) ); + upperPanel.add( segSocialLabel, new TableLayoutConstraints( 8, 1 ) ); + segSocialText.setPreferredSize( new Dimension(120,0) ); + upperPanel.add( segSocialText, new TableLayoutConstraints( 9, 1 ) ); - constraints.weightx = 0.6; - constraints.gridwidth = 1; - gridbag.setConstraints( actividadeText, constraints ); - upperPanel.add( actividadeText ); - - constraints.weightx = 0; - constraints.gridwidth = 1; -// gridbag.setConstraints( codigoPostalLabel, constraints ); -// upperPanel.add( codigoPostalLabel ); - gridbag.setConstraints( contribuinteLabel, constraints ); - upperPanel.add( contribuinteLabel ); - - constraints.weightx = 0.1; - constraints.gridwidth = 1; - gridbag.setConstraints( contribuinteText, constraints ); - upperPanel.add( contribuinteText ); - constraints.weightx = 0; - constraints.gridwidth = 2; -// gridbag.setConstraints( localLabel, constraints ); -// upperPanel.add( localLabel ); - gridbag.setConstraints( segSocialLabel, constraints ); - upperPanel.add( segSocialLabel ); - - constraints.weightx = 0.1; - constraints.gridwidth = 1; - gridbag.setConstraints( segSocialText, constraints ); - upperPanel.add( segSocialText ); - - - gridbag = new GridBagLayout(); + GridBagLayout gridbag = new GridBagLayout(); dadosEmpresaPanel.setLayout( gridbag ); - constraints = new GridBagConstraints(); + GridBagConstraints constraints = new GridBagConstraints(); constraints.insets = new Insets( 1, 1, 1, 1 ); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.weighty = 0; @@ -822,12 +820,15 @@ public class EmpresaPanel extends JPanel { Long numTrabalhadoresActivos = provider.countTrabalhadoresActivosForEmpresa( empresaID ); labelTrabalhadoresActivos.setText( getTextForTrabalhadoresActivos( numTrabalhadoresActivos ) ); + Image logo = imageDAO.getImageForEmpresaID( empresaID ); + logotipo.fill( logo == null ? null : logo.getImageData() ); } // if( webAware ) // { // userPanel.setEmpresaID( (Integer) empresa.get( EmpresaData.ID ) ); // userPanel.setEnabled( id != null ); // } + } public Object save() @@ -851,6 +852,7 @@ public class EmpresaPanel extends JPanel Integer elementosProtocolo[][] = new Integer[][]{ ( Integer [] ) dadosProtocolo[ 0 ].elementAt( 1 ), ( Integer [] ) dadosProtocolo[ 1 ].elementAt( 1 ) }; + imageDAO.setImageForEmpresaID( (Integer) empresa.get( EmpresaData.ID ), (byte[]) logotipo.save() ); return new Object[] { empresa, elementosProtocolo }; } @@ -860,6 +862,7 @@ public class EmpresaPanel extends JPanel String names[] = (String[])components.keySet().toArray( new String[0] ); ComponentController.setEnabled( names, enable, components ); protocoloPanel.setEnabled( enable ); + logotipo.setEnabled( enable ); //estabelecimentosTable.setEnabled( enable ); } diff --git a/trunk/SIPRPSoft/src/siprp/clientes/EstabelecimentoPlanoActuacaoPanel.java b/trunk/SIPRPSoft/src/siprp/clientes/EstabelecimentoPlanoActuacaoPanel.java new file mode 100644 index 00000000..c8992f49 --- /dev/null +++ b/trunk/SIPRPSoft/src/siprp/clientes/EstabelecimentoPlanoActuacaoPanel.java @@ -0,0 +1,491 @@ +package siprp.clientes; + +import static com.evolute.utils.strings.UnicodeLatin1Map.aacute; +import static com.evolute.utils.strings.UnicodeLatin1Map.atilde; +import static com.evolute.utils.strings.UnicodeLatin1Map.ccedil; +import static com.evolute.utils.strings.UnicodeLatin1Map.otilde; +import info.clearthought.layout.TableLayout; +import info.clearthought.layout.TableLayoutConstraints; + +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Vector; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.ScrollPaneConstants; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +import org.apache.cayenne.CayenneDataObject; + +import siprp.database.cayenne.objects.EmailPlanoDeActuacao; +import siprp.database.cayenne.objects.Estabelecimentos; +import siprp.database.cayenne.objects.Legislacao; +import siprp.database.cayenne.objects.LegislacaoEstabelecimento; +import siprp.database.cayenne.objects.PostoDeTrabalho; +import siprp.database.cayenne.objects.PostoDeTrabalhoEstabelecimento; +import siprp.database.cayenne.providers.PlanoActuacaoDAO; + +import com.evolute.utils.dataui.ControllableComponent; +import com.evolute.utils.tables.VectorTableModel; + +public class EstabelecimentoPlanoActuacaoPanel extends JPanel implements ControllableComponent +{ + + private static final long serialVersionUID = 1L; + + private static final Dimension PREFERRED_DIMENSION_EMAIL = new Dimension(200,0); + + private static final Dimension PREFERRED_DIMENSION_LEGISLACAO = new Dimension(400,0); + + private static final Dimension PREFERRED_DIMENSION_POSTO_TRABALHO = new Dimension(300,0); + + private final VectorTableModel modelEmail = new VectorTableModel( new String[]{ "Endere" + ccedil + "o" } ); + + private final VectorTableModel modelLegislacao = new VectorTableModel( new String[]{ "Descri" + ccedil + atilde + "o" } ); + + private final VectorTableModel modelPostoTrabalho= new VectorTableModel( new String[]{ "Descri" + ccedil + atilde + "o" } ); + + private final JTable tableEmail = new JTable( modelEmail ); + + private final JTable tableLegislacao = new JTable( modelLegislacao ); + + private final JTable tablePostoTrabalho = new JTable( modelPostoTrabalho ); + + private final JScrollPane scrollEmail = new JScrollPane( tableEmail, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER ); + + private final JScrollPane scrollLegislacao = new JScrollPane( tableLegislacao, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER ); + + private final JScrollPane scrollPostoTrabalho = new JScrollPane( tablePostoTrabalho, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER ); + + private final JPanel panelEmail = new JPanel(); + + private final JPanel panelLegislacao = new JPanel(); + + private final JPanel panelPostoTrabalho = new JPanel(); + + 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 buttonPostoTrabalhoAdicionar = new JButton("Adicionar"); + + private final JButton buttonEmailRemover = new JButton("Remover"); + + private final JButton buttonLegislacaoRemover = new JButton("Remover"); + + private final JButton buttonPostoTrabalhoRemover = new JButton("Remover"); + + private final PlanoActuacaoDAO provider = new PlanoActuacaoDAO(); + + private Estabelecimentos estabelecimento = null; + + public EstabelecimentoPlanoActuacaoPanel() + { + startupComponents(); + startupLayout(); + placeComponents(); + startupListeners(); + } + + private void startupLayout() + { + startupEmailLayout(); + startupPostoTrabalhoLayout(); + startupLegislacaoLayout(); + double [] cols = new double[]{ TableLayout.FILL, TableLayout.FILL, TableLayout.PREFERRED }; + double [] rows = new double[]{ TableLayout.FILL }; + TableLayout layout = new TableLayout(cols,rows); + layout.setHGap( 5 ); + layout.setVGap( 5 ); + this.setLayout( layout ); + } + + private void startupEmailLayout() + { + 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 ); + layout.setVGap( 5 ); + panelEmail.setLayout( layout ); + } + + private void startupPostoTrabalhoLayout() + { + double [] cols = new double[]{ 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 ); + layout.setVGap( 5 ); + panelPostoTrabalho.setLayout( layout ); + } + + private void startupLegislacaoLayout() + { + double [] cols = new double[]{ 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 ); + layout.setVGap( 5 ); + panelLegislacao.setLayout( layout ); + } + + private void startupComponents() + { + panelLegislacao.setPreferredSize( PREFERRED_DIMENSION_LEGISLACAO ); + panelLegislacao.setBorder( BorderFactory.createTitledBorder( "Legisla" + ccedil + otilde + "es" ) ); + + panelPostoTrabalho.setPreferredSize( PREFERRED_DIMENSION_POSTO_TRABALHO ); + panelPostoTrabalho.setBorder( BorderFactory.createTitledBorder( "Postos de trabalho" ) ); + + panelEmail.setPreferredSize( PREFERRED_DIMENSION_EMAIL ); + panelEmail.setBorder( BorderFactory.createTitledBorder( "E-mails" ) ); + + buttonEmailAdicionar.setEnabled( false ); + buttonEmailRemover.setEnabled( false ); + + buttonLegislacaoCriar.setEnabled( false ); + buttonLegislacaoAdicionar.setEnabled( false ); + buttonLegislacaoRemover.setEnabled( false ); + + buttonPostoTrabalhoCriar.setEnabled( false ); + buttonPostoTrabalhoAdicionar.setEnabled( false ); + buttonPostoTrabalhoRemover.setEnabled( false ); + } + + private void placeComponents() + { + + panelEmail.add( scrollEmail, new TableLayoutConstraints( 0, 0, 2, 0 ) ); + 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 ) ); + + panelPostoTrabalho.add( scrollPostoTrabalho, new TableLayoutConstraints( 0, 0, 3, 0 ) ); + panelPostoTrabalho.add( buttonPostoTrabalhoCriar, new TableLayoutConstraints( 0, 1 ) ); + panelPostoTrabalho.add( buttonPostoTrabalhoAdicionar, new TableLayoutConstraints( 1, 1 ) ); + panelPostoTrabalho.add( buttonPostoTrabalhoRemover, new TableLayoutConstraints( 2, 1 ) ); + + this.add( panelLegislacao, new TableLayoutConstraints( 0,0 ) ); + this.add( panelPostoTrabalho, new TableLayoutConstraints( 1,0 ) ); + this.add( panelEmail, new TableLayoutConstraints( 2,0 ) ); + + } + + private void refresh() + { + clear(); + load(); + } + + private void load() + { + if( estabelecimento != null ) + { + modelEmail.setValues( new Vector( estabelecimento.getEmailPlanoDeActuacaoArray() ) ); + modelLegislacao.setValues( new Vector( estabelecimento.getLegislacaoEstabelecimentoArray() ) ); + modelPostoTrabalho.setValues( new Vector( estabelecimento.getPostoDeTrabalhoEstabelecimentoArray() ) ); + } + } + + private void startupListeners() + { + buttonEmailAdicionar.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + adicionarEmail(); + } + } ); + buttonEmailRemover.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + removeSelected(tableEmail); + } + } ); + buttonLegislacaoCriar.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + criarLegislacao(); + } + } ); + buttonLegislacaoAdicionar.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + adicionarLegislacao(); + } + } ); + buttonLegislacaoRemover.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + removeSelected(tableLegislacao); + } + } ); + buttonPostoTrabalhoCriar.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + criarPostoTrabalho(); + } + } ); + buttonPostoTrabalhoAdicionar.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + adicionarPostoTrabalho(); + } + } ); + buttonPostoTrabalhoRemover.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + removeSelected(tablePostoTrabalho); + } + } ); + tableEmail.getSelectionModel().addListSelectionListener( new ListSelectionListener() + { + @Override + public void valueChanged( ListSelectionEvent e ) + { + if( !e.getValueIsAdjusting() ) + { + buttonEmailRemover.setEnabled( tableEmail.getSelectedRowCount() > 0 ); + } + } + } ); + tableLegislacao.getSelectionModel().addListSelectionListener( new ListSelectionListener() + { + @Override + public void valueChanged( ListSelectionEvent e ) + { + if( !e.getValueIsAdjusting() ) + { + buttonLegislacaoRemover.setEnabled( tableLegislacao.getSelectedRowCount() > 0 ); + } + } + } ); + tablePostoTrabalho.getSelectionModel().addListSelectionListener( new ListSelectionListener() + { + @Override + public void valueChanged( ListSelectionEvent e ) + { + if( !e.getValueIsAdjusting() ) + { + 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 ); + adicionarLegislacao( legislacao ); + } + + private void adicionarLegislacao( Legislacao legislacao ) + { + if( legislacao != null ) + { + provider.addLegislacaoToEstabelecimento( legislacao, estabelecimento ); + refresh(); + } + } + + private void criarPostoTrabalho() + { + String postoTrabalho = JOptionPane.showInputDialog( "Criar posto de trabalho" ); + PostoDeTrabalho postoTrabalhoObject = criarPostoTrabalho( postoTrabalho ); + if( postoTrabalhoObject != null ) + { + adicionarPostoTrabalho( postoTrabalhoObject ); + } + } + + private PostoDeTrabalho criarPostoTrabalho( String postoTrabalho ) + { + PostoDeTrabalho result = null; + if( postoTrabalho != null ) + { + if( postoTrabalho.trim().length() > 0 ) + { + postoTrabalho = postoTrabalho.trim(); + result = provider.createPostoTrabalho( postoTrabalho ); + } + else + { + JOptionPane.showMessageDialog( this, "Posto de trabalho inv" + aacute + "lido", "Erro", JOptionPane.ERROR_MESSAGE, null ); + } + } + return result; + } + + 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 ); + adicionarPostoTrabalho( postoDeTrabalho ); + } + + private void adicionarPostoTrabalho( PostoDeTrabalho postoTrabalho ) + { + if( postoTrabalho != null ) + { + provider.addPostoTrabalhoToEstabelecimento( postoTrabalho, estabelecimento ); + refresh(); + } + } + + private void adicionarEmail() + { + adicionarEmail( JOptionPane.showInputDialog( "Inserir e-mail" ) ); + } + + private void adicionarEmail( String email ) + { + if( email != null && email.trim().length() > 0 ) + { + email = email.trim(); + boolean valid = email.toUpperCase().matches( "[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}" ); + if( valid ) + { + provider.addEmailToEstabelecimento( email, estabelecimento); + refresh(); + } + else + { + JOptionPane.showMessageDialog( this, "Endere" + ccedil + "o de e-mail inv" + aacute + "lido", "Erro", JOptionPane.ERROR_MESSAGE, null ); + } + } + } + + private void removeSelected( JTable table ) + { + VectorTableModel model = (VectorTableModel) table.getModel(); + int indexes [] = table.getSelectedRows(); + if( indexes != null && indexes.length > 0 ) + { + for( int i = 0; i < indexes.length; ++i ) + { + removeSelected( model, indexes[i] ); + } + refresh(); + } + } + + private void removeSelected( VectorTableModel model, int index ) + { + provider.delete( model.getRowAt( index ) ); + } + + @Override + public void clear() + { + modelEmail.clearAll(); + modelLegislacao.clearAll(); + modelPostoTrabalho.clearAll(); + } + + @Override + public void fill( Object value ) + { + if( value != null ) + { + if( value instanceof Integer ) + { + estabelecimento = provider.getEstabelecimentoByID( (Integer) value ); + } + setEnabled( true ); + } + else + { + setEnabled( false ); + } + refresh(); + } + + @Override + public Object save() + { + return null; + } + + @Override + public void setEnabled( boolean enabled ) + { + tableEmail.setEnabled( enabled ); + tableLegislacao.setEnabled( enabled ); + tablePostoTrabalho.setEnabled( enabled ); + buttonEmailAdicionar.setEnabled( enabled ); + buttonLegislacaoAdicionar.setEnabled( enabled ); + buttonPostoTrabalhoAdicionar.setEnabled( enabled ); + buttonLegislacaoCriar.setEnabled( enabled ); + buttonPostoTrabalhoCriar.setEnabled( enabled ); + tableEmail.clearSelection(); + tableLegislacao.clearSelection(); + tablePostoTrabalho.clearSelection(); + } + +} diff --git a/trunk/SIPRPSoft/src/siprp/clientes/ImagePanel.java b/trunk/SIPRPSoft/src/siprp/clientes/ImagePanel.java new file mode 100644 index 00000000..58b60f18 --- /dev/null +++ b/trunk/SIPRPSoft/src/siprp/clientes/ImagePanel.java @@ -0,0 +1,215 @@ +package siprp.clientes; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Image; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.geom.AffineTransform; +import java.awt.image.AffineTransformOp; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; +import javax.swing.BorderFactory; +import javax.swing.JFileChooser; +import javax.swing.JPanel; + +import com.evolute.utils.dataui.ControllableComponent; + +public class ImagePanel extends JPanel implements MouseListener, ControllableComponent +{ + + private static final long serialVersionUID = 1L; + + public static final int WIDTH_THUMBNAIL = 64; + + public static final int HEIGHT_THUMBNAIL = 64; + + public static final int WIDTH_FULL = 512; + + public static final int HEIGHT_FULL = 512; + + private final int w; + + private final int h; + + private boolean thumb = false; + + private BufferedImage scaledImage = null; + + private BufferedImage image = null; + + public ImagePanel( boolean thumbnail ) + { + thumb = thumbnail; + w = thumb ? WIDTH_THUMBNAIL : WIDTH_FULL; + h = thumb ? HEIGHT_THUMBNAIL : HEIGHT_FULL; + this.setSize( new Dimension(w,h) ); + this.setPreferredSize( new Dimension(w,h) ); + this.setOpaque( false ); + this.setLayout( new BorderLayout() ); + this.addMouseListener( this ); + this.setToolTipText( "Alterar logotipo " ); + fill( null ); + } + + public void fill( Object object ) + { + byte[] array = (byte[]) object; + image = null; + scaledImage = null; + try + { + if( array != null ) + { + ByteArrayInputStream input = new ByteArrayInputStream( array ); + scaledImage = ImageIO.read( input ); + input = new ByteArrayInputStream( array ); + image = ImageIO.read( input ); + } + } catch( IOException e ) + { + e.printStackTrace(); + } + refresh(); + } + + private void changeImage( File file ) + { + image = null; + scaledImage = null; + try + { + if( file != null && file.exists() ) + { + scaledImage = ImageIO.read( file ); + image = ImageIO.read( file ); + } + } catch( IOException e ) + { + e.printStackTrace(); + } + refresh(); + } + + private void scaleImage() + { + if( scaledImage != null ) + { + this.setBorder( BorderFactory.createEmptyBorder() ); + if( scaledImage.getWidth() > w ) + { + AffineTransform af = AffineTransform.getScaleInstance( ( (double) w) / ( (double) scaledImage.getWidth() ), ( (double) w ) / ( (double) scaledImage.getWidth() ) ); + AffineTransformOp afOp = new AffineTransformOp( af, AffineTransformOp.TYPE_BILINEAR ); + scaledImage = afOp.filter( scaledImage, null ); + } + if( scaledImage.getHeight() > h ) + { + AffineTransform af = AffineTransform.getScaleInstance( ( (double) h) / ( (double) scaledImage.getHeight() ), ( (double) h ) / ( (double) scaledImage.getHeight() ) ); + AffineTransformOp afOp = new AffineTransformOp( af, AffineTransformOp.TYPE_BILINEAR ); + scaledImage = afOp.filter( scaledImage, null ); + } + } + else + { + this.setBorder( BorderFactory.createLineBorder( Color.GRAY, 1 ) ); + } + } + + private void refresh() + { + scaleImage(); + repaint(); + } + + @Override + public boolean imageUpdate( Image img, int infoflags, int x, int y, int w, int h ) + { + boolean loaded = !imageUpdate( img, infoflags, x, y, w, h ); + if( !loaded ) + { + refresh(); + } + return !loaded; + } + + @Override + protected void paintComponent( Graphics g ) + { + super.paintComponent( g ); + if( scaledImage != null ) + { + int shiftX = ( w - scaledImage.getWidth() ) / 2; + int shiftY = ( h - scaledImage.getHeight() ) / 2; + g.drawImage( scaledImage, 0 + shiftX, 0 + shiftY, w - shiftX, h - shiftY, this ); + } + } + + @Override + public void mouseClicked( MouseEvent e ) + { + if( this.isEnabled() ) + { + JFileChooser fc = new JFileChooser(); + int returned = fc.showOpenDialog( this ); + if( JFileChooser.APPROVE_OPTION == returned ) + { + changeImage( fc.getSelectedFile() ); + } + + } + } + + @Override + public void mouseEntered( MouseEvent e ) + { + this.setCursor( new Cursor( Cursor.HAND_CURSOR ) ); + } + + @Override + public void mouseExited( MouseEvent e ) + { + this.setCursor( new Cursor( Cursor.DEFAULT_CURSOR ) ); + } + + @Override + public void mousePressed( MouseEvent e ) + { + } + + @Override + public void mouseReleased( MouseEvent e ) + { + } + + @Override + public void clear() + { + fill( null ); + } + + @Override + public Object save() + { + byte [] result = null; + try + { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ImageIO.write( image, "PNG", out ); + result = out.toByteArray(); + } + catch( IOException e ) + { + e.printStackTrace(); + } + return result; + } + +}