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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
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;
19 * Switch and ICompilationUnit to working copy mode and signal the working copy
20 * addition through a delta.
22 public class BecomeWorkingCopyOperation extends JavaModelOperation {
24 IProblemRequestor problemRequestor;
27 * Creates a BecomeWorkingCopyOperation for the given working copy.
28 * perOwnerWorkingCopies map is not null if the working copy is a shared
31 public BecomeWorkingCopyOperation(CompilationUnit workingCopy,
32 IProblemRequestor problemRequestor) {
33 super(new IJavaElement[] { workingCopy });
34 this.problemRequestor = problemRequestor;
37 protected void executeOperation() throws JavaModelException {
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);
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);
54 if (workingCopy.getResource().isAccessible()) {
55 // report a F_PRIMARY_WORKING_COPY change delta for a primary
57 JavaElementDelta delta = new JavaElementDelta(this
59 delta.changed(workingCopy,
60 IJavaElementDelta.F_PRIMARY_WORKING_COPY);
63 // report an ADDED delta
64 JavaElementDelta delta = new JavaElementDelta(this
66 delta.added(workingCopy,
67 IJavaElementDelta.F_PRIMARY_WORKING_COPY);
72 this.resultElements = new IJavaElement[] { workingCopy };
76 * Returns the working copy this operation is working on.
78 protected CompilationUnit getWorkingCopy() {
79 return (CompilationUnit) getElementToProcess();
83 * @see JavaModelOperation#isReadOnly
85 public boolean isReadOnly() {