use of com.intellij.xdebugger.attach.XLocalAttachDebuggerProvider in project intellij-community by JetBrains.
the class AttachToLocalProcessAction method collectAttachItems.
@NotNull
public static List<AttachItem> collectAttachItems(@NotNull final Project project, @NotNull ProcessInfo[] processList, @NotNull ProgressIndicator indicator, @NotNull XLocalAttachDebuggerProvider... providers) {
MultiMap<XLocalAttachGroup, Pair<ProcessInfo, ArrayList<XLocalAttachDebugger>>> groupWithItems = new MultiMap<>();
UserDataHolderBase dataHolder = new UserDataHolderBase();
for (ProcessInfo eachInfo : processList) {
MultiMap<XLocalAttachGroup, XLocalAttachDebugger> groupsWithDebuggers = new MultiMap<>();
for (XLocalAttachDebuggerProvider eachProvider : providers) {
indicator.checkCanceled();
groupsWithDebuggers.putValues(eachProvider.getAttachGroup(), eachProvider.getAvailableDebuggers(project, eachInfo, dataHolder));
}
for (XLocalAttachGroup eachGroup : groupsWithDebuggers.keySet()) {
Collection<XLocalAttachDebugger> debuggers = groupsWithDebuggers.get(eachGroup);
if (!debuggers.isEmpty()) {
groupWithItems.putValue(eachGroup, Pair.create(eachInfo, new ArrayList<>(debuggers)));
}
}
}
ArrayList<XLocalAttachGroup> sortedGroups = new ArrayList<>(groupWithItems.keySet());
sortedGroups.sort(Comparator.comparingInt(XLocalAttachGroup::getOrder));
List<AttachItem> currentItems = new ArrayList<>();
for (final XLocalAttachGroup eachGroup : sortedGroups) {
List<Pair<ProcessInfo, ArrayList<XLocalAttachDebugger>>> sortedItems = new ArrayList<>(groupWithItems.get(eachGroup));
sortedItems.sort((a, b) -> eachGroup.compare(project, a.first, b.first, dataHolder));
boolean first = true;
for (Pair<ProcessInfo, ArrayList<XLocalAttachDebugger>> eachItem : sortedItems) {
currentItems.add(new AttachItem(eachGroup, first, eachItem.first, eachItem.second, dataHolder));
first = false;
}
}
List<AttachItem> currentHistoryItems = new ArrayList<>();
List<HistoryItem> history = getHistory(project);
for (int i = history.size() - 1; i >= 0; i--) {
HistoryItem eachHistoryItem = history.get(i);
for (AttachItem eachCurrentItem : currentItems) {
boolean isSuitableItem = eachHistoryItem.getGroup().equals(eachCurrentItem.getGroup()) && eachHistoryItem.getProcessInfo().getCommandLine().equals(eachCurrentItem.getProcessInfo().getCommandLine());
if (!isSuitableItem)
continue;
List<XLocalAttachDebugger> debuggers = eachCurrentItem.getDebuggers();
int selectedDebugger = -1;
for (int j = 0; j < debuggers.size(); j++) {
XLocalAttachDebugger eachDebugger = debuggers.get(j);
if (eachDebugger.getDebuggerDisplayName().equals(eachHistoryItem.getDebuggerName())) {
selectedDebugger = j;
break;
}
}
if (selectedDebugger == -1)
continue;
currentHistoryItems.add(new AttachItem(eachCurrentItem.getGroup(), currentHistoryItems.isEmpty(), XDebuggerBundle.message("xdebugger.attach.toLocal.popup.recent"), eachCurrentItem.getProcessInfo(), debuggers, selectedDebugger, dataHolder));
}
}
currentHistoryItems.addAll(currentItems);
return currentHistoryItems;
}
use of com.intellij.xdebugger.attach.XLocalAttachDebuggerProvider in project intellij-community by JetBrains.
the class AttachToLocalProcessAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final Project project = getEventProject(e);
if (project == null)
return;
XLocalAttachDebuggerProvider[] providers = Extensions.getExtensions(XLocalAttachDebuggerProvider.EP);
new Task.Backgroundable(project, XDebuggerBundle.message("xdebugger.attach.toLocal.action.collectingProcesses"), true, PerformInBackgroundOption.DEAF) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
ProcessInfo[] processList = OSProcessUtil.getProcessList();
List<AttachItem> items = collectAttachItems(project, processList, indicator, providers);
ApplicationManager.getApplication().invokeLater(() -> {
if (project.isDisposed()) {
return;
}
ProcessListStep step = new ProcessListStep(items, project);
final ListPopup popup = JBPopupFactory.getInstance().createListPopup(step);
final JList mainList = ((ListPopupImpl) popup).getList();
ListSelectionListener listener = event -> {
if (event.getValueIsAdjusting())
return;
Object item = ((JList) event.getSource()).getSelectedValue();
if (item == null) {
item = mainList.getSelectedValue();
}
if (item instanceof AttachItem) {
String debuggerName = ((AttachItem) item).getSelectedDebugger().getDebuggerDisplayName();
debuggerName = StringUtil.shortenTextWithEllipsis(debuggerName, 50, 0);
((ListPopupImpl) popup).setCaption(XDebuggerBundle.message("xdebugger.attach.toLocal.popup.title", debuggerName));
}
};
popup.addListSelectionListener(listener);
// force first valueChanged event
listener.valueChanged(new ListSelectionEvent(mainList, mainList.getMinSelectionIndex(), mainList.getMaxSelectionIndex(), false));
popup.showCenteredInCurrentWindow(project);
});
}
}.queue();
}
Aggregations