A massive organize imports and formatting of the sources using default Eclipse code...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / BecomeWorkingCopyOperation.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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.internal.core;
12
13 import net.sourceforge.phpdt.core.IJavaElement;
14 import net.sourceforge.phpdt.core.IJavaElementDelta;
15 import net.sourceforge.phpdt.core.IProblemRequestor;
16 import net.sourceforge.phpdt.core.JavaModelException;
17
18 /**
19  * Switch and ICompilationUnit to working copy mode and signal the working copy
20  * addition through a delta.
21  */
22 public class BecomeWorkingCopyOperation extends JavaModelOperation {
23
24         IProblemRequestor problemRequestor;
25
26         /*
27          * Creates a BecomeWorkingCopyOperation for the given working copy.
28          * perOwnerWorkingCopies map is not null if the working copy is a shared
29          * working copy.
30          */
31         public BecomeWorkingCopyOperation(CompilationUnit workingCopy,
32                         IProblemRequestor problemRequestor) {
33                 super(new IJavaElement[] { workingCopy });
34                 this.problemRequestor = problemRequestor;
35         }
36
37         protected void executeOperation() throws JavaModelException {
38
39                 // open the working copy now to ensure contents are that of the current
40                 // state of this element
41                 CompilationUnit workingCopy = getWorkingCopy();
42                 JavaModelManager.getJavaModelManager().getPerWorkingCopyInfo(
43                                 workingCopy, true/* create if needed */, true/* record usage */,
44                                 this.problemRequestor);
45                 workingCopy.openWhenClosed(workingCopy.createElementInfo(),
46                                 this.progressMonitor);
47
48                 if (!workingCopy.isPrimary()) {
49                         // report added java delta for a non-primary working copy
50                         JavaElementDelta delta = new JavaElementDelta(this.getJavaModel());
51                         delta.added(workingCopy);
52                         addDelta(delta);
53                 } else {
54                         if (workingCopy.getResource().isAccessible()) {
55                                 // report a F_PRIMARY_WORKING_COPY change delta for a primary
56                                 // working copy
57                                 JavaElementDelta delta = new JavaElementDelta(this
58                                                 .getJavaModel());
59                                 delta.changed(workingCopy,
60                                                 IJavaElementDelta.F_PRIMARY_WORKING_COPY);
61                                 addDelta(delta);
62                         } else {
63                                 // report an ADDED delta
64                                 JavaElementDelta delta = new JavaElementDelta(this
65                                                 .getJavaModel());
66                                 delta.added(workingCopy,
67                                                 IJavaElementDelta.F_PRIMARY_WORKING_COPY);
68                                 addDelta(delta);
69                         }
70                 }
71
72                 this.resultElements = new IJavaElement[] { workingCopy };
73         }
74
75         /*
76          * Returns the working copy this operation is working on.
77          */
78         protected CompilationUnit getWorkingCopy() {
79                 return (CompilationUnit) getElementToProcess();
80         }
81
82         /*
83          * @see JavaModelOperation#isReadOnly
84          */
85         public boolean isReadOnly() {
86                 return true;
87         }
88
89 }