Search in sources :

Example 21 with TableColumn

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

the class BaseColumnMapper method generateTableColumns.

/**
	 * 컬럼 제너레이터
	 *
	 * @Date 2015. 10. 8.
	 * @param classType
	 * @return
	 * @User KYJ
	 */
@Override
public TableColumn<T, ?> generateTableColumns(Class<?> classType, String columnName, IOptions options) {
    TableColumn tableColumn = new TableColumn<>();
    // 2015.11.18 커스텀 컬럼은 cellFactory를 가져다 쓰지않음.
    tableColumn.setCellFactory(cell -> {
        TextFieldTableCell<T, Object> textFieldTableCell = new TextFieldTableCell<>();
        textFieldTableCell.setConverter(converter(classType));
        return textFieldTableCell;
    });
    // 2015.11.18 커스텀 컬럼값을 정의한경우 대체.
    TableColumn<T, ?> customTableColumn = options.customTableColumn(columnName);
    if (customTableColumn != null) {
        tableColumn = customTableColumn;
    }
    // 2015.11.18 커스텀 컬럼은 ValueFactory는 기본적으로 사용
    PropertyValueFactory<T, ?> value = new PropertyValueFactory<>(columnName);
    tableColumn.setCellValueFactory(value);
    tableColumn.setId(columnName);
    // 컬럼의 속성을 정의
    setColumnProperty(tableColumn, columnName, options);
    tableColumn.setResizable(true);
    tableColumn.setEditable(false);
    tableColumn.setVisible(options.visible(columnName));
    return tableColumn;
}
Also used : TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) TableColumn(javafx.scene.control.TableColumn)

Example 22 with TableColumn

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

the class MacroControl method tbResultOnKeyReleased.

public void tbResultOnKeyReleased() {
    Skin<?> skin = this.getSkin();
    if (!(skin instanceof MacroBaseSkin)) {
        return;
    }
    MacroBaseSkin mskin = (MacroBaseSkin) skin;
    TableView<Map<String, String>> tbResult = mskin.getTbResult();
    int type = 1;
    ObservableList<TablePosition> selectedCells = tbResult.getSelectionModel().getSelectedCells();
    TablePosition tablePosition = selectedCells.get(0);
    TableColumn tableColumn = tablePosition.getTableColumn();
    int row = tablePosition.getRow();
    int col = tbResult.getColumns().indexOf(tableColumn);
    switch(type) {
        case 1:
            StringBuilder sb = new StringBuilder();
            for (TablePosition cell : selectedCells) {
                // 행변경시
                if (row != cell.getRow()) {
                    sb.append("\n");
                    row++;
                } else // 열 변경시
                if (col != tbResult.getColumns().indexOf(cell.getTableColumn())) {
                    sb.append("\t");
                }
                Object cellData = cell.getTableColumn().getCellData(cell.getRow());
                sb.append(ValueUtil.decode(cellData, cellData, "").toString());
            }
            FxClipboardUtil.putString(sb.toString());
            break;
        case 2:
            Object cellData = tableColumn.getCellData(row);
            FxClipboardUtil.putString(ValueUtil.decode(cellData, cellData, "").toString());
            break;
    }
}
Also used : TablePosition(javafx.scene.control.TablePosition) Map(java.util.Map) TableColumn(javafx.scene.control.TableColumn)

Example 23 with TableColumn

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

the class FxTableViewUtil method installCopyHandler.

@SuppressWarnings("rawtypes")
public static void installCopyHandler(TableView<?> table) {
    table.addEventHandler(KeyEvent.KEY_PRESSED, e -> {
        if (e.isConsumed())
            return;
        int type = -1;
        if (e.isControlDown() && e.getCode() == KeyCode.C) {
            if (e.isShiftDown()) {
                type = 2;
            } else {
                type = 1;
            }
        }
        if (type == -1)
            return;
        TableViewSelectionModel<?> selectionModel = table.getSelectionModel();
        SelectionMode selectionMode = selectionModel.getSelectionMode();
        boolean cellSelectionEnabled = selectionModel.isCellSelectionEnabled();
        if (!cellSelectionEnabled) {
            Object selectedItem = table.getSelectionModel().getSelectedItem();
            ObservableList<?> columns = table.getColumns();
            Optional<String> reduce = columns.stream().filter(ob -> ob instanceof TableColumn).map(obj -> (TableColumn) obj).map(tc -> tc.getCellData(selectedItem)).filter(v -> v != null).map(v -> v.toString()).reduce((o1, o2) -> o1.toString().concat("\t").concat(o2.toString()));
            reduce.ifPresent(str -> {
                FxClipboardUtil.putString(str);
                e.consume();
            });
        } else if (cellSelectionEnabled) {
            ObservableList<TablePosition> selectedCells = selectionModel.getSelectedCells();
            TablePosition tablePosition = selectedCells.get(0);
            TableColumn tableColumn = tablePosition.getTableColumn();
            int row = tablePosition.getRow();
            int col = table.getColumns().indexOf(tableColumn);
            switch(type) {
                case 1:
                    StringBuilder sb = new StringBuilder();
                    for (TablePosition cell : selectedCells) {
                        if (row != cell.getRow()) {
                            sb.append("\n");
                            row++;
                        } else if (col != table.getColumns().indexOf(cell.getTableColumn())) {
                            sb.append("\t");
                        }
                        Object cellData = cell.getTableColumn().getCellData(cell.getRow());
                        sb.append(ValueUtil.decode(cellData, cellData, "").toString());
                    }
                    FxClipboardUtil.putString(sb.toString());
                    e.consume();
                    break;
                case 2:
                    Object cellData = tableColumn.getCellData(row);
                    FxClipboardUtil.putString(ValueUtil.decode(cellData, cellData, "").toString());
                    e.consume();
                    break;
            }
        }
    });
}
Also used : KeyCode(javafx.scene.input.KeyCode) ObjectProperty(javafx.beans.property.ObjectProperty) TablePosition(javafx.scene.control.TablePosition) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) KeyEvent(javafx.scene.input.KeyEvent) StringConverter(javafx.util.StringConverter) Field(java.lang.reflect.Field) TableColumn(javafx.scene.control.TableColumn) TableCell(javafx.scene.control.TableCell) SelectionMode(javafx.scene.control.SelectionMode) ComboBoxTableCell(javafx.scene.control.cell.ComboBoxTableCell) Clipboard(javafx.scene.input.Clipboard) Optional(java.util.Optional) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) Method(java.lang.reflect.Method) TableViewSelectionModel(javafx.scene.control.TableView.TableViewSelectionModel) TableColumn(javafx.scene.control.TableColumn) ObservableList(javafx.collections.ObservableList) TablePosition(javafx.scene.control.TablePosition) SelectionMode(javafx.scene.control.SelectionMode)

Example 24 with TableColumn

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

the class FxTableViewUtil method installCopyPasteHandler.

/********************************
	 * 작성일 : 2016. 5. 12. 작성자 : KYJ
	 *
	 * 테이블뷰 클립보드 기능.
	 * 
	 * @Deprecated COPY 기능과 PASTE 기능을 분리.
	 *   installCopyHandler 사용할것
	 * @param table
	 ********************************/
@SuppressWarnings("rawtypes")
@Deprecated
public static void installCopyPasteHandler(TableView<?> table) {
    table.addEventHandler(KeyEvent.KEY_PRESSED, e -> {
        if (e.isConsumed())
            return;
        int type = -1;
        if (e.isControlDown() && e.getCode() == KeyCode.C) {
            if (e.isShiftDown()) {
                type = 2;
            } else {
                type = 1;
            }
        }
        if (type == -1)
            return;
        ObservableList<TablePosition> selectedCells = table.getSelectionModel().getSelectedCells();
        TablePosition tablePosition = selectedCells.get(0);
        TableColumn tableColumn = tablePosition.getTableColumn();
        int row = tablePosition.getRow();
        int col = table.getColumns().indexOf(tableColumn);
        switch(type) {
            case 1:
                StringBuilder sb = new StringBuilder();
                for (TablePosition cell : selectedCells) {
                    if (row != cell.getRow()) {
                        sb.append("\n");
                        row++;
                    } else if (col != table.getColumns().indexOf(cell.getTableColumn())) {
                        sb.append("\t");
                    }
                    Object cellData = cell.getTableColumn().getCellData(cell.getRow());
                    sb.append(ValueUtil.decode(cellData, cellData, "").toString());
                }
                FxClipboardUtil.putString(sb.toString());
                e.consume();
                break;
            case 2:
                Object cellData = tableColumn.getCellData(row);
                FxClipboardUtil.putString(ValueUtil.decode(cellData, cellData, "").toString());
                e.consume();
                break;
        }
    });
}
Also used : TablePosition(javafx.scene.control.TablePosition) TableColumn(javafx.scene.control.TableColumn)

Example 25 with TableColumn

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

the class FxExcelUtil method getMaxLevel.

/**
	 * 다중헤더를 갖는 컬럼의 가장 높은 크기를 리턴하는 함수 + 
	 * List<ExcelColumnExpression>배열에 헤더순서대로 값을 input해줌.
	 * 
	 * @작성자 : KYJ
	 * @작성일 : 2016. 9. 7. 
	 * @param columns
	 * @param allColumnsList
	 * @return
	 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private static int getMaxLevel(ObservableList<TableColumn> columns, List<ExcelColumnExpression> allColumnsList, ITableColumnForExcel use) {
    int maxLevel = 0;
    int SIZE = columns.size();
    for (int i = 0; i < SIZE; i++) {
        TableColumn col = columns.get(i);
        if (!col.isVisible())
            continue;
        int level = appendAllColumns(null, allColumnsList, col, /*시작은 0레벨부터.*/
        HEADER_ROW_INDEX, use);
        if (maxLevel < level)
            maxLevel = level;
    }
    return maxLevel;
}
Also used : TableColumn(javafx.scene.control.TableColumn)

Aggregations

TableColumn (javafx.scene.control.TableColumn)40 TableView (javafx.scene.control.TableView)13 BigDecimal (java.math.BigDecimal)11 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)10 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)9 LocalDate (java.time.LocalDate)8 Map (java.util.Map)8 Scene (javafx.scene.Scene)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 BorderPane (javafx.scene.layout.BorderPane)7 List (java.util.List)6 FXML (javafx.fxml.FXML)5 TableCell (javafx.scene.control.TableCell)5 ObjectProperty (javafx.beans.property.ObjectProperty)4 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)4 ObservableValue (javafx.beans.value.ObservableValue)4 ObservableList (javafx.collections.ObservableList)4 Button (javafx.scene.control.Button)4 SelectionMode (javafx.scene.control.SelectionMode)4