KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > filebuffers > AbstractFileBuffer


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.core.internal.filebuffers;
12
13 import org.eclipse.core.filesystem.IFileInfo;
14 import org.eclipse.core.filesystem.IFileStore;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IPath;
18 import org.eclipse.core.runtime.IProgressMonitor;
19
20 import org.eclipse.core.filebuffers.FileBuffers;
21 import org.eclipse.core.filebuffers.IFileBuffer;
22 import org.eclipse.core.filebuffers.IStateValidationSupport;
23 import org.eclipse.core.filebuffers.ITextFileBufferManager;
24
25 import org.eclipse.jface.text.IDocumentExtension4;
26
27 /**
28  * @since 3.0
29  */

30 public abstract class AbstractFileBuffer implements IFileBuffer, IStateValidationSupport {
31
32     /**
33      * The element for which the info is stored.
34      * @since 3.3
35      */

36     protected IFileStore fFileStore;
37
38
39     public abstract void create(IPath location, IProgressMonitor monitor) throws CoreException;
40
41     public abstract void connect();
42
43     public abstract void disconnect() throws CoreException;
44
45     /**
46      * Returns whether this file buffer has been disconnected.
47      *
48      * @return <code>true</code> if already disposed, <code>false</code> otherwise
49      * @since 3.1
50      */

51     protected abstract boolean isDisconnected();
52
53     /**
54      * Disposes this file buffer.
55      * This implementation is always empty.
56      * <p>
57      * Subclasses may extend but must call <code>super.dispose()</code>.
58      * <p>
59      *
60      * @since 3.1
61      */

62     protected void dispose() {
63     }
64
65     /*
66      * @see org.eclipse.core.filebuffers.IStateValidationSupport#validationStateAboutToBeChanged()
67      */

68     public void validationStateAboutToBeChanged() {
69         ITextFileBufferManager fileBufferManager= FileBuffers.getTextFileBufferManager();
70         if (fileBufferManager instanceof TextFileBufferManager) {
71             TextFileBufferManager manager= (TextFileBufferManager) fileBufferManager;
72             manager.fireStateChanging(this);
73         }
74     }
75
76     /*
77      * @see org.eclipse.core.filebuffers.IStateValidationSupport#validationStateChangeFailed()
78      */

79     public void validationStateChangeFailed() {
80         ITextFileBufferManager fileBufferManager= FileBuffers.getTextFileBufferManager();
81         if (fileBufferManager instanceof TextFileBufferManager) {
82             TextFileBufferManager manager= (TextFileBufferManager) fileBufferManager;
83             manager.fireStateChangeFailed(this);
84         }
85     }
86
87     /*
88      * @see org.eclipse.core.filebuffers.IFileBuffer#getModificationStamp()
89      */

90     public long getModificationStamp() {
91         IFileInfo info= fFileStore.fetchInfo();
92         return info.exists() ? info.getLastModified() : IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP;
93     }
94
95     /*
96      * @see org.eclipse.core.filebuffers.IFileBuffer#getFileStore()
97      * @since 3.3
98      */

99     public IFileStore getFileStore() {
100         return fFileStore;
101     }
102
103 }
104
Popular Tags