BrightSide Workbench Full Report + Source Code
TasksVM.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.scheduler.model;
20 
21 import java.util.List;
22 import java.util.Set;
23 import org.turro.elephant.util.Messages;
24 import org.turro.reflection.Instances;
25 import org.turro.scheduler.motor.Motor;
26 import org.turro.scheduler.task.AbstractTask;
27 import org.turro.scheduler.task.TaskSet;
28 import org.zkoss.bind.BindUtils;
29 import org.zkoss.bind.annotation.BindingParam;
30 import org.zkoss.bind.annotation.Command;
31 
36 public class TasksVM {
37 
38  @Command
39  public void runSelected() {
40  if(selected != null && selected.isDone()) {
41  selected.doRun(Motor.getInstance());
42  }
43  }
44 
45  @Command
46  public void save() {
48  }
49 
50  @Command
51  public void delete() {
52  if(selected != null && !selected.isSystem()) {
54  .show(() -> {
55  Motor.getInstance().getTasks().remove(selected);
56  selected = null;
57  BindUtils.postNotifyChange(null, null, TasksVM.this, "model", "selected");
58  });
59  }
60  }
61 
62  @Command
63  public void add(@BindingParam("task") AbstractTask task) {
64  Motor.getInstance().getTasks().add(task);
65  selected = task;
66  BindUtils.postNotifyChange(null, null, TasksVM.this, "model", "selected");
67  }
68 
69  /* Tasks */
70 
71  public List<AbstractTask> getAvailable() {
72  return Instances.fresh().bySuper(AbstractTask.class, AbstractTask.class)
73  .stream().filter(t -> !t.isSystem()).toList();
74  }
75 
76  /* Selection */
77 
78  private AbstractTask selected;
79 
81  return selected;
82  }
83 
84  public void setSelected(AbstractTask selected) {
85  this.selected = selected;
86  }
87 
88  /* Model */
89 
90  public Set getModel() {
91  return Motor.getInstance().getTasks();
92  }
93 
94 }
static Messages confirmDeletion()
Definition: Messages.java:87
Messages add(String word)
Definition: Messages.java:50
void setSelected(AbstractTask selected)
Definition: TasksVM.java:84
void add(@BindingParam("task") AbstractTask task)
Definition: TasksVM.java:63
List< AbstractTask > getAvailable()
Definition: TasksVM.java:71
static Motor getInstance()
Definition: Motor.java:62
Set< AbstractTask > getTasks()
Definition: Motor.java:76
static void save(Set< AbstractTask > tasks)
Definition: TaskSet.java:58