|
1 /* |
|
2 * Copyright (c) 2007 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 * Base class for document monitors |
|
17 * |
|
18 */ |
|
19 package com.nokia.tracebuilder.utils; |
|
20 |
|
21 import java.util.ArrayList; |
|
22 import java.util.Iterator; |
|
23 |
|
24 import com.nokia.tracebuilder.source.OffsetLength; |
|
25 import com.nokia.tracebuilder.source.SourceDocumentFactory; |
|
26 import com.nokia.tracebuilder.source.SourceDocumentInterface; |
|
27 import com.nokia.tracebuilder.source.SourceDocumentMonitor; |
|
28 import com.nokia.tracebuilder.source.SourceDocumentProcessor; |
|
29 |
|
30 /** |
|
31 * Base class for document monitors. |
|
32 * |
|
33 */ |
|
34 public class DocumentMonitorBase implements SourceDocumentMonitor { |
|
35 |
|
36 /** |
|
37 * Zero offset, zero length |
|
38 */ |
|
39 private static final OffsetLength ZERO_OFFSET_LENGTH = new OffsetLength(); |
|
40 |
|
41 /** |
|
42 * Document factory adapter |
|
43 */ |
|
44 private DocumentFactoryBase factory; |
|
45 |
|
46 /** |
|
47 * Document processor |
|
48 */ |
|
49 private SourceDocumentProcessor processor; |
|
50 |
|
51 /** |
|
52 * List of sources |
|
53 */ |
|
54 private ArrayList<SourceDocumentInterface> sources = new ArrayList<SourceDocumentInterface>(); |
|
55 |
|
56 /* |
|
57 * (non-Javadoc) |
|
58 * |
|
59 * @see com.nokia.tracebuilder.source.SourceDocumentMonitor#getFactory() |
|
60 */ |
|
61 public SourceDocumentFactory getFactory() { |
|
62 if (factory == null) { |
|
63 factory = new DocumentFactoryBase(); |
|
64 } |
|
65 return factory; |
|
66 } |
|
67 |
|
68 /* |
|
69 * (non-Javadoc) |
|
70 * |
|
71 * @see com.nokia.tracebuilder.source.SourceDocumentMonitor#getSelectedSource() |
|
72 */ |
|
73 public SourceDocumentInterface getSelectedSource() { |
|
74 return null; |
|
75 } |
|
76 |
|
77 /* |
|
78 * (non-Javadoc) |
|
79 * |
|
80 * @see com.nokia.tracebuilder.source.SourceDocumentMonitor# |
|
81 * getSelection(com.nokia.tracebuilder.source.SourceDocumentInterface) |
|
82 */ |
|
83 public OffsetLength getSelection(SourceDocumentInterface props) { |
|
84 return ZERO_OFFSET_LENGTH; |
|
85 } |
|
86 |
|
87 /* |
|
88 * (non-Javadoc) |
|
89 * |
|
90 * @see java.lang.Iterable#iterator() |
|
91 */ |
|
92 public Iterator<SourceDocumentInterface> iterator() { |
|
93 return sources.iterator(); |
|
94 } |
|
95 |
|
96 /** |
|
97 * Adds a source to this monitor and notifies the document processor |
|
98 * |
|
99 * @param source |
|
100 * the source to be added |
|
101 */ |
|
102 protected void addSource(SourceDocumentInterface source) { |
|
103 sources.add(source); |
|
104 processor.sourceOpened(source); |
|
105 } |
|
106 |
|
107 /** |
|
108 * Removes a source from this monitor and calls the document processor |
|
109 * |
|
110 * @param source |
|
111 * the source to be removed |
|
112 */ |
|
113 protected void removeSource(SourceDocumentInterface source) { |
|
114 sources.remove(source); |
|
115 processor.sourceClosed(source); |
|
116 } |
|
117 |
|
118 /* |
|
119 * (non-Javadoc) |
|
120 * |
|
121 * @see com.nokia.tracebuilder.source.SourceDocumentMonitor# |
|
122 * isSourceEditable(com.nokia.tracebuilder.source.SourceDocumentInterface) |
|
123 */ |
|
124 public boolean isSourceEditable(SourceDocumentInterface selectedSource) { |
|
125 return false; |
|
126 } |
|
127 |
|
128 /* |
|
129 * (non-Javadoc) |
|
130 * |
|
131 * @see com.nokia.tracebuilder.source.SourceDocumentMonitor#setFocus() |
|
132 */ |
|
133 public void setFocus() { |
|
134 } |
|
135 |
|
136 /* |
|
137 * (non-Javadoc) |
|
138 * |
|
139 * @see com.nokia.tracebuilder.source.SourceDocumentMonitor# |
|
140 * startMonitor(com.nokia.tracebuilder.source.SourceDocumentProcessor) |
|
141 */ |
|
142 public void startMonitor(SourceDocumentProcessor processor) { |
|
143 this.processor = processor; |
|
144 } |
|
145 |
|
146 /* |
|
147 * (non-Javadoc) |
|
148 * |
|
149 * @see com.nokia.tracebuilder.source.SourceDocumentMonitor#stopMonitor() |
|
150 */ |
|
151 public void stopMonitor() { |
|
152 for (SourceDocumentInterface document : sources) { |
|
153 processor.sourceClosed(document); |
|
154 } |
|
155 sources.clear(); |
|
156 processor = null; |
|
157 } |
|
158 |
|
159 /** |
|
160 * Gets the source processor |
|
161 * |
|
162 * @return the processor |
|
163 */ |
|
164 protected SourceDocumentProcessor getProcessor() { |
|
165 return processor; |
|
166 } |
|
167 |
|
168 } |