use of com.intellij.ui.AnActionButtonRunnable in project intellij-community by JetBrains.
the class CertificateConfigurable method initializeUI.
private void initializeUI() {
myTree = new Tree();
myTreeBuilder = new CertificateTreeBuilder(myTree);
myTrustManager = CertificateManager.getInstance().getCustomTrustManager();
// show newly added certificates
myTrustManager.addListener(this);
myTree.getEmptyText().setText("No certificates");
myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
myTree.setRootVisible(false);
//myTree.setShowsRootHandles(false);
ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myTree).disableUpDownActions();
decorator.setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
// show choose file dialog, add certificate
FileChooser.chooseFile(CERTIFICATE_DESCRIPTOR, null, null, file -> {
String path = file.getPath();
X509Certificate certificate = CertificateUtil.loadX509Certificate(path);
if (certificate == null) {
Messages.showErrorDialog(myRootPanel, "Malformed X509 server certificate", "Not Imported");
} else if (myCertificates.contains(certificate)) {
Messages.showWarningDialog(myRootPanel, "Certificate already exists", "Not Imported");
} else {
myCertificates.add(certificate);
myTreeBuilder.addCertificate(certificate);
addCertificatePanel(certificate);
myTreeBuilder.selectCertificate(certificate);
}
});
}
}).setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
// allow to delete several certificates at once
for (X509Certificate certificate : myTreeBuilder.getSelectedCertificates(true)) {
myCertificates.remove(certificate);
myTreeBuilder.removeCertificate(certificate);
}
if (myCertificates.isEmpty()) {
showCard(EMPTY_PANEL);
} else {
myTreeBuilder.selectFirstCertificate();
}
}
});
myTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
X509Certificate certificate = myTreeBuilder.getFirstSelectedCertificate(true);
if (certificate != null) {
showCard(getCardName(certificate));
}
}
});
myCertificatesListPanel.add(decorator.createPanel(), BorderLayout.CENTER);
}
use of com.intellij.ui.AnActionButtonRunnable in project intellij-community by JetBrains.
the class LibraryRootsComponent method init.
private void init(AbstractTreeStructure treeStructure) {
myTree = new Tree(new DefaultTreeModel(new DefaultMutableTreeNode()));
myTree.setRootVisible(false);
myTree.setShowsRootHandles(true);
new LibraryRootsTreeSpeedSearch(myTree);
myTree.setCellRenderer(new LibraryTreeRenderer());
myTreeBuilder = new LibraryTableTreeBuilder(myTree, (DefaultTreeModel) myTree.getModel(), treeStructure);
myTreePanel.setLayout(new BorderLayout());
ToolbarDecorator toolbarDecorator = ToolbarDecorator.createDecorator(myTree).disableUpDownActions().setRemoveActionName(ProjectBundle.message("library.remove.action")).disableRemoveAction();
toolbarDecorator.setPanelBorder(new CustomLineBorder(1, 0, 0, 0));
final List<AttachRootButtonDescriptor> popupItems = new ArrayList<>();
for (AttachRootButtonDescriptor descriptor : myDescriptor.createAttachButtons()) {
Icon icon = descriptor.getToolbarIcon();
if (icon != null) {
AttachItemAction action = new AttachItemAction(descriptor, descriptor.getButtonText(), icon);
toolbarDecorator.addExtraAction(AnActionButton.fromAction(action));
} else {
popupItems.add(descriptor);
}
}
myAddExcludedRootActionButton = new AddExcludedRootActionButton();
toolbarDecorator.addExtraAction(myAddExcludedRootActionButton);
toolbarDecorator.addExtraAction(new AnActionButton("Remove", IconUtil.getRemoveIcon()) {
@Override
public void actionPerformed(AnActionEvent e) {
final Object[] selectedElements = getSelectedElements();
if (selectedElements.length == 0) {
return;
}
ApplicationManager.getApplication().runWriteAction(() -> {
for (Object selectedElement : selectedElements) {
if (selectedElement instanceof ItemElement) {
final ItemElement itemElement = (ItemElement) selectedElement;
getLibraryEditor().removeRoot(itemElement.getUrl(), itemElement.getRootType());
} else if (selectedElement instanceof OrderRootTypeElement) {
final OrderRootType rootType = ((OrderRootTypeElement) selectedElement).getOrderRootType();
final String[] urls = getLibraryEditor().getUrls(rootType);
for (String url : urls) {
getLibraryEditor().removeRoot(url, rootType);
}
} else if (selectedElement instanceof ExcludedRootElement) {
getLibraryEditor().removeExcludedRoot(((ExcludedRootElement) selectedElement).getUrl());
}
}
});
libraryChanged(true);
}
@Override
public void updateButton(AnActionEvent e) {
super.updateButton(e);
Object[] elements = getSelectedElements();
Presentation presentation = e.getPresentation();
if (ContainerUtil.and(elements, new FilteringIterator.InstanceOf<>(ExcludedRootElement.class))) {
presentation.setText("Cancel Exclusion");
} else {
presentation.setText(getTemplatePresentation().getText());
}
}
@Override
public ShortcutSet getShortcut() {
return CommonShortcuts.getDelete();
}
});
toolbarDecorator.setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
if (popupItems.isEmpty()) {
new AttachFilesAction(myDescriptor.getAttachFilesActionName()).actionPerformed(null);
return;
}
List<AnAction> actions = new ArrayList<>();
actions.add(new AttachFilesAction(myDescriptor.getAttachFilesActionName()));
for (AttachRootButtonDescriptor descriptor : popupItems) {
actions.add(new AttachItemAction(descriptor, descriptor.getButtonText(), null));
}
final DefaultActionGroup group = new DefaultActionGroup(actions);
JBPopupFactory.getInstance().createActionGroupPopup(null, group, DataManager.getInstance().getDataContext(button.getContextComponent()), JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, true).show(button.getPreferredPopupPoint());
}
});
myTreePanel.add(toolbarDecorator.createPanel(), BorderLayout.CENTER);
Disposer.register(this, myTreeBuilder);
}
use of com.intellij.ui.AnActionButtonRunnable in project intellij-community by JetBrains.
the class JsonSchemaMappingsView method createUI.
private void createUI(final Project project) {
myProject = project;
myTableView = new TableView<>();
myTableView.getTableHeader().setVisible(false);
myDecorator = ToolbarDecorator.createDecorator(myTableView);
myDecorator.setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
final int[] rows = myTableView.getSelectedRows();
if (rows != null && rows.length > 0) {
int cnt = 0;
for (int row : rows) {
myTableView.getListTableModel().removeRow(row - cnt);
++cnt;
}
myTableView.getListTableModel().fireTableDataChanged();
myTreeUpdater.run();
}
}
}).setAddAction(new MyAddActionButtonRunnable(project)).disableUpDownActions();
mySchemaField = new TextFieldWithBrowseButton();
SwingHelper.installFileCompletionAndBrowseDialog(myProject, mySchemaField, JsonBundle.message("json.schema.add.schema.chooser.title"), FileChooserDescriptorFactory.createSingleFileDescriptor());
attachNavigateToSchema();
myError = SwingHelper.createHtmlLabel("Warning: conflicting mappings. <a href=\"#\">Show details</a>", null, s -> {
final BalloonBuilder builder = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(myErrorText, UIUtil.getBalloonWarningIcon(), MessageType.WARNING.getPopupBackground(), null);
builder.setDisposable(this);
builder.setHideOnClickOutside(true);
builder.setCloseButtonEnabled(true);
builder.createBalloon().showInCenterOf(myError);
});
final FormBuilder builder = FormBuilder.createFormBuilder();
final JBLabel label = new JBLabel("JSON schema file:");
builder.addLabeledComponent(label, mySchemaField);
label.setBorder(JBUI.Borders.empty(0, 10, 0, 10));
mySchemaField.setBorder(JBUI.Borders.empty(0, 0, 0, 10));
final JPanel wrapper = new JPanel(new BorderLayout());
wrapper.setBorder(JBUI.Borders.empty(0, 10, 0, 10));
myErrorIcon = new JBLabel(UIUtil.getBalloonWarningIcon());
wrapper.add(myErrorIcon, BorderLayout.WEST);
wrapper.add(myError, BorderLayout.CENTER);
builder.addComponent(wrapper);
builder.addComponentFillVertically(myDecorator.createPanel(), 5);
myComponent = builder.getPanel();
}
use of com.intellij.ui.AnActionButtonRunnable in project google-cloud-intellij by GoogleCloudPlatform.
the class BreakpointConfigurationPanel method loadFrom.
@Override
public void loadFrom(@NotNull XLineBreakpoint<CloudLineBreakpointProperties> breakpoint) {
XBreakpointBase lineBreakpointImpl = breakpoint instanceof XBreakpointBase ? (XBreakpointBase) breakpoint : null;
Breakpoint javaBreakpoint = BreakpointManager.getJavaBreakpoint(breakpoint);
CloudLineBreakpointType.CloudLineBreakpoint cloudBreakpoint = null;
if (javaBreakpoint instanceof CloudLineBreakpointType.CloudLineBreakpoint) {
cloudBreakpoint = (CloudLineBreakpointType.CloudLineBreakpoint) javaBreakpoint;
}
if (cloudBreakpoint == null || lineBreakpointImpl == null) {
return;
}
XDebuggerEditorsProvider debuggerEditorsProvider = cloudLineBreakpointType.getEditorsProvider(breakpoint, cloudBreakpoint.getProject());
if (debuggerEditorsProvider != null) {
treePanel = new XDebuggerTreePanel(cloudBreakpoint.getProject(), debuggerEditorsProvider, this, breakpoint.getSourcePosition(), "GoogleCloudTools.BreakpointWatchContextMenu", null);
List<XExpression> watches = new ArrayList<XExpression>();
for (String watchExpression : breakpoint.getProperties().getWatchExpressions()) {
watches.add(debuggerEditorsProvider.createExpression(((XBreakpointBase) breakpoint).getProject(), new DocumentImpl(watchExpression), getFileTypeLanguage(breakpoint), EvaluationMode.EXPRESSION));
}
rootNode = new WatchesRootNode(treePanel.getTree(), this, watches.toArray(new XExpression[watches.size()]));
treePanel.getTree().setRoot(rootNode, false);
watchPanel.removeAll();
watchPanel.add(watchLabel, BorderLayout.NORTH);
treePanel.getTree().getEmptyText().setText("There are no custom watches for this snapshot location.");
final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(treePanel.getTree()).disableUpDownActions();
decorator.setToolbarPosition(ActionToolbarPosition.RIGHT);
decorator.setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
executeAction(XDebuggerActions.XNEW_WATCH);
}
});
decorator.setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
executeAction(XDebuggerActions.XREMOVE_WATCH);
}
});
CustomLineBorder border = new CustomLineBorder(CaptionPanel.CNT_ACTIVE_BORDER_COLOR, SystemInfo.isMac ? 1 : 0, 0, SystemInfo.isMac ? 0 : 1, 0);
decorator.setToolbarBorder(border);
watchPanel.add(decorator.createPanel(), BorderLayout.CENTER);
}
}
use of com.intellij.ui.AnActionButtonRunnable in project azure-tools-for-java by Microsoft.
the class LibrariesConfigurationDialog method createUIComponents.
private void createUIComponents() {
librariesList = new JBList(currentLibs);
tempList = new ArrayList(currentLibs);
librariesPanel = ToolbarDecorator.createDecorator(librariesList).setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
addLibrary();
}
}).setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
removeLibrary();
}
}).setEditAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
editLibrary();
}
}).disableUpDownActions().createPanel();
}
Aggregations