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;
}
});
}
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;
}
use of javafx.scene.control.TableColumn in project Gargoyle by callakrsos.
the class FxExcelUtil method appendAllColumns.
/**
* 테이블뷰의 모든 컬럼을 찾기위한 재귀함수.
*
* (( 설마 테이블컬럼이 무한대로 있는 화면은 없겠지. ))
* @작성자 : KYJ
* @작성일 : 2016. 9. 6.
* @param parent 계층형 컬럼의 부모를 가리킴.
* @param pocket 컬럼이 일렬로 저정된다.
* @param index 트리레벨을 가리킴. 다른말로하면 컬럼의 순서를 가리킴.
* @param col
* @param level 계층형 컬럼의 현재 레벨을 가리킴.
* @param use 엑셀처리에 사용할 컬럼인지 처리여부
* @return 가장 Depth가 긴 레벨을 리턴.
*/
static <T> int appendAllColumns(ExcelColumnExpression parent, List<ExcelColumnExpression> pocket, TableColumn<T, ?> col, int level, ITableColumnForExcel use) {
int maxLevel = level;
int myLevel = level;
if (col == null)
/*|| !col.isVisible()*/
return maxLevel;
if (use != null) {
boolean test = use.test(col.getTableView(), col);
if (!test)
return maxLevel;
}
ExcelColumnExpression columnExpr = new ExcelColumnExpression();
String text = ValueUtil.isEmpty(col.getText()) ? "-" : col.getText();
boolean visible = col.isVisible();
double width = col.getWidth();
columnExpr.setRealText(text);
columnExpr.setTableColumn(col);
columnExpr.setIndex(pocket.isEmpty() ? 0 : pocket.get(pocket.size() - 1).getIndex() + 1);
columnExpr.setLevel(myLevel);
columnExpr.setVisible(visible);
columnExpr.setParent(parent);
LOGGER.debug("col : {} , isVisible : {} , level : {}, width : {} ", text, col.isVisible(), myLevel, width);
pocket.add(columnExpr);
if (parent != null) {
parent.getChildrens().add(columnExpr);
}
List<TableColumn<T, ?>> columns = col.getColumns();
if (columns == null || columns.isEmpty()) {
return maxLevel;
} else {
int visibledColumnCount = 0;
for (int i = 0; i < columns.size(); i++) {
TableColumn<T, ?> subCol = columns.get(i);
if (use.test(subCol.getTableView(), subCol)) {
int _level = appendAllColumns(columnExpr, pocket, subCol, (myLevel + 1), use);
if (maxLevel < _level)
maxLevel = _level;
visibledColumnCount++;
}
}
List<ExcelColumnExpression> subList = pocket.subList(pocket.size() - visibledColumnCount, pocket.size());
// if (parent != null) {
//fix indexㅒ
int idx = 0;
for (ExcelColumnExpression c : subList) {
// if (c.isVisible()) {
c.setIndex(columnExpr.getIndex() + idx);
idx++;
// }
}
return maxLevel;
}
}
use of javafx.scene.control.TableColumn in project Gargoyle by callakrsos.
the class PivotTableViewExam method start.
/*
* (non-Javadoc)
*
* @see javafx.application.Application#start(javafx.stage.Stage)
*/
@Override
public void start(Stage primaryStage) throws Exception {
// TableView<VocStA001DVO> root = new TableView<VocStA001DVO>();
TableView<Map<String, Object>> root = new TableView<>();
root.setOnMouseClicked(event -> {
System.out.println(root.getSelectionModel().getSelectedItem());
});
// 샘플데이터
List<VocStA001DVO> arrayList = new ArrayList<VocStA001DVO>();
arrayList.add(getSample("HQ", "11", "등록", "2016W1", 6));
arrayList.add(getSample("HQ", "12", "로컬접수", "2016W1", 1));
arrayList.add(getSample("HQ", "13", "HQ접수", "2016W1", 0));
arrayList.add(getSample("HQ", "14", "PI리더", "2016W1", 4));
arrayList.add(getSample("HQ", "15", "PI실무", "2016W1", 6));
arrayList.add(getSample("HQ", "11", "등록", "2016W2", 23));
arrayList.add(getSample("HQ", "12", "로컬접수", "2016W2", 32));
arrayList.add(getSample("HQ", "13", "HQ접수", "2016W2", 1));
arrayList.add(getSample("HQ", "14", "PI리더", "2016W2", 5));
arrayList.add(getSample("HQ", "15", "PI실무", "2016W2", 9));
arrayList.add(getSample("HQ", "11", "등록", "2016W3", 50));
arrayList.add(getSample("HQ", "12", "로컬접수", "2016W3", 1));
arrayList.add(getSample("HQ", "13", "HQ접수", "2016W3", 3));
arrayList.add(getSample("HQ", "14", "PI리더", "2016W3", 1));
arrayList.add(getSample("HQ", "15", "PI실무", "2016W3", 8));
arrayList.add(getSample("SEDA", "11", "등록", "2016W1", 12));
arrayList.add(getSample("SEDA", "12", "로컬접수", "2016W1", 2));
arrayList.add(getSample("SEDA", "13", "HQ접수", "2016W1", 1));
arrayList.add(getSample("SEDA", "14", "PI리더", "2016W1", 8));
arrayList.add(getSample("SEDA", "15", "PI실무", "2016W1", 12));
arrayList.add(getSample("SEDA", "11", "등록", "2016W2", 46));
arrayList.add(getSample("SEDA", "12", "로컬접수", "2016W2", 64));
arrayList.add(getSample("SEDA", "13", "HQ접수", "2016W2", 2));
arrayList.add(getSample("SEDA", "14", "PI리더", "2016W2", 10));
arrayList.add(getSample("SEDA", "15", "PI실무", "2016W2", 18));
arrayList.add(getSample("SEDA", "11", "등록", "2016W3", 100));
arrayList.add(getSample("SEDA", "12", "로컬접수", "2016W3", 2));
arrayList.add(getSample("SEDA", "13", "HQ접수", "2016W3", 6));
arrayList.add(getSample("SEDA", "14", "PI리더", "2016W3", 2));
arrayList.add(getSample("SEDA", "15", "PI실무", "2016W3", 16));
primaryStage.setScene(new Scene(root));
primaryStage.show();
Header header = new Header(Arrays.asList(new Header("vocStatusNm", "vocStatusNm")), "week", "week");
GroupingSet headerData = new GroupingSet("cnt", "sysCode");
header.setGroupingSet(headerData);
List<Map<String, Object>> groupBy = groupBy(header, arrayList);
List<TableColumn<Map<String, Object>, Object>> groupByColumns = groupByColumn(header, arrayList);
// List<TableColumn<Map<String, Object>, Object>> collect =
// groupBy.get(0).keySet().stream().map(k -> createColumn(k))
// .collect(Collectors.toList());
root.getColumns().addAll(groupByColumns);
root.getItems().addAll(groupBy);
// List<TableColumn<VocStA001DVO, String>> columns =
// createTableColumns(header, arrayList);
// root.getColumns().addAll(columns);
// root.getItems().addAll(arrayList);
}
use of javafx.scene.control.TableColumn in project Gargoyle by callakrsos.
the class EditableTableView method readByTableName.
private void readByTableName(String sql, String tableName, boolean appendHist) throws Exception {
LOGGER.debug(sql);
getColumns().clear();
getItems().clear();
removedList.clear();
columnMap.clear();
try (Connection connection = connectionSupplier.get()) {
List<String> pks = DbUtil.pks(connection, tableName);
Map<String, Boolean> columnsToMap = DbUtil.columnsToMap(connection, tableName, rs -> {
try {
return rs.getString(4);
} catch (Exception e) {
return null;
}
}, rs -> {
try {
return Boolean.valueOf("YES".equals(rs.getString(18)));
} catch (Exception e) {
return false;
}
});
LOGGER.debug("nullable columns ? {} ", columnsToMap);
DbUtil.select(connection, sql, FETCH_COUNT, LIMIT_ROW_COUNT, new BiFunction<ResultSetMetaData, ResultSet, List<Map<String, Object>>>() {
@Override
public List<Map<String, Object>> apply(ResultSetMetaData t, ResultSet u) {
try {
int columnCount = t.getColumnCount();
for (int i = 1; i <= columnCount; i++) {
String columnName = t.getColumnName(i);
ColumnExpression columnExp = new ColumnExpression(columnName);
columnExp.isPrimaryColumn = pks.contains(columnName);
columnExp.isNullableColumn = columnsToMap.containsKey(columnName) && (columnsToMap.get(columnName) == true);
columnExp.setColumnType(t.getColumnType(i));
TableColumn<Map<ColumnExpression, ObjectProperty<ValueExpression>>, ValueExpression> e = new TableColumn<>(columnName);
e.setUserData(columnExp);
e.setCellValueFactory(DynamicCallback.fromTableColumn(columnExp));
e.setCellFactory(DEFAULT_CELL_FACTORY);
e.setEditable(true);
columnMap.put(columnName, columnExp);
getColumns().add(e);
}
while (u.next()) {
Map<ColumnExpression, ObjectProperty<ValueExpression>> hashMap = new HashMap<>();
for (int i = 1; i <= columnCount; i++) {
String columnName = t.getColumnName(i);
//new ColumnExpression(columnName);
ColumnExpression columnExp = columnMap.get(columnName);
ValueExpression valueExp = new ValueExpression();
valueExp.displayText.set(u.getString(columnName));
valueExp.isPrimaryKey = pks.contains(columnName);
valueExp.realValue.set(u.getObject(columnName));
valueExp.setColumnExpression(columnExp);
hashMap.put(columnExp, new SimpleObjectProperty<>(valueExp));
}
getItems().removeListener(itemChangeListener);
getItems().add(hashMap);
getItems().addListener(itemChangeListener);
}
} catch (SQLException e) {
LOGGER.error(ValueUtil.toString(e));
}
return null;
}
});
if (appendHist) {
if (history.size() >= HISTORY_LIMITED_SIZE) {
history.removeFirst();
}
history.add(sql);
}
this.tableName.set(tableName);
}
}
Aggregations