Grid: Java => Kotlin (conversion), add logging of page size changes

GitOrigin-RevId: e1f7ab9ccba220900543cae03c120c0a60166d84
This commit is contained in:
Ilya Muradyan
2025-06-01 13:43:28 +02:00
committed by intellij-monorepo-bot
parent 3ef0fc8e21
commit 731b8d273c
6 changed files with 318 additions and 359 deletions

View File

@@ -1,56 +1,30 @@
package com.intellij.database.run.actions; package com.intellij.database.run.actions
import com.intellij.database.DataGridBundle; import com.intellij.database.DataGridBundle
import com.intellij.database.DatabaseDataKeys; import com.intellij.database.DatabaseDataKeys
import com.intellij.database.datagrid.*; import com.intellij.database.datagrid.GridPagingModel
import com.intellij.database.run.ui.DataGridRequestPlace; import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.ide.ActivityTracker; import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.ActionUpdateThread; import com.intellij.openapi.project.DumbAwareAction
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.DumbAwareAction;
import org.jetbrains.annotations.NotNull;
import static com.intellij.database.datagrid.GridPagingModel.UNLIMITED_PAGE_SIZE; class ChangePageSizeAction(private val myPageSize: Int) : DumbAwareAction(if (myPageSize == GridPagingModel.UNLIMITED_PAGE_SIZE) DataGridBundle.message("action.ChangePageSize.text.all") else format(myPageSize.toLong()),
import static com.intellij.database.run.actions.ChangePageSizeActionGroup.format; if (myPageSize == GridPagingModel.UNLIMITED_PAGE_SIZE)
DataGridBundle.message("action.ChangePageSize.description.all")
public class ChangePageSizeAction extends DumbAwareAction { else
private final int myPageSize; DataGridBundle.message("action.ChangePageSize.description.some", format(myPageSize.toLong())),
null) {
public ChangePageSizeAction(int pageSize) { override fun getActionUpdateThread(): ActionUpdateThread {
super(pageSize == UNLIMITED_PAGE_SIZE ? DataGridBundle.message("action.ChangePageSize.text.all") : format(pageSize), return ActionUpdateThread.BGT
pageSize == UNLIMITED_PAGE_SIZE ? DataGridBundle.message("action.ChangePageSize.description.all")
: DataGridBundle.message("action.ChangePageSize.description.some", format(pageSize)),
null);
myPageSize = pageSize;
} }
@Override override fun update(e: AnActionEvent) {
public @NotNull ActionUpdateThread getActionUpdateThread() { val grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY)
return ActionUpdateThread.BGT; e.presentation.setEnabledAndVisible(grid != null)
} }
@Override override fun actionPerformed(e: AnActionEvent) {
public void update(@NotNull AnActionEvent e) { val grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY)
DataGrid grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY); if (grid == null) return
e.getPresentation().setEnabledAndVisible(grid != null); setPageSizeAndReload(myPageSize, grid)
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
DataGrid grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY);
if (grid == null) return;
setPageSizeAndReload(myPageSize, grid);
}
public static void setPageSizeAndReload(int pageSize, @NotNull DataGrid grid) {
GridPagingModel<GridRow, GridColumn> pageModel = grid.getDataHookup().getPageModel();
pageModel.setPageSize(pageSize);
ActivityTracker.getInstance().inc();
GridLoader loader = grid.getDataHookup().getLoader();
GridRequestSource source = new GridRequestSource(new DataGridRequestPlace(grid));
if (GridUtilCore.isPageSizeUnlimited(pageSize)) loader.load(source, 0);
else loader.reloadCurrentPage(source);
} }
} }

View File

@@ -1,273 +1,222 @@
package com.intellij.database.run.actions; package com.intellij.database.run.actions
import com.intellij.database.DataGridBundle; import com.intellij.database.DataGridBundle
import com.intellij.database.DatabaseDataKeys; import com.intellij.database.DatabaseDataKeys
import com.intellij.database.datagrid.*; import com.intellij.database.datagrid.*
import com.intellij.database.run.ui.FloatingPagingManager; import com.intellij.database.run.ui.FloatingPagingManager
import com.intellij.database.settings.DataGridSettings; import com.intellij.database.run.ui.FloatingPagingManager.Companion.adjustAction
import com.intellij.database.util.DataGridUIUtil; import com.intellij.database.settings.DataGridSettings
import com.intellij.openapi.actionSystem.*; import com.intellij.database.util.DataGridUIUtil
import com.intellij.openapi.actionSystem.ex.CustomComponentAction; import com.intellij.openapi.actionSystem.*
import com.intellij.openapi.actionSystem.impl.ActionButtonWithText; import com.intellij.openapi.actionSystem.ex.CustomComponentAction
import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.DumbAwareAction
import com.intellij.openapi.roots.ui.configuration.actions.AlignedIconWithTextAction; import com.intellij.openapi.ui.popup.JBPopup
import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.ui.popup.JBPopupFactory
import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.util.Key
import com.intellij.openapi.util.Key; import com.intellij.openapi.util.NlsActions
import com.intellij.openapi.util.NlsActions; import com.intellij.openapi.util.NlsContexts
import com.intellij.openapi.util.NlsContexts; import com.intellij.util.containers.ContainerUtil
import com.intellij.util.containers.ContainerUtil; import java.awt.Component
import com.intellij.util.ui.JBInsets; import java.util.*
import org.jetbrains.annotations.NotNull; import javax.swing.JComponent
import org.jetbrains.annotations.Nullable;
import javax.swing.*; private val DEFAULT_PAGE_SIZES = mutableListOf(10, 100, 500, 1000)
import java.awt.*; private val PAGE_SIZE_KEY = Key<Int?>("DATA_GRID_PAGE_SIZE_KEY")
import java.util.ArrayList; private val SHOW_COUNT_ALL_ACTION_KEY = Key<Boolean?>("DATA_GRID_SHOW_COUNT_ALL_ACTION_KEY")
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import static com.intellij.database.datagrid.GridPagingModel.UNLIMITED_PAGE_SIZE; class ChangePageSizeActionGroup : DefaultActionGroup(), CustomComponentAction, DumbAware {
import static com.intellij.database.datagrid.GridPagingModel.UNSET_PAGE_SIZE; override fun getActionUpdateThread(): ActionUpdateThread {
import static com.intellij.database.datagrid.GridUtil.getSettings; return ActionUpdateThread.EDT
import static com.intellij.database.datagrid.GridUtil.hidePageActions;
public class ChangePageSizeActionGroup extends DefaultActionGroup implements CustomComponentAction, DumbAware {
private static final List<Integer> DEFAULT_PAGE_SIZES = Arrays.asList(10, 100, 500, 1000);
private static final Key<Integer> PAGE_SIZE_KEY = new Key<>("DATA_GRID_PAGE_SIZE_KEY");
private static final Key<Boolean> SHOW_COUNT_ALL_ACTION_KEY = new Key<>("DATA_GRID_SHOW_COUNT_ALL_ACTION_KEY");
@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.EDT;
} }
public ChangePageSizeActionGroup() { init {
setPopup(true); isPopup = true
setActions(DEFAULT_PAGE_SIZES, false); setActions(DEFAULT_PAGE_SIZES, false)
} }
private void setActions(List<Integer> sizes, boolean isSinglePage) { private fun setActions(sizes: MutableList<Int>, isSinglePage: Boolean) {
removeAll(); removeAll()
if (isSinglePage) { if (isSinglePage) {
add(new MyCountRowsAction()); add(MyCountRowsAction())
} }
addSeparator(DataGridBundle.message("separator.page.size")); addSeparator(DataGridBundle.message("separator.page.size"))
for (Integer pageSize : sizes) { for (pageSize in sizes) {
add(new ChangePageSizeAction(pageSize)); add(ChangePageSizeAction(pageSize))
} }
add(new ChangePageSizeAction(UNLIMITED_PAGE_SIZE)); add(ChangePageSizeAction(GridPagingModel.UNLIMITED_PAGE_SIZE))
add(new SetCustomPageSizeAction()); add(SetCustomPageSizeAction())
add(new Separator()); add(Separator())
add(new SetDefaultPageSizeAction()); add(SetDefaultPageSizeAction())
} }
@Override override fun update(e: AnActionEvent) {
public void update(@NotNull AnActionEvent e) { val grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY)
DataGrid grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY); if (grid == null || grid.getDataHookup() is DocumentDataHookUp) {
if (grid == null || grid.getDataHookup() instanceof DocumentDataHookUp) { e.presentation.setEnabledAndVisible(false)
e.getPresentation().setEnabledAndVisible(false); return
return;
} }
if (grid.getDataHookup().getPageModel() instanceof NestedTableGridPagingModel<GridRow, GridColumn> nestedPageModel && if ((grid.getDataHookup().getPageModel() as? NestedTableGridPagingModel<GridRow?, GridColumn?>)?.isStatic == true) {
nestedPageModel.isStatic()) { e.presentation.setEnabledAndVisible(false)
e.getPresentation().setEnabledAndVisible(false); return
return;
} }
if (FloatingPagingManager.adjustAction(e) == FloatingPagingManager.AdjustmentResult.HIDDEN) { if (adjustAction(e) == FloatingPagingManager.AdjustmentResult.HIDDEN) {
return; return
} }
ChangePageSizeActionState state = getActionState(grid); val state = getActionState(grid)
if (hidePageActions(grid, e.getPlace())) { if (GridUtil.hidePageActions(grid, e.place)) {
e.getPresentation().setVisible(false); e.presentation.setVisible(false)
} }
else { else {
e.getPresentation().setVisible(true); e.presentation.setVisible(true)
updatePresentation(state, e.getPresentation(), getSettings(grid)); updatePresentation(state, e.presentation, GridUtil.getSettings(grid))
} }
} }
@Override override fun actionPerformed(e: AnActionEvent) {
public void actionPerformed(@NotNull AnActionEvent e) { val component: Component? = e.presentation.getClientProperty(CustomComponentAction.COMPONENT_KEY)
Component component = e.getPresentation().getClientProperty(COMPONENT_KEY); val popup: JBPopup = JBPopupFactory.getInstance().createActionGroupPopup(null, this, e.dataContext, null, true, null)
JBPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(null, this, e.getDataContext(), null, true, null);
if (component == null) { if (component == null) {
DataGridUIUtil.showPopup(popup, null, e); DataGridUIUtil.showPopup(popup, null, e)
return; return
} }
popup.showUnderneathOf(component); popup.showUnderneathOf(component)
} }
static @NotNull String format(long num) { override fun createCustomComponent(presentation: Presentation, place: String): JComponent {
return String.format("%,d", num); return createCustomComponentForResultViewToolbar(this, presentation, place)
} }
@Override private fun updatePresentation(state: ChangePageSizeActionState, presentation: Presentation, settings: DataGridSettings?) {
public @NotNull JComponent createCustomComponent(@NotNull Presentation presentation, @NotNull String place) { val oldState = getActionState(presentation)
return createCustomComponentForResultViewToolbar(this, presentation, place); if (oldState == state) return
}
public static @NotNull JComponent createCustomComponentForResultViewToolbar(@NotNull AnAction action, presentation.setText(state.text)
@NotNull Presentation presentation, presentation.setDescription(state.description)
@NotNull String place) { presentation.setEnabled(state.enabled)
ActionButtonWithText c = new ActionButtonWithText(action, presentation, place, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE) { presentation.putClientProperty<Int?>(PAGE_SIZE_KEY, state.pageSize)
@Override presentation.putClientProperty<Boolean?>(SHOW_COUNT_ALL_ACTION_KEY, state.showCountAllAction)
public Insets getInsets() {
return new JBInsets(0, 0, 0, 0);
}
};
return AlignedIconWithTextAction.align(c);
}
private void updatePresentation(ChangePageSizeActionState state, Presentation presentation, @Nullable DataGridSettings settings) { val component = presentation.getClientProperty(CustomComponentAction.COMPONENT_KEY)
ChangePageSizeActionState oldState = getActionState(presentation);
if (oldState.equals(state)) return;
presentation.setText(state.text);
presentation.setDescription(state.description);
presentation.setEnabled(state.enabled);
presentation.putClientProperty(PAGE_SIZE_KEY, state.pageSize);
presentation.putClientProperty(SHOW_COUNT_ALL_ACTION_KEY, state.showCountAllAction);
JComponent component = presentation.getClientProperty(COMPONENT_KEY);
if (component != null) { if (component != null) {
component.setToolTipText(state.tooltip); component.setToolTipText(state.tooltip)
component.repaint(); component.repaint()
} }
List<Integer> pageSizes = new ArrayList<>(DEFAULT_PAGE_SIZES); val pageSizes: MutableList<Int> = ArrayList<Int>(DEFAULT_PAGE_SIZES)
pageSizes.add(GridUtilCore.getPageSize(settings)); pageSizes.add(GridUtilCore.getPageSize(settings))
if (state.pageSize > 0) { if (state.pageSize > 0) {
pageSizes.add(state.pageSize * 2); pageSizes.add(state.pageSize * 2)
int halfSize = state.pageSize / 2; val halfSize = state.pageSize / 2
if (halfSize > 0) pageSizes.add(halfSize); if (halfSize > 0) pageSizes.add(halfSize)
ContainerUtil.removeAll(pageSizes, state.pageSize); ContainerUtil.removeAll(pageSizes, state.pageSize)
} }
ContainerUtil.removeDuplicates(pageSizes); ContainerUtil.removeDuplicates(pageSizes)
ContainerUtil.sort(pageSizes); ContainerUtil.sort(pageSizes)
setActions(pageSizes, state.showCountAllAction); setActions(pageSizes, state.showCountAllAction)
} }
private static @NotNull ChangePageSizeActionState getActionState(@NotNull Presentation presentation) { }
JComponent component = presentation.getClientProperty(COMPONENT_KEY);
String text = presentation.getText(); private fun getActionState(presentation: Presentation): ChangePageSizeActionState {
String description = presentation.getDescription(); val component = presentation.getClientProperty(CustomComponentAction.COMPONENT_KEY)
String tooltip = component != null ? component.getToolTipText() : null;
boolean loading = presentation.isEnabled();
Integer pageSize = presentation.getClientProperty(PAGE_SIZE_KEY);
if (pageSize == null) pageSize = UNSET_PAGE_SIZE;
Boolean showCountAllAction = presentation.getClientProperty(SHOW_COUNT_ALL_ACTION_KEY);
if (showCountAllAction == null) showCountAllAction = false;
return new ChangePageSizeActionState(text, description, tooltip, loading, pageSize, showCountAllAction); val text = presentation.text
val description = presentation.description
val tooltip = component?.toolTipText
val loading = presentation.isEnabled
var pageSize = presentation.getClientProperty<Int?>(PAGE_SIZE_KEY)
if (pageSize == null) pageSize = GridPagingModel.UNSET_PAGE_SIZE
var showCountAllAction = presentation.getClientProperty<Boolean?>(SHOW_COUNT_ALL_ACTION_KEY)
if (showCountAllAction == null) showCountAllAction = false
return ChangePageSizeActionState(text, description, tooltip, loading, pageSize, showCountAllAction)
}
private fun getActionState(grid: DataGrid): ChangePageSizeActionState {
val pageModel = grid.getDataHookup().getPageModel()
val pageStartIdx = pageModel.getPageStart()
val pageEndIdx = pageModel.getPageEnd()
val totalRowCount = pageModel.getTotalRowCount()
val rowsWereDeleted = totalRowCount < pageEndIdx
val isSinglePage = pageModel.isFirstPage() && pageModel.isLastPage() && !rowsWereDeleted
val text = if (isSinglePage) (format(totalRowCount) +
" " +
(if (totalRowCount == 1L)
DataGridBundle.message("action.Console.TableResult.ChangePageSize.row")
else
DataGridBundle.message("action.Console.TableResult.ChangePageSize.rows")))
else if (pageEndIdx == 0)
"0 " + DataGridBundle.message("action.Console.TableResult.ChangePageSize.rows")
else
format(pageStartIdx.toLong()) + "-" + format(pageEndIdx.toLong())
val querying = grid.getDataHookup().getBusyCount() > 0
val enabled = !querying && grid.isReady()
var description = DataGridBundle.message("group.Console.TableResult.ChangePageSize.description")
var tooltip = DataGridBundle.message("group.Console.TableResult.ChangePageSize.description")
if (!enabled) {
val unavailableText = if (querying) DataGridBundle.message("action.Console.TableResult.ChangePageSize.querying") else ""
description = unavailableText
tooltip = unavailableText
} }
private static @NotNull ChangePageSizeActionState getActionState(@NotNull DataGrid grid) { val showCountRowsAction = isSinglePage && pageModel.isTotalRowCountUpdateable() && !querying && grid.isReady()
GridPagingModel<GridRow, GridColumn> pageModel = grid.getDataHookup().getPageModel(); return ChangePageSizeActionState(text, description, tooltip, enabled, pageModel.getPageSize(), showCountRowsAction)
}
int pageStartIdx = pageModel.getPageStart(); private fun updateIsTotalRowCountUpdateable(grid: DataGrid) {
int pageEndIdx = pageModel.getPageEnd(); grid.getDataHookup().getLoader().updateIsTotalRowCountUpdateable()
long totalRowCount = pageModel.getTotalRowCount(); }
boolean rowsWereDeleted = totalRowCount < pageEndIdx; private class ChangePageSizeActionState(
boolean isSinglePage = pageModel.isFirstPage() && pageModel.isLastPage() && !rowsWereDeleted; val text: @NlsActions.ActionText String?,
String text = isSinglePage ? val description: @NlsActions.ActionDescription String?,
format(totalRowCount) + val tooltip: @NlsContexts.Tooltip String?,
" " + val enabled: Boolean,
(totalRowCount == 1 val pageSize: Int,
? DataGridBundle.message("action.Console.TableResult.ChangePageSize.row") val showCountAllAction: Boolean,
: DataGridBundle.message("action.Console.TableResult.ChangePageSize.rows")) : ) {
pageEndIdx == 0 override fun equals(other: Any?): Boolean {
? "0 " + DataGridBundle.message("action.Console.TableResult.ChangePageSize.rows") if (this === other) return true
: format(pageStartIdx) + "-" + format(pageEndIdx); if (other == null || javaClass != other.javaClass) return false
val state = other as ChangePageSizeActionState
boolean querying = grid.getDataHookup().getBusyCount() > 0; return enabled == state.enabled && pageSize == state.pageSize &&
boolean enabled = !querying && grid.isReady(); text == state.text &&
description == state.description &&
String description = DataGridBundle.message("group.Console.TableResult.ChangePageSize.description"); tooltip == state.tooltip
String tooltip = DataGridBundle.message("group.Console.TableResult.ChangePageSize.description");
if (!enabled) {
String unavailableText = querying ? DataGridBundle.message("action.Console.TableResult.ChangePageSize.querying") : "";
description = unavailableText;
tooltip = unavailableText;
}
boolean showCountRowsAction = isSinglePage && pageModel.isTotalRowCountUpdateable() && !querying && grid.isReady();
return new ChangePageSizeActionState(text, description, tooltip, enabled, pageModel.getPageSize(), showCountRowsAction);
} }
private static void updateIsTotalRowCountUpdateable(@NotNull DataGrid grid) { override fun hashCode(): Int {
grid.getDataHookup().getLoader().updateIsTotalRowCountUpdateable(); return Objects.hash(text, description, tooltip, enabled, pageSize)
} }
}
private static class ChangePageSizeActionState {
final @NlsActions.ActionText String text; private class MyCountRowsAction : DumbAwareAction(
final @NlsActions.ActionDescription String description; DataGridBundle.message("action.CountRows.text"),
final @NlsContexts.Tooltip String tooltip; DataGridBundle.message("action.CountRows.description"),
final boolean enabled; null
final int pageSize; ) {
final boolean showCountAllAction; override fun actionPerformed(e: AnActionEvent) {
val grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY)
ChangePageSizeActionState(@NlsActions.ActionText String text, if (grid == null) {
@NlsActions.ActionDescription String description, e.presentation.setEnabledAndVisible(false)
@NlsContexts.Tooltip String tooltip, return
boolean enabled, }
int pageSize, updateIsTotalRowCountUpdateable(grid)
boolean showCountAllAction) { val pageModel = grid.getDataHookup().getPageModel()
this.text = text; if (!pageModel.isTotalRowCountUpdateable()) return
this.description = description; CountRowsAction.countRows(grid)
this.tooltip = tooltip; updateIsTotalRowCountUpdateable(grid)
this.enabled = enabled;
this.pageSize = pageSize;
this.showCountAllAction = showCountAllAction;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ChangePageSizeActionState state = (ChangePageSizeActionState)o;
return enabled == state.enabled &&
pageSize == state.pageSize &&
Objects.equals(text, state.text) &&
Objects.equals(description, state.description) &&
Objects.equals(tooltip, state.tooltip);
}
@Override
public int hashCode() {
return Objects.hash(text, description, tooltip, enabled, pageSize);
}
}
private static class MyCountRowsAction extends DumbAwareAction {
MyCountRowsAction() {
super(DataGridBundle.message("action.CountRows.text"), DataGridBundle.message("action.CountRows.description"), null);
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
DataGrid grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY);
if (grid == null) {
e.getPresentation().setEnabledAndVisible(false);
return;
}
updateIsTotalRowCountUpdateable(grid);
GridPagingModel<GridRow, GridColumn> pageModel = grid.getDataHookup().getPageModel();
if (!pageModel.isTotalRowCountUpdateable()) return;
CountRowsAction.countRows(grid);
updateIsTotalRowCountUpdateable(grid);
}
} }
} }

View File

@@ -0,0 +1,55 @@
package com.intellij.database.run.actions
import com.intellij.database.datagrid.DataGrid
import com.intellij.database.datagrid.GridRequestSource
import com.intellij.database.datagrid.GridUtilCore
import com.intellij.database.run.ui.DataGridRequestPlace
import com.intellij.ide.ActivityTracker
import com.intellij.openapi.actionSystem.ActionToolbar
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.Presentation
import com.intellij.openapi.actionSystem.impl.ActionButtonWithText
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.roots.ui.configuration.actions.AlignedIconWithTextAction
import com.intellij.openapi.util.NlsSafe
import com.intellij.util.ui.JBInsets
import java.awt.Insets
import javax.swing.JComponent
fun format(num: Long): @NlsSafe String {
return String.format("%,d", num)
}
fun createCustomComponentForResultViewToolbar(
action: AnAction,
presentation: Presentation,
place: String,
): JComponent {
val c: ActionButtonWithText = object : ActionButtonWithText(action, presentation, place, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE) {
override fun getInsets(): Insets {
return JBInsets(0, 0, 0, 0)
}
}
return AlignedIconWithTextAction.align(c)
}
fun setPageSizeAndReload(pageSize: Int, grid: DataGrid) {
val pageModel = grid.getDataHookup().getPageModel()
pageModel.setPageSize(pageSize)
ActivityTracker.getInstance().inc()
trace {
"Setting page size of grid $grid to $pageSize (page model: $pageModel)"
}
val loader = grid.getDataHookup().getLoader()
val source = GridRequestSource(DataGridRequestPlace(grid))
if (GridUtilCore.isPageSizeUnlimited(pageSize)) loader.load(source, 0)
else loader.reloadCurrentPage(source)
}
private fun trace(messageFactory: () -> String) {
val logger = logger<ChangePageSizeAction>()
if (logger.isTraceEnabled) {
logger.trace(messageFactory())
}
}

View File

@@ -30,7 +30,7 @@ import java.awt.*;
import java.util.Objects; import java.util.Objects;
import static com.intellij.database.datagrid.GridUtil.hidePageActions; import static com.intellij.database.datagrid.GridUtil.hidePageActions;
import static com.intellij.database.run.actions.ChangePageSizeActionGroup.format; import static com.intellij.database.run.actions.ChangePageSizeUtilKt.format;
public class CountRowsAction extends IconWithTextAction implements CustomComponentAction, GridAction { public class CountRowsAction extends IconWithTextAction implements CustomComponentAction, GridAction {
@Override @Override

View File

@@ -1,126 +1,105 @@
package com.intellij.database.run.actions; package com.intellij.database.run.actions
import com.intellij.database.DataGridBundle; import com.intellij.database.DataGridBundle
import com.intellij.database.DatabaseDataKeys; import com.intellij.database.DatabaseDataKeys
import com.intellij.database.datagrid.*; import com.intellij.database.datagrid.GridUtil
import com.intellij.database.run.ui.CustomPageSizeForm; import com.intellij.database.datagrid.GridUtilCore
import com.intellij.openapi.actionSystem.ActionUpdateThread; import com.intellij.database.run.ui.CustomPageSizeForm
import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.application.ApplicationBundle; import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.application.ApplicationBundle
import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.options.ConfigurationException
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.DumbAwareAction
import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.project.Project
import org.jetbrains.annotations.NotNull; import com.intellij.openapi.ui.DialogWrapper
import org.jetbrains.annotations.Nullable; import javax.swing.Icon
import javax.swing.JComponent
import javax.swing.event.DocumentEvent
import javax.swing.event.DocumentListener
import javax.swing.*; class SetCustomPageSizeAction : DumbAwareAction(ApplicationBundle.messagePointer("custom.option"), ApplicationBundle.messagePointer("custom.option.description"), null as Icon?) {
import javax.swing.event.DocumentEvent; override fun update(e: AnActionEvent) {
import javax.swing.event.DocumentListener; val grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY)
e.presentation.setEnabledAndVisible(grid != null)
import static com.intellij.database.run.actions.ChangePageSizeAction.setPageSizeAndReload;
public final class SetCustomPageSizeAction extends DumbAwareAction {
public SetCustomPageSizeAction() {
super(ApplicationBundle.messagePointer("custom.option"), ApplicationBundle.messagePointer("custom.option.description"), (Icon)null);
} }
@Override override fun getActionUpdateThread(): ActionUpdateThread {
public void update(@NotNull AnActionEvent e) { return ActionUpdateThread.BGT
DataGrid grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY);
e.getPresentation().setEnabledAndVisible(grid != null);
} }
@Override override fun actionPerformed(e: AnActionEvent) {
public @NotNull ActionUpdateThread getActionUpdateThread() { val grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY)
return ActionUpdateThread.BGT; if (grid == null) return
} val pageModel = grid.getDataHookup().getPageModel()
@Override object : SetPageSizeDialogWrapper(getEventProject(e)) {
public void actionPerformed(@NotNull AnActionEvent e) { override val pageSize: Int get() {
DataGrid grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY); val unlimited = GridUtilCore.isPageSizeUnlimited(pageModel.getPageSize())
if (grid == null) return; return if (unlimited) GridUtilCore.getPageSize(GridUtil.getSettings(grid)) else pageModel.getPageSize()
GridPagingModel<GridRow, GridColumn> pageModel = grid.getDataHookup().getPageModel();
new SetPageSizeDialogWrapper(getEventProject(e)) {
@Override
protected int getPageSize() {
boolean unlimited = GridUtilCore.isPageSizeUnlimited(pageModel.getPageSize());
return unlimited ? GridUtilCore.getPageSize(GridUtil.getSettings(grid)) : pageModel.getPageSize();
} }
@Override override val isLimitPageSize: Boolean get() {
protected boolean isLimitPageSize() { return !GridUtilCore.isPageSizeUnlimited(pageModel.getPageSize())
return !GridUtilCore.isPageSizeUnlimited(pageModel.getPageSize());
} }
@Override override fun doOKAction() {
protected void doOKAction() { super.doOKAction()
super.doOKAction(); setPageSizeAndReload(myForm.getPageSize(), grid)
setPageSizeAndReload(myForm.getPageSize(), grid);
} }
}.show(); }.show()
} }
public abstract static class SetPageSizeDialogWrapper extends DialogWrapper { abstract class SetPageSizeDialogWrapper(project: Project?) : DialogWrapper(project) {
protected final CustomPageSizeForm myForm = new CustomPageSizeForm(); protected val myForm: CustomPageSizeForm = CustomPageSizeForm()
public SetPageSizeDialogWrapper(@Nullable Project project) { init {
super(project); title = DataGridBundle.message("dialog.title.change.page.size")
initListeners()
setTitle(DataGridBundle.message("dialog.title.change.page.size")); init()
initListeners();
init();
} }
@Override override fun getPreferredFocusedComponent(): JComponent? {
public @Nullable JComponent getPreferredFocusedComponent() { return myForm.resultPageSizeTextField
return myForm.getResultPageSizeTextField();
} }
private void initListeners() { private fun initListeners() {
myForm.getResultPageSizeTextField().getDocument().addDocumentListener(new DocumentListener() { myForm.resultPageSizeTextField.document.addDocumentListener(object : DocumentListener {
@Override override fun insertUpdate(e: DocumentEvent?) {
public void insertUpdate(DocumentEvent e) { updateOk()
updateOk();
} }
@Override override fun removeUpdate(e: DocumentEvent?) {
public void removeUpdate(DocumentEvent e) { updateOk()
updateOk();
} }
@Override override fun changedUpdate(e: DocumentEvent?) {
public void changedUpdate(DocumentEvent e) { updateOk()
updateOk();
} }
}); })
} }
private void updateOk() { private fun updateOk() {
getOKAction().setEnabled(isOKActionEnabled()); okAction.isEnabled = isOKActionEnabled
} }
@Override override fun isOKActionEnabled(): Boolean {
public boolean isOKActionEnabled() {
try { try {
myForm.getResultPageSizeTextField().validateContent(); myForm.resultPageSizeTextField.validateContent()
return true; return true
} }
catch (ConfigurationException ignored) { catch (_: ConfigurationException) {
return false; return false
} }
} }
protected abstract int getPageSize(); protected abstract val pageSize: Int
protected abstract boolean isLimitPageSize(); protected abstract val isLimitPageSize: Boolean
@Override override fun createCenterPanel(): JComponent {
protected @NotNull JComponent createCenterPanel() { myForm.reset(this.isLimitPageSize, this.pageSize)
myForm.reset(isLimitPageSize(), getPageSize()); return myForm.panel
return myForm.getPanel();
} }
} }
} }

View File

@@ -11,6 +11,8 @@ import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.DumbAwareAction;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import static com.intellij.database.run.actions.ChangePageSizeUtilKt.setPageSizeAndReload;
public class SetDefaultPageSizeAction extends DumbAwareAction { public class SetDefaultPageSizeAction extends DumbAwareAction {
public SetDefaultPageSizeAction() { public SetDefaultPageSizeAction() {
@@ -55,7 +57,7 @@ public class SetDefaultPageSizeAction extends DumbAwareAction {
protected void doOKAction() { protected void doOKAction() {
super.doOKAction(); super.doOKAction();
GridHelper helper = GridHelper.get(grid); GridHelper helper = GridHelper.get(grid);
int pageSize = myForm.getPageSize(); int pageSize = getMyForm().getPageSize();
if (GridUtilCore.isPageSizeUnlimited(pageSize)) { if (GridUtilCore.isPageSizeUnlimited(pageSize)) {
helper.setLimitDefaultPageSize(false); helper.setLimitDefaultPageSize(false);
} }
@@ -63,7 +65,7 @@ public class SetDefaultPageSizeAction extends DumbAwareAction {
helper.setLimitDefaultPageSize(true); helper.setLimitDefaultPageSize(true);
helper.setDefaultPageSize(pageSize); helper.setDefaultPageSize(pageSize);
} }
ChangePageSizeAction.setPageSizeAndReload(pageSize, grid); setPageSizeAndReload(pageSize, grid);
} }
}.show(); }.show();
} }