public void cargarTabla() {

    idCocinerotable.setCellValueFactory(new PropertyValueFactory<Cocinero, Integer>("IdCocinero"));
    añostable.setCellValueFactory(new PropertyValueFactory<Cocinero, String>("años"));
    idEmpleadotable.setCellValueFactory(new PropertyValueFactory<Cocinero, Integer>("IdEmpleado"));

    Service<ObservableList<Cocinero>> service =
        new Service<ObservableList<Cocinero>>() {
          @Override
          protected Task<ObservableList<Cocinero>> createTask() {
            return new Task<ObservableList<Cocinero>>() {
              @Override
              protected ObservableList<Cocinero> call() throws Exception {
                return FXCollections.observableArrayList(getAllCocinero());
              }
            };
          }
        };

    Cocinero.itemsProperty().bind(service.valueProperty());
    service.start();
  }
  public void cargarTabla() {

    idtable.setCellValueFactory(new PropertyValueFactory<Empleado, Integer>("id"));
    nombretable.setCellValueFactory(new PropertyValueFactory<Empleado, String>("nombre"));
    telefonotable.setCellValueFactory(new PropertyValueFactory<Empleado, String>("telf"));

    // tableView.getItems().setAll();

    Service<ObservableList<Empleado>> service =
        new Service<ObservableList<Empleado>>() {
          @Override
          protected Task<ObservableList<Empleado>> createTask() {
            return new Task<ObservableList<Empleado>>() {
              @Override
              protected ObservableList<Empleado> call() throws Exception {
                return FXCollections.observableArrayList(getAllEmpleados());
              }
            };
          }
        };

    Empleados.itemsProperty().bind(service.valueProperty());
    service.start();
  }
Beispiel #3
0
  public void setContent(String cat) {
    cat = cat.trim();
    selectAllCB.setVisible(false);
    selectAllCB.setSelected(false);
    deleteBut.setVisible(false);
    restoreBut.setVisible(false);
    refreshBut.setVisible(true);
    Object columns[] = null;
    int count = 0;
    switch (cat) {
      case "Inbox":
        columns = new Object[] {"", "From", "Date", "Subject", "Content"};
        count = Database.getCount("Inbox");
        workingSet = db.getData("SELECT * FROM messages WHERE tag='inbox' ORDER BY msg_id desc");
        ;
        break;
      case "SentMail":
        columns = new Object[] {"", "To", "Date", "Subject", "Content"};
        count = Database.getCount("Sentmail");
        workingSet = db.getData("SELECT * FROM messages WHERE tag='sentmail' ORDER BY msg_id desc");
        break;
      case "Draft":
        columns = new Object[] {"", "To", "Date", "Subject", "Content"};
        count = Database.getCount("Draft");
        workingSet = db.getData("SELECT * FROM messages WHERE tag='draft' ORDER BY msg_id desc");
        break;
      case "Outbox":
        columns = new Object[] {"", "To", "Date", "Subject", "Content"};
        count = Database.getCount("Outbox");
        workingSet = db.getData("SELECT * FROM messages WHERE tag='outbox' ORDER BY msg_id desc");
        break;
      case "Trash":
        //                restoreBut.setVisible(true);
        columns = new Object[] {"", "To/From", "Date", "Subject", "Content"};
        count = Database.getCount("Trash");
        workingSet =
            db.getData(
                "SELECT * FROM messages,trash WHERE messages.tag='trash' and messages.msg_id=trash.msg_id ORDER BY deleted_at desc");
        break;
      default:
        System.out.println("in default case");
    }
    if (count > 0) {
      selectAllCB.setVisible(true);
      rows = new Object[count][];
      msgID = new int[count];
      try {
        workingSet.beforeFirst();
        for (int i = 0; i < count && workingSet.next(); i++) {
          msgID[i] = workingSet.getInt(1);
          rows[i] =
              new Object[] {
                false,
                workingSet.getString(2),
                workingSet.getDate(3),
                workingSet.getString(4),
                workingSet.getString(5)
              };
        }
      } catch (SQLException sqlExc) {
        JOptionPane.showMessageDialog(null, sqlExc, "EXCEPTION", JOptionPane.ERROR_MESSAGE);
        sqlExc.printStackTrace();
      }

      tableModel = new MyDefaultTableModel(rows, columns);
      table = new JTable(tableModel);
      table.getSelectionModel().addListSelectionListener(this);
      table.addMouseListener(this);
      table.getTableHeader().setOpaque(true);
      table.getTableHeader().setReorderingAllowed(false);
      //            table.getTableHeader().setBackground(Color.blue);
      table.getTableHeader().setForeground(Color.blue);
      //        table.setRowSelectionAllowed(false);
      //            table.setColumnSelectionAllowed(false);
      table.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 14));
      table.setRowHeight(20);
      table.setFillsViewportHeight(true);

      TableColumn column = null;
      for (int i = 0; i < 5; i++) {
        column = table.getColumnModel().getColumn(i);
        if (i == 0) {
          column.setPreferredWidth(6);
        } else if (i == 3) {
          column.setPreferredWidth(250);
        } else if (i == 4) {
          column.setPreferredWidth(450);
        } else {
          column.setPreferredWidth(40);
        }
      }
      table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);

      remove(contentPan);
      contentPan = new JScrollPane(table);
      contentPan.setBackground(Color.orange);
      contentPan.setOpaque(true);
      contentPan.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
      add(contentPan, "Center");
      Home.home.homeFrame.setVisible(true);
    } else {
      JPanel centPan = new JPanel(new GridBagLayout());
      centPan.setBackground(new Color(52, 86, 70));
      JLabel label = new JLabel("No Messages In This Category");
      label.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 22));
      label.setForeground(Color.orange);
      centPan.add(label);
      remove(contentPan);
      contentPan = new JScrollPane(centPan);
      contentPan.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
      add(contentPan, "Center");
      contentPan.repaint();
    }
  }
  // Method for displaying all available product types
  public void createStatement() {

    data = FXCollections.observableArrayList();

    // Local variables
    ResultSet rs;
    Statement stmt;
    String query = "SELECT namn FROM Produktgrupp ORDER BY namn ASC";

    try {

      stmt = con.createStatement();
      rs = stmt.executeQuery(query);

      // Clearing tables of old data
      tableview.getItems().clear();
      tableview.getColumns().clear();

      // Table columns added dynamically using ResultSet metadata.
      for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {

        // We are using non property style for making dynamic table
        final int j = i;
        TableColumn col = new TableColumn(rs.getMetaData().getColumnName(i + 1));
        col.setCellValueFactory(
            new Callback<
                TableColumn.CellDataFeatures<ObservableList, String>, ObservableValue<String>>() {
              public ObservableValue<String> call(
                  TableColumn.CellDataFeatures<ObservableList, String> param) {
                return new SimpleStringProperty(param.getValue().get(j).toString());
              }
            });

        tableview.getColumns().addAll(col);
        System.out.println("Column [" + i + "] ");
      }

      // Data added to ObservableList
      while (rs.next()) {

        // Iterate Row
        ObservableList<String> row = FXCollections.observableArrayList();
        for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {

          // Iterate Column
          row.add(rs.getString(i));
        }

        data.add(row);
      }

      // Data added to TableView
      tableview.setItems(data);

      // Close the variable stmt and release all resources bound to it
      // Any ResultSet associated to the Statement will be automatically closed too.
      stmt.close();
    } catch (Exception e) {
      e.printStackTrace();
      System.out.println("Error on Building Data");
    }
  }
  // Method for checking store stock and printing it to TableView
  public void storeStock(String store) {

    data = FXCollections.observableArrayList();

    // Local variables
    ResultSet rs;
    PreparedStatement stmt;
    // Store query string to variable
    String query =
        "SELECT Förpackning.[streckkod], LagerfördVara.[antalIButik], LagerfördVara.[maxantal] FROM Förpackning, LagerfördVara, Butik WHERE Förpackning.[streckkod]=LagerfördVara.[streckkod] AND LagerfördVara.[butik_id]=Butik.[butik_id] AND Butik.[namn]=?";

    try {

      // The new statement is placed in the variable stmt.
      // Provide the value for the first ? in the SQL statement.
      // Execute query and save ResultSet to variable rs.
      stmt = con.prepareStatement(query);
      stmt.setString(1, store);
      rs = stmt.executeQuery();

      // Clearing tables of old data
      tableview.getItems().clear();
      tableview.getColumns().clear();

      // Table columns added dynamically using ResultSet metadata.
      for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {

        // We are using non property style for making dynamic table
        final int j = i;
        TableColumn col = new TableColumn(rs.getMetaData().getColumnName(i + 1));
        col.setCellValueFactory(
            new Callback<
                TableColumn.CellDataFeatures<ObservableList, String>, ObservableValue<String>>() {
              public ObservableValue<String> call(
                  TableColumn.CellDataFeatures<ObservableList, String> param) {
                return new SimpleStringProperty(param.getValue().get(j).toString());
              }
            });

        tableview.getColumns().addAll(col);
        System.out.println("Column [" + i + "] ");
      }

      // Data added to ObservableList
      while (rs.next()) {

        // Iterate Row
        ObservableList<String> row = FXCollections.observableArrayList();
        for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {

          // Iterate Column
          row.add(rs.getString(i));
        }
        // Console printout
        System.out.println("Row [1] added " + row);
        data.add(row);
      }

      // Data added to TableView
      tableview.setItems(data);

      // Close the variable stmt and release all resources bound to it
      // Any ResultSet associated to the Statement will be automatically closed too.
      stmt.close();
    } catch (Exception e) {
      e.printStackTrace();
      System.out.println("Error on building Data");
    }
  }
  // Method for presenting all available brands of a selected product.
  public void preparedStatement(String ptype) {

    data = FXCollections.observableArrayList();

    // Local variables, query statement saved to variable query.
    ResultSet rs;
    PreparedStatement stmt;
    String query =
        "SELECT DISTINCT Märke.namn FROM "
            + "Märke, Märkesprodukt, Produkt, Produktbeskrivning, Produktgrupp "
            + "WHERE Märke.[märke_id]=Märkesprodukt.[märke_id] "
            + "AND Märkesprodukt.[produkt_id]=Produkt.[produkt_id] "
            + "AND Produkt.[pbeskrivning_id]=Produktbeskrivning.[pbeskrivning_id] "
            + "AND Produktbeskrivning.[pgrupp_id]=Produktgrupp.[pgrupp_id] "
            + "AND Produktgrupp.[namn]= ?";

    try {

      // Create a statement associated to the connection con.
      // The new statement is placed in the variable stmt.
      // Provide the value for the first ? in the SQL statement.
      // Execute query and save ResultSet to variable rs.
      stmt = con.prepareStatement(query);
      stmt.setString(1, ptype);
      rs = stmt.executeQuery();

      // Clearing tables of old data
      tableview.getItems().clear();
      tableview.getColumns().clear();

      // Table columns added dynamically using ResultSet metadata.
      for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {

        // We are using non property style for making dynamic table
        final int j = i;
        TableColumn col = new TableColumn(rs.getMetaData().getColumnName(i + 1));
        col.setCellValueFactory(
            new Callback<
                TableColumn.CellDataFeatures<ObservableList, String>, ObservableValue<String>>() {
              public ObservableValue<String> call(
                  TableColumn.CellDataFeatures<ObservableList, String> param) {
                return new SimpleStringProperty(param.getValue().get(j).toString());
              }
            });

        tableview.getColumns().addAll(col);
        System.out.println("Column [" + i + "] ");
      }

      // Data added to ObservableList
      while (rs.next()) {

        // Iterate Row
        ObservableList<String> row = FXCollections.observableArrayList();
        for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {

          // Iterate Column
          row.add(rs.getString(i));
        }
        // Console printout
        System.out.println("Row [1] added " + row);
        data.add(row);
      }

      // Data added to TableView
      tableview.setItems(data);

      // Close the variable stmt and release all resources bound to it
      // Any ResultSet associated to the Statement will be automatically closed too.
      stmt.close();
    } catch (Exception e) {
      e.printStackTrace();
      System.out.println("Error on Building Data");
    }
  }