001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.so6.core.ui;
034:
035: import org.libresource.so6.core.FileLockedException;
036: import org.libresource.so6.core.WorkspaceCorruptedException;
037: import org.libresource.so6.core.WsConnection;
038: import org.libresource.so6.core.client.AuthenticationException;
039: import org.libresource.so6.core.client.ClientI;
040: import org.libresource.so6.core.client.ClientIServletImpl;
041: import org.libresource.so6.core.client.LocalException;
042: import org.libresource.so6.core.client.ServerException;
043: import org.libresource.so6.core.client.WorkspaceListener;
044: import org.libresource.so6.core.engine.log.LogHandler;
045: import org.libresource.so6.core.engine.log.LogPrinter;
046: import org.libresource.so6.core.engine.log.monitoring.ProgressView;
047: import org.libresource.so6.core.exec.ui.tools.CheckWscParameters;
048: import org.libresource.so6.core.ui.util.Wizard;
049: import org.libresource.so6.core.ui.util.WizardComponent;
050:
051: import java.awt.BorderLayout;
052: import java.awt.Color;
053: import java.awt.Toolkit;
054:
055: import java.util.Properties;
056: import java.util.logging.Handler;
057: import java.util.logging.LogRecord;
058: import java.util.logging.Logger;
059:
060: import javax.swing.JFrame;
061: import javax.swing.JOptionPane;
062: import javax.swing.JPanel;
063: import javax.swing.JScrollPane;
064: import javax.swing.JTextArea;
065:
066: /**
067: * @author smack
068: */
069: public class BasicProgressView extends JPanel implements
070: WizardComponent, LogPrinter {
071: private ProgressView view;
072: private WsConnection wsc;
073: private String wsPath;
074:
075: //
076: protected JTextArea log = null;
077: protected JFrame logFrame = null;
078: private Wizard wizard;
079:
080: public BasicProgressView(String wsPath) throws Exception {
081: super (new BorderLayout());
082: this .wsPath = wsPath;
083: wsc = new WsConnection(wsPath);
084:
085: /*
086: // add the chek params and read password
087: CheckWscParameters checkWscParameters = new CheckWscParameters(wsc.getProperty(ClientIServletImpl.SO6_SERVICE_URL),
088: wsc.getProperty(ClientI.SO6_QUEUE_ID), wsc.getProperty(wsc.PATH), wsc.getProperty(ClientI.SO6_LOGIN), wsc.getProperty(wsc.WS_NAME),
089: wsc.getProperty(wsc.SYNC_CLIENT_NAME), null);
090: // get props
091: Properties props = checkWscParameters.getWscProps();
092: String serviceUrl = (String) props.get("serviceUrl");
093: String basePath = (String) props.get("basePath");
094: String wsName = (String) props.get("wsName");
095: String queueId = (String) props.get("synchronizerURI");
096: String login = (String) props.get("login");
097: String password = (String) props.get("password");
098: // save props
099: Properties newProps = new Properties();
100: newProps.put(ClientIServletImpl.SO6_SERVICE_URL, serviceUrl);
101: newProps.put(ClientI.SO6_QUEUE_ID, queueId);
102: newProps.put(wsc.PATH, basePath);
103: newProps.put(ClientI.SO6_LOGIN, login);
104: newProps.put(wsc.WS_NAME, wsName);
105: newProps.put(ClientI.SO6_PASSWORD, password);
106: wsc.updateProp(newProps);
107: wsc.save();
108: */
109: //
110: log = new JTextArea();
111: log.setEditable(false);
112: logFrame = new JFrame("Execution log");
113: logFrame.getContentPane().add(new JScrollPane(log));
114: logFrame.setSize(400, 200);
115: logFrame.setLocation(((int) Toolkit.getDefaultToolkit()
116: .getScreenSize().getWidth() - logFrame.getWidth()) / 2,
117: (((int) Toolkit.getDefaultToolkit().getScreenSize()
118: .getHeight() - getHeight()) / 2) + 110);
119:
120: //
121: view = new ProgressView();
122: add(view, BorderLayout.CENTER);
123: }
124:
125: public void setStyle(Color back, Color forground) {
126: view.setStyle(back, forground);
127: }
128:
129: public void publish(LogRecord record) {
130: printMessage(record.getMessage());
131: }
132:
133: public void printMessage(String message) {
134: log.append(message + "\n");
135: log.setCaretPosition(log.getText().length());
136: }
137:
138: public void printError(Exception e) {
139: printMessage("###\n" + e.getMessage() + "\n###");
140:
141: StackTraceElement[] stack = e.getStackTrace();
142:
143: for (int i = 0; i < stack.length; i++) {
144: printMessage("# " + stack[i].getClassName() + ": line "
145: + stack[i].getLineNumber());
146: }
147: }
148:
149: public void initLog() {
150: Handler[] handler = Logger.getLogger("ui.log").getHandlers();
151:
152: for (int i = 0; i < handler.length; i++) {
153: Logger.getLogger("ui.log").removeHandler(handler[i]);
154: }
155:
156: //
157: Logger.getLogger("ui.log").setUseParentHandlers(false);
158: Logger.getLogger("ui.log").addHandler(new LogHandler(this ));
159: }
160:
161: public void showLog() {
162: logFrame.setVisible(true);
163: }
164:
165: public void hideLog() {
166: logFrame.setVisible(false);
167: }
168:
169: public boolean isLogShow() {
170: return logFrame.isVisible();
171: }
172:
173: public void update() {
174: initLog();
175:
176: try {
177: wsc.getClient();
178: wsc.update();
179:
180: if (wsc.getClient() instanceof WorkspaceListener) {
181: ((WorkspaceListener) wsc.getClient()).notifyQueue(wsc
182: .getNs());
183: }
184: } catch (AuthenticationException e) {
185: String message = "Authentication error: Invalide login or password.";
186: printMessage(message);
187: printError(e);
188: e.printStackTrace();
189: JOptionPane.showMessageDialog(this , message);
190: } catch (ServerException e) {
191: String message = "Server error: " + e.getMessage();
192: printMessage(message);
193: printError(e);
194: e.printStackTrace();
195: JOptionPane.showMessageDialog(this , message);
196: } catch (LocalException e) {
197: String message = "Local error: " + e.getMessage();
198: printMessage(message);
199: printError(e);
200: e.printStackTrace();
201: JOptionPane.showMessageDialog(this , message);
202: } catch (WorkspaceCorruptedException e) {
203: String message = "<html>Your local workspace is corrupted. <br>Please restore it</html>";
204: printMessage(message);
205: printError(e);
206: e.printStackTrace();
207: JOptionPane.showMessageDialog(this , message);
208: } catch (FileLockedException e) {
209: String message = "<html>"
210: + e.getMessage()
211: + " <br>Please close the application that is locking this file</html>";
212: printMessage(message);
213: printError(e);
214: e.printStackTrace();
215: JOptionPane.showMessageDialog(this , message);
216: } catch (Exception e) {
217: String message = "Forget exception : "
218: + e.getClass().getName();
219: printMessage(message);
220: printError(e);
221: e.printStackTrace();
222: JOptionPane.showMessageDialog(this , message);
223: }
224:
225: printMessage("Update finished");
226:
227: // Print report
228: if (wsc.getReport().length() > 0) {
229: printMessage("\n*** Report ***");
230: printMessage(wsc.getReport());
231: }
232: }
233:
234: public void commit(String comment) {
235: initLog();
236:
237: try {
238: wsc.getClient();
239: wsc.commit(comment);
240:
241: if (wsc.getClient() instanceof WorkspaceListener) {
242: ((WorkspaceListener) wsc.getClient()).notifyQueue(wsc
243: .getNs());
244: }
245: } catch (AuthenticationException e) {
246: String message = "Authentication error: Invalide login or password.";
247: printMessage(message);
248: printError(e);
249: e.printStackTrace();
250: JOptionPane.showMessageDialog(this , message);
251: } catch (ServerException e) {
252: String message = "Server error: " + e.getMessage();
253: printMessage(message);
254: printError(e);
255: e.printStackTrace();
256: JOptionPane.showMessageDialog(this , message);
257: } catch (LocalException e) {
258: String message = "Local error: " + e.getMessage();
259: printMessage(message);
260: printError(e);
261: e.printStackTrace();
262: JOptionPane.showMessageDialog(this , message);
263: } catch (WorkspaceCorruptedException e) {
264: String message = "<html>Your local workspace is corrupted. <br>Please restore it</html>";
265: printMessage(message);
266: printError(e);
267: e.printStackTrace();
268: JOptionPane.showMessageDialog(this , message);
269: } catch (FileLockedException e) {
270: String message = "<html>"
271: + e.getMessage()
272: + " <br>Please close the application that is locking this file</html>";
273: printMessage(message);
274: printError(e);
275: e.printStackTrace();
276: JOptionPane.showMessageDialog(this , message);
277: } catch (Exception e) {
278: String message = "Forget exception : "
279: + e.getClass().getName();
280: printMessage(message);
281: printError(e);
282: e.printStackTrace();
283: JOptionPane.showMessageDialog(this , message);
284: }
285:
286: printMessage("Commit finished");
287:
288: // Print report
289: if (wsc.getReport().length() > 0) {
290: printMessage("\n*** Report ***");
291: printMessage(wsc.getReport());
292: }
293: }
294:
295: public void sendCurrentCompressState() {
296: initLog();
297:
298: try {
299: wsc.getClient();
300: wsc.sendCurrentCompressState();
301: } catch (AuthenticationException e) {
302: String message = "Authentication error: Invalide login or password.";
303: printMessage(message);
304: printError(e);
305: e.printStackTrace();
306: JOptionPane.showMessageDialog(this , message);
307: } catch (ServerException e) {
308: String message = "Server error: " + e.getMessage();
309: printMessage(message);
310: printError(e);
311: e.printStackTrace();
312: JOptionPane.showMessageDialog(this , message);
313: } catch (LocalException e) {
314: String message = "Local error: " + e.getMessage();
315: printMessage(message);
316: printError(e);
317: e.printStackTrace();
318: JOptionPane.showMessageDialog(this , message);
319: } catch (WorkspaceCorruptedException e) {
320: String message = "<html>Your local workspace is corrupted. <br>Please restore it</html>";
321: printMessage(message);
322: printError(e);
323: e.printStackTrace();
324: JOptionPane.showMessageDialog(this , message);
325: } catch (FileLockedException e) {
326: String message = "<html>"
327: + e.getMessage()
328: + " <br>Please close the application that is locking this file</html>";
329: printMessage(message);
330: printError(e);
331: e.printStackTrace();
332: JOptionPane.showMessageDialog(this , message);
333: } catch (Exception e) {
334: String message = "Forget exception : "
335: + e.getClass().getName();
336: printMessage(message);
337: printError(e);
338: e.printStackTrace();
339: JOptionPane.showMessageDialog(this , message);
340: }
341:
342: printMessage("Compress finished");
343:
344: // Print report
345: if (wsc.getReport().length() > 0) {
346: printMessage("\n*** Report ***");
347: printMessage(wsc.getReport());
348: }
349: }
350:
351: public String getReport() {
352: return wsc.getReport();
353: }
354:
355: public void setWizard(Wizard wizard) {
356: this .wizard = wizard;
357: }
358:
359: public Wizard getWizard() {
360: return wizard;
361: }
362: }
|