Search in sources :

Example 1 with CellDataFeatures

use of javafx.scene.control.TableColumn.CellDataFeatures in project Gargoyle by callakrsos.

the class ColumnExample3Con method initialize.

@FXML
public void initialize() {
    tableView.setEditable(true);
    {
        Map<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("commCode", "코드1");
        hashMap.put("commCodeNm", "데이터 1");
        tableView.getItems().add(hashMap);
    }
    {
        Map<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("commCode", "코드1");
        hashMap.put("commCodeNm", "데이터 223492342309842402394823049238420942384029343809248420934809428409238409238423094823049");
        tableView.getItems().add(hashMap);
    }
    {
        Map<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("commCode", "코드3");
        hashMap.put("commCodeNm", "데이터 3");
        tableView.getItems().add(hashMap);
    }
    {
        Map<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("commCode", "코드4");
        hashMap.put("commCodeNm", "데이터 4");
        tableView.getItems().add(hashMap);
    }
    colCode.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Map<String, String>, String>, ObservableValue<String>>() {

        @Override
        public ObservableValue<String> call(CellDataFeatures<Map<String, String>, String> param) {
            return new SimpleStringProperty(param.getValue().get("commCode"));
        }
    });
    colCodeNm.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Map<String, String>, String>, ObservableValue<String>>() {

        @Override
        public ObservableValue<String> call(CellDataFeatures<Map<String, String>, String> param) {
            return new SimpleStringProperty(param.getValue().get("commCodeNm"));
        }
    });
}
Also used : CellDataFeatures(javafx.scene.control.TableColumn.CellDataFeatures) ObservableValue(javafx.beans.value.ObservableValue) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Map(java.util.Map) HashMap(java.util.HashMap) FXML(javafx.fxml.FXML)

Example 2 with CellDataFeatures

use of javafx.scene.control.TableColumn.CellDataFeatures in project org.csstudio.display.builder by kasemir.

the class PointsTable method create.

/**
 * @return Top-level {@link Node}
 */
public Node create() {
    // Layout:
    // 
    // | table |  [Add]
    // | table |  [Remove]
    // | table |
    // | table |
    // Create table with editable columns for type Double (supported as Number)
    final TableColumn<Point, Number> x_col = new TableColumn<>(Messages.PointsTable_X);
    x_col.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Point, Number>, ObservableValue<Number>>() {

        @Override
        public ObservableValue<Number> call(CellDataFeatures<Point, Number> param) {
            return new SimpleDoubleProperty(param.getValue().getX());
        }
    });
    x_col.setCellFactory(TextFieldTableCell.<Point, Number>forTableColumn(new NumberStringConverter()));
    x_col.setOnEditCommit(event -> {
        final int row = event.getTablePosition().getRow();
        points.setX(row, event.getNewValue().doubleValue());
    });
    final TableColumn<Point, Number> y_col = new TableColumn<>(Messages.PointsTable_Y);
    y_col.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Point, Number>, ObservableValue<Number>>() {

        @Override
        public ObservableValue<Number> call(CellDataFeatures<Point, Number> param) {
            return new SimpleDoubleProperty(param.getValue().getY());
        }
    });
    y_col.setCellFactory(TextFieldTableCell.<Point, Number>forTableColumn(new NumberStringConverter()));
    y_col.setOnEditCommit(event -> {
        final int row = event.getTablePosition().getRow();
        points.setY(row, event.getNewValue().doubleValue());
    });
    final ObservableList<Point> data = new PointsAdapter(points);
    final TableView<Point> table = new TableView<>(data);
    table.getColumns().add(x_col);
    table.getColumns().add(y_col);
    table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    table.setPlaceholder(new Label(Messages.PointsTable_Empty));
    table.setEditable(true);
    // Buttons
    final Button add = new Button(Messages.Add, JFXUtil.getIcon("add.png"));
    add.setMaxWidth(Double.MAX_VALUE);
    add.setOnAction(event -> data.add(new Point(0, 0)));
    final Button remove = new Button(Messages.Remove, JFXUtil.getIcon("delete.png"));
    remove.setMaxWidth(Double.MAX_VALUE);
    remove.setOnAction(event -> {
        final int sel = table.getSelectionModel().getSelectedIndex();
        if (sel >= 0)
            data.remove(sel);
    });
    final Button up = new Button(Messages.MoveUp, JFXUtil.getIcon("up.png"));
    up.setMaxWidth(Double.MAX_VALUE);
    up.setOnAction(event -> TableHelper.move_item_up(table, data));
    final Button down = new Button(Messages.MoveDown, JFXUtil.getIcon("down.png"));
    down.setMaxWidth(Double.MAX_VALUE);
    down.setOnAction(event -> TableHelper.move_item_down(table, data));
    final VBox buttons = new VBox(10, add, remove, up, down);
    final HBox content = new HBox(10, table, buttons);
    HBox.setHgrow(table, Priority.ALWAYS);
    return content;
}
Also used : HBox(javafx.scene.layout.HBox) CellDataFeatures(javafx.scene.control.TableColumn.CellDataFeatures) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) ObservableValue(javafx.beans.value.ObservableValue) Label(javafx.scene.control.Label) Point(org.csstudio.display.builder.model.properties.Point) TableColumn(javafx.scene.control.TableColumn) Point(org.csstudio.display.builder.model.properties.Point) NumberStringConverter(javafx.util.converter.NumberStringConverter) Button(javafx.scene.control.Button) VBox(javafx.scene.layout.VBox) TableView(javafx.scene.control.TableView)

Example 3 with CellDataFeatures

use of javafx.scene.control.TableColumn.CellDataFeatures in project Gargoyle by callakrsos.

the class CheckBoxTableCellExam method start.

/*
	 * (non-Javadoc)
	 *
	 * @see javafx.application.Application#start(javafx.stage.Stage)
	 */
@Override
public void start(Stage primaryStage) throws Exception {
    TableView<SampleVO> center = new TableView<>();
    center.setEditable(true);
    TableColumn<SampleVO, Boolean> e = new TableColumn<SampleVO, Boolean>();
    e.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<SampleVO, Boolean>, ObservableValue<Boolean>>() {

        @Override
        public ObservableValue<Boolean> call(CellDataFeatures<SampleVO, Boolean> param) {
            return param.getValue().checked;
        }
    });
    e.setCellFactory(new Callback<TableColumn<SampleVO, Boolean>, TableCell<SampleVO, Boolean>>() {

        @Override
        public TableCell<SampleVO, Boolean> call(TableColumn<SampleVO, Boolean> param) {
            return new CheckBoxTableCell<SampleVO, Boolean>() {

                /*
					 * (non-Javadoc)
					 *
					 * @see
					 * javafx.scene.control.cell.CheckBoxTableCell#updateItem(
					 * java.lang.Object, boolean)
					 */
                @Override
                public void updateItem(Boolean item, boolean empty) {
                    super.updateItem(item, empty);
                }

                /*
					 * (non-Javadoc)
					 *
					 * @see
					 * javafx.scene.control.Cell#isItemChanged(java.lang.Object,
					 * java.lang.Object)
					 */
                @Override
                protected boolean isItemChanged(Boolean oldItem, Boolean newItem) {
                    System.out.println(oldItem + " : " + newItem);
                    return super.isItemChanged(oldItem, newItem);
                }
            };
        }
    });
    e.setEditable(true);
    TableColumn<SampleVO, String> e2 = new TableColumn<SampleVO, String>();
    e2.setCellValueFactory(new PropertyValueFactory<SampleVO, String>("name"));
    center.getColumns().add(e);
    center.getColumns().add(e2);
    center.getItems().add(new SampleVO(true, "kim"));
    center.getItems().add(new SampleVO(true, "young"));
    BorderPane borderPane = new BorderPane(center);
    primaryStage.setScene(new Scene(borderPane));
    primaryStage.show();
}
Also used : BorderPane(javafx.scene.layout.BorderPane) CellDataFeatures(javafx.scene.control.TableColumn.CellDataFeatures) ObservableValue(javafx.beans.value.ObservableValue) Scene(javafx.scene.Scene) TableColumn(javafx.scene.control.TableColumn) TableCell(javafx.scene.control.TableCell) CheckBoxTableCell(javafx.scene.control.cell.CheckBoxTableCell) SampleVO(com.kyj.fx.voeditor.visual.example.CheckBoxTableCellExam.SampleVO) TableView(javafx.scene.control.TableView)

Example 4 with CellDataFeatures

use of javafx.scene.control.TableColumn.CellDataFeatures in project Gargoyle by callakrsos.

the class AbstractTableColumnInformationController method initialize.

@FXML
public void initialize() {
    colNumber.setCellValueFactory(new NumberingCellValueFactory<TableColumnMetaVO>(tbColumns));
    colKeyType.setCellFactory(param -> new TableCell<TableColumnMetaVO, KEY_TYPE>() {

        @Override
        protected void updateItem(KEY_TYPE item, boolean empty) {
            super.updateItem(item, empty);
            if (empty) {
                setGraphic(null);
            } else {
                ImageView image = null;
                switch(item) {
                    case PRI:
                        image = getImage(PRIMAKRY_KEY_IMAGE_NAME);
                        image.setFitWidth(getPrefWidth());
                        setGraphic(image);
                        break;
                    case MULTI:
                        image = getImage(MULTI_KEY_IMAGE_NAME);
                        image.setFitWidth(getPrefWidth());
                        setGraphic(image);
                        break;
                    case FOREIGN:
                        image = getImage(FOREIGN_KEY_IMAGE_NAME);
                        image.setFitWidth(getPrefWidth());
                        setGraphic(image);
                        break;
                    default:
                        image = new ImageView();
                }
                setGraphic(image);
            }
        }
    });
    colReference.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<TableColumnMetaVO, String>, ObservableValue<String>>() {

        @Override
        public ObservableValue<String> call(CellDataFeatures<TableColumnMetaVO, String> param) {
            TableColumnMetaVO value = param.getValue();
            SimpleStringProperty stringProperty = new SimpleStringProperty();
            if (value != null && value.getRefs() != null) {
                Optional<String> reduce = value.getRefs().stream().map(v -> v.getPkColumnName() + " ->  [ " + v.getFkTableName() + "-" + v.getFkColumnName() + " ]").reduce((str1, str2) -> str1.concat("\n").concat(str2));
                reduce.ifPresent(stringProperty::setValue);
            }
            return stringProperty;
        }
    });
    colKeyType.setCellValueFactory(new PropertyValueFactory<>("keyType"));
    colKeyType.setStyle("-fx-alignment:center");
    this.tbColumns.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    FxUtil.installClipboardKeyEvent(this.tbColumns);
}
Also used : KEY_TYPE(com.kyj.fx.voeditor.visual.component.sql.table.IKeyType.KEY_TYPE) NumberingCellValueFactory(com.kyj.fx.voeditor.visual.component.NumberingCellValueFactory) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) LoggerFactory(org.slf4j.LoggerFactory) DatabaseMetaData(java.sql.DatabaseMetaData) Function(java.util.function.Function) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) SQLException(java.sql.SQLException) TableCell(javafx.scene.control.TableCell) ResultSet(java.sql.ResultSet) Map(java.util.Map) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) Logger(org.slf4j.Logger) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) Set(java.util.Set) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) Collectors(java.util.stream.Collectors) CellDataFeatures(javafx.scene.control.TableColumn.CellDataFeatures) FXML(javafx.fxml.FXML) FxUtil(com.kyj.fx.voeditor.visual.util.FxUtil) List(java.util.List) SelectionMode(javafx.scene.control.SelectionMode) TreeMap(java.util.TreeMap) ImageView(javafx.scene.image.ImageView) RowMapper(org.springframework.jdbc.core.RowMapper) Optional(java.util.Optional) ObservableValue(javafx.beans.value.ObservableValue) Collections(java.util.Collections) Image(javafx.scene.image.Image) InputStream(java.io.InputStream) CellDataFeatures(javafx.scene.control.TableColumn.CellDataFeatures) Optional(java.util.Optional) ObservableValue(javafx.beans.value.ObservableValue) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) ImageView(javafx.scene.image.ImageView) KEY_TYPE(com.kyj.fx.voeditor.visual.component.sql.table.IKeyType.KEY_TYPE) FXML(javafx.fxml.FXML)

Example 5 with CellDataFeatures

use of javafx.scene.control.TableColumn.CellDataFeatures in project Gargoyle by callakrsos.

the class TextBaseDiffAppController method initialize.

@FXML
public void initialize() {
    /* initControls */
    ivReviced = new ImageView();
    ivpReviced = new ImageViewPane(ivReviced);
    ivpReviced.setPrefWidth(200);
    ivpReviced.setPrefHeight(150);
    ivOrigin = new ImageView();
    ivpOrigin = new ImageViewPane(ivOrigin);
    ivpOrigin.setPrefWidth(200);
    ivpOrigin.setPrefHeight(150);
    gpSnap.add(ivpReviced, 0, 0);
    gpSnap.add(ivpOrigin, 1, 0);
    lvOrinal.setCellFactory(param -> new DefaultTextFieldListCell(ORIGINAL));
    lvRevice.setCellFactory(param -> new DefaultTextFieldListCell(REVICED));
    fileCompareResultProperty.addListener(compareResultListener);
    lvRevice.setOnMouseClicked(event -> {
        if (event.getClickCount() == 2) {
            int movePosition = -1;
            ChunkWrapper selectedItem = lvRevice.getSelectionModel().getSelectedItem();
            Delta delta = selectedItem.getDelta();
            if (delta != null && delta.getOriginal() != null) {
                movePosition = selectedItem.getPosition();
                lvOrinal.scrollTo(movePosition - 1);
                lvOrinal.getSelectionModel().select(movePosition);
            }
        }
    });
    lvOrinal.setOnMouseClicked(event -> {
        if (event.getClickCount() == 2) {
            int movePosition = -1;
            ChunkWrapper selectedItem = lvOrinal.getSelectionModel().getSelectedItem();
            if (selectedItem != null) {
                Delta delta = selectedItem.getDelta();
                if (delta != null && delta.getRevised() != null) {
                    movePosition = delta.getRevised().getPosition();
                    lvRevice.scrollTo(movePosition - 1);
                    lvRevice.getSelectionModel().select(movePosition);
                }
            }
        }
    });
    lvOrinal.addEventFilter(ScrollEvent.SCROLL, event -> {
        snappOriginShot();
    });
    lvRevice.addEventFilter(ScrollEvent.SCROLL, event -> {
        snappReviceShot();
    });
    btnCompare.setOnMouseClicked(event -> {
        String ori = txtOrigin.getText();
        String rev = txtRevice.getText();
        if (!(ori.isEmpty() && rev.isEmpty())) {
            clear();
            try {
                this.compare.setOriginal(ori);
                this.compare.setRevised(rev);
                CompareResult chunkResult = this.compare.getChunkResult();
                this.fileCompareResultProperty.set(chunkResult);
                snappOriginShot();
                snappReviceShot();
            } catch (Exception e) {
                LOGGER.error(ValueUtil.toString(e));
            }
        }
    });
    colStatus.setCellValueFactory(new Callback<CellDataFeatures<ChunkWrapper, String>, ObservableValue<String>>() {

        @Override
        public ObservableValue<String> call(CellDataFeatures<ChunkWrapper, String> param) {
            TYPE type = param.getValue().getType();
            StringProperty prop = new SimpleStringProperty();
            if (type != null)
                prop.set(type.name());
            return prop;
        }
    });
    colPosition.setCellValueFactory(param -> new SimpleIntegerProperty(new Integer(param.getValue().getPosition() + 1)));
    colRevice.setCellValueFactory(param -> {
        Delta delta = param.getValue().getDelta();
        SimpleStringProperty prop = new SimpleStringProperty();
        if (delta != null) {
            Chunk c = delta.getRevised();
            prop.setValue(c.getLines().toString());
        }
        return prop;
    });
    colOrigin.setCellValueFactory(param -> {
        Delta delta = param.getValue().getDelta();
        SimpleStringProperty prop = new SimpleStringProperty();
        if (delta != null) {
            Chunk c = delta.getOriginal();
            prop.setValue(c.getLines().toString());
        }
        return prop;
    });
}
Also used : CellDataFeatures(javafx.scene.control.TableColumn.CellDataFeatures) ObservableValue(javafx.beans.value.ObservableValue) ChunkWrapper(com.kyj.fx.voeditor.visual.diff.ChunkWrapper) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) StringProperty(javafx.beans.property.StringProperty) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Chunk(difflib.Chunk) CompareResult(com.kyj.fx.voeditor.visual.diff.CompareResult) IOException(java.io.IOException) Delta(difflib.Delta) ImageView(javafx.scene.image.ImageView) TYPE(difflib.Delta.TYPE) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) FXML(javafx.fxml.FXML)

Aggregations

ObservableValue (javafx.beans.value.ObservableValue)9 CellDataFeatures (javafx.scene.control.TableColumn.CellDataFeatures)9 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)5 FXML (javafx.fxml.FXML)5 TableColumn (javafx.scene.control.TableColumn)5 TableView (javafx.scene.control.TableView)5 IOException (java.io.IOException)4 ImageView (javafx.scene.image.ImageView)4 ChunkWrapper (com.kyj.fx.voeditor.visual.diff.ChunkWrapper)3 CompareResult (com.kyj.fx.voeditor.visual.diff.CompareResult)3 Chunk (difflib.Chunk)3 Delta (difflib.Delta)3 TYPE (difflib.Delta.TYPE)3 Map (java.util.Map)3 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)3 StringProperty (javafx.beans.property.StringProperty)3 Label (javafx.scene.control.Label)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2