|
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 * Listener interface for source file changes |
|
17 * |
|
18 */ |
|
19 package com.nokia.tracebuilder.eclipse; |
|
20 |
|
21 import org.eclipse.jface.text.DocumentEvent; |
|
22 import org.eclipse.jface.text.IDocumentListener; |
|
23 |
|
24 import com.nokia.tracebuilder.engine.TraceBuilderConfiguration; |
|
25 import com.nokia.tracebuilder.engine.TraceBuilderGlobals; |
|
26 |
|
27 /** |
|
28 * Listener interface for source file changes |
|
29 * |
|
30 */ |
|
31 final class JFaceSourceChangeListener implements IDocumentListener { |
|
32 |
|
33 /** |
|
34 * Workbench monitor |
|
35 */ |
|
36 private WorkbenchEditorMonitor monitor; |
|
37 |
|
38 /** |
|
39 * Source to be monitored |
|
40 */ |
|
41 private JFaceDocumentWrapper source; |
|
42 |
|
43 /** |
|
44 * Constructor |
|
45 * |
|
46 * @param monitor |
|
47 * the workbench monitor |
|
48 * @param source |
|
49 * the observed source |
|
50 */ |
|
51 JFaceSourceChangeListener(WorkbenchEditorMonitor monitor, |
|
52 JFaceDocumentWrapper source) { |
|
53 this.monitor = monitor; |
|
54 this.source = source; |
|
55 } |
|
56 |
|
57 /* |
|
58 * (non-Javadoc) |
|
59 * |
|
60 * @see org.eclipse.jface.text.IDocumentListener# |
|
61 * documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent) |
|
62 */ |
|
63 public void documentAboutToBeChanged(DocumentEvent event) { |
|
64 try { |
|
65 monitor.sourceAboutToBeChanged(source, event.getOffset(), event |
|
66 .getLength(), event.getText()); |
|
67 } catch (Exception e) { |
|
68 if (TraceBuilderConfiguration.ASSERTIONS_ENABLED) { |
|
69 TraceBuilderGlobals.getEvents().postCriticalAssertionFailed( |
|
70 "Document change preprocessor failure", e); //$NON-NLS-1$ |
|
71 } |
|
72 } |
|
73 } |
|
74 |
|
75 /* |
|
76 * (non-Javadoc) |
|
77 * |
|
78 * @see org.eclipse.jface.text.IDocumentListener# |
|
79 * documentChanged(org.eclipse.jface.text.DocumentEvent) |
|
80 */ |
|
81 public void documentChanged(DocumentEvent event) { |
|
82 try { |
|
83 monitor.sourceChanged(source, event.getOffset(), event.getLength(), |
|
84 event.getText()); |
|
85 } catch (Exception e) { |
|
86 if (TraceBuilderConfiguration.ASSERTIONS_ENABLED) { |
|
87 TraceBuilderGlobals.getEvents().postCriticalAssertionFailed( |
|
88 "Document change processor failure", e); //$NON-NLS-1$ |
|
89 } |
|
90 } |
|
91 } |
|
92 } |