ComponentWithBrowseButton - optional remove listener on hide
[fedora-idea.git] / platform / lang-impl / src / com / intellij / ide / favoritesTreeView / FavoritesViewSelectInTarget.java
blobaeae7191306cc579e7786c2acac8f874cb2034df
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.
17 package com.intellij.ide.favoritesTreeView;
19 import com.intellij.ide.SelectInContext;
20 import com.intellij.ide.SelectInManager;
21 import com.intellij.ide.StandardTargetWeights;
22 import com.intellij.ide.impl.ProjectViewSelectInTarget;
23 import com.intellij.openapi.project.Project;
24 import com.intellij.openapi.vfs.VirtualFile;
25 import com.intellij.psi.PsiFileSystemItem;
27 /**
28 * User: anna
29 * Date: Feb 25, 2005
31 public class FavoritesViewSelectInTarget extends ProjectViewSelectInTarget {
32 public FavoritesViewSelectInTarget(final Project project) {
33 super(project);
36 public String toString() {
37 return SelectInManager.FAVORITES;
40 protected boolean canSelect(final PsiFileSystemItem file) {
41 if (!super.canSelect(file)) return false;
42 return findSuitableFavoritesList(file.getVirtualFile(), myProject, null) != null;
45 public static String findSuitableFavoritesList(VirtualFile file, Project project, final String currentSubId) {
46 final FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
47 if (currentSubId != null && favoritesManager.contains(currentSubId, file)) return currentSubId;
48 final String[] lists = favoritesManager.getAvailableFavoritesLists();
49 for (String name : lists) {
50 if (favoritesManager.contains(name, file)) return name;
52 return null;
55 public String getMinorViewId() {
56 return FavoritesProjectViewPane.ID;
59 public float getWeight() {
60 return StandardTargetWeights.FAVORITES_WEIGHT;
63 protected boolean canWorkWithCustomObjects() {
64 return false;
67 public boolean isSubIdSelectable(String subId, SelectInContext context) {
68 final FavoritesManager favoritesManager = FavoritesManager.getInstance(myProject);
69 return favoritesManager.contains(subId, context.getVirtualFile());