BrightSide Workbench Full Report + Source Code
elephant-plugins/src/main/java/org/turro/plugin/command/CalendarEventPlugin.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 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.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Date;
24 import java.util.HashMap;
25 import java.util.Map;
26 import org.turro.command.Command;
27 import org.turro.command.Context;
28 import org.turro.elephant.context.Application;
29 import org.turro.plugin.calendar.ICalendarEvent;
30 import org.turro.plugin.contacts.IContact;
31 
36 public abstract class CalendarEventPlugin implements IPlugin, Command {
37 
38  public static final int
39  CREATE = 1, // click or drag on empty cell
40  EDIT = 2, // click on occupied cell
41  UPDATE = 3; // drag on occupied cell
42 
43  protected Map<String, Object> params;
44  protected Collection controls;
45 
46  @Override
47  public String getName() {
48  return "CalendarEvent";
49  }
50 
51  @Override
52  public boolean stopsPropagating() {
53  return false;
54  }
55 
56  @Override
57  public void setParams(Object params) {
58  this.params = (Map<String, Object>) params;
59  }
60 
61  public IContact getContact() {
62  return (IContact) params.get("contact");
63  }
64 
65  public Date getOldFrom() {
66  return (Date) params.get("oldFrom");
67  }
68 
69  public Date getOldTo() {
70  return (Date) params.get("oldTo");
71  }
72 
73  public Date getFrom() {
74  return (Date) params.get("from");
75  }
76 
77  public Date getTo() {
78  return (Date) params.get("to");
79  }
80 
81  public String getPath() {
82  return (String) params.get("path");
83  }
84 
85  public Integer getMode() {
86  return (Integer) params.get("mode");
87  }
88 
89  @Override
90  public Object execute(Context context) {
91 // if(getName().equals(context.get(CommandFactory.COMMAND_PARS))) {
92 // setParams(context.get(CommandFactory.DATA));
93 // controls = (Collection) context.get(CommandFactory.RESULT);
94 // executePlugin(context);
95 // context.put(CommandFactory.RESULT, controls);
96 // if(stopsPropagating()) {
97 // return PROCESSING_COMPLETE;
98 // }
99 // }
100 // return CONTINUE_PROCESSING;
101  return null;
102  };
103 
104  protected void addToResult(Object data) {
105  if(controls == null) {
106  controls = new ArrayList();
107  }
108  controls.add(data);
109  }
110 
111  protected abstract void executePlugin(Context context) throws Exception;
112 
113  public static Collection<ICalendarEvent> getCalendarEventFor(Application app,
114  IContact contact, Date oldFrom, Date oldTo, Date from, Date to, String path, int mode) {
115 // Map<String, Object> params = new HashMap<String, Object>();
116 // params.put("contact", contact);
117 // params.put("oldFrom", oldFrom);
118 // params.put("oldTo", oldTo);
119 // params.put("from", from);
120 // params.put("to", to);
121 // params.put("path", path);
122 // params.put("mode", mode);
123 // return (Collection<ICalendarEvent>) CommandFactory
124 // .executePlugins(app, params, "CalendarEvent");
125  return null;
126  }
127 
128 }
129 
static Collection< ICalendarEvent > getCalendarEventFor(Application app, IContact contact, Date oldFrom, Date oldTo, Date from, Date to, String path, int mode)
abstract void executePlugin(Context context)