Example usage for javafx.scene.control TableColumn.CellEditEvent getTableView

List of usage examples for javafx.scene.control TableColumn.CellEditEvent getTableView

Introduction

In this page you can find the example usage for javafx.scene.control TableColumn.CellEditEvent getTableView.

Prototype

public final TableView<S> getTableView() 

Source Link

Usage

From source file:ninja.javafx.smartcsv.fx.SmartCSVController.java

/**
 * Adds a column with the given name to the tableview
 * @param header name of the column header
 * @param tableView the tableview/*w  w w .j  a va2  s.  c  o m*/
 */
private void addColumn(final String header, TableView tableView) {
    TableColumn column = new TableColumn(header);
    column.setCellValueFactory(new ObservableMapValueFactory(header));
    column.setCellFactory(cellFactory);
    column.setEditable(true);
    column.setSortable(false);

    ContextMenu contextMenu = contextMenuForColumn(header);
    column.setContextMenu(contextMenu);

    column.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent<CSVRow, CSVValue>>() {
        @Override
        public void handle(TableColumn.CellEditEvent<CSVRow, CSVValue> event) {
            event.getTableView().getItems().get(event.getTablePosition().getRow()).getColumns().get(header)
                    .setValue(event.getNewValue());
            runLater(() -> {
                currentCsvFile.setFileChanged(true);
            });
        }
    });

    tableView.getColumns().add(column);
}

From source file:frontend.GUIController.java

@Override
public void initialize(URL url, ResourceBundle rb) throws IllegalArgumentException {
    at = new AnnotationTask();
    comboBoxes = new ArrayList<ComboBox<String>>();
    comboBoxes.add(combo1);/*from w w  w.  j  a  v  a2s .c o m*/
    comboBoxes.add(combo3);
    comboBoxes.add(combo5);
    comboBoxes.add(combo7);
    comboBoxes.add(combo9);
    comboBoxes.add(combo2);
    comboBoxes.add(combo4);
    comboBoxes.add(combo6);
    comboBoxes.add(combo8);
    comboBoxes.add(combo10);

    for (int i = 0; i < comboBoxes.size(); i++) {
        comboBoxes.get(i).setPromptText("Choose one");
    }

    predModel.getItems().add(MODELTYPE.SENTIMENT_WORD);
    predModel.getItems().add(MODELTYPE.CUSTOM);
    /* Handle ComboBox event.
    predModel.setOnAction((event) -> {
    if(predModel.getSelectionModel().getSelectedItem().equals(MODELTYPE.CUSTOM)){
       System.out.println("ComboBox Action (selected: " + MODELTYPE.CUSTOM + ")");
       try {
       this.selectModelFile(event);
    } catch (Exception e) {
       e.printStackTrace();
    }
    }
    });//*/
    //predModel.getItems().add(MODELTYPE.SENTIMENT);
    //predModel.getSelectionModel().selectFirst();
    //progressBar = new ProgressIndicator();

    // always use 'custom' config - what's in the config file!
    predModel.getSelectionModel().selectLast();
    predModel.setDisable(true);

    //        tabPane.prefWidthProperty().bind(scene.widthProperty());
    //        tabPane.prefHeightProperty().bind(scene.heightProperty());

    tweetText.setCellValueFactory(new PropertyValueFactory<Tweet, String>("tweet"));
    tweetText.setCellFactory(new Callback<TableColumn<Tweet, String>, TableCell<Tweet, String>>() {
        @Override
        public TableCell<Tweet, String> call(TableColumn<Tweet, String> param) {
            final TableCell<Tweet, String> cell = new TableCell<Tweet, String>() {
                private Text text;

                @Override
                public void updateItem(String item, boolean empty) {
                    super.updateItem(item, empty);
                    if (!isEmpty()) {
                        text = new Text(item.toString());
                        text.wrappingWidthProperty().bind(getTableColumn().widthProperty());
                        setGraphic(text);
                    }
                }
            };
            return cell;
        }
    });
    tweetLabel.setCellValueFactory(new PropertyValueFactory<Tweet, LABEL>("label"));
    tweetLabel.setCellFactory(ComboBoxTableCell.<Tweet, LABEL>forTableColumn(LABEL.values()));
    tweetLabel.setEditable(true);
    // add here
    //        
    //        tweetLabel.setOnEditCommit(
    //                (CellEditEvent<Tweet, LABEL> t) -> {
    //                    ((Tweet) t.getTableView().getItems().get(
    //                            t.getTablePosition().getRow())
    //                            ).setLabel(t.getNewValue());
    //            });

    tweetLabel.setOnEditCommit(event -> {
        @SuppressWarnings("rawtypes")
        final TableColumn.CellEditEvent _evn = (TableColumn.CellEditEvent) event;
        int rowId = _evn.getTablePosition().getRow();
        String newVal = _evn.getNewValue().toString();
        Tweet t = ((Tweet) _evn.getTableView().getItems().get(rowId));
        t.setLabel(LABEL.getEnum(newVal));
        System.out.println("Getting new value at row : " + rowId + " with label " + newVal);
        System.out.println("Tweet information : " + t.toString());
        String[] meta = t.getMeta();
        System.out.println(t.getTweet() + "\t" + meta[meta.length - 8]);
        System.out.println(
                personData.get(rowId).getTweet() + "\t" + personData.get(rowId).getMeta()[meta.length - 8]);

    });

    tweetFeature.setCellValueFactory(new PropertyValueFactory<Tweet, String>("feature"));
    tweetProb.setCellValueFactory(new PropertyValueFactory<Tweet, Double>("probability"));
    dirChooser.setInitialDirectory(new File(System.getProperty("user.dir")));
    /*tweetText.prefWidthProperty().bind(featureTable.widthProperty().divide(4)); // w * 2/4
    tweetLabel.prefWidthProperty().bind(featureTable.widthProperty().divide(2)); // w * 1/4
    tweetFeature.prefWidthProperty().bind(featureTable.widthProperty().divide(4)); // w * 1/4        
     */

}

From source file:staff.Waiter.MenuController.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    DBConn c = new DBConn();
    conn = c.geConnection();/*  w ww. j  av  a2  s .co m*/

    menutable.setEditable(true);
    mid.setCellValueFactory(new PropertyValueFactory<>("mid"));
    mname.setCellValueFactory(new PropertyValueFactory<>("mname"));
    mprice.setCellValueFactory(new PropertyValueFactory<>("mprice"));
    mquantity.setCellValueFactory(new PropertyValueFactory<>("mquantity"));
    mquantity.setEditable(true);

    mquantity.setCellFactory(TextFieldTableCell.forTableColumn());
    mquantity.setOnEditCommit((TableColumn.CellEditEvent<Menu, String> t) -> {

        ((Menu) t.getTableView().getItems().get(t.getTablePosition().getRow())).setMquantity(t.getNewValue());
    });
    s = new String[20];
    idx = 0;
    getListButton.setDisable(true);
    couponTextField.setEditable(false);
}