2 * Copyright 2000-2016 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 package com.intellij.openapi.vfs;
22 import com.intellij.openapi.application.Application;
23 import com.intellij.openapi.application.ApplicationManager;
24 import com.intellij.openapi.vfs.impl.BulkVirtualFileListenerAdapter;
25 import com.intellij.util.EventDispatcher;
26 import org.jetbrains.annotations.NotNull;
27 import org.jetbrains.annotations.Nullable;
29 import java.io.IOException;
31 public abstract class DeprecatedVirtualFileSystem extends VirtualFileSystem {
32 private final EventDispatcher<VirtualFileListener> myEventDispatcher = EventDispatcher.create(VirtualFileListener.class);
34 protected void startEventPropagation() {
35 Application app = ApplicationManager.getApplication();
37 app.getMessageBus().connect().subscribe(
38 VirtualFileManager.VFS_CHANGES, new BulkVirtualFileListenerAdapter(myEventDispatcher.getMulticaster(), this));
43 public void addVirtualFileListener(@NotNull VirtualFileListener listener) {
44 myEventDispatcher.addListener(listener);
48 public void removeVirtualFileListener(@NotNull VirtualFileListener listener) {
49 myEventDispatcher.removeListener(listener);
52 protected void firePropertyChanged(Object requestor,
53 @NotNull VirtualFile file,
54 @NotNull String propertyName,
57 assertWriteAccessAllowed();
58 VirtualFilePropertyEvent event = new VirtualFilePropertyEvent(requestor, file, propertyName, oldValue, newValue);
59 myEventDispatcher.getMulticaster().propertyChanged(event);
62 protected void fireContentsChanged(Object requestor, @NotNull VirtualFile file, long oldModificationStamp) {
63 assertWriteAccessAllowed();
64 VirtualFileEvent event = new VirtualFileEvent(requestor, file, file.getParent(), oldModificationStamp, file.getModificationStamp());
65 myEventDispatcher.getMulticaster().contentsChanged(event);
68 protected void fireFileCreated(@Nullable Object requestor, @NotNull VirtualFile file) {
69 assertWriteAccessAllowed();
70 VirtualFileEvent event = new VirtualFileEvent(requestor, file, file.getName(), file.getParent());
71 myEventDispatcher.getMulticaster().fileCreated(event);
74 protected void fireFileDeleted(Object requestor, @NotNull VirtualFile file, @NotNull String fileName, VirtualFile parent) {
75 assertWriteAccessAllowed();
76 VirtualFileEvent event = new VirtualFileEvent(requestor, file, fileName, parent);
77 myEventDispatcher.getMulticaster().fileDeleted(event);
80 protected void fireFileMoved(Object requestor, @NotNull VirtualFile file, VirtualFile oldParent) {
81 assertWriteAccessAllowed();
82 VirtualFileMoveEvent event = new VirtualFileMoveEvent(requestor, file, oldParent, file.getParent());
83 myEventDispatcher.getMulticaster().fileMoved(event);
86 protected void fireFileCopied(@Nullable Object requestor, @NotNull VirtualFile originalFile, @NotNull VirtualFile createdFile) {
87 assertWriteAccessAllowed();
88 VirtualFileCopyEvent event = new VirtualFileCopyEvent(requestor, originalFile, createdFile);
89 myEventDispatcher.getMulticaster().fileCopied(event);
92 protected void fireBeforePropertyChange(Object requestor,
93 @NotNull VirtualFile file,
94 @NotNull String propertyName,
97 assertWriteAccessAllowed();
98 VirtualFilePropertyEvent event = new VirtualFilePropertyEvent(requestor, file, propertyName, oldValue, newValue);
99 myEventDispatcher.getMulticaster().beforePropertyChange(event);
102 protected void fireBeforeContentsChange(Object requestor, @NotNull VirtualFile file) {
103 assertWriteAccessAllowed();
104 VirtualFileEvent event = new VirtualFileEvent(requestor, file, file.getName(), file.getParent());
105 myEventDispatcher.getMulticaster().beforeContentsChange(event);
108 protected void fireBeforeFileDeletion(Object requestor, @NotNull VirtualFile file) {
109 assertWriteAccessAllowed();
110 VirtualFileEvent event = new VirtualFileEvent(requestor, file, file.getName(), file.getParent());
111 myEventDispatcher.getMulticaster().beforeFileDeletion(event);
114 protected void fireBeforeFileMovement(Object requestor, @NotNull VirtualFile file, VirtualFile newParent) {
115 assertWriteAccessAllowed();
116 VirtualFileMoveEvent event = new VirtualFileMoveEvent(requestor, file, file.getParent(), newParent);
117 myEventDispatcher.getMulticaster().beforeFileMovement(event);
120 protected void assertWriteAccessAllowed() {
121 ApplicationManager.getApplication().assertWriteAccessAllowed();
125 public boolean isReadOnly() {
130 protected void deleteFile(Object requestor, @NotNull VirtualFile vFile) throws IOException {
131 throw unsupported("deleteFile", vFile);
135 protected void moveFile(Object requestor, @NotNull VirtualFile vFile, @NotNull VirtualFile newParent) throws IOException {
136 throw unsupported("move", vFile);
140 protected void renameFile(Object requestor, @NotNull VirtualFile vFile, @NotNull String newName) throws IOException {
141 throw unsupported("renameFile", vFile);
146 public VirtualFile createChildFile(Object requestor, @NotNull VirtualFile vDir, @NotNull String fileName) throws IOException {
147 throw unsupported("createChildFile", vDir);
152 public VirtualFile createChildDirectory(Object requestor, @NotNull VirtualFile vDir, @NotNull String dirName) throws IOException {
153 throw unsupported("createChildDirectory", vDir);
158 public VirtualFile copyFile(Object requestor, @NotNull VirtualFile vFile, @NotNull VirtualFile newParent, @NotNull String copyName) throws IOException {
159 throw unsupported("copyFile", vFile);
162 private UnsupportedOperationException unsupported(String op, VirtualFile vFile) {
163 return new UnsupportedOperationException(op + '(' + vFile + ") not supported by " + getClass().getName());