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.DatabaseDataKeys;
import com.intellij.database.datagrid.*;
import com.intellij.database.run.ui.DataGridRequestPlace;
import com.intellij.ide.ActivityTracker;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.DumbAwareAction;
import org.jetbrains.annotations.NotNull;
import com.intellij.database.DataGridBundle
import com.intellij.database.DatabaseDataKeys
import com.intellij.database.datagrid.GridPagingModel
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.DumbAwareAction
import static com.intellij.database.datagrid.GridPagingModel.UNLIMITED_PAGE_SIZE;
import static com.intellij.database.run.actions.ChangePageSizeActionGroup.format;
public class ChangePageSizeAction extends DumbAwareAction {
private final int myPageSize;
public ChangePageSizeAction(int pageSize) {
super(pageSize == UNLIMITED_PAGE_SIZE ? DataGridBundle.message("action.ChangePageSize.text.all") : format(pageSize),
pageSize == UNLIMITED_PAGE_SIZE ? DataGridBundle.message("action.ChangePageSize.description.all")
: DataGridBundle.message("action.ChangePageSize.description.some", format(pageSize)),
null);
myPageSize = pageSize;
class ChangePageSizeAction(private val myPageSize: Int) : DumbAwareAction(if (myPageSize == GridPagingModel.UNLIMITED_PAGE_SIZE) DataGridBundle.message("action.ChangePageSize.text.all") else format(myPageSize.toLong()),
if (myPageSize == GridPagingModel.UNLIMITED_PAGE_SIZE)
DataGridBundle.message("action.ChangePageSize.description.all")
else
DataGridBundle.message("action.ChangePageSize.description.some", format(myPageSize.toLong())),
null) {
override fun getActionUpdateThread(): ActionUpdateThread {
return ActionUpdateThread.BGT
}
@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
override fun update(e: AnActionEvent) {
val grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY)
e.presentation.setEnabledAndVisible(grid != null)
}
@Override
public void update(@NotNull AnActionEvent e) {
DataGrid grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY);
e.getPresentation().setEnabledAndVisible(grid != null);
}
@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);
override fun actionPerformed(e: AnActionEvent) {
val grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY)
if (grid == null) return
setPageSizeAndReload(myPageSize, grid)
}
}

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.DatabaseDataKeys;
import com.intellij.database.datagrid.*;
import com.intellij.database.run.ui.FloatingPagingManager;
import com.intellij.database.settings.DataGridSettings;
import com.intellij.database.util.DataGridUIUtil;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.ex.CustomComponentAction;
import com.intellij.openapi.actionSystem.impl.ActionButtonWithText;
import com.intellij.openapi.project.DumbAware;
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.JBPopupFactory;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.NlsActions;
import com.intellij.openapi.util.NlsContexts;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.JBInsets;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.intellij.database.DataGridBundle
import com.intellij.database.DatabaseDataKeys
import com.intellij.database.datagrid.*
import com.intellij.database.run.ui.FloatingPagingManager
import com.intellij.database.run.ui.FloatingPagingManager.Companion.adjustAction
import com.intellij.database.settings.DataGridSettings
import com.intellij.database.util.DataGridUIUtil
import com.intellij.openapi.actionSystem.*
import com.intellij.openapi.actionSystem.ex.CustomComponentAction
import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.project.DumbAwareAction
import com.intellij.openapi.ui.popup.JBPopup
import com.intellij.openapi.ui.popup.JBPopupFactory
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.NlsActions
import com.intellij.openapi.util.NlsContexts
import com.intellij.util.containers.ContainerUtil
import java.awt.Component
import java.util.*
import javax.swing.JComponent
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
private val DEFAULT_PAGE_SIZES = mutableListOf(10, 100, 500, 1000)
private val PAGE_SIZE_KEY = Key<Int?>("DATA_GRID_PAGE_SIZE_KEY")
private val SHOW_COUNT_ALL_ACTION_KEY = Key<Boolean?>("DATA_GRID_SHOW_COUNT_ALL_ACTION_KEY")
import static com.intellij.database.datagrid.GridPagingModel.UNLIMITED_PAGE_SIZE;
import static com.intellij.database.datagrid.GridPagingModel.UNSET_PAGE_SIZE;
import static com.intellij.database.datagrid.GridUtil.getSettings;
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;
class ChangePageSizeActionGroup : DefaultActionGroup(), CustomComponentAction, DumbAware {
override fun getActionUpdateThread(): ActionUpdateThread {
return ActionUpdateThread.EDT
}
public ChangePageSizeActionGroup() {
setPopup(true);
setActions(DEFAULT_PAGE_SIZES, false);
init {
isPopup = true
setActions(DEFAULT_PAGE_SIZES, false)
}
private void setActions(List<Integer> sizes, boolean isSinglePage) {
removeAll();
private fun setActions(sizes: MutableList<Int>, isSinglePage: Boolean) {
removeAll()
if (isSinglePage) {
add(new MyCountRowsAction());
add(MyCountRowsAction())
}
addSeparator(DataGridBundle.message("separator.page.size"));
addSeparator(DataGridBundle.message("separator.page.size"))
for (Integer pageSize : sizes) {
add(new ChangePageSizeAction(pageSize));
for (pageSize in sizes) {
add(ChangePageSizeAction(pageSize))
}
add(new ChangePageSizeAction(UNLIMITED_PAGE_SIZE));
add(new SetCustomPageSizeAction());
add(new Separator());
add(new SetDefaultPageSizeAction());
add(ChangePageSizeAction(GridPagingModel.UNLIMITED_PAGE_SIZE))
add(SetCustomPageSizeAction())
add(Separator())
add(SetDefaultPageSizeAction())
}
@Override
public void update(@NotNull AnActionEvent e) {
DataGrid grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY);
if (grid == null || grid.getDataHookup() instanceof DocumentDataHookUp) {
e.getPresentation().setEnabledAndVisible(false);
return;
override fun update(e: AnActionEvent) {
val grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY)
if (grid == null || grid.getDataHookup() is DocumentDataHookUp) {
e.presentation.setEnabledAndVisible(false)
return
}
if (grid.getDataHookup().getPageModel() instanceof NestedTableGridPagingModel<GridRow, GridColumn> nestedPageModel &&
nestedPageModel.isStatic()) {
e.getPresentation().setEnabledAndVisible(false);
return;
if ((grid.getDataHookup().getPageModel() as? NestedTableGridPagingModel<GridRow?, GridColumn?>)?.isStatic == true) {
e.presentation.setEnabledAndVisible(false)
return
}
if (FloatingPagingManager.adjustAction(e) == FloatingPagingManager.AdjustmentResult.HIDDEN) {
return;
if (adjustAction(e) == FloatingPagingManager.AdjustmentResult.HIDDEN) {
return
}
ChangePageSizeActionState state = getActionState(grid);
if (hidePageActions(grid, e.getPlace())) {
e.getPresentation().setVisible(false);
val state = getActionState(grid)
if (GridUtil.hidePageActions(grid, e.place)) {
e.presentation.setVisible(false)
}
else {
e.getPresentation().setVisible(true);
updatePresentation(state, e.getPresentation(), getSettings(grid));
e.presentation.setVisible(true)
updatePresentation(state, e.presentation, GridUtil.getSettings(grid))
}
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Component component = e.getPresentation().getClientProperty(COMPONENT_KEY);
JBPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(null, this, e.getDataContext(), null, true, null);
override fun actionPerformed(e: AnActionEvent) {
val component: Component? = e.presentation.getClientProperty(CustomComponentAction.COMPONENT_KEY)
val popup: JBPopup = JBPopupFactory.getInstance().createActionGroupPopup(null, this, e.dataContext, null, true, null)
if (component == null) {
DataGridUIUtil.showPopup(popup, null, e);
return;
DataGridUIUtil.showPopup(popup, null, e)
return
}
popup.showUnderneathOf(component);
popup.showUnderneathOf(component)
}
static @NotNull String format(long num) {
return String.format("%,d", num);
override fun createCustomComponent(presentation: Presentation, place: String): JComponent {
return createCustomComponentForResultViewToolbar(this, presentation, place)
}
@Override
public @NotNull JComponent createCustomComponent(@NotNull Presentation presentation, @NotNull String place) {
return createCustomComponentForResultViewToolbar(this, presentation, place);
}
private fun updatePresentation(state: ChangePageSizeActionState, presentation: Presentation, settings: DataGridSettings?) {
val oldState = getActionState(presentation)
if (oldState == state) return
public static @NotNull JComponent createCustomComponentForResultViewToolbar(@NotNull AnAction action,
@NotNull Presentation presentation,
@NotNull String place) {
ActionButtonWithText c = new ActionButtonWithText(action, presentation, place, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE) {
@Override
public Insets getInsets() {
return new JBInsets(0, 0, 0, 0);
}
};
return AlignedIconWithTextAction.align(c);
}
presentation.setText(state.text)
presentation.setDescription(state.description)
presentation.setEnabled(state.enabled)
presentation.putClientProperty<Int?>(PAGE_SIZE_KEY, state.pageSize)
presentation.putClientProperty<Boolean?>(SHOW_COUNT_ALL_ACTION_KEY, state.showCountAllAction)
private void updatePresentation(ChangePageSizeActionState state, Presentation presentation, @Nullable DataGridSettings settings) {
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);
val component = presentation.getClientProperty(CustomComponentAction.COMPONENT_KEY)
if (component != null) {
component.setToolTipText(state.tooltip);
component.repaint();
component.setToolTipText(state.tooltip)
component.repaint()
}
List<Integer> pageSizes = new ArrayList<>(DEFAULT_PAGE_SIZES);
pageSizes.add(GridUtilCore.getPageSize(settings));
val pageSizes: MutableList<Int> = ArrayList<Int>(DEFAULT_PAGE_SIZES)
pageSizes.add(GridUtilCore.getPageSize(settings))
if (state.pageSize > 0) {
pageSizes.add(state.pageSize * 2);
int halfSize = state.pageSize / 2;
if (halfSize > 0) pageSizes.add(halfSize);
ContainerUtil.removeAll(pageSizes, state.pageSize);
pageSizes.add(state.pageSize * 2)
val halfSize = state.pageSize / 2
if (halfSize > 0) pageSizes.add(halfSize)
ContainerUtil.removeAll(pageSizes, state.pageSize)
}
ContainerUtil.removeDuplicates(pageSizes);
ContainerUtil.sort(pageSizes);
setActions(pageSizes, state.showCountAllAction);
ContainerUtil.removeDuplicates(pageSizes)
ContainerUtil.sort(pageSizes)
setActions(pageSizes, state.showCountAllAction)
}
private static @NotNull ChangePageSizeActionState getActionState(@NotNull Presentation presentation) {
JComponent component = presentation.getClientProperty(COMPONENT_KEY);
}
String text = presentation.getText();
String description = presentation.getDescription();
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;
private fun getActionState(presentation: Presentation): ChangePageSizeActionState {
val component = presentation.getClientProperty(CustomComponentAction.COMPONENT_KEY)
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) {
GridPagingModel<GridRow, GridColumn> pageModel = grid.getDataHookup().getPageModel();
val showCountRowsAction = isSinglePage && pageModel.isTotalRowCountUpdateable() && !querying && grid.isReady()
return ChangePageSizeActionState(text, description, tooltip, enabled, pageModel.getPageSize(), showCountRowsAction)
}
int pageStartIdx = pageModel.getPageStart();
int pageEndIdx = pageModel.getPageEnd();
long totalRowCount = pageModel.getTotalRowCount();
private fun updateIsTotalRowCountUpdateable(grid: DataGrid) {
grid.getDataHookup().getLoader().updateIsTotalRowCountUpdateable()
}
boolean rowsWereDeleted = totalRowCount < pageEndIdx;
boolean isSinglePage = pageModel.isFirstPage() && pageModel.isLastPage() && !rowsWereDeleted;
String text = isSinglePage ?
format(totalRowCount) +
" " +
(totalRowCount == 1
? DataGridBundle.message("action.Console.TableResult.ChangePageSize.row")
: DataGridBundle.message("action.Console.TableResult.ChangePageSize.rows")) :
pageEndIdx == 0
? "0 " + DataGridBundle.message("action.Console.TableResult.ChangePageSize.rows")
: format(pageStartIdx) + "-" + format(pageEndIdx);
boolean querying = grid.getDataHookup().getBusyCount() > 0;
boolean enabled = !querying && grid.isReady();
String description = DataGridBundle.message("group.Console.TableResult.ChangePageSize.description");
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 class ChangePageSizeActionState(
val text: @NlsActions.ActionText String?,
val description: @NlsActions.ActionDescription String?,
val tooltip: @NlsContexts.Tooltip String?,
val enabled: Boolean,
val pageSize: Int,
val showCountAllAction: Boolean,
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || javaClass != other.javaClass) return false
val state = other as ChangePageSizeActionState
return enabled == state.enabled && pageSize == state.pageSize &&
text == state.text &&
description == state.description &&
tooltip == state.tooltip
}
private static void updateIsTotalRowCountUpdateable(@NotNull DataGrid grid) {
grid.getDataHookup().getLoader().updateIsTotalRowCountUpdateable();
}
private static class ChangePageSizeActionState {
final @NlsActions.ActionText String text;
final @NlsActions.ActionDescription String description;
final @NlsContexts.Tooltip String tooltip;
final boolean enabled;
final int pageSize;
final boolean showCountAllAction;
ChangePageSizeActionState(@NlsActions.ActionText String text,
@NlsActions.ActionDescription String description,
@NlsContexts.Tooltip String tooltip,
boolean enabled,
int pageSize,
boolean showCountAllAction) {
this.text = text;
this.description = description;
this.tooltip = tooltip;
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);
}
override fun hashCode(): Int {
return Objects.hash(text, description, tooltip, enabled, pageSize)
}
}
private class MyCountRowsAction : DumbAwareAction(
DataGridBundle.message("action.CountRows.text"),
DataGridBundle.message("action.CountRows.description"),
null
) {
override fun actionPerformed(e: AnActionEvent) {
val grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY)
if (grid == null) {
e.presentation.setEnabledAndVisible(false)
return
}
updateIsTotalRowCountUpdateable(grid)
val 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 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 {
@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.DatabaseDataKeys;
import com.intellij.database.datagrid.*;
import com.intellij.database.run.ui.CustomPageSizeForm;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.application.ApplicationBundle;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.intellij.database.DataGridBundle
import com.intellij.database.DatabaseDataKeys
import com.intellij.database.datagrid.GridUtil
import com.intellij.database.datagrid.GridUtilCore
import com.intellij.database.run.ui.CustomPageSizeForm
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.application.ApplicationBundle
import com.intellij.openapi.options.ConfigurationException
import com.intellij.openapi.project.DumbAwareAction
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.DialogWrapper
import javax.swing.Icon
import javax.swing.JComponent
import javax.swing.event.DocumentEvent
import javax.swing.event.DocumentListener
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
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);
class SetCustomPageSizeAction : DumbAwareAction(ApplicationBundle.messagePointer("custom.option"), ApplicationBundle.messagePointer("custom.option.description"), null as Icon?) {
override fun update(e: AnActionEvent) {
val grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY)
e.presentation.setEnabledAndVisible(grid != null)
}
@Override
public void update(@NotNull AnActionEvent e) {
DataGrid grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY);
e.getPresentation().setEnabledAndVisible(grid != null);
override fun getActionUpdateThread(): ActionUpdateThread {
return ActionUpdateThread.BGT
}
@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
}
override fun actionPerformed(e: AnActionEvent) {
val grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY)
if (grid == null) return
val pageModel = grid.getDataHookup().getPageModel()
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
DataGrid grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY);
if (grid == null) return;
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();
object : SetPageSizeDialogWrapper(getEventProject(e)) {
override val pageSize: Int get() {
val unlimited = GridUtilCore.isPageSizeUnlimited(pageModel.getPageSize())
return if (unlimited) GridUtilCore.getPageSize(GridUtil.getSettings(grid)) else pageModel.getPageSize()
}
@Override
protected boolean isLimitPageSize() {
return !GridUtilCore.isPageSizeUnlimited(pageModel.getPageSize());
override val isLimitPageSize: Boolean get() {
return !GridUtilCore.isPageSizeUnlimited(pageModel.getPageSize())
}
@Override
protected void doOKAction() {
super.doOKAction();
setPageSizeAndReload(myForm.getPageSize(), grid);
override fun doOKAction() {
super.doOKAction()
setPageSizeAndReload(myForm.getPageSize(), grid)
}
}.show();
}.show()
}
public abstract static class SetPageSizeDialogWrapper extends DialogWrapper {
protected final CustomPageSizeForm myForm = new CustomPageSizeForm();
abstract class SetPageSizeDialogWrapper(project: Project?) : DialogWrapper(project) {
protected val myForm: CustomPageSizeForm = CustomPageSizeForm()
public SetPageSizeDialogWrapper(@Nullable Project project) {
super(project);
init {
title = DataGridBundle.message("dialog.title.change.page.size")
initListeners()
setTitle(DataGridBundle.message("dialog.title.change.page.size"));
initListeners();
init();
init()
}
@Override
public @Nullable JComponent getPreferredFocusedComponent() {
return myForm.getResultPageSizeTextField();
override fun getPreferredFocusedComponent(): JComponent? {
return myForm.resultPageSizeTextField
}
private void initListeners() {
myForm.getResultPageSizeTextField().getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
updateOk();
private fun initListeners() {
myForm.resultPageSizeTextField.document.addDocumentListener(object : DocumentListener {
override fun insertUpdate(e: DocumentEvent?) {
updateOk()
}
@Override
public void removeUpdate(DocumentEvent e) {
updateOk();
override fun removeUpdate(e: DocumentEvent?) {
updateOk()
}
@Override
public void changedUpdate(DocumentEvent e) {
updateOk();
override fun changedUpdate(e: DocumentEvent?) {
updateOk()
}
});
})
}
private void updateOk() {
getOKAction().setEnabled(isOKActionEnabled());
private fun updateOk() {
okAction.isEnabled = isOKActionEnabled
}
@Override
public boolean isOKActionEnabled() {
override fun isOKActionEnabled(): Boolean {
try {
myForm.getResultPageSizeTextField().validateContent();
return true;
myForm.resultPageSizeTextField.validateContent()
return true
}
catch (ConfigurationException ignored) {
return false;
catch (_: ConfigurationException) {
return false
}
}
protected abstract int getPageSize();
protected abstract val pageSize: Int
protected abstract boolean isLimitPageSize();
protected abstract val isLimitPageSize: Boolean
@Override
protected @NotNull JComponent createCenterPanel() {
myForm.reset(isLimitPageSize(), getPageSize());
return myForm.getPanel();
override fun createCenterPanel(): JComponent {
myForm.reset(this.isLimitPageSize, this.pageSize)
return myForm.panel
}
}
}

View File

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