use of javafx.util.Callback in project Gargoyle by callakrsos.
the class FxTableViewUtil method getDisplayText.
/**
* 테이블컬럼에서 화면에 보여주는 텍스트를 리턴한다.
* @작성자 : KYJ
* @작성일 : 2017. 3. 31.
* @param tc
* @param row
* @return
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Object getDisplayText(TableColumn<?, ?> tc, int row) {
Callback cellFactory = tc.getCellFactory();
if (cellFactory != null) /*&& cellObservableValue != null*/
{
// Object value = cellObservableValue.getValue();
Object call = cellFactory.call(tc);
if (call != null && call instanceof TableCell) {
TableCell cell = (TableCell) call;
StringConverter converter = null;
if (cell instanceof TextFieldTableCell) {
TextFieldTableCell txtCell = (TextFieldTableCell) cell;
converter = txtCell.getConverter();
} else // }
if (cell instanceof ComboBoxTableCell) {
ComboBoxTableCell txtCell = (ComboBoxTableCell) cell;
converter = txtCell.getConverter();
} else // else if (cell instanceof HyperlinkTableCell) {
// HyperlinkTableCell txtCell = (HyperlinkTableCell) cell;
// converter = txtCell.getConverter();
// }
/* else 기본값. */
{
try {
Method m = cell.getClass().getMethod("converterProperty");
if (m != null) {
Object object = m.invoke(cell);
if (object != null && object instanceof ObjectProperty) {
ObjectProperty<StringConverter> convert = (ObjectProperty<StringConverter>) object;
converter = convert.get();
}
}
} catch (Exception e) {
// Nothing...
}
}
if (converter != null) {
Object cellData = tc.getCellData(row);
return converter.toString(cellData);
}
}
return call;
}
return tc.getCellData(row);
}
use of javafx.util.Callback in project Gargoyle by callakrsos.
the class FxSVNHistoryDataSupplier method createHistoryListView.
public ListView<GargoyleSVNLogEntryPath> createHistoryListView(ObservableList<GargoyleSVNLogEntryPath> list) {
ListView<GargoyleSVNLogEntryPath> listView = new ListView<GargoyleSVNLogEntryPath>(list);
listView.setCellFactory(new Callback<ListView<GargoyleSVNLogEntryPath>, ListCell<GargoyleSVNLogEntryPath>>() {
@Override
public ListCell<GargoyleSVNLogEntryPath> call(ListView<GargoyleSVNLogEntryPath> param) {
ListCell<GargoyleSVNLogEntryPath> listCell = new ListCell<GargoyleSVNLogEntryPath>() {
/* (non-Javadoc)
* @see javafx.scene.control.Cell#updateItem(java.lang.Object, boolean)
*/
@Override
protected void updateItem(GargoyleSVNLogEntryPath item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setText(null);
} else {
String type = "Modify";
switch(item.getType()) {
case GargoyleSVNLogEntryPath.TYPE_ADDED:
type = "Add";
break;
case GargoyleSVNLogEntryPath.TYPE_MODIFIED:
type = "Modify";
break;
case GargoyleSVNLogEntryPath.TYPE_REPLACED:
type = "Replace";
break;
case GargoyleSVNLogEntryPath.TYPE_DELETED:
type = "Delete";
break;
}
String path = item.getPath();
setText(String.format("Resivion :%d File : %s Date : %s Type : %s ", item.getCopyRevision(), path.substring(path.lastIndexOf("/")), YYYY_MM_DD_HH_MM_SS_PATTERN.format(item.getDate()), type));
}
}
};
return listCell;
}
});
listView.setPrefSize(600, ListView.USE_COMPUTED_SIZE);
listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
listView.addEventHandler(MouseEvent.MOUSE_CLICKED, ev -> {
ContextMenu contextMenu = null;
ObservableList<GargoyleSVNLogEntryPath> selectedItems = listView.getSelectionModel().getSelectedItems();
GargoyleSVNLogEntryPath selectedItem = null;
if (selectedItems != null && !selectedItems.isEmpty()) {
selectedItem = selectedItems.get(0);
}
if (ev.getClickCount() == 2 && ev.getButton() == MouseButton.PRIMARY) {
if (selectedItem != null) {
String path = selectedItem.getPath();
long copyRevision = selectedItem.getCopyRevision();
String rootUrl = getRootUrl();
LOGGER.debug("{}", rootUrl);
LOGGER.debug("Cat Command, Path : {} Revision {}", path, copyRevision);
String content = "";
VBox vBox = new VBox(5);
if (isExists(path)) {
content = cat(path, String.valueOf(copyRevision));
List<SVNLogEntry> log = log(path, String.valueOf(copyRevision), ex -> {
LOGGER.error(ValueUtil.toString(ex));
});
if (ValueUtil.isNotEmpty(log)) {
SVNLogEntry svnLogEntry = log.get(0);
String apply = getManager().fromPrettySVNLogConverter().apply(svnLogEntry);
Label e = new Label(apply);
e.setStyle("-fx-text-fill:black");
vBox.getChildren().add(e);
}
vBox.getChildren().add(createJavaTextArea(content));
} else {
content = "Does not exists. Repository. [Removed]";
Label e = new Label(content);
e.setStyle("-fx-text-fill:black");
vBox.getChildren().add(e);
}
FxUtil.showPopOver(ev.getPickResult().getIntersectedNode(), vBox);
}
ev.consume();
} else if (ev.getClickCount() == 1 && ev.getButton() == MouseButton.SECONDARY) {
ObservableList<MenuItem> menus = FXCollections.observableArrayList();
MenuItem miHist = new MenuItem("History");
miHist.setUserData(selectedItem);
MenuItem miAllHist = new MenuItem("All History");
MenuItem miDiff = new MenuItem("Diff");
miDiff.setDisable(true);
menus.add(miHist);
menus.add(miAllHist);
menus.add(new SeparatorMenuItem());
menus.add(miDiff);
if (selectedItems.size() == 2) {
miDiff.setUserData(selectedItems);
miDiff.setDisable(false);
}
miHist.setOnAction(event -> {
GargoyleSVNLogEntryPath userData = (GargoyleSVNLogEntryPath) miHist.getUserData();
if (userData == null)
return;
FxUtil.showPopOver(ev.getPickResult().getIntersectedNode(), createHistoryListView(userData.getPath()));
});
miAllHist.setOnAction(event -> {
GargoyleSVNLogEntryPath userData = (GargoyleSVNLogEntryPath) miHist.getUserData();
if (userData == null)
return;
String path = userData.getPath();
try {
Collection<SVNLogEntry> allLogs = getManager().getAllLogs(path);
ObservableList<GargoyleSVNLogEntryPath> collect = createStream(allLogs).filter(v -> {
return path.equals(v.getPath());
}).collect(FxCollectors.toObservableList());
FxUtil.showPopOver(ev.getPickResult().getIntersectedNode(), createHistoryListView(collect));
} catch (Exception e) {
LOGGER.error(ValueUtil.toString(e));
}
});
miDiff.setOnAction(event -> {
List<GargoyleSVNLogEntryPath> userData = (List<GargoyleSVNLogEntryPath>) miDiff.getUserData();
if (userData == null && userData.size() != 2)
return;
GargoyleSVNLogEntryPath gargoyleSVNLogEntryPath1 = userData.get(0);
GargoyleSVNLogEntryPath gargoyleSVNLogEntryPath2 = userData.get(1);
try {
String diff = diff(gargoyleSVNLogEntryPath1.getPath(), gargoyleSVNLogEntryPath1.getCopyRevision(), gargoyleSVNLogEntryPath2.getCopyRevision());
TextArea showingNode = new TextArea(diff);
showingNode.setPrefSize(600d, 800d);
FxUtil.showPopOver(ev.getPickResult().getIntersectedNode(), showingNode);
} catch (Exception e) {
e.printStackTrace();
}
});
contextMenu = new ContextMenu(menus.stream().toArray(MenuItem[]::new));
contextMenu.show(ev.getPickResult().getIntersectedNode(), ev.getScreenX(), ev.getScreenY());
}
});
return listView;
}
use of javafx.util.Callback 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);
}
Aggregations