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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package net.sourceforge.phpeclipse.phpeditor;
15 import java.util.HashMap;
18 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.jface.text.Assert;
22 import org.eclipse.ui.IEditorInput;
24 import net.sourceforge.phpdt.core.ICompilationUnit;
26 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
27 import net.sourceforge.phpdt.ui.IWorkingCopyManagerExtension;
31 * This working copy manager works together with a given compilation unit document provider and
32 * additionally offers to "overwrite" the working copy provided by this document provider.
34 public class WorkingCopyManager implements IWorkingCopyManager, IWorkingCopyManagerExtension {
36 private PHPDocumentProvider fDocumentProvider;
38 private boolean fIsShuttingDown;
41 * Creates a new working copy manager that co-operates with the given
42 * compilation unit document provider.
44 * @param provider the provider
46 public WorkingCopyManager(PHPDocumentProvider provider) {
47 Assert.isNotNull(provider);
48 fDocumentProvider= provider;
52 * @see org.eclipse.jdt.ui.IWorkingCopyManager#connect(org.eclipse.ui.IEditorInput)
54 public void connect(IEditorInput input) throws CoreException {
55 fDocumentProvider.connect(input);
59 * @see org.eclipse.jdt.ui.IWorkingCopyManager#disconnect(org.eclipse.ui.IEditorInput)
61 public void disconnect(IEditorInput input) {
62 fDocumentProvider.disconnect(input);
66 * @see org.eclipse.jdt.ui.IWorkingCopyManager#shutdown()
68 public void shutdown() {
69 if (!fIsShuttingDown) {
70 fIsShuttingDown= true;
76 fDocumentProvider.shutdown();
78 fIsShuttingDown= false;
84 * @see org.eclipse.jdt.ui.IWorkingCopyManager#getWorkingCopy(org.eclipse.ui.IEditorInput)
86 public ICompilationUnit getWorkingCopy(IEditorInput input) {
87 ICompilationUnit unit= fMap == null ? null : (ICompilationUnit) fMap.get(input);
88 return unit != null ? unit : fDocumentProvider.getWorkingCopy(input);
92 * @see org.eclipse.jdt.internal.ui.javaeditor.IWorkingCopyManagerExtension#setWorkingCopy(org.eclipse.ui.IEditorInput, org.eclipse.jdt.core.ICompilationUnit)
94 public void setWorkingCopy(IEditorInput input, ICompilationUnit workingCopy) {
95 if (fDocumentProvider.isConnected(input)) {
98 fMap.put(input, workingCopy);
103 * @see org.eclipse.jdt.internal.ui.javaeditor.IWorkingCopyManagerExtension#removeWorkingCopy(org.eclipse.ui.IEditorInput)
105 public void removeWorkingCopy(IEditorInput input) {