Skip to content

Commit

Permalink
Fixed #365 - Support Custom Series (Experimental)
Browse files Browse the repository at this point in the history
  • Loading branch information
eselmeister committed Aug 31, 2023
1 parent 855f3f1 commit fd41a37
Show file tree
Hide file tree
Showing 18 changed files with 959 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swtchart.ISeries;
import org.eclipse.swtchart.extensions.barcharts.IBarSeriesSettings;
import org.eclipse.swtchart.extensions.core.BaseChart;
import org.eclipse.swtchart.extensions.core.CustomSeriesListUI;
import org.eclipse.swtchart.extensions.core.IExtendedChart;
import org.eclipse.swtchart.extensions.core.ISeriesSettings;
import org.eclipse.swtchart.extensions.core.MappingsSupport;
Expand Down Expand Up @@ -109,19 +112,32 @@ protected Control createDialogArea(Composite parent) {
//
createSelectionAxisX(container);
createSelectionAxisY(container);
createSeriesList(container);
createSeriesSection(container);
//
return composite;
}

private void createSeriesList(Composite container) {
private void createSeriesSection(Composite parent) {

SeriesListUI seriesListUI = new SeriesListUI(container, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
seriesListUI.setTableSortable(preferenceStore.getBoolean(PreferenceConstants.P_SORT_LEGEND_TABLE));
Table table = seriesListUI.getTable();
TabFolder tabFolder = new TabFolder(parent, SWT.BOTTOM);
GridData gridData = new GridData(GridData.FILL_BOTH);
gridData.horizontalSpan = 2;
table.setLayoutData(gridData);
tabFolder.setLayoutData(gridData);
tabFolder.setLayout(new GridLayout(1, true));
//
createStandardSeriesList(tabFolder);
createCustomSeriesList(tabFolder);
}

private void createStandardSeriesList(TabFolder tabFolder) {

TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
tabItem.setText("Standard Series");
//
SeriesListUI seriesListUI = new SeriesListUI(tabFolder, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
seriesListUI.setTableSortable(preferenceStore.getBoolean(PreferenceConstants.P_SORT_LEGEND_TABLE));
Table table = seriesListUI.getTable();
table.setLayoutData(new GridData(GridData.FILL_BOTH));
seriesListUI.setInput(baseChart.getSeriesSet());
seriesListUI.setBaseChart(baseChart);
//
Expand Down Expand Up @@ -168,6 +184,21 @@ public void mouseDoubleClick(MouseEvent e) {
});
//
listControl.set(seriesListUI);
tabItem.setControl(seriesListUI.getTable());
}

private void createCustomSeriesList(TabFolder tabFolder) {

TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
tabItem.setText("Custom Series");
//
CustomSeriesListUI seriesListUI = new CustomSeriesListUI(tabFolder, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
// seriesListUI.setTableSortable(preferenceStore.getBoolean(PreferenceConstants.P_SORT_LEGEND_TABLE));
Table table = seriesListUI.getTable();
table.setLayoutData(new GridData(GridData.FILL_BOTH));
seriesListUI.setInput(baseChart.getCustomSeries().toArray());
//
tabItem.setControl(seriesListUI.getTable());
}

private void applySettings(BaseChart baseChart, ISeries<?> series, ISeriesSettings seriesSettingsSource, boolean refresh) {
Expand Down
1 change: 1 addition & 0 deletions org.eclipse.swtchart.extensions/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Export-Package: org.eclipse.swtchart.extensions.axisconverter,
org.eclipse.swtchart.extensions.marker,
org.eclipse.swtchart.extensions.menu,
org.eclipse.swtchart.extensions.menu.toggle,
org.eclipse.swtchart.extensions.model,
org.eclipse.swtchart.extensions.piecharts,
org.eclipse.swtchart.extensions.preferences,
org.eclipse.swtchart.extensions.properties,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2020, 2023 Lablicate GmbH.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Philip Wenig - initial API and implementation
*******************************************************************************/
package org.eclipse.swtchart.extensions.core;

import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.Composite;

public abstract class AbstractSeriesListUI extends TableViewer {

public AbstractSeriesListUI(Composite parent, int style) {

super(parent, style);
}

public void clear() {

super.setInput(null);
}

public boolean isTableSortable() {

return getComparator() != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Dr. Philip Wenig - initial API and implementation
* Philip Wenig - initial API and implementation
* Frank Buloup - Internationalization
* Himanshu Balasamanta - Circular Charts
*******************************************************************************/
Expand Down Expand Up @@ -50,6 +50,8 @@
import org.eclipse.swtchart.extensions.events.IHandledEventProcessor;
import org.eclipse.swtchart.extensions.exceptions.SeriesException;
import org.eclipse.swtchart.extensions.linecharts.ILineSeriesSettings;
import org.eclipse.swtchart.extensions.model.CustomSeries;
import org.eclipse.swtchart.extensions.model.ICustomSeries;
import org.eclipse.swtchart.extensions.piecharts.ICircularSeriesSettings;
import org.eclipse.swtchart.extensions.preferences.PreferenceConstants;
import org.eclipse.swtchart.extensions.scattercharts.IScatterSeriesSettings;
Expand Down Expand Up @@ -128,6 +130,10 @@ public class BaseChart extends AbstractExtendedChart implements IChartDataCoordi
* This supplier returns a specific Copy & Paste clipboard content on demand.
*/
private IImageClipboardSupplier imageClipboardSupplier = null;
/*
* Custom Paint Series (Experimental)
*/
private List<ICustomSeries> customSeriesList = new ArrayList<>();
//
private IPreferenceStore preferenceStore = ResourceSupport.getPreferenceStore();

Expand Down Expand Up @@ -182,6 +188,62 @@ public BaseChart(Composite parent, int style) {
dataShiftHistory = new HashMap<>();
//
setData("org.eclipse.e4.ui.css.CssClassName", "BaseChart");
/*
* Draw the custom paint series elements (Experimental).
* Not yet implemented.
*/
// addPaintListener(new CustomSeriesMarker(this));
}

/**
* (Experimental)
* Returns an unmodifiable list of the custom paint series.
*
* @return List<ICustomPaintSeries>
*/
public List<ICustomSeries> getCustomSeries() {

return Collections.unmodifiableList(customSeriesList);
}

/**
* (Experimental)
* Create a custom series.
*
* @param label
* @param description
* @return
*/
public ICustomSeries createCustomSeries(String label, String description) {

ICustomSeries customSeries = new CustomSeries();
customSeries.setLabel(label);
customSeries.setDescription(description);
customSeriesList.add(customSeries);
//
return customSeries;
}

/**
* (Experimental)
* Delete the custom series.
*
* @param id
*/
public void deleteCustomSeries(String id) {

ICustomSeries customSeriesDelete = null;
exitloop:
for(ICustomSeries customSeries : customSeriesList) {
if(customSeries.getId().equals(id)) {
customSeriesDelete = customSeries;
break exitloop;
}
}
//
if(customSeriesDelete != null) {
customSeriesList.remove(customSeriesDelete);
}
}

private void initializeEventProcessors() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*******************************************************************************
* Copyright (c) 2023 Lablicate GmbH.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Philip Wenig - initial API and implementation
*******************************************************************************/
package org.eclipse.swtchart.extensions.core;

import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swtchart.extensions.model.ICustomSeries;

public class CustomSeriesLabelProvider extends ColumnLabelProvider implements ITableLabelProvider {

public static final String ID = "ID";
public static final String DRAW = "Draw";
public static final String LABEL = "Label";
public static final String DESCRIPTION = "Description";
//
public static final int INDEX_ID = 0;
public static final int INDEX_DRAW = 1;
//
public static final String[] TITLES = { //
ID, //
DRAW, //
LABEL, //
DESCRIPTION, //
};
//
public static final int[] BOUNDS = { //
24, //
30, //
100, //
200 //
};

@Override
public Image getColumnImage(Object element, int columnIndex) {

if(element instanceof ICustomSeries customPaintSeries) {
if(columnIndex == INDEX_ID) {
return ResourceSupport.getImage(ResourceSupport.ICON_SERIES_MARKER);
} else if(columnIndex == INDEX_DRAW) {
Image checked = ResourceSupport.getImage(ResourceSupport.ICON_CHECKED);
Image unchecked = ResourceSupport.getImage(ResourceSupport.ICON_UNCHECKED);
return customPaintSeries.isDraw() ? checked : unchecked;
}
}
return null;
}

@Override
public String getColumnText(Object element, int columnIndex) {

String text = "";
if(element instanceof ICustomSeries customPaintSeries) {
switch(columnIndex) {
case 0:
text = customPaintSeries.getId();
break;
case 1:
text = "";
break;
case 2:
text = customPaintSeries.getLabel();
break;
case 3:
text = customPaintSeries.getDescription();
break;
default:
text = "";
break;
}
}
//
return text;
}
}
Loading

0 comments on commit fd41a37

Please sign in to comment.