use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class ShowByteCodeAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
final Project project = e.getProject();
if (project == null)
return;
final Editor editor = e.getData(CommonDataKeys.EDITOR);
final PsiElement psiElement = getPsiElement(dataContext, project, editor);
if (psiElement == null)
return;
if (ByteCodeViewerManager.getContainingClass(psiElement) == null) {
Messages.showWarningDialog(project, "The selection should contain a class", "Unable to Find Class to Show Bytecode");
return;
}
final String psiElementTitle = ByteCodeViewerManager.getInstance(project).getTitle(psiElement);
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(psiElement);
if (virtualFile == null)
return;
final RelativePoint bestPopupLocation = JBPopupFactory.getInstance().guessBestPopupLocation(dataContext);
final SmartPsiElementPointer element = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(psiElement);
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Looking for Bytecode...") {
private String myByteCode;
private String myErrorMessage;
private String myErrorTitle;
@Override
public void run(@NotNull ProgressIndicator indicator) {
if (ProjectRootManager.getInstance(project).getFileIndex().isInContent(virtualFile) && isMarkedForCompilation(project, virtualFile)) {
myErrorMessage = "Unable to show bytecode for '" + psiElementTitle + "'. Class file does not exist or is out-of-date.";
myErrorTitle = "Class File Out-Of-Date";
} else {
myByteCode = ReadAction.compute(() -> ByteCodeViewerManager.getByteCode(psiElement));
}
}
@Override
public void onSuccess() {
if (project.isDisposed())
return;
if (myErrorMessage != null && myTitle != null) {
Messages.showWarningDialog(project, myErrorMessage, myErrorTitle);
return;
}
final PsiElement targetElement = element.getElement();
if (targetElement == null)
return;
final ByteCodeViewerManager codeViewerManager = ByteCodeViewerManager.getInstance(project);
if (codeViewerManager.hasActiveDockedDocWindow()) {
codeViewerManager.doUpdateComponent(targetElement, myByteCode);
} else {
if (myByteCode == null) {
Messages.showErrorDialog(project, "Unable to parse class file for '" + psiElementTitle + "'.", "Bytecode not Found");
return;
}
final ByteCodeViewerComponent component = new ByteCodeViewerComponent(project, null);
component.setText(myByteCode, targetElement);
Processor<JBPopup> pinCallback = popup -> {
codeViewerManager.recreateToolWindow(targetElement, targetElement);
popup.cancel();
return false;
};
final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(component, null).setProject(project).setDimensionServiceKey(project, ShowByteCodeAction.class.getName(), false).setResizable(true).setMovable(true).setRequestFocus(LookupManager.getActiveLookup(editor) == null).setTitle(psiElementTitle + " Bytecode").setCouldPin(pinCallback).createPopup();
Disposer.register(popup, component);
if (editor != null) {
popup.showInBestPositionFor(editor);
} else {
popup.show(bestPopupLocation);
}
}
}
});
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class MultilinePopupBuilder method createPopup.
@NotNull
JBPopup createPopup() {
JPanel panel = new JPanel(new BorderLayout());
panel.add(myTextField, BorderLayout.CENTER);
ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, myTextField).setCancelOnClickOutside(true).setAdText(KeymapUtil.getShortcutsText(CommonShortcuts.CTRL_ENTER.getShortcuts()) + " to finish").setRequestFocus(true).setResizable(true).setMayBeParent(true);
final JBPopup popup = builder.createPopup();
popup.setMinimumSize(new JBDimension(200, 90));
AnAction okAction = new DumbAwareAction() {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
unregisterCustomShortcutSet(popup.getContent());
popup.closeOk(e.getInputEvent());
}
};
okAction.registerCustomShortcutSet(CommonShortcuts.CTRL_ENTER, popup.getContent());
return popup;
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class ShowJavadocAction method actionPerformed.
public void actionPerformed(final AnActionEvent e) {
final PropertyInspectorTable inspector = PropertyInspectorTable.DATA_KEY.getData(e.getDataContext());
final IntrospectedProperty introspectedProperty = inspector.getSelectedIntrospectedProperty();
final PsiClass aClass = inspector.getComponentClass();
final PsiMethod getter = PropertyUtil.findPropertyGetter(aClass, introspectedProperty.getName(), false, true);
LOG.assertTrue(getter != null);
final PsiMethod setter = PropertyUtil.findPropertySetter(aClass, introspectedProperty.getName(), false, true);
LOG.assertTrue(setter != null);
final DocumentationManager documentationManager = DocumentationManager.getInstance(aClass.getProject());
final DocumentationComponent component1 = new DocumentationComponent(documentationManager);
final DocumentationComponent component2 = new DocumentationComponent(documentationManager);
final Disposable disposable = Disposer.newDisposable();
final TabbedPaneWrapper tabbedPane = new TabbedPaneWrapper(disposable);
tabbedPane.addTab(UIDesignerBundle.message("tab.getter"), component1);
tabbedPane.addTab(UIDesignerBundle.message("tab.setter"), component2);
documentationManager.fetchDocInfo(getter, component1);
documentationManager.queueFetchDocInfo(setter, component2).doWhenProcessed(() -> {
final JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(tabbedPane.getComponent(), component1).setDimensionServiceKey(aClass.getProject(), DocumentationManager.JAVADOC_LOCATION_AND_SIZE, false).setResizable(true).setMovable(true).setRequestFocus(true).setTitle(UIDesignerBundle.message("property.javadoc.title", introspectedProperty.getName())).createPopup();
component1.setHint(hint);
component2.setHint(hint);
Disposer.register(hint, component1);
Disposer.register(hint, component2);
Disposer.register(hint, disposable);
hint.show(new RelativePoint(inspector, new Point(0, 0)));
//component1.requestFocus();
});
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class ExternalProjectPathField method createPanel.
@NotNull
public static MyPathAndProjectButtonPanel createPanel(@NotNull final Project project, @NotNull final ProjectSystemId externalSystemId) {
final EditorTextField textField = createTextField(project, externalSystemId);
final FixedSizeButton selectRegisteredProjectButton = new FixedSizeButton();
selectRegisteredProjectButton.setIcon(AllIcons.Actions.Module);
String tooltipText = ExternalSystemBundle.message("run.configuration.tooltip.choose.registered.project", externalSystemId.getReadableName());
selectRegisteredProjectButton.setToolTipText(tooltipText);
selectRegisteredProjectButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final Ref<JBPopup> popupRef = new Ref<>();
final Tree tree = buildRegisteredProjectsTree(project, externalSystemId);
tree.setBorder(IdeBorderFactory.createEmptyBorder(8));
Runnable treeSelectionCallback = () -> {
TreePath path = tree.getSelectionPath();
if (path != null) {
Object lastPathComponent = path.getLastPathComponent();
if (lastPathComponent instanceof ExternalSystemNode) {
Object e1 = ((ExternalSystemNode) lastPathComponent).getDescriptor().getElement();
if (e1 instanceof ExternalProjectPojo) {
ExternalProjectPojo pojo = (ExternalProjectPojo) e1;
textField.setText(pojo.getPath());
Editor editor = textField.getEditor();
if (editor != null) {
collapseIfPossible(editor, externalSystemId, project);
}
}
}
}
popupRef.get().closeOk(null);
};
JBPopup popup = new PopupChooserBuilder(tree).setTitle(ExternalSystemBundle.message("run.configuration.title.choose.registered.project", externalSystemId.getReadableName())).setResizable(true).setItemChoosenCallback(treeSelectionCallback).setAutoselectOnMouseMove(true).setCloseOnEnter(false).createPopup();
popupRef.set(popup);
popup.showUnderneathOf(selectRegisteredProjectButton);
}
});
return new MyPathAndProjectButtonPanel(textField, selectRegisteredProjectButton);
}
use of com.intellij.openapi.ui.popup.JBPopup 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;
}
Aggregations