Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: de8dfb8afb1cbbe10dafa171f82e2be2ab642a81 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*******************************************************************************
 * Copyright (c) 2008 ARM Limited and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * ARM Limited - Initial API and implementation
 *******************************************************************************/

package org.eclipse.cdt.debug.internal.ui.disassembly.viewer;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.cdt.debug.internal.ui.disassembly.editor.DisassemblyEditorInput;
import org.eclipse.cdt.debug.internal.ui.disassembly.editor.DisassemblyEditorPresentation;
import org.eclipse.cdt.debug.ui.disassembly.IDocumentPresentation;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.source.AnnotationModel;
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.IElementStateListener;

/**
 * org.eclipse.cdt.debug.internal.ui.disassembly.viewer.DisassemblyDocumentProvider: 
 * //TODO Add description.
 */
public class DisassemblyDocumentProvider implements IDocumentProvider {

    class DocumentInfo {
        
        private VirtualDocument fDocument;
        private IAnnotationModel fAnnotationModel;
        private IDocumentPresentation fPresentation;

        DocumentInfo( VirtualDocument document, IAnnotationModel annotationModel, IDocumentPresentation presentation ) {
            fDocument = document;
            fAnnotationModel = annotationModel;
            fPresentation = presentation;
        }

        VirtualDocument getDocument() {
            return fDocument;
        }

        IAnnotationModel getAnnotationModel() {
            return fAnnotationModel;
        }

        IDocumentPresentation getPresentation() {
            return fPresentation;
        }
        
        void dispose() {
            fPresentation.dispose();
            fPresentation = null;
            fAnnotationModel = null;
            fDocument.dispose();
            fDocument = null;
        }
    }

    private Map<Object, DocumentInfo> fDocumentInfos;

    public DisassemblyDocumentProvider() {
        fDocumentInfos = new HashMap<Object, DocumentInfo>();
    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.texteditor.IDocumentProvider#aboutToChange(java.lang.Object)
     */
    public void aboutToChange( Object element ) {
    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.texteditor.IDocumentProvider#addElementStateListener(org.eclipse.ui.texteditor.IElementStateListener)
     */
    public void addElementStateListener( IElementStateListener listener ) {
        // TODO Auto-generated method stub

    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.texteditor.IDocumentProvider#canSaveDocument(java.lang.Object)
     */
    public boolean canSaveDocument( Object element ) {
        return false;
    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.texteditor.IDocumentProvider#changed(java.lang.Object)
     */
    public void changed( Object element ) {
    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.texteditor.IDocumentProvider#connect(java.lang.Object)
     */
    public synchronized void connect( Object element ) throws CoreException {
        Object disassemblyContext = ((DisassemblyEditorInput)element).getDisassemblyContext();
        if ( fDocumentInfos.get( disassemblyContext ) == null ) {
            IDocumentPresentation presentation = createDocumentPresentation( disassemblyContext );
            IAnnotationModel annotationModel = createAnnotationModel();
            VirtualDocument document = createDocument( disassemblyContext, presentation, annotationModel );
            fDocumentInfos.put( disassemblyContext, new DocumentInfo( document, annotationModel, presentation ) );
        }
    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.texteditor.IDocumentProvider#disconnect(java.lang.Object)
     */
    public synchronized void disconnect( Object element ) {
        Object disassemblyContext = ((DisassemblyEditorInput)element).getDisassemblyContext();
        DocumentInfo info = fDocumentInfos.remove( disassemblyContext );
        if ( info != null ) {
            info.dispose();
        }
    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.texteditor.IDocumentProvider#getAnnotationModel(java.lang.Object)
     */
    public IAnnotationModel getAnnotationModel( Object element ) {
        Object disassemblyContext = ((DisassemblyEditorInput)element).getDisassemblyContext();
        DocumentInfo info = fDocumentInfos.get( disassemblyContext );
        return ( info != null ) ? info.getAnnotationModel() : null;
    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.texteditor.IDocumentProvider#getDocument(java.lang.Object)
     */
    public IDocument getDocument( Object element ) {
        Object disassemblyContext = ((DisassemblyEditorInput)element).getDisassemblyContext();        
        DocumentInfo info = fDocumentInfos.get( disassemblyContext );
        return ( info != null ) ? info.getDocument() : null;
    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.texteditor.IDocumentProvider#getModificationStamp(java.lang.Object)
     */
    public long getModificationStamp( Object element ) {
        // TODO Auto-generated method stub
        return 0;
    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.texteditor.IDocumentProvider#getSynchronizationStamp(java.lang.Object)
     */
    public long getSynchronizationStamp( Object element ) {
        // TODO Auto-generated method stub
        return 0;
    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.texteditor.IDocumentProvider#isDeleted(java.lang.Object)
     */
    public boolean isDeleted( Object element ) {
        return false;
    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.texteditor.IDocumentProvider#mustSaveDocument(java.lang.Object)
     */
    public boolean mustSaveDocument( Object element ) {
        return false;
    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.texteditor.IDocumentProvider#removeElementStateListener(org.eclipse.ui.texteditor.IElementStateListener)
     */
    public void removeElementStateListener( IElementStateListener listener ) {
        // TODO Auto-generated method stub

    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.texteditor.IDocumentProvider#resetDocument(java.lang.Object)
     */
    public void resetDocument( Object element ) throws CoreException {
        // TODO Auto-generated method stub

    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.texteditor.IDocumentProvider#saveDocument(org.eclipse.core.runtime.IProgressMonitor, java.lang.Object, org.eclipse.jface.text.IDocument, boolean)
     */
    public void saveDocument( IProgressMonitor monitor, Object element, IDocument document, boolean overwrite ) throws CoreException {
        // TODO Auto-generated method stub

    }

    public void dispose() {
        for( DocumentInfo info : fDocumentInfos.values() ) {
            info.dispose();
        }
        fDocumentInfos.clear();
    }

    public IDocumentPresentation getDocumentPresentation( Object element ) {
        Object disassemblyContext = ((DisassemblyEditorInput)element).getDisassemblyContext();
        DocumentInfo info = fDocumentInfos.get( disassemblyContext );
        return ( info != null ) ? info.getPresentation() : null;
    }

    private IAnnotationModel createAnnotationModel() {
        return new AnnotationModel();
    }

    private VirtualDocument createDocument( Object disassemblyContext, IDocumentPresentation presentationContext, IAnnotationModel annotationModel ) {
        return new VirtualDocument( annotationModel, presentationContext, disassemblyContext );
    }

    private IDocumentPresentation createDocumentPresentation( Object context ) {
        return new DisassemblyEditorPresentation();
    }
}

Back to the top