Java tutorial
/** * Copyright 2015 TIKAL-TECHNOLOGY * *Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License */ package org.nekorp.workflow.desktop.view; import java.io.File; import java.io.IOException; import java.util.Date; import javax.swing.JFileChooser; import javax.swing.filechooser.FileNameExtensionFilter; import org.joda.time.DateTime; import org.nekorp.workflow.desktop.control.WorkflowApp; import org.nekorp.workflow.desktop.modelo.reporte.global.ParametrosReporteGlobal; import org.nekorp.workflow.desktop.view.binding.Bindable; import org.nekorp.workflow.desktop.view.binding.BindingManager; import org.nekorp.workflow.desktop.view.model.reporte.global.ParametrosReporteGlobalVB; import org.nekorp.workflow.desktop.view.resource.DialogFactory; import org.springframework.stereotype.Component; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; /** * * @author Nekorp */ @Component("appLayoutView") public class AppLayoutView extends ApplicationView { private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger.getLogger(AppLayoutView.class); @Autowired() @Qualifier(value = "servicioView") private ApplicationView servicioView; @Autowired() @Qualifier(value = "navegadorServiciosView") private ApplicationView navegadorServiciosView; @Autowired() @Qualifier(value = "servicioDatosGeneralesView") private ApplicationView servicioDatosGeneralesView; @Autowired private javax.swing.JFrame mainFrame; @Autowired @Qualifier(value = "servicioPreviewDialogFactory") private DialogFactory servicioPreviewDialogFactory; @Qualifier(value = "progrmacionWizardDialogFactory") private DialogFactory dialogFactoryWizardProgramacion; @Autowired @Qualifier(value = "parametrosReporteGlobalDialogFactory") private DialogFactory parametrosReporteGlobalDialogFactory; @Autowired private ParametrosReporteGlobalVB parametrosReporteGlobal; @Autowired private WorkflowApp aplication; //@Autowired private BindingManager<Bindable> bindingManager; private BusquedaServicioView busquedaDialog; /** * Creates new form NavegadorServicios */ public AppLayoutView() { super(); } @Override public void iniciaVista() { initComponents(); servicioDatosGeneralesView.iniciaVista(); this.leftPanel.add(servicioDatosGeneralesView); navegadorServiciosView.iniciaVista(); this.rightPanel.add(navegadorServiciosView); servicioView.iniciaVista(); this.contenidoView.add(servicioView); busquedaDialog = new BusquedaServicioView(mainFrame, true, this.aplication, servicioPreviewDialogFactory); } @Override public void setEditableStatus(boolean value) { /// } @Override public ViewValidIndicator getValidInidicator() { return null; } /** * 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() { jPanel1 = new javax.swing.JPanel(); jToolBar2 = new javax.swing.JToolBar(); nuevoButton = new javax.swing.JButton(); buscarButton = new javax.swing.JButton(); formatoProgramacionButton = new javax.swing.JButton(); reporteGlobalButton = new javax.swing.JButton(); jPanel3 = new javax.swing.JPanel(); leftPanel = new javax.swing.JPanel(); contenidoView = new javax.swing.JPanel(); rightPanel = new javax.swing.JPanel(); jPanel1.setBackground(new java.awt.Color(0, 0, 0)); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 147, Short.MAX_VALUE)); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 0, Short.MAX_VALUE)); jToolBar2.setBackground(new java.awt.Color(0, 0, 0)); jToolBar2.setFloatable(false); jToolBar2.setRollover(true); nuevoButton.setBackground(new java.awt.Color(0, 0, 0)); nuevoButton.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N nuevoButton.setForeground(new java.awt.Color(255, 255, 255)); nuevoButton.setText("Nuevo"); nuevoButton.setFocusable(false); nuevoButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); nuevoButton.setMinimumSize(new java.awt.Dimension(40, 40)); nuevoButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); nuevoButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { nuevoButtonActionPerformed(evt); } }); jToolBar2.add(nuevoButton); buscarButton.setBackground(new java.awt.Color(0, 0, 0)); buscarButton.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N buscarButton.setForeground(new java.awt.Color(255, 255, 255)); buscarButton.setText("Buscar"); buscarButton.setFocusable(false); buscarButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); buscarButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); buscarButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buscarButtonActionPerformed(evt); } }); jToolBar2.add(buscarButton); formatoProgramacionButton.setBackground(new java.awt.Color(0, 0, 0)); formatoProgramacionButton.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N formatoProgramacionButton.setForeground(new java.awt.Color(255, 255, 255)); formatoProgramacionButton.setText("Formato de Programacin"); formatoProgramacionButton.setFocusable(false); formatoProgramacionButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); formatoProgramacionButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); formatoProgramacionButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { formatoProgramacionButtonActionPerformed(evt); } }); jToolBar2.add(formatoProgramacionButton); reporteGlobalButton.setBackground(new java.awt.Color(0, 0, 0)); reporteGlobalButton.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N reporteGlobalButton.setForeground(new java.awt.Color(255, 255, 255)); reporteGlobalButton.setText("Reporte Global"); reporteGlobalButton.setFocusable(false); reporteGlobalButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); reporteGlobalButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); reporteGlobalButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { reporteGlobalButtonActionPerformed(evt); } }); jToolBar2.add(reporteGlobalButton); jPanel3.setBackground(new java.awt.Color(0, 0, 0)); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 174, Short.MAX_VALUE)); jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 30, Short.MAX_VALUE)); leftPanel.setBackground(new java.awt.Color(51, 51, 51)); leftPanel.setLayout(new java.awt.BorderLayout()); contenidoView.setBackground(new java.awt.Color(255, 255, 255)); contenidoView.setLayout(new java.awt.BorderLayout()); rightPanel.setBackground(new java.awt.Color(51, 51, 51)); rightPanel.setLayout(new java.awt.BorderLayout()); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(leftPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jToolBar2, javax.swing.GroupLayout.DEFAULT_SIZE, 638, Short.MAX_VALUE) .addGap(0, 0, 0).addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(contenidoView, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGap(0, 0, 0).addComponent(rightPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE))))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jToolBar2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(leftPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 440, Short.MAX_VALUE) .addComponent(contenidoView, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(rightPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))); }// </editor-fold>//GEN-END:initComponents private void nuevoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nuevoButtonActionPerformed this.aplication.crearServicio(); }//GEN-LAST:event_nuevoButtonActionPerformed private void buscarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscarButtonActionPerformed try { /*if (this.servicioMetaData.isEditado()) { int n = javax.swing.JOptionPane.showConfirmDialog( mainFrame, "Guardar Servicio?", "Guardar", javax.swing.JOptionPane.YES_NO_CANCEL_OPTION); if (n == javax.swing.JOptionPane.YES_OPTION) { this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); this.aplication.guardaServicio(); } if (n == javax.swing.JOptionPane.CANCEL_OPTION || n == javax.swing.JOptionPane.CLOSED_OPTION) { return; } }*/ this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); if (!busquedaDialog.isIniciado()) { busquedaDialog.inicializa(); } busquedaDialog.validate(); busquedaDialog.pack(); busquedaDialog.setLocationRelativeTo(mainFrame); this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR)); busquedaDialog.setVisible(true); } catch (IllegalArgumentException e) { //por que se tragaria excepciones de este tipo sin que sean los que arroja al no poder guardar } finally { this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR)); } }//GEN-LAST:event_buscarButtonActionPerformed private void formatoProgramacionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_formatoProgramacionButtonActionPerformed dialogFactoryWizardProgramacion.createDialog(mainFrame, true).setVisible(true); }//GEN-LAST:event_formatoProgramacionButtonActionPerformed private void reporteGlobalButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reporteGlobalButtonActionPerformed try { parametrosReporteGlobal.setFechaInicial(new Date()); parametrosReporteGlobal.setFechaFinal(new Date()); parametrosReporteGlobalDialogFactory.createDialog(mainFrame, true).setVisible(true); if (parametrosReporteGlobal.isEjecutar()) { JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Hojas de clculo", "xlsx"); chooser.setFileFilter(filter); String homePath = System.getProperty("user.home"); File f = new File(new File(homePath + "/Reporte-Global" + ".xlsx").getCanonicalPath()); chooser.setSelectedFile(f); int returnVal = chooser.showSaveDialog(this.mainFrame); if (returnVal == JFileChooser.APPROVE_OPTION) { this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); ParametrosReporteGlobal param = new ParametrosReporteGlobal(); param.setDestination(chooser.getSelectedFile()); DateTime fechaInicial = new DateTime(parametrosReporteGlobal.getFechaInicial()); DateTime fechaFinal = new DateTime(parametrosReporteGlobal.getFechaFinal()); fechaFinal = new DateTime(fechaFinal.getYear(), fechaFinal.getMonthOfYear(), fechaFinal.getDayOfMonth(), fechaFinal.hourOfDay().getMaximumValue(), fechaFinal.minuteOfHour().getMaximumValue(), fechaFinal.secondOfMinute().getMaximumValue(), fechaFinal.millisOfSecond().getMaximumValue(), fechaFinal.getZone()); param.setFechaInicial(fechaInicial); param.setFechaFinal(fechaFinal); this.aplication.generaReporteGlobal(param); } } } catch (IOException ex) { AppLayoutView.LOGGER.error("Exploto al tratar de generar el reporte global", ex); } finally { this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR)); } }//GEN-LAST:event_reporteGlobalButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton buscarButton; private javax.swing.JPanel contenidoView; private javax.swing.JButton formatoProgramacionButton; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel3; private javax.swing.JToolBar jToolBar2; private javax.swing.JPanel leftPanel; private javax.swing.JButton nuevoButton; private javax.swing.JButton reporteGlobalButton; private javax.swing.JPanel rightPanel; // End of variables declaration//GEN-END:variables }