Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Ole Hermann Bakka
todo-list-example
Commits
f67eaeec
Commit
f67eaeec
authored
Oct 01, 2020
by
Hallvard Trætteberg
Browse files
Fikset kontrolleren så den virker...
parent
8e00b1ec
Changes
3
Hide whitespace changes
Inline
Side-by-side
todolist/fxui/src/main/java/todolist/ui/TodoController.java
View file @
f67eaeec
...
...
@@ -23,18 +23,19 @@ import javafx.scene.control.ListView;
import
javafx.scene.control.TextField
;
import
todolist.core.TodoItem
;
import
todolist.core.TodoList
;
import
todolist.core.TodoModel
;
import
todolist.json.TodoPersistence
;
public
class
TodoController
{
private
static
final
String
todoListWithTwoItems
=
"{\"items\":[{\"text\":\"
Øl
\",\"checked\":false},{\"text\":\"
Pizza
\",\"checked\":true}]}"
;
"{\"
lists\":[{\"name\":\"todo\",\"
items\":[{\"text\":\"
item1
\",\"checked\":false},{\"text\":\"
item2
\",\"checked\":true
,\"deadline\":\"2020-10-01T14:53:11\"}]
}]}"
;
private
Todo
List
todoList
;
private
Todo
Model
todoModel
;
// makes class more testable
TodoList
getTodoList
()
{
return
todo
List
;
return
todo
Model
.
iterator
().
next
()
;
}
private
TodoPersistence
todoPersistence
=
new
TodoPersistence
();
...
...
@@ -84,12 +85,14 @@ public class TodoController {
reader
=
new
StringReader
(
todoListWithTwoItems
);
}
try
{
todo
List
=
todoPersistence
.
readTodo
List
(
reader
);
todo
Model
=
todoPersistence
.
readTodo
Model
(
reader
);
}
catch
(
IOException
e
)
{
todoList
=
new
TodoList
(
todoList
.
createTodoItem
().
text
(
"Øl"
),
todoList
.
createTodoItem
().
text
(
"Pizza"
)
todoModel
=
new
TodoModel
();
TodoList
todoList
=
new
TodoList
(
new
TodoItem
().
text
(
"Øl"
),
new
TodoItem
().
text
(
"Pizza"
)
);
todoModel
.
addTodoList
(
todoList
);
}
finally
{
try
{
if
(
reader
!=
null
)
{
...
...
@@ -110,11 +113,11 @@ public class TodoController {
// kobler data til list-controll
updateTodoListView
();
updateTodoListButtons
();
t
odoList
.
addTodoListListener
(
todoList
->
{
getT
odoList
()
.
addTodoListListener
(
todoList
->
{
autoSaveTodoList
();
updateTodoListView
();
});
TodoItemListCellDragHandler
dragHandler
=
new
TodoItemListCellDragHandler
(
t
odoList
);
TodoItemListCellDragHandler
dragHandler
=
new
TodoItemListCellDragHandler
(
getT
odoList
()
);
todoListView
.
setCellFactory
(
listView
->
{
TodoItemListCell
listCell
=
new
TodoItemListCell
();
dragHandler
.
registerHandlers
(
listCell
);
...
...
@@ -127,8 +130,8 @@ public class TodoController {
protected
void
updateTodoListView
()
{
List
<
TodoItem
>
items
=
new
ArrayList
<>();
items
.
addAll
(
t
odoList
.
getUncheckedTodoItems
());
items
.
addAll
(
t
odoList
.
getCheckedTodoItems
());
items
.
addAll
(
getT
odoList
()
.
getUncheckedTodoItems
());
items
.
addAll
(
getT
odoList
()
.
getCheckedTodoItems
());
TodoItem
selectedItem
=
todoListView
.
getSelectionModel
().
getSelectedItem
();
todoListView
.
getItems
().
setAll
(
items
);
// keep selection
...
...
@@ -176,9 +179,9 @@ public class TodoController {
@FXML
void
handleNewTodoItemAction
()
{
TodoItem
item
=
t
odoList
.
createTodoItem
();
TodoItem
item
=
getT
odoList
()
.
createTodoItem
();
item
.
setText
(
newTodoItemText
.
getText
());
t
odoList
.
addTodoItem
(
item
);
getT
odoList
()
.
addTodoItem
(
item
);
todoListView
.
getSelectionModel
().
select
(
item
);
}
...
...
@@ -187,7 +190,7 @@ public class TodoController {
int
index
=
todoListView
.
getSelectionModel
().
getSelectedIndex
();
TodoItem
item
=
todoListView
.
getItems
().
get
(
index
);
if
(
item
!=
null
)
{
t
odoList
.
removeTodoItem
(
item
);
getT
odoList
()
.
removeTodoItem
(
item
);
selectWithinBounds
(
index
);
}
}
...
...
@@ -217,7 +220,7 @@ public class TodoController {
if
(
userTodoListPath
!=
null
)
{
Path
path
=
Paths
.
get
(
System
.
getProperty
(
"user.home"
),
userTodoListPath
);
try
(
Writer
writer
=
new
FileWriter
(
path
.
toFile
(),
StandardCharsets
.
UTF_8
))
{
todoPersistence
.
writeTodo
List
(
todoList
,
writer
);
todoPersistence
.
writeTodo
Model
(
todoModel
,
writer
);
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"Fikk ikke skrevet til todolist.json på hjemmeområdet"
);
}
...
...
todolist/fxui/src/main/resources/todolist/ui/sample-todolist.json
View file @
f67eaeec
{
"
item
s"
:
[
"
list
s"
:
[
{
"text"
:
"Øl"
,
"checked"
:
false
},
{
"text"
:
"Pizza"
,
"checked"
:
false
"name"
:
"todo"
,
"items"
:
[
{
"text"
:
"Øl"
,
"checked"
:
false
},
{
"text"
:
"Pizza"
,
"checked"
:
false
}
]
}
]
}
\ No newline at end of file
todolist/fxui/src/test/resources/todolist/ui/test-todolist.json
View file @
f67eaeec
{
"
item
s"
:
[
"
list
s"
:
[
{
"text"
:
"Item 1"
,
"checked"
:
true
},
{
"text"
:
"Item 2"
,
"checked"
:
false
"name"
:
"todo"
,
"deadline"
:
"2020-10-01T14:53:11"
,
"items"
:
[
{
"text"
:
"Item 1"
,
"checked"
:
true
},
{
"text"
:
"Item 2"
,
"checked"
:
false
}
]
}
]
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment