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 net.sourceforge.phpeclipse.phpeditor.ICompilationUnitDocumentProvider;
24 import org.eclipse.jface.text.Assert;
25 import org.eclipse.ui.IEditorInput;
29 * This working copy manager works together with a given compilation unit document provider and
30 * additionally offers to "overwrite" the working copy provided by this document provider.
32 public class WorkingCopyManager implements IWorkingCopyManager, IWorkingCopyManagerExtension {
34 private ICompilationUnitDocumentProvider fDocumentProvider;
36 private boolean fIsShuttingDown;
39 * Creates a new working copy manager that co-operates with the given
40 * compilation unit document provider.
42 * @param provider the provider
44 public WorkingCopyManager(ICompilationUnitDocumentProvider provider) {
45 Assert.isNotNull(provider);
46 fDocumentProvider= provider;
50 * @see org.eclipse.jdt.ui.IWorkingCopyManager#connect(org.eclipse.ui.IEditorInput)
52 public void connect(IEditorInput input) throws CoreException {
53 fDocumentProvider.connect(input);
57 * @see org.eclipse.jdt.ui.IWorkingCopyManager#disconnect(org.eclipse.ui.IEditorInput)
59 public void disconnect(IEditorInput input) {
60 fDocumentProvider.disconnect(input);
64 * @see org.eclipse.jdt.ui.IWorkingCopyManager#shutdown()
66 public void shutdown() {
67 if (!fIsShuttingDown) {
68 fIsShuttingDown= true;
74 fDocumentProvider.shutdown();
76 fIsShuttingDown= false;
82 * @see org.eclipse.jdt.ui.IWorkingCopyManager#getWorkingCopy(org.eclipse.ui.IEditorInput)
84 public ICompilationUnit getWorkingCopy(IEditorInput input) {
85 ICompilationUnit unit= fMap == null ? null : (ICompilationUnit) fMap.get(input);
86 return unit != null ? unit : fDocumentProvider.getWorkingCopy(input);
90 * @see org.eclipse.jdt.internal.ui.javaeditor.IWorkingCopyManagerExtension#setWorkingCopy(org.eclipse.ui.IEditorInput, org.eclipse.jdt.core.ICompilationUnit)
92 public void setWorkingCopy(IEditorInput input, ICompilationUnit workingCopy) {
93 if (fDocumentProvider.getDocument(input) != null) {
96 fMap.put(input, workingCopy);
100 * @see org.eclipse.jdt.internal.ui.javaeditor.IWorkingCopyManagerExtension#removeWorkingCopy(org.eclipse.ui.IEditorInput)
102 public void removeWorkingCopy(IEditorInput input) {