Skip to content
This repository has been archived by the owner on Jun 11, 2023. It is now read-only.

Commit

Permalink
Previous expanded [Topic]s will now also expanded after a refresh.
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoghuman committed Feb 4, 2017
1 parent 2a7b899 commit e2bc027
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ private void onActionCreateNewExerciseWithTopicId(long entityId) {
// Update the gui
final ObservableList<Topic> topics = SqlProvider.getDefault().findAllTopics();
NavigationProvider.getDefault().onActionRefreshNavigationTabTopics(topics);
NavigationProvider.getDefault().onActionExpandTopic(topic);
}

public void onActionCreateNewTerm() {
Expand Down Expand Up @@ -220,7 +219,6 @@ public void onActionCreateNewTopic() {
topics.clear();
topics.addAll(SqlProvider.getDefault().findAllTopics());
NavigationProvider.getDefault().onActionRefreshNavigationTabTopics(topics);
// NavigationProvider.getDefault().onActionRefreshNavigationTabTerms(topics);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
import com.github.naoghuman.lib.action.api.IRegisterActions;
import com.github.naoghuman.lib.action.api.TransferData;
import com.github.naoghuman.lib.logger.api.LoggerFacade;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
Expand Down Expand Up @@ -159,17 +162,19 @@ private String getInfoFoundedTerms(int foundedTerms) {
return sb.toString();
}

public void onActionExpandTopic(Topic topic) {
LoggerFacade.getDefault().debug(this.getClass(), "On action expand [Topic]"); // NOI18N
// public void onAcitonExpandAllOpen

final Optional<TreeItem<NavigationEntity>> optionalTreeItem = rootItemNavigationTabTopics.getChildren().stream()
.filter(treeItem -> ((NavigationEntity) treeItem.getValue()).getNavigation().getNavigationType().equals(ENavigationType.TOPIC))
.filter(treeItem -> Objects.equals(((NavigationEntity) treeItem.getValue()).getNavigation().getEntityId(), topic.getId()))
.findFirst();
if (optionalTreeItem.isPresent()) {
optionalTreeItem.get().setExpanded(true);
}
}
// public void onActionExpandTopic(Topic topic) {
// LoggerFacade.getDefault().debug(this.getClass(), "On action expand [Topic]"); // NOI18N
//
// final Optional<TreeItem<NavigationEntity>> optionalTreeItem = rootItemNavigationTabTopics.getChildren().stream()
// .filter(treeItem -> ((NavigationEntity) treeItem.getValue()).getNavigation().getNavigationType().equals(ENavigationType.TOPIC))
// .filter(treeItem -> Objects.equals(((NavigationEntity) treeItem.getValue()).getNavigation().getEntityId(), topic.getId()))
// .findFirst();
// if (optionalTreeItem.isPresent()) {
// optionalTreeItem.get().setExpanded(true);
// }
// }

public void onActionRefreshNavigationTabTerms(ObservableList<Topic> topics) {
LoggerFacade.getDefault().debug(this.getClass(), "On action refresh [Navigation] tab [Term]s"); // NOI18N
Expand Down Expand Up @@ -207,30 +212,28 @@ private void onActionRefreshNavigationTabTerms(Term term) {
lvNavigationTerms.getItems().add(selectedIndex, term);
lvNavigationTerms.getSelectionModel().clearAndSelect(selectedIndex);
}

private void onActionRefreshNavigationTabTopics() {
LoggerFacade.getDefault().debug(this.getClass(), "On action refresh [Navigation] tab [Topics]"); // NOI18N

final ObservableList<Topic> observableListTopics = SqlProvider.getDefault().findAllTopics();
NavigationProvider.getDefault().onActionRefreshNavigationTabTopics(observableListTopics);
}

public void onActionRefreshNavigationTabTopics(ObservableList<Topic> topics) {
LoggerFacade.getDefault().debug(this.getClass(), "On action refresh [Navigation] tab [Topic]s"); // NOI18N

// Catch expanded [TreeItem]s
final List<NavigationEntity> navigationEntities = new ArrayList<>();
rootItemNavigationTabTopics.getChildren().stream()
.filter((treeItem) -> treeItem.isExpanded())
.forEach((treeItem) -> {
navigationEntities.add(treeItem.getValue());
});

// Refresh the [TreeView]
rootItemNavigationTabTopics.getChildren().clear();

topics.forEach(topic -> {
LoggerFacade.getDefault().debug(this.getClass(), " # " + topic.toString());

final ObservableList<Exercise> observableListExercises = SqlProvider.getDefault().findAllExercisesWithTopicId(topic.getId());
topic.setExercises(observableListExercises.size());

final NavigationEntity navigationEntity = ModelProvider.getDefault().getNavigationEntity(ENavigationType.TOPIC, topic.getId(), new TopicNavigationConverter(topic));
final TreeItem<NavigationEntity> treeItemTopic = new TreeItem<>(navigationEntity);
observableListExercises.forEach(exercise -> {
LoggerFacade.getDefault().debug(this.getClass(), " # " + exercise.toString());

final NavigationEntity navigationEntity2 = ModelProvider.getDefault().getNavigationEntity(ENavigationType.EXERCISE, exercise.getId(), new ExerciseNavigationConverter(exercise));
final TreeItem<NavigationEntity> treeItemExercise = new TreeItem<>(navigationEntity2);
treeItemTopic.getChildren().add(treeItemExercise);
Expand All @@ -240,6 +243,17 @@ public void onActionRefreshNavigationTabTopics(ObservableList<Topic> topics) {
});

tvNavigationTabTopics.setRoot(rootItemNavigationTabTopics);

// Expanded previous [TreeItem]s
Platform.runLater(() -> {
navigationEntities.stream().forEach((navigationEntity) -> {
rootItemNavigationTabTopics.getChildren().stream()
.filter((treeItem) -> (Objects.equals(((NavigationEntity) treeItem.getValue()).getNavigation().getEntityId(), navigationEntity.getNavigation().getEntityId())))
.forEach((treeItem) -> {
treeItem.setExpanded(true);
});
});
});
}

public void onActionSelectPreviousSelectedIndex() {
Expand Down Expand Up @@ -306,7 +320,8 @@ private void registerOnActionRefreshNavigationTabTopics() {
ActionFacade.getDefault().register(
ACTION__APPLICATION__REFRESH_NAVIGATION_TAB_TOPICS,
(ActionEvent event) -> {
this.onActionRefreshNavigationTabTopics();
final ObservableList<Topic> topics = SqlProvider.getDefault().findAllTopics();
this.onActionRefreshNavigationTabTopics(topics);//topic);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.github.naoghuman.abclist.model.Topic;
import com.github.naoghuman.abclist.sql.SqlProvider;
import com.github.naoghuman.lib.action.api.ActionFacade;
import com.github.naoghuman.lib.action.api.TransferData;
import com.github.naoghuman.lib.logger.api.LoggerFacade;
import java.net.URL;
import java.util.ResourceBundle;
Expand Down Expand Up @@ -58,16 +59,19 @@ private void initializeListeners() {
}

public void configure(Topic topic) {
LoggerFacade.getDefault().debug(this.getClass(), "configure"); // NOI18N

this.topic = topic;

bSave.disableProperty().bind(topic.markAsChangedProperty().not());

tfTitle.setText(topic.getTitle());
tfTitle.textProperty().addListener(stringChangeListener);
topic.titleProperty().bind(tfTitle.textProperty());

taDescription.setText(topic.getDescription());
taDescription.textProperty().addListener(stringChangeListener);
topic.descriptionProperty().bind(taDescription.textProperty());
}

public long getId() {
Expand All @@ -78,20 +82,13 @@ public void onActionSaveTopic() {
LoggerFacade.getDefault().debug(this.getClass(), "On action save [Topic]"); // NOI18N

// TODO check if title is valid

// Catch new data
final String title = tfTitle.getText();
topic.setTitle(title);

final String description = taDescription.getText();
topic.setDescription(description);

// Data in the model is updated through binding
SqlProvider.getDefault().updateTopic(topic);

// Reset [MarkAsChanged]
topic.setMarkAsChanged(Boolean.FALSE);

// Refresh navigation-tab-topics
// Refresh the [Navigation]
ActionFacade.getDefault().handle(ACTION__APPLICATION__REFRESH_NAVIGATION_TAB_TOPICS);
}

Expand Down

0 comments on commit e2bc027

Please sign in to comment.