-/*\r
- * Copyright 2000-2009 JetBrains s.r.o.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package com.intellij.ide.impl;\r
-\r
-import com.intellij.ide.SelectInContext;\r
-import com.intellij.ide.SelectInTarget;\r
-import com.intellij.openapi.editor.Document;\r
-import com.intellij.openapi.fileEditor.FileDocumentManager;\r
-import com.intellij.openapi.project.Project;\r
-import com.intellij.openapi.vfs.VirtualFile;\r
-import com.intellij.psi.*;\r
-import org.jetbrains.annotations.NotNull;\r
-\r
-\r
-public abstract class SelectInTargetPsiWrapper implements SelectInTarget {\r
- protected final Project myProject;\r
-\r
- protected SelectInTargetPsiWrapper(@NotNull final Project project) {\r
- myProject = project;\r
- }\r
-\r
- public abstract String toString();\r
-\r
- protected abstract boolean canSelect(PsiFileSystemItem file);\r
-\r
- public final boolean canSelect(SelectInContext context) {\r
- if (myProject.isDisposed()) return false;\r
-\r
- VirtualFile virtualFile = context.getVirtualFile();\r
- if (!virtualFile.isValid()) return false;\r
-\r
- final Document document = FileDocumentManager.getInstance().getDocument(virtualFile);\r
- final PsiFileSystemItem psiFile;\r
- if (document != null) {\r
- psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(document);\r
- }\r
- else if (context.getSelectorInFile() instanceof PsiFile) {\r
- psiFile = (PsiFile)context.getSelectorInFile();\r
- }\r
- else if (virtualFile.isDirectory()) {\r
- psiFile = PsiManager.getInstance(myProject).findDirectory(virtualFile);\r
- }\r
- else {\r
- psiFile = PsiManager.getInstance(myProject).findFile(virtualFile);\r
- }\r
- return psiFile != null && canSelect(psiFile) || canWorkWithCustomObjects();\r
- }\r
-\r
- public final void selectIn(SelectInContext context, final boolean requestFocus) {\r
- VirtualFile file = context.getVirtualFile();\r
- Object selector = context.getSelectorInFile();\r
- if (selector == null) {\r
- PsiManager psiManager = PsiManager.getInstance(myProject);\r
- selector = file.isDirectory() ? psiManager.findDirectory(file) : psiManager.findFile(file);\r
- }\r
-\r
- if (selector instanceof PsiElement) {\r
- select(((PsiElement)selector).getOriginalElement(), requestFocus);\r
- } else {\r
- select(selector, file, requestFocus);\r
- }\r
- }\r
-\r
- protected abstract void select(final Object selector, VirtualFile virtualFile, final boolean requestFocus);\r
-\r
- protected abstract boolean canWorkWithCustomObjects();\r
-\r
- protected abstract void select(PsiElement element, boolean requestFocus);\r
-}\r
+/*
+ * Copyright 2000-2009 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.intellij.ide.impl;
+
+import com.intellij.ide.SelectInContext;
+import com.intellij.ide.SelectInTarget;
+import com.intellij.openapi.editor.Document;
+import com.intellij.openapi.fileEditor.FileDocumentManager;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.*;
+import org.jetbrains.annotations.NotNull;
+
+
+public abstract class SelectInTargetPsiWrapper implements SelectInTarget {
+ protected final Project myProject;
+
+ protected SelectInTargetPsiWrapper(@NotNull final Project project) {
+ myProject = project;
+ }
+
+ public abstract String toString();
+
+ protected abstract boolean canSelect(PsiFileSystemItem file);
+
+ public final boolean canSelect(SelectInContext context) {
+ if (myProject.isDisposed()) return false;
+
+ VirtualFile virtualFile = context.getVirtualFile();
+ if (!virtualFile.isValid()) return false;
+
+ final Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
+ final PsiFileSystemItem psiFile;
+ if (document != null) {
+ psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(document);
+ }
+ else if (context.getSelectorInFile() instanceof PsiFile) {
+ psiFile = (PsiFile)context.getSelectorInFile();
+ }
+ else if (virtualFile.isDirectory()) {
+ psiFile = PsiManager.getInstance(myProject).findDirectory(virtualFile);
+ }
+ else {
+ psiFile = PsiManager.getInstance(myProject).findFile(virtualFile);
+ }
+ return psiFile != null && canSelect(psiFile) || canWorkWithCustomObjects();
+ }
+
+ public final void selectIn(SelectInContext context, final boolean requestFocus) {
+ VirtualFile file = context.getVirtualFile();
+ Object selector = context.getSelectorInFile();
+ if (selector == null) {
+ PsiManager psiManager = PsiManager.getInstance(myProject);
+ selector = file.isDirectory() ? psiManager.findDirectory(file) : psiManager.findFile(file);
+ }
+
+ if (selector instanceof PsiElement) {
+ select(((PsiElement)selector).getOriginalElement(), requestFocus);
+ } else {
+ select(selector, file, requestFocus);
+ }
+ }
+
+ protected abstract void select(final Object selector, VirtualFile virtualFile, final boolean requestFocus);
+
+ protected abstract boolean canWorkWithCustomObjects();
+
+ protected abstract void select(PsiElement element, boolean requestFocus);
+}