diff --git a/plugins/org.jkiss.dbeaver.ui.dashboard/src/org/jkiss/dbeaver/ui/dashboard/DashboardStorage.java b/plugins/org.jkiss.dbeaver.ui.dashboard/src/org/jkiss/dbeaver/ui/dashboard/DashboardStorage.java deleted file mode 100644 index db32cf192de08fad54d75115feb81ec271844b59..0000000000000000000000000000000000000000 --- a/plugins/org.jkiss.dbeaver.ui.dashboard/src/org/jkiss/dbeaver/ui/dashboard/DashboardStorage.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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"); - } - -} diff --git a/plugins/org.jkiss.dbeaver.ui.dashboard/src/org/jkiss/dbeaver/ui/dashboard/control/DashboardChartComposite.java b/plugins/org.jkiss.dbeaver.ui.dashboard/src/org/jkiss/dbeaver/ui/dashboard/control/DashboardChartComposite.java index 38bf2018a6bbaa03b67a2a1a4a780d125a9515ff..b80d48c8d7223a3d3ff8d5155aca1d6b596dcd26 100644 --- a/plugins/org.jkiss.dbeaver.ui.dashboard/src/org/jkiss/dbeaver/ui/dashboard/control/DashboardChartComposite.java +++ b/plugins/org.jkiss.dbeaver.ui.dashboard/src/org/jkiss/dbeaver/ui/dashboard/control/DashboardChartComposite.java @@ -22,6 +22,7 @@ import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Composite; import org.jkiss.dbeaver.ui.charts.BaseChartComposite; import org.jkiss.dbeaver.ui.dashboard.model.DashboardContainer; +import org.jkiss.dbeaver.ui.dashboard.view.DashboardChartConfigDialog; /** * Dashboard chart composite diff --git a/plugins/org.jkiss.dbeaver.ui.dashboard/src/org/jkiss/dbeaver/ui/dashboard/view/DashboardAddDialog.java b/plugins/org.jkiss.dbeaver.ui.dashboard/src/org/jkiss/dbeaver/ui/dashboard/view/DashboardAddDialog.java new file mode 100644 index 0000000000000000000000000000000000000000..040fe48638285de920f8641faf615f627bc4a2b5 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ui.dashboard/src/org/jkiss/dbeaver/ui/dashboard/view/DashboardAddDialog.java @@ -0,0 +1,63 @@ +/* + * 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 diff --git a/plugins/org.jkiss.dbeaver.ui.dashboard/src/org/jkiss/dbeaver/ui/dashboard/control/DashboardChartConfigDialog.java b/plugins/org.jkiss.dbeaver.ui.dashboard/src/org/jkiss/dbeaver/ui/dashboard/view/DashboardChartConfigDialog.java similarity index 73% rename from plugins/org.jkiss.dbeaver.ui.dashboard/src/org/jkiss/dbeaver/ui/dashboard/control/DashboardChartConfigDialog.java rename to plugins/org.jkiss.dbeaver.ui.dashboard/src/org/jkiss/dbeaver/ui/dashboard/view/DashboardChartConfigDialog.java index b81377af7daa22e37c1922e1f12d1f86e7132fc2..e9b60d225bcf166d2ce38fe0a6e583447344f980 100644 --- a/plugins/org.jkiss.dbeaver.ui.dashboard/src/org/jkiss/dbeaver/ui/dashboard/control/DashboardChartConfigDialog.java +++ b/plugins/org.jkiss.dbeaver.ui.dashboard/src/org/jkiss/dbeaver/ui/dashboard/view/DashboardChartConfigDialog.java @@ -14,30 +14,23 @@ * See the License for the specific language governing permissions and * 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.swt.custom.CTabFolder; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; 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.dialogs.BaseDialog; -class DashboardChartConfigDialog extends BaseDialog { +public class DashboardChartConfigDialog extends BaseDialog { private static final String DIALOG_ID = "DBeaver.DashboardChartConfigDialog";//$NON-NLS-1$ - private DashboardChartComposite chartComposite; - private DashboardContainer container; - private CTabFolder chartTabFolder; - - DashboardChartConfigDialog(DashboardChartComposite chartComposite, DashboardContainer container) + public DashboardChartConfigDialog(DashboardChartComposite chartComposite, DashboardContainer container) { - super(chartComposite.getShell(), "Charts for [" + container.getDataSourceContainer().getName() + "]", null); - - this.chartComposite = chartComposite; - this.container = container; + super(chartComposite.getShell(), "Dashboard [" + container.getDashboardTitle() + "]", null); } @Override diff --git a/plugins/org.jkiss.dbeaver.ui.dashboard/src/org/jkiss/dbeaver/ui/dashboard/view/DashboardViewConfiguration.java b/plugins/org.jkiss.dbeaver.ui.dashboard/src/org/jkiss/dbeaver/ui/dashboard/view/DashboardViewConfiguration.java new file mode 100644 index 0000000000000000000000000000000000000000..e251457f4c3d72bd7f95d0407b73aa07ba37439c --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ui.dashboard/src/org/jkiss/dbeaver/ui/dashboard/view/DashboardViewConfiguration.java @@ -0,0 +1,126 @@ +/* + * 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 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"); + } + +} diff --git a/plugins/org.jkiss.dbeaver.ui.dashboard/src/org/jkiss/dbeaver/ui/dashboard/view/HandlerDashboardAddItem.java b/plugins/org.jkiss.dbeaver.ui.dashboard/src/org/jkiss/dbeaver/ui/dashboard/view/HandlerDashboardAddItem.java index af383bf52ee81e2d0cce49d5ab00247b56b2db43..79277f292505ff8e30eb9eccc55603fd3c992100 100644 --- a/plugins/org.jkiss.dbeaver.ui.dashboard/src/org/jkiss/dbeaver/ui/dashboard/view/HandlerDashboardAddItem.java +++ b/plugins/org.jkiss.dbeaver.ui.dashboard/src/org/jkiss/dbeaver/ui/dashboard/view/HandlerDashboardAddItem.java @@ -18,6 +18,8 @@ package org.jkiss.dbeaver.ui.dashboard.view; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.ui.handlers.HandlerUtil; public class HandlerDashboardAddItem extends HandlerDashboardAbstract { @@ -25,7 +27,10 @@ public class HandlerDashboardAddItem extends HandlerDashboardAbstract { public Object execute(ExecutionEvent event) throws ExecutionException { DashboardView view = getActiveDashboardView(event); if (view != null) { + DashboardAddDialog addDialog = new DashboardAddDialog(HandlerUtil.getActiveShell(event)); + if (addDialog.open() == IDialogConstants.OK_ID) { + } } return null; }