Skip to content

Commit c9bc4ea

Browse files
committed
PTBAS-738: Refactor SearchPopup into SearchCombobox and remove unnecessary code
1 parent e51e25d commit c9bc4ea

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

src/main/java/de/doubleslash/keeptime/view/ExternalProjectsSyncController.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import de.doubleslash.keeptime.model.StyledMessage;
2626
import de.doubleslash.keeptime.model.Work;
2727
import de.doubleslash.keeptime.rest.integration.heimat.model.HeimatTask;
28-
import de.doubleslash.keeptime.viewpopup.SearchPopup;
28+
import de.doubleslash.keeptime.viewpopup.SearchCombobox;
2929
import javafx.animation.Animation;
3030
import javafx.animation.KeyFrame;
3131
import javafx.animation.RotateTransition;
@@ -208,10 +208,10 @@ public void initForDate(LocalDate currentReportDate, List<Work> currentWorkItems
208208
tasksNotInList.setPredicate(predicate);
209209
});
210210

211-
SearchPopup<HeimatTask> heimatTaskSearchPopup = new SearchPopup<>(tasksNotInList);
212-
heimatTaskSearchPopup.setDisplayTextFunction(task -> task.taskHolderName() + " - " + task.name());
211+
SearchCombobox<HeimatTask> heimatTaskSearchCombobox = new SearchCombobox<>(tasksNotInList);
212+
heimatTaskSearchCombobox.setDisplayTextFunction(task -> task.taskHolderName() + " - " + task.name());
213213

214-
heimatTaskSearchPopup.setOnItemSelected((selectedTask, popup) -> {
214+
heimatTaskSearchCombobox.setOnItemSelected((selectedTask, popup) -> {
215215
if (selectedTask == null)
216216
return;
217217
boolean alreadyExists = items.stream().anyMatch(row -> row.mapping.heimatTaskId() == selectedTask.id());
@@ -229,10 +229,10 @@ public void initForDate(LocalDate currentReportDate, List<Work> currentWorkItems
229229
itemsForBindings.add(addedRow); // add new row also to items2 - as it is not added automatically :(
230230
mappingTableView.scrollTo(items.size() - 1); // scroll to newly added row
231231
});
232-
heimatTaskSearchPopup.setClearFieldAfterSelection(true);
232+
heimatTaskSearchCombobox.setClearFieldAfterSelection(true);
233233

234-
heimatTaskSearchContainer.getChildren().add(heimatTaskSearchPopup.getComboBox());
235-
HBox.setHgrow(heimatTaskSearchPopup.getComboBox(), Priority.ALWAYS);
234+
heimatTaskSearchContainer.getChildren().add(heimatTaskSearchCombobox.getComboBox());
235+
HBox.setHgrow(heimatTaskSearchCombobox.getComboBox(), Priority.ALWAYS);
236236
}
237237

238238
@FXML
@@ -292,9 +292,6 @@ private HBox createRow(Color color, String text) {
292292
Label label = new Label(text);
293293
label.setTooltip(new Tooltip(text));
294294

295-
label.setMaxWidth(Double.MAX_VALUE);
296-
HBox.setHgrow(label, Priority.ALWAYS);
297-
298295
return new HBox(5, circle, label);
299296
}
300297
});
@@ -454,10 +451,6 @@ protected void updateItem(TableRow item, boolean empty) {
454451
tooltip.setText(statusForTooltip);
455452
}
456453

457-
// Fix Cell height not aligning with Textflow
458-
// https://stackoverflow.com/questions/42855724/textflow-inside-tablecell-not-correct-cell-height
459-
statusFlow.maxWidthProperty().bind(column.widthProperty());
460-
461454
setGraphic(new Group(statusFlow));
462455

463456
setTooltip(tooltip);

src/main/java/de/doubleslash/keeptime/viewpopup/SearchPopup.java renamed to src/main/java/de/doubleslash/keeptime/viewpopup/SearchCombobox.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import java.util.function.Function;
1919
import java.util.stream.Collectors;
2020

21-
public class SearchPopup<T> {
21+
public class SearchCombobox<T> {
2222
private final TextField searchField = new TextField();
2323
private final Button showSuggestionsButton = new Button("▼");
2424
private final ListView<T> suggestionList = new ListView<>();
@@ -33,14 +33,10 @@ public class SearchPopup<T> {
3333
private String promptText = "Select item…";
3434
private double maxSuggestionHeight = 200;
3535

36-
private BiConsumer<T, SearchPopup<T>> onItemSelected = (item, popup) -> {};
36+
private BiConsumer<T, SearchCombobox<T>> onItemSelected = (item, popup) -> {};
3737
private boolean clearFieldAfterSelection = false;
3838

39-
public SearchPopup() {
40-
this(FXCollections.observableArrayList());
41-
}
42-
43-
public SearchPopup(ObservableList<T> items) {
39+
public SearchCombobox(ObservableList<T> items) {
4440
container = new HBox(searchField, showSuggestionsButton);
4541
container.getStyleClass().add("search-popup-container");
4642
container.setAlignment(Pos.CENTER_LEFT);
@@ -246,7 +242,7 @@ public Function<T, String> getDisplayTextFunction() {
246242
return displayTextFunction;
247243
}
248244

249-
public void setOnItemSelected(BiConsumer<T, SearchPopup<T>> handler) {
245+
public void setOnItemSelected(BiConsumer<T, SearchCombobox<T>> handler) {
250246
this.onItemSelected = handler != null ? handler : (item, popup) -> {};
251247
}
252248

0 commit comments

Comments
 (0)