001: package hero.client.manager;
002:
003: /*
004: *
005: * Manager.java -
006: * Copyright (C) 2003 Ecoo Team
007: * valdes@loria.fr
008: *
009: *
010: * This program is free software; you can redistribute it and/or
011: * modify it under the terms of the GNU Lesser General Public License
012: * as published by the Free Software Foundation; either version 2
013: * of the License, or (at your option) any later version.
014: *
015: * This program is distributed in the hope that it will be useful,
016: * but WITHOUT ANY WARRANTY; without even the implied warranty of
017: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
018: * GNU Lesser General Public License for more details.
019: *
020: * You should have received a copy of the GNU Lesser General Public License
021: * along with this program; if not, write to the Free Software
022: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
023: */
024:
025: import hero.util.BonitaClient;
026: import hero.client.events.JMSServicesClient;
027:
028: import java.awt.Container;
029: import java.awt.Dimension;
030: import java.awt.GridLayout;
031: import java.awt.event.WindowAdapter;
032: import java.awt.event.WindowEvent;
033: import java.util.Iterator;
034: import java.util.Collection;
035: import java.util.ArrayList;
036: import java.awt.Color;
037:
038: import javax.swing.JComboBox;
039: import javax.swing.JFrame;
040: import javax.swing.JLabel;
041: import javax.swing.JOptionPane;
042: import javax.swing.JPanel;
043: import javax.swing.JPasswordField;
044: import javax.swing.JTextField;
045: import javax.swing.SwingConstants;
046: import javax.swing.ImageIcon;
047: import java.awt.Toolkit;
048:
049: public class Manager extends JPanel {
050:
051: static java.util.ResourceBundle resource = java.util.ResourceBundle
052: .getBundle("resources.Traduction")/*#BundleType=List*/;
053:
054: String url = null, host = null;
055: int port;
056: String userName = null;
057: String userPassword = null;
058: Collection projects = new ArrayList();
059: JProjectList projectList = null;
060: final JFrame p = new JFrame();
061: BonitaClient soapclient;
062: public final static String imageBase = "images/";
063: public final static ImageIcon icon = new ImageIcon(Thread
064: .currentThread().getContextClassLoader().getResource(
065: imageBase + "icon.png"));
066:
067: public Manager(String userName, String userPassword)
068: throws Exception {
069:
070: this .userName = userName;
071: this .userPassword = userPassword;
072:
073: // Obtains bonita host and port
074: url = System.getProperty("bonita.host");
075:
076: host = url.substring(7);
077: int point = host.indexOf(":");
078: url = host;
079: this .host = host.substring(0, point);
080: int portPoint = url.indexOf("/");
081: if (portPoint != -1)
082: this .port = new Integer(url.substring(point + 1, portPoint))
083: .intValue(); // ant application
084: else
085: this .port = new Integer(url.substring(point + 1))
086: .intValue(); //Java Web Start application
087:
088: BonitaClient soapclient = new BonitaClient(host, port,
089: "/bonita_ws/services/");
090: soapclient.login(userName, userPassword);
091: this .soapclient = soapclient;
092: buildView();
093: }
094:
095: public void buildView() throws Exception {
096: String subscription = "(event = 'addUserProject' AND userName = '"
097: + this .userName + "')" + " OR";
098:
099: Collection allProjects = soapclient.getProjects();
100: Iterator i = allProjects.iterator();
101: while (i.hasNext()) {
102: String name = (String) i.next();
103: subscription = subscription + " projectName = '" + name
104: + "' OR";
105: if (!name.matches(".*_instance.*"))
106: this .projects.add(name);
107: }
108:
109: MListener ml = MListener.getInstance(this .userName,
110: this .userPassword, this .host, this .port);
111: ml.subscription(subscription.substring(0,
112: subscription.length() - 3));
113: projectList = new JProjectList(this .soapclient, ml,
114: this .projects);
115: projectList.setBackground(new Color(177, 177, 251));
116: JTodoList todoList = new JTodoList(this .soapclient, ml);
117: todoList.setBackground(new Color(177, 177, 251));
118: JActivityList activityList = new JActivityList(this .soapclient,
119: ml);
120: activityList.setBackground(new Color(177, 177, 251));
121:
122: projectList.addPropertyChangeListener(JProjectList.SELECTED,
123: todoList);
124: projectList.addPropertyChangeListener(JProjectList.SELECTED,
125: activityList);
126:
127: java.net.URL iconUrl = Thread.currentThread()
128: .getContextClassLoader().getResource(
129: imageBase + "icon.png");
130: p.setIconImage(Toolkit.getDefaultToolkit().getImage(iconUrl));
131:
132: hero.client.manager.Menubar menubar = new hero.client.manager.Menubar(
133: this );
134: menubar.setBackground(new Color(153, 153, 255));
135: p.setJMenuBar(menubar);
136: Container c = p.getContentPane();
137: c.setLayout(new GridLayout(3, 1));
138: c.add(projectList);
139: c.add(todoList);
140: c.add(activityList);
141:
142: p.addWindowListener(new WindowAdapter() {
143: public void windowClosing(WindowEvent e) {
144: try {
145: JMSServicesClient jms = JMSServicesClient
146: .getInstance();
147: jms.closeConnection();
148: System.exit(0);
149: } catch (Exception ex) {
150: }
151: }
152: });
153:
154: p.setSize(new Dimension(150, 400));
155:
156: p.setTitle(resource.getString("manager.activity") + userName);
157: p.pack();
158: p.show();
159: }
160:
161: public void CloneProject() {
162: JPanel jp = new JPanel();
163:
164: Object[] possibleValues = this .projects.toArray();
165: JComboBox projectNames = new JComboBox(possibleValues);
166: jp.setLayout(new GridLayout(0, 2));
167: jp.add(new JLabel(resource.getString("manager.choose"),
168: SwingConstants.LEFT));
169: jp.add(projectNames);
170:
171: JTextField newProject = new JTextField("", 0);
172: jp.setLayout(new GridLayout(0, 2));
173: jp.add(new JLabel(resource.getString("manager.create.name2"),
174: SwingConstants.LEFT));
175: jp.add(newProject);
176:
177: int cloneOption = JOptionPane.showConfirmDialog(null, jp,
178: resource.getString("manager.create.clone"),
179: JOptionPane.OK_CANCEL_OPTION,
180: JOptionPane.QUESTION_MESSAGE, icon);
181: if (cloneOption != JOptionPane.CANCEL_OPTION) {
182: while ((newProject.getText()).equals("")
183: && cloneOption != JOptionPane.CANCEL_OPTION) {
184: JOptionPane.showMessageDialog(null, resource
185: .getString("manager.create.name"), resource
186: .getString("manager.create.clone"),
187: JOptionPane.INFORMATION_MESSAGE, icon);
188: cloneOption = JOptionPane.showConfirmDialog(null, jp,
189: resource.getString("manager.create.clone"),
190: JOptionPane.OK_CANCEL_OPTION,
191: JOptionPane.QUESTION_MESSAGE, icon);
192: }
193: if (cloneOption != JOptionPane.CANCEL_OPTION) {
194: try {
195: if (exists(newProject.getText())) {
196: JOptionPane
197: .showMessageDialog(
198: null,
199: resource
200: .getString("manager.create.exist"),
201: resource
202: .getString("manager.create.clone"),
203: JOptionPane.INFORMATION_MESSAGE,
204: icon);
205: } else {
206: soapclient.cloneProject((String) projectNames
207: .getSelectedItem(), newProject
208: .getText());
209: this .projects.clear();
210: Collection allProjects = soapclient
211: .getProjects();
212: Iterator i = allProjects.iterator();
213: while (i.hasNext()) {
214: String name = (String) i.next();
215: if (!name.matches(".*_instance.*"))
216: this .projects.add(name);
217: }
218: }
219: } catch (Exception e) {
220: e.printStackTrace();
221: JOptionPane.showMessageDialog(null, resource
222: .getString("manager.create.exist"),
223: resource.getString("manager.create.clone"),
224: JOptionPane.INFORMATION_MESSAGE, icon);
225: }
226: }
227: }
228: }
229:
230: public void InstantiateProject() {
231: JPanel jp = new JPanel();
232:
233: Object[] possibleValues = this .projects.toArray();
234: JComboBox projectNames = new JComboBox(possibleValues);
235: jp.setLayout(new GridLayout(0, 2));
236: jp.add(new JLabel(resource.getString("manager.choose"),
237: SwingConstants.LEFT));
238: jp.add(projectNames);
239:
240: int instOption = JOptionPane.showConfirmDialog(null, jp,
241: resource.getString("manager.create.inst"),
242: JOptionPane.OK_CANCEL_OPTION,
243: JOptionPane.QUESTION_MESSAGE, icon);
244: if (instOption != JOptionPane.CANCEL_OPTION) {
245: try {
246: soapclient.instantiateProject((String) projectNames
247: .getSelectedItem());
248: this .projects.clear();
249: Collection allProjects = soapclient.getProjects();
250: Iterator i = allProjects.iterator();
251: while (i.hasNext()) {
252: String name = (String) i.next();
253: if (!name.matches(".*_instance.*"))
254: this .projects.add(name);
255: }
256: } catch (Exception e) {
257: e.printStackTrace();
258: JOptionPane.showMessageDialog(null, resource
259: .getString("manager.inst.error")
260: + ", " + e.getMessage(), resource
261: .getString("manager.create.inst"),
262: JOptionPane.INFORMATION_MESSAGE, icon);
263: }
264: }
265: }
266:
267: private boolean exists(String project) {
268: try {
269: Object[] elems = this .projects.toArray();
270: for (int i = 0; i < elems.length; i++) {
271: if (((String) elems[i]).equalsIgnoreCase(project))
272: return true;
273: }
274: return false;
275: } catch (Exception e) {
276: e.printStackTrace();
277: }
278: return true;
279: }
280:
281: public void NewProject() {
282: projectList.newProject();
283: }
284:
285: static public void main(String[] args) {
286: boolean exit = false;
287: String userName = null;
288: String userPassword = null;
289:
290: if (System.getProperty("user.login") != null
291: && System.getProperty("user.password") != null) {
292: try {
293: userName = System.getProperty("user.login");
294: char[] password = System.getProperty("user.password")
295: .toCharArray();
296: userPassword = new String(password);
297: new Manager(userName, userPassword);
298: } catch (Exception e) {
299: JOptionPane.showMessageDialog(null, resource
300: .getString("manager.login.failed"), resource
301: .getString("manager.login.login"),
302: JOptionPane.INFORMATION_MESSAGE, icon);
303: System.exit(0);
304: }
305: } else {
306: while (!exit) {
307: JPanel jp = new JPanel();
308:
309: JTextField login = new JTextField("", 0);
310: jp.setLayout(new GridLayout(0, 2));
311: jp.add(new JLabel(resource
312: .getString("manager.login.login"),
313: SwingConstants.LEFT));
314: jp.add(login);
315:
316: JPasswordField passwd = new JPasswordField("", 0);
317: jp.setLayout(new GridLayout(0, 2));
318: jp.add(new JLabel(resource
319: .getString("manager.login.password"),
320: SwingConstants.LEFT));
321: jp.add(passwd);
322:
323: try {
324: if (System.getProperty("user.login") != null
325: && System.getProperty("user.password") != null) {
326: userName = System.getProperty("user.login");
327: char[] password = System.getProperty(
328: "user.password").toCharArray();
329: userPassword = new String(password);
330: new Manager(userName, userPassword);
331: exit = true;
332: } else {
333:
334: int option = JOptionPane.showConfirmDialog(
335: null, jp, resource
336: .getString("manager.login"),
337: JOptionPane.OK_CANCEL_OPTION,
338: JOptionPane.QUESTION_MESSAGE, icon);
339: if (option != JOptionPane.CANCEL_OPTION) {
340: while (((login.getText()).equals("") || (passwd
341: .getPassword()).length == 0)
342: && option != JOptionPane.CANCEL_OPTION) {
343: JOptionPane
344: .showMessageDialog(
345: null,
346: null,
347: resource
348: .getString("manager.login.relogin"),
349: JOptionPane.QUESTION_MESSAGE,
350: icon);
351: option = JOptionPane
352: .showConfirmDialog(
353: null,
354: jp,
355: resource
356: .getString("manager.login"),
357: JOptionPane.OK_CANCEL_OPTION,
358: JOptionPane.QUESTION_MESSAGE,
359: icon);
360: }
361: if (option != JOptionPane.CANCEL_OPTION) {
362: userName = (String) login.getText();
363: char[] password = passwd.getPassword();
364: userPassword = new String(password);
365: new Manager(userName, userPassword);
366: exit = true;
367: } else
368: System.exit(0);
369: } else
370: System.exit(0);
371: }
372: } catch (Exception e) {
373: JOptionPane.showMessageDialog(null, resource
374: .getString("manager.login.failed")
375: + ": " + e.getMessage(), resource
376: .getString("manager.login.login"),
377: JOptionPane.QUESTION_MESSAGE, icon);
378: exit = false;
379: }
380: }
381: }
382: }
383: }
|