Package edu.spbstu.hoteldb.panels

Source Code of edu.spbstu.hoteldb.panels.CleaningPanel

package edu.spbstu.hoteldb.panels;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;

import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import edu.spbstu.hoteldb.handlers.NameFilter;
import edu.spbstu.hoteldb.handlers.NumFilter;
import edu.spbstu.hoteldb.handlers.TimeFilter;
import edu.spbstu.hoteldb.interfaces.Panel;

public class CleaningPanel extends VBox implements Panel {

  private Connection connect;
  private final TextArea results;

  public CleaningPanel(TextArea results) {
    this.results = results;
  }

  @Override
  public void create(List<Object> args) {
    this.setSpacing(10);
    this.setPadding(new Insets(10, 10, 10, 10));

    this.getChildren().addAll(createCleanSearchPanel(),
        createSheduleSearchPanel(), createAddTaskPanel(),
        createRemoveTaskPanel());
  }

  @Override
  public void connect() throws ClassNotFoundException, SQLException {
    Class.forName("com.mysql.jdbc.Driver");
    connect = DriverManager
        .getConnection("jdbc:mysql://localhost/hotel_db?"
            + "user=hoteldb_clean&password=clean");
  }

  @Override
  public void close() throws SQLException {
    connect.close();
  }
 
  private Node createCleanSearchPanel() {
    GridPane gp = new GridPane();
    gp.setHgap(10);
    gp.setVgap(10);
   
    Label lclean = new Label("Worker search");
    Label lid = new Label("Id:");
    TextField tfid = new TextField();
    tfid.addEventFilter(KeyEvent.KEY_TYPED, new NumFilter());
    Label lname = new Label("Name:");
    TextField tfname = new TextField();
    tfname.addEventFilter(KeyEvent.KEY_TYPED, new NameFilter());
    Button btnsearch = new Button("Search");
   
    gp.add(lclean, 0, 0);
    gp.add(lid, 0, 1);
    gp.add(tfid, 1, 1);
    gp.add(lname, 0, 2);
    gp.add(tfname, 1, 2);
    gp.add(btnsearch, 0, 3);
   
    return gp;
  }

  private Node createSheduleSearchPanel() {
    GridPane gp = new GridPane();
    gp.setHgap(10);
    gp.setVgap(10);
   
    Label lshed = new Label("Shedule search");
    Label lfrom = new Label("Time from");
    TextField tffrom = new TextField();
    tffrom.setPromptText("hh:mm");
    tffrom.addEventFilter(KeyEvent.KEY_TYPED, new TimeFilter());
    Label lto = new Label("Time to");
    TextField tfto = new TextField();
    tfto.addEventFilter(KeyEvent.KEY_TYPED, new TimeFilter());
    tffrom.setPromptText("hh:mm");
    Button btnsearch = new Button("Search");
 
    gp.add(lshed, 0, 0);
    gp.add(lfrom, 0, 1);
    gp.add(tffrom, 1, 1);
    gp.add(lto, 0, 2);
    gp.add(tfto, 1, 2);
    gp.add(btnsearch, 0, 3);
   
    return gp;
  }
 
  private Node createAddTaskPanel() {
    GridPane gp = new GridPane();
    gp.setHgap(10);
    gp.setVgap(10);
    return gp;
  }
 
  private Node createRemoveTaskPanel() {
    GridPane gp = new GridPane();
    gp.setHgap(10);
    gp.setVgap(10);
    return gp;
  }
 
}
TOP

Related Classes of edu.spbstu.hoteldb.panels.CleaningPanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.