提交 6ed8d216 编写于 作者: A Andrey Hitrin

Plugin org.jkiss.dbeaver.ext.ui.locks and pom.xml.


Former-commit-id: c8928dbd
上级 8c4948ae
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.jkiss.dbeaver.ext.ui.locks</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Locks Graph Plugin
Bundle-SymbolicName: org.jkiss.dbeaver.ext.ui.locks;singleton:=true
Bundle-Version: 1.0.0
Bundle-Vendor: Andrew Khitrin
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.resources,
org.eclipse.ui,
org.eclipse.ui.ide,
org.eclipse.gef,
org.jkiss.dbeaver.core;bundle-version="4.0.4"
Export-Package: org.jkiss.dbeaver.ext.ui.locks.edit,
org.jkiss.dbeaver.ext.ui.locks.manage
Bundle-ActivationPolicy: lazy
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jkiss.dbeaver</groupId>
<artifactId>dbeaver</artifactId>
<version>1.0.0</version>
<relativePath>../../</relativePath>
</parent>
<artifactId>org.jkiss.dbeaver.ext.ui.locks</artifactId>
<version>1.0.0</version>
<packaging>eclipse-plugin</packaging>
</project>
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.ext.ui.locks.edit;
import org.eclipse.swt.widgets.Composite;
import org.jkiss.dbeaver.ext.ui.locks.manage.LockManagerViewer;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput;
import org.jkiss.dbeaver.ui.editors.SinglePageDatabaseEditor;
/**
* AbstractLockEditor for Lock View
*/
public abstract class AbstractLockEditor extends SinglePageDatabaseEditor<IDatabaseEditorInput>
{
private LockManagerViewer lockViewer;
public LockManagerViewer getLockViewer() {
return lockViewer;
}
@Override
public void dispose()
{
if (lockViewer != null) {
lockViewer.dispose();
}
super.dispose();
}
@Override
public void createPartControl(Composite parent) {
final DBCExecutionContext executionContext = getExecutionContext();
if (executionContext != null) {
setPartName("Lock - " + executionContext.getDataSource().getContainer().getName());
lockViewer = createLockViewer(executionContext, parent);
lockViewer.refreshLocks(null);
}
}
protected abstract LockManagerViewer createLockViewer(DBCExecutionContext executionContext, Composite parent);
@Override
public void refreshPart(Object source, boolean force)
{
lockViewer.refreshLocks(null);
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.ext.ui.locks.graph;
import java.util.ArrayList;
import java.util.List;
import org.jkiss.dbeaver.ext.ui.locks.manage.LockManagerViewer;
import org.jkiss.dbeaver.model.admin.locks.DBAServerLock;
public class LockGraph {
private List<LockGraphNode> nodes = new ArrayList<LockGraphNode>();
private int maxWidth = 0;
private LockGraphNode selection;
private LockManagerViewer lockManagerViewer;
private final DBAServerLock<?> lockRoot;
public DBAServerLock<?> getLockRoot() {
return lockRoot;
}
public LockManagerViewer getLockManagerViewer() {
return lockManagerViewer;
}
public void setLockManagerViewer(LockManagerViewer lockManagerViewer) {
this.lockManagerViewer = lockManagerViewer;
}
public LockGraph(DBAServerLock<?> lockRoot) {
this.selection = null;
this.lockRoot = lockRoot;
}
public LockGraphNode getSelection() {
return selection;
}
public void setSelection(LockGraphNode selection) {
this.selection = selection;
}
public List<LockGraphNode> getNodes() {
return this.nodes;
}
public int getMaxWidth() {
return maxWidth;
}
public void setMaxWidth(int maxWidth) {
this.maxWidth = maxWidth;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.ext.ui.locks.graph;
import org.eclipse.draw2d.AbstractConnectionAnchor;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Point;
public class LockGraphConnectionAnchor extends AbstractConnectionAnchor {
public LockGraphConnectionAnchor(IFigure owner) {
super(owner);
}
public Point getLocation(Point reference) {
Point point = getOwner().getBounds().getCenter();
getOwner().translateToAbsolute(point);
if (reference.x < point.x)
point = getOwner().getBounds().getTop();
else
point = getOwner().getBounds().getBottom();
getOwner().translateToAbsolute(point);
return point;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.ext.ui.locks.graph;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.ConnectionEditPolicy;
import org.eclipse.gef.requests.GroupRequest;
public class LockGraphConnectionEditPolicy extends ConnectionEditPolicy {
@Override
protected Command getDeleteCommand(GroupRequest request) {
return null;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.ext.ui.locks.graph;
public class LockGraphEdge {
private LockGraphNode source;
private LockGraphNode target;
public LockGraphNode getSource() {
return this.source;
}
public LockGraphNode getTarget() {
return this.target;
}
public void setSource(LockGraphNode newSource) {
if (this.source != null) {
this.source.removeSourceEdge(this);
}
this.source = newSource;
if (this.source != null) {
this.source.addSourceEdge(this);
}
}
public void setTarget(LockGraphNode newTarget) {
if (this.target != null) {
this.target.removeTargetEdge(this);
}
this.target = newTarget;
if (this.target != null) {
this.target.addTargetEdge(this);
}
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.ext.ui.locks.graph;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.PolygonDecoration;
import org.eclipse.draw2d.PolylineConnection;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.editparts.AbstractConnectionEditPart;
import org.eclipse.gef.editpolicies.ConnectionEndpointEditPolicy;
public class LockGraphEdgeEditPart extends AbstractConnectionEditPart {
@Override
protected void createEditPolicies() {
installEditPolicy(EditPolicy.CONNECTION_ROLE,
new LockGraphConnectionEditPolicy());
installEditPolicy(EditPolicy.CONNECTION_ENDPOINTS_ROLE,
new ConnectionEndpointEditPolicy());
}
@Override
protected IFigure createFigure() {
PolylineConnection connection = (PolylineConnection) super.createFigure();
connection.setLineWidth(1);
PolygonDecoration decoration = new PolygonDecoration();
decoration.setTemplate(PolygonDecoration.TRIANGLE_TIP);
connection.setSourceDecoration(decoration);
return connection;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.ext.ui.locks.graph;
import java.util.List;
import org.eclipse.draw2d.ConnectionLayer;
import org.eclipse.draw2d.FreeformLayer;
import org.eclipse.draw2d.GridLayout;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.ShortestPathConnectionRouter;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.LayerConstants;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
public class LockGraphEditPart extends AbstractGraphicalEditPart {
@Override
protected void createEditPolicies() {
installEditPolicy(EditPolicy.LAYOUT_ROLE,
new LockGraphXYLayoutEditPolicy());
}
@Override
protected IFigure createFigure() {
FreeformLayer freeformLayer = new FreeformLayer();
freeformLayer.setLayoutManager(new GridLayout(((LockGraph) getModel()).getMaxWidth(), true));
return freeformLayer;
}
@Override
protected List<LockGraphNode> getModelChildren() {
List<LockGraphNode> nodes = ((LockGraph) getModel()).getNodes();
return nodes;
}
@Override
protected void refreshVisuals() {
ConnectionLayer connectionLayer = (ConnectionLayer) getLayer(LayerConstants.CONNECTION_LAYER);
connectionLayer.setConnectionRouter(new ShortestPathConnectionRouter(getFigure()));
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.ext.ui.locks.graph;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartFactory;
public class LockGraphEditPartFactory implements EditPartFactory {
public EditPart createEditPart(EditPart context, Object model) {
EditPart editPart = null;
if (model instanceof LockGraph) {
editPart = new LockGraphEditPart();
} else if (model instanceof LockGraphEdge) {
editPart = new LockGraphEdgeEditPart();
} else if (model instanceof LockGraphNode) {
editPart = new LockGraphNodeEditPart();
}
if (editPart != null) {
editPart.setModel(model);
}
return editPart;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.ext.ui.locks.graph;
import java.util.ArrayList;
import java.util.List;
import org.jkiss.dbeaver.model.admin.locks.DBAServerLock;
public class LockGraphNode {
private int level;
private int span;
private String title;
private DBAServerLock<?> lock;
public enum LevelPosition { LEFT, CENTER, RIGHT};
private LevelPosition levelPosition;
public LevelPosition getLevelPosition() {
return levelPosition;
}
public void setLevelPosition(LevelPosition levelPosition) {
this.levelPosition = levelPosition;
}
public int getLevel() {
return this.level;
}
private List<LockGraphEdge> sourceEdges;
private List<LockGraphEdge> targetEdges;
public LockGraphNode(DBAServerLock<?> lock){
this.lock = lock;
this.level = 0;
this.span = 0;
this.title = lock.getTitle();
this.sourceEdges = new ArrayList<LockGraphEdge>();
this.targetEdges = new ArrayList<LockGraphEdge>();
this.levelPosition = LevelPosition.CENTER;
}
public LockGraphNode(String title,int level,int span) {
this.level = level;
this.span = span;
this.title = title;
this.sourceEdges = new ArrayList<LockGraphEdge>();
this.targetEdges = new ArrayList<LockGraphEdge>();
}
public void addSourceEdge(LockGraphEdge sourceEdge) {
this.sourceEdges.add(sourceEdge);
}
public void addTargetEdge(LockGraphEdge targetEdge) {
this.targetEdges.add(targetEdge);
}
public List<LockGraphEdge> getSourceEdges() {
return this.sourceEdges;
}
public List<LockGraphEdge> getTargetEdges() {
return this.targetEdges;
}
public void removeSourceEdge(LockGraphEdge sourceEdge) {
this.sourceEdges.remove(sourceEdge);
}
public void removeTargetEdge(LockGraphEdge targetEdge) {
this.targetEdges.remove(targetEdge);
}
public int getSpan() {
return span;
}
public String getTitle() {
return title;
}
public void setLevel(int level) {
this.level = level;
}
public void setSpan(int span) {
this.span = span;
}
public DBAServerLock<?> getLock() {
return lock;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.ext.ui.locks.graph;
import java.util.List;
import org.eclipse.draw2d.ConnectionAnchor;
import org.eclipse.draw2d.GridData;
import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.ConnectionEditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
import org.jkiss.dbeaver.ext.ui.locks.manage.LockManagerViewer;
public class LockGraphNodeEditPart extends AbstractGraphicalEditPart {
private LockGraphConnectionAnchor sourceAnchor;
private LockGraphConnectionAnchor targetAnchor;
@Override
public boolean isSelectable() {
return true;
}
@Override
protected IFigure createFigure() {
LockGraphNode node = (LockGraphNode) getModel();
LockGraph graph = (LockGraph)((LockGraphEditPart) getParent()).getModel();
LockGraphNodeFigure nodeFigure = new LockGraphNodeFigure(node.getTitle(),(node == graph.getSelection()));
this.targetAnchor = new LockGraphConnectionAnchor(nodeFigure);
this.sourceAnchor = new LockGraphConnectionAnchor(nodeFigure);
return nodeFigure;
}
@Override
protected List<LockGraphEdge> getModelSourceConnections() {
return ((LockGraphNode) getModel()).getSourceEdges();
}
@Override
protected List<LockGraphEdge> getModelTargetConnections() {
return ((LockGraphNode) getModel()).getTargetEdges();
}
public ConnectionAnchor getSourceConnectionAnchor(
ConnectionEditPart connection) {
return this.sourceAnchor;
}
public ConnectionAnchor getSourceConnectionAnchor(Request request) {
return this.sourceAnchor;
}
public ConnectionAnchor getTargetConnectionAnchor(
ConnectionEditPart connection) {
return this.targetAnchor;
}
public ConnectionAnchor getTargetConnectionAnchor(Request request) {
return this.targetAnchor;
}
@Override
protected void refreshVisuals() {
LockGraphNode node = (LockGraphNode) getModel();
LockGraph lgraph = (LockGraph)((LockGraphEditPart) getParent()).getModel();
LockGraphNodeFigure nodeFigure = (LockGraphNodeFigure) getFigure();
LockGraphEditPart graph = (LockGraphEditPart) getParent();
GridData gridData = new GridData(55,30);
gridData.horizontalAlignment = GridData.CENTER;
gridData.verticalAlignment = GridData.CENTER;
gridData.verticalSpan = 10;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
int span = lgraph.getMaxWidth() / node.getSpan();
int spanMod = lgraph.getMaxWidth() % node.getSpan();
gridData.horizontalSpan = 0 ;
if (span > 1 && node.getLevelPosition() != LockGraphNode.LevelPosition.RIGHT) {
gridData.horizontalSpan = span;
} else if (spanMod > 0 && node.getLevelPosition() == LockGraphNode.LevelPosition.RIGHT) {
gridData.horizontalSpan = span + spanMod;
}
graph.setLayoutConstraint(this, nodeFigure,gridData);
}
@Override
protected void createEditPolicies() {
SelectionPolicy selectionPolicy = new SelectionPolicy();
selectionPolicy.setDragAllowed(false);
installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, selectionPolicy);
}
}
class SelectionPolicy extends NonResizableEditPolicy {
@Override
protected void hideSelection() {
}
@Override
protected void showSelection() {
LockManagerViewer viewer = ((LockGraph)getHost().getParent().getModel()).getLockManagerViewer();
if (viewer != null) {
viewer.setTableLockSelect(((LockGraphNode)getHost().getModel()).getLock());
}
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.ext.ui.locks.graph;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Rectangle;
public class LockGraphNodeFigure extends Figure {
private Label label;
private RectangleFigure rectangleFigure;
public LockGraphNodeFigure(String title,boolean selected) {
setLayoutManager(new XYLayout());
this.rectangleFigure = new RectangleFigure();
this.rectangleFigure.setBackgroundColor(selected ? ColorConstants.orange : ColorConstants.lightGray);
add(this.rectangleFigure);
this.label = new Label();
this.label.setText(title); //$NON-NLS-1$
add(this.label);
}
public Label getLabel() {
return this.label;
}
public RectangleFigure getRectangleFigure() {
return this.rectangleFigure;
}
@Override
public void paintFigure(Graphics g) {
Rectangle r = getBounds().getCopy();
setConstraint(getRectangleFigure(), new Rectangle(0, 0, r.width,r.height));
setConstraint(getLabel(), new Rectangle(0, 0, r.width, r.height));
getRectangleFigure().invalidate();
getLabel().invalidate();
}
}
\ No newline at end of file
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.ext.ui.locks.graph;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.XYLayoutEditPolicy;
import org.eclipse.gef.requests.CreateRequest;
public class LockGraphXYLayoutEditPolicy extends XYLayoutEditPolicy {
@Override
protected Command createChangeConstraintCommand(EditPart child,
Object constraint) {
return null;
}
@Override
protected Command getCreateCommand(CreateRequest request) {
return null;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.ext.ui.locks.graph;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.gef.ContextMenuProvider;
import org.eclipse.gef.DefaultEditDomain;
import org.eclipse.gef.GraphicalViewer;
import org.eclipse.gef.editparts.FreeformGraphicalRootEditPart;
import org.eclipse.gef.ui.parts.ScrollingGraphicalViewer;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
import org.jkiss.dbeaver.ext.ui.locks.manage.LockGraphManager;
import org.jkiss.dbeaver.ext.ui.locks.manage.LockManagerViewer;
import org.jkiss.dbeaver.model.admin.locks.DBAServerLock;
public class LockGraphicalView extends ViewPart {
private static final LockGraph EMPTY_GRAPH = new LockGraph(null);
private DefaultEditDomain editDomain;
private GraphicalViewer graphicalViewer;
private final LockGraphManager<?, ?> graphManager;
private final LockManagerViewer viewer;
public LockGraphicalView(LockManagerViewer viewer) {
super();
this.viewer = viewer;
this.graphManager = viewer.getGraphManager();
}
@Override
public void createPartControl(Composite parent) {
setEditDomain(new DefaultEditDomain(null));
setGraphicalViewer(new ScrollingGraphicalViewer());
getGraphicalViewer().createControl(parent);
getGraphicalViewer().setRootEditPart(new FreeformGraphicalRootEditPart());
getGraphicalViewer().setEditPartFactory(new LockGraphEditPartFactory());
getGraphicalViewer().setContextMenu(new ContextMenuProvider(graphicalViewer){
@Override
public void buildContextMenu(IMenuManager menu) {
menu.add(viewer.getKillAction());
}
});
}
public void drawGraf(DBAServerLock<?> selection)
{
if (selection == null) return;
LockGraph g = selection == null ? EMPTY_GRAPH : graphManager.getGraph(selection);
if (g == null) return;
if (g != EMPTY_GRAPH) {
g.setLockManagerViewer(viewer);
}
getGraphicalViewer().setContents(g);
getGraphicalViewer().getControl().setBackground(ColorConstants.listBackground);
}
protected DefaultEditDomain getEditDomain() {
return this.editDomain;
}
protected GraphicalViewer getGraphicalViewer() {
return this.graphicalViewer;
}
protected void setEditDomain(DefaultEditDomain anEditDomain) {
this.editDomain = anEditDomain;
}
@Override
public void setFocus() {
getGraphicalViewer().getControl().setFocus();
}
protected void setGraphicalViewer(GraphicalViewer viewer) {
getEditDomain().addViewer(viewer);
this.graphicalViewer = viewer;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.ext.ui.locks.manage;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jkiss.dbeaver.ext.ui.locks.graph.LockGraph;
import org.jkiss.dbeaver.ext.ui.locks.graph.LockGraphEdge;
import org.jkiss.dbeaver.ext.ui.locks.graph.LockGraphNode;
import org.jkiss.dbeaver.model.admin.locks.DBAServerLock;
public abstract class LockGraphManager<LOCK_TYPE extends DBAServerLock<?>, ID_TYPE> {
private Map<ID_TYPE,LockGraphNode> nodes = new HashMap<ID_TYPE,LockGraphNode>();
private Map<ID_TYPE,LockGraph> graphIndex = new HashMap<ID_TYPE,LockGraph>();
public LockGraph getGraph(DBAServerLock<?> curLock) {
LockGraphNode selection = nodes.get(curLock.getId());
LockGraph graph = graphIndex.get(curLock.getId());
if (graph != null && selection != null) {
graph.setSelection(selection);
}
return graph;
}
@SuppressWarnings("unchecked")
private LockGraph createGraph(LOCK_TYPE root) {
LockGraph graph = new LockGraph(root);
int maxWidth = 1;
int level = 1;
LockGraphNode nodeRoot = nodes.get(root.getId());
nodeRoot.setLevel(0);
nodeRoot.setSpan(1);
graph.getNodes().add(nodeRoot);
graphIndex.put((ID_TYPE) root.getId(), graph);
List<LOCK_TYPE> current = new ArrayList<LOCK_TYPE>();
Set<DBAServerLock<ID_TYPE>> touched = new HashSet<>(); //Prevent Cycle
current.add(root);
touched.add((DBAServerLock<ID_TYPE>) root);
Map<ID_TYPE,DBAServerLock<ID_TYPE>> childs = new HashMap<ID_TYPE,DBAServerLock<ID_TYPE>>();
while(current.size() > 0) {
if (maxWidth < current.size()) {
maxWidth = current.size();
}
for(int index = 0; index < current.size(); index++) {
DBAServerLock<ID_TYPE> l = (DBAServerLock<ID_TYPE>) current.get(index);
LockGraphNode node = nodes.get(l.getId());
if (index == 0) {
node.setLevelPosition(LockGraphNode.LevelPosition.LEFT);
} else if (index == current.size() - 1) {
node.setLevelPosition(LockGraphNode.LevelPosition.RIGHT);
} else {
node.setLevelPosition(LockGraphNode.LevelPosition.CENTER);
}
node.setSpan(current.size());
for(DBAServerLock<ID_TYPE> c : l.waitThis()) {
if (touched.contains(c)) continue;
touched.add(c);
childs.put(c.getId(), c);
graphIndex.put(c.getId(), graph);
LockGraphNode nodeChild = nodes.get(c.getId());
graph.getNodes().add(nodeChild);
nodeChild.setLevel(level);
LockGraphEdge edge = new LockGraphEdge();
edge.setSource(node);
edge.setTarget(nodeChild);
}
}
level++;
current = new ArrayList<LOCK_TYPE>((Collection<? extends LOCK_TYPE>) childs.values());
childs.clear();
}
graph.setMaxWidth(maxWidth);
return graph;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public void buildGraphs(Map<ID_TYPE,LOCK_TYPE> locks) {
Set<LOCK_TYPE> roots = new HashSet<LOCK_TYPE>();
this.nodes.clear();
this.graphIndex.clear();
for(LOCK_TYPE l: locks.values()) {
if (locks.containsKey(l.getHoldID()) && (!l.getHoldID().equals(l.getId()))) {
LOCK_TYPE holder = locks.get(l.getHoldID());
l.setHoldBy(holder);
holder.waitThis().add((DBAServerLock) l);
} else {
roots.add(l);
}
nodes.put((ID_TYPE) l.getId(), new LockGraphNode(l));
}
for(LOCK_TYPE root : roots) {
if (root.waitThis().size() >= 0)
createGraph(root);
}
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.ext.ui.locks.manage;
import java.util.Map;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IContributionManager;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchSite;
import org.jkiss.dbeaver.ext.ui.locks.graph.LockGraphicalView;
import org.jkiss.dbeaver.ext.ui.locks.table.LockTable;
import org.jkiss.dbeaver.ext.ui.locks.table.LockTableDetail;
import org.jkiss.dbeaver.model.admin.locks.DBAServerLock;
import org.jkiss.dbeaver.model.admin.locks.DBAServerLockItem;
import org.jkiss.dbeaver.model.admin.locks.DBAServerLockManager;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.UIIcon;
import org.jkiss.dbeaver.ui.UIUtils;
/**
* LockManagerViewer
*/
public class LockManagerViewer
{
public static final String keyType = "type";
public static final String typeWait = "wait";
public static final String typeHold = "hold";
private Font boldFont;
private LockListControl lockTable;
private LockTableDetail blockedTable;
private LockTableDetail blockingTable;
private Label blockedLabel;
private Label blockingLabel;
private SashForm sashMain;
private DBAServerLock<?> curLock;
private LockGraphManager<?,?> graphManager;
private LockGraphicalView gv;
@SuppressWarnings("unused")
private final DBAServerLockManager<DBAServerLock<?>,DBAServerLockItem> lockManager;
private Action killAction = new Action("Kill waiting session", UIUtils.getShardImageDescriptor(ISharedImages.IMG_ELCL_STOP)) {
@Override
public void run()
{
DBAServerLock<?> root = graphManager.getGraph((DBAServerLock<?>)curLock).getLockRoot();
alterSession();
refreshLocks(root);
setTableLockSelect(root);
}
};
public LockGraphManager<?, ?> getGraphManager() {
return graphManager;
}
public void dispose()
{
lockTable.disposeControl();
UIUtils.dispose(boldFont);
}
public LockManagerViewer(IWorkbenchPart part, Composite parent, final DBAServerLockManager<DBAServerLock<?>,DBAServerLockItem> lockManager) {
this.graphManager = (LockGraphManager<?, ?>) lockManager;
boldFont = UIUtils.makeBoldFont(parent.getFont());
Composite composite = UIUtils.createPlaceholder(parent, 1);
sashMain = UIUtils.createPartDivider(part, composite, SWT.HORIZONTAL | SWT.SMOOTH);
sashMain.setLayoutData(new GridData(GridData.FILL_BOTH));
SashForm sash = UIUtils.createPartDivider(part, sashMain, SWT.VERTICAL | SWT.SMOOTH);
sash.setLayoutData(new GridData(GridData.FILL_BOTH));
this.lockManager = lockManager;
lockTable = new LockListControl(sash, part.getSite(), lockManager);
lockTable.createProgressPanel(composite);
lockTable.getItemsViewer().addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event)
{
onLockSelect(getSelectedLock());
}
});
lockTable.loadData();
SashForm infoSash = UIUtils.createPartDivider(part, sash, SWT.HORIZONTAL | SWT.SMOOTH);
infoSash.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite cBlocked = new Composite(infoSash,SWT.DOUBLE_BUFFERED);
cBlocked.setLayout(new GridLayout(1,true));
blockedLabel = new Label(cBlocked, SWT.NULL);
blockedLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
blockedLabel.setFont(boldFont);
blockedTable = new LockTableDetail(cBlocked, SWT.SHEET, part.getSite(), lockManager);
blockedTable.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite cBlocking = new Composite(infoSash,SWT.DOUBLE_BUFFERED);
cBlocking.setLayout(new GridLayout(1,true));
blockingLabel = new Label(cBlocking, SWT.NULL);
blockingLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
blockingLabel.setFont(boldFont);
blockingTable = new LockTableDetail(cBlocking, SWT.SHEET, part.getSite(), lockManager);
blockingTable.setLayoutData(new GridData(GridData.FILL_BOTH));
gv = new LockGraphicalView(this);
gv.createPartControl(sashMain);
sashMain.setWeights(new int[] { 3, 1});
sash.setWeights(new int[] { 4, 1});
}
protected void onLockSelect(DBAServerLock<?> lock)
{
curLock = lock;
refreshGraph(curLock);
}
public void setTableLockSelect(DBAServerLock<?> lock) {
lockTable.getItemsViewer().setSelection(new StructuredSelection(lock),true);
curLock = lock;
}
protected void contributeToToolbar(DBAServerLockManager<DBAServerLock<?>,DBAServerLockItem> sessionManager, IContributionManager contributionManager)
{
}
public Action getKillAction() {
return killAction;
}
public DBAServerLock<?> getSelectedLock()
{
ISelection selection = lockTable.getSelectionProvider().getSelection();
if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
return (DBAServerLock<?>)((IStructuredSelection) selection).getFirstElement();
} else {
return null;
}
}
private void refreshGraph(DBAServerLock<?> selected){
gv.drawGraf(selected);
}
public void refreshLocks(DBAServerLock<?> selected)
{
lockTable.loadData(false);
gv.drawGraf(selected);
}
public void refreshDetail(Map<String, Object> options)
{
StringBuilder sb = new StringBuilder("Wait - ");
sb.append(curLock.getTitle());
blockedLabel.setText(sb.toString());
blockedTable.getOptions().putAll(options);
blockedTable.getOptions().put(keyType, typeWait);
blockedTable.loadData(false);
sb.setLength(0);
if (curLock.getHoldBy() != null) {
sb.append("Hold - ");
sb.append(curLock.getHoldBy().getTitle());
blockingLabel.setText(sb.toString());
}
blockingTable.getOptions().putAll(options);
blockingTable.getOptions().put(keyType, typeHold);
blockingTable.loadData();
}
public void alterSession() {
if (UIUtils.confirmAction(
"Terminate",
NLS.bind("Teminate session?", "Terminate"))) {
lockTable.createAlterService(curLock,null).schedule();
}
}
private class LockListControl extends LockTable {
public LockListControl(SashForm sash, IWorkbenchSite site, DBAServerLockManager<DBAServerLock<?>,DBAServerLockItem> lockManager)
{
super(sash, SWT.SHEET, site, lockManager);
}
@Override
protected void fillCustomActions(IContributionManager contributionManager) {
contributeToToolbar(getLockManager(), contributionManager);
contributionManager.add(new Action("Refresh locks", DBeaverIcons.getImageDescriptor(UIIcon.REFRESH)) {
@Override
public void run()
{
refreshLocks(curLock);
}
});
contributionManager.add(killAction);
}
}
}
\ No newline at end of file
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
* Copyright (C) 2010-2016 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.ext.ui.locks.table;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbenchSite;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.admin.locks.DBAServerLock;
import org.jkiss.dbeaver.model.admin.locks.DBAServerLockItem;
import org.jkiss.dbeaver.model.admin.locks.DBAServerLockManager;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.model.exec.DBCExecutionPurpose;
import org.jkiss.dbeaver.model.exec.DBCSession;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.load.DatabaseLoadService;
import org.jkiss.dbeaver.ui.LoadingJob;
import org.jkiss.dbeaver.ui.controls.itemlist.DatabaseObjectListControl;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
* Session table
*/
public class LockTable extends DatabaseObjectListControl<DBAServerLock<?>> {
private DBAServerLockManager<DBAServerLock<?>,DBAServerLockItem> lockManager;
public LockTable(Composite parent, int style, IWorkbenchSite site, DBAServerLockManager<DBAServerLock<?>,DBAServerLockItem> lockManager)
{
super(parent, style, site, CONTENT_PROVIDER);
this.lockManager = lockManager;
}
public DBAServerLockManager<DBAServerLock<?>,DBAServerLockItem> getLockManager() {
return lockManager;
}
@NotNull
@Override
protected String getListConfigId(List<Class<?>> classList) {
return "Locks/" + lockManager.getDataSource().getContainer().getDriver().getId();
}
@Override
protected LoadingJob<Collection<DBAServerLock<?>>> createLoadService()
{
return LoadingJob.createService(
new LoadLocksService(),
new ObjectsLoadVisualizer());
}
public LoadingJob<Void> createAlterService(DBAServerLock<?> lock, Map<String, Object> options)
{
return LoadingJob.createService(
new KillSessionByLockService(lock, options),
new ObjectActionVisualizer());
}
public void init(DBAServerLockManager<DBAServerLock<?>,DBAServerLockItem> lockManager)
{
this.lockManager = lockManager;
}
private static IStructuredContentProvider CONTENT_PROVIDER = new IStructuredContentProvider() {
@Override
public Object[] getElements(Object inputElement)
{
if (inputElement instanceof Collection) {
return ((Collection<?>)inputElement).toArray();
}
return null;
}
@Override
public void dispose()
{
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
{
}
};
private class LoadLocksService extends DatabaseLoadService<Collection<DBAServerLock<?>>> {
protected LoadLocksService()
{
super("Load locks", lockManager.getDataSource());
}
@Override
public Collection<DBAServerLock<?>> evaluate(DBRProgressMonitor monitor)
throws InvocationTargetException, InterruptedException
{
try {
try (DBCExecutionContext isolatedContext = lockManager.getDataSource().openIsolatedContext(monitor, "View Locks")) {
try (DBCSession session = isolatedContext.openSession(monitor, DBCExecutionPurpose.UTIL, "Retrieve server locks")) {
return lockManager.getLocks(session, null).values();
}
}
} catch (Throwable ex) {
throw new InvocationTargetException(ex);
}
}
}
private class KillSessionByLockService extends DatabaseLoadService<Void> {
private final DBAServerLock<?> lock;
private final Map<String, Object> options;
protected KillSessionByLockService(DBAServerLock<?> lock, Map<String, Object> options)
{
super("Kill session by lock", lockManager.getDataSource());
this.lock = lock;
this.options = options;
}
@Override
public Void evaluate(DBRProgressMonitor monitor)
throws InvocationTargetException, InterruptedException
{
try {
try (DBCExecutionContext isolatedContext = lockManager.getDataSource().openIsolatedContext(monitor, "View locks")) {
try (DBCSession session = isolatedContext.openSession(monitor, DBCExecutionPurpose.UTIL, "Kill server session by lock")) {
lockManager.alterSession(session, this.lock, options);
return null;
}
}
} catch (Throwable ex) {
throw new InvocationTargetException(ex);
}
}
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
* Copyright (C) 2010-2016 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.ext.ui.locks.table;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbenchSite;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.admin.locks.DBAServerLock;
import org.jkiss.dbeaver.model.admin.locks.DBAServerLockItem;
import org.jkiss.dbeaver.model.admin.locks.DBAServerLockManager;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.model.exec.DBCExecutionPurpose;
import org.jkiss.dbeaver.model.exec.DBCSession;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.load.DatabaseLoadService;
import org.jkiss.dbeaver.ui.LoadingJob;
import org.jkiss.dbeaver.ui.controls.itemlist.DatabaseObjectListControl;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Lock detail table
*/
public class LockTableDetail extends DatabaseObjectListControl<DBAServerLockItem> {
private DBAServerLockManager<DBAServerLock<?>,DBAServerLockItem> lockManager;
Map<String, Object> options = new HashMap<String, Object>(1);
public Map<String, Object> getOptions() {
return options;
}
public LockTableDetail(Composite parent, int style, IWorkbenchSite site, DBAServerLockManager<DBAServerLock<?>,DBAServerLockItem> lockManager)
{
super(parent, style, site, CONTENT_PROVIDER);
this.lockManager = lockManager;
}
public DBAServerLockManager<DBAServerLock<?>,DBAServerLockItem> getLockManager() {
return lockManager;
}
@NotNull
@Override
protected String getListConfigId(List<Class<?>> classList) {
return "LocksDetail/" + lockManager.getDataSource().getContainer().getDriver().getId();
}
@Override
protected LoadingJob<Collection<DBAServerLockItem>> createLoadService()
{
return LoadingJob.createService(
new LoadLockDetailService(),
new ObjectsLoadVisualizer());
}
public void init(DBAServerLockManager<DBAServerLock<?>,DBAServerLockItem> lockManager)
{
this.lockManager = lockManager;
}
private static IStructuredContentProvider CONTENT_PROVIDER = new IStructuredContentProvider() {
@Override
public Object[] getElements(Object inputElement)
{
if (inputElement instanceof Collection) {
return ((Collection<?>)inputElement).toArray();
}
return null;
}
@Override
public void dispose()
{
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
{
}
};
private class LoadLockDetailService extends DatabaseLoadService<Collection<DBAServerLockItem>> {
protected LoadLockDetailService()
{
super(String.format("Load lock details"), lockManager.getDataSource());
}
@Override
public Collection<DBAServerLockItem> evaluate(DBRProgressMonitor monitor)
throws InvocationTargetException, InterruptedException
{
try {
try (DBCExecutionContext isolatedContext = lockManager.getDataSource().openIsolatedContext(monitor, "View Lock item")) {
try (DBCSession session = isolatedContext.openSession(monitor, DBCExecutionPurpose.UTIL, "Retrieve server lock detail")) {
return lockManager.getLockItems(session, options);
}
}
} catch (Throwable ex) {
throw new InvocationTargetException(ex);
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册