From ec8d54dca345050f9f9d8383b58c065773b62dd5 Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Tue, 17 Mar 2020 12:54:38 +0100 Subject: [PATCH] add multi file feature --- .../META-INF/MANIFEST.MF | 2 +- com.minres.scviewer.e4.application/pom.xml | 2 +- .../scviewer/e4/application/E4LifeCycle.java | 12 +++- .../e4/application/handlers/OpenHandler.java | 25 ++++---- .../e4/application/parts/WaveformViewer.java | 58 ++++++++++--------- com.minres.scviewer.e4.product/pom.xml | 2 +- .../scviewer.product | 2 +- 7 files changed, 61 insertions(+), 42 deletions(-) diff --git a/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF b/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF index c7b3710..3fee919 100644 --- a/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF +++ b/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name Bundle-SymbolicName: com.minres.scviewer.e4.application;singleton:=true -Bundle-Version: 2.2.0.qualifier +Bundle-Version: 2.3.0.qualifier Bundle-Vendor: %Bundle-Vendor Require-Bundle: javax.inject;bundle-version="1.0.0", org.eclipse.core.runtime;bundle-version="3.11.1", diff --git a/com.minres.scviewer.e4.application/pom.xml b/com.minres.scviewer.e4.application/pom.xml index d43c9c9..a0c8e84 100644 --- a/com.minres.scviewer.e4.application/pom.xml +++ b/com.minres.scviewer.e4.application/pom.xml @@ -1,7 +1,7 @@ 4.0.0 com.minres.scviewer.e4.application - 2.2.0-SNAPSHOT + 2.3.0-SNAPSHOT com.minres.scviewer com.minres.scviewer.parent diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/E4LifeCycle.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/E4LifeCycle.java index 3866bed..2feb068 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/E4LifeCycle.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/E4LifeCycle.java @@ -158,19 +158,27 @@ public class E4LifeCycle { * @param name the name */ public void openViewForFile(String name){ - File file = new File(name); + File file = new File(getFirstFileName(name)); MPart part = partService.createPart("com.minres.scviewer.e4.application.partdescriptor.waveformviewer"); //$NON-NLS-1$ part.setLabel(file.getName()); MPartStack partStack = (MPartStack)modelService.find("org.eclipse.editorss", app); //$NON-NLS-1$ partStack.getChildren().add(part); partService.showPart(part, PartState.ACTIVATE); IEclipseContext ctx=part.getContext(); - ctx.modify("input", file); //$NON-NLS-1$ + ctx.modify("input", name); //$NON-NLS-1$ //ctx.declareModifiable("input"); //$NON-NLS-1$ ctx.modify("config", confFile); //$NON-NLS-1$ //ctx.declareModifiable("config"); //$NON-NLS-1$ } + private String getFirstFileName(String name) { + if(name.contains(":")) { + String[] tokens = name.split(","); + return tokens[0]; + } else + return name; + } + public void setConfigFile(String confFile) { this.confFile=confFile; } diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/OpenHandler.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/OpenHandler.java index df60b5d..42288c2 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/OpenHandler.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/OpenHandler.java @@ -11,6 +11,7 @@ package com.minres.scviewer.e4.application.handlers; import java.io.File; +import java.util.ArrayList; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.di.annotations.Execute; @@ -33,19 +34,23 @@ public class OpenHandler { dialog.setFilterExtensions (new String []{Messages.OpenHandler_0}); dialog.open(); String path = dialog.getFilterPath(); + ArrayList files = new ArrayList(); for(String fileName: dialog.getFileNames()){ File file = new File(path+File.separator+fileName); - if(file.exists()){ - MPart part = partService .createPart("com.minres.scviewer.e4.application.partdescriptor.waveformviewer"); //$NON-NLS-1$ - part.setLabel(file.getName()); - MPartStack partStack = (MPartStack)modelService.find("org.eclipse.editorss", app); //$NON-NLS-1$ - partStack.getChildren().add(part); - partService.showPart(part, PartState.ACTIVATE); - IEclipseContext ctx=part.getContext(); - ctx.modify("input", file); //$NON-NLS-1$ - ctx.modify("config", ""); //$NON-NLS-1$ - } + if(file.exists()) + files.add(file); } + MPart part = partService .createPart("com.minres.scviewer.e4.application.partdescriptor.waveformviewer"); //$NON-NLS-1$ + part.setLabel(files.get(0).getName()); + MPartStack partStack = (MPartStack)modelService.find("org.eclipse.editorss", app); //$NON-NLS-1$ + partStack.getChildren().add(part); + partService.showPart(part, PartState.ACTIVATE); + final IEclipseContext ctx=part.getContext(); + files.stream() + .map(x -> x.getAbsolutePath()) + .reduce((s1, s2) -> s1 + "," + s2) + .ifPresent(s -> ctx.modify("input", s)); //$NON-NLS-1$ + ctx.modify("config", ""); //$NON-NLS-1$ } } diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java index 6441654..5495e59 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java @@ -507,34 +507,40 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis @Inject @Optional public void setPartInput(@Named("input") Object partInput, @Named("config") Object partConfig) { - if (partInput instanceof File) { + if (partInput instanceof String) { + String name = (String)partInput; filesToLoad = new ArrayList(); - File file = (File) partInput; - if(file.isFile() && "CURRENT".equals(file.getName())){ - file=file.getParentFile(); - } - if (file.exists()) { - filesToLoad.add(file); - try { - String ext = getFileExtension(file.getName()); - if (Messages.WaveformViewer_19.equals(ext.toLowerCase())) { - if (askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), Messages.WaveformViewer_20)))) { - filesToLoad.add(new File(renameFileExtension(file.getCanonicalPath(), Messages.WaveformViewer_20))); - } else if (askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), Messages.WaveformViewer_21)))) { - filesToLoad.add(new File(renameFileExtension(file.getCanonicalPath(), Messages.WaveformViewer_21))); - } else if (askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), Messages.WaveformViewer_22)))) { - filesToLoad.add(new File(renameFileExtension(file.getCanonicalPath(), Messages.WaveformViewer_22))); - } - } else if (Messages.WaveformViewer_20.equals(ext.toLowerCase()) || - Messages.WaveformViewer_21.equals(ext.toLowerCase()) || - Messages.WaveformViewer_22.equals(ext.toLowerCase()) - ) { - if (askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), Messages.WaveformViewer_19)))) { - filesToLoad.add(new File(renameFileExtension(file.getCanonicalPath(), Messages.WaveformViewer_19))); - } - } - } catch (IOException e) { // silently ignore any error + boolean explicit = name.contains(","); + for(String tok: name.split(",")) { + File file = new File(tok); + if(file.isFile() && "CURRENT".equals(file.getName())){ + file=file.getParentFile(); } + if (file.exists()) { + filesToLoad.add(file); + } + if(!explicit) + try { + String ext = getFileExtension(file.getName()); + if (Messages.WaveformViewer_19.equals(ext.toLowerCase())) { + if (askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), Messages.WaveformViewer_20)))) { + filesToLoad.add(new File(renameFileExtension(file.getCanonicalPath(), Messages.WaveformViewer_20))); + } else if (askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), Messages.WaveformViewer_21)))) { + filesToLoad.add(new File(renameFileExtension(file.getCanonicalPath(), Messages.WaveformViewer_21))); + } else if (askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), Messages.WaveformViewer_22)))) { + filesToLoad.add(new File(renameFileExtension(file.getCanonicalPath(), Messages.WaveformViewer_22))); + } + } else if (Messages.WaveformViewer_20.equals(ext.toLowerCase()) || + Messages.WaveformViewer_21.equals(ext.toLowerCase()) || + Messages.WaveformViewer_22.equals(ext.toLowerCase()) + ) { + if (askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), Messages.WaveformViewer_19)))) { + filesToLoad.add(new File(renameFileExtension(file.getCanonicalPath(), Messages.WaveformViewer_19))); + } + } + } catch (IOException e) { // silently ignore any error + } + } if (filesToLoad.size() > 0) loadDatabase(persistedState); diff --git a/com.minres.scviewer.e4.product/pom.xml b/com.minres.scviewer.e4.product/pom.xml index 06d3ffb..effbfb5 100644 --- a/com.minres.scviewer.e4.product/pom.xml +++ b/com.minres.scviewer.e4.product/pom.xml @@ -10,7 +10,7 @@ ../com.minres.scviewer.parent com.minres.scviewer.e4.product - 2.2.0-SNAPSHOT + 2.3.0-SNAPSHOT eclipse-repository com.minres.scviewer diff --git a/com.minres.scviewer.e4.product/scviewer.product b/com.minres.scviewer.e4.product/scviewer.product index a22bfa4..6a40894 100644 --- a/com.minres.scviewer.e4.product/scviewer.product +++ b/com.minres.scviewer.e4.product/scviewer.product @@ -1,7 +1,7 @@ - +