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;
23 //import org.eclipse.jface.text.Assert;
24 import org.eclipse.core.runtime.Assert;
25 import org.eclipse.ui.IEditorInput;
28 * This working copy manager works together with a given compilation unit
29 * document provider and additionally offers to "overwrite" the working copy
30 * provided by this document provider.
32 public class WorkingCopyManager implements IWorkingCopyManager,
33 IWorkingCopyManagerExtension {
35 private ICompilationUnitDocumentProvider fDocumentProvider;
39 private boolean fIsShuttingDown;
42 * Creates a new working copy manager that co-operates with the given
43 * compilation unit document provider.
48 public WorkingCopyManager(ICompilationUnitDocumentProvider provider) {
49 Assert.isNotNull(provider);
50 fDocumentProvider = provider;
54 * @see net.sourceforge.phpdt.ui.IWorkingCopyManager#connect(org.eclipse.ui.IEditorInput)
56 public void connect(IEditorInput input) throws CoreException {
57 fDocumentProvider.connect(input);
61 * @see net.sourceforge.phpdt.ui.IWorkingCopyManager#disconnect(org.eclipse.ui.IEditorInput)
63 public void disconnect(IEditorInput input) {
64 fDocumentProvider.disconnect(input);
68 * @see net.sourceforge.phpdt.ui.IWorkingCopyManager#shutdown()
70 public void shutdown() {
71 if (!fIsShuttingDown) {
72 fIsShuttingDown = true;
78 fDocumentProvider.shutdown();
80 fIsShuttingDown = false;
86 * @see net.sourceforge.phpdt.ui.IWorkingCopyManager#getWorkingCopy(org.eclipse.ui.IEditorInput)
88 public ICompilationUnit getWorkingCopy(IEditorInput input) {
89 ICompilationUnit unit = fMap == null ? null : (ICompilationUnit) fMap
91 return unit != null ? unit : fDocumentProvider.getWorkingCopy(input);
95 * @see net.sourceforge.phpdt.internal.ui.javaeditor.IWorkingCopyManagerExtension#setWorkingCopy(org.eclipse.ui.IEditorInput,
96 * net.sourceforge.phpdt.core.ICompilationUnit)
98 public void setWorkingCopy(IEditorInput input, ICompilationUnit workingCopy) {
99 if (fDocumentProvider.getDocument(input) != null) {
101 fMap = new HashMap();
102 fMap.put(input, workingCopy);
107 * @see net.sourceforge.phpdt.internal.ui.javaeditor.IWorkingCopyManagerExtension#removeWorkingCopy(org.eclipse.ui.IEditorInput)
109 public void removeWorkingCopy(IEditorInput input) {