|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.s60tools.hticonnection.util; |
|
19 |
|
20 import org.eclipse.jface.resource.ImageDescriptor; |
|
21 import org.eclipse.swt.widgets.Display; |
|
22 |
|
23 import com.nokia.s60tools.hticonnection.common.ProductInfoRegistry; |
|
24 import com.nokia.s60tools.hticonnection.ui.views.main.LogDocument; |
|
25 import com.nokia.s60tools.util.console.AbstractProductSpecificConsole; |
|
26 |
|
27 /** |
|
28 * Singleton class that offers console printing |
|
29 * services for the HTI API product. All text is printed |
|
30 * first to document and then transferred to console. |
|
31 */ |
|
32 public class HtiApiConsole extends AbstractProductSpecificConsole { |
|
33 |
|
34 /** |
|
35 * Singleton instance of the class. |
|
36 */ |
|
37 static private HtiApiConsole instance = null; |
|
38 /** |
|
39 * Storing log document instance here. |
|
40 */ |
|
41 private static LogDocument log = null; |
|
42 |
|
43 /** |
|
44 * Public accessor method. |
|
45 * @return Singleton instance of the class. |
|
46 */ |
|
47 static public HtiApiConsole getInstance(){ |
|
48 if(instance == null ){ |
|
49 instance = new HtiApiConsole(); |
|
50 log = LogDocument.getInstance(); |
|
51 } |
|
52 return instance; |
|
53 } |
|
54 |
|
55 /** |
|
56 * Private constructor forcing Singleton usage of the class. |
|
57 */ |
|
58 private HtiApiConsole(){ |
|
59 } |
|
60 |
|
61 /* (non-Javadoc) |
|
62 * @see com.nokia.s60tools.util.console.IConsolePrintUtility#println(java.lang.String) |
|
63 */ |
|
64 public void println(String message){ |
|
65 appendText(message); |
|
66 } |
|
67 |
|
68 /* (non-Javadoc) |
|
69 * @see com.nokia.s60tools.util.console.IConsolePrintUtility#println(java.lang.String, int) |
|
70 */ |
|
71 public void println(String message, int messageType){ |
|
72 appendText(message); |
|
73 } |
|
74 |
|
75 /** |
|
76 * Appends text to the end of log. |
|
77 * @param text Appended to the end of log. |
|
78 */ |
|
79 private void appendText(String text){ |
|
80 |
|
81 // Adding new text to log. |
|
82 log.addText(text); |
|
83 |
|
84 // Updating the changes. |
|
85 Runnable updateView = new Runnable(){ |
|
86 public void run() { |
|
87 log.updateDocument(); |
|
88 } |
|
89 }; |
|
90 // UI updates from background threads has to be queued |
|
91 // into UI thread in order not to cause invalid thread access |
|
92 Display.getDefault().asyncExec(updateView); |
|
93 } |
|
94 |
|
95 /* (non-Javadoc) |
|
96 * @see com.nokia.s60tools.util.console.AbstractProductSpecificConsole#getProductConsoleName() |
|
97 */ |
|
98 protected String getProductConsoleName() { |
|
99 return ProductInfoRegistry.getConsoleWindowName(); |
|
100 } |
|
101 |
|
102 /* (non-Javadoc) |
|
103 * @see com.nokia.s60tools.util.console.AbstractProductSpecificConsole#getProductConsoleImageDescriptor() |
|
104 */ |
|
105 protected ImageDescriptor getProductConsoleImageDescriptor() { |
|
106 return null; |
|
107 } |
|
108 } |