Advertisement
xlrnxnlx

dev-MainWindowController

May 21st, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.42 KB | None | 0 0
  1. package aap.controller;
  2.  
  3. import aap.view.*;
  4. import app.dao.*;
  5. import java.awt.event.*;
  6. import javax.swing.*;
  7.  
  8. public class MainWindowController implements ActionListener {
  9.  
  10.     private MainWindow window;
  11.     private CategoryController categoryControll;
  12.     private PilotController pilotControll;
  13.     private PilotWindow pilotWindow;
  14.     private CategoryWindow categoryWindow;
  15.     private PilotDataAccess pilotDAO;
  16.     private AirplaneDataAccess airplaneDAO;
  17.     private TravelDataAccess travelDAO;
  18.  
  19.     public MainWindowController(MainWindow window) {
  20.         this.window = window;
  21.  
  22.         window.getBtAirplane().addActionListener(this);
  23.         window.getBtAirplaneCategory().addActionListener(this);
  24.         window.getBtPilot().addActionListener(this);
  25.         window.getBtPilotCategory().addActionListener(this);
  26.         window.getBtNew().addActionListener(this);
  27.         window.getBtCancel().addActionListener(this);
  28.         window.getBtInsert().addActionListener(this);
  29.  
  30.         refreshTable();
  31.  
  32.         window.setVisible(true);
  33.     }
  34.  
  35.     @Override
  36.     public void actionPerformed(ActionEvent e) {
  37.         JButton b = (JButton) e.getSource();
  38.  
  39.         switch (b.getText().toLowerCase()) {
  40.             case "pilotos":
  41.                 execPilotWindow();
  42.                 break;
  43.             case "categoria de pilotos":
  44.                 execCategoryWindow("pilot");
  45.                 break;
  46.             case "categoria de aviões":
  47.                 execCategoryWindow("airplane");
  48.                 break;
  49.             case "nova":
  50.                 execNewTravel();
  51.                 break;
  52.             case "inserir":
  53.                 execInsert();
  54.                 break;
  55.  
  56.         }
  57.  
  58.     }
  59.  
  60.     public void execPilotWindow() {
  61.         pilotWindow = new PilotWindow(window, true);
  62.         pilotControll = new PilotController(pilotWindow);
  63.     }
  64.  
  65.     public void execCategoryWindow(String type) {
  66.         if (categoryControll == null) {
  67.             categoryWindow = new CategoryWindow();
  68.             categoryControll = new CategoryController(categoryWindow);
  69.         }
  70.         if (type.equals("airplane")) {
  71.             categoryWindow.changeCategory("airplane");
  72.         } else {
  73.             categoryWindow.changeCategory("pilot");
  74.         }
  75.         categoryControll.updateComboBox();
  76.         categoryWindow.setVisible(true);
  77.     }
  78.    
  79.     public void execNewTravel() {
  80.         window.isNewMode(true);
  81.         refreshComboBox();
  82.     }
  83.  
  84.     public void execInsert() {
  85.         window.isNewMode(false);
  86.     }
  87.    
  88.     private void refreshTable() {
  89.         travelDAO = new TravelDataAccess();
  90.         window.popTable(travelDAO.select());
  91.         IDToGenre();
  92.     }
  93.    
  94.     private void refreshComboBox() {
  95.         pilotDAO = new PilotDataAccess();
  96.         window.popComboBox(pilotDAO.selectAllPilotNames(), 1);
  97.         airplaneDAO = new AirplaneDataAccess();
  98.         window.popComboBox(airplaneDAO.selectAllPlaneIDs(), 2);
  99.     }
  100.  
  101.     private void IDToGenre() {
  102.         JTable table = window.getTable();
  103.         int rows = table.getRowCount();
  104.         pilotDAO = new PilotDataAccess();
  105.        
  106.         for (int i = 0; i < rows; i++) {
  107.             int brevet = Integer.parseInt(table.getModel().getValueAt(i, 0).toString());
  108.             String test = pilotDAO.selectByID(brevet);
  109.             table.getModel().setValueAt(test, i, 0);
  110.         }
  111.     }
  112.    
  113.  
  114.     private int PILOT_BREVET, PLANE_ID;
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement