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

#5191 Dashboard model + renderers


Former-commit-id: ddda092b
上级 880bd6c7
......@@ -452,17 +452,17 @@ public class CommonUtils {
@Nullable
public static <T extends Enum<T>> T valueOf(@NotNull Class<T> type, @Nullable String name) {
return valueOf(type, name, false);
return valueOf(type, name, null, false);
}
@Nullable
public static <T extends Enum<T>> T valueOf(@Nullable Class<T> type, @Nullable String name, boolean underscoreSpaces) {
public static <T extends Enum<T>> T valueOf(@Nullable Class<T> type, @Nullable String name, T defValue, boolean underscoreSpaces) {
if (name == null) {
return null;
return defValue;
}
name = name.trim();
if (name.length() == 0) {
return null;
return defValue;
}
if (underscoreSpaces) {
name = name.replace(' ', '_');
......@@ -471,7 +471,19 @@ public class CommonUtils {
return Enum.valueOf(type, name);
} catch (Exception e) {
e.printStackTrace();
return null;
return defValue;
}
}
public static <T extends Enum<T>> T valueOf(Class<T> enumType, String str, T defValue) {
if (isEmpty(str)) {
return defValue;
}
try {
return Enum.valueOf(enumType, str);
} catch (Exception e) {
e.printStackTrace();
return defValue;
}
}
......@@ -583,4 +595,5 @@ public class CommonUtils {
else
return String.valueOf(val);
}
}
......@@ -120,16 +120,16 @@ public class OracleTablespace extends OracleGlobalObject implements DBPRefreshab
this.maxExtents = JDBCUtils.safeGetLong(dbResult, "MAX_EXTENTS");
this.pctIncrease = JDBCUtils.safeGetLong(dbResult, "PCT_INCREASE");
this.minExtLen = JDBCUtils.safeGetLong(dbResult, "MIN_EXTLEN");
this.status = CommonUtils.valueOf(Status.class, JDBCUtils.safeGetString(dbResult, "STATUS"), true);
this.contents = CommonUtils.valueOf(Contents.class, JDBCUtils.safeGetString(dbResult, "CONTENTS"), true);
this.logging = CommonUtils.valueOf(Logging.class, JDBCUtils.safeGetString(dbResult, "LOGGING"), true);
this.status = CommonUtils.valueOf(Status.class, JDBCUtils.safeGetString(dbResult, "STATUS"), Status.OFFLINE, true);
this.contents = CommonUtils.valueOf(Contents.class, JDBCUtils.safeGetString(dbResult, "CONTENTS"), null, true);
this.logging = CommonUtils.valueOf(Logging.class, JDBCUtils.safeGetString(dbResult, "LOGGING"), null, true);
this.forceLogging = JDBCUtils.safeGetBoolean(dbResult, "FORCE_LOGGING", "Y");
this.extentManagement = CommonUtils.valueOf(ExtentManagement.class, JDBCUtils.safeGetString(dbResult, "EXTENT_MANAGEMENT"), true);
this.allocationType = CommonUtils.valueOf(AllocationType.class, JDBCUtils.safeGetString(dbResult, "ALLOCATION_TYPE"), true);
this.extentManagement = CommonUtils.valueOf(ExtentManagement.class, JDBCUtils.safeGetString(dbResult, "EXTENT_MANAGEMENT"), null, true);
this.allocationType = CommonUtils.valueOf(AllocationType.class, JDBCUtils.safeGetString(dbResult, "ALLOCATION_TYPE"), null, true);
this.pluggedIn = JDBCUtils.safeGetBoolean(dbResult, "PLUGGED_IN", "Y");
this.segmentSpaceManagement = CommonUtils.valueOf(SegmentSpaceManagement.class, JDBCUtils.safeGetString(dbResult, "SEGMENT_SPACE_MANAGEMENT"), true);
this.segmentSpaceManagement = CommonUtils.valueOf(SegmentSpaceManagement.class, JDBCUtils.safeGetString(dbResult, "SEGMENT_SPACE_MANAGEMENT"), null, true);
this.defTableCompression = "ENABLED".equals(JDBCUtils.safeGetString(dbResult, "DEF_TAB_COMPRESSION"));
this.retention = CommonUtils.valueOf(Retention.class, JDBCUtils.safeGetString(dbResult, "RETENTION"), true);
this.retention = CommonUtils.valueOf(Retention.class, JDBCUtils.safeGetString(dbResult, "RETENTION"), null, true);
this.bigFile = JDBCUtils.safeGetBoolean(dbResult, "BIGFILE", "Y");
}
......
......@@ -630,7 +630,8 @@
<extension point="org.jkiss.dbeaver.dashboard">
<dashboard id="postgresql.sessionCount" label="Server sessions" type="histogram" refresh="2" calc="value">
<dashboard id="postgresql.sessionCount" label="Server sessions" type="histogram" group="Standard" refresh="2" calc="value" fetch="columns" showByDefault="true">
<datasource id="postgresql"/>
<query>
SELECT
(SELECT count(*) AS "Active" FROM pg_catalog.pg_stat_activity sa WHERE state='active'),
......@@ -638,7 +639,8 @@
(SELECT count(*) as "Total" FROM pg_catalog.pg_stat_activity sa)
</query>
</dashboard>
<dashboard id="postgresql.transactionCount" label="Transactions per second" type="histogram" refresh="2" calc="delta">
<dashboard id="postgresql.transactionCount" label="Transactions per second" group="Standard" type="histogram" refresh="2" calc="delta" fetch="columns" showByDefault="true">
<datasource id="postgresql"/>
<query>
SELECT
(SELECT sum(xact_commit) + sum(xact_rollback) AS "Total" FROM pg_stat_database),
......
......@@ -23,3 +23,4 @@ Require-Bundle: org.eclipse.equinox.preferences,
org.jkiss.dbeaver.ui.editors.base,
org.jkiss.dbeaver.ui.navigator,
org.jkiss.bundle.jfreechart
Export-Package: org.jkiss.dbeaver.ui.dashboard.control
......@@ -75,9 +75,9 @@
</extension>
<extension point="org.jkiss.dbeaver.dashboard">
<dashboard >
<dashboardType id="histogram" label="Histogram" renderer="org.jkiss.dbeaver.ui.dashboard.control.DashboardRendererHistogram">
</dashboard>
</dashboardType>
</extension>
</plugin>
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ui.dashboard.control;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
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.swt.widgets.Text;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.dashboard.registry.DashboardDescriptor;
public class DashboardItem extends Composite {
private DashboardDescriptor dashboardDescriptor;
public DashboardItem(DashboardList parent, DashboardDescriptor dashboardDescriptor) {
super(parent, SWT.BORDER);
GridLayout layout = new GridLayout(1, true);
layout.marginHeight = 0;
layout.marginWidth = 0;
setLayout(layout);
this.dashboardDescriptor = dashboardDescriptor;
try {
DashboardRenderer renderer = dashboardDescriptor.getType().createRenderer();
renderer.createDashboard(this);
} catch (DBException e) {
// Something went wrong
Text errorLabel = new Text(this, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP);
errorLabel.setText("Error creating " + dashboardDescriptor.getLabel() + " renderer: " + e.getMessage());
errorLabel.setLayoutData(new GridData(GridData.CENTER, GridData.CENTER, true, true));
}
}
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
return new Point(200, 200);//super.computeSize(wHint, hHint, changed);
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ui.dashboard.control;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.DBPDataSourceProvider;
import org.jkiss.dbeaver.model.IDataSourceContainerProvider;
import org.jkiss.dbeaver.model.IDataSourceContainerProviderEx;
import org.jkiss.dbeaver.ui.dashboard.registry.DashboardDescriptor;
import org.jkiss.dbeaver.ui.dashboard.registry.DashboardRegistry;
import java.util.List;
public class DashboardList extends Composite {
private IDataSourceContainerProvider provider;
public DashboardList(Composite parent, IDataSourceContainerProvider provider) {
super(parent, SWT.NONE);
this.provider = provider;
RowLayout layout = new RowLayout();
layout.wrap = true;
layout.spacing = 5;
this.setLayout(layout);
}
DBPDataSourceContainer getDataSourceContainer() {
return provider.getDataSourceContainer();
}
void createDefaultDashboards() {
List<DashboardDescriptor> dashboards = DashboardRegistry.getInstance().getDashboards(provider.getDataSourceContainer(), true);
for (DashboardDescriptor dd : dashboards) {
DashboardItem item = new DashboardItem(this, dd);
}
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ui.dashboard.control;
import org.eclipse.swt.widgets.Composite;
/**
* Dashboard renderer
*/
public interface DashboardRenderer {
void createDashboard(Composite composite);
void updateDashboard();
void disposeDashboard();
}
......@@ -19,21 +19,20 @@ package org.jkiss.dbeaver.ui.dashboard.control;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.DBPEvent;
import org.jkiss.dbeaver.model.DBPEventListener;
import org.jkiss.dbeaver.model.IDataSourceContainerProvider;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.UIUtils;
import java.util.Date;
public class DashboardViewManager implements DBPEventListener {
public class DashboardViewManager implements DBPEventListener, IDataSourceContainerProvider {
private final DBPDataSourceContainer dataSourceContainer;
private Composite dashContainer;
private DashboardList dashContainer;
private CLabel statusLabel;
private Date initDate;
......@@ -42,7 +41,9 @@ public class DashboardViewManager implements DBPEventListener {
this.dataSourceContainer = dataSourceContainer;
this.dataSourceContainer.getRegistry().addDataSourceListener(this);
//UIDashboardActivator.getDefault().getPreferences().get
if (!this.dataSourceContainer.isConnected()) {
//DataSourceConnectHandler
}
}
public void dispose() {
......@@ -65,14 +66,15 @@ public class DashboardViewManager implements DBPEventListener {
public void createControl(Composite parent) {
Composite composite = UIUtils.createComposite(parent, 1);
dashContainer = new Composite(composite, SWT.NONE);
dashContainer = new DashboardList(composite, this);
dashContainer.setLayoutData(new GridData(GridData.FILL_BOTH));
dashContainer.setLayout(new RowLayout());
statusLabel = new CLabel(composite, SWT.NONE);
statusLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
updateStatus();
dashContainer.createDefaultDashboards();
}
private void updateStatus() {
......@@ -81,4 +83,8 @@ public class DashboardViewManager implements DBPEventListener {
statusLabel.setText(this.dataSourceContainer.getName() + ": " + status);
}
@Override
public DBPDataSourceContainer getDataSourceContainer() {
return dataSourceContainer;
}
}
......@@ -19,10 +19,10 @@ package org.jkiss.dbeaver.ui.dashboard.model;
/**
* Dashboard value calculation
*/
public enum DashboardCalc {
public enum DashboardCalcType {
VALUE, // Absolute value
DELTA, // Delta between last two value
PERCENT, // Percent
value, // Absolute value
delta, // Delta between last two value
percent, // Percent
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ui.dashboard.model;
/**
* Dashboard data fetch type
*/
public enum DashboardFetchType {
columns,
rows,
}
......@@ -20,8 +20,13 @@ import org.eclipse.core.runtime.IConfigurationElement;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.impl.AbstractContextDescriptor;
import org.jkiss.dbeaver.ui.dashboard.model.DashboardCalcType;
import org.jkiss.dbeaver.ui.dashboard.model.DashboardFetchType;
import org.jkiss.utils.CommonUtils;
import java.util.ArrayList;
import java.util.List;
/**
* DashboardDescriptor
*/
......@@ -29,17 +34,45 @@ public class DashboardDescriptor extends AbstractContextDescriptor
{
public static final String EXTENSION_ID = "org.jkiss.dbeaver.dashboard"; //$NON-NLS-1$
private final String id;
private final String label;
private final String description;
private final String group;
private final String[] tags;
private String id;
private String label;
private String description;
private String group;
private boolean showByDefault;
private DashboardTypeDescriptor type;
private String[] tags;
private final List<DataSourceMapping> dataSourceMappings = new ArrayList<>();
private DashboardCalcType calcType;
private DashboardFetchType fetchType;
private static class DataSourceMapping {
private final String dataSourceProvider;
private final String driverId;
private final String driverClass;
public DataSourceMapping(IConfigurationElement config) {
this.dataSourceProvider = config.getAttribute("datasource");
this.driverId = config.getAttribute("driver");
this.driverClass = config.getAttribute("driverClass");
}
private final String dataSourceProvider;
private final String driverId;
private final String driverClass;
public boolean matches(DBPDataSourceContainer dataSource) {
if (this.dataSourceProvider != null && !this.dataSourceProvider.equals(dataSource.getDriver().getProviderId())) {
return false;
}
if (this.driverId != null && !this.driverId.equals(dataSource.getDriver().getId())) {
return false;
}
if (this.driverClass != null && !this.driverClass.equals(dataSource.getDriver().getDriverClassName())) {
return false;
}
return true;
}
}
public DashboardDescriptor(
DashboardRegistry registry,
IConfigurationElement config)
{
super(config);
......@@ -49,10 +82,18 @@ public class DashboardDescriptor extends AbstractContextDescriptor
this.description = config.getAttribute("description");
this.group = config.getAttribute("group");
this.tags = CommonUtils.notEmpty(config.getAttribute("tags")).split(",");
this.showByDefault = CommonUtils.toBoolean(config.getAttribute("showByDefault"));
this.type = registry.getDashboardType(config.getAttribute("type"));
this.calcType = CommonUtils.valueOf(DashboardCalcType.class, config.getAttribute("calc"), DashboardCalcType.value);
this.fetchType = CommonUtils.valueOf(DashboardFetchType.class, config.getAttribute("fetch"), DashboardFetchType.columns);
this.dataSourceProvider = config.getAttribute("datasource");
this.driverId = config.getAttribute("driver");
this.driverClass = config.getAttribute("driverClass");
IConfigurationElement[] datasourceList = config.getChildren("datasource");
if (datasourceList != null) {
for (IConfigurationElement ds : datasourceList) {
dataSourceMappings.add(new DataSourceMapping(ds));
}
}
}
@NotNull
......@@ -75,19 +116,31 @@ public class DashboardDescriptor extends AbstractContextDescriptor
return group;
}
public boolean isShowByDefault() {
return showByDefault;
}
public DashboardTypeDescriptor getType() {
return type;
}
public String[] getTags() {
return tags;
}
public DashboardCalcType getCalcType() {
return calcType;
}
public DashboardFetchType getFetchType() {
return fetchType;
}
public boolean matches(DBPDataSourceContainer dataSource) {
if (this.dataSourceProvider != null && !this.dataSourceProvider.equals(dataSource.getDriver().getProviderId())) {
return false;
}
if (this.driverId != null && !this.driverId.equals(dataSource.getDriver().getId())) {
return false;
}
if (this.driverClass != null && !this.driverClass.equals(dataSource.getDriver().getDriverClassName())) {
return false;
for (DataSourceMapping dsm : dataSourceMappings) {
if (!dsm.matches(dataSource)) {
return false;
}
}
return true;
......
......@@ -34,25 +34,43 @@ public class DashboardRegistry {
return instance;
}
private final List<DashboardDescriptor> descriptors = new ArrayList<>();
private final List<DashboardDescriptor> dashboardList = new ArrayList<>();
private final List<DashboardTypeDescriptor> dashboardTypeList = new ArrayList<>();
private DashboardRegistry(IExtensionRegistry registry) {
// Load data descriptors from external plugins
{
IConfigurationElement[] extElements = registry.getConfigurationElementsFor(DashboardDescriptor.EXTENSION_ID);
for (IConfigurationElement ext : extElements) {
DashboardDescriptor formatterDescriptor = new DashboardDescriptor(ext);
descriptors.add(formatterDescriptor);
// Load data dashboardList from external plugins
IConfigurationElement[] extElements = registry.getConfigurationElementsFor(DashboardDescriptor.EXTENSION_ID);
// Load types
for (IConfigurationElement ext : extElements) {
if ("dashboardType".equals(ext.getName())) {
dashboardTypeList.add(
new DashboardTypeDescriptor(ext));
}
}
// Load dashboards
for (IConfigurationElement ext : extElements) {
if ("dashboard".equals(ext.getName())) {
dashboardList.add(
new DashboardDescriptor(this, ext));
}
}
}
public DashboardTypeDescriptor getDashboardType(String id) {
for (DashboardTypeDescriptor descriptor : dashboardTypeList) {
if (descriptor.getId().equals(id)) {
return descriptor;
}
}
return null;
}
public List<DashboardDescriptor> getAllDashboards() {
return descriptors;
return dashboardList;
}
public DashboardDescriptor getDashboard(String id) {
for (DashboardDescriptor descriptor : descriptors) {
public DashboardDescriptor getDashboards(String id) {
for (DashboardDescriptor descriptor : dashboardList) {
if (descriptor.getId().equals(id)) {
return descriptor;
}
......@@ -60,11 +78,13 @@ public class DashboardRegistry {
return null;
}
public List<DashboardDescriptor> getDashboard(DBPDataSourceContainer dataSourceContainer) {
public List<DashboardDescriptor> getDashboards(DBPDataSourceContainer dataSourceContainer, boolean defaultOnly) {
List<DashboardDescriptor> result = new ArrayList<>();
for (DashboardDescriptor dd : descriptors) {
for (DashboardDescriptor dd : dashboardList) {
if (dd.matches(dataSourceContainer)) {
result.add(dd);
if (!defaultOnly || dd.isShowByDefault()) {
result.add(dd);
}
}
}
return result;
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ui.dashboard.registry;
import org.eclipse.core.runtime.IConfigurationElement;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.impl.AbstractContextDescriptor;
import org.jkiss.dbeaver.ui.dashboard.control.DashboardRenderer;
/**
* DashboardDescriptor
*/
public class DashboardTypeDescriptor extends AbstractContextDescriptor
{
private String id;
private String label;
private String description;
private ObjectType implType;
public DashboardTypeDescriptor(
IConfigurationElement config)
{
super(config);
this.id = config.getAttribute("id");
this.label = config.getAttribute("label");
this.description = config.getAttribute("description");
this.implType = new ObjectType(config.getAttribute("class"));
}
@NotNull
public String getId() {
return id;
}
@NotNull
public String getLabel()
{
return label;
}
public String getDescription()
{
return description;
}
public DashboardRenderer createRenderer() throws DBException {
return implType.createInstance(DashboardRenderer.class);
}
@Override
public String toString() {
return id;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册