Skip to content

Commit 49bc993

Browse files
author
Martin Plieske
committed
Merge branch 'feature/searchbarForProjectsInMainView' of https://github.com/doubleSlashde/KeepTime into feature/searchbarForProjectsInMainView
2 parents 573fc66 + ec99e9f commit 49bc993

File tree

4 files changed

+18
-23
lines changed

4 files changed

+18
-23
lines changed

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

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.util.Map;
88
import java.util.Map.Entry;
99
import java.util.Optional;
10-
import java.util.function.Consumer;
1110

1211
import org.slf4j.Logger;
1312
import org.slf4j.LoggerFactory;
@@ -37,6 +36,7 @@
3736
import javafx.scene.control.ListView;
3837
import javafx.scene.control.MenuItem;
3938
import javafx.scene.control.MultipleSelectionModel;
39+
import javafx.scene.control.SelectionMode;
4040
import javafx.scene.control.Spinner;
4141
import javafx.scene.control.SpinnerValueFactory.IntegerSpinnerValueFactory;
4242
import javafx.scene.control.TextField;
@@ -80,14 +80,6 @@ public ProjectsListViewController(final Model model, final Controller controller
8080
addProjectToProjectSelectionNodeMap(project);
8181
}
8282

83-
// TODO why is there no nice way for listview height?
84-
// https://stackoverflow.com/questions/17429508/how-do-you-get-javafx-listview-to-be-the-height-of-its-items
85-
final Consumer<Double> updateSize = height -> {
86-
LOG.debug(String.format("%s%f", "update size ", height));
87-
availableProjectsListView.setPrefHeight(height);
88-
mainStage.sizeToScene(); // also update scene size
89-
};
90-
9183
searchTextField.textProperty().addListener((a, b, newValue) -> {
9284
LOG.info("New filter value: " + newValue);
9385
// TODO do i always have to create a new predicate?
@@ -100,38 +92,40 @@ public ProjectsListViewController(final Model model, final Controller controller
10092
final String lowerCaseFilter = newValue.toLowerCase();
10193

10294
if (project.getName().toLowerCase().contains(lowerCaseFilter)) {
103-
return true; // Filter matches first name.
95+
return true;
10496
}
10597

106-
return false; // Does not match.
98+
return false;
10799
});
108100
LOG.debug("Amount of projects to show '{}'.", filteredData.size());
101+
availableProjectsListView.getSelectionModel().selectFirst();
102+
availableProjectsListView.scrollTo(0);
109103
});
110104

111105
searchTextField.setOnKeyPressed(eh -> {
112106
final MultipleSelectionModel<Project> selectionModel = availableProjectsListView.getSelectionModel();
113-
final int selectedIndex = selectionModel.getSelectedIndex();
114107
switch (eh.getCode()) {
115108
case UP:
116109
LOG.debug("Arrow up pressed.");
117-
selectionModel.select(selectedIndex - 1);
110+
selectionModel.selectPrevious();
118111
eh.consume();
119112
break;
120113
case DOWN:
121114
LOG.debug("Arrow down pressed.");
122-
selectionModel.select(selectedIndex + 1);
115+
selectionModel.selectNext();
123116
eh.consume();
124117
break;
125118
case ESCAPE:
119+
LOG.debug("Esc pressed.");
126120
if (hideable) {
127-
searchTextField.getScene().getWindow().hide();
121+
mainStage.hide();
128122
}
123+
eh.consume();
129124
break;
130125
default:
131126
break;
132127
}
133128
availableProjectsListView.scrollTo(selectionModel.getSelectedIndex());
134-
LOG.debug("Selected list item index '{}'.", selectionModel.getSelectedIndex());
135129
});
136130

137131
// enter pressed in textfield
@@ -143,9 +137,8 @@ public ProjectsListViewController(final Model model, final Controller controller
143137
}
144138
});
145139

140+
availableProjectsListView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
146141
availableProjectsListView.getSelectionModel().selectFirst();
147-
148-
searchTextField.setPromptText("Search");
149142
}
150143

151144
private void addProjectToProjectSelectionNodeMap(final Project project) {
@@ -321,8 +314,9 @@ private Pane addProjectToProjectList(final Project p) {
321314
projectNameLabel.setTextFill(new Color(p.getColor().getRed() * dimFactor,
322315
p.getColor().getGreen() * dimFactor, p.getColor().getBlue() * dimFactor, 1));
323316
projectNameLabel.setUnderline(p.isWork());
317+
projectNameLabel.getTooltip().setText(p.getName());
324318

325-
// updateProjectView(); // TODO how to update currentProjectLabel when project was edited?
319+
// TODO how to update currentProjectLabel when active project was edited?
326320
realignProjectList();
327321
});
328322
});

src/main/resources/css/application.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767

6868
.list-cell {
6969
-fx-background-color: transparent;
70+
-fx-padding: 0px;
7071
}
7172

7273
.list-cell:selected {

src/main/resources/layouts/ViewLayout.fxml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@
108108
<left>
109109
<VBox fx:id="projectsVBox" BorderPane.alignment="CENTER">
110110
<children>
111-
<TextField fx:id="searchTextField" maxHeight="15.0" minHeight="0.0" prefHeight="15.0" prefWidth="148.0" stylesheets="@../css/application.css">
111+
<TextField fx:id="searchTextField" maxHeight="15.0" minHeight="0.0" prefHeight="15.0" prefWidth="140.0" promptText="Search" stylesheets="@../css/application.css">
112112
<font>
113113
<Font name="Open Sans Regular" size="12.0" />
114114
</font>
115115
</TextField>
116-
<ListView fx:id="availableProjectsListView" prefHeight="130.0" prefWidth="148.0" stylesheets="@../css/application.css" />
116+
<ListView fx:id="availableProjectsListView" prefHeight="130.0" prefWidth="140.0" stylesheets="@../css/application.css" />
117117
<Button fx:id="addNewProjectButton" minHeight="-Infinity" mnemonicParsing="false" onAction="#addNewProject" prefHeight="23.0" prefWidth="120.0" stylesheets="@../css/application.css" text="+ Add new project">
118118
<font>
119119
<Font name="Open Sans Regular" size="12.0" />

src/main/resources/layouts/ViewLayoutPopup.fxml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
<?import javafx.scene.layout.VBox?>
2222
<?import javafx.scene.text.Font?>
2323

24-
<VBox fx:id="root" prefHeight="425.0" prefWidth="145.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.doubleslash.keeptime.viewpopup.ViewControllerPopup">
24+
<VBox fx:id="root" prefHeight="350.0" prefWidth="145.0" style="-fx-background-radius: 10 10 10 10; -fx-border-radius: 10 10 10 10; -fx-border-color: rgba(54,143,179,.0.01);" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.doubleslash.keeptime.viewpopup.ViewControllerPopup">
2525
<children>
2626
<TextField fx:id="searchTextField" maxHeight="15.0" minHeight="0.0" prefHeight="15.0" promptText="Search" stylesheets="@../css/application.css">
2727
<font>
2828
<Font name="Open Sans Regular" size="12.0" />
2929
</font>
3030
</TextField>
31-
<ListView fx:id="projectListView" prefHeight="400.0" prefWidth="312.0" stylesheets="@../css/application.css" />
31+
<ListView fx:id="projectListView" prefHeight="335.0" prefWidth="145.0" stylesheets="@../css/application.css" />
3232
</children>
3333
</VBox>

0 commit comments

Comments
 (0)