Java Code Examples for com.intellij.pom.Navigatable#canNavigate()

The following examples show how to use com.intellij.pom.Navigatable#canNavigate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GoToBuckFile.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  Project project = e.getProject();
  if (project == null) {
    return;
  }
  VirtualFile buckFile = findBuckFile(project);
  if (buckFile != null) {
    final OpenFileDescriptor descriptor = new OpenFileDescriptor(e.getProject(), buckFile);
    // This is for better cursor position.
    final Navigatable n = descriptor.setUseCurrentWindow(false);
    if (!n.canNavigate()) {
      return;
    }
    n.navigate(true);
  }
}
 
Example 2
Source File: NavBarPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void doubleClick(final Object object) {
  if (object instanceof Navigatable) {
    Navigatable navigatable = (Navigatable)object;
    if (navigatable.canNavigate()) {
      navigatable.navigate(true);
    }
  }
  else if (object instanceof Module) {
    ProjectView projectView = ProjectView.getInstance(myProject);
    AbstractProjectViewPane projectViewPane = projectView.getProjectViewPaneById(projectView.getCurrentViewId());
    if (projectViewPane != null) {
      projectViewPane.selectModule((Module)object, true);
    }
  }
  else if (object instanceof Project) {
    return;
  }
  hideHint(true);
}
 
Example 3
Source File: AbstractGotoSEContributor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean processSelectedItem(@Nonnull Object selected, int modifiers, @Nonnull String searchText) {
  if (selected instanceof PsiElement) {
    if (!((PsiElement)selected).isValid()) {
      LOG.warn("Cannot navigate to invalid PsiElement");
      return true;
    }

    PsiElement psiElement = preparePsi((PsiElement)selected, modifiers, searchText);
    Navigatable extNavigatable = createExtendedNavigatable(psiElement, searchText, modifiers);
    if (extNavigatable != null && extNavigatable.canNavigate()) {
      extNavigatable.navigate(true);
      return true;
    }

    NavigationUtil.activateFileWithPsiElement(psiElement, openInCurrentWindow(modifiers));
  }
  else {
    EditSourceUtil.navigate(((NavigationItem)selected), true, openInCurrentWindow(modifiers));
  }

  return true;
}
 
Example 4
Source File: OccurenceNavigatorActionBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void actionPerformed(AnActionEvent e) {
  Project project = e.getData(CommonDataKeys.PROJECT);
  if (project == null) return;

  OccurenceNavigator navigator = getNavigator(e.getDataContext());
  if (navigator == null) {
    return;
  }
  if (!hasOccurenceToGo(navigator)) {
    return;
  }
  OccurenceNavigator.OccurenceInfo occurenceInfo = go(navigator);
  if (occurenceInfo == null) {
    return;
  }
  Navigatable descriptor = occurenceInfo.getNavigateable();
  if (descriptor != null && descriptor.canNavigate()) {
    descriptor.navigate(false);
  }
  if(occurenceInfo.getOccurenceNumber()==-1||occurenceInfo.getOccurencesCount()==-1){
    return;
  }
  WindowManager.getInstance().getStatusBar(project).setInfo(
    IdeBundle.message("message.occurrence.N.of.M", occurenceInfo.getOccurenceNumber(), occurenceInfo.getOccurencesCount()));
}
 
Example 5
Source File: UsageViewImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private static Navigatable getNavigatableForNode(@Nonnull DefaultMutableTreeNode node, boolean allowRequestFocus) {
  Object userObject = node.getUserObject();
  if (userObject instanceof Navigatable) {
    final Navigatable navigatable = (Navigatable)userObject;
    return navigatable.canNavigate() ? new Navigatable() {
      @Override
      public void navigate(boolean requestFocus) {
        navigatable.navigate(allowRequestFocus && requestFocus);
      }

      @Override
      public boolean canNavigate() {
        return navigatable.canNavigate();
      }

      @Override
      public boolean canNavigateToSource() {
        return navigatable.canNavigateToSource();
      }
    } : null;
  }
  return null;
}
 
Example 6
Source File: JumpToSourceAction.java    From MavenHelper with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
	final Navigatable navigatable = getNavigatable(myArtifact, myProject, myMavenProject);
	if (navigatable != null && navigatable.canNavigate()) {
		navigatable.navigate(true);
	} else {
		final Notification notification = new Notification(MAVEN_HELPER_DEPENDENCY_ANALYZER_NOTIFICATION, "", "Parent dependency not found, strange...",
				NotificationType.WARNING);
		ApplicationManager.getApplication().invokeLater(new Runnable() {
			@Override
			public void run() {
				Notifications.Bus.notify(notification, myProject);
			}
		});
	}
}
 
Example 7
Source File: OpenSourceUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void navigate(final boolean requestFocus, final Navigatable...navigatables) {
  if (navigatables == null) return;
  for (Navigatable navigatable : navigatables) {
    if (navigatable.canNavigate()) {
      navigatable.navigate(requestFocus);
    }
  }
}
 
Example 8
Source File: OpenSourceUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void navigate(final boolean requestFocus, final boolean tryNotToScroll, final Navigatable...navigatables) {
  if (navigatables == null) return;
  for (Navigatable navigatable : navigatables) {
    if (navigatable.canNavigate()) {
      if (tryNotToScroll && navigatable instanceof StatePreservingNavigatable) {
        ((StatePreservingNavigatable)navigatable).navigate(requestFocus, true);
      } else {
        navigatable.navigate(requestFocus);
      }
    }
  }
}
 
Example 9
Source File: NewErrorTreeViewPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void navigateToSource(final boolean focusEditor) {
  NavigatableMessageElement element = getSelectedMessageElement();
  if (element == null) {
    return;
  }
  final Navigatable navigatable = element.getNavigatable();
  if (navigatable.canNavigate()) {
    navigatable.navigate(focusEditor);
  }
}
 
Example 10
Source File: BaseNavigateToSourceAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private Navigatable findTargetForUpdate(@Nonnull DataContext dataContext) {
  Navigatable[] navigatables = getNavigatables(dataContext);
  if (navigatables == null) return null;

  for (Navigatable navigatable : navigatables) {
    if (navigatable.canNavigate()) {
      return navigatable instanceof PomTargetPsiElement ? ((PomTargetPsiElement)navigatable).getTarget() : navigatable;
    }
  }
  return null;
}
 
Example 11
Source File: XBreakpointItem.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void navigate(boolean requestFocus) {
  Navigatable navigatable = myBreakpoint.getNavigatable();
  if (navigatable != null && navigatable.canNavigate()) {
    navigatable.navigate(requestFocus);
  }
}
 
Example 12
Source File: GotoTargetHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected boolean navigateToElement(PsiElement target) {
  Navigatable descriptor = target instanceof Navigatable ? (Navigatable)target : EditSourceUtil.getDescriptor(target);
  if (descriptor != null && descriptor.canNavigate()) {
    navigateToElement(descriptor);
    return true;
  }
  return false;
}
 
Example 13
Source File: OpenInEditorAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void openEditor(@Nonnull Project project, @Nonnull Navigatable[] navigatables) {
  boolean success = false;
  for (Navigatable navigatable : navigatables) {
    if (navigatable.canNavigate()) {
      navigatable.navigate(true);
      success = true;
    }
  }
  if (success && myAfterRunnable != null) myAfterRunnable.run();
}
 
Example 14
Source File: ClassSearchEverywhereContributor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
protected Navigatable createExtendedNavigatable(PsiElement psi, String searchText, int modifiers) {
  Navigatable res = super.createExtendedNavigatable(psi, searchText, modifiers);
  if (res != null) {
    return res;
  }

  VirtualFile file = PsiUtilCore.getVirtualFile(psi);
  String memberName = getMemberName(searchText);
  if (file != null && memberName != null) {
    Navigatable delegate = GotoClassAction.findMember(memberName, searchText, psi, file);
    if (delegate != null) {
      return new Navigatable() {
        @Override
        public void navigate(boolean requestFocus) {
          NavigationUtil.activateFileWithPsiElement(psi, openInCurrentWindow(modifiers));
          delegate.navigate(true);

        }

        @Override
        public boolean canNavigate() {
          return delegate.canNavigate();
        }

        @Override
        public boolean canNavigateToSource() {
          return delegate.canNavigateToSource();
        }
      };
    }
  }

  return null;
}
 
Example 15
Source File: GotoClassAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
static void handleSubMemberNavigation(ChooseByNamePopup popup, Object element) {
  if (element instanceof PsiElement && ((PsiElement)element).isValid()) {
    PsiElement psiElement = getElement(((PsiElement)element), popup);
    psiElement = psiElement.getNavigationElement();
    VirtualFile file = PsiUtilCore.getVirtualFile(psiElement);

    if (file != null && popup.getLinePosition() != -1) {
      OpenFileDescriptor descriptor = new OpenFileDescriptor(psiElement.getProject(), file, popup.getLinePosition(), popup.getColumnPosition());
      Navigatable n = descriptor.setUseCurrentWindow(popup.isOpenInCurrentWindowRequested());
      if (n.canNavigate()) {
        n.navigate(true);
        return;
      }
    }

    if (file != null && popup.getMemberPattern() != null) {
      NavigationUtil.activateFileWithPsiElement(psiElement, !popup.isOpenInCurrentWindowRequested());
      Navigatable member = findMember(popup.getMemberPattern(), popup.getTrimmedText(), psiElement, file);
      if (member != null) {
        member.navigate(true);
      }
    }

    NavigationUtil.activateFileWithPsiElement(psiElement, !popup.isOpenInCurrentWindowRequested());
  }
  else {
    EditSourceUtil.navigate(((NavigationItem)element), true, popup.isOpenInCurrentWindowRequested());
  }
}
 
Example 16
Source File: NavBarIdeView.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void selectElement(PsiElement element) {
  myPanel.getModel().updateModel(element, null);

  if (element instanceof Navigatable) {
    final Navigatable navigatable = (Navigatable)element;
    if (navigatable.canNavigate()) {
      ((Navigatable)element).navigate(true);
    }
  }
  myPanel.hideHint();
}
 
Example 17
Source File: XBreakpointItem.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean canNavigate() {
  Navigatable navigatable = myBreakpoint.getNavigatable();
  return navigatable != null && navigatable.canNavigate();
}
 
Example 18
Source File: GotoDeclarationAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static void gotoTargetElement(PsiElement element) {
  Navigatable navigatable = element instanceof Navigatable ? (Navigatable)element : EditSourceUtil.getDescriptor(element);
  if (navigatable != null && navigatable.canNavigate()) {
    navigatable.navigate(true);
  }
}