Search in sources :

Example 1 with RefreshableOnComponent

use of com.intellij.openapi.vcs.ui.RefreshableOnComponent in project intellij-community by JetBrains.

the class CommitChangeListDialog method createOptionsPanel.

@Nullable
private JPanel createOptionsPanel(@NotNull Project project, @NotNull String borderTitleName) {
    boolean hasVcsOptions = false;
    Box vcsCommitOptions = Box.createVerticalBox();
    for (AbstractVcs vcs : ContainerUtil.sorted(getAffectedVcses(), VCS_COMPARATOR)) {
        final CheckinEnvironment checkinEnvironment = vcs.getCheckinEnvironment();
        if (checkinEnvironment != null) {
            final RefreshableOnComponent options = checkinEnvironment.createAdditionalOptionsPanel(this, myAdditionalData);
            if (options != null) {
                JPanel vcsOptions = new JPanel(new BorderLayout());
                vcsOptions.add(options.getComponent(), BorderLayout.CENTER);
                vcsOptions.setBorder(IdeBorderFactory.createTitledBorder(vcs.getDisplayName(), true));
                vcsCommitOptions.add(vcsOptions);
                myPerVcsOptionsPanels.put(vcs, vcsOptions);
                myAdditionalComponents.add(options);
                if (options instanceof CheckinChangeListSpecificComponent) {
                    myCheckinChangeListSpecificComponents.put(vcs.getName(), (CheckinChangeListSpecificComponent) options);
                }
                hasVcsOptions = true;
            }
        }
    }
    boolean beforeVisible = false;
    boolean afterVisible = false;
    Box beforeBox = Box.createVerticalBox();
    Box afterBox = Box.createVerticalBox();
    for (BaseCheckinHandlerFactory factory : getCheckInFactories(project)) {
        final CheckinHandler handler = factory.createHandler(this, myCommitContext);
        if (CheckinHandler.DUMMY.equals(handler))
            continue;
        myHandlers.add(handler);
        final RefreshableOnComponent beforePanel = handler.getBeforeCheckinConfigurationPanel();
        if (beforePanel != null) {
            beforeBox.add(beforePanel.getComponent());
            beforeVisible = true;
            myAdditionalComponents.add(beforePanel);
        }
        final RefreshableOnComponent afterPanel = handler.getAfterCheckinConfigurationPanel(getDisposable());
        if (afterPanel != null) {
            afterBox.add(afterPanel.getComponent());
            afterVisible = true;
            myAdditionalComponents.add(afterPanel);
        }
    }
    if (!hasVcsOptions && !beforeVisible && !afterVisible)
        return null;
    Box optionsBox = Box.createVerticalBox();
    if (hasVcsOptions) {
        vcsCommitOptions.add(Box.createVerticalGlue());
        optionsBox.add(vcsCommitOptions);
    }
    if (beforeVisible) {
        beforeBox.add(Box.createVerticalGlue());
        JPanel beforePanel = new JPanel(new BorderLayout());
        beforePanel.add(beforeBox);
        beforePanel.setBorder(IdeBorderFactory.createTitledBorder(VcsBundle.message("border.standard.checkin.options.group", borderTitleName), true));
        optionsBox.add(beforePanel);
    }
    if (afterVisible) {
        afterBox.add(Box.createVerticalGlue());
        JPanel afterPanel = new JPanel(new BorderLayout());
        afterPanel.add(afterBox);
        afterPanel.setBorder(IdeBorderFactory.createTitledBorder(VcsBundle.message("border.standard.after.checkin.options.group", borderTitleName), true));
        optionsBox.add(afterPanel);
    }
    optionsBox.add(Box.createVerticalGlue());
    JPanel additionalOptionsPanel = new JPanel(new BorderLayout());
    additionalOptionsPanel.add(optionsBox, BorderLayout.NORTH);
    JScrollPane optionsPane = ScrollPaneFactory.createScrollPane(additionalOptionsPanel, true);
    return JBUI.Panels.simplePanel(optionsPane).withBorder(JBUI.Borders.emptyLeft(10));
}
Also used : RefreshableOnComponent(com.intellij.openapi.vcs.ui.RefreshableOnComponent) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with RefreshableOnComponent

use of com.intellij.openapi.vcs.ui.RefreshableOnComponent in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoFmtCheckinFactory method createHandler.

@Override
@NotNull
public CheckinHandler createHandler(@NotNull CheckinProjectPanel panel, @NotNull CommitContext commitContext) {
    return new CheckinHandler() {

        @Override
        public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
            JCheckBox checkBox = new JCheckBox("Go fmt");
            return new RefreshableOnComponent() {

                @Override
                @NotNull
                public JComponent getComponent() {
                    JPanel panel = new JPanel(new BorderLayout());
                    panel.add(checkBox, BorderLayout.WEST);
                    return panel;
                }

                @Override
                public void refresh() {
                }

                @Override
                public void saveState() {
                    PropertiesComponent.getInstance(panel.getProject()).setValue(GO_FMT, Boolean.toString(checkBox.isSelected()));
                }

                @Override
                public void restoreState() {
                    checkBox.setSelected(enabled(panel));
                }
            };
        }

        @Override
        public ReturnResult beforeCheckin(@Nullable CommitExecutor executor, PairConsumer<Object, Object> additionalDataConsumer) {
            if (enabled(panel)) {
                Ref<Boolean> success = Ref.create(true);
                FileDocumentManager.getInstance().saveAllDocuments();
                for (PsiFile file : getPsiFiles()) {
                    VirtualFile virtualFile = file.getVirtualFile();
                    new GoFmtFileAction().doSomething(virtualFile, ModuleUtilCore.findModuleForPsiElement(file), file.getProject(), "Go fmt", true, result -> {
                        if (!result)
                            success.set(false);
                    });
                }
                if (!success.get()) {
                    return showErrorMessage(executor);
                }
            }
            return super.beforeCheckin();
        }

        @NotNull
        private ReturnResult showErrorMessage(@Nullable CommitExecutor executor) {
            String[] buttons = new String[] { "&Details...", commitButtonMessage(executor, panel), CommonBundle.getCancelButtonText() };
            int answer = Messages.showDialog(panel.getProject(), "<html><body>GoFmt returned non-zero code on some of the files.<br/>" + "Would you like to commit anyway?</body></html>\n", "Go Fmt", null, buttons, 0, 1, UIUtil.getWarningIcon());
            if (answer == Messages.OK) {
                return ReturnResult.CLOSE_WINDOW;
            }
            if (answer == Messages.NO) {
                return ReturnResult.COMMIT;
            }
            return ReturnResult.CANCEL;
        }

        @NotNull
        private List<PsiFile> getPsiFiles() {
            Collection<VirtualFile> files = panel.getVirtualFiles();
            List<PsiFile> psiFiles = ContainerUtil.newArrayList();
            PsiManager manager = PsiManager.getInstance(panel.getProject());
            for (VirtualFile file : files) {
                PsiFile psiFile = manager.findFile(file);
                if (psiFile instanceof GoFile) {
                    psiFiles.add(psiFile);
                }
            }
            return psiFiles;
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GoFile(com.goide.psi.GoFile) PsiManager(com.intellij.psi.PsiManager) CheckinHandler(com.intellij.openapi.vcs.checkin.CheckinHandler) CommitExecutor(com.intellij.openapi.vcs.changes.CommitExecutor) PairConsumer(com.intellij.util.PairConsumer) RefreshableOnComponent(com.intellij.openapi.vcs.ui.RefreshableOnComponent) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with RefreshableOnComponent

use of com.intellij.openapi.vcs.ui.RefreshableOnComponent in project intellij-community by JetBrains.

the class ExternalToolsCheckinHandlerFactory method createHandler.

@NotNull
@Override
public CheckinHandler createHandler(@NotNull final CheckinProjectPanel panel, @NotNull CommitContext commitContext) {
    final ToolsProjectConfig config = ToolsProjectConfig.getInstance(panel.getProject());
    return new CheckinHandler() {

        @Override
        public RefreshableOnComponent getAfterCheckinConfigurationPanel(Disposable parentDisposable) {
            final JLabel label = new JLabel(ToolsBundle.message("tools.after.commit.description"));
            ComboboxWithBrowseButton listComponent = new ComboboxWithBrowseButton();
            final JComboBox comboBox = listComponent.getComboBox();
            comboBox.setModel(new CollectionComboBoxModel(getComboBoxElements(), null));
            comboBox.setRenderer(new ListCellRendererWrapper<Object>() {

                @Override
                public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
                    if (value instanceof ToolsGroup) {
                        setText(StringUtil.notNullize(((ToolsGroup) value).getName(), ToolsBundle.message("tools.unnamed.group")));
                    } else if (value instanceof Tool) {
                        setText("  " + StringUtil.notNullize(((Tool) value).getName()));
                    } else {
                        setText(ToolsBundle.message("tools.list.item.none"));
                    }
                }
            });
            listComponent.getButton().addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    final Object item = comboBox.getSelectedItem();
                    String id = null;
                    if (item instanceof Tool) {
                        id = ((Tool) item).getActionId();
                    }
                    final ToolSelectDialog dialog = new ToolSelectDialog(panel.getProject(), id, new ToolsPanel());
                    if (!dialog.showAndGet()) {
                        return;
                    }
                    comboBox.setModel(new CollectionComboBoxModel(getComboBoxElements(), dialog.getSelectedTool()));
                }
            });
            BorderLayout layout = new BorderLayout();
            layout.setVgap(3);
            final JPanel panel = new JPanel(layout);
            panel.add(label, BorderLayout.NORTH);
            panel.add(listComponent, BorderLayout.CENTER);
            listComponent.setBorder(BorderFactory.createEmptyBorder(0, 0, 3, 0));
            if (comboBox.getItemCount() == 0 || (comboBox.getItemCount() == 1 && comboBox.getItemAt(0) == NONE_TOOL)) {
                return null;
            }
            return new RefreshableOnComponent() {

                @Override
                public JComponent getComponent() {
                    return panel;
                }

                @Override
                public void refresh() {
                    String id = config.getAfterCommitToolsId();
                    if (id == null) {
                        comboBox.setSelectedIndex(-1);
                    } else {
                        for (int i = 0; i < comboBox.getItemCount(); i++) {
                            final Object itemAt = comboBox.getItemAt(i);
                            if (itemAt instanceof Tool && id.equals(((Tool) itemAt).getActionId())) {
                                comboBox.setSelectedIndex(i);
                                return;
                            }
                        }
                    }
                }

                @Override
                public void saveState() {
                    Object item = comboBox.getSelectedItem();
                    config.setAfterCommitToolId(item instanceof Tool ? ((Tool) item).getActionId() : null);
                }

                @Override
                public void restoreState() {
                    refresh();
                }
            };
        }

        @Override
        public void checkinSuccessful() {
            final String id = config.getAfterCommitToolsId();
            if (id == null) {
                return;
            }
            DataManager.getInstance().getDataContextFromFocus().doWhenDone(new Consumer<DataContext>() {

                @Override
                public void consume(final DataContext context) {
                    UIUtil.invokeAndWaitIfNeeded(new Runnable() {

                        @Override
                        public void run() {
                            ToolAction.runTool(id, context);
                        }
                    });
                }
            });
        }
    };
}
Also used : ActionEvent(java.awt.event.ActionEvent) DataContext(com.intellij.openapi.actionSystem.DataContext) CollectionComboBoxModel(com.intellij.ui.CollectionComboBoxModel) Disposable(com.intellij.openapi.Disposable) CheckinHandler(com.intellij.openapi.vcs.checkin.CheckinHandler) ActionListener(java.awt.event.ActionListener) ComboboxWithBrowseButton(com.intellij.ui.ComboboxWithBrowseButton) RefreshableOnComponent(com.intellij.openapi.vcs.ui.RefreshableOnComponent) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with RefreshableOnComponent

use of com.intellij.openapi.vcs.ui.RefreshableOnComponent in project intellij-community by JetBrains.

the class TodoCheckinHandler method getBeforeCheckinConfigurationPanel.

@Override
public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
    JCheckBox checkBox = new JCheckBox(VcsBundle.message("before.checkin.new.todo.check", ""));
    return new RefreshableOnComponent() {

        @Override
        public JComponent getComponent() {
            JPanel panel = new JPanel(new BorderLayout(4, 0));
            panel.add(checkBox, BorderLayout.WEST);
            setFilterText(myConfiguration.myTodoPanelSettings.todoFilterName);
            if (myConfiguration.myTodoPanelSettings.todoFilterName != null) {
                myTodoFilter = TodoConfiguration.getInstance().getTodoFilter(myConfiguration.myTodoPanelSettings.todoFilterName);
            }
            Consumer<TodoFilter> consumer = todoFilter -> {
                myTodoFilter = todoFilter;
                String name = todoFilter == null ? null : todoFilter.getName();
                myConfiguration.myTodoPanelSettings.todoFilterName = name;
                setFilterText(name);
            };
            LinkLabel linkLabel = new LinkLabel("Configure", null);
            linkLabel.setListener(new LinkListener() {

                @Override
                public void linkSelected(LinkLabel aSource, Object aLinkData) {
                    DefaultActionGroup group = SetTodoFilterAction.createPopupActionGroup(myProject, myConfiguration.myTodoPanelSettings, consumer);
                    ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.TODO_VIEW_TOOLBAR, group);
                    popupMenu.getComponent().show(linkLabel, 0, linkLabel.getHeight());
                }
            }, null);
            panel.add(linkLabel, BorderLayout.CENTER);
            CheckinHandlerUtil.disableWhenDumb(myProject, checkBox, "TODO check is impossible until indices are up-to-date");
            return panel;
        }

        private void setFilterText(String filterName) {
            if (filterName == null) {
                checkBox.setText(VcsBundle.message("before.checkin.new.todo.check", IdeBundle.message("action.todo.show.all")));
            } else {
                checkBox.setText(VcsBundle.message("before.checkin.new.todo.check", "Filter: " + filterName));
            }
        }

        @Override
        public void refresh() {
        }

        @Override
        public void saveState() {
            myConfiguration.CHECK_NEW_TODO = checkBox.isSelected();
        }

        @Override
        public void restoreState() {
            checkBox.setSelected(myConfiguration.CHECK_NEW_TODO);
        }
    };
}
Also used : ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) DateFormatUtil(com.intellij.util.text.DateFormatUtil) LinkListener(com.intellij.ui.components.labels.LinkListener) Change(com.intellij.openapi.vcs.changes.Change) UIUtil.getWarningIcon(com.intellij.util.ui.UIUtil.getWarningIcon) ModalityState(com.intellij.openapi.application.ModalityState) PairConsumer(com.intellij.util.PairConsumer) com.intellij.ide.todo(com.intellij.ide.todo) ActionManager(com.intellij.openapi.actionSystem.ActionManager) VcsConfiguration(com.intellij.openapi.vcs.VcsConfiguration) Task(com.intellij.openapi.progress.Task) ActionPopupMenu(com.intellij.openapi.actionSystem.ActionPopupMenu) ApplicationNamesInfo(com.intellij.openapi.application.ApplicationNamesInfo) Project(com.intellij.openapi.project.Project) LinkLabel(com.intellij.ui.components.labels.LinkLabel) Messages(com.intellij.openapi.ui.Messages) CommitExecutor(com.intellij.openapi.vcs.changes.CommitExecutor) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ProgressManager(com.intellij.openapi.progress.ProgressManager) DumbService(com.intellij.openapi.project.DumbService) CheckinProjectPanel(com.intellij.openapi.vcs.CheckinProjectPanel) ToolWindow(com.intellij.openapi.wm.ToolWindow) StringUtil(com.intellij.openapi.util.text.StringUtil) Collection(java.util.Collection) Content(com.intellij.ui.content.Content) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) RefreshableOnComponent(com.intellij.openapi.vcs.ui.RefreshableOnComponent) VcsBundle(com.intellij.openapi.vcs.VcsBundle) java.awt(java.awt) IdeBundle(com.intellij.ide.IdeBundle) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ServiceManager(com.intellij.openapi.components.ServiceManager) ActionPlaces(com.intellij.openapi.actionSystem.ActionPlaces) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ContentManager(com.intellij.ui.content.ContentManager) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) Consumer(com.intellij.util.Consumer) javax.swing(javax.swing) CommonBundle.getCancelButtonText(com.intellij.CommonBundle.getCancelButtonText) LinkListener(com.intellij.ui.components.labels.LinkListener) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) LinkLabel(com.intellij.ui.components.labels.LinkLabel) ActionPopupMenu(com.intellij.openapi.actionSystem.ActionPopupMenu) RefreshableOnComponent(com.intellij.openapi.vcs.ui.RefreshableOnComponent)

Example 5 with RefreshableOnComponent

use of com.intellij.openapi.vcs.ui.RefreshableOnComponent in project intellij-community by JetBrains.

the class UpdateCopyrightCheckinHandlerFactory method createHandler.

@NotNull
public CheckinHandler createHandler(@NotNull final CheckinProjectPanel panel, @NotNull CommitContext commitContext) {
    return new CheckinHandler() {

        @Override
        public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
            final JCheckBox updateCopyrightCb = new JCheckBox("Update copyright");
            return new RefreshableOnComponent() {

                public JComponent getComponent() {
                    return JBUI.Panels.simplePanel().addToLeft(updateCopyrightCb);
                }

                public void refresh() {
                }

                public void saveState() {
                    UpdateCopyrightCheckinHandlerState.getInstance(panel.getProject()).UPDATE_COPYRIGHT = updateCopyrightCb.isSelected();
                }

                public void restoreState() {
                    updateCopyrightCb.setSelected(UpdateCopyrightCheckinHandlerState.getInstance(panel.getProject()).UPDATE_COPYRIGHT);
                }
            };
        }

        @Override
        public ReturnResult beforeCheckin(@Nullable CommitExecutor executor, PairConsumer<Object, Object> additionalDataConsumer) {
            if (UpdateCopyrightCheckinHandlerState.getInstance(panel.getProject()).UPDATE_COPYRIGHT) {
                new UpdateCopyrightProcessor(panel.getProject(), null, getPsiFiles()).run();
                FileDocumentManager.getInstance().saveAllDocuments();
            }
            return super.beforeCheckin();
        }

        private PsiFile[] getPsiFiles() {
            final Collection<VirtualFile> files = panel.getVirtualFiles();
            final List<PsiFile> psiFiles = new ArrayList<>();
            final PsiManager manager = PsiManager.getInstance(panel.getProject());
            for (final VirtualFile file : files) {
                final PsiFile psiFile = manager.findFile(file);
                if (psiFile != null) {
                    psiFiles.add(psiFile);
                }
            }
            return PsiUtilCore.toPsiFileArray(psiFiles);
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) PsiManager(com.intellij.psi.PsiManager) CheckinHandler(com.intellij.openapi.vcs.checkin.CheckinHandler) CommitExecutor(com.intellij.openapi.vcs.changes.CommitExecutor) PairConsumer(com.intellij.util.PairConsumer) RefreshableOnComponent(com.intellij.openapi.vcs.ui.RefreshableOnComponent) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

RefreshableOnComponent (com.intellij.openapi.vcs.ui.RefreshableOnComponent)5 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)4 CommitExecutor (com.intellij.openapi.vcs.changes.CommitExecutor)3 CheckinHandler (com.intellij.openapi.vcs.checkin.CheckinHandler)3 PairConsumer (com.intellij.util.PairConsumer)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiFile (com.intellij.psi.PsiFile)2 PsiManager (com.intellij.psi.PsiManager)2 GoFile (com.goide.psi.GoFile)1 CommonBundle.getCancelButtonText (com.intellij.CommonBundle.getCancelButtonText)1 IdeBundle (com.intellij.ide.IdeBundle)1 com.intellij.ide.todo (com.intellij.ide.todo)1 Disposable (com.intellij.openapi.Disposable)1 ActionManager (com.intellij.openapi.actionSystem.ActionManager)1 ActionPlaces (com.intellij.openapi.actionSystem.ActionPlaces)1 ActionPopupMenu (com.intellij.openapi.actionSystem.ActionPopupMenu)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1