From b0ecc8023f0ab168bc3ea6ca35fb8936b33ee35a Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 23 Aug 2011 17:53:34 +0200 Subject: [PATCH] pull NavigatableAdapter to upper level --- .../src/com/intellij/pom/Navigatable.java | 29 ------------ .../com/intellij/pom/NavigatableAdapter.java | 45 +++++++++++++++++++ .../impl/EditorHyperlinkSupport.java | 4 +- .../shelf/ShelvedChangesViewManager.java | 3 +- .../maven/navigator/MavenNavigationUtil.java | 5 ++- 5 files changed, 52 insertions(+), 34 deletions(-) create mode 100644 platform/platform-api/src/com/intellij/pom/NavigatableAdapter.java diff --git a/platform/platform-api/src/com/intellij/pom/Navigatable.java b/platform/platform-api/src/com/intellij/pom/Navigatable.java index c637cd5eb264..1ea3cd7bd6e9 100644 --- a/platform/platform-api/src/com/intellij/pom/Navigatable.java +++ b/platform/platform-api/src/com/intellij/pom/Navigatable.java @@ -15,10 +15,6 @@ */ package com.intellij.pom; -import com.intellij.openapi.fileEditor.OpenFileDescriptor; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.vfs.VirtualFile; - public interface Navigatable { /** * Open editor and select/navigate to the object there if possible. @@ -38,29 +34,4 @@ public interface Navigatable { * Source means some kind of editor */ boolean canNavigateToSource(); - -/** - * Very often both methods canNavigate and canNavigateToSource - * return true. This adapter class lets focus on navigation - * routine only. - * - * @author Konstantin Bulenkov - */ - abstract class Adapter implements Navigatable { - public boolean canNavigate() { - return true; - } - - public boolean canNavigateToSource() { - return true; - } - - public static void navigate(Project project, VirtualFile file, boolean requestFocus) { - navigate(project, file, 0, requestFocus); - } - - public static void navigate(Project project, VirtualFile file, int offset, boolean requestFocus) { - new OpenFileDescriptor(project, file, offset).navigate(requestFocus); - } - } } diff --git a/platform/platform-api/src/com/intellij/pom/NavigatableAdapter.java b/platform/platform-api/src/com/intellij/pom/NavigatableAdapter.java new file mode 100644 index 000000000000..2740295c701a --- /dev/null +++ b/platform/platform-api/src/com/intellij/pom/NavigatableAdapter.java @@ -0,0 +1,45 @@ +/* + * Copyright 2000-2011 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.pom; + +import com.intellij.openapi.fileEditor.OpenFileDescriptor; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; + +/** + * Very often both methods canNavigate and canNavigateToSource + * return true. This adapter class lets focus on navigation + * routine only. + * + * @author Konstantin Bulenkov + */ +public abstract class NavigatableAdapter implements Navigatable { + public boolean canNavigate() { + return true; + } + + public boolean canNavigateToSource() { + return true; + } + + public static void navigate(Project project, VirtualFile file, boolean requestFocus) { + navigate(project, file, 0, requestFocus); + } + + public static void navigate(Project project, VirtualFile file, int offset, boolean requestFocus) { + new OpenFileDescriptor(project, file, offset).navigate(requestFocus); + } +} diff --git a/platform/platform-impl/src/com/intellij/execution/impl/EditorHyperlinkSupport.java b/platform/platform-impl/src/com/intellij/execution/impl/EditorHyperlinkSupport.java index 24bbc64fe360..b08b964a9af7 100644 --- a/platform/platform-impl/src/com/intellij/execution/impl/EditorHyperlinkSupport.java +++ b/platform/platform-impl/src/com/intellij/execution/impl/EditorHyperlinkSupport.java @@ -33,7 +33,7 @@ import com.intellij.openapi.editor.markup.RangeHighlighter; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; -import com.intellij.pom.Navigatable; +import com.intellij.pom.NavigatableAdapter; import com.intellij.util.BeforeAfter; import com.intellij.util.Consumer; import com.intellij.util.SmartList; @@ -319,7 +319,7 @@ public class EditorHyperlinkSupport { int newIndex = ranges.isEmpty() ? -1 : i == ranges.size() ? 0 : (i + delta + ranges.size()) % ranges.size(); final RangeHighlighter next = newIndex < ranges.size() && newIndex >= 0 ? ranges.get(newIndex) : null; if (next == null) return null; - return new OccurenceNavigator.OccurenceInfo(new Navigatable.Adapter() { + return new OccurenceNavigator.OccurenceInfo(new NavigatableAdapter() { public void navigate(final boolean requestFocus) { action.consume(next); linkFollowed(editor, ranges, next); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesViewManager.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesViewManager.java index 55591146ca62..1c3d0ef9410f 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesViewManager.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesViewManager.java @@ -48,6 +48,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.ToolWindow; import com.intellij.openapi.wm.ToolWindowManager; import com.intellij.pom.Navigatable; +import com.intellij.pom.NavigatableAdapter; import com.intellij.ui.*; import com.intellij.ui.content.Content; import com.intellij.ui.content.ContentFactory; @@ -318,7 +319,7 @@ public class ShelvedChangesViewManager implements ProjectComponent { } for (final ShelvedChange shelvedChange : shelvedChanges) { if (shelvedChange.getBeforePath() != null && ! FileStatus.ADDED.equals(shelvedChange.getFileStatus())) { - final Navigatable.Adapter navigatable = new Navigatable.Adapter() { + final NavigatableAdapter navigatable = new NavigatableAdapter() { @Override public void navigate(boolean requestFocus) { final VirtualFile vf = shelvedChange.getBeforeVFUnderProject(myProject); diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/MavenNavigationUtil.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/MavenNavigationUtil.java index 8f73fc2f2e15..c78438e07754 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/MavenNavigationUtil.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/MavenNavigationUtil.java @@ -19,6 +19,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.pom.Navigatable; +import com.intellij.pom.NavigatableAdapter; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; import com.intellij.psi.xml.XmlDocument; @@ -47,7 +48,7 @@ public class MavenNavigationUtil { public static Navigatable createNavigatableForPom(final Project project, final VirtualFile file) { if (file == null || !file.isValid()) return null; final PsiFile result = PsiManager.getInstance(project).findFile(file); - return result == null ? null : new Navigatable.Adapter() { + return result == null ? null : new NavigatableAdapter() { public void navigate(boolean requestFocus) { int offset = 0; if (result instanceof XmlFile) { @@ -69,7 +70,7 @@ public class MavenNavigationUtil { @Nullable public static Navigatable createNavigatableForDependency(final Project project, final VirtualFile file, final MavenArtifact artifact) { - return new Navigatable.Adapter() { + return new NavigatableAdapter() { public void navigate(boolean requestFocus) { final PsiFile pom = PsiManager.getInstance(project).findFile(file); if (pom instanceof XmlFile) {