Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package aap.controller;
- import aap.view.*;
- import app.dao.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class MainWindowController implements ActionListener {
- private MainWindow window;
- private CategoryController categoryControll;
- private PilotController pilotControll;
- private PilotWindow pilotWindow;
- private CategoryWindow categoryWindow;
- private PilotDataAccess pilotDAO;
- private AirplaneDataAccess airplaneDAO;
- private TravelDataAccess travelDAO;
- public MainWindowController(MainWindow window) {
- this.window = window;
- window.getBtAirplane().addActionListener(this);
- window.getBtAirplaneCategory().addActionListener(this);
- window.getBtPilot().addActionListener(this);
- window.getBtPilotCategory().addActionListener(this);
- window.getBtNew().addActionListener(this);
- window.getBtCancel().addActionListener(this);
- window.getBtInsert().addActionListener(this);
- refreshTable();
- window.setVisible(true);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- JButton b = (JButton) e.getSource();
- switch (b.getText().toLowerCase()) {
- case "pilotos":
- execPilotWindow();
- break;
- case "categoria de pilotos":
- execCategoryWindow("pilot");
- break;
- case "categoria de aviões":
- execCategoryWindow("airplane");
- break;
- case "nova":
- execNewTravel();
- break;
- case "inserir":
- execInsert();
- break;
- }
- }
- public void execPilotWindow() {
- pilotWindow = new PilotWindow(window, true);
- pilotControll = new PilotController(pilotWindow);
- }
- public void execCategoryWindow(String type) {
- if (categoryControll == null) {
- categoryWindow = new CategoryWindow();
- categoryControll = new CategoryController(categoryWindow);
- }
- if (type.equals("airplane")) {
- categoryWindow.changeCategory("airplane");
- } else {
- categoryWindow.changeCategory("pilot");
- }
- categoryControll.updateComboBox();
- categoryWindow.setVisible(true);
- }
- public void execNewTravel() {
- window.isNewMode(true);
- refreshComboBox();
- }
- public void execInsert() {
- window.isNewMode(false);
- }
- private void refreshTable() {
- travelDAO = new TravelDataAccess();
- window.popTable(travelDAO.select());
- IDToGenre();
- }
- private void refreshComboBox() {
- pilotDAO = new PilotDataAccess();
- window.popComboBox(pilotDAO.selectAllPilotNames(), 1);
- airplaneDAO = new AirplaneDataAccess();
- window.popComboBox(airplaneDAO.selectAllPlaneIDs(), 2);
- }
- private void IDToGenre() {
- JTable table = window.getTable();
- int rows = table.getRowCount();
- pilotDAO = new PilotDataAccess();
- for (int i = 0; i < rows; i++) {
- int brevet = Integer.parseInt(table.getModel().getValueAt(i, 0).toString());
- String test = pilotDAO.selectByID(brevet);
- table.getModel().setValueAt(test, i, 0);
- }
- }
- private int PILOT_BREVET, PLANE_ID;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement