提交 0d98f89c 编写于 作者: S serge-rider

#1577 RSV: column swap

上级 f8c8c8fe
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ui.controls.lightgrid;
public interface IGridController {
void moveColumn(Object dragColumn, Object dropColumn);
}
......@@ -431,6 +431,9 @@ public abstract class LightGrid extends Canvas {
@NotNull
public abstract IGridLabelProvider getLabelProvider();
@Nullable
public abstract IGridController getGridController();
public boolean hasNodes() {
return !rowNodes.isEmpty();
}
......@@ -3762,6 +3765,10 @@ public abstract class LightGrid extends Canvas {
focusColumn = column;
}
public void resetFocus() {
focusColumn = null;
focusItem = -1;
}
/**
* Returns true if the table is set to horizontally scroll column-by-column
......@@ -4263,7 +4270,7 @@ public abstract class LightGrid extends Canvas {
// DnD
/////////////////////////////////////////////////////////////////////////////////
public void addDragAndDropSupport()
private void addDragAndDropSupport()
{
int operations = DND.DROP_MOVE;
......@@ -4272,10 +4279,13 @@ public abstract class LightGrid extends Canvas {
source.addDragListener (new DragSourceListener() {
private Image dragImage;
private long lastDragEndTime;
@Override
public void dragStart(DragSourceEvent event) {
if (hoveringColumn == null || !headerColumnDragStarted) {
if (hoveringColumn == null || !headerColumnDragStarted ||
(lastDragEndTime > 0 && System.currentTimeMillis() - lastDragEndTime < 100))
{
event.doit = false;
} else {
draggingColumn = hoveringColumn;
......@@ -4301,6 +4311,7 @@ public abstract class LightGrid extends Canvas {
UIUtils.dispose(dragImage);
dragImage = null;
}
lastDragEndTime = System.currentTimeMillis();
}
});
......@@ -4376,7 +4387,11 @@ public abstract class LightGrid extends Canvas {
if (draggingColumn == null || draggingColumn == overColumn) {
return;
}
System.out.println("DROP " + draggingColumn.getElement() + " over " + overColumn.getElement());
IGridController gridController = getGridController();
if (gridController != null) {
gridController.moveColumn(draggingColumn.getElement(), overColumn.getElement());
}
draggingColumn = null;
}
});
}
......
......@@ -27,6 +27,7 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBPContextProvider;
import org.jkiss.dbeaver.model.DBPMessageType;
import org.jkiss.dbeaver.model.data.DBDAttributeBinding;
import org.jkiss.dbeaver.model.data.DBDDataFilter;
import org.jkiss.dbeaver.model.data.DBDDataReceiver;
import org.jkiss.dbeaver.model.edit.DBEPersistAction;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
......@@ -160,6 +161,7 @@ public interface IResultSetController extends DBPContextProvider {
void updatePanelsContent(boolean forceRefresh);
void setDataFilter(final DBDDataFilter dataFilter, boolean refreshData);
/**
* Enable/disable viewer actions. May be used by editors to "lock" RSV actions like navigation, edit, etc.
......
......@@ -340,7 +340,7 @@ public class ResultSetViewer extends Viewer
}
}
void setDataFilter(final DBDDataFilter dataFilter, boolean refreshData)
public void setDataFilter(final DBDDataFilter dataFilter, boolean refreshData)
{
if (!model.getDataFilter().equals(dataFilter)) {
//model.setDataFilter(dataFilter);
......
......@@ -65,6 +65,8 @@ public class Spreadsheet extends LightGrid implements Listener {
private final IGridContentProvider contentProvider;
@NotNull
private final IGridLabelProvider labelProvider;
@Nullable
private final IGridController gridController;
private Clipboard clipboard;
......@@ -74,7 +76,8 @@ public class Spreadsheet extends LightGrid implements Listener {
@NotNull final IWorkbenchPartSite site,
@NotNull final SpreadsheetPresentation presentation,
@NotNull final IGridContentProvider contentProvider,
@NotNull final IGridLabelProvider labelProvider)
@NotNull final IGridLabelProvider labelProvider,
@Nullable final IGridController gridController)
{
super(parent, style);
GridLayout layout = new GridLayout(1, true);
......@@ -88,6 +91,7 @@ public class Spreadsheet extends LightGrid implements Listener {
this.presentation = presentation;
this.contentProvider = contentProvider;
this.labelProvider = labelProvider;
this.gridController = gridController;
this.clipboard = new Clipboard(getDisplay());
......@@ -371,6 +375,11 @@ public class Spreadsheet extends LightGrid implements Listener {
return labelProvider;
}
@Override
public IGridController getGridController() {
return gridController;
}
public void redrawGrid()
{
Rectangle bounds = super.getBounds();
......
......@@ -85,10 +85,7 @@ import org.jkiss.dbeaver.ui.ActionUtils;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.controls.PropertyPageStandard;
import org.jkiss.dbeaver.ui.controls.lightgrid.GridCell;
import org.jkiss.dbeaver.ui.controls.lightgrid.GridPos;
import org.jkiss.dbeaver.ui.controls.lightgrid.IGridContentProvider;
import org.jkiss.dbeaver.ui.controls.lightgrid.IGridLabelProvider;
import org.jkiss.dbeaver.ui.controls.lightgrid.*;
import org.jkiss.dbeaver.ui.controls.resultset.*;
import org.jkiss.dbeaver.ui.controls.resultset.panel.ViewValuePanel;
import org.jkiss.dbeaver.ui.data.IMultiController;
......@@ -111,7 +108,7 @@ import java.util.regex.*;
* Spreadsheet presentation.
* Visualizes results as grid.
*/
public class SpreadsheetPresentation extends AbstractPresentation implements IResultSetEditor, ISelectionProvider, IStatefulControl, IAdaptable {
public class SpreadsheetPresentation extends AbstractPresentation implements IResultSetEditor, ISelectionProvider, IStatefulControl, IAdaptable, IGridController {
private static final Log log = Log.getLog(SpreadsheetPresentation.class);
......@@ -174,7 +171,8 @@ public class SpreadsheetPresentation extends AbstractPresentation implements IRe
controller.getSite(),
this,
new ContentProvider(),
new GridLabelProvider());
new GridLabelProvider(),
this);
this.spreadsheet.setLayoutData(new GridData(GridData.FILL_BOTH));
this.spreadsheet.addSelectionListener(new SelectionAdapter() {
......@@ -1169,6 +1167,22 @@ public class SpreadsheetPresentation extends AbstractPresentation implements IRe
fireSelectionChanged(selection);
}
@Override
public void moveColumn(Object dragColumn, Object dropColumn) {
if (dragColumn instanceof DBDAttributeBinding && dropColumn instanceof DBDAttributeBinding) {
//System.out.println("SWAP " + dragColumn + " -> " + dropColumn);
DBDDataFilter dataFilter = new DBDDataFilter(controller.getModel().getDataFilter());
final DBDAttributeConstraint c1 = dataFilter.getConstraint((DBDAttributeBinding) dragColumn);
final DBDAttributeConstraint c2 = dataFilter.getConstraint((DBDAttributeBinding) dropColumn);
final int vp2 = c2.getVisualPosition();
c2.setVisualPosition(c1.getVisualPosition());
c1.setVisualPosition(vp2);
spreadsheet.resetFocus();
controller.setDataFilter(dataFilter, false);
}
}
private class SpreadsheetSelectionImpl implements IResultSetSelection {
@Nullable
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册