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 net.sourceforge.phpdt.core.ICompilationUnit;
19 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
20 import net.sourceforge.phpdt.ui.IWorkingCopyManagerExtension;
22 import org.eclipse.core.runtime.CoreException;
23 import org.eclipse.jface.text.Assert;
24 import org.eclipse.ui.IEditorInput;
28 * This working copy manager works together with a given compilation unit document provider and
29 * additionally offers to "overwrite" the working copy provided by this document provider.
31 public class WorkingCopyManager implements IWorkingCopyManager, IWorkingCopyManagerExtension {
33 private ICompilationUnitDocumentProvider fDocumentProvider;
35 private boolean fIsShuttingDown;
38 * Creates a new working copy manager that co-operates with the given
39 * compilation unit document provider.
41 * @param provider the provider
43 public WorkingCopyManager(ICompilationUnitDocumentProvider provider) {
44 Assert.isNotNull(provider);
45 fDocumentProvider= provider;
49 * @see net.sourceforge.phpdt.ui.IWorkingCopyManager#connect(org.eclipse.ui.IEditorInput)
51 public void connect(IEditorInput input) throws CoreException {
52 fDocumentProvider.connect(input);
56 * @see net.sourceforge.phpdt.ui.IWorkingCopyManager#disconnect(org.eclipse.ui.IEditorInput)
58 public void disconnect(IEditorInput input) {
59 fDocumentProvider.disconnect(input);
63 * @see net.sourceforge.phpdt.ui.IWorkingCopyManager#shutdown()
65 public void shutdown() {
66 if (!fIsShuttingDown) {
67 fIsShuttingDown= true;
73 fDocumentProvider.shutdown();
75 fIsShuttingDown= false;
81 * @see net.sourceforge.phpdt.ui.IWorkingCopyManager#getWorkingCopy(org.eclipse.ui.IEditorInput)
83 public ICompilationUnit getWorkingCopy(IEditorInput input) {
84 ICompilationUnit unit= fMap == null ? null : (ICompilationUnit) fMap.get(input);
85 return unit != null ? unit : fDocumentProvider.getWorkingCopy(input);
89 * @see net.sourceforge.phpdt.internal.ui.javaeditor.IWorkingCopyManagerExtension#setWorkingCopy(org.eclipse.ui.IEditorInput, net.sourceforge.phpdt.core.ICompilationUnit)
91 public void setWorkingCopy(IEditorInput input, ICompilationUnit workingCopy) {
92 if (fDocumentProvider.getDocument(input) != null) {
95 fMap.put(input, workingCopy);
99 * @see net.sourceforge.phpdt.internal.ui.javaeditor.IWorkingCopyManagerExtension#removeWorkingCopy(org.eclipse.ui.IEditorInput)
101 public void removeWorkingCopy(IEditorInput input) {