Organized imports
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / IOpenable.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.core;
12
13 import org.eclipse.core.runtime.IProgressMonitor;
14
15
16 /**
17  * Common protocol for Java elements that must be opened before they can be 
18  * navigated or modified. Opening a textual element (such as a compilation unit)
19  * involves opening a buffer on its contents.  While open, any changes to the buffer
20  * can be reflected in the element's structure; 
21  * see <code>isConsistent</code> and <code>makeConsistent(IProgressMonitor)</code>.
22  * <p>
23  * To reduce complexity in clients, elements are automatically opened
24  * by the Java model as element properties are accessed. The Java model maintains
25  * an LRU cache of open elements, and automatically closes elements as they
26  * are swapped out of the cache to make room for other elements. Elements with
27  * unsaved changes are never removed from the cache, and thus, if the client
28  * maintains many open elements with unsaved
29  * changes, the LRU cache can grow in size (in this case the cache is not
30  * bounded). However, as elements are saved, the cache will shrink back to its
31  * original bounded size.
32  * </p>
33  * <p>
34  * To open an element, all openable parent elements must be open.
35  * The Java model automatically opens parent elements, as it automatically opens elements.
36  * Opening an element may provide access to direct children and other descendants,
37  * but does not automatically open any descendents which are themselves <code>IOpenable</code>.
38  * For example, opening a compilation unit provides access to all its constituent elements,
39  * but opening a package fragment does not open all compilation units in the package fragment.
40  * </p>
41  * <p>
42  * This interface is not intended to be implemented by clients.
43  * </p>
44  */
45 public interface IOpenable {
46
47 /**
48  * Closes this element and its buffer (if any).
49  * Closing an element which is not open has no effect.
50  *
51  * <p>Note: although <code>close</code> is exposed in the API, clients are
52  * not expected to open and close elements - the Java model does this automatically
53  * as elements are accessed.
54  *
55  * @exception JavaModelException if an error occurs closing this element
56  */
57 public void close() throws JavaModelException;
58 /**
59  * Returns the buffer opened for this element, or <code>null</code>
60  * if this element does not have a buffer.
61  *
62  * @exception JavaModelException if this element does not exist or if an
63  *              exception occurs while accessing its corresponding resource.
64  * @return the buffer opened for this element, or <code>null</code>
65  * if this element does not have a buffer
66  */
67 public IBuffer getBuffer() throws JavaModelException;
68 /**
69  * Returns <code>true</code> if this element is open and:
70  * <ul>
71  * <li>its buffer has unsaved changes, or
72  * <li>one of its descendants has unsaved changes, or
73  * <li>a working copy has been created on one of this
74  * element's children and has not yet destroyed
75  * </ul>
76  *
77  * @exception JavaModelException if this element does not exist or if an
78  *              exception occurs while accessing its corresponding resource.
79  * @return <code>true</code> if this element is open and:
80  * <ul>
81  * <li>its buffer has unsaved changes, or
82  * <li>one of its descendants has unsaved changes, or
83  * <li>a working copy has been created on one of this
84  * element's children and has not yet destroyed
85  * </ul>
86  */
87 boolean hasUnsavedChanges() throws JavaModelException;
88 /**
89  * Returns whether the element is consistent with its underlying resource or buffer.
90  * The element is consistent when opened, and is consistent if the underlying resource
91  * or buffer has not been modified since it was last consistent.
92  *
93  * <p>NOTE: Child consistency is not considered. For example, a package fragment
94  * responds <code>true</code> when it knows about all of its
95  * compilation units present in its underlying folder. However, one or more of
96  * the compilation units could be inconsistent.
97  *
98  * @exception JavaModelException if this element does not exist or if an
99  *              exception occurs while accessing its corresponding resource.
100  * @return true if the element is consistent with its underlying resource or buffer, false otherwise.
101  * @see IOpenable#makeConsistent
102  */
103 boolean isConsistent() throws JavaModelException;
104 /**
105  * Returns whether this openable is open. This is a handle-only method.
106  * @return true if this openable is open, false otherwise
107  */
108 boolean isOpen();
109 /**
110  * Opens this element and all parent elements that are not already open.
111  * For compilation units, a buffer is opened on the contents of the underlying resource.
112  *
113  * <p>Note: although <code>open</code> is exposed in the API, clients are
114  * not expected to open and close elements - the Java model does this automatically
115  * as elements are accessed.
116  *
117  * @param progress the given progress monitor
118  * @exception JavaModelException if an error occurs accessing the contents
119  *              of its underlying resource. Reasons include:
120  * <ul>
121  *  <li>This Java element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
122  * </ul>
123  */
124 public void open(IProgressMonitor progress) throws JavaModelException;
125 /**
126  * Makes this element consistent with its underlying resource or buffer 
127  * by updating the element's structure and properties as necessary.
128  *
129  * @param progress the given progress monitor
130  * @exception JavaModelException if the element is unable to access the contents
131  *              of its underlying resource. Reasons include:
132  * <ul>
133  *  <li>This Java element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
134  * </ul>
135  * @see IOpenable#isConsistent
136  */
137 void makeConsistent(IProgressMonitor progress) throws JavaModelException;
138 /**
139  * Opens this element and all parent elements that are not already open.
140  * For compilation units, a buffer is opened on the contents of the underlying resource.
141  *
142  * <p>Note: although <code>open</code> is exposed in the API, clients are
143  * not expected to open and close elements - the Java model does this automatically
144  * as elements are accessed.
145  *
146  * @param progress the given progress monitor
147  * @exception JavaModelException if an error occurs accessing the contents
148  *              of its underlying resource. Reasons include:
149  * <ul>
150  *  <li>This Java element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
151  * </ul>
152  */
153 //public void open(IProgressMonitor progress) throws JavaModelException;
154 /**
155  * Saves any changes in this element's buffer to its underlying resource
156  * via a workspace resource operation. This has no effect if the element has no underlying
157  * buffer, or if there are no unsaved changed in the buffer.
158  * <p>
159  * The <code>force</code> parameter controls how this method deals with
160  * cases where the workbench is not completely in sync with the local file system.
161  * If <code>false</code> is specified, this method will only attempt
162  * to overwrite a corresponding file in the local file system provided
163  * it is in sync with the workbench. This option ensures there is no 
164  * unintended data loss; it is the recommended setting.
165  * However, if <code>true</code> is specified, an attempt will be made
166  * to write a corresponding file in the local file system, 
167  * overwriting any existing one if need be.
168  * In either case, if this method succeeds, the resource will be marked 
169  * as being local (even if it wasn't before).
170  * <p>
171  * As a result of this operation, the element is consistent with its underlying 
172  * resource or buffer. 
173  *
174  * @param progress the given progress monitor
175  * @param force it controls how this method deals with
176  * cases where the workbench is not completely in sync with the local file system
177  * @exception JavaModelException if an error occurs accessing the contents
178  *              of its underlying resource. Reasons include:
179  * <ul>
180  *  <li>This Java element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
181  *  <li>This Java element is read-only (READ_ONLY)</li>
182  * </ul>
183  */
184 public void save(IProgressMonitor progress, boolean force) throws JavaModelException;
185
186 }