use of com.intellij.openapi.ui.popup.util.BaseListPopupStep in project intellij-community by JetBrains.
the class GitPushTargetPanel method showRemoteSelector.
private void showRemoteSelector(@NotNull Component component, @NotNull Point point) {
List<PopupItem> remotes = getPopupItems();
if (remotes.size() <= 1) {
return;
}
ListPopup popup = new ListPopupImpl(new BaseListPopupStep<PopupItem>(null, remotes) {
@Override
public PopupStep onChosen(@NotNull PopupItem selectedValue, boolean finalChoice) {
return doFinalStep(() -> {
if (selectedValue.isDefineRemote()) {
showDefineRemoteDialog();
} else {
myRemoteRenderer.updateLinkText(selectedValue.getPresentable());
if (myFireOnChangeAction != null && !myTargetEditor.isShowing()) {
//fireOnChange only when editing completed
myFireOnChangeAction.run();
}
}
});
}
@Nullable
@Override
public ListSeparator getSeparatorAbove(PopupItem value) {
return value.isDefineRemote() ? new ListSeparator() : null;
}
}) {
@Override
public void cancel(InputEvent e) {
super.cancel(e);
if (myTargetEditor.isShowing()) {
//repaint and force move focus to target editor component
GitPushTargetPanel.this.repaint();
IdeFocusManager.getInstance(myProject).requestFocus(myTargetEditor, true);
}
}
};
popup.show(new RelativePoint(component, point));
}
use of com.intellij.openapi.ui.popup.util.BaseListPopupStep 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);
}
use of com.intellij.openapi.ui.popup.util.BaseListPopupStep in project intellij-community by JetBrains.
the class ClasspathPanelImpl method createTableWithButtons.
private JComponent createTableWithButtons() {
final boolean isAnalyzeShown = false;
final ClasspathPanelAction removeAction = new ClasspathPanelAction(this) {
@Override
public void run() {
removeSelectedItems(TableUtil.removeSelectedItems(myEntryTable));
}
};
final AnActionButton analyzeButton = new AnActionButton(ProjectBundle.message("classpath.panel.analyze"), null, IconUtil.getAnalyzeIcon()) {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
AnalyzeDependenciesDialog.show(getRootModel().getModule());
}
};
//addButton.setShortcut(CustomShortcutSet.fromString("alt A", "INSERT"));
//removeButton.setShortcut(CustomShortcutSet.fromString("alt DELETE"));
//upButton.setShortcut(CustomShortcutSet.fromString("alt UP"));
//downButton.setShortcut(CustomShortcutSet.fromString("alt DOWN"));
final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myEntryTable);
AnActionButtonUpdater moveUpDownUpdater = new AnActionButtonUpdater() {
@Override
public boolean isEnabled(AnActionEvent e) {
for (RowSorter.SortKey key : myEntryTable.getRowSorter().getSortKeys()) {
if (key.getSortOrder() != SortOrder.UNSORTED) {
return false;
}
}
return true;
}
};
decorator.setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
initPopupActions();
final JBPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<AddItemPopupAction<?>>(null, myPopupActions) {
@Override
public Icon getIconFor(AddItemPopupAction<?> aValue) {
return aValue.getIcon();
}
@Override
public boolean hasSubstep(AddItemPopupAction<?> selectedValue) {
return selectedValue.hasSubStep();
}
@Override
public boolean isMnemonicsNavigationEnabled() {
return true;
}
@Override
public PopupStep onChosen(final AddItemPopupAction<?> selectedValue, final boolean finalChoice) {
if (selectedValue.hasSubStep()) {
return selectedValue.createSubStep();
}
return doFinalStep(() -> selectedValue.execute());
}
@Override
@NotNull
public String getTextFor(AddItemPopupAction<?> value) {
return "&" + value.getIndex() + " " + value.getTitle();
}
});
popup.show(button.getPreferredPopupPoint());
}
}).setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
removeAction.actionPerformed(null);
}
}).setRemoveActionUpdater(new AnActionButtonUpdater() {
@Override
public boolean isEnabled(AnActionEvent e) {
final int[] selectedRows = myEntryTable.getSelectedRows();
for (final int selectedRow : selectedRows) {
if (!getItemAt(selectedRow).isRemovable()) {
return false;
}
}
return selectedRows.length > 0;
}
}).setMoveUpAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
moveSelectedRows(-1);
}
}).setMoveUpActionUpdater(moveUpDownUpdater).setMoveUpActionName("Move Up (disabled if items are shown in sorted order)").setMoveDownAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
moveSelectedRows(+1);
}
}).setMoveDownActionUpdater(moveUpDownUpdater).setMoveDownActionName("Move Down (disabled if items are shown in sorted order)").addExtraAction(myEditButton);
if (isAnalyzeShown) {
decorator.addExtraAction(analyzeButton);
}
final JPanel panel = decorator.createPanel();
myRemoveButton = ToolbarDecorator.findRemoveButton(panel);
return panel;
}
use of com.intellij.openapi.ui.popup.util.BaseListPopupStep in project intellij-community by JetBrains.
the class ShowRecentFindUsagesAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
UsageView usageView = e.getData(UsageView.USAGE_VIEW_KEY);
Project project = e.getData(CommonDataKeys.PROJECT);
final FindUsagesManager findUsagesManager = ((FindManagerImpl) FindManager.getInstance(project)).getFindUsagesManager();
List<ConfigurableUsageTarget> history = new ArrayList<>(findUsagesManager.getHistory().getAll());
if (!history.isEmpty()) {
// skip most recent find usage, it's under your nose
history.remove(history.size() - 1);
Collections.reverse(history);
}
if (history.isEmpty()) {
// to fill the popup
history.add(null);
}
BaseListPopupStep<ConfigurableUsageTarget> step = new BaseListPopupStep<ConfigurableUsageTarget>(FindBundle.message("recent.find.usages.action.title"), history) {
@Override
public Icon getIconFor(final ConfigurableUsageTarget data) {
ItemPresentation presentation = data == null ? null : data.getPresentation();
return presentation == null ? null : presentation.getIcon(false);
}
@Override
@NotNull
public String getTextFor(final ConfigurableUsageTarget data) {
if (data == null) {
return FindBundle.message("recent.find.usages.action.nothing");
}
return data.getLongDescriptiveName();
}
@Override
public PopupStep onChosen(final ConfigurableUsageTarget selectedValue, final boolean finalChoice) {
return doFinalStep(() -> {
if (selectedValue != null) {
TransactionGuard.getInstance().submitTransactionAndWait(() -> findUsagesManager.rerunAndRecallFromHistory(selectedValue));
}
});
}
};
RelativePoint point;
if (e.getInputEvent() instanceof MouseEvent) {
point = new RelativePoint((MouseEvent) e.getInputEvent());
} else {
point = new RelativePoint(usageView.getComponent(), new Point(4, 4));
}
JBPopupFactory.getInstance().createListPopup(step).show(point);
}
use of com.intellij.openapi.ui.popup.util.BaseListPopupStep in project intellij-community by JetBrains.
the class ExpressionEditorWithHistory method showHistory.
private void showHistory() {
List<XExpression> expressions = getRecentExpressions();
if (!expressions.isEmpty()) {
ListPopupImpl historyPopup = new ListPopupImpl(new BaseListPopupStep<XExpression>(null, expressions) {
@Override
public PopupStep onChosen(XExpression selectedValue, boolean finalChoice) {
setExpression(selectedValue);
requestFocusInEditor();
return FINAL_CHOICE;
}
}) {
@Override
protected ListCellRenderer getListElementRenderer() {
return new ColoredListCellRenderer<XExpression>() {
@Override
protected void customizeCellRenderer(@NotNull JList list, XExpression value, int index, boolean selected, boolean hasFocus) {
append(value.getExpression(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
}
};
}
};
historyPopup.getList().setFont(EditorUtil.getEditorFont());
historyPopup.showUnderneathOf(getEditorComponent());
}
}
Aggregations