forked from Coded/SIPRP
git-svn-id: https://svn.coded.pt/svn/SIPRP@901 bb69d46d-e84e-40c8-a05a-06db0d633741
parent
b882491cc9
commit
88830f4af6
@ -0,0 +1,229 @@
|
||||
package siprp.higiene.gestao.equipamentos;
|
||||
|
||||
import info.clearthought.layout.TableLayout;
|
||||
import info.clearthought.layout.TableLayoutConstraints;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.event.TreeSelectionEvent;
|
||||
import javax.swing.event.TreeSelectionListener;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.TreePath;
|
||||
import javax.swing.tree.TreeSelectionModel;
|
||||
|
||||
import leaf.data.Validator;
|
||||
import leaf.ui.LeafButton;
|
||||
import leaf.ui.LeafTextAreaEditor;
|
||||
import leaf.ui.TreeTools;
|
||||
import siprp.database.cayenne.objects.HsEquipamento;
|
||||
import siprp.logic.HigieneSegurancaLogic;
|
||||
|
||||
public class GerirEquipamentosPanel extends JPanel
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final JPanel panelButtons = new JPanel();
|
||||
|
||||
private final JPanel panelTree = new JPanel();
|
||||
|
||||
private final JPanel panelData = new JPanel();
|
||||
|
||||
private final LeafTextAreaEditor textMarca = new LeafTextAreaEditor( new Validator<String>()
|
||||
{
|
||||
@Override
|
||||
public boolean isValid( String object )
|
||||
{
|
||||
return isMarcaValida( object );
|
||||
}
|
||||
}, true );
|
||||
|
||||
private final LeafTextAreaEditor textModelo = new LeafTextAreaEditor( new Validator<String>()
|
||||
{
|
||||
@Override
|
||||
public boolean isValid( String object )
|
||||
{
|
||||
return isModeloValido( object );
|
||||
}
|
||||
}, true );
|
||||
|
||||
private final LeafButton buttonCriar = new LeafButton( "Criar" );
|
||||
|
||||
private final LeafButton buttonEditar = new LeafButton( "Editar" );
|
||||
|
||||
private final LeafButton buttonRemover = new LeafButton( "Remover" );
|
||||
|
||||
private final DefaultMutableTreeNode root = new DefaultMutableTreeNode();
|
||||
|
||||
private final DefaultTreeModel model = new DefaultTreeModel( root );
|
||||
|
||||
private final JTree tree = new JTree( model );
|
||||
|
||||
private final JScrollPane scroll = new JScrollPane( tree );
|
||||
|
||||
public GerirEquipamentosPanel()
|
||||
{
|
||||
startupComponents();
|
||||
startupLayout();
|
||||
placeComponents();
|
||||
setupListeners();
|
||||
refresh();
|
||||
}
|
||||
|
||||
private void setupListeners()
|
||||
{
|
||||
buttonCriar.addActionListener( new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed( ActionEvent e )
|
||||
{
|
||||
criar();
|
||||
}
|
||||
} );
|
||||
buttonEditar.addActionListener( new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed( ActionEvent e )
|
||||
{
|
||||
editar();
|
||||
}
|
||||
} );
|
||||
buttonRemover.addActionListener( new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed( ActionEvent e )
|
||||
{
|
||||
remover();
|
||||
}
|
||||
} );
|
||||
tree.getSelectionModel().addTreeSelectionListener( new TreeSelectionListener()
|
||||
{
|
||||
@Override
|
||||
public void valueChanged( TreeSelectionEvent e )
|
||||
{
|
||||
setEnabled();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
private void criar()
|
||||
{
|
||||
}
|
||||
|
||||
private void editar()
|
||||
{
|
||||
}
|
||||
|
||||
private void remover()
|
||||
{
|
||||
}
|
||||
|
||||
private HsEquipamento getSelected()
|
||||
{
|
||||
Object object = getSelectedObject();
|
||||
return object == null ? null : ((object instanceof HsEquipamento) ? (HsEquipamento) object : null);
|
||||
}
|
||||
|
||||
private Object getSelectedObject()
|
||||
{
|
||||
DefaultMutableTreeNode node = getSelectedNode();
|
||||
return node == null ? null : node.getUserObject();
|
||||
}
|
||||
|
||||
private DefaultMutableTreeNode getSelectedNode()
|
||||
{
|
||||
TreePath path = tree.getSelectionPath();
|
||||
return path == null ? null : (DefaultMutableTreeNode) path.getLastPathComponent();
|
||||
}
|
||||
|
||||
private void startupComponents()
|
||||
{
|
||||
panelTree.setPreferredSize( new Dimension( 400, 400 ) );
|
||||
tree.setRootVisible( false );
|
||||
tree.getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION );
|
||||
}
|
||||
|
||||
private void setEnabled()
|
||||
{
|
||||
HsEquipamento equipamento = getSelected();
|
||||
buttonEditar.setEnabled( equipamento != null );
|
||||
buttonRemover.setEnabled( equipamento != null );
|
||||
}
|
||||
|
||||
private void startupLayout()
|
||||
{
|
||||
TableLayout layout = new TableLayout( new double[] {
|
||||
TableLayout.MINIMUM, TableLayout.PREFERRED, TableLayout.FILL
|
||||
}, new double[] {
|
||||
TableLayout.FILL
|
||||
} );
|
||||
layout.setHGap( 5 );
|
||||
layout.setVGap( 5 );
|
||||
setLayout( layout );
|
||||
|
||||
layout = new TableLayout( new double[] {
|
||||
TableLayout.MINIMUM
|
||||
}, new double[] {
|
||||
TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM
|
||||
} );
|
||||
layout.setHGap( 5 );
|
||||
layout.setVGap( 5 );
|
||||
panelButtons.setLayout( layout );
|
||||
|
||||
layout = new TableLayout( new double[] {
|
||||
TableLayout.MINIMUM, TableLayout.FILL
|
||||
}, new double[] {
|
||||
TableLayout.MINIMUM, TableLayout.MINIMUM
|
||||
} );
|
||||
layout.setHGap( 5 );
|
||||
layout.setVGap( 5 );
|
||||
panelData.setLayout( layout );
|
||||
|
||||
panelTree.setLayout( new GridLayout( 1,1 ) );
|
||||
}
|
||||
|
||||
private void placeComponents()
|
||||
{
|
||||
panelButtons.add( buttonCriar, new TableLayoutConstraints( 0, 0 ) );
|
||||
panelButtons.add( buttonEditar, new TableLayoutConstraints( 0, 1 ) );
|
||||
panelButtons.add( buttonRemover, new TableLayoutConstraints( 0, 2 ) );
|
||||
|
||||
panelTree.add( scroll, new TableLayoutConstraints( 0, 0 ) );
|
||||
|
||||
panelData.add( new JLabel("Marca"), new TableLayoutConstraints( 0, 0 ) );
|
||||
panelData.add( textMarca, new TableLayoutConstraints( 1, 0 ) );
|
||||
panelData.add( new JLabel("Modelo"), new TableLayoutConstraints( 0, 1 ) );
|
||||
panelData.add( textModelo, new TableLayoutConstraints( 1, 1 ) );
|
||||
|
||||
add( panelButtons, new TableLayoutConstraints( 0, 0 ) );
|
||||
add( panelTree, new TableLayoutConstraints( 1, 0 ) );
|
||||
add( panelData, new TableLayoutConstraints( 2, 0 ) );
|
||||
}
|
||||
|
||||
private void refresh()
|
||||
{
|
||||
root.removeAllChildren();
|
||||
TreeTools.merge( root, HigieneSegurancaLogic.getEquipamentosTree() );
|
||||
TreeTools.refreshTree( tree, root );
|
||||
setEnabled();
|
||||
}
|
||||
|
||||
private boolean isMarcaValida( String marca )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isModeloValido( String modelo )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,65 @@
|
||||
package siprp.update.updates;
|
||||
|
||||
import com.evolute.utils.Singleton;
|
||||
import com.evolute.utils.db.DBManager;
|
||||
import com.evolute.utils.db.Executer;
|
||||
|
||||
public class V10_1_To_V10_2
|
||||
implements siprp.update.Update
|
||||
{
|
||||
|
||||
public V10_1_To_V10_2()
|
||||
{
|
||||
}
|
||||
|
||||
public String []listChanges()
|
||||
{
|
||||
return new String[]{
|
||||
"adicionadas normalizacoes para estabelecimentos e empresas"
|
||||
};
|
||||
}
|
||||
|
||||
public double getStartVersion()
|
||||
{
|
||||
return 10.1;
|
||||
}
|
||||
|
||||
public double getEndVersion()
|
||||
{
|
||||
return 10.2;
|
||||
}
|
||||
|
||||
public void doUpdate()
|
||||
throws Exception
|
||||
{
|
||||
DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER );
|
||||
Executer executer = dbm.getSharedExecuter();
|
||||
com.evolute.utils.sql.Update update =
|
||||
new com.evolute.utils.sql.Update(
|
||||
"CREATE TABLE hs_equipamento( " +
|
||||
"id SERIAL PRIMARY KEY, " +
|
||||
"tipo VARCHAR(512) NOT NULL, " +
|
||||
"marca VARCHAR(255), " +
|
||||
"modelo VARCHAR(255), " +
|
||||
"deleted_date TIMESTAMP " +
|
||||
"); " +
|
||||
"CREATE TABLE hs_relatorio_equipamento( " +
|
||||
"hs_relatorio_id INT4 REFERENCES hs_relatorio(id), " +
|
||||
"hs_equipamento INT4 REFERENCES hs_equipamento(id), " +
|
||||
"CONSTRAINT hs_relatorio_equipamento_pkey PRIMARY KEY (hs_relatorio_id,hs_equipamento) " +
|
||||
"); " +
|
||||
"INSERT INTO hs_equipamento(id, tipo) " +
|
||||
"SELECT id, nome FROM hs_equipamento_medico ; " +
|
||||
"INSERT INTO hs_relatorio_equipamento(hs_relatorio_id, hs_equipamento) " +
|
||||
"SELECT hs_relatorio_id, hs_equipamento_medico_id FROM hs_relatorio_equipamento_medico; " +
|
||||
"DROP TABLE hs_relatorio_equipamento_medico; " +
|
||||
"DROP TABLE hs_equipamento_medico; "
|
||||
);
|
||||
executer.executeQuery( update );
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "v" + getStartVersion() + " para v" + getEndVersion();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
package siprp.database.cayenne.objects;
|
||||
|
||||
import siprp.database.cayenne.objects.auto._HsEquipamento;
|
||||
|
||||
public class HsEquipamento extends _HsEquipamento {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public String getTipo()
|
||||
{
|
||||
return parseFromUnicode( super.getTipo() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTipo( String nome )
|
||||
{
|
||||
super.setTipo( parseToUnicode( nome ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMarca()
|
||||
{
|
||||
return parseFromUnicode( super.getMarca() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMarca( String marca )
|
||||
{
|
||||
super.setMarca( parseToUnicode( marca ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModelo()
|
||||
{
|
||||
return parseFromUnicode( super.getModelo() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setModelo( String modelo )
|
||||
{
|
||||
super.setModelo( parseToUnicode( modelo ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return getTipo();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
package siprp.database.cayenne.objects;
|
||||
|
||||
import siprp.database.cayenne.objects.auto._HsEquipamentoMedico;
|
||||
|
||||
public class HsEquipamentoMedico extends _HsEquipamentoMedico {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public String getNome()
|
||||
{
|
||||
return parseFromUnicode( super.getNome() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNome( String nome )
|
||||
{
|
||||
super.setNome( parseToUnicode( nome ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return getNome();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,15 +1,14 @@
|
||||
package siprp.database.cayenne.objects;
|
||||
|
||||
import siprp.database.cayenne.objects.auto._HsRelatorioEquipamentoMedico;
|
||||
import siprp.database.cayenne.objects.auto._HsRelatorioEquipamento;
|
||||
|
||||
public class HsRelatorioEquipamentoMedico extends _HsRelatorioEquipamentoMedico {
|
||||
public class HsRelatorioEquipamento extends _HsRelatorioEquipamento {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return getToHsEquipamentoMedico().toString();
|
||||
return getToHsEquipamento().toString();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,65 @@
|
||||
package siprp.database.cayenne.objects.auto;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import siprp.database.cayenne.objects.BaseObject;
|
||||
import siprp.database.cayenne.objects.HsRelatorioEquipamento;
|
||||
|
||||
/**
|
||||
* Class _HsEquipamento was generated by Cayenne.
|
||||
* It is probably a good idea to avoid changing this class manually,
|
||||
* since it may be overwritten next time code is regenerated.
|
||||
* If you need to make any customizations, please use subclass.
|
||||
*/
|
||||
public abstract class _HsEquipamento extends BaseObject {
|
||||
|
||||
public static final String DELETED_DATE_PROPERTY = "deletedDate";
|
||||
public static final String MARCA_PROPERTY = "marca";
|
||||
public static final String MODELO_PROPERTY = "modelo";
|
||||
public static final String TIPO_PROPERTY = "tipo";
|
||||
public static final String HS_RELATORIO_EQUIPAMENTO_ARRAY_PROPERTY = "hsRelatorioEquipamentoArray";
|
||||
|
||||
public static final String ID_PK_COLUMN = "id";
|
||||
|
||||
public void setDeletedDate(Date deletedDate) {
|
||||
writeProperty("deletedDate", deletedDate);
|
||||
}
|
||||
public Date getDeletedDate() {
|
||||
return (Date)readProperty("deletedDate");
|
||||
}
|
||||
|
||||
public void setMarca(String marca) {
|
||||
writeProperty("marca", marca);
|
||||
}
|
||||
public String getMarca() {
|
||||
return (String)readProperty("marca");
|
||||
}
|
||||
|
||||
public void setModelo(String modelo) {
|
||||
writeProperty("modelo", modelo);
|
||||
}
|
||||
public String getModelo() {
|
||||
return (String)readProperty("modelo");
|
||||
}
|
||||
|
||||
public void setTipo(String tipo) {
|
||||
writeProperty("tipo", tipo);
|
||||
}
|
||||
public String getTipo() {
|
||||
return (String)readProperty("tipo");
|
||||
}
|
||||
|
||||
public void addToHsRelatorioEquipamentoArray(HsRelatorioEquipamento obj) {
|
||||
addToManyTarget("hsRelatorioEquipamentoArray", obj, true);
|
||||
}
|
||||
public void removeFromHsRelatorioEquipamentoArray(HsRelatorioEquipamento obj) {
|
||||
removeToManyTarget("hsRelatorioEquipamentoArray", obj, true);
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<HsRelatorioEquipamento> getHsRelatorioEquipamentoArray() {
|
||||
return (List<HsRelatorioEquipamento>)readProperty("hsRelatorioEquipamentoArray");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,40 +0,0 @@
|
||||
package siprp.database.cayenne.objects.auto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import siprp.database.cayenne.objects.BaseObject;
|
||||
import siprp.database.cayenne.objects.HsRelatorioEquipamentoMedico;
|
||||
|
||||
/**
|
||||
* Class _HsEquipamentoMedico was generated by Cayenne.
|
||||
* It is probably a good idea to avoid changing this class manually,
|
||||
* since it may be overwritten next time code is regenerated.
|
||||
* If you need to make any customizations, please use subclass.
|
||||
*/
|
||||
public abstract class _HsEquipamentoMedico extends BaseObject {
|
||||
|
||||
public static final String NOME_PROPERTY = "nome";
|
||||
public static final String HS_RELATORIO_EQUIPAMENTO_MEDICO_ARRAY_PROPERTY = "hsRelatorioEquipamentoMedicoArray";
|
||||
|
||||
public static final String ID_PK_COLUMN = "id";
|
||||
|
||||
public void setNome(String nome) {
|
||||
writeProperty("nome", nome);
|
||||
}
|
||||
public String getNome() {
|
||||
return (String)readProperty("nome");
|
||||
}
|
||||
|
||||
public void addToHsRelatorioEquipamentoMedicoArray(HsRelatorioEquipamentoMedico obj) {
|
||||
addToManyTarget("hsRelatorioEquipamentoMedicoArray", obj, true);
|
||||
}
|
||||
public void removeFromHsRelatorioEquipamentoMedicoArray(HsRelatorioEquipamentoMedico obj) {
|
||||
removeToManyTarget("hsRelatorioEquipamentoMedicoArray", obj, true);
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<HsRelatorioEquipamentoMedico> getHsRelatorioEquipamentoMedicoArray() {
|
||||
return (List<HsRelatorioEquipamentoMedico>)readProperty("hsRelatorioEquipamentoMedicoArray");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,29 +1,29 @@
|
||||
package siprp.database.cayenne.objects.auto;
|
||||
|
||||
import siprp.database.cayenne.objects.BaseObject;
|
||||
import siprp.database.cayenne.objects.HsEquipamentoMedico;
|
||||
import siprp.database.cayenne.objects.HsEquipamento;
|
||||
import siprp.database.cayenne.objects.HsRelatorio;
|
||||
|
||||
/**
|
||||
* Class _HsRelatorioEquipamentoMedico was generated by Cayenne.
|
||||
* Class _HsRelatorioEquipamento was generated by Cayenne.
|
||||
* It is probably a good idea to avoid changing this class manually,
|
||||
* since it may be overwritten next time code is regenerated.
|
||||
* If you need to make any customizations, please use subclass.
|
||||
*/
|
||||
public abstract class _HsRelatorioEquipamentoMedico extends BaseObject {
|
||||
public abstract class _HsRelatorioEquipamento extends BaseObject {
|
||||
|
||||
public static final String TO_HS_EQUIPAMENTO_MEDICO_PROPERTY = "toHsEquipamentoMedico";
|
||||
public static final String TO_HS_EQUIPAMENTO_PROPERTY = "toHsEquipamento";
|
||||
public static final String TO_HS_RELATORIO_PROPERTY = "toHsRelatorio";
|
||||
|
||||
public static final String HS_EQUIPAMENTO_MEDICO_ID_PK_COLUMN = "hs_equipamento_medico_id";
|
||||
public static final String HS_EQUIPAMENTO_PK_COLUMN = "hs_equipamento";
|
||||
public static final String HS_RELATORIO_ID_PK_COLUMN = "hs_relatorio_id";
|
||||
|
||||
public void setToHsEquipamentoMedico(HsEquipamentoMedico toHsEquipamentoMedico) {
|
||||
setToOneTarget("toHsEquipamentoMedico", toHsEquipamentoMedico, true);
|
||||
public void setToHsEquipamento(HsEquipamento toHsEquipamento) {
|
||||
setToOneTarget("toHsEquipamento", toHsEquipamento, true);
|
||||
}
|
||||
|
||||
public HsEquipamentoMedico getToHsEquipamentoMedico() {
|
||||
return (HsEquipamentoMedico)readProperty("toHsEquipamentoMedico");
|
||||
public HsEquipamento getToHsEquipamento() {
|
||||
return (HsEquipamento)readProperty("toHsEquipamento");
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in new issue