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 com
.intellij
.openapi
.vcs
.actions
;
18 import com
.intellij
.openapi
.actionSystem
.AnActionEvent
;
19 import com
.intellij
.openapi
.actionSystem
.AsyncUpdateAction
;
20 import com
.intellij
.openapi
.actionSystem
.Presentation
;
21 import com
.intellij
.openapi
.application
.ApplicationManager
;
22 import com
.intellij
.openapi
.project
.DumbAware
;
23 import com
.intellij
.openapi
.project
.Project
;
24 import com
.intellij
.openapi
.vcs
.AbstractVcs
;
25 import com
.intellij
.openapi
.vcs
.FilePath
;
26 import com
.intellij
.openapi
.vcs
.ProjectLevelVcsManager
;
27 import com
.intellij
.util
.containers
.HashSet
;
28 import org
.jetbrains
.annotations
.NotNull
;
30 import java
.util
.Collection
;
31 import java
.util
.Collections
;
33 public abstract class AbstractVcsAction
extends AsyncUpdateAction
<VcsContext
> implements DumbAware
{
34 public static Collection
<AbstractVcs
> getActiveVcses(VcsContext dataContext
) {
35 Collection
<AbstractVcs
> result
= new HashSet
<AbstractVcs
>();
36 final Project project
= dataContext
.getProject();
37 if (project
!= null) {
38 Collections
.addAll(result
, ProjectLevelVcsManager
.getInstance(project
).getAllActiveVcss());
44 protected static FilePath
[] filterDescindingFiles(@NotNull FilePath
[] roots
, Project project
) {
45 return DescindingFilesFilter
.filterDescindingFiles(roots
, project
, null);
48 protected VcsContext
prepareDataFromContext(final AnActionEvent e
) {
49 return forceSyncUpdate(e
) ? VcsContextWrapper
.createInstanceOn(e
) : VcsContextWrapper
.createCachedInstanceOn(e
);
52 protected void performUpdate(final Presentation presentation
, final VcsContext data
) {
53 ApplicationManager
.getApplication().runReadAction(new Runnable() {
55 update(data
, presentation
);
60 public final void actionPerformed(AnActionEvent e
) {
61 actionPerformed(VcsContextWrapper
.createCachedInstanceOn(e
));
64 protected abstract void actionPerformed(VcsContext e
);
66 protected abstract void update(VcsContext vcsContext
, Presentation presentation
);