From 8feba7488f85fafec971bfd6b4500fcb02d128b5 Mon Sep 17 00:00:00 2001 From: Philip Wenig Date: Wed, 5 Jan 2022 13:46:21 +0100 Subject: [PATCH] Fixed #184 - Time Ratio Classifier - upgrade to new editor style --- .../plugin.xml | 11 +- .../TimeRatioSettingsAdapterFactory.java | 56 ++ .../ui/fieldeditors/TimeRatioFieldEditor.java | 346 +------------ .../time/TimeRatioEditingSupport.java | 13 +- .../ui/preferences/PreferencePageTime.java | 8 +- .../ratios/ui/swt/TimeRatioListEditor.java | 481 ++++++++++++++++++ .../ratios/core/TimeRatioClassifier.java | 6 +- .../ratios/settings/TimeRatioSettings.java | 11 +- 8 files changed, 581 insertions(+), 351 deletions(-) create mode 100644 openchrom/plugins/net.openchrom.xxd.classifier.supplier.ratios.ui/src/net/openchrom/xxd/classifier/supplier/ratios/ui/adapter/TimeRatioSettingsAdapterFactory.java create mode 100644 openchrom/plugins/net.openchrom.xxd.classifier.supplier.ratios.ui/src/net/openchrom/xxd/classifier/supplier/ratios/ui/swt/TimeRatioListEditor.java diff --git a/openchrom/plugins/net.openchrom.xxd.classifier.supplier.ratios.ui/plugin.xml b/openchrom/plugins/net.openchrom.xxd.classifier.supplier.ratios.ui/plugin.xml index a7bcb0530..6e9ba72b9 100644 --- a/openchrom/plugins/net.openchrom.xxd.classifier.supplier.ratios.ui/plugin.xml +++ b/openchrom/plugins/net.openchrom.xxd.classifier.supplier.ratios.ui/plugin.xml @@ -18,7 +18,7 @@ category="net.openchrom.xxd.classifier.supplier.ratios.ui.preferences.preferencePage" class="net.openchrom.xxd.classifier.supplier.ratios.ui.preferences.PreferencePageTime" id="net.openchrom.xxd.classifier.supplier.ratios.ui.preferences.preferencePageTime" - name="Time Ratio Classifier"> + name="Time Ratios"> - + + + + + \ No newline at end of file diff --git a/openchrom/plugins/net.openchrom.xxd.classifier.supplier.ratios.ui/src/net/openchrom/xxd/classifier/supplier/ratios/ui/adapter/TimeRatioSettingsAdapterFactory.java b/openchrom/plugins/net.openchrom.xxd.classifier.supplier.ratios.ui/src/net/openchrom/xxd/classifier/supplier/ratios/ui/adapter/TimeRatioSettingsAdapterFactory.java new file mode 100644 index 000000000..8fcb60a34 --- /dev/null +++ b/openchrom/plugins/net.openchrom.xxd.classifier.supplier.ratios.ui/src/net/openchrom/xxd/classifier/supplier/ratios/ui/adapter/TimeRatioSettingsAdapterFactory.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2022 Lablicate GmbH. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Philip Wenig - initial API and implementation + *******************************************************************************/ +package net.openchrom.xxd.classifier.supplier.ratios.ui.adapter; + +import java.io.IOException; + +import org.eclipse.chemclipse.processing.supplier.ProcessorPreferences; +import org.eclipse.chemclipse.ux.extension.xxd.ui.methods.SettingsUIProvider; +import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.swt.widgets.Composite; + +import net.openchrom.xxd.classifier.supplier.ratios.settings.TimeRatioSettings; +import net.openchrom.xxd.classifier.supplier.ratios.ui.swt.TimeRatioListEditor; + +public class TimeRatioSettingsAdapterFactory implements IAdapterFactory { + + @Override + public T getAdapter(Object adaptableObject, Class adapterType) { + + if(adaptableObject instanceof TimeRatioSettings) { + TimeRatioSettings settings = (TimeRatioSettings)adaptableObject; + if(adapterType == SettingsUIProvider.class) { + return adapterType.cast(createSettingsUIProvider(settings)); + } + } + return null; + } + + private static SettingsUIProvider createSettingsUIProvider(TimeRatioSettings adaptedSettings) { + + return new SettingsUIProvider() { + + @Override + public SettingsUIProvider.SettingsUIControl createUI(Composite parent, ProcessorPreferences preferences, boolean showProfileToolbar) throws IOException { + + TimeRatioSettings userSettings = preferences.getUserSettings(); + return new TimeRatioListEditor(parent, preferences, userSettings == null ? adaptedSettings : userSettings); + } + }; + } + + @Override + public Class[] getAdapterList() { + + return new Class[]{SettingsUIProvider.class}; + } +} \ No newline at end of file diff --git a/openchrom/plugins/net.openchrom.xxd.classifier.supplier.ratios.ui/src/net/openchrom/xxd/classifier/supplier/ratios/ui/fieldeditors/TimeRatioFieldEditor.java b/openchrom/plugins/net.openchrom.xxd.classifier.supplier.ratios.ui/src/net/openchrom/xxd/classifier/supplier/ratios/ui/fieldeditors/TimeRatioFieldEditor.java index 1daa14fc5..bbe93a95c 100644 --- a/openchrom/plugins/net.openchrom.xxd.classifier.supplier.ratios.ui/src/net/openchrom/xxd/classifier/supplier/ratios/ui/fieldeditors/TimeRatioFieldEditor.java +++ b/openchrom/plugins/net.openchrom.xxd.classifier.supplier.ratios.ui/src/net/openchrom/xxd/classifier/supplier/ratios/ui/fieldeditors/TimeRatioFieldEditor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019 Lablicate GmbH. + * Copyright (c) 2019, 2022 Lablicate GmbH. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -11,56 +11,17 @@ *******************************************************************************/ package net.openchrom.xxd.classifier.supplier.ratios.ui.fieldeditors; -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.chemclipse.support.ui.events.IKeyEventProcessor; -import org.eclipse.chemclipse.support.ui.menu.ITableMenuEntry; -import org.eclipse.chemclipse.support.ui.swt.ExtendedTableViewer; -import org.eclipse.chemclipse.support.ui.swt.ITableSettings; -import org.eclipse.chemclipse.swt.ui.components.ISearchListener; -import org.eclipse.chemclipse.swt.ui.components.SearchSupportUI; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.InputDialog; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import net.openchrom.xxd.classifier.supplier.ratios.model.time.TimeRatio; -import net.openchrom.xxd.classifier.supplier.ratios.model.time.TimeRatios; -import net.openchrom.xxd.classifier.supplier.ratios.preferences.PreferenceSupplier; -import net.openchrom.xxd.classifier.supplier.ratios.ui.internal.provider.time.TimeRatioInputValidator; -import net.openchrom.xxd.classifier.supplier.ratios.ui.swt.TimeRatioListUI; -import net.openchrom.xxd.classifier.supplier.ratios.util.time.TimeRatioListUtil; +import net.openchrom.xxd.classifier.supplier.ratios.ui.swt.TimeRatioListEditor; public class TimeRatioFieldEditor extends AbstractFieldEditor { - private static final int NUMBER_COLUMNS = 2; - // - private Composite composite; - private TimeRatios settings = new TimeRatios(); - private TimeRatioListUI listUI; - // - private static final String FILTER_EXTENSION = "*.txt"; - private static final String FILTER_NAME = "Time Ratio Template (*.txt)"; - private static final String FILE_NAME = "TimeRatioTemplate.txt"; - // - private static final String CATEGORY = "Time Ratio"; - private static final String DELETE = "Delete"; + private TimeRatioListEditor editor; public TimeRatioFieldEditor(String name, String labelText, Composite parent) { + init(name, labelText); createControl(parent); } @@ -69,261 +30,29 @@ public TimeRatioFieldEditor(String name, String labelText, Composite parent) { protected void doFillIntoGrid(Composite parent, int numColumns) { getLabelControl(parent); - // - composite = new Composite(parent, SWT.NONE); - GridLayout gridLayout = new GridLayout(NUMBER_COLUMNS, false); - gridLayout.marginWidth = 0; - gridLayout.marginHeight = 0; - composite.setLayout(gridLayout); + editor = new TimeRatioListEditor(parent, null, null); GridData gridData = new GridData(GridData.FILL_BOTH); - composite.setLayoutData(gridData); - // - createLabelSection(composite); - createSearchSection(composite); - createTableSection(composite); - createButtonGroup(composite); - } - - private void createSearchSection(Composite parent) { - - SearchSupportUI searchSupportUI = new SearchSupportUI(parent, SWT.NONE); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.horizontalSpan = NUMBER_COLUMNS; - searchSupportUI.setLayoutData(gridData); - searchSupportUI.setSearchListener(new ISearchListener() { - - @Override - public void performSearch(String searchText, boolean caseSensitive) { - - listUI.setSearchText(searchText, caseSensitive); - } - }); - } - - private void createLabelSection(Composite parent) { - - Label label = new Label(parent, SWT.LEFT); - label.setText(""); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.horizontalSpan = NUMBER_COLUMNS; - label.setLayoutData(gridData); - } - - private void createTableSection(Composite parent) { - - Composite composite = new Composite(parent, SWT.NONE); - composite.setLayout(new FillLayout()); - GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - composite.setLayoutData(gridData); - // - listUI = new TimeRatioListUI(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); - // - Shell shell = listUI.getTable().getShell(); - ITableSettings tableSettings = listUI.getTableSettings(); - addDeleteMenuEntry(shell, tableSettings); - addKeyEventProcessors(shell, tableSettings); - listUI.applySettings(tableSettings); - // - setTableViewerInput(); - } - - private void createButtonGroup(Composite parent) { - - Composite composite = new Composite(parent, SWT.NULL); - GridLayout gridLayout = new GridLayout(1, true); - gridLayout.marginWidth = 0; - gridLayout.marginHeight = 0; - composite.setLayout(gridLayout); - GridData gridData = new GridData(); - gridData.verticalAlignment = GridData.FILL; - gridData.horizontalAlignment = GridData.FILL; - composite.setLayoutData(gridData); - // - setButtonLayoutData(createButtonAdd(composite)); - setButtonLayoutData(createButtonEdit(composite)); - setButtonLayoutData(createButtonRemove(composite)); - setButtonLayoutData(createButtonRemoveAll(composite)); - setButtonLayoutData(createButtonImport(composite)); - setButtonLayoutData(createButtonExport(composite)); - } - - private Button createButtonAdd(Composite parent) { - - Button button = new Button(parent, SWT.PUSH); - button.setText(ADD); - button.setToolTipText(ADD_TOOLTIP); - button.addSelectionListener(new SelectionAdapter() { - - public void widgetSelected(SelectionEvent e) { - - InputDialog dialog = new InputDialog(button.getShell(), DIALOG_TITLE, MESSAGE_ADD, TimeRatioListUtil.EXAMPLE_SINGLE, new TimeRatioInputValidator(settings)); - if(IDialogConstants.OK_ID == dialog.open()) { - String item = dialog.getValue(); - TimeRatio setting = settings.extractSettingInstance(item); - if(setting != null) { - settings.add(setting); - setTableViewerInput(); - } - } - } - }); - // - return button; - } - - private Button createButtonEdit(Composite parent) { - - Button button = new Button(parent, SWT.PUSH); - button.setText(EDIT); - button.setToolTipText(EDIT_TOOLTIP); - button.addSelectionListener(new SelectionAdapter() { - - public void widgetSelected(SelectionEvent e) { - - IStructuredSelection structuredSelection = (IStructuredSelection)listUI.getSelection(); - Object object = structuredSelection.getFirstElement(); - if(object instanceof TimeRatio) { - List settingsEdit = new ArrayList<>(); - settingsEdit.addAll(settings); - TimeRatio setting = (TimeRatio)object; - settingsEdit.remove(setting); - InputDialog dialog = new InputDialog(button.getShell(), DIALOG_TITLE, MESSAGE_EDIT, settings.extractSettingString(setting), new TimeRatioInputValidator(settingsEdit)); - if(IDialogConstants.OK_ID == dialog.open()) { - String item = dialog.getValue(); - TimeRatio settingNew = settings.extractSettingInstance(item); - setting.copyFrom(settingNew); - setTableViewerInput(); - } - } - } - }); - // - return button; - } - - private Button createButtonRemove(Composite parent) { - - Button button = new Button(parent, SWT.PUSH); - button.setText(REMOVE); - button.setToolTipText(REMOVE_TOOLTIP); - button.addSelectionListener(new SelectionAdapter() { - - public void widgetSelected(SelectionEvent e) { - - deleteItems(e.display.getActiveShell()); - } - }); - // - return button; - } - - private Button createButtonRemoveAll(Composite parent) { - - Button button = new Button(parent, SWT.PUSH); - button.setText(REMOVE_ALL); - button.setToolTipText(REMOVE_ALL_TOOLTIP); - button.addSelectionListener(new SelectionAdapter() { - - public void widgetSelected(SelectionEvent e) { - - if(MessageDialog.openQuestion(button.getShell(), DIALOG_TITLE, MESSAGE_REMOVE_ALL)) { - settings.clear(); - setTableViewerInput(); - } - } - }); - // - return button; - } - - private Button createButtonImport(Composite parent) { - - Button button = new Button(parent, SWT.PUSH); - button.setText(IMPORT); - button.setToolTipText(IMPORT_TITLE); - button.addSelectionListener(new SelectionAdapter() { - - public void widgetSelected(SelectionEvent e) { - - FileDialog fileDialog = new FileDialog(e.widget.getDisplay().getActiveShell(), SWT.READ_ONLY); - fileDialog.setText(IMPORT_TITLE); - fileDialog.setFilterExtensions(new String[]{FILTER_EXTENSION}); - fileDialog.setFilterNames(new String[]{FILTER_NAME}); - fileDialog.setFilterPath(PreferenceSupplier.getListPathImport()); - String path = fileDialog.open(); - if(path != null) { - PreferenceSupplier.setListPathImport(fileDialog.getFilterPath()); - File file = new File(path); - settings.importItems(file); - setTableViewerInput(); - } - } - }); - // - return button; - } - - private Button createButtonExport(Composite parent) { - - Button button = new Button(parent, SWT.PUSH); - button.setText(EXPORT); - button.setToolTipText(EXPORT_TITLE); - button.addSelectionListener(new SelectionAdapter() { - - public void widgetSelected(SelectionEvent e) { - - FileDialog fileDialog = new FileDialog(e.widget.getDisplay().getActiveShell(), SWT.SAVE); - fileDialog.setOverwrite(true); - fileDialog.setText(EXPORT_TITLE); - fileDialog.setFilterExtensions(new String[]{FILTER_EXTENSION}); - fileDialog.setFilterNames(new String[]{FILTER_NAME}); - fileDialog.setFileName(FILE_NAME); - fileDialog.setFilterPath(PreferenceSupplier.getListPathExport()); - String path = fileDialog.open(); - if(path != null) { - PreferenceSupplier.setListPathExport(fileDialog.getFilterPath()); - File file = new File(path); - if(settings.exportItems(file)) { - MessageDialog.openInformation(button.getShell(), EXPORT_TITLE, MESSAGE_EXPORT_SUCCESSFUL); - } else { - MessageDialog.openWarning(button.getShell(), EXPORT_TITLE, MESSAGE_EXPORT_FAILED); - } - } - } - }); - // - return button; - } - - private void setTableViewerInput() { - - listUI.setInput(settings); + editor.getControl().setLayoutData(gridData); } @Override protected void doLoad() { String entries = getPreferenceStore().getString(getPreferenceName()); - settings.load(entries); - setTableViewerInput(); + editor.load(entries); } @Override protected void doLoadDefault() { String entries = getPreferenceStore().getDefaultString(getPreferenceName()); - settings.loadDefault(entries); - setTableViewerInput(); + editor.load(entries); } @Override protected void doStore() { - getPreferenceStore().setValue(getPreferenceName(), settings.save()); + getPreferenceStore().setValue(getPreferenceName(), editor.getValues()); } @Override @@ -336,62 +65,9 @@ public int getNumberOfControls() { protected void adjustForNumColumns(int numColumns) { if(numColumns >= 2) { - GridData gridData = (GridData)composite.getLayoutData(); + GridData gridData = (GridData)editor.getControl().getLayoutData(); gridData.horizontalSpan = numColumns - 1; gridData.grabExcessHorizontalSpace = true; } } - - private void addDeleteMenuEntry(Shell shell, ITableSettings tableSettings) { - - tableSettings.addMenuEntry(new ITableMenuEntry() { - - @Override - public String getName() { - - return DELETE; - } - - @Override - public String getCategory() { - - return CATEGORY; - } - - @Override - public void execute(ExtendedTableViewer extendedTableViewer) { - - deleteItems(shell); - } - }); - } - - private void addKeyEventProcessors(Shell shell, ITableSettings tableSettings) { - - tableSettings.addKeyEventProcessor(new IKeyEventProcessor() { - - @Override - public void handleEvent(ExtendedTableViewer extendedTableViewer, KeyEvent e) { - - if(e.keyCode == SWT.DEL) { - deleteItems(shell); - } - } - }); - } - - private void deleteItems(Shell shell) { - - if(MessageDialog.openQuestion(shell, DIALOG_TITLE, MESSAGE_REMOVE)) { - IStructuredSelection structuredSelection = (IStructuredSelection)listUI.getSelection(); - List removeElements = new ArrayList<>(); - for(Object object : structuredSelection.toArray()) { - if(object instanceof TimeRatio) { - removeElements.add((TimeRatio)object); - } - } - settings.removeAll(removeElements); - setTableViewerInput(); - } - } -} +} \ No newline at end of file diff --git a/openchrom/plugins/net.openchrom.xxd.classifier.supplier.ratios.ui/src/net/openchrom/xxd/classifier/supplier/ratios/ui/internal/provider/time/TimeRatioEditingSupport.java b/openchrom/plugins/net.openchrom.xxd.classifier.supplier.ratios.ui/src/net/openchrom/xxd/classifier/supplier/ratios/ui/internal/provider/time/TimeRatioEditingSupport.java index 0df78307b..7aff68ee2 100644 --- a/openchrom/plugins/net.openchrom.xxd.classifier.supplier.ratios.ui/src/net/openchrom/xxd/classifier/supplier/ratios/ui/internal/provider/time/TimeRatioEditingSupport.java +++ b/openchrom/plugins/net.openchrom.xxd.classifier.supplier.ratios.ui/src/net/openchrom/xxd/classifier/supplier/ratios/ui/internal/provider/time/TimeRatioEditingSupport.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019 Lablicate GmbH. + * Copyright (c) 2019, 2022 Lablicate GmbH. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -12,22 +12,23 @@ package net.openchrom.xxd.classifier.supplier.ratios.ui.internal.provider.time; import org.eclipse.chemclipse.logging.core.Logger; -import org.eclipse.chemclipse.support.ui.swt.ExtendedTableViewer; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.EditingSupport; import org.eclipse.jface.viewers.TextCellEditor; import net.openchrom.xxd.classifier.supplier.ratios.model.time.TimeRatio; +import net.openchrom.xxd.classifier.supplier.ratios.ui.swt.AbstractRatioListUI; public class TimeRatioEditingSupport extends EditingSupport { private static final Logger logger = Logger.getLogger(TimeRatioEditingSupport.class); // private CellEditor cellEditor; - private ExtendedTableViewer tableViewer; + private AbstractRatioListUI tableViewer; private String column; - public TimeRatioEditingSupport(ExtendedTableViewer tableViewer, String column) { + public TimeRatioEditingSupport(AbstractRatioListUI tableViewer, String column) { + super(tableViewer); this.column = column; this.cellEditor = new TextCellEditor(tableViewer.getTable()); @@ -88,7 +89,9 @@ protected void setValue(Object element, Object value) { } break; } + // tableViewer.refresh(); + tableViewer.updateContent(); } } @@ -102,4 +105,4 @@ private double parseDouble(String text) { } return value; } -} +} \ No newline at end of file diff --git a/openchrom/plugins/net.openchrom.xxd.classifier.supplier.ratios.ui/src/net/openchrom/xxd/classifier/supplier/ratios/ui/preferences/PreferencePageTime.java b/openchrom/plugins/net.openchrom.xxd.classifier.supplier.ratios.ui/src/net/openchrom/xxd/classifier/supplier/ratios/ui/preferences/PreferencePageTime.java index 333c7c28f..58f300251 100644 --- a/openchrom/plugins/net.openchrom.xxd.classifier.supplier.ratios.ui/src/net/openchrom/xxd/classifier/supplier/ratios/ui/preferences/PreferencePageTime.java +++ b/openchrom/plugins/net.openchrom.xxd.classifier.supplier.ratios.ui/src/net/openchrom/xxd/classifier/supplier/ratios/ui/preferences/PreferencePageTime.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019 Lablicate GmbH. + * Copyright (c) 2019, 2022 Lablicate GmbH. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -22,9 +22,11 @@ public class PreferencePageTime extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { public PreferencePageTime() { + super(GRID); setPreferenceStore(Activator.getDefault().getPreferenceStore()); - setDescription("Time Ratio"); + setTitle("Time Ratios"); + setDescription(""); } /** @@ -35,7 +37,7 @@ public PreferencePageTime() { @Override public void createFieldEditors() { - addField(new TimeRatioFieldEditor(PreferenceSupplier.P_TIME_RATIO_LIST, "Time Ratio(s)", getFieldEditorParent())); + addField(new TimeRatioFieldEditor(PreferenceSupplier.P_TIME_RATIO_LIST, "Time Ratios", getFieldEditorParent())); } /* diff --git a/openchrom/plugins/net.openchrom.xxd.classifier.supplier.ratios.ui/src/net/openchrom/xxd/classifier/supplier/ratios/ui/swt/TimeRatioListEditor.java b/openchrom/plugins/net.openchrom.xxd.classifier.supplier.ratios.ui/src/net/openchrom/xxd/classifier/supplier/ratios/ui/swt/TimeRatioListEditor.java new file mode 100644 index 000000000..764f0d5d8 --- /dev/null +++ b/openchrom/plugins/net.openchrom.xxd.classifier.supplier.ratios.ui/src/net/openchrom/xxd/classifier/supplier/ratios/ui/swt/TimeRatioListEditor.java @@ -0,0 +1,481 @@ +/******************************************************************************* + * Copyright (c) 2022 Lablicate GmbH. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Philip Wenig - initial API and implementation + *******************************************************************************/ +package net.openchrom.xxd.classifier.supplier.ratios.ui.swt; + +import static net.openchrom.xxd.classifier.supplier.ratios.ui.fieldeditors.AbstractFieldEditor.ADD_TOOLTIP; +import static net.openchrom.xxd.classifier.supplier.ratios.ui.fieldeditors.AbstractFieldEditor.DIALOG_TITLE; +import static net.openchrom.xxd.classifier.supplier.ratios.ui.fieldeditors.AbstractFieldEditor.EDIT_TOOLTIP; +import static net.openchrom.xxd.classifier.supplier.ratios.ui.fieldeditors.AbstractFieldEditor.EXPORT_TITLE; +import static net.openchrom.xxd.classifier.supplier.ratios.ui.fieldeditors.AbstractFieldEditor.IMPORT_TITLE; +import static net.openchrom.xxd.classifier.supplier.ratios.ui.fieldeditors.AbstractFieldEditor.MESSAGE_ADD; +import static net.openchrom.xxd.classifier.supplier.ratios.ui.fieldeditors.AbstractFieldEditor.MESSAGE_EDIT; +import static net.openchrom.xxd.classifier.supplier.ratios.ui.fieldeditors.AbstractFieldEditor.MESSAGE_EXPORT_FAILED; +import static net.openchrom.xxd.classifier.supplier.ratios.ui.fieldeditors.AbstractFieldEditor.MESSAGE_EXPORT_SUCCESSFUL; +import static net.openchrom.xxd.classifier.supplier.ratios.ui.fieldeditors.AbstractFieldEditor.MESSAGE_REMOVE; +import static net.openchrom.xxd.classifier.supplier.ratios.ui.fieldeditors.AbstractFieldEditor.MESSAGE_REMOVE_ALL; +import static net.openchrom.xxd.classifier.supplier.ratios.ui.fieldeditors.AbstractFieldEditor.REMOVE_ALL_TOOLTIP; +import static net.openchrom.xxd.classifier.supplier.ratios.ui.fieldeditors.AbstractFieldEditor.REMOVE_TOOLTIP; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicReference; + +import org.eclipse.chemclipse.model.updates.IUpdateListener; +import org.eclipse.chemclipse.processing.supplier.ProcessorPreferences; +import org.eclipse.chemclipse.rcp.ui.icons.core.ApplicationImageFactory; +import org.eclipse.chemclipse.rcp.ui.icons.core.IApplicationImage; +import org.eclipse.chemclipse.support.ui.events.IKeyEventProcessor; +import org.eclipse.chemclipse.support.ui.menu.ITableMenuEntry; +import org.eclipse.chemclipse.support.ui.swt.ExtendedTableViewer; +import org.eclipse.chemclipse.support.ui.swt.ITableSettings; +import org.eclipse.chemclipse.swt.ui.components.ISearchListener; +import org.eclipse.chemclipse.swt.ui.components.SearchSupportUI; +import org.eclipse.chemclipse.ux.extension.xxd.ui.methods.SettingsUIProvider; +import org.eclipse.chemclipse.ux.extension.xxd.ui.swt.IExtendedPartUI; +import org.eclipse.core.databinding.validation.ValidationStatus; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; + +import net.openchrom.xxd.classifier.supplier.ratios.model.time.TimeRatio; +import net.openchrom.xxd.classifier.supplier.ratios.model.time.TimeRatios; +import net.openchrom.xxd.classifier.supplier.ratios.preferences.PreferenceSupplier; +import net.openchrom.xxd.classifier.supplier.ratios.settings.TimeRatioSettings; +import net.openchrom.xxd.classifier.supplier.ratios.ui.internal.provider.time.TimeRatioInputValidator; +import net.openchrom.xxd.classifier.supplier.ratios.util.time.TimeRatioListUtil; + +public class TimeRatioListEditor implements SettingsUIProvider.SettingsUIControl, IExtendedPartUI { + + private Composite control; + // + private Button buttonToolbarSearch; + private AtomicReference toolbarSearch = new AtomicReference<>(); + private AtomicReference listControl = new AtomicReference<>(); + // + private static final String FILTER_EXTENSION = "*.txt"; + private static final String FILTER_NAME = "Time Ratio Template (*.txt)"; + private static final String FILE_NAME = "TimeRatioTemplate.txt"; + // + private static final String CATEGORY = "Time Ratio"; + private static final String DELETE = "Delete"; + // + private Listener listener; + private List