mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
[ui] Update UI in PerFileConfigurableBase
#IJPL-163682 Fixed GitOrigin-RevId: a6e9cd10f59be52a60e72a06377e102cb7c7cb51
This commit is contained in:
committed by
intellij-monorepo-bot
parent
64959bc2d6
commit
cbff17a5a3
@@ -19392,7 +19392,6 @@ a:com.intellij.util.ui.tree.PerFileConfigurableBase
|
||||
- p:createActionPanel(com.intellij.openapi.actionSystem.AnAction):javax.swing.JPanel
|
||||
- p:createActionPanel(java.lang.Object,com.intellij.util.ui.tree.PerFileConfigurableBase$Value):javax.swing.JPanel
|
||||
- createComponent():javax.swing.JComponent
|
||||
- p:createDefaultMappingComponent():javax.swing.JComponent
|
||||
- pf:createValueAction(java.lang.Object,com.intellij.util.ui.tree.PerFileConfigurableBase$Value):com.intellij.openapi.actionSystem.AnAction
|
||||
- pf:createValueEditorActionListPopup(java.lang.Object,java.lang.Runnable,com.intellij.openapi.actionSystem.DataContext,com.intellij.util.Consumer):com.intellij.openapi.ui.popup.JBPopup
|
||||
- p:createValueEditorPopup(java.lang.Object,java.lang.Object,java.lang.Runnable,com.intellij.openapi.actionSystem.DataContext,com.intellij.util.Consumer,java.lang.Runnable):com.intellij.openapi.ui.popup.JBPopup
|
||||
|
||||
@@ -34,7 +34,6 @@ import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.ui.speedSearch.SpeedSearchUtil;
|
||||
import com.intellij.ui.table.JBTable;
|
||||
import com.intellij.util.Consumer;
|
||||
@@ -44,8 +43,6 @@ import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.concurrency.ThreadingAssertions;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.AbstractTableCellEditor;
|
||||
import com.intellij.util.ui.JBInsets;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
@@ -64,7 +61,6 @@ import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.intellij.openapi.util.Pair.pair;
|
||||
import static com.intellij.ui.IdeBorderFactory.*;
|
||||
|
||||
public abstract class PerFileConfigurableBase<T> implements SearchableConfigurable, Configurable.NoScroll {
|
||||
public record Mapping<T>(@Nls String name, @NotNull Supplier<? extends T> getter, @NotNull Consumer<? super T> setter) {
|
||||
@@ -145,7 +141,6 @@ public abstract class PerFileConfigurableBase<T> implements SearchableConfigurab
|
||||
public @NotNull JComponent createComponent() {
|
||||
ThreadingAssertions.assertEventDispatchThread();
|
||||
//todo multi-editing, separate project/ide combos _if_ needed by specific configurable (SQL, no Web)
|
||||
myPanel = new JPanel(new BorderLayout());
|
||||
myModel = new MyModel<>(param(TARGET_TITLE), param(MAPPING_TITLE));
|
||||
myTable = new JBTable(myModel) {
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -171,17 +166,31 @@ public abstract class PerFileConfigurableBase<T> implements SearchableConfigurab
|
||||
.createPanel();
|
||||
myTable.getEmptyText().setText(param(EMPTY_TEXT).replace(
|
||||
"$addShortcut", KeymapUtil.getFirstKeyboardShortcutText(CommonActionsPanel.getCommonShortcut(CommonActionsPanel.Buttons.ADD))));
|
||||
JBLabel label = new JBLabel(param(DESCRIPTION));
|
||||
label.setBorder(BorderFactory.createEmptyBorder(TITLED_BORDER_TOP_INSET, TITLED_BORDER_INDENT, TITLED_BORDER_BOTTOM_INSET, 0));
|
||||
label.setComponentStyle(UIUtil.ComponentStyle.SMALL);
|
||||
|
||||
JComponent north = createDefaultMappingComponent();
|
||||
if (north != null) {
|
||||
myPanel.add(north, BorderLayout.NORTH);
|
||||
myDefaultProps.addAll(getDefaultMappings());
|
||||
if (myMappings instanceof LanguagePerFileMappings && param(ADD_PROJECT_MAPPING)) {
|
||||
myDefaultProps.add(myProjectMapping);
|
||||
}
|
||||
for (Mapping<T> prop : myDefaultProps) {
|
||||
myDefaultVals.put(prop.name, prop.getter.get());
|
||||
}
|
||||
myPanel.add(label, BorderLayout.SOUTH);
|
||||
myPanel.add(tablePanel, BorderLayout.CENTER);
|
||||
|
||||
myPanel = new PerFileConfigurableBaseUi<T>().getPanel(tablePanel, param(DESCRIPTION), myDefaultProps, (Mapping<T> prop) -> createActionPanel(null, new Value<>() {
|
||||
@Override
|
||||
public void commit() {
|
||||
myModel.fireTableDataChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get() {
|
||||
return myDefaultVals.get(prop.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(T value) {
|
||||
myDefaultVals.put(prop.name, adjustChosenValue(null, value));
|
||||
}
|
||||
}));
|
||||
return myPanel;
|
||||
}
|
||||
|
||||
@@ -189,52 +198,6 @@ public abstract class PerFileConfigurableBase<T> implements SearchableConfigurab
|
||||
return null;
|
||||
}
|
||||
|
||||
protected @Nullable JComponent createDefaultMappingComponent() {
|
||||
myDefaultProps.addAll(getDefaultMappings());
|
||||
if (myMappings instanceof LanguagePerFileMappings && param(ADD_PROJECT_MAPPING)) {
|
||||
myDefaultProps.add(myProjectMapping);
|
||||
}
|
||||
if (myDefaultProps.size() == 0) return null;
|
||||
JPanel panel = new JPanel(new GridBagLayout());
|
||||
|
||||
GridBagConstraints cons1 = new GridBagConstraints();
|
||||
cons1.fill = GridBagConstraints.HORIZONTAL;
|
||||
cons1.weightx = 0;
|
||||
cons1.gridx = 0;
|
||||
cons1.insets = JBUI.insets(0, 0, 5, UIUtil.DEFAULT_HGAP);
|
||||
GridBagConstraints cons2 = new GridBagConstraints();
|
||||
cons2.fill = GridBagConstraints.NONE;
|
||||
cons2.anchor = GridBagConstraints.WEST;
|
||||
cons2.weightx = 0;
|
||||
cons2.gridx = 1;
|
||||
cons2.insets = cons1.insets;
|
||||
panel.add(Box.createGlue(), new GridBagConstraints(2, 0, 1, 1, 1., 1., GridBagConstraints.CENTER, GridBagConstraints.NONE,
|
||||
JBInsets.emptyInsets(), 0, 0));
|
||||
|
||||
for (Mapping<T> prop : myDefaultProps) {
|
||||
myDefaultVals.put(prop.name, prop.getter.get());
|
||||
JPanel p = createActionPanel(null, new Value<>() {
|
||||
@Override
|
||||
public void commit() {
|
||||
myModel.fireTableDataChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get() {
|
||||
return myDefaultVals.get(prop.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(T value) {
|
||||
myDefaultVals.put(prop.name, adjustChosenValue(null, value));
|
||||
}
|
||||
});
|
||||
panel.add(new JBLabel(prop.name + ":"), cons1);
|
||||
panel.add(p, cons2);
|
||||
}
|
||||
return panel;
|
||||
}
|
||||
|
||||
private void doAddAction() {
|
||||
TableCellEditor editor = myTable.getCellEditor();
|
||||
if (editor != null) editor.cancelCellEditing();
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.util.ui.tree
|
||||
|
||||
import com.intellij.openapi.ui.DialogPanel
|
||||
import com.intellij.openapi.util.NlsContexts
|
||||
import com.intellij.ui.dsl.builder.Align
|
||||
import com.intellij.ui.dsl.builder.panel
|
||||
import javax.swing.JPanel
|
||||
|
||||
internal class PerFileConfigurableBaseUi<T> {
|
||||
|
||||
fun getPanel(
|
||||
tablePanel: JPanel,
|
||||
tableComment: @NlsContexts.DetailedDescription String,
|
||||
defaultProps: List<PerFileConfigurableBase.Mapping<T>>,
|
||||
actionPanelProvider: (PerFileConfigurableBase.Mapping<T>) -> JPanel,
|
||||
): DialogPanel = panel {
|
||||
for (prop in defaultProps) {
|
||||
row(prop.name + ":") {
|
||||
cell(actionPanelProvider(prop))
|
||||
}
|
||||
}
|
||||
|
||||
row {
|
||||
cell(tablePanel)
|
||||
.align(Align.FILL)
|
||||
.apply {
|
||||
if (tableComment.isNotEmpty()) { comment(tableComment) }
|
||||
}
|
||||
}.resizableRow()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user