BrightSide Workbench Full Report + Source Code
ChallengeComposer.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2019 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.students.view;
20 
21 import org.turro.elephant.context.Application;
22 import org.turro.jpa.composer.EntityComposer;
23 import org.turro.jpa.entity.DaoEntity;
24 import org.turro.students.db.StudentsPU;
25 import org.turro.students.entities.Challenge;
26 import org.turro.students.menu.StudentsMenu;
27 import org.turro.students.wrappers.ChallengeWrapper;
28 import org.turro.zkoss.text.WikiEditor;
29 import org.turro.zul.frame.Framework;
30 import org.zkoss.zk.ui.Component;
31 import org.zkoss.zk.ui.select.annotation.Listen;
32 import org.zkoss.zk.ui.select.annotation.Wire;
33 
38 public class ChallengeComposer extends EntityComposer<Challenge, Long> {
39 
40  @Wire("#wiki")
41  private WikiEditor wiki;
42 
43  @Listen("onChange = #wiki")
44  public void onWikiChange() {
45  entity.setWikiText(wiki.getValue());
46  }
47 
48  @Override
49  protected String getAttributeName() {
50  return "challenge";
51  }
52 
53  @Override
54  protected Challenge getEntityInstance(Long id) {
55  if(id == null) {
56  entity = new Challenge();
57  } else {
58  entity = new StudentsPU().find(Challenge.class, id);
59  }
60  return entity;
61  }
62 
63  @Override
64  protected DaoEntity getWrapperInstance(Component comp) {
68  return w;
69  }
70 
71  @Override
72  public void afterSave() {
73  if(entity != null) {
75  }
76  }
77 
78  @Override
79  protected boolean shouldBeSaved() {
80  return !entity.isEmpty() && (entity.getId() == null || entity.getId() == 0) || super.shouldBeSaved();
81  }
82 
83  @Override
84  protected boolean inSaveRole() {
85  return Application.getApplication().isInRole("challenge:edit");
86  }
87 
88  @Override
89  protected boolean inDeleteRole() {
90  return Application.getApplication().isInRole("challenge:delete");
91  }
92 
93 }
94 
static void showChallenge(Challenge challenge)
static Framework getCurrent()
Definition: Framework.java:203
void setSelectedLabel(String text)
Definition: Framework.java:103
void setSelectedTooltiptext(String text)
Definition: Framework.java:107