Search in sources :

Example 1 with TablePosition

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

the class FxUtil method installDoubleClickPopup.

public static <T> void installDoubleClickPopup(Window owner, POPUP_STYLE style, TableView<T> tbMetadata) {
    tbMetadata.addEventHandler(MouseEvent.MOUSE_CLICKED, ev -> {
        if (MouseButton.PRIMARY == ev.getButton() && ev.getClickCount() == 2) {
            ObservableList<TablePosition> selectedCells = tbMetadata.getSelectionModel().getSelectedCells();
            TablePosition tablePosition = selectedCells.get(0);
            int column = tablePosition.getColumn();
            int row = tablePosition.getRow();
            Object valueByConverter = FxTableViewUtil.getValue(tbMetadata, column, row);
            String value = "";
            if (ValueUtil.isNotEmpty(valueByConverter)) {
                value = valueByConverter.toString();
            }
            final double WIDTH = 500d;
            final double HEIGHT = 400d;
            JavaTextArea createJavaTextArea = createJavaTextArea(value);
            createJavaTextArea.setPrefSize(WIDTH, HEIGHT);
            switch(style) {
                case POP_OVER:
                    FxUtil.showPopOver(tbMetadata, createJavaTextArea);
                    break;
                case POPUP:
                    createSimpleTextAreaAndShow(value, stage -> {
                        stage.setTitle("Show Values");
                        stage.setWidth(WIDTH);
                        stage.setHeight(HEIGHT);
                        stage.initStyle(StageStyle.UTILITY);
                        stage.initOwner(owner);
                        stage.focusedProperty().addListener((oba, o, n) -> {
                            if (!n)
                                stage.close();
                        });
                        stage.getScene().addEventHandler(KeyEvent.KEY_PRESSED, event -> {
                            if (KeyCode.ESCAPE == event.getCode()) {
                                if (!event.isConsumed()) {
                                    stage.close();
                                }
                            }
                        });
                    });
                    break;
            }
        }
    });
}
Also used : TablePosition(javafx.scene.control.TablePosition) JavaTextArea(com.kyj.fx.voeditor.visual.component.text.JavaTextArea)

Example 2 with TablePosition

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

the class ClipboardKeyEventInstaller method install.

/********************************
	 * 작성일 :  2016. 9. 3. 작성자 : KYJ
	 *
	 *
	 * @param tb
	 ********************************/
public static void install(TableView<?> tb) {
    tb.addEventHandler(KeyEvent.KEY_PRESSED, e -> {
        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 = tb.getSelectionModel().getSelectedCells();
            TablePosition tablePosition = selectedCells.get(0);
            TableColumn tableColumn = tablePosition.getTableColumn();
            int row = tablePosition.getRow();
            int col = tb.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 != tb.getColumns().indexOf(cell.getTableColumn())) {
                            sb.append("\t");
                        }
                        Object cellData = getDisplayText(cell, row);
                        sb.append(ValueUtil.decode(cellData, cellData, "").toString());
                    }
                    FxClipboardUtil.putString(sb.toString());
                    break;
                case 2:
                    Object cellData = getDisplayText(tableColumn, row);
                    FxClipboardUtil.putString(ValueUtil.decode(cellData, cellData, "").toString());
                    break;
            }
            e.consume();
        }
    });
}
Also used : TablePosition(javafx.scene.control.TablePosition) TableColumn(javafx.scene.control.TableColumn)

Example 3 with TablePosition

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

the class GagoyleSpreadSheetView method spreadSheetKeyPress.

public void spreadSheetKeyPress(KeyEvent e) {
    if (e.isControlDown() && e.getCode() == KeyCode.C) {
        StringBuffer clipboardContent = new StringBuffer();
        ObservableList<TablePosition> selectedCells = ssv.getSelectionModel().getSelectedCells();
        int prevRow = -1;
        for (TablePosition<?, ?> pos : selectedCells) {
            int currentRow = pos.getRow();
            int currentColumn = pos.getColumn();
            if ((prevRow != -1 && prevRow != currentRow)) {
                clipboardContent.setLength(clipboardContent.length() - 1);
                LOGGER.debug(clipboardContent.toString());
                /*
					 * 라인세퍼레이터 사용하지말것. 이유는 클립보드에 들어가는 컨텐츠가 /r/n이되면서 엑셀에 붙여넣기시
					 * 잘못된 값이 입력됨. [ 금지 : SystemUtils.LINE_SEPARATOR = /r/n ]
					 */
                clipboardContent.append("\n");
            }
            prevRow = currentRow;
            SpreadsheetCell spreadsheetCell = ssv.getGrid().getRows().get(currentRow).get(currentColumn);
            clipboardContent.append(spreadsheetCell.getText()).append("\t");
        }
        clipboardContent.setLength(clipboardContent.length() - 1);
        LOGGER.debug(String.format("clipboard content : \n%s", clipboardContent.toString()));
        FxClipboardUtil.putString(clipboardContent.toString());
        // 상위 이벤트가 호출되서 클립보드가 없어지는것을 방지한다.
        e.consume();
    } else if (e.isControlDown() && e.getCode() == KeyCode.V) {
        int type = FxClipboardUtil.getCipboardContentTypes();
        switch(type) {
            case FxClipboardUtil.IMAGE:
                {
                    Image pastImage = FxClipboardUtil.pastImage();
                    ObservableList<TablePosition> selectedCells = ssv.getSelectionModel().getSelectedCells();
                    TablePosition tablePosition = selectedCells.get(0);
                    int row = tablePosition.getRow();
                    int column = tablePosition.getColumn();
                    SpreadsheetCell cell = new ImageCellType().createCell(row, column, 1, 1, pastImage);
                    ssv.getGrid().getRows().get(tablePosition.getRow()).set(tablePosition.getColumn(), cell);
                // this.getGrid().setCellValue(tablePosition.getRow(),
                // tablePosition.getColumn(), new ImageView(pastImage));
                }
                break;
            case FxClipboardUtil.FILE:
                List<File> pastFiles = FxClipboardUtil.pasteFiles();
                File file = pastFiles.get(0);
                if (file != null && file.exists()) {
                    try {
                        Image pastImage = new Image(file.toURI().toURL().openStream());
                        ObservableList<TablePosition> selectedCells = ssv.getSelectionModel().getSelectedCells();
                        TablePosition tablePosition = selectedCells.get(0);
                        int row = tablePosition.getRow();
                        int column = tablePosition.getColumn();
                        SpreadsheetCell cell = new ImageCellType().createCell(row, column, 1, 1, pastImage);
                        ssv.getGrid().getRows().get(tablePosition.getRow()).set(tablePosition.getColumn(), cell);
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
                break;
            case FxClipboardUtil.URL:
                {
                    String pasteUrl = FxClipboardUtil.pasteUrl();
                    Image pastImage = new Image(pasteUrl);
                    ObservableList<TablePosition> selectedCells = ssv.getSelectionModel().getSelectedCells();
                    TablePosition tablePosition = selectedCells.get(0);
                    int row = tablePosition.getRow();
                    int column = tablePosition.getColumn();
                    SpreadsheetCell cell = new ImageCellType().createCell(row, column, 1, 1, pastImage);
                    ssv.getGrid().getRows().get(tablePosition.getRow()).set(tablePosition.getColumn(), cell);
                }
                break;
            case FxClipboardUtil.STRING:
                paste();
                break;
            default:
                paste();
                break;
        }
    }
    e.consume();
}
Also used : Image(javafx.scene.image.Image) SpreadsheetCell(org.controlsfx.control.spreadsheet.SpreadsheetCell) TablePosition(javafx.scene.control.TablePosition) ObservableList(javafx.collections.ObservableList) ArrayList(java.util.ArrayList) List(java.util.List) ObservableList(javafx.collections.ObservableList) File(java.io.File)

Example 4 with TablePosition

use of javafx.scene.control.TablePosition 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 5 with TablePosition

use of javafx.scene.control.TablePosition 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)

Aggregations

TablePosition (javafx.scene.control.TablePosition)6 TableColumn (javafx.scene.control.TableColumn)4 ObservableList (javafx.collections.ObservableList)2 JavaTextArea (com.kyj.fx.voeditor.visual.component.text.JavaTextArea)1 File (java.io.File)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 ObjectProperty (javafx.beans.property.ObjectProperty)1 ObservableValue (javafx.beans.value.ObservableValue)1 SelectionMode (javafx.scene.control.SelectionMode)1 TableCell (javafx.scene.control.TableCell)1 TableView (javafx.scene.control.TableView)1 TableViewSelectionModel (javafx.scene.control.TableView.TableViewSelectionModel)1 ComboBoxTableCell (javafx.scene.control.cell.ComboBoxTableCell)1 TextFieldTableCell (javafx.scene.control.cell.TextFieldTableCell)1 Image (javafx.scene.image.Image)1