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));
}
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;
}
};
}
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);
}
});
}
});
}
};
}
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);
}
};
}
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);
}
};
}
Aggregations