KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > compare > structuremergeviewer > SharedDocumentAdapterWrapper


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.compare.structuremergeviewer;
12
13 import org.eclipse.compare.ISharedDocumentAdapter;
14 import org.eclipse.compare.SharedDocumentAdapter;
15 import org.eclipse.compare.internal.Utilities;
16 import org.eclipse.core.runtime.*;
17 import org.eclipse.jface.text.IDocument;
18 import org.eclipse.ui.IEditorInput;
19 import org.eclipse.ui.texteditor.IDocumentProvider;
20
21 /**
22  * An implementation of {@link ISharedDocumentAdapter} that wraps another
23  * shared document adapter.
24  * <p>
25  * Clients may subclass this class.
26  * </p>
27  * @since 3.3
28  */

29 public class SharedDocumentAdapterWrapper implements ISharedDocumentAdapter {
30
31     private ISharedDocumentAdapter wrappedAdapter;
32     
33     /**
34      * Helper method that returns the shared document adapter for the
35      * given typed element or <code>null</code> if there isn't one.
36      * @param element the typed element
37      * @return the shared document adapter for the given typed element
38      * or <code>null</code>
39      */

40     public static ISharedDocumentAdapter getAdapter(Object JavaDoc element) {
41         return (ISharedDocumentAdapter)Utilities.getAdapter(element, ISharedDocumentAdapter.class, true);
42     }
43     
44     /**
45      * Create a shared document adapter that wraps the given adapter.
46      * @param wrappedAdapter the wrapped adapter
47      */

48     public SharedDocumentAdapterWrapper(ISharedDocumentAdapter wrappedAdapter) {
49         super();
50         this.wrappedAdapter = wrappedAdapter;
51     }
52     
53     /* (non-Javadoc)
54      * @see org.eclipse.compare.ISharedDocumentAdapter#connect(org.eclipse.ui.texteditor.IDocumentProvider, org.eclipse.ui.IEditorInput)
55      */

56     public void connect(IDocumentProvider provider, IEditorInput documentKey)
57             throws CoreException {
58         wrappedAdapter.connect(provider, documentKey);
59     }
60
61     /* (non-Javadoc)
62      * @see org.eclipse.compare.ISharedDocumentAdapter#disconnect(org.eclipse.ui.texteditor.IDocumentProvider, org.eclipse.ui.IEditorInput)
63      */

64     public void disconnect(IDocumentProvider provider, IEditorInput documentKey) {
65         wrappedAdapter.disconnect(provider, documentKey);
66     }
67
68     /* (non-Javadoc)
69      * @see org.eclipse.compare.ISharedDocumentAdapter#getDocumentKey(java.lang.Object)
70      */

71     public IEditorInput getDocumentKey(Object JavaDoc element) {
72         return wrappedAdapter.getDocumentKey(element);
73     }
74
75     /* (non-Javadoc)
76      * @see org.eclipse.compare.ISharedDocumentAdapter#saveDocument(org.eclipse.ui.texteditor.IDocumentProvider, org.eclipse.ui.IEditorInput, org.eclipse.jface.text.IDocument, boolean, org.eclipse.core.runtime.IProgressMonitor)
77      */

78     public void flushDocument(IDocumentProvider provider,
79             IEditorInput documentKey, IDocument document, boolean overwrite) throws CoreException {
80         wrappedAdapter.flushDocument(provider, documentKey, document, overwrite);
81     }
82
83     /**
84      * Return the wrapped adapter.
85      * @return the wrapped adapter
86      */

87     public final ISharedDocumentAdapter getWrappedAdapter() {
88         return wrappedAdapter;
89     }
90
91     /* (non-Javadoc)
92      * @see org.eclipse.compare.ISharedDocumentAdapter#disconnect(java.lang.Object)
93      */

94     public void disconnect(Object JavaDoc element) {
95         IEditorInput input = getDocumentKey(element);
96         if (input == null)
97             return;
98         IDocumentProvider provider = SharedDocumentAdapter.getDocumentProvider(input);
99         if (provider == null)
100             return;
101         disconnect(provider, input);
102     }
103
104 }
105
Popular Tags