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;
14 import java.util.HashMap;
17 import net.sourceforge.phpdt.core.ICompilationUnit;
18 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
19 import net.sourceforge.phpdt.ui.IWorkingCopyManagerExtension;
21 import org.eclipse.core.runtime.CoreException;
22 import org.eclipse.jface.text.Assert;
23 import org.eclipse.ui.IEditorInput;
26 * This working copy manager works together with a given compilation unit
27 * document provider and additionally offers to "overwrite" the working copy
28 * provided by this document provider.
30 public class WorkingCopyManager implements IWorkingCopyManager,
31 IWorkingCopyManagerExtension {
33 private ICompilationUnitDocumentProvider fDocumentProvider;
37 private boolean fIsShuttingDown;
40 * Creates a new working copy manager that co-operates with the given
41 * compilation unit document provider.
46 public WorkingCopyManager(ICompilationUnitDocumentProvider provider) {
47 Assert.isNotNull(provider);
48 fDocumentProvider = provider;
52 * @see net.sourceforge.phpdt.ui.IWorkingCopyManager#connect(org.eclipse.ui.IEditorInput)
54 public void connect(IEditorInput input) throws CoreException {
55 fDocumentProvider.connect(input);
59 * @see net.sourceforge.phpdt.ui.IWorkingCopyManager#disconnect(org.eclipse.ui.IEditorInput)
61 public void disconnect(IEditorInput input) {
62 fDocumentProvider.disconnect(input);
66 * @see net.sourceforge.phpdt.ui.IWorkingCopyManager#shutdown()
68 public void shutdown() {
69 if (!fIsShuttingDown) {
70 fIsShuttingDown = true;
76 fDocumentProvider.shutdown();
78 fIsShuttingDown = false;
84 * @see net.sourceforge.phpdt.ui.IWorkingCopyManager#getWorkingCopy(org.eclipse.ui.IEditorInput)
86 public ICompilationUnit getWorkingCopy(IEditorInput input) {
87 ICompilationUnit unit = fMap == null ? null : (ICompilationUnit) fMap
89 return unit != null ? unit : fDocumentProvider.getWorkingCopy(input);
93 * @see net.sourceforge.phpdt.internal.ui.javaeditor.IWorkingCopyManagerExtension#setWorkingCopy(org.eclipse.ui.IEditorInput,
94 * net.sourceforge.phpdt.core.ICompilationUnit)
96 public void setWorkingCopy(IEditorInput input, ICompilationUnit workingCopy) {
97 if (fDocumentProvider.getDocument(input) != null) {
100 fMap.put(input, workingCopy);
105 * @see net.sourceforge.phpdt.internal.ui.javaeditor.IWorkingCopyManagerExtension#removeWorkingCopy(org.eclipse.ui.IEditorInput)
107 public void removeWorkingCopy(IEditorInput input) {