Java Code Examples for javafx.scene.control.TableColumn#setEditable()

The following examples show how to use javafx.scene.control.TableColumn#setEditable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FormulaPane.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
private TableView<InputItem> createInputs()
{
    TableColumn<InputItem, String> col = new TableColumn<>(Messages.FormulaTabInput);
    col.setCellValueFactory(c ->  c.getValue().input_name);
    input_table.getColumns().add(col);

    col = new TableColumn<>(Messages.FormulaTabVariable);
    col.setCellValueFactory(c ->  c.getValue().variable_name);
    col.setCellFactory(TextFieldTableCell.forTableColumn());
    // When variable is renamed, re-evaluate formula
    col.setOnEditCommit(event -> parseFormula());
    col.setEditable(true);
    input_table.getColumns().add(col);

    input_table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    input_table.setTooltip(new Tooltip(Messages.FormulaTabTT));
    input_table.setEditable(true);
    // Double-click (on input column) adds that variable name to formula
    input_table.addEventHandler(MouseEvent.MOUSE_PRESSED, event ->
    {
        if (event.getClickCount() == 2)
            insert(input_table.getSelectionModel().getSelectedItem().variable_name.get());
    });

    return input_table;
}
 
Example 2
Source File: TableController.java    From zest-writer with GNU General Public License v3.0 6 votes vote down vote up
private void addCol() {
    TableColumn tc = new TableColumn();
    tc.setEditable(true);
    tc.setCellValueFactory(param -> {
        CellDataFeatures<ZRow, String> dtf = (CellDataFeatures<ZRow, String>) param;
        return new SimpleStringProperty(dtf.getValue().getRow().get(0));
    });

    tc.setCellFactory(TextFieldTableCell.forTableColumn());
    tc.setOnEditCommit(t -> {
        CellEditEvent<ZRow, String> evt = (CellEditEvent<ZRow, String>) t;
        List<String> row = evt.getTableView().getItems().get(evt.getTablePosition().getRow()).getRow();
        row.set(evt.getTablePosition().getColumn(), evt.getNewValue());
    });
    tc.setPrefWidth(150);
    TextField txf = new TextField();
    txf.setPrefWidth(150);
    txf.setPromptText(Configuration.getBundle().getString("ui.dialog.table_editor.colon") +
            (tableView.getColumns().size()+1));
    tc.setGraphic(txf);
    tableView.getColumns().addAll(tc);
    postAddColumn();
}
 
Example 3
Source File: CTimePeriodField.java    From Open-Lowcode with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public TableColumn<ObjectTableRow, TimePeriod> getTableColumn(
		PageActionManager pageactionmanager,
		boolean largedisplay,
		int preferedrowheight,
		String actionkeyforupdate) {
	TableColumn<
			ObjectTableRow, TimePeriod> thiscolumn = new TableColumn<ObjectTableRow, TimePeriod>(this.getLabel());
	if (actionkeyforupdate != null) {
		thiscolumn.setEditable(true);
		thiscolumn.setOnEditCommit(new TableColumnOnEditCommit(this));
	} else {
		thiscolumn.setEditable(false);
	}

	int length = 15 * 7;
	if (length > 300)
		length = 300;

	double pixellength = ((new Text(this.label)).getBoundsInLocal().getWidth() + 10) * 1.05;

	int pixellengthi = (int) pixellength;
	thiscolumn.setMinWidth(pixellengthi);
	thiscolumn.setPrefWidth(pixellengthi);
	thiscolumn.setCellValueFactory(new TableCellValueFactory(this));

	thiscolumn.setCellFactory(new TableCellFactory(helper, periodtype));

	return thiscolumn;
}
 
Example 4
Source File: CChoiceField.java    From Open-Lowcode with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public TableColumn<ObjectTableRow, CChoiceFieldValue> getTableColumn(
		PageActionManager pageactionmanager,
		boolean largedisplay,
		int rowheight,
		String actionkeyforupdate) {

	TableColumn<
			ObjectTableRow,
			CChoiceFieldValue> thiscolumn = new TableColumn<ObjectTableRow, CChoiceFieldValue>(this.getLabel());
	if ((actionkeyforupdate != null) && (this.isEditable()))  {
		thiscolumn.setEditable(true);
		thiscolumn.setOnEditCommit(new TableColumnOnEditCommit(this));
	} else {
		thiscolumn.setEditable(false);
	}

	int length = this.maxcharlength * 7;
	if (length > 300)
		length = 300;
	if (this.prefereddisplaysizeintable >= 0) {
		length = this.prefereddisplaysizeintable * 7;

	}

	double pixellength = ((new Text(this.label)).getBoundsInLocal().getWidth() + 10) * 1.05;
	for (int i = 0; i < this.values.size(); i++) {
		double valuelength = ((new Text(values.get(i).getDisplayvalue()).getBoundsInLocal().getWidth()) + 10)
				* 1.05;
		if (valuelength > pixellength)
			pixellength = valuelength;
	}
	int pixellengthi = (int) pixellength;
	thiscolumn.setMinWidth(pixellengthi);
	thiscolumn.setPrefWidth(pixellengthi);
	logger.fine(" --**-- length for field" + this.getLabel() + " maxcharlength:" + maxcharlength
			+ " pref display in table " + this.prefereddisplaysizeintable + " final length = " + length
			+ " - pixel length" + pixellengthi);
	thiscolumn.setCellValueFactory(new TableCellValueFactory(this));
	thiscolumn.setCellFactory(new TableCellFactory(helper, values));
	return thiscolumn;
}
 
Example 5
Source File: ScansTable.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private void createTable()
{
    // Don't really allow editing, just copying from some of the text fields
    scan_table.setEditable(true);

    final TableColumn<ScanInfoProxy, Number> id_col = new TableColumn<>("ID");
    id_col.setPrefWidth(40);
    id_col.setStyle("-fx-alignment: CENTER-RIGHT;");
    id_col.setCellValueFactory(cell -> cell.getValue().id);
    scan_table.getColumns().add(id_col);

    final TableColumn<ScanInfoProxy, Instant> create_col = new TableColumn<>("Created");
    create_col.setCellValueFactory(cell -> cell.getValue().created);
    create_col.setCellFactory(cell -> new InstantCell());
    scan_table.getColumns().add(create_col);

    final TableColumn<ScanInfoProxy, String> name_col = new TableColumn<>("Name");
    name_col.setCellValueFactory(cell -> cell.getValue().name);
    name_col.setCellFactory(info -> new TextCopyCell());
    name_col.setEditable(true);
    scan_table.getColumns().add(name_col);

    final TableColumn<ScanInfoProxy, ScanState> state_col = new TableColumn<>("State");
    state_col.setPrefWidth(210);
    state_col.setCellValueFactory(cell -> cell.getValue().state);
    state_col.setCellFactory(cell -> new StateCell(scan_client));
    state_col.setComparator((a, b) ->  rankState(a) - rankState(b));
    scan_table.getColumns().add(state_col);

    final TableColumn<ScanInfoProxy, Number> perc_col = new TableColumn<>("%");
    perc_col.setPrefWidth(50);
    perc_col.setCellValueFactory(cell -> cell.getValue().percent);
    perc_col.setCellFactory(cell -> new PercentCell());
    scan_table.getColumns().add(perc_col);

    final TableColumn<ScanInfoProxy, String>  rt_col = new TableColumn<>("Runtime");
    rt_col.setCellValueFactory(cell -> cell.getValue().runtime);
    scan_table.getColumns().add(rt_col);

    final TableColumn<ScanInfoProxy, Instant> finish_col = new TableColumn<>("Finish");
    finish_col.setCellValueFactory(cell -> cell.getValue().finish);
    finish_col.setCellFactory(cell -> new InstantCell());
    scan_table.getColumns().add(finish_col);

    final TableColumn<ScanInfoProxy, String> cmd_col = new TableColumn<>("Command");
    cmd_col.setPrefWidth(200);
    cmd_col.setCellValueFactory(cell -> cell.getValue().command);
    cmd_col.setCellFactory(info -> new TextCopyCell());
    cmd_col.setEditable(true);
    scan_table.getColumns().add(cmd_col);

    TableColumn<ScanInfoProxy, String> err_col = new TableColumn<>("Error");
    err_col.setCellValueFactory(cell -> cell.getValue().error);
    err_col.setCellFactory(info -> new TextCopyCell());
    err_col.setEditable(true);
    scan_table.getColumns().add(err_col);

    // Last column fills remaining space
    err_col.prefWidthProperty().bind(scan_table.widthProperty()
                                               .subtract(id_col.widthProperty())
                                               .subtract(create_col.widthProperty())
                                               .subtract(name_col.widthProperty())
                                               .subtract(state_col.widthProperty())
                                               .subtract(perc_col.widthProperty())
                                               .subtract(rt_col.widthProperty())
                                               .subtract(finish_col.widthProperty())
                                               .subtract(cmd_col.widthProperty())
                                               .subtract(2));

    scan_table.setPlaceholder(new Label("No Scans"));

    scan_table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

    sorted_scans.comparatorProperty().bind(scan_table.comparatorProperty());
}
 
Example 6
Source File: PaceColumn.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public TableColumn<SelectionTableRowData, String> getTableColumn() {
    TableColumn<SelectionTableRowData, String> tableColumn = SelectionTableColumn.super.getTableColumn();
    tableColumn.setEditable(true);
    tableColumn.setOnEditCommit(t -> t.getTableView().getItems().get(t.getTablePosition().getRow()).pace
            .set(defaultIfBlank(t.getNewValue(), "1")));
    return tableColumn;
}
 
Example 7
Source File: PageRangesColumn.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public TableColumn<SelectionTableRowData, String> getTableColumn() {
    TableColumn<SelectionTableRowData, String> tableColumn = SelectionTableColumn.super.getTableColumn();
    tableColumn.setEditable(true);
    tableColumn.setOnEditCommit(
            t -> t.getTableView().getItems().get(t.getTablePosition().getRow()).pageSelection.set(t.getNewValue()));
    return tableColumn;
}
 
Example 8
Source File: CMultipleChoiceField.java    From Open-Lowcode with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public TableColumn<ObjectTableRow, ?> getTableColumn(
		PageActionManager pageactionmanager,
		boolean largedisplay,
		int preferedrowheight,
		String actionkeyforupdate) {
	TableColumn<ObjectTableRow, String> thiscolumn = new TableColumn<ObjectTableRow, String>(this.getLabel());
	thiscolumn.setEditable(false);
	int length = (this.maxcharlength * 7);
	if (length > 300)
		length = 300;
	if (this.prefereddisplayintable >= 0) {
		length = this.prefereddisplayintable * 7;

	}
	logger.fine(" --**-- length for field" + this.getLabel() + " maxcharlength:" + maxcharlength
			+ " pref display in table " + this.prefereddisplayintable + " final length = " + length);

	thiscolumn.setMinWidth(length);
	thiscolumn.setPrefWidth(length);
	CMultipleChoiceField thischoicefield = this;
	thiscolumn.setCellValueFactory(
			new Callback<TableColumn.CellDataFeatures<ObjectTableRow, String>, ObservableValue<String>>() {

				@SuppressWarnings("unchecked")
				@Override
				public ObservableValue<String> call(
						javafx.scene.control.TableColumn.CellDataFeatures<ObjectTableRow, String> p) {

					ObjectDataElt line = p.getValue().getObject();
					String fieldname = thischoicefield.getFieldname();
					if (line == null)
						return new SimpleStringProperty("");
					SimpleDataElt lineelement = line.lookupEltByName(fieldname);
					if (lineelement == null) {

						return new SimpleStringProperty("Field Not found !" + fieldname);
					}
					if (!(lineelement instanceof MultipleChoiceDataElt))
						return new SimpleStringProperty("Invalid type " + lineelement.getType());

					return new SimpleStringProperty(thischoicefield
							.displayMultiValue((MultipleChoiceDataElt<CChoiceFieldValue>) lineelement));
				}

			});
	return thiscolumn;
}
 
Example 9
Source File: CIntegerField.java    From Open-Lowcode with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public TableColumn<ObjectTableRow, Integer> getTableColumn(
		PageActionManager pageactionmanager,
		boolean largedisplay,
		int preferedrowheight,
		String actionkeyforupdate) {
	TableColumn<ObjectTableRow, Integer> thiscolumn = new TableColumn<ObjectTableRow, Integer>(this.getLabel());
	if (actionkeyforupdate != null) {
		thiscolumn.setEditable(true);
	} else {
		thiscolumn.setEditable(false);
	}
	int length = 110;
	thiscolumn.setMinWidth(length);
	CIntegerField thisintegerfield = this;

	thiscolumn.setCellFactory(column -> {
		return new TableCell<ObjectTableRow, Integer>() {
			@Override
			protected void updateItem(Integer integer, boolean empty) {
				super.updateItem(integer, empty);
				if (integer == null || empty) {
					setText("0");

				} else {
					setText(integer.toString());

				}

			}
		};
	});

	thiscolumn.setCellValueFactory(
			new Callback<CellDataFeatures<ObjectTableRow, Integer>, ObservableValue<Integer>>() {

				@Override
				public ObservableValue<Integer> call(CellDataFeatures<ObjectTableRow, Integer> p) {
					try {
						ObjectTableRow line = p.getValue();
						String fieldname = thisintegerfield.getFieldname();
						SimpleDataElt lineelement = line.getFieldDataEltClone(fieldname);

						if (lineelement == null)
							return new SimpleObjectProperty<Integer>(null);
						if (!(lineelement instanceof IntegerDataElt))
							return new SimpleObjectProperty<Integer>(null);
						IntegerDataElt linedataelt = (IntegerDataElt) lineelement;
						return new SimpleObjectProperty<Integer>(linedataelt.getPayload());
					} catch (RuntimeException e) {
						ExceptionLogger.setInLogs(e, logger);
						return null;
					}
				}

			});

	return thiscolumn;
}
 
Example 10
Source File: StringTableDemo.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void start(Stage stage) throws Exception
{
    TableColumn<List<StringProperty>, String> tc = new TableColumn<>("A");
    tc.setCellValueFactory(param ->  param.getValue().get(0));
    tc.setCellFactory(TextFieldTableCell.forTableColumn());

    tc.setOnEditCommit(event ->
    {
        final int col = event.getTablePosition().getColumn();
        event.getRowValue().get(col).set(event.getNewValue());
    });

    tc.setEditable(true);
    table.getColumns().add(tc);

    tc = new TableColumn<>("B");
    tc.setCellValueFactory(param ->  param.getValue().get(1));
    tc.setCellFactory(TextFieldTableCell.forTableColumn());
    tc.setEditable(true);
    table.getColumns().add(tc);

    table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

    table.setEditable(true);

    final Scene scene = new Scene(table, 800, 600);
    stage.setScene(scene);
    stage.show();

    List<StringProperty> row = new ArrayList<>();
    row.add(new SimpleStringProperty("One"));
    row.add(new SimpleStringProperty("Another"));
    data.add(row);

    row = new ArrayList<>();
    row.add(new SimpleStringProperty("Two"));
    row.add(new SimpleStringProperty("Something"));
    data.add(row);

    final Thread change_cell = new Thread(() ->
    {
        while (true)
        {
            try
            {
                Thread.sleep(500);
            }
            catch (InterruptedException e)
            {
                e.printStackTrace();
            }
            Platform.runLater(() ->  updateCell(1, 0, LocalDateTime.now().toString().replace('T', ' ')));
        }
    });
    change_cell.setDaemon(true);
    change_cell.start();
}
 
Example 11
Source File: GUI.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
private TableView<Instance> createTable()
{
    final TableView<Instance> table = new TableView<>(FXCollections.observableList(model.getInstances()));
    table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    table.getSelectionModel().setCellSelectionEnabled(true);

    table.setEditable(true);

    TableColumn<Instance, String> col = new TableColumn<>(Messages.SystemColumn);
    col.setCellValueFactory(cell -> new SimpleStringProperty(cell.getValue().getName()));
    table.getColumns().add(col);

    int col_index = 0;
    for (Column column : model.getColumns())
    {
        final int the_col_index = col_index;
        col = new TableColumn<>(column.getName());
        col.setCellFactory(info -> new PACETableCell());
        col.setCellValueFactory(cell -> cell.getValue().getCell(the_col_index).getObservable());
        table.getColumns().add(col);

        if (column.isReadonly())
            col.setEditable(false);
        else
        {
            col.setOnEditCommit(event ->
            {
                event.getRowValue().getCell(the_col_index).setUserValue(event.getNewValue());
                final int row = event.getTablePosition().getRow();
                // Start to edit same column in next row
                if (row < table.getItems().size() - 1)
                    Platform.runLater(() ->  table.edit(row+1, event.getTableColumn()));
            });
        }

        ++col_index;
    }

    return table;
}