Search in sources :

Example 1 with ProjectStructureElementUsage

use of com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElementUsage in project intellij-community by JetBrains.

the class FindUsagesInProjectStructureActionBase method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final ProjectStructureElement selected = getSelectedElement();
    if (selected == null)
        return;
    final Collection<ProjectStructureElementUsage> usages = getContext().getDaemonAnalyzer().getUsages(selected);
    if (usages.isEmpty()) {
        Messages.showInfoMessage(myParentComponent, FindBundle.message("find.usage.view.no.usages.text"), FindBundle.message("find.pointcut.applications.not.found.title"));
        return;
    }
    RelativePoint point = getPointToShowResults();
    final ProjectStructureElementUsage[] usagesArray = usages.toArray(new ProjectStructureElementUsage[usages.size()]);
    Arrays.sort(usagesArray, (o1, o2) -> o1.getPresentableName().compareToIgnoreCase(o2.getPresentableName()));
    BaseListPopupStep<ProjectStructureElementUsage> step = new BaseListPopupStep<ProjectStructureElementUsage>(ProjectBundle.message("dependencies.used.in.popup.title"), usagesArray) {

        @Override
        public PopupStep onChosen(final ProjectStructureElementUsage selected, final boolean finalChoice) {
            selected.getPlace().navigate();
            return FINAL_CHOICE;
        }

        @NotNull
        @Override
        public String getTextFor(ProjectStructureElementUsage value) {
            return value.getPresentableName();
        }

        @Override
        public Icon getIconFor(ProjectStructureElementUsage selection) {
            return selection.getIcon();
        }
    };
    new ListPopupImpl(step) {

        @Override
        protected ListCellRenderer getListElementRenderer() {
            return new ListCellRendererWithRightAlignedComponent<ProjectStructureElementUsage>() {

                @Override
                protected void customize(ProjectStructureElementUsage value) {
                    setLeftText(value.getPresentableName());
                    setIcon(value.getIcon());
                    setRightForeground(Color.GRAY);
                    setRightText(value.getPresentableLocationInElement());
                }
            };
        }
    }.show(point);
}
Also used : ProjectStructureElementUsage(com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElementUsage) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) ListPopupImpl(com.intellij.ui.popup.list.ListPopupImpl) ProjectStructureElement(com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 2 with ProjectStructureElementUsage

use of com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElementUsage in project intellij-community by JetBrains.

the class ChangeLibraryLevelAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final ProjectStructureElement selectedElement = mySourceConfigurable.getSelectedElement();
    if (!(selectedElement instanceof LibraryProjectStructureElement))
        return;
    final StructureConfigurableContext context = mySourceConfigurable.myContext;
    final LibraryProjectStructureElement libraryElement = (LibraryProjectStructureElement) selectedElement;
    final LibraryEx oldLibrary = (LibraryEx) context.getLibrary(libraryElement.getLibrary().getName(), mySourceConfigurable.getLevel());
    LOG.assertTrue(oldLibrary != null);
    final Library newLibrary = doCopy(oldLibrary);
    if (newLibrary == null)
        return;
    final Collection<ProjectStructureElementUsage> usages = context.getDaemonAnalyzer().getUsages(libraryElement);
    for (ProjectStructureElementUsage usage : usages) {
        usage.replaceElement(new LibraryProjectStructureElement(context, newLibrary));
    }
    if (!myCopy) {
        mySourceConfigurable.removeLibrary(libraryElement);
    }
    ProjectStructureConfigurable.getInstance(myProject).selectProjectOrGlobalLibrary(newLibrary, true);
}
Also used : ProjectStructureElementUsage(com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElementUsage) LibraryProjectStructureElement(com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.LibraryProjectStructureElement) ProjectStructureElement(com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) Library(com.intellij.openapi.roots.libraries.Library) LibraryProjectStructureElement(com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.LibraryProjectStructureElement)

Aggregations

ProjectStructureElement (com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement)2 ProjectStructureElementUsage (com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElementUsage)2 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)1 Library (com.intellij.openapi.roots.libraries.Library)1 LibraryProjectStructureElement (com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.LibraryProjectStructureElement)1 BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 ListPopupImpl (com.intellij.ui.popup.list.ListPopupImpl)1