From 6ed8d216e217ef2b5e3529349476a0c7d37d7df7 Mon Sep 17 00:00:00 2001 From: Andrey Hitrin Date: Thu, 6 Apr 2017 13:01:16 +0300 Subject: [PATCH] Plugin org.jkiss.dbeaver.ext.ui.locks and pom.xml. Former-commit-id: c8928dbd134275ac84f6739a6edc85c737df4f53 --- .../org.jkiss.dbeaver.ext.ui.locks/.classpath | 7 + .../org.jkiss.dbeaver.ext.ui.locks/.project | 28 ++ .../.settings/org.eclipse.jdt.core.prefs | 7 + .../META-INF/MANIFEST.MF | 16 ++ .../build.properties | 4 + .../org.jkiss.dbeaver.ext.ui.locks/pom.xml | 14 + .../ext/ui/locks/edit/AbstractLockEditor.java | 65 +++++ .../dbeaver/ext/ui/locks/graph/LockGraph.java | 78 ++++++ .../graph/LockGraphConnectionAnchor.java | 40 +++ .../graph/LockGraphConnectionEditPolicy.java | 30 +++ .../ext/ui/locks/graph/LockGraphEdge.java | 52 ++++ .../ui/locks/graph/LockGraphEdgeEditPart.java | 54 ++++ .../ext/ui/locks/graph/LockGraphEditPart.java | 58 ++++ .../locks/graph/LockGraphEditPartFactory.java | 50 ++++ .../ext/ui/locks/graph/LockGraphNode.java | 122 +++++++++ .../ui/locks/graph/LockGraphNodeEditPart.java | 131 +++++++++ .../ui/locks/graph/LockGraphNodeFigure.java | 60 +++++ .../graph/LockGraphXYLayoutEditPolicy.java | 40 +++ .../ext/ui/locks/graph/LockGraphicalView.java | 108 ++++++++ .../ext/ui/locks/manage/LockGraphManager.java | 183 +++++++++++++ .../ui/locks/manage/LockManagerViewer.java | 249 ++++++++++++++++++ .../dbeaver/ext/ui/locks/table/LockTable.java | 160 +++++++++++ .../ext/ui/locks/table/LockTableDetail.java | 133 ++++++++++ 23 files changed, 1689 insertions(+) create mode 100644 plugins/org.jkiss.dbeaver.ext.ui.locks/.classpath create mode 100644 plugins/org.jkiss.dbeaver.ext.ui.locks/.project create mode 100644 plugins/org.jkiss.dbeaver.ext.ui.locks/.settings/org.eclipse.jdt.core.prefs create mode 100644 plugins/org.jkiss.dbeaver.ext.ui.locks/META-INF/MANIFEST.MF create mode 100644 plugins/org.jkiss.dbeaver.ext.ui.locks/build.properties create mode 100644 plugins/org.jkiss.dbeaver.ext.ui.locks/pom.xml create mode 100644 plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/edit/AbstractLockEditor.java create mode 100644 plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraph.java create mode 100644 plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphConnectionAnchor.java create mode 100644 plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphConnectionEditPolicy.java create mode 100644 plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphEdge.java create mode 100644 plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphEdgeEditPart.java create mode 100644 plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphEditPart.java create mode 100644 plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphEditPartFactory.java create mode 100644 plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphNode.java create mode 100644 plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphNodeEditPart.java create mode 100644 plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphNodeFigure.java create mode 100644 plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphXYLayoutEditPolicy.java create mode 100644 plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphicalView.java create mode 100644 plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/manage/LockGraphManager.java create mode 100644 plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/manage/LockManagerViewer.java create mode 100644 plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/table/LockTable.java create mode 100644 plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/table/LockTableDetail.java diff --git a/plugins/org.jkiss.dbeaver.ext.ui.locks/.classpath b/plugins/org.jkiss.dbeaver.ext.ui.locks/.classpath new file mode 100644 index 0000000000..098194ca4b --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.ui.locks/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/plugins/org.jkiss.dbeaver.ext.ui.locks/.project b/plugins/org.jkiss.dbeaver.ext.ui.locks/.project new file mode 100644 index 0000000000..0c31feb426 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.ui.locks/.project @@ -0,0 +1,28 @@ + + + org.jkiss.dbeaver.ext.ui.locks + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/plugins/org.jkiss.dbeaver.ext.ui.locks/.settings/org.eclipse.jdt.core.prefs b/plugins/org.jkiss.dbeaver.ext.ui.locks/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..f42de363af --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.ui.locks/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +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 diff --git a/plugins/org.jkiss.dbeaver.ext.ui.locks/META-INF/MANIFEST.MF b/plugins/org.jkiss.dbeaver.ext.ui.locks/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..d03e6199f0 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.ui.locks/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +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 diff --git a/plugins/org.jkiss.dbeaver.ext.ui.locks/build.properties b/plugins/org.jkiss.dbeaver.ext.ui.locks/build.properties new file mode 100644 index 0000000000..34d2e4d2da --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.ui.locks/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/plugins/org.jkiss.dbeaver.ext.ui.locks/pom.xml b/plugins/org.jkiss.dbeaver.ext.ui.locks/pom.xml new file mode 100644 index 0000000000..ae3b933347 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.ui.locks/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + + org.jkiss.dbeaver + dbeaver + 1.0.0 + ../../ + + org.jkiss.dbeaver.ext.ui.locks + 1.0.0 + eclipse-plugin + diff --git a/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/edit/AbstractLockEditor.java b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/edit/AbstractLockEditor.java new file mode 100644 index 0000000000..04bdd350ad --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/edit/AbstractLockEditor.java @@ -0,0 +1,65 @@ +/* + * 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 + { + + 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); + } + + } diff --git a/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraph.java b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraph.java new file mode 100644 index 0000000000..ac08bfae10 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraph.java @@ -0,0 +1,78 @@ +/* + * 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 nodes = new ArrayList(); + + 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 getNodes() { + return this.nodes; + } + + + public int getMaxWidth() { + return maxWidth; + } + + + public void setMaxWidth(int maxWidth) { + this.maxWidth = maxWidth; + } +} diff --git a/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphConnectionAnchor.java b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphConnectionAnchor.java new file mode 100644 index 0000000000..133b25bec6 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphConnectionAnchor.java @@ -0,0 +1,40 @@ +/* + * 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; + } + +} diff --git a/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphConnectionEditPolicy.java b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphConnectionEditPolicy.java new file mode 100644 index 0000000000..4247be12cf --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphConnectionEditPolicy.java @@ -0,0 +1,30 @@ +/* + * 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; + } + +} diff --git a/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphEdge.java b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphEdge.java new file mode 100644 index 0000000000..33bc9aae55 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphEdge.java @@ -0,0 +1,52 @@ +/* + * 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); + } + } +} diff --git a/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphEdgeEditPart.java b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphEdgeEditPart.java new file mode 100644 index 0000000000..6649ed5f56 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphEdgeEditPart.java @@ -0,0 +1,54 @@ +/* + * 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; + + + } + +} diff --git a/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphEditPart.java b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphEditPart.java new file mode 100644 index 0000000000..5eb07b5d0d --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphEditPart.java @@ -0,0 +1,58 @@ +/* + * 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 getModelChildren() { + List nodes = ((LockGraph) getModel()).getNodes(); + return nodes; + } + + @Override + protected void refreshVisuals() { + ConnectionLayer connectionLayer = (ConnectionLayer) getLayer(LayerConstants.CONNECTION_LAYER); + connectionLayer.setConnectionRouter(new ShortestPathConnectionRouter(getFigure())); + } + + +} diff --git a/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphEditPartFactory.java b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphEditPartFactory.java new file mode 100644 index 0000000000..15d1ca3b5a --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphEditPartFactory.java @@ -0,0 +1,50 @@ +/* + * 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; + } +} diff --git a/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphNode.java b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphNode.java new file mode 100644 index 0000000000..f8a5d9a800 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphNode.java @@ -0,0 +1,122 @@ +/* + * 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 sourceEdges; + + private List targetEdges; + + public LockGraphNode(DBAServerLock lock){ + + this.lock = lock; + this.level = 0; + this.span = 0; + this.title = lock.getTitle(); + this.sourceEdges = new ArrayList(); + this.targetEdges = new ArrayList(); + + 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(); + this.targetEdges = new ArrayList(); + } + + public void addSourceEdge(LockGraphEdge sourceEdge) { + this.sourceEdges.add(sourceEdge); + } + + public void addTargetEdge(LockGraphEdge targetEdge) { + this.targetEdges.add(targetEdge); + } + + public List getSourceEdges() { + return this.sourceEdges; + } + + public List 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; + } + + +} + diff --git a/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphNodeEditPart.java b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphNodeEditPart.java new file mode 100644 index 0000000000..5a88579d0d --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphNodeEditPart.java @@ -0,0 +1,131 @@ +/* + * 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 getModelSourceConnections() { + return ((LockGraphNode) getModel()).getSourceEdges(); + } + + @Override + protected List 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()); + } + + } +} + diff --git a/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphNodeFigure.java b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphNodeFigure.java new file mode 100644 index 0000000000..7c809af9fb --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphNodeFigure.java @@ -0,0 +1,60 @@ +/* + * 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 diff --git a/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphXYLayoutEditPolicy.java b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphXYLayoutEditPolicy.java new file mode 100644 index 0000000000..efbf65c77e --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphXYLayoutEditPolicy.java @@ -0,0 +1,40 @@ +/* + * 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; + } + + + +} diff --git a/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphicalView.java b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphicalView.java new file mode 100644 index 0000000000..90f1ef74eb --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/graph/LockGraphicalView.java @@ -0,0 +1,108 @@ +/* + * 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; + } + +} diff --git a/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/manage/LockGraphManager.java b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/manage/LockGraphManager.java new file mode 100644 index 0000000000..24c9111bdc --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/manage/LockGraphManager.java @@ -0,0 +1,183 @@ +/* + * 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, ID_TYPE> { + + private Map nodes = new HashMap(); + + private Map graphIndex = new HashMap(); + + + 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 current = new ArrayList(); + + Set> touched = new HashSet<>(); //Prevent Cycle + + current.add(root); + + touched.add((DBAServerLock) root); + + Map> childs = new HashMap>(); + + while(current.size() > 0) { + + if (maxWidth < current.size()) { + + maxWidth = current.size(); + + } + + for(int index = 0; index < current.size(); index++) { + + DBAServerLock l = (DBAServerLock) 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 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((Collection) childs.values()); + + childs.clear(); + + + } + + graph.setMaxWidth(maxWidth); + + return graph; + + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void buildGraphs(Map locks) { + + Set roots = new HashSet(); + + 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); + } + + } + +} diff --git a/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/manage/LockManagerViewer.java b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/manage/LockManagerViewer.java new file mode 100644 index 0000000000..efcc16d831 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/manage/LockManagerViewer.java @@ -0,0 +1,249 @@ +/* + * 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,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,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,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 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,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 diff --git a/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/table/LockTable.java b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/table/LockTable.java new file mode 100644 index 0000000000..8102cc8259 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/table/LockTable.java @@ -0,0 +1,160 @@ +/* + * 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> { + + private DBAServerLockManager,DBAServerLockItem> lockManager; + + public LockTable(Composite parent, int style, IWorkbenchSite site, DBAServerLockManager,DBAServerLockItem> lockManager) + { + super(parent, style, site, CONTENT_PROVIDER); + this.lockManager = lockManager; + } + + public DBAServerLockManager,DBAServerLockItem> getLockManager() { + return lockManager; + } + + @NotNull + @Override + protected String getListConfigId(List> classList) { + return "Locks/" + lockManager.getDataSource().getContainer().getDriver().getId(); + } + + @Override + protected LoadingJob>> createLoadService() + { + return LoadingJob.createService( + new LoadLocksService(), + new ObjectsLoadVisualizer()); + } + + public LoadingJob createAlterService(DBAServerLock lock, Map options) + { + return LoadingJob.createService( + new KillSessionByLockService(lock, options), + new ObjectActionVisualizer()); + } + + public void init(DBAServerLockManager,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>> { + + protected LoadLocksService() + { + super("Load locks", lockManager.getDataSource()); + } + + @Override + public Collection> 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 { + private final DBAServerLock lock; + private final Map options; + + + protected KillSessionByLockService(DBAServerLock lock, Map 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); + } + } + + } + +} diff --git a/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/table/LockTableDetail.java b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/table/LockTableDetail.java new file mode 100644 index 0000000000..7b137d6934 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.ui.locks/src/org/jkiss/dbeaver/ext/ui/locks/table/LockTableDetail.java @@ -0,0 +1,133 @@ +/* + * 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 { + + private DBAServerLockManager,DBAServerLockItem> lockManager; + Map options = new HashMap(1); + + public Map getOptions() { + return options; + } + + public LockTableDetail(Composite parent, int style, IWorkbenchSite site, DBAServerLockManager,DBAServerLockItem> lockManager) + { + super(parent, style, site, CONTENT_PROVIDER); + this.lockManager = lockManager; + } + + public DBAServerLockManager,DBAServerLockItem> getLockManager() { + return lockManager; + } + + @NotNull + @Override + protected String getListConfigId(List> classList) { + return "LocksDetail/" + lockManager.getDataSource().getContainer().getDriver().getId(); + } + + @Override + protected LoadingJob> createLoadService() + { + return LoadingJob.createService( + new LoadLockDetailService(), + new ObjectsLoadVisualizer()); + } + + public void init(DBAServerLockManager,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> { + + protected LoadLockDetailService() + { + super(String.format("Load lock details"), lockManager.getDataSource()); + } + + @Override + public Collection 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); + } + } + } + + +} + + -- GitLab