BrightSide Workbench Full Report + Source Code
TimelineReport.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 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.plugin.command;
20 
21 import java.io.File;
22 import java.io.IOException;
23 import java.util.Date;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
26 import org.amic.util.file.FileUtil;
27 import org.turro.auth.Authentication;
28 import org.turro.elephant.context.ElephantContext;
29 import org.turro.plugin.contacts.IContact;
30 import org.turro.util.IdGenerator;
31 import org.zkforge.timeline.Bandinfo;
32 import org.zkforge.timeline.Timeline;
33 import org.zkoss.zk.ui.ext.AfterCompose;
34 
39 public class TimelineReport extends Timeline implements AfterCompose {
40 
41  @Override
42  public void afterCompose() {
44  String xml = TimelinePlugin.getTimelineFor(contact),
45  fname = "/_internal/tmp/tl-" + contact.getId() + "-" + contact.getId() + ".xml";
46  File fxml = new File(ElephantContext.getRealPath(fname));
47  FileUtil.checkDirs(fxml);
48  Date now = new Date();
49  try {
50  FileUtil.setContent(fxml, xml, null);
51  Bandinfo bm1 = new Bandinfo();
52  bm1.setId(IdGenerator.generate());
53  bm1.setWidth("80%");
54  bm1.setIntervalUnit("month");
55  bm1.setDate(now);
56  bm1.setIntervalPixels(100);
57  bm1.setEventSourceUrl(fname);
58  appendChild(bm1);
59  Bandinfo bm2 = new Bandinfo();
60  bm2.setWidth("20%");
61  bm2.setIntervalUnit("year");
62  bm2.setDate(now);
63  bm2.setIntervalPixels(200);
64  bm2.setEventSourceUrl(fname);
65  bm2.setOverview(true);
66  appendChild(bm2);
67  bm2.setSyncWith(bm1.getId());
68  if(bm1 instanceof AfterCompose) {
69  ((AfterCompose) bm1).afterCompose();
70  }
71  if(bm2 instanceof AfterCompose) {
72  ((AfterCompose) bm2).afterCompose();
73  }
74  } catch (IOException ex) {
75  Logger.getLogger(TimelineReport.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
76  }
77  }
78 
79 
80 }