/* * Copyright (C) 2012 Miguel Angel Garcia <miguelangel.garcia@gmail.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package org.magmax.master.project.admin; import java.awt.event.WindowEvent; import org.magmax.eswing.crud.CrudObject; import org.magmax.eswing.crud.CrudUICreate; import org.magmax.eswing.crud.CrudUIDetails; import org.magmax.eswing.crud.CrudUIUpdate; /** * * @author Miguel Angel Garcia <miguelangel.garcia@gmail.com> */ public class BaseUI<T extends CrudObject> extends javax.swing.JDialog implements CrudUICreate<T>, CrudUIUpdate<T>, CrudUIDetails<T> { private final BaseCrudPanel panel; private boolean save = false; public BaseUI(java.awt.Frame parent, BaseCrudPanel<T> panel) { super(parent, true); initComponents(); setLocationByPlatform(true); this.panel = panel; contentPane.add(panel); } public T create() { T result = null; setTitle(panel.getTitleCreation()); panel.setWidgetsEnabled(true); panel.clearWidgets(); showWindow(); if (save) { result = (T) panel.getCrudObject(); } return result; } public void update(T item) { setTitle(panel.getTitleUpdate()); panel.setCrudObject(item); panel.setWidgetsEnabled(true); showWindow(); if (save) { panel.updateCrudObject(item); } } public void details(T item) { setTitle(panel.getTitleDetails()); panel.setCrudObject(item); panel.setWidgetsEnabled(false); showWindow(); } private void close() { this.processWindowEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); } private void showWindow() { setVisible(true); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); contentPane = new javax.swing.JPanel(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); jButton1.setText("Close"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton2.setText("Save"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); contentPane.setLayout(new java.awt.BorderLayout()); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(contentPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 654, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(jButton2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jButton1))) .addContainerGap()) ); layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton1, jButton2}); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addComponent(contentPane, javax.swing.GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1) .addComponent(jButton2)) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed close(); }//GEN-LAST:event_jButton1ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed save = true; close(); }//GEN-LAST:event_jButton2ActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel contentPane; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; // End of variables declaration//GEN-END:variables }