update copyright
[fedora-idea.git] / plugins / svn4idea / src / org / jetbrains / idea / svn / actions / SvnExcludingIgnoredOperation.java
blobac34ac5d2a9b4077004db07ad82d2f7de1ed7d5e
1 /*
2 * Copyright 2000-2009 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.
16 package org.jetbrains.idea.svn.actions;
18 import com.intellij.openapi.project.Project;
19 import com.intellij.openapi.vcs.changes.ChangeListManager;
20 import com.intellij.openapi.vcs.impl.ExcludedFileIndex;
21 import com.intellij.openapi.vfs.VirtualFile;
22 import org.tmatesoft.svn.core.SVNDepth;
23 import org.tmatesoft.svn.core.SVNException;
25 public class SvnExcludingIgnoredOperation {
26 private final Operation myImportAction;
27 private final SVNDepth myDepth;
28 private final Filter myFilter;
30 public SvnExcludingIgnoredOperation(final Project project, final Operation importAction, final SVNDepth depth) {
31 myImportAction = importAction;
32 myDepth = depth;
34 myFilter = new Filter(project);
37 public static class Filter {
38 private final Project myProject;
39 private final ExcludedFileIndex myIndex;
40 private final ChangeListManager myClManager;
42 public Filter(final Project project) {
43 myProject = project;
45 if (! project.isDefault()) {
46 myIndex = ExcludedFileIndex.getInstance(project);
47 myClManager = ChangeListManager.getInstance(project);
48 } else {
49 myIndex = null;
50 myClManager = null;
54 public boolean accept(final VirtualFile file) {
55 if (! myProject.isDefault()) {
56 if (myIndex.isExcludedFile(file)) {
57 return false;
59 if (myClManager.isIgnoredFile(file)) {
60 return false;
63 return true;
67 private boolean operation(final VirtualFile file) throws SVNException {
68 if (! myFilter.accept(file)) return false;
70 myImportAction.doOperation(file);
71 return true;
74 private void executeDown(final VirtualFile file) throws SVNException {
75 if (! operation(file)) {
76 return;
79 for (VirtualFile child : file.getChildren()) {
80 executeDown(child);
84 public void execute(final VirtualFile file) throws SVNException {
85 if (SVNDepth.INFINITY.equals(myDepth)) {
86 executeDown(file);
87 return;
90 if (! operation(file)) {
91 return;
94 if (SVNDepth.EMPTY.equals(myDepth)) {
95 return;
98 for (VirtualFile child : file.getChildren()) {
99 if (SVNDepth.FILES.equals(myDepth) && child.isDirectory()) {
100 continue;
102 operation(child);
106 public interface Operation {
107 void doOperation(final VirtualFile file) throws SVNException;