From 3518674c29aa0eceac2cfa21097c8a3116d0755b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Tue, 3 May 2022 16:41:32 +0200 Subject: [PATCH] Move the buttons into a static toolbar --- .../ui/views/MassSpectrumFileExplorer.java | 8 +- .../ui/views/MassSpectrumLibraryExplorer.java | 8 +- .../ux/extension/ui/swt/DataExplorerUI.java | 276 ------------------ .../ui/swt/MultiDataExplorerTreeUI.java | 227 +++++++++++++- .../fragment.e4xmi | 7 +- .../handlers/DataExplorerSettingsHandler.java | 55 ---- .../handlers/ResetDataExplorerHandler.java | 30 -- .../xxd/ui/parts/DataExplorerPart.java | 107 +------ .../extension/xxd/ui/swt/DataExplorerUI.java | 215 ++++++++++++++ 9 files changed, 454 insertions(+), 479 deletions(-) delete mode 100644 chemclipse/plugins/org.eclipse.chemclipse.ux.extension.ui/src/org/eclipse/chemclipse/ux/extension/ui/swt/DataExplorerUI.java delete mode 100644 chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/handlers/DataExplorerSettingsHandler.java delete mode 100644 chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/handlers/ResetDataExplorerHandler.java create mode 100644 chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/swt/DataExplorerUI.java diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.msd.ui/src/org/eclipse/chemclipse/ux/extension/msd/ui/views/MassSpectrumFileExplorer.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.msd.ui/src/org/eclipse/chemclipse/ux/extension/msd/ui/views/MassSpectrumFileExplorer.java index 9e5e0293ee..6bbc9a5e40 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.msd.ui/src/org/eclipse/chemclipse/ux/extension/msd/ui/views/MassSpectrumFileExplorer.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.msd.ui/src/org/eclipse/chemclipse/ux/extension/msd/ui/views/MassSpectrumFileExplorer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2020 Lablicate GmbH. + * Copyright (c) 2013, 2022 Lablicate GmbH. * * All rights reserved. * This program and the accompanying materials are made available under the @@ -18,18 +18,18 @@ import org.eclipse.chemclipse.ux.extension.msd.ui.Activator; import org.eclipse.chemclipse.ux.extension.msd.ui.support.MassSpectrumSupport; -import org.eclipse.chemclipse.ux.extension.ui.swt.DataExplorerUI; +import org.eclipse.chemclipse.ux.extension.ui.swt.MultiDataExplorerTreeUI; import org.eclipse.e4.ui.di.Focus; import org.eclipse.swt.widgets.Composite; public class MassSpectrumFileExplorer { - private DataExplorerUI explorerUI; + private MultiDataExplorerTreeUI explorerUI; @Inject public MassSpectrumFileExplorer(Composite parent) { - explorerUI = new DataExplorerUI(parent, Activator.getDefault().getPreferenceStore()); + explorerUI = new MultiDataExplorerTreeUI(parent, Activator.getDefault().getPreferenceStore()); explorerUI.setSupplierFileIdentifier(Collections.singleton(MassSpectrumSupport.getInstanceEditorSupport())); explorerUI.expandLastDirectoryPath(); } diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.msd.ui/src/org/eclipse/chemclipse/ux/extension/msd/ui/views/MassSpectrumLibraryExplorer.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.msd.ui/src/org/eclipse/chemclipse/ux/extension/msd/ui/views/MassSpectrumLibraryExplorer.java index 08ce733ec1..5e8431cc9c 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.msd.ui/src/org/eclipse/chemclipse/ux/extension/msd/ui/views/MassSpectrumLibraryExplorer.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.msd.ui/src/org/eclipse/chemclipse/ux/extension/msd/ui/views/MassSpectrumLibraryExplorer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2020 Lablicate GmbH. + * Copyright (c) 2014, 2022 Lablicate GmbH. * * All rights reserved. * This program and the accompanying materials are made available under the @@ -18,18 +18,18 @@ import org.eclipse.chemclipse.ux.extension.msd.ui.Activator; import org.eclipse.chemclipse.ux.extension.msd.ui.support.DatabaseSupport; -import org.eclipse.chemclipse.ux.extension.ui.swt.DataExplorerUI; +import org.eclipse.chemclipse.ux.extension.ui.swt.MultiDataExplorerTreeUI; import org.eclipse.e4.ui.di.Focus; import org.eclipse.swt.widgets.Composite; public class MassSpectrumLibraryExplorer { - private DataExplorerUI explorerUI; + private MultiDataExplorerTreeUI explorerUI; @Inject public MassSpectrumLibraryExplorer(Composite parent) { - explorerUI = new DataExplorerUI(parent, Activator.getDefault().getPreferenceStore()); + explorerUI = new MultiDataExplorerTreeUI(parent, Activator.getDefault().getPreferenceStore()); explorerUI.setSupplierFileIdentifier((Collections.singleton(DatabaseSupport.getInstanceEditorSupport()))); explorerUI.expandLastDirectoryPath(); } diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.ui/src/org/eclipse/chemclipse/ux/extension/ui/swt/DataExplorerUI.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.ui/src/org/eclipse/chemclipse/ux/extension/ui/swt/DataExplorerUI.java deleted file mode 100644 index 5ac5ce88d4..0000000000 --- a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.ui/src/org/eclipse/chemclipse/ux/extension/ui/swt/DataExplorerUI.java +++ /dev/null @@ -1,276 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2018, 2021 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: - * Dr. Philip Wenig - initial API and implementation - * Christoph Läubrich - performance optimization and cleanup, refactor handling of Suppliers - * Matthias Mailänder - right-click refresh option - *******************************************************************************/ -package org.eclipse.chemclipse.ux.extension.ui.swt; - -import java.io.File; -import java.util.Collection; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.TreeSet; - -import org.eclipse.chemclipse.model.notifier.UpdateNotifier; -import org.eclipse.chemclipse.processing.converter.ISupplier; -import org.eclipse.chemclipse.processing.converter.ISupplierFileIdentifier; -import org.eclipse.chemclipse.rcp.ui.icons.core.ApplicationImageFactory; -import org.eclipse.chemclipse.rcp.ui.icons.core.IApplicationImage; -import org.eclipse.chemclipse.support.events.IChemClipseEvents; -import org.eclipse.chemclipse.ux.extension.ui.preferences.PreferenceSupplier; -import org.eclipse.chemclipse.ux.extension.ui.provider.DataExplorerContentProvider; -import org.eclipse.chemclipse.ux.extension.ui.provider.ISupplierFileEditorSupport; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Menu; - -public class DataExplorerUI extends MultiDataExplorerTreeUI { - - public DataExplorerUI(Composite parent, IPreferenceStore preferenceStore) { - - super(parent, preferenceStore); - } - - @Override - protected void initTabComponent(Composite parent, DataExplorerTreeUI treeUI) { - - super.initTabComponent(parent, treeUI); - createContextMenu(treeUI); - addBatchOpenButton(parent, treeUI); - } - - @Override - protected void handleDoubleClick(File file, DataExplorerTreeUI treeUI) { - - openEditor(file, treeUI); - } - - @Override - protected void handleSelection(File[] files, DataExplorerTreeUI treeUI) { - - if(files.length > 0) { - openOverview(files[0], treeUI); - } - } - - private void createContextMenu(DataExplorerTreeUI treeUI) { - - TreeViewer treeViewer = treeUI.getTreeViewer(); - MenuManager contextMenu = new MenuManager("#ViewerMenu"); //$NON-NLS-1$ - contextMenu.setRemoveAllWhenShown(true); - contextMenu.addMenuListener(new IMenuListener() { - - @Override - public void menuAboutToShow(IMenuManager mgr) { - - Object[] selection = treeViewer.getStructuredSelection().toArray(); - Map>> converterSupplier = new HashMap<>(); - Set supplierSet = new TreeSet<>(new Comparator() { - - @Override - public int compare(ISupplier o1, ISupplier o2) { - - return o1.getId().compareTo(o2.getId()); - } - }); - // - for(Object object : selection) { - if(object instanceof File) { - File file = (File)object; - Map> map = getIdentifierSupplier().apply(file); - converterSupplier.put(file, map); - for(Collection s : map.values()) { - supplierSet.addAll(s); - } - } - } - contextMenu.add(new Action("Scan for file and folder updates", ApplicationImageFactory.getInstance().getImageDescriptor(IApplicationImage.IMAGE_REFRESH, IApplicationImage.SIZE_16x16)) { - - @Override - public void run() { - - treeViewer.refresh(); - } - }); - // - for(ISupplier activeFileSupplier : supplierSet) { - contextMenu.add(new Action("Open as: " + activeFileSupplier.getFilterName(), ApplicationImageFactory.getInstance().getImageDescriptor(IApplicationImage.IMAGE_FILE, IApplicationImage.SIZE_16x16)) { - - @Override - public void run() { - - outer: - for(Object object : selection) { - if(object instanceof File) { - File file = (File)object; - Map> map = converterSupplier.get(file); - for(Entry> entry : map.entrySet()) { - ISupplierFileIdentifier identifier = entry.getKey(); - if(identifier instanceof ISupplierFileEditorSupport) { - for(ISupplier supplier : entry.getValue()) { - if(activeFileSupplier.getId().equals(supplier.getId())) { - openEditorWithSupplier(file, (ISupplierFileEditorSupport)identifier, supplier); - continue outer; - } - } - } - } - } - } - } - - @Override - public String getToolTipText() { - - return activeFileSupplier.getDescription(); - }; - }); - } - // - if(selection.length == 1 && selection[0] instanceof File && ((File)selection[0]).isDirectory()) { - contextMenu.add(new Action("Open all contained measurements in this folder", ApplicationImageFactory.getInstance().getImageDescriptor(IApplicationImage.IMAGE_FOLDER, IApplicationImage.SIZE_16x16)) { - - @Override - public void run() { - - openRecurse((File)selection[0], treeUI); - } - }); - } - } - }); - // - Menu menu = contextMenu.createContextMenu(treeViewer.getControl()); - treeViewer.getControl().setMenu(menu); - } - - private boolean openRecurse(File file, DataExplorerTreeUI treeUI) { - - boolean opened = false; - File[] listFiles = file.listFiles(); - if(listFiles != null) { - for(File f : listFiles) { - opened |= openEditor(f, treeUI); - } - if(!opened) { - for(File f : listFiles) { - if(f.isDirectory()) { - // recurse into sub-directory... - opened |= openRecurse(f, treeUI); - } - } - } - } - return opened; - }; - - private void addBatchOpenButton(Composite parent, DataExplorerTreeUI treeUI) { - - Button button = new Button(parent, SWT.PUSH); - button.setText("Open Selected Measurements"); - button.setToolTipText("Try to open all selected files. Handle with care."); - button.setImage(ApplicationImageFactory.getInstance().getImage(IApplicationImage.IMAGE_IMPORT, IApplicationImage.SIZE_16x16)); - button.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - button.addSelectionListener(new SelectionAdapter() { - - @SuppressWarnings("rawtypes") - @Override - public void widgetSelected(SelectionEvent e) { - - IStructuredSelection structuredSelection = treeUI.getTreeViewer().getStructuredSelection(); - Iterator iterator = structuredSelection.iterator(); - while(iterator.hasNext()) { - Object object = iterator.next(); - if(object instanceof File) { - e.display.asyncExec(new Runnable() { - - @Override - public void run() { - - File file = (File)object; - openEditor(file, treeUI); - } - }); - } - } - } - }); - } - - private void openOverview(File file, DataExplorerTreeUI dataExplorerTreeUI) { - - if(file != null) { - DataExplorerContentProvider contentProvider = (DataExplorerContentProvider)dataExplorerTreeUI.getTreeViewer().getContentProvider(); - /* - * Update the directories content, until there is - * actual no way to monitor the file system outside - * of the workbench without using operating system - * specific function via e.g. JNI. - */ - if(file.isDirectory()) { - contentProvider.refresh(file); - } - // - Collection identifiers = getIdentifierSupplier().apply(file).keySet(); - for(ISupplierFileIdentifier identifier : identifiers) { - if(identifier instanceof ISupplierFileEditorSupport) { - ISupplierFileEditorSupport fileEditorSupport = (ISupplierFileEditorSupport)identifier; - fileEditorSupport.openOverview(file); - return; - } - } - // - UpdateNotifier.update(IChemClipseEvents.TOPIC_CHROMATOGRAM_XXD_UPDATE_NONE, null); - } - } - - private boolean openEditor(File file, DataExplorerTreeUI treeUI) { - - boolean success = false; - if(file != null) { - boolean openFirstDataMatchOnly = PreferenceSupplier.isOpenFirstDataMatchOnly(); - Map> identifiers = getIdentifierSupplier().apply(file); - for(Entry> entry : identifiers.entrySet()) { - ISupplierFileIdentifier identifier = entry.getKey(); - if(identifier instanceof ISupplierFileEditorSupport) { - for(ISupplier converter : entry.getValue()) { - success = success | openEditorWithSupplier(file, (ISupplierFileEditorSupport)identifier, converter); - if(success && openFirstDataMatchOnly) { - return true; - } - } - } - } - } - return success; - } - - private boolean openEditorWithSupplier(File file, ISupplierFileEditorSupport identifier, ISupplier converter) { - - saveLastDirectoryPath(); - return identifier.openEditor(file, converter); - } -} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.ui/src/org/eclipse/chemclipse/ux/extension/ui/swt/MultiDataExplorerTreeUI.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.ui/src/org/eclipse/chemclipse/ux/extension/ui/swt/MultiDataExplorerTreeUI.java index 6a3de719ce..ce91674b9b 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.ui/src/org/eclipse/chemclipse/ux/extension/ui/swt/MultiDataExplorerTreeUI.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.ui/src/org/eclipse/chemclipse/ux/extension/ui/swt/MultiDataExplorerTreeUI.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019, 2020 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 @@ -15,19 +15,34 @@ import java.io.File; import java.io.IOException; import java.util.Collection; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.TreeSet; import java.util.function.Function; +import org.eclipse.chemclipse.model.notifier.UpdateNotifier; import org.eclipse.chemclipse.processing.converter.ISupplier; import org.eclipse.chemclipse.processing.converter.ISupplierFileIdentifier; import org.eclipse.chemclipse.rcp.ui.icons.core.ApplicationImageFactory; import org.eclipse.chemclipse.rcp.ui.icons.core.IApplicationImage; +import org.eclipse.chemclipse.support.events.IChemClipseEvents; import org.eclipse.chemclipse.ux.extension.ui.Activator; import org.eclipse.chemclipse.ux.extension.ui.preferences.PreferenceConstants; +import org.eclipse.chemclipse.ux.extension.ui.preferences.PreferenceSupplier; +import org.eclipse.chemclipse.ux.extension.ui.provider.DataExplorerContentProvider; +import org.eclipse.chemclipse.ux.extension.ui.provider.ISupplierFileEditorSupport; import org.eclipse.chemclipse.ux.extension.ui.provider.LazyFileExplorerContentProvider; import org.eclipse.chemclipse.xxd.process.files.SupplierFileIdentifierCache; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.preference.IPersistentPreferenceStore; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.viewers.DoubleClickEvent; @@ -45,6 +60,7 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.TabFolder; import org.eclipse.swt.widgets.TabItem; @@ -129,10 +145,14 @@ protected Function>> ge protected void handleDoubleClick(File file, DataExplorerTreeUI treeUI) { + openEditor(file, treeUI); } protected void handleSelection(File[] files, DataExplorerTreeUI treeUI) { + if(files.length > 0) { + openOverview(files[0], treeUI); + } } protected String getSelectedTabPreferenceKey() { @@ -150,6 +170,10 @@ protected String getPreferenceKey(DataExplorerTreeRoot root) { return root.getPreferenceKeyDefaultPath(); } + protected void createToolbarMain(Composite parent) { + + } + protected void initTabComponent(Composite parent, DataExplorerTreeUI treeUI) { if(treeUI.getRoot() == DataExplorerTreeRoot.USER_LOCATION) { @@ -159,6 +183,8 @@ protected void initTabComponent(Composite parent, DataExplorerTreeUI treeUI) { treeUI.getTreeViewer().setInput(new File[]{directory}); } } + createContextMenu(treeUI); + addBatchOpenButton(parent, treeUI); } private DataExplorerTreeUI createDataExplorerTreeUI(TabFolder tabFolder, DataExplorerTreeRoot root) { @@ -169,6 +195,7 @@ private DataExplorerTreeUI createDataExplorerTreeUI(TabFolder tabFolder, DataExp Composite composite = new Composite(tabFolder, SWT.NONE); composite.setLayoutData(new GridData(GridData.FILL_BOTH)); composite.setLayout(new GridLayout()); + createToolbarMain(composite); // DataExplorerTreeUI dataExplorerTreeUI = new DataExplorerTreeUI(composite, root, getIdentifierSupplier()); TreeViewer treeViewer = dataExplorerTreeUI.getTreeViewer(); @@ -242,4 +269,202 @@ public void widgetSelected(SelectionEvent e) { } }); } + + private void createContextMenu(DataExplorerTreeUI treeUI) { + + TreeViewer treeViewer = treeUI.getTreeViewer(); + MenuManager contextMenu = new MenuManager("#ViewerMenu"); //$NON-NLS-1$ + contextMenu.setRemoveAllWhenShown(true); + contextMenu.addMenuListener(new IMenuListener() { + + @Override + public void menuAboutToShow(IMenuManager mgr) { + + Object[] selection = treeViewer.getStructuredSelection().toArray(); + Map>> converterSupplier = new HashMap<>(); + Set supplierSet = new TreeSet<>(new Comparator() { + + @Override + public int compare(ISupplier o1, ISupplier o2) { + + return o1.getId().compareTo(o2.getId()); + } + }); + // + for(Object object : selection) { + if(object instanceof File) { + File file = (File)object; + Map> map = getIdentifierSupplier().apply(file); + converterSupplier.put(file, map); + for(Collection s : map.values()) { + supplierSet.addAll(s); + } + } + } + contextMenu.add(new Action("Scan for file and folder updates", ApplicationImageFactory.getInstance().getImageDescriptor(IApplicationImage.IMAGE_REFRESH, IApplicationImage.SIZE_16x16)) { + + @Override + public void run() { + + treeViewer.refresh(); + } + }); + // + for(ISupplier activeFileSupplier : supplierSet) { + contextMenu.add(new Action("Open as: " + activeFileSupplier.getFilterName(), ApplicationImageFactory.getInstance().getImageDescriptor(IApplicationImage.IMAGE_FILE, IApplicationImage.SIZE_16x16)) { + + @Override + public void run() { + + outer: + for(Object object : selection) { + if(object instanceof File) { + File file = (File)object; + Map> map = converterSupplier.get(file); + for(Entry> entry : map.entrySet()) { + ISupplierFileIdentifier identifier = entry.getKey(); + if(identifier instanceof ISupplierFileEditorSupport) { + for(ISupplier supplier : entry.getValue()) { + if(activeFileSupplier.getId().equals(supplier.getId())) { + openEditorWithSupplier(file, (ISupplierFileEditorSupport)identifier, supplier); + continue outer; + } + } + } + } + } + } + } + + @Override + public String getToolTipText() { + + return activeFileSupplier.getDescription(); + }; + }); + } + // + if(selection.length == 1 && selection[0] instanceof File && ((File)selection[0]).isDirectory()) { + contextMenu.add(new Action("Open all contained measurements in this folder", ApplicationImageFactory.getInstance().getImageDescriptor(IApplicationImage.IMAGE_FOLDER, IApplicationImage.SIZE_16x16)) { + + @Override + public void run() { + + openRecurse((File)selection[0], treeUI); + } + }); + } + } + }); + // + Menu menu = contextMenu.createContextMenu(treeViewer.getControl()); + treeViewer.getControl().setMenu(menu); + } + + private boolean openRecurse(File file, DataExplorerTreeUI treeUI) { + + boolean opened = false; + File[] listFiles = file.listFiles(); + if(listFiles != null) { + for(File f : listFiles) { + opened |= openEditor(f, treeUI); + } + if(!opened) { + for(File f : listFiles) { + if(f.isDirectory()) { + // recurse into sub-directory... + opened |= openRecurse(f, treeUI); + } + } + } + } + return opened; + }; + + private void addBatchOpenButton(Composite parent, DataExplorerTreeUI treeUI) { + + Button button = new Button(parent, SWT.PUSH); + button.setText("Open Selected Measurements"); + button.setToolTipText("Try to open all selected files. Handle with care."); + button.setImage(ApplicationImageFactory.getInstance().getImage(IApplicationImage.IMAGE_IMPORT, IApplicationImage.SIZE_16x16)); + button.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + button.addSelectionListener(new SelectionAdapter() { + + @SuppressWarnings("rawtypes") + @Override + public void widgetSelected(SelectionEvent e) { + + IStructuredSelection structuredSelection = treeUI.getTreeViewer().getStructuredSelection(); + Iterator iterator = structuredSelection.iterator(); + while(iterator.hasNext()) { + Object object = iterator.next(); + if(object instanceof File) { + e.display.asyncExec(new Runnable() { + + @Override + public void run() { + + File file = (File)object; + openEditor(file, treeUI); + } + }); + } + } + } + }); + } + + private void openOverview(File file, DataExplorerTreeUI dataExplorerTreeUI) { + + if(file != null) { + DataExplorerContentProvider contentProvider = (DataExplorerContentProvider)dataExplorerTreeUI.getTreeViewer().getContentProvider(); + /* + * Update the directories content, until there is + * actual no way to monitor the file system outside + * of the workbench without using operating system + * specific function via e.g. JNI. + */ + if(file.isDirectory()) { + contentProvider.refresh(file); + } + // + Collection identifiers = getIdentifierSupplier().apply(file).keySet(); + for(ISupplierFileIdentifier identifier : identifiers) { + if(identifier instanceof ISupplierFileEditorSupport) { + ISupplierFileEditorSupport fileEditorSupport = (ISupplierFileEditorSupport)identifier; + fileEditorSupport.openOverview(file); + return; + } + } + // + UpdateNotifier.update(IChemClipseEvents.TOPIC_CHROMATOGRAM_XXD_UPDATE_NONE, null); + } + } + + private boolean openEditor(File file, DataExplorerTreeUI treeUI) { + + boolean success = false; + if(file != null) { + boolean openFirstDataMatchOnly = PreferenceSupplier.isOpenFirstDataMatchOnly(); + Map> identifiers = getIdentifierSupplier().apply(file); + for(Entry> entry : identifiers.entrySet()) { + ISupplierFileIdentifier identifier = entry.getKey(); + if(identifier instanceof ISupplierFileEditorSupport) { + for(ISupplier converter : entry.getValue()) { + success = success | openEditorWithSupplier(file, (ISupplierFileEditorSupport)identifier, converter); + if(success && openFirstDataMatchOnly) { + return true; + } + } + } + } + } + return success; + } + + private boolean openEditorWithSupplier(File file, ISupplierFileEditorSupport identifier, ISupplier converter) { + + saveLastDirectoryPath(); + return identifier.openEditor(file, converter); + } } diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/fragment.e4xmi b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/fragment.e4xmi index 45e725c1f6..da372a3dcf 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/fragment.e4xmi +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/fragment.e4xmi @@ -2,12 +2,7 @@ - - - - - - + diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/handlers/DataExplorerSettingsHandler.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/handlers/DataExplorerSettingsHandler.java deleted file mode 100644 index fd669da315..0000000000 --- a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/handlers/DataExplorerSettingsHandler.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2020 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: - * Dr. Philip Wenig - initial API and implementation - * Christoph Läubrich - Move custom made toolbar to the native toolbar with E4Handlers - * Philip Wenig - modularization - *******************************************************************************/ -package org.eclipse.chemclipse.ux.extension.xxd.ui.internal.handlers; - -import javax.inject.Named; - -import org.eclipse.chemclipse.ux.extension.ui.preferences.PreferencePage; -import org.eclipse.chemclipse.ux.extension.xxd.ui.parts.DataExplorerPart; -import org.eclipse.chemclipse.ux.extension.xxd.ui.preferences.PreferencePageFileExplorer; -import org.eclipse.e4.core.di.annotations.Execute; -import org.eclipse.e4.ui.model.application.ui.basic.MPart; -import org.eclipse.e4.ui.services.IServiceConstants; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.preference.PreferenceDialog; -import org.eclipse.jface.preference.PreferenceManager; -import org.eclipse.jface.preference.PreferenceNode; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.widgets.Shell; - -public class DataExplorerSettingsHandler { - - @Execute - public void execute(MPart part, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell) { - - Object object = part.getObject(); - if(object instanceof DataExplorerPart) { - DataExplorerPart dataExplorerPart = (DataExplorerPart)object; - PreferenceManager preferenceManager = new PreferenceManager(); - preferenceManager.addToRoot(new PreferenceNode("1", new PreferencePageFileExplorer())); - preferenceManager.addToRoot(new PreferenceNode("2", new PreferencePage())); - // - PreferenceDialog preferenceDialog = new PreferenceDialog(shell, preferenceManager); - preferenceDialog.create(); - preferenceDialog.setMessage("Settings"); - if(preferenceDialog.open() == Window.OK) { - try { - dataExplorerPart.setSupplierFileEditorSupport(); - } catch(Exception e1) { - MessageDialog.openError(shell, "Settings", "Something has gone wrong to apply the settings."); - } - } - } - } -} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/handlers/ResetDataExplorerHandler.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/handlers/ResetDataExplorerHandler.java deleted file mode 100644 index e8d22d6154..0000000000 --- a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/handlers/ResetDataExplorerHandler.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2020 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: - * Dr. Philip Wenig - initial API and implementation - * Christoph Läubrich - Move custom made toolbar to the native toolbar with E4Handlers - *******************************************************************************/ -package org.eclipse.chemclipse.ux.extension.xxd.ui.internal.handlers; - -import org.eclipse.chemclipse.ux.extension.xxd.ui.parts.DataExplorerPart; -import org.eclipse.e4.core.di.annotations.Execute; -import org.eclipse.e4.ui.model.application.ui.basic.MPart; - -public class ResetDataExplorerHandler { - - @Execute - public void execute(MPart part) { - - Object object = part.getObject(); - if(object instanceof DataExplorerPart) { - DataExplorerPart dataExplorerPart = (DataExplorerPart)object; - dataExplorerPart.getDataExplorerUI().expandLastDirectoryPath(); - } - } -} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/parts/DataExplorerPart.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/parts/DataExplorerPart.java index 20e25b9947..fc91bea8f4 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/parts/DataExplorerPart.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/parts/DataExplorerPart.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016, 2021 Lablicate GmbH. + * Copyright (c) 2016, 2022 Lablicate GmbH. * * All rights reserved. * This program and the accompanying materials are made available under the @@ -13,21 +13,12 @@ *******************************************************************************/ package org.eclipse.chemclipse.ux.extension.xxd.ui.parts; -import java.util.ArrayList; -import java.util.List; - import javax.annotation.PostConstruct; import javax.inject.Inject; -import org.eclipse.chemclipse.model.types.DataType; import org.eclipse.chemclipse.processing.converter.ISupplierFileIdentifier; -import org.eclipse.chemclipse.ux.extension.ui.provider.ISupplierFileEditorSupport; -import org.eclipse.chemclipse.ux.extension.ui.swt.DataExplorerUI; import org.eclipse.chemclipse.ux.extension.xxd.ui.Activator; -import org.eclipse.chemclipse.ux.extension.xxd.ui.internal.editors.ProjectExplorerSupportFactory; -import org.eclipse.chemclipse.ux.extension.xxd.ui.part.support.GenericSupplierEditorSupport; -import org.eclipse.chemclipse.ux.extension.xxd.ui.part.support.SupplierEditorSupport; -import org.eclipse.chemclipse.ux.extension.xxd.ui.preferences.PreferenceConstants; +import org.eclipse.chemclipse.ux.extension.xxd.ui.swt.DataExplorerUI; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.ui.di.Focus; import org.eclipse.e4.ui.model.application.ui.basic.MPart; @@ -36,8 +27,6 @@ public class DataExplorerPart { - @Inject - private IEclipseContext context; @Inject private ISupplierFileIdentifier supplierFileIdentifier; // @@ -45,97 +34,9 @@ public class DataExplorerPart { private IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore(); @PostConstruct - public void init(Composite parent, MPart part, IEclipseContext eclipseContext) { - - dataExplorerUI = new DataExplorerUI(parent, preferenceStore); - setSupplierFileEditorSupport(); - } - - public void setSupplierFileEditorSupport() { + public void init(Composite parent, MPart part, IEclipseContext context) { - List editorSupportList = new ArrayList(); - /* - * MSD - */ - if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_DATA_MSD)) { - editorSupportList.add(new SupplierEditorSupport(DataType.MSD, () -> context)); - } - /* - * MSD Library - */ - if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_LIBRARY_MSD)) { - editorSupportList.add(org.eclipse.chemclipse.ux.extension.msd.ui.support.DatabaseSupport.getInstanceEditorSupport()); - } - /* - * MSD Scan - */ - if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_SCANS_MSD)) { - editorSupportList.add(org.eclipse.chemclipse.ux.extension.msd.ui.support.MassSpectrumSupport.getInstanceEditorSupport()); - } - /* - * CSD - */ - if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_DATA_CSD)) { - editorSupportList.add(new SupplierEditorSupport(DataType.CSD, () -> context)); - } - /* - * WSD - */ - if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_DATA_WSD)) { - editorSupportList.add(new SupplierEditorSupport(DataType.WSD, () -> context)); - } - /* - * TSD - */ - if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_DATA_TSD)) { - editorSupportList.add(new SupplierEditorSupport(DataType.TSD, () -> context)); - } - /* - * XIR - */ - if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_DATA_XIR)) { - editorSupportList.add(new SupplierEditorSupport(DataType.XIR, () -> context)); - } - /* - * NMR - */ - if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_DATA_NMR)) { - editorSupportList.add(new SupplierEditorSupport(DataType.NMR, () -> context)); - } - /* - * CAL - */ - if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_DATA_CAL)) { - editorSupportList.add(new ProjectExplorerSupportFactory(DataType.CAL).getInstanceEditorSupport()); - } - /* - * PCR - */ - if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_DATA_PCR)) { - editorSupportList.add(new SupplierEditorSupport(DataType.PCR, () -> context)); - } - /* - * SEQ - */ - if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_DATA_SEQUENCE)) { - editorSupportList.add(new SupplierEditorSupport(DataType.SEQ, () -> context)); - } - /* - * MTH - */ - if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_DATA_METHOD)) { - editorSupportList.add(new SupplierEditorSupport(DataType.MTH, () -> context)); - } - /* - * QDB - */ - if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_DATA_QUANT_DB)) { - editorSupportList.add(new SupplierEditorSupport(DataType.QDB, () -> context)); - } - // - editorSupportList.add(new GenericSupplierEditorSupport(supplierFileIdentifier, () -> context)); - dataExplorerUI.setSupplierFileIdentifier(editorSupportList); - dataExplorerUI.expandLastDirectoryPath(); + dataExplorerUI = new DataExplorerUI(parent, preferenceStore, context, supplierFileIdentifier); } public DataExplorerUI getDataExplorerUI() { diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/swt/DataExplorerUI.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/swt/DataExplorerUI.java new file mode 100644 index 0000000000..31de78cee5 --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/swt/DataExplorerUI.java @@ -0,0 +1,215 @@ +/******************************************************************************* + * Copyright (c) 2018, 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: + * Dr. Philip Wenig - initial API and implementation + * Christoph Läubrich - performance optimization and cleanup, refactor handling of Suppliers + * Matthias Mailänder - right-click refresh option + *******************************************************************************/ +package org.eclipse.chemclipse.ux.extension.xxd.ui.swt; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.chemclipse.model.types.DataType; +import org.eclipse.chemclipse.processing.converter.ISupplierFileIdentifier; +import org.eclipse.chemclipse.rcp.ui.icons.core.ApplicationImageFactory; +import org.eclipse.chemclipse.rcp.ui.icons.core.IApplicationImage; +import org.eclipse.chemclipse.rcp.ui.icons.core.IApplicationImageProvider; +import org.eclipse.chemclipse.support.ui.workbench.DisplayUtils; +import org.eclipse.chemclipse.swt.ui.preferences.PreferencePageSystem; +import org.eclipse.chemclipse.ux.extension.ui.provider.ISupplierFileEditorSupport; +import org.eclipse.chemclipse.ux.extension.ui.swt.MultiDataExplorerTreeUI; +import org.eclipse.chemclipse.ux.extension.xxd.ui.internal.editors.ProjectExplorerSupportFactory; +import org.eclipse.chemclipse.ux.extension.xxd.ui.part.support.GenericSupplierEditorSupport; +import org.eclipse.chemclipse.ux.extension.xxd.ui.part.support.SupplierEditorSupport; +import org.eclipse.chemclipse.ux.extension.xxd.ui.preferences.PreferenceConstants; +import org.eclipse.chemclipse.ux.extension.xxd.ui.preferences.PreferencePage; +import org.eclipse.chemclipse.ux.extension.xxd.ui.preferences.PreferencePageFileExplorer; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.preference.IPreferencePage; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferenceDialog; +import org.eclipse.jface.preference.PreferenceManager; +import org.eclipse.jface.preference.PreferenceNode; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +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; + +public class DataExplorerUI extends MultiDataExplorerTreeUI { + + private IEclipseContext context; + private ISupplierFileIdentifier supplierFileIdentifier; + // + IPreferenceStore preferenceStore; + + public DataExplorerUI(Composite parent, IPreferenceStore preferenceStore, IEclipseContext context, ISupplierFileIdentifier supplierFileIdentifier) { + + super(parent, preferenceStore); + this.preferenceStore = preferenceStore; + this.context = context; + this.supplierFileIdentifier = supplierFileIdentifier; + setSupplierFileEditorSupport(); + } + + @Override + protected void createToolbarMain(Composite parent) { + + Composite composite = new Composite(parent, SWT.NONE); + GridData gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.horizontalAlignment = SWT.END; + composite.setLayoutData(gridData); + composite.setLayout(new GridLayout(2, false)); + // + createResetButton(composite); + createSettingsButton(composite); + } + + private void createResetButton(Composite parent) { + + Button button = new Button(parent, SWT.PUSH); + button.setToolTipText("Reset the data explorer."); + button.setText(""); + button.setImage(ApplicationImageFactory.getInstance().getImage(IApplicationImage.IMAGE_RESET, IApplicationImageProvider.SIZE_16x16)); + button.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + + expandLastDirectoryPath(); + } + }); + } + + private void createSettingsButton(Composite parent) { + + Button button = new Button(parent, SWT.PUSH); + button.setToolTipText("Open the Settings."); + button.setText(""); + button.setImage(ApplicationImageFactory.getInstance().getImage(IApplicationImage.IMAGE_PREFERENCES, IApplicationImageProvider.SIZE_16x16)); + button.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + + IPreferencePage preferencePageSWT = new PreferencePageSystem(); + preferencePageSWT.setTitle("Settings (SWT)"); + IPreferencePage preferencePageMSD = new PreferencePage(); + preferencePageMSD.setTitle("Settings (MSD)"); + // + PreferenceManager preferenceManager = new PreferenceManager(); + preferenceManager.addToRoot(new PreferenceNode("1", new PreferencePageFileExplorer())); + preferenceManager.addToRoot(new PreferenceNode("2", new PreferencePage())); + // + PreferenceDialog preferenceDialog = new PreferenceDialog(DisplayUtils.getShell(), preferenceManager); + preferenceDialog.create(); + preferenceDialog.setMessage("Settings"); + if(preferenceDialog.open() == Window.OK) { + try { + setSupplierFileEditorSupport(); + } catch(Exception e1) { + MessageDialog.openError(DisplayUtils.getShell(), "Settings", "Something has gone wrong to apply the settings."); + } + } + } + }); + } + + private void setSupplierFileEditorSupport() { + + List editorSupportList = new ArrayList<>(); + /* + * MSD + */ + if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_DATA_MSD)) { + editorSupportList.add(new SupplierEditorSupport(DataType.MSD, () -> context)); + } + /* + * MSD Library + */ + if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_LIBRARY_MSD)) { + editorSupportList.add(org.eclipse.chemclipse.ux.extension.msd.ui.support.DatabaseSupport.getInstanceEditorSupport()); + } + /* + * MSD Scan + */ + if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_SCANS_MSD)) { + editorSupportList.add(org.eclipse.chemclipse.ux.extension.msd.ui.support.MassSpectrumSupport.getInstanceEditorSupport()); + } + /* + * CSD + */ + if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_DATA_CSD)) { + editorSupportList.add(new SupplierEditorSupport(DataType.CSD, () -> context)); + } + /* + * WSD + */ + if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_DATA_WSD)) { + editorSupportList.add(new SupplierEditorSupport(DataType.WSD, () -> context)); + } + /* + * TSD + */ + if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_DATA_TSD)) { + editorSupportList.add(new SupplierEditorSupport(DataType.TSD, () -> context)); + } + /* + * XIR + */ + if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_DATA_XIR)) { + editorSupportList.add(new SupplierEditorSupport(DataType.XIR, () -> context)); + } + /* + * NMR + */ + if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_DATA_NMR)) { + editorSupportList.add(new SupplierEditorSupport(DataType.NMR, () -> context)); + } + /* + * CAL + */ + if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_DATA_CAL)) { + editorSupportList.add(new ProjectExplorerSupportFactory(DataType.CAL).getInstanceEditorSupport()); + } + /* + * PCR + */ + if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_DATA_PCR)) { + editorSupportList.add(new SupplierEditorSupport(DataType.PCR, () -> context)); + } + /* + * SEQ + */ + if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_DATA_SEQUENCE)) { + editorSupportList.add(new SupplierEditorSupport(DataType.SEQ, () -> context)); + } + /* + * MTH + */ + if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_DATA_METHOD)) { + editorSupportList.add(new SupplierEditorSupport(DataType.MTH, () -> context)); + } + /* + * QDB + */ + if(preferenceStore.getBoolean(PreferenceConstants.P_SHOW_DATA_QUANT_DB)) { + editorSupportList.add(new SupplierEditorSupport(DataType.QDB, () -> context)); + } + // + editorSupportList.add(new GenericSupplierEditorSupport(supplierFileIdentifier, () -> context)); + setSupplierFileIdentifier(editorSupportList); + expandLastDirectoryPath(); + } +}