提交 43a225ae 编写于 作者: S serge-rider

Vertical tabs, explain plan viewer

上级 6475d66d
......@@ -18,8 +18,6 @@ package org.jkiss.dbeaver.ui.views.plan;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IContributionManager;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.Viewer;
......@@ -33,7 +31,6 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchPart;
import org.jkiss.dbeaver.ui.editors.sql.SQLEditorCommands;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.exec.DBCException;
......@@ -45,15 +42,19 @@ import org.jkiss.dbeaver.ui.ActionUtils;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.UIIcon;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.controls.VerticalButton;
import org.jkiss.dbeaver.ui.controls.VerticalFolder;
import org.jkiss.dbeaver.ui.editors.sql.SQLEditorCommands;
import org.jkiss.dbeaver.ui.properties.PropertyTreeViewer;
import org.jkiss.utils.CommonUtils;
/**
* ResultSetViewer
*/
public class ExplainPlanViewer implements IPropertyChangeListener
public class ExplainPlanViewer
{
//static final Log log = Log.getLog(ResultSetViewer.class);
private SashForm planPanel;
private Text sqlText;
private PlanNodesTree planTree;
......@@ -73,7 +74,22 @@ public class ExplainPlanViewer implements IPropertyChangeListener
super();
createActions();
Composite composite = UIUtils.createPlaceholder(parent, 1);
Composite planPresentationContainer = UIUtils.createPlaceholder(parent, 2);
planPresentationContainer.setLayoutData(new GridData(GridData.FILL_BOTH));
{
VerticalFolder tabViewFolder = new VerticalFolder(planPresentationContainer, SWT.LEFT);
tabViewFolder.setLayoutData(new GridData(GridData.FILL_VERTICAL));
VerticalButton treeViewButton = new VerticalButton(tabViewFolder, SWT.LEFT);
treeViewButton.setText("Simple");
treeViewButton.setImage(DBeaverIcons.getImage(UIIcon.SQL_PAGE_EXPLAIN_PLAN));
treeViewButton.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
//Composite ph = new Composite(tabViewFolder, SWT.NONE);
//ph.setLayoutData(new GridData(GridData.FILL_VERTICAL));
}
Composite composite = UIUtils.createPlaceholder(planPresentationContainer, 1);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
this.planPanel = UIUtils.createPartDivider(workbenchPart, composite, SWT.HORIZONTAL);
this.planPanel.setLayoutData(new GridData(GridData.FILL_BOTH));
......@@ -172,7 +188,7 @@ public class ExplainPlanViewer implements IPropertyChangeListener
public Control getControl()
{
return planPanel.getParent();
return planPanel.getParent().getParent();
}
public Viewer getViewer()
......@@ -180,11 +196,6 @@ public class ExplainPlanViewer implements IPropertyChangeListener
return planTree.getItemsViewer();
}
@Override
public void propertyChange(PropertyChangeEvent event)
{
}
public void explainQueryPlan(DBCExecutionContext executionContext, SQLQuery query) throws DBCException
{
this.executionContext = executionContext;
......
......@@ -18,73 +18,55 @@ package org.jkiss.dbeaver.ui.controls;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.Transform;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.jkiss.dbeaver.ui.UIUtils;
public class VerticalButton extends Canvas {
public static final int BORDER_MARGIN = 2;
public static final int VERT_INDENT = 8;
public class RotatingButton extends Canvas {
private int mouse = 0;
private boolean hit = false;
private String text = "Button";
float rotatingAngle = 0f;
float[] angles = {0, 90, 180, 270};
int index = 0;
public RotatingButton(Composite parent, int style) {
super(parent, style);
private String text = "";
private Image image = null;
this.addListener(SWT.MouseUp, e -> {
index++;
index = index > 3 ? 0 : index;
Rectangle r = getBounds();
private float rotatingAngle = -90;
private boolean isHover;
//float[] angles = {0, 90, 180, 270};
//int index = 0;
setBounds(r.x, r.y, r.height, r.width);
public VerticalButton(Composite parent, int style) {
super(parent, style);
rotatingAngle = angles[index];
redraw();
});
this.addPaintListener(this::paint);
this.addMouseMoveListener(e -> {
if (!hit)
return;
mouse = 2;
if (e.x < 0 || e.y < 0 || e.x > getBounds().width
|| e.y > getBounds().height) {
mouse = 0;
}
redraw();
});
this.addMouseTrackListener(new MouseTrackAdapter() {
public void mouseEnter(MouseEvent e) {
mouse = 1;
isHover = true;
redraw();
}
public void mouseExit(MouseEvent e) {
mouse = 0;
isHover = false;
redraw();
}
});
this.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
hit = true;
mouse = 2;
redraw();
}
public void mouseUp(MouseEvent e) {
hit = false;
mouse = 1;
if (e.x < 0 || e.y < 0 || e.x > getBounds().width
|| e.y > getBounds().height) {
mouse = 0;
}
redraw();
if (mouse == 1)
if (hit) {
notifyListeners(SWT.Selection, new Event());
}
}
});
this.addKeyListener(new KeyAdapter() {
......@@ -102,19 +84,53 @@ public class RotatingButton extends Canvas {
redraw();
}
public void setImage(Image image) {
this.image = image;
redraw();
}
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
GC gc = new GC(this);
Point textSize = gc.stringExtent(text);
gc.dispose();
Point iconSize = new Point(0, 0);
if (image != null) {
Rectangle imageBounds = image.getBounds();
iconSize.x = imageBounds.width + BORDER_MARGIN;
iconSize.y = imageBounds.height + BORDER_MARGIN * 2;
}
return new Point(
Math.max(iconSize.y, textSize.y + BORDER_MARGIN * 2),
textSize.x + (BORDER_MARGIN + VERT_INDENT) * 2 + iconSize.x);
}
public void paint(PaintEvent e) {
if (isHover) {
Color curBackground = e.gc.getBackground();
// Make bg a bit darker
RGB buttonHoverRGB = UIUtils.blend(curBackground.getRGB(), new RGB(0, 0, 0), 90);
Color buttonHoverColor = UIUtils.getSharedTextColors().getColor(buttonHoverRGB);
e.gc.setBackground(buttonHoverColor);
e.gc.fillRectangle(e.x, e.y, e.width, e.height);
}
Transform tr = new Transform(e.display);
Rectangle r = getBounds();
text = e.gc.stringExtent(text) + "";
e.gc.setAntialias(SWT.ON);
Point p = e.gc.stringExtent(text);
int w = e.width;
int h = e.height;
tr.translate(w / 2, h / 2);
tr.translate(0, e.height);
tr.rotate(rotatingAngle);
e.gc.setTransform(tr);
e.gc.drawString(text, r.x - (p.x / 3) * 2, r.y - p.y);
int x = e.x + VERT_INDENT;
if (image != null) {
e.gc.drawImage(image, x, e.y + BORDER_MARGIN);
x += image.getBounds().width + BORDER_MARGIN;
}
e.gc.drawString(text, x, e.y + BORDER_MARGIN);
}
}
\ No newline at end of file
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 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;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
public class VerticalFolder extends Canvas {
private boolean isLeft;
public VerticalFolder(Composite parent, int style) {
super(parent, style);
this.isLeft = (style & SWT.LEFT) == SWT.LEFT;
GridLayout gl = new GridLayout(1, true);
gl.horizontalSpacing = 0;
gl.marginWidth = 0;
this.setLayout(gl);
}
public boolean isLeft() {
return isLeft;
}
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
Point size = super.computeSize(wHint, hHint, changed);
return size;
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册