Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
todo-list-example
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ole Hermann Bakka
todo-list-example
Commits
b7e18200
Commit
b7e18200
authored
4 years ago
by
Hallvard Trætteberg
Browse files
Options
Downloads
Patches
Plain Diff
(De)aktivering av knapper og penere liste-elementer (#4)
parent
648100a8
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
todolist/src/main/java/todolist/ui/TodoController.java
+27
-2
27 additions, 2 deletions
todolist/src/main/java/todolist/ui/TodoController.java
todolist/src/main/java/todolist/ui/TodoItemListCell.java
+19
-0
19 additions, 0 deletions
todolist/src/main/java/todolist/ui/TodoItemListCell.java
with
46 additions
and
2 deletions
todolist/src/main/java/todolist/ui/TodoController.java
+
27
−
2
View file @
b7e18200
package
todolist.ui
;
import
java.util.Collection
;
import
java.util.List
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
javafx.fxml.FXML
;
import
javafx.scene.control.Button
;
import
javafx.scene.control.ListView
;
import
javafx.scene.control.TextField
;
import
todolist.core.TodoItem
;
...
...
@@ -48,11 +50,23 @@ public class TodoController {
@FXML
ListView
<
TodoItem
>
todoListView
;
@FXML
Button
deleteTodoItemButton
;
@FXML
Button
checkTodoItemButton
;
private
Collection
<
Button
>
selectionButtons
;
@FXML
public
void
initialize
()
{
selectionButtons
=
List
.
of
(
deleteTodoItemButton
,
checkTodoItemButton
);
// kobler data til list-controll
updateTodoListView
();
updateTodoListButtons
();
todoList
.
addTodoListListener
(
todoList
->
updateTodoListView
());
todoListView
.
setCellFactory
(
listView
->
new
TodoItemListCell
());
todoListView
.
getSelectionModel
().
selectedItemProperty
().
addListener
((
prop
,
oldValue
,
newValue
)
->
updateTodoListButtons
());
}
protected
void
updateTodoListView
()
{
...
...
@@ -62,13 +76,22 @@ public class TodoController {
viewList
.
addAll
(
todoList
.
getCheckedTodoItems
());
}
private
void
updateTodoListButtons
()
{
boolean
disable
=
todoListView
.
getSelectionModel
().
getSelectedItem
()
==
null
;
for
(
Button
button
:
selectionButtons
)
{
button
.
setDisable
(
disable
);
}
}
@FXML
public
void
handleNewTodoItemAction
()
{
TodoItem
item
=
new
TodoItem
();
TodoItem
item
=
todoList
.
create
TodoItem
();
item
.
setText
(
newTodoItemText
.
getText
());
todoList
.
addTodoItem
(
item
);
}
@FXML
public
void
handleDeleteItemAction
()
{
TodoItem
item
=
todoListView
.
getSelectionModel
().
getSelectedItem
();
...
...
@@ -80,6 +103,8 @@ public class TodoController {
@FXML
public
void
handleCheckItemAction
()
{
TodoItem
item
=
todoListView
.
getSelectionModel
().
getSelectedItem
();
if
(
item
!=
null
)
{
item
.
setChecked
(
true
);
}
}
}
This diff is collapsed.
Click to expand it.
todolist/src/main/java/todolist/ui/TodoItemListCell.java
0 → 100644
+
19
−
0
View file @
b7e18200
package
todolist.ui
;
import
javafx.scene.control.ListCell
;
import
todolist.core.TodoItem
;
public
class
TodoItemListCell
extends
ListCell
<
TodoItem
>
{
@Override
protected
void
updateItem
(
TodoItem
item
,
boolean
empty
)
{
super
.
updateItem
(
item
,
empty
);
if
(
empty
||
item
==
null
)
{
setText
(
null
);
setGraphic
(
null
);
}
else
{
setText
((
item
.
isChecked
()
?
"v"
:
"-"
)
+
" "
+
item
.
getText
());
setGraphic
(
null
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment