use of javafx.scene.control.TableRow in project Retrospector by NonlinearFruit.
the class SearchTabController method initSearchTab.
private void initSearchTab() {
searchEditMedia.setDisable(true);
searchDeleteMedia.setDisable(true);
// Table Double Click
searchTable.setRowFactory(tv -> {
TableRow<Media> row = new TableRow<>();
row.setOnMouseClicked(event -> {
if (event.getClickCount() == 2 && (!row.isEmpty())) {
setMedia(row.getItem());
setTab(TAB.MEDIA);
}
});
return row;
});
// Table data setup
searchTableData = DataManager.getMedia();
FilteredList<Media> mediaFiltered = new FilteredList(searchTableData, x -> true);
SortedList<Media> mediaSortable = new SortedList<>(mediaFiltered);
searchTable.setItems(mediaSortable);
mediaSortable.comparatorProperty().bind(searchTable.comparatorProperty());
// Link to data properties
searchTitleColumn.setCellValueFactory(new PropertyValueFactory<>("Title"));
searchCreatorColumn.setCellValueFactory(new PropertyValueFactory<>("Creator"));
searchSeasonColumn.setCellValueFactory(new PropertyValueFactory<>("SeasonId"));
searchEpisodeColumn.setCellValueFactory(new PropertyValueFactory<>("EpisodeId"));
searchCategoryColumn.setCellValueFactory(new PropertyValueFactory<>("Category"));
// Values for special columns
searchNumberColumn.setSortable(false);
searchNumberColumn.setCellValueFactory(p -> new ReadOnlyObjectWrapper(1 + searchTable.getItems().indexOf(p.getValue())));
searchReviewsColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Media, Integer>, ObservableValue<Integer>>() {
@Override
public ObservableValue<Integer> call(TableColumn.CellDataFeatures<Media, Integer> p) {
return new ReadOnlyObjectWrapper(p.getValue().getReviews().size());
}
});
searchMeanRColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Media, BigDecimal>, ObservableValue<BigDecimal>>() {
@Override
public ObservableValue<BigDecimal> call(TableColumn.CellDataFeatures<Media, BigDecimal> p) {
return new ReadOnlyObjectWrapper(p.getValue().getAverageRating());
}
});
searchCurrentRColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Media, BigDecimal>, ObservableValue<BigDecimal>>() {
@Override
public ObservableValue<BigDecimal> call(TableColumn.CellDataFeatures<Media, BigDecimal> p) {
return new ReadOnlyObjectWrapper(p.getValue().getCurrentRating());
}
});
// Comparators for string columns
searchTitleColumn.setComparator(new NaturalOrderComparator());
searchCreatorColumn.setComparator(new NaturalOrderComparator());
searchSeasonColumn.setComparator(new NaturalOrderComparator());
searchEpisodeColumn.setComparator(new NaturalOrderComparator());
searchCategoryColumn.setComparator(new NaturalOrderComparator());
searchTable.getSelectionModel().selectedItemProperty().addListener((observe, old, neo) -> {
setMedia(neo);
});
searchBox.textProperty().addListener((observa, old, neo) -> {
String query = neo;
if (query == null || query.equals(""))
mediaFiltered.setPredicate(x -> true);
else {
String[] queries = query.split(":");
mediaFiltered.setPredicate(x -> QueryProcessor.isMatchForMedia(query, x));
}
updateStats();
});
// Buttons
searchNewMedia.setOnAction(e -> {
Media neo = new Media();
neo.setId(DataManager.createDB(neo));
setMedia(neo);
setTab(TAB.MEDIA);
});
searchQuickEntry.setOnAction(e -> {
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("QuickEntry.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
QuickEntryController qec = fxmlLoader.getController();
qec.setup(currentTab);
Stage stage = new Stage();
stage.setTitle("Quick Entry");
stage.setScene(new Scene(root1));
stage.show();
} catch (Exception ex) {
}
});
searchStandardEntry.setOnAction(e -> {
Media neo = new Media();
neo.setId(DataManager.createDB(neo));
setMedia(neo);
setTab(TAB.MEDIA);
});
searchBackup.setOnAction(e -> DataManager.makeBackup());
searchCheatsheet.setOnAction(e -> {
new Cheatsheet().start(new Stage());
});
searchEditMedia.setOnAction(e -> {
setTab(TAB.MEDIA);
});
searchDeleteMedia.setOnAction(e -> {
if (new Alert(Alert.AlertType.WARNING, "Are you sure you want to delete this?", ButtonType.NO, ButtonType.YES).showAndWait().get().equals(ButtonType.YES)) {
DataManager.deleteDB(getMedia());
updateSearchTab();
}
});
// Init stuff
updateStats();
}
use of javafx.scene.control.TableRow in project Media-Library by The-Rain-Goddess.
the class ApplicationWindow method setDataTableClickEvents.
private void setDataTableClickEvents() {
dataTable.setRowFactory(tv -> {
TableRow<MediaFile> row = new TableRow<>();
row.setOnMouseClicked(event -> {
try {
if (event.getButton() == MouseButton.SECONDARY) {
ContextMenu cMenu = new ContextMenu();
MenuItem remove = new MenuItem("Remove");
remove.setOnAction((ActionEvent ev) -> {
Main.getMasterData().remove(row.getItem().getUUID());
updateDataTable();
updateFileSystem();
});
cMenu.getItems().add(remove);
row.setOnContextMenuRequested(e -> cMenu.show(row, event.getScreenX(), event.getScreenY()));
} else {
if (event.getClickCount() == 1) {
System.out.println("Clicked");
System.out.println(row.getItem());
} else if (event.getClickCount() == 2) {
System.out.println("Playing: \n" + row.getItem());
File mediaFile = new File(row.getItem().getLibraryFilePath());
Media mediaToPlay = new Media(mediaFile.toURI().toString());
artistLabel.setText(row.getItem().getArtistName() + " - " + row.getItem().getAlbumName());
songLabel.setText(row.getItem().getSongName());
player.stop();
player = new MediaPlayer(mediaToPlay);
player.setAutoPlay(true);
updatePlayer();
}
}
} catch (MediaException e) {
Stage errorWindow = new Stage();
VBox componentLayout = new VBox();
Label errorLabel = new Label(e.getMessage());
VBox.setMargin(errorLabel, new Insets(10, 10, 10, 10));
componentLayout.getChildren().addAll(errorLabel);
Scene scene = new Scene(componentLayout);
errorWindow.setScene(scene);
errorWindow.show();
}
});
return row;
});
}
use of javafx.scene.control.TableRow in project Gargoyle by callakrsos.
the class CrudBaseGridView method saveBtnClickHandler.
/**
* 저장버튼 클릭 핸들러
*
* @param saveClickCallbackProperty2
*
* @Date 2015. 10. 10.
* @return
* @User KYJ
*/
private EventHandler<MouseEvent> saveBtnClickHandler(ObjectProperty<Consumer<List<T>>> saveClickCallbackProperty) {
return new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
try {
Consumer<List<T>> callback = saveClickCallbackProperty.get();
if (callback == null) {
errorMsgCallback.accept("saveClickCallback 함수에 에러메세지 콜백을 등록하세요.");
return;
}
gridview.fireEvent(event);
List<T> items = getItems();
//필수값 검증로직 추가. 2016.12.08
AbstractVoNullChecker<T> nullCheckHandler = new DefaultVoNullChecker<>(CrudBaseGridView.this);
nullCheckHandler.setList(items);
Optional<Field> findFirst = nullCheckHandler.findFirst();
boolean present = findFirst.isPresent();
if (present) {
String msgFieldName = nullCheckHandler.getMsgNameByfield();
// String message = ValueUtil.getMessage("MSG_W_000001", msgFieldName);
int emptyIndex = nullCheckHandler.getEmptyIndex();
Set<Node> findAllByNodes = CrudBaseGridView.this.lookupAll("TableRow");
findAllByNodes.stream().map(n -> (TableRow) n).filter(r -> {
return emptyIndex == r.getIndex();
}).findFirst().ifPresent(n -> {
Timeline timeline = new Timeline();
timeline.setCycleCount(10);
timeline.setAutoReverse(true);
KeyFrame keyFrame = new KeyFrame(Duration.millis(500), new KeyValue(n.styleProperty(), "-fx-border-color : red ; -fx-border-width : 1px"));
KeyFrame keyFrame2 = new KeyFrame(Duration.millis(500), new KeyValue(n.styleProperty(), ""));
KeyValue keyValueX = new KeyValue(n.styleProperty(), "-fx-border-color : red ; -fx-border-width : 1px");
KeyValue keyValueY = new KeyValue(n.styleProperty(), "");
KeyFrame keyFrame3 = new KeyFrame(Duration.seconds(2), "", keyValueX, keyValueY);
timeline.getKeyFrames().add(keyFrame3);
timeline.play();
});
getSelectionModel().select(emptyIndex);
// DialogUtil.showMessageDialog(SharedMemory.getPrimaryStage(), msgFieldName + " Field is empty.");
return;
}
List<T> arrayList = new ArrayList<T>(items);
arrayList.addAll(deleteItems);
callback.accept(arrayList);
// 사용자 정의 로직이 이상없으면 deleteItems 항목도 비운다.
deleteItems.clear();
} catch (Exception e) {
throw e;
}
}
};
}
use of javafx.scene.control.TableRow in project Retrospector by NonlinearFruit.
the class MediaTabController method initMediaTab.
private void initMediaTab() {
// Rating Stuff
mediaStars.setPartialRating(true);
mediaStars.setDisable(true);
mediaStars.setMax(DataManager.getMaxRating() / 2);
mediaStars.setRating(DataManager.getDefaultRating() / 2);
mediaRating.setText(CoreController.ratingFormat.format(DataManager.getDefaultRating()));
mediaMaxRating.setText(CoreController.ratingFormat.format(DataManager.getMaxRating()));
mediaCategory.setItems(FXCollections.observableArrayList(DataManager.getCategories()));
mediaCategory.getSelectionModel().selectedItemProperty().addListener((observe, old, neo) -> {
});
// Media Stuff
mediaTitle.textProperty().addListener((observe, old, neo) -> mediaSave.setDisable(false));
mediaCreator.textProperty().addListener((observe, old, neo) -> mediaSave.setDisable(false));
mediaSeason.textProperty().addListener((observe, old, neo) -> mediaSave.setDisable(false));
mediaEpisode.textProperty().addListener((observe, old, neo) -> mediaSave.setDisable(false));
mediaDescription.textProperty().addListener((observe, old, neo) -> mediaSave.setDisable(false));
mediaCategory.getSelectionModel().selectedItemProperty().addListener((observe, old, neo) -> mediaSave.setDisable(false));
mediaType.setItems(FXCollections.observableArrayList(Media.Type.values()));
mediaType.getSelectionModel().selectedItemProperty().addListener((observe, old, neo) -> {
switch(neo) {
case SERIES:
mediaSeasonBox.setVisible(true);
mediaEpisodeBox.setVisible(true);
mediaEpisodeBox.toFront();
break;
case MINISERIES:
mediaSeasonBox.setVisible(false);
mediaEpisodeBox.setVisible(true);
mediaSeasonBox.toFront();
break;
case SINGLE:
default:
mediaSeasonBox.setVisible(false);
mediaEpisodeBox.setVisible(false);
}
});
// Buttons
mediaSave.setOnAction(e -> {
Media m = new Media();
m.clone(getMedia());
System.out.println("Media ID: " + m.getId());
m.setTitle(mediaTitle.getText());
m.setCreator(mediaCreator.getText());
m.setSeasonId(mediaSeason.getText());
m.setEpisodeId(mediaEpisode.getText());
m.setCategory(mediaCategory.getValue());
m.setType(mediaType.getValue());
m.setDescription(mediaDescription.getText());
DataManager.updateDB(m);
setMedia(m);
mediaSave.setDisable(true);
});
mediaDelete.setOnAction(e -> {
if (new Alert(Alert.AlertType.WARNING, "Are you sure you want to delete this?", ButtonType.NO, ButtonType.YES).showAndWait().get().equals(ButtonType.YES)) {
DataManager.deleteDB(getMedia());
setTab(TAB.SEARCH);
}
});
mediaCancel.setOnAction(e -> {
setTab(TAB.SEARCH);
});
mediaNewMedia.setOnAction(e -> {
Media media = new Media();
media.setId(DataManager.createDB(media));
if (media.getId() < 2)
System.err.println("Media got a <2 id (mediaNewMedia#setOnAction");
setMedia(media);
updateMediaTab();
mediaTitle.requestFocus();
});
mediaAddSeason.setOnAction(e -> {
Media media = new Media(getMedia().getTitle(), getMedia().getCreator(), getMedia().getCategory(), getMedia().getType());
media.setDescription(getMedia().getDescription());
int id = DataManager.createDB(media);
for (Factoid factoid : getMedia().getFactoids()) {
Factoid fact = new Factoid(factoid.getTitle(), factoid.getContent());
fact.setMediaId(id);
DataManager.createDB(fact);
}
setMedia(DataManager.getMedia(id));
if (getMedia().getId() == -1)
System.err.println("Media got a -1 id (mediaAddSeason#setOnAction");
updateMediaTab();
mediaSeason.requestFocus();
});
mediaAddEpisode.setOnAction(e -> {
Media media = new Media(getMedia().getTitle(), getMedia().getCreator(), getMedia().getCategory(), getMedia().getType());
media.setDescription(getMedia().getDescription());
media.setSeasonId(getMedia().getSeasonId());
int id = DataManager.createDB(media);
for (Factoid factoid : getMedia().getFactoids()) {
Factoid fact = new Factoid(factoid.getTitle(), factoid.getContent());
fact.setMediaId(id);
DataManager.createDB(fact);
}
setMedia(DataManager.getMedia(id));
if (getMedia().getId() == -1)
System.err.println("Media got a -1 id (mediaAddEpisode#setOnAction");
updateMediaTab();
mediaEpisode.requestFocus();
});
nextBtn.setOnAction(e -> {
nextPreviousFunct.accept(1);
update();
});
prevBtn.setOnAction(e -> {
nextPreviousFunct.accept(-1);
update();
});
// Factoid Stuff
mediaTitleFactoid.setItems(FXCollections.observableArrayList(DataManager.getFactiodTypes()));
mediaTitleFactoid.setDisable(true);
mediaContentFactoid.setDisable(true);
mediaSaveFactoid.setDisable(true);
mediaEditFactoid.setDisable(true);
mediaDeleteFactoid.setDisable(true);
currentFactoid = new SimpleObjectProperty<>();
currentFactoid.addListener((observe, old, neo) -> {
boolean tf = false;
if (neo == null)
tf = true;
mediaTitleFactoid.setDisable(tf);
mediaContentFactoid.setDisable(tf);
mediaSaveFactoid.setDisable(tf);
mediaEditFactoid.setDisable(tf);
mediaDeleteFactoid.setDisable(tf);
});
mediaFactoidTable.getSelectionModel().selectedItemProperty().addListener((observe, old, neo) -> {
boolean tf = false;
if (neo == null)
tf = true;
mediaEditFactoid.setDisable(tf);
mediaDeleteFactoid.setDisable(tf);
});
mediaFactoidTable.setRowFactory(tv -> {
TableRow<Factoid> row = new TableRow<>();
row.setOnMouseClicked(event -> {
if (event.getClickCount() == 2 && (!row.isEmpty())) {
setFactoid(row.getItem());
}
});
return row;
});
mediaTitleColumn.setCellValueFactory(new PropertyValueFactory<>("Title"));
mediaContentColumn.setCellValueFactory(new PropertyValueFactory<>("Content"));
mediaNewFactoid.setOnAction(e -> {
Factoid factoid = new Factoid();
factoid.setMediaId(getMedia().getId());
factoid.setId(DataManager.createDB(factoid));
mediaFactoidTable.getItems().add(factoid);
setFactoid(factoid);
});
mediaEditFactoid.setOnAction(e -> {
setFactoid(mediaFactoidTable.getSelectionModel().getSelectedItem());
});
mediaDeleteFactoid.setOnAction(e -> {
if (new Alert(Alert.AlertType.WARNING, "Are you sure you want to delete this?", ButtonType.NO, ButtonType.YES).showAndWait().get().equals(ButtonType.YES)) {
DataManager.deleteDB(mediaFactoidTable.getSelectionModel().getSelectedItem());
updateMediaTab();
}
});
mediaSaveFactoid.setOnAction(e -> {
Factoid factoid = getFactoid();
if (factoid.getId() > 0)
DataManager.updateDB(factoid);
else
DataManager.createDB(factoid);
updateMediaTab();
});
// Review Stuff
mediaReviewTable.getSelectionModel().selectedItemProperty().addListener((observe, old, neo) -> {
setReview(neo);
});
mediaReviewTable.setRowFactory(tv -> {
TableRow<Review> row = new TableRow<>();
row.setOnMouseClicked(event -> {
if (event.getClickCount() == 2 && (!row.isEmpty())) {
setTab(TAB.REVIEW);
}
});
return row;
});
mediaRatingColumn.setCellValueFactory(new PropertyValueFactory<>("Rating"));
mediaUserColumn.setCellValueFactory(new PropertyValueFactory<>("User"));
mediaDateColumn.setCellValueFactory(new PropertyValueFactory<>("Date"));
mediaNewReview.setOnAction(e -> {
Review review = new Review();
review.setMediaId(getMedia().getId());
review.setId(DataManager.createDB(review));
setReview(review);
setTab(TAB.REVIEW);
});
mediaEditReview.setOnAction(e -> {
setTab(TAB.REVIEW);
});
mediaDeleteReview.setOnAction(e -> {
if (new Alert(Alert.AlertType.WARNING, "Are you sure you want to delete this?", ButtonType.NO, ButtonType.YES).showAndWait().get().equals(ButtonType.YES)) {
DataManager.deleteDB(getReview());
updateMediaTab();
}
});
}
Aggregations