提交 fef862f2 编写于 作者: S Serge Rider

#4209 Dashboards configuration and dialogs

上级 a3a97d95
/*
* 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;
import org.jkiss.dbeaver.ui.dashboard.internal.UIDashboardActivator;
import org.jkiss.dbeaver.ui.dashboard.registry.DashboardDescriptor;
import java.io.File;
/**
* Dashboard renderer
*/
public class DashboardStorage {
public static class ViewSettings {
DashboardDescriptor dashboard;
}
private String viewId;
public DashboardStorage(String viewId) {
this.viewId = viewId;
}
public boolean loadSettings() {
//getInstance().getStateLocation().toFile()
ViewSettings viewConfig = getViewsSettings(viewId);
if (viewConfig == null) {
return false;
}
return true;
}
private ViewSettings getViewsSettings(String viewId) {
ViewSettings viewSettings = new ViewSettings();
File configFile = getConfigFile(viewId);
if (configFile.exists()) {
}
return viewSettings;
}
private File getConfigFile(String viewId) {
File pluginFolder = UIDashboardActivator.getDefault().getStateLocation().toFile();
return new File(pluginFolder, "view-" + viewId + ".xml");
}
}
...@@ -22,6 +22,7 @@ import org.eclipse.swt.graphics.Point; ...@@ -22,6 +22,7 @@ import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.jkiss.dbeaver.ui.charts.BaseChartComposite; import org.jkiss.dbeaver.ui.charts.BaseChartComposite;
import org.jkiss.dbeaver.ui.dashboard.model.DashboardContainer; import org.jkiss.dbeaver.ui.dashboard.model.DashboardContainer;
import org.jkiss.dbeaver.ui.dashboard.view.DashboardChartConfigDialog;
/** /**
* Dashboard chart composite * Dashboard chart composite
......
/*
* 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.view;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.jkiss.dbeaver.ui.controls.finder.viewer.AdvancedListViewer;
import org.jkiss.dbeaver.ui.dialogs.BaseDialog;
/**
* Dashboard add dialog
*/
public class DashboardAddDialog extends BaseDialog {
private static final String DIALOG_ID = "DBeaver.DashboardAddDialog";//$NON-NLS-1$
private static final int MANAGER_BUTTON_ID = 1000;
public DashboardAddDialog(Shell parentShell) {
super(parentShell, "Add Dashboard", null);
}
@Override
protected Composite createDialogArea(Composite parent) {
Composite dialogArea = super.createDialogArea(parent);
AdvancedListViewer listViewer = new AdvancedListViewer(dialogArea, SWT.NONE);
listViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
return dialogArea;
}
@Override
protected void createButtonsForButtonBar(Composite parent) {
((GridData)parent.getLayoutData()).grabExcessHorizontalSpace = true;
final Button createButton = createButton(parent, MANAGER_BUTTON_ID, "Manage ...", false);
((GridData) createButton.getLayoutData()).horizontalAlignment = GridData.BEGINNING;
((GridData) createButton.getLayoutData()).grabExcessHorizontalSpace = true;
createButton(parent, IDialogConstants.OK_ID, "Add", true);
createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
}
}
\ No newline at end of file
...@@ -14,30 +14,23 @@ ...@@ -14,30 +14,23 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.jkiss.dbeaver.ui.dashboard.control; package org.jkiss.dbeaver.ui.dashboard.view;
import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Control;
import org.jkiss.dbeaver.ui.UIUtils; import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.dashboard.control.DashboardChartComposite;
import org.jkiss.dbeaver.ui.dashboard.model.DashboardContainer; import org.jkiss.dbeaver.ui.dashboard.model.DashboardContainer;
import org.jkiss.dbeaver.ui.dialogs.BaseDialog; import org.jkiss.dbeaver.ui.dialogs.BaseDialog;
class DashboardChartConfigDialog extends BaseDialog { public class DashboardChartConfigDialog extends BaseDialog {
private static final String DIALOG_ID = "DBeaver.DashboardChartConfigDialog";//$NON-NLS-1$ private static final String DIALOG_ID = "DBeaver.DashboardChartConfigDialog";//$NON-NLS-1$
private DashboardChartComposite chartComposite; public DashboardChartConfigDialog(DashboardChartComposite chartComposite, DashboardContainer container)
private DashboardContainer container;
private CTabFolder chartTabFolder;
DashboardChartConfigDialog(DashboardChartComposite chartComposite, DashboardContainer container)
{ {
super(chartComposite.getShell(), "Charts for [" + container.getDataSourceContainer().getName() + "]", null); super(chartComposite.getShell(), "Dashboard [" + container.getDashboardTitle() + "]", null);
this.chartComposite = chartComposite;
this.container = container;
} }
@Override @Override
......
/*
* 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.view;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.ui.dashboard.internal.UIDashboardActivator;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.utils.xml.XMLBuilder;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
/**
* DashboardViewConfiguration
*/
public class DashboardViewConfiguration {
private static final Log log = Log.getLog(DashboardViewConfiguration.class);
private String viewId;
public class DashboardItemViewConfig {
private String dashboardId;
private String description;
private float widthRatio;
private long updatePeriod;
private int maxItems;
private long maxAge;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public float getWidthRatio() {
return widthRatio;
}
public void setWidthRatio(float widthRatio) {
this.widthRatio = widthRatio;
}
public long getUpdatePeriod() {
return updatePeriod;
}
public void setUpdatePeriod(long updatePeriod) {
this.updatePeriod = updatePeriod;
}
public int getMaxItems() {
return maxItems;
}
public void setMaxItems(int maxItems) {
this.maxItems = maxItems;
}
public long getMaxAge() {
return maxAge;
}
public void setMaxAge(long maxAge) {
this.maxAge = maxAge;
}
}
List<DashboardItemViewConfig> items = new ArrayList<>();
public DashboardViewConfiguration(String viewId) {
this.viewId = viewId;
loadSettings();
}
private void loadSettings() {
File configFile = getConfigFile();
if (!configFile.exists()) {
return;
}
}
private void saveSettings() {
File configFile = getConfigFile();
try (OutputStream out = new FileOutputStream(configFile)){
XMLBuilder xml = new XMLBuilder(out, GeneralUtils.UTF8_ENCODING);
xml.startElement("dashboards");
for (DashboardItemViewConfig itemConfig : items) {
xml.startElement("dashboard");
//itemConfig.serialize(xml);
xml.endElement();
}
xml.endElement();
out.flush();
} catch (Exception e) {
log.error("Error saving dashboard view configuration", e);
}
}
private File getConfigFile() {
File pluginFolder = UIDashboardActivator.getDefault().getStateLocation().toFile();
return new File(pluginFolder, "view-" + viewId + ".xml");
}
}
...@@ -18,6 +18,8 @@ package org.jkiss.dbeaver.ui.dashboard.view; ...@@ -18,6 +18,8 @@ package org.jkiss.dbeaver.ui.dashboard.view;
import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.ui.handlers.HandlerUtil;
public class HandlerDashboardAddItem extends HandlerDashboardAbstract { public class HandlerDashboardAddItem extends HandlerDashboardAbstract {
...@@ -25,8 +27,11 @@ public class HandlerDashboardAddItem extends HandlerDashboardAbstract { ...@@ -25,8 +27,11 @@ public class HandlerDashboardAddItem extends HandlerDashboardAbstract {
public Object execute(ExecutionEvent event) throws ExecutionException { public Object execute(ExecutionEvent event) throws ExecutionException {
DashboardView view = getActiveDashboardView(event); DashboardView view = getActiveDashboardView(event);
if (view != null) { if (view != null) {
DashboardAddDialog addDialog = new DashboardAddDialog(HandlerUtil.getActiveShell(event));
if (addDialog.open() == IDialogConstants.OK_ID) {
} }
}
return null; return null;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册