void doAddAction(AnActionButton button) { if (isUnknown()) { return; } final JBPopupFactory popupFactory = JBPopupFactory.getInstance(); final BeforeRunTaskProvider<BeforeRunTask>[] providers = Extensions.getExtensions( BeforeRunTaskProvider.EXTENSION_POINT_NAME, myRunConfiguration.getProject()); Set<Key> activeProviderKeys = getActiveProviderKeys(); DefaultActionGroup actionGroup = new DefaultActionGroup(null, false); for (final BeforeRunTaskProvider<BeforeRunTask> provider : providers) { if (provider.createTask(myRunConfiguration) == null) continue; if (activeProviderKeys.contains(provider.getId()) && provider.isSingleton()) continue; AnAction providerAction = new AnAction(provider.getName(), null, provider.getIcon()) { @Override public void actionPerformed(AnActionEvent e) { BeforeRunTask task = provider.createTask(myRunConfiguration); if (task != null) { provider.configureTask(myRunConfiguration, task); if (!provider.canExecuteTask(myRunConfiguration, task)) return; } else { return; } task.setEnabled(true); Set<RunConfiguration> configurationSet = new HashSet<RunConfiguration>(); getAllRunBeforeRuns(task, configurationSet); if (configurationSet.contains(myRunConfiguration)) { JOptionPane.showMessageDialog( BeforeRunStepsPanel.this, ExecutionBundle.message( "before.launch.panel.cyclic_dependency_warning", myRunConfiguration.getName(), provider.getDescription(task)), ExecutionBundle.message("warning.common.title"), JOptionPane.WARNING_MESSAGE); return; } addTask(task); myListener.fireStepsBeforeRunChanged(); } }; actionGroup.add(providerAction); } final ListPopup popup = popupFactory.createActionGroupPopup( ExecutionBundle.message("add.new.run.configuration.acrtion.name"), actionGroup, SimpleDataContext.getProjectContext(myRunConfiguration.getProject()), false, false, false, null, -1, Condition.TRUE); popup.show(button.getPreferredPopupPoint()); }
@Override protected JComponent createTreePanel(final WatchDebuggerTree tree) { final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(tree); decorator.setAddAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { executeAction(DebuggerActions.NEW_WATCH, tree); } }); // TODO[den]: add "Add to watches action" on Mac if (!SystemInfo.isMac) { decorator.addExtraAction( AnActionButton.fromAction( ActionManager.getInstance().getAction(XDebuggerActions.ADD_TO_WATCH))); } decorator.setRemoveAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { executeAction(DebuggerActions.REMOVE_WATCH, tree); } }); CustomLineBorder border = new CustomLineBorder( CaptionPanel.CNT_ACTIVE_BORDER_COLOR, SystemInfo.isMac ? 1 : 0, 0, SystemInfo.isMac ? 0 : 1, 0); decorator.setToolbarBorder(border); final JPanel panel = decorator.createPanel(); panel.setBorder(null); return panel; }
@Override public VcsDependentHistoryComponents getUICustomization( final VcsHistorySession session, JComponent forShortcutRegistration) { final ColumnInfo[] columns; final Consumer<VcsFileRevision> listener; final JComponent addComp; if (((SvnHistorySession) session).isHaveMergeSources()) { final MergeSourceColumnInfo mergeSourceColumn = new MergeSourceColumnInfo((SvnHistorySession) session); columns = new ColumnInfo[] {new CopyFromColumnInfo(), mergeSourceColumn}; final JPanel panel = new JPanel(new BorderLayout()); final JTextArea field = new JTextArea(); field.setEditable(false); field.setBackground(UIUtil.getComboBoxDisabledBackground()); field.setWrapStyleWord(true); listener = new Consumer<VcsFileRevision>() { @Override public void consume(VcsFileRevision vcsFileRevision) { field.setText(mergeSourceColumn.getText(vcsFileRevision)); } }; final MergeSourceDetailsAction sourceAction = new MergeSourceDetailsAction(); sourceAction.registerSelf(forShortcutRegistration); JPanel fieldPanel = new ToolbarDecorator() { @Override protected JComponent getComponent() { return field; } @Override protected void updateButtons() {} @Override protected void installDnDSupport() {} @Override protected boolean isModelEditable() { return false; } }.initPosition().addExtraAction(AnActionButton.fromAction(sourceAction)).createPanel(); fieldPanel.setBorder(IdeBorderFactory.createBorder(SideBorder.LEFT | SideBorder.TOP)); panel.add(fieldPanel, BorderLayout.CENTER); panel.add(new JLabel("Merge Sources:"), BorderLayout.NORTH); addComp = panel; } else { columns = new ColumnInfo[] {new CopyFromColumnInfo()}; addComp = null; listener = null; } return new VcsDependentHistoryComponents(columns, listener, addComp); }
private void performAdd(AnActionButton e) { DefaultActionGroup group = new DefaultActionGroup(myAddActions); JBPopupFactory.getInstance() .createActionGroupPopup( null, group, e.getDataContext(), JBPopupFactory.ActionSelectionAid.NUMBERING, true, new Runnable() { public void run() { updateCountLabel(); } }, -1) .show(e.getPreferredPopupPoint()); }
private void addSdk(AnActionButton button) { PythonSdkDetailsStep.show( myProject, myProjectSdksModel.getSdks(), null, myMainPanel, button.getPreferredPopupPoint().getScreenPoint(), sdk -> addCreatedSdk(sdk, true)); }
private void updateButtons() { final int[] selectedRows = myEntryTable.getSelectedRows(); boolean removeButtonEnabled = true; int minRow = myEntryTable.getRowCount() + 1; int maxRow = -1; for (final int selectedRow : selectedRows) { minRow = Math.min(minRow, selectedRow); maxRow = Math.max(maxRow, selectedRow); final ClasspathTableItem<?> item = myModel.getItemAt(selectedRow); if (!item.isRemovable()) { removeButtonEnabled = false; } } if (myRemoveButton != null) { myRemoveButton.setEnabled(removeButtonEnabled && selectedRows.length > 0); } ClasspathTableItem<?> selectedItem = selectedRows.length == 1 ? myModel.getItemAt(selectedRows[0]) : null; myEditButton.setEnabled(selectedItem != null && selectedItem.isEditable()); }
@Override protected void addToolbarButtons(ToolbarDecorator toolbarDecorator) { AnActionButton specifyUrlButton = new AnActionButton( ProjectBundle.message("sdk.paths.specify.url.button"), IconUtil.getAddLinkIcon()) { @Override public void actionPerformed(AnActionEvent e) { onSpecifyUrlButtonClicked(); } }; specifyUrlButton.setShortcut(CustomShortcutSet.fromString("alt S")); specifyUrlButton.addCustomUpdater( new AnActionButtonUpdater() { @Override public boolean isEnabled(AnActionEvent e) { return myEnabled && !isUrlInserted(); } }); toolbarDecorator.addExtraAction(specifyUrlButton); }
@Override public void navigate(boolean openLibraryEditor) { final OrderEntry entry = getSelectedEntry(); final ProjectStructureConfigurable rootConfigurable = ProjectStructureConfigurable.getInstance(myState.getProject()); if (entry instanceof ModuleOrderEntry) { Module module = ((ModuleOrderEntry) entry).getModule(); if (module != null) { rootConfigurable.select(module.getName(), null, true); } } else if (entry instanceof LibraryOrderEntry) { if (!openLibraryEditor) { rootConfigurable.select((LibraryOrderEntry) entry, true); } else { myEditButton.actionPerformed(null); } } else if (entry instanceof SdkOrderEntry) { Sdk jdk = ((SdkOrderEntry) entry).getSdk(); if (jdk != null) { rootConfigurable.select(jdk, true); } } }
@NotNull protected List<Pair<String, JPanel>> createAdditionalPanels() { // this method is invoked before constructor body myExceptionsModel = new ExceptionsTableModel(myMethod.getMethod().getThrowsList()); myExceptionsModel.setTypeInfos(myMethod.getMethod()); final JBTable table = new JBTable(myExceptionsModel); table.setStriped(true); table.setRowHeight(20); table .getColumnModel() .getColumn(0) .setCellRenderer(new CodeFragmentTableCellRenderer(myProject)); final JavaCodeFragmentTableCellEditor cellEditor = new JavaCodeFragmentTableCellEditor(myProject); cellEditor.addDocumentListener( new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { final int row = table.getSelectedRow(); final int col = table.getSelectedColumn(); myExceptionsModel.setValueAt(cellEditor.getCellEditorValue(), row, col); updateSignature(); } }); table.getColumnModel().getColumn(0).setCellEditor(cellEditor); table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.getSelectionModel().setSelectionInterval(0, 0); table.setSurrendersFocusOnKeystroke(true); myPropExceptionsButton = new AnActionButton( RefactoringBundle.message("changeSignature.propagate.exceptions.title"), null, PlatformIcons.NEW_EXCEPTION) { @Override public void actionPerformed(AnActionEvent e) { final Ref<JavaCallerChooser> chooser = new Ref<JavaCallerChooser>(); Consumer<Set<PsiMethod>> callback = new Consumer<Set<PsiMethod>>() { @Override public void consume(Set<PsiMethod> psiMethods) { myMethodsToPropagateExceptions = psiMethods; myExceptionPropagationTree = chooser.get().getTree(); } }; chooser.set( new JavaCallerChooser( myMethod.getMethod(), myProject, RefactoringBundle.message("changeSignature.exception.caller.chooser"), myExceptionPropagationTree, callback)); chooser.get().show(); } }; myPropExceptionsButton.setShortcut(CustomShortcutSet.fromString("alt X")); final JPanel panel = ToolbarDecorator.createDecorator(table) .addExtraAction(myPropExceptionsButton) .createPanel(); panel.setBorder(IdeBorderFactory.createEmptyBorder(0)); myExceptionsModel.addTableModelListener(mySignatureUpdater); final ArrayList<Pair<String, JPanel>> result = new ArrayList<Pair<String, JPanel>>(); final String message = RefactoringBundle.message("changeSignature.exceptions.panel.border.title"); result.add(Pair.create(message, panel)); return result; }
@Override protected void updatePropagateButtons() { super.updatePropagateButtons(); myPropExceptionsButton.setEnabled(!isGenerateDelegate() && mayPropagateExceptions()); }
private void update() { CheckedTreeNode node = getSelectedToolNode(); Tool selectedTool = getSelectedTool(); ToolsGroup selectedGroup = getSelectedToolGroup(); if (selectedTool != null) { myAddButton.setEnabled(true); myCopyButton.setEnabled(true); myEditButton.setEnabled(true); myMoveDownButton.setEnabled(isMovingAvailable(node, Direction.DOWN)); myMoveUpButton.setEnabled(isMovingAvailable(node, Direction.UP)); myRemoveButton.setEnabled(true); } else if (selectedGroup != null) { myAddButton.setEnabled(true); myCopyButton.setEnabled(false); myEditButton.setEnabled(false); myMoveDownButton.setEnabled(isMovingAvailable(node, Direction.DOWN)); myMoveUpButton.setEnabled(isMovingAvailable(node, Direction.UP)); myRemoveButton.setEnabled(true); } else { myAddButton.setEnabled(true); myCopyButton.setEnabled(false); myEditButton.setEnabled(false); myMoveDownButton.setEnabled(false); myMoveUpButton.setEnabled(false); myRemoveButton.setEnabled(false); } (getModel()).nodeStructureChanged(null); myTree.repaint(); }
private void createActions(ToolbarDecorator decorator) { final Consumer<BaseInjection> consumer = new Consumer<BaseInjection>() { public void consume(final BaseInjection injection) { addInjection(injection); } }; final Factory<BaseInjection> producer = new NullableFactory<BaseInjection>() { public BaseInjection create() { final InjInfo info = getSelectedInjection(); return info == null ? null : info.injection; } }; for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) { ContainerUtil.addAll(myAddActions, support.createAddActions(myProject, consumer)); final AnAction action = support.createEditAction(myProject, producer); myEditActions.put( support.getId(), action == null ? AbstractLanguageInjectionSupport.createDefaultEditAction(myProject, producer) : action); mySupports.put(support.getId(), support); } Collections.sort( myAddActions, new Comparator<AnAction>() { public int compare(final AnAction o1, final AnAction o2) { return Comparing.compare( o1.getTemplatePresentation().getText(), o2.getTemplatePresentation().getText()); } }); decorator.disableUpDownActions(); decorator.setAddActionUpdater( new AnActionButtonUpdater() { @Override public boolean isEnabled(AnActionEvent e) { return !myAddActions.isEmpty(); } }); decorator.setAddAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { performAdd(button); } }); decorator.setRemoveActionUpdater( new AnActionButtonUpdater() { @Override public boolean isEnabled(AnActionEvent e) { boolean enabled = false; for (InjInfo info : getSelectedInjections()) { if (!info.bundled) { enabled = true; break; } } return enabled; } }); decorator.setRemoveAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { performRemove(); } }); decorator.setEditActionUpdater( new AnActionButtonUpdater() { @Override public boolean isEnabled(AnActionEvent e) { AnAction edit = getEditAction(); if (edit != null) edit.update(e); return edit != null && edit.getTemplatePresentation().isEnabled(); } }); decorator.setEditAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { performEditAction(); } }); decorator.addExtraAction( new DumbAwareActionButton("Duplicate", "Duplicate", PlatformIcons.COPY_ICON) { @Override public boolean isEnabled() { return getEditAction() != null; } @Override public void actionPerformed(@NotNull AnActionEvent e) { final InjInfo injection = getSelectedInjection(); if (injection != null) { addInjection(injection.injection.copy()); // performEditAction(e); } } }); decorator.addExtraAction( new DumbAwareActionButton( "Enable Selected Injections", "Enable Selected Injections", PlatformIcons.SELECT_ALL_ICON) { @Override public void actionPerformed(@NotNull final AnActionEvent e) { performSelectedInjectionsEnabled(true); } }); decorator.addExtraAction( new DumbAwareActionButton( "Disable Selected Injections", "Disable Selected Injections", PlatformIcons.UNSELECT_ALL_ICON) { @Override public void actionPerformed(@NotNull final AnActionEvent e) { performSelectedInjectionsEnabled(false); } }); new DumbAwareAction("Toggle") { @Override public void update(@NotNull AnActionEvent e) { SpeedSearchSupply supply = SpeedSearchSupply.getSupply(myInjectionsTable); e.getPresentation().setEnabled(supply == null || !supply.isPopupActive()); } @Override public void actionPerformed(@NotNull final AnActionEvent e) { performToggleAction(); } }.registerCustomShortcutSet( new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0)), myInjectionsTable); if (myInfos.length > 1) { AnActionButton shareAction = new DumbAwareActionButton("Move to IDE Scope", null, PlatformIcons.IMPORT_ICON) { { addCustomUpdater( new AnActionButtonUpdater() { @Override public boolean isEnabled(AnActionEvent e) { CfgInfo cfg = getTargetCfgInfo(getSelectedInjections()); e.getPresentation() .setText( cfg == getDefaultCfgInfo() ? "Move to IDE Scope" : "Move to Project Scope"); return cfg != null; } }); } @Override public void actionPerformed(@NotNull final AnActionEvent e) { final List<InjInfo> injections = getSelectedInjections(); final CfgInfo cfg = getTargetCfgInfo(injections); if (cfg == null) return; for (InjInfo info : injections) { if (info.cfgInfo == cfg) continue; if (info.bundled) continue; info.cfgInfo.injectionInfos.remove(info); cfg.addInjection(info.injection); } final int[] selectedRows = myInjectionsTable.getSelectedRows(); myInjectionsTable.getListTableModel().setItems(getInjInfoList(myInfos)); TableUtil.selectRows(myInjectionsTable, selectedRows); } @Nullable private CfgInfo getTargetCfgInfo(final List<InjInfo> injections) { CfgInfo cfg = null; for (InjInfo info : injections) { if (info.bundled) { continue; } if (cfg == null) cfg = info.cfgInfo; else if (cfg != info.cfgInfo) return info.cfgInfo; } if (cfg == null) return null; for (CfgInfo info : myInfos) { if (info != cfg) return info; } throw new AssertionError(); } }; shareAction.setShortcut( new CustomShortcutSet( KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.SHIFT_DOWN_MASK))); decorator.addExtraAction(shareAction); } decorator.addExtraAction( new DumbAwareActionButton("Import", "Import", AllIcons.Actions.Install) { @Override public void actionPerformed(@NotNull final AnActionEvent e) { doImportAction(e.getDataContext()); updateCountLabel(); } }); decorator.addExtraAction( new DumbAwareActionButton("Export", "Export", AllIcons.Actions.Export) { @Override public void actionPerformed(@NotNull final AnActionEvent e) { final List<BaseInjection> injections = getInjectionList(getSelectedInjections()); final VirtualFileWrapper wrapper = FileChooserFactory.getInstance() .createSaveFileDialog( new FileSaverDescriptor("Export Selected Injections to File...", "", "xml"), myProject) .save(null, null); if (wrapper == null) return; final Configuration configuration = new Configuration(); configuration.setInjections(injections); final Document document = new Document(configuration.getState()); try { JDOMUtil.writeDocument(document, wrapper.getFile(), "\n"); } catch (IOException ex) { final String msg = ex.getLocalizedMessage(); Messages.showErrorDialog( myProject, msg != null && msg.length() > 0 ? msg : ex.toString(), "Export Failed"); } } @Override public boolean isEnabled() { return !getSelectedInjections().isEmpty(); } }); }