From 868eceddc59326b0a8e08ef6bd88516ec5bfd7f1 Mon Sep 17 00:00:00 2001 From: eyck Date: Tue, 27 Oct 2020 18:11:03 +0100 Subject: [PATCH 1/2] fix CLI handling --- .../scviewer/e4/application/E4LifeCycle.java | 116 +++++------------- 1 file changed, 29 insertions(+), 87 deletions(-) diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/E4LifeCycle.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/E4LifeCycle.java index 310323a..6f91a1d 100644 --- a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/E4LifeCycle.java +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/E4LifeCycle.java @@ -12,11 +12,14 @@ package com.minres.scviewer.e4.application; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import javax.annotation.PostConstruct; import javax.inject.Inject; import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener; import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.services.events.IEventBroker; @@ -64,9 +67,11 @@ public class E4LifeCycle { * @param eventBroker the event broker */ @PostContextCreate - void postContextCreate(IApplicationContext appContext, final IEventBroker eventBroker) { + void postContextCreate(IApplicationContext appContext, final IEventBroker eventBroker, + final IEclipseContext workbenchContext) { + final String[] args = (String[])appContext.getArguments().get(IApplicationContext.APPLICATION_ARGS); - Options opt = new Options(args, 0, 1); + final Options opt = new Options(args, 0, Integer.MAX_VALUE); opt.getSet() .addOption("clearPersistedState", Multiplicity.ZERO_OR_ONE) .addOption("c", Separator.BLANK, Multiplicity.ZERO_OR_ONE); @@ -77,22 +82,14 @@ public class E4LifeCycle { final String confFile =opt.getSet().isSet("c")?opt.getSet().getOption("c").getResultValue(0):""; // react on the first view being created, at that time the UI is available - eventBroker.subscribe(UIEvents.UILifeCycle.ACTIVATE, new EventHandler() { - @Override - public void handleEvent(Event event) { - MPart part = (MPart) event.getProperty("ChangedElement"); //$NON-NLS-1$ - if(part!=null){ - IEclipseContext ctx = part.getContext(); - OpenViewHandler openViewHandler= new OpenViewHandler(); - if(confFile.length()>0) openViewHandler.setConfigFile(confFile); - ContextInjectionFactory.inject(openViewHandler, ctx); - eventBroker.unsubscribe(this); - for(String name:opt.getSet().getData()){ - openViewHandler.openViewForFile(name); - } - } - } - }); +// eventBroker.subscribe(UIEvents.UILifeCycle.ACTIVATE, new EventHandler() { +// @Override +// public void handleEvent(Event event) { +// MPart part = (MPart) event.getProperty("ChangedElement"); //$NON-NLS-1$ +// if(part!=null){ +// } +// } +// }); eventBroker.subscribe(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE, new EventHandler() { @Override public void handleEvent(Event event) { @@ -101,9 +98,20 @@ public class E4LifeCycle { boolean isLocked = instanceLocation.isLocked(); if(isLocked) instanceLocation.release(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + } catch (IOException e) { } + if(opt.getSet().getData().size()>0) { + MApplication app= workbenchContext.get(MApplication.class); + EModelService modelService = workbenchContext.get(EModelService.class); + EPartService partService= workbenchContext.get(EPartService.class); + MPart part = partService .createPart("com.minres.scviewer.e4.application.partdescriptor.waveformviewer"); //$NON-NLS-1$ + part.setLabel(opt.getSet().getData().get(0)); + MPartStack partStack = (MPartStack)modelService.find("org.eclipse.editorss", app); //$NON-NLS-1$ + partStack.getChildren().add(part); + partService.showPart(part, PartState.CREATE); + partService.showPart(part, PartState.ACTIVATE); + IEclipseContext ctx = part.getContext(); + ctx.modify("input", opt.getSet().getData()); + ctx.modify("config", confFile); //$NON-NLS-1$ } } }); @@ -135,70 +143,4 @@ public class E4LifeCycle { @ProcessRemovals void processRemovals(IEclipseContext workbenchContext) { } - - /** - * Join. - * - * @param tokens the tokens - * @return the string - */ - String join(String[] tokens){ - StringBuilder sb = new StringBuilder(); - boolean first=true; - for(String token:tokens){ - if(!first) sb.append(","); //$NON-NLS-1$ - sb.append(token); - first=false; - } - return sb.toString(); - } - - /** - * The Class OpenViewHandler. - */ - private class OpenViewHandler { - - /** The app. */ - @Inject MApplication app; - - /** The model service. */ - @Inject EModelService modelService; - - /** The part service. */ - @Inject EPartService partService; - - String confFile=""; - /** - * Open view for file. - * - * @param name the name - */ - public void openViewForFile(String name){ - File file = new File(getFirstFileName(name)); - if(!file.exists()) - return; - 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", 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; - } - } } From b34fe0d0baecb673802faa4ecae1f25f2514dfa1 Mon Sep 17 00:00:00 2001 From: eyck Date: Wed, 28 Oct 2020 13:32:17 +0100 Subject: [PATCH 2/2] add reload menu and toolbar item --- .../Application.e4xmi | 8 +++- .../icons/database_refresh.png | Bin 0 -> 770 bytes .../application/handlers/ReloadHandler.java | 42 ++++++++++++++++++ .../e4/application/parts/WaveformViewer.java | 24 +++++++--- 4 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 plugins/com.minres.scviewer.e4.application/icons/database_refresh.png create mode 100644 plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/ReloadHandler.java diff --git a/plugins/com.minres.scviewer.e4.application/Application.e4xmi b/plugins/com.minres.scviewer.e4.application/Application.e4xmi index 81fadd5..0822bbe 100644 --- a/plugins/com.minres.scviewer.e4.application/Application.e4xmi +++ b/plugins/com.minres.scviewer.e4.application/Application.e4xmi @@ -11,7 +11,8 @@ - + + @@ -58,7 +59,8 @@ - + + @@ -133,6 +135,7 @@ + type:user @@ -264,6 +267,7 @@ + diff --git a/plugins/com.minres.scviewer.e4.application/icons/database_refresh.png b/plugins/com.minres.scviewer.e4.application/icons/database_refresh.png new file mode 100644 index 0000000000000000000000000000000000000000..ff803be124ac5f1bd747490d2243f876eebdf5f6 GIT binary patch literal 770 zcmV+d1O5DoP)L1E-$)@F1-w)3&R|k zpe8{Z8<~c8GL+Q$?>DkG77MrB>ib*oIq``rr5B#_9^P}_=lwfJ$Ye4I1OislR|zeK zVbqYWCeYUSM0$zz3qqi|xmm|wBKZCO<8;X*Nm5-|Ss83L8wv^vz=$_CHjqpv5e|nD zi^V>Y?WWu9Ue99i`F!tXS!UrfyNRl*nP4!OdF<_2YxlP1Fme+XT27Rfmg0ZnbUKmN zQchLT0^98(MdnP?)6=lq?HnZ~C0I!=;+^~kYsqD3nhs6X;Vdi{?VA1UEzfmtU&~-q z7JwZi{gIM{t3{_E4UR1%)L*WJg$bH{MmVw30fE`e?I2IEj?l`hAghYH3 zt$W+>w6P28pTBBza%f!nsWhE`b~-<+1YOrT3B$cZ4>?gZ8b$I)lH1swJjJS$^EqF~ zm_fejtPITPCdn3|s^RUIA%3SpXiSi^{?8N`Oh=PY(SA|m3=BsGkWx0eT~QP?b~cPr zKhDrN8M!R7Nbz_a^b+|5(&_XcW=k#xvLap&a?YNRF|tvD>5s;|fF{5;0S zC%l5k;M1&07*qoM6N<$f state) { + loadDatabase(state, 1000L); + } + + protected void loadDatabase(final Map state, long delay) { fileMonitor.removeFileChangeListener(this); Job job = new Job(Messages.WaveformViewer_15) { @Override @@ -619,8 +623,9 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis return result; } }; + job.setName("Load Database"); job.setSystem(true); - job.schedule(1000L); // let the UI initialize so that we have a progress monitor + job.schedule(delay); // let the UI initialize so that we have a progress monitor } /* (non-Javadoc) @@ -634,18 +639,23 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis public void run() { if (MessageDialog.openQuestion(display.getActiveShell(), Messages.WaveformViewer_17, Messages.WaveformViewer_18)) { - Map state = new HashMap<>(); - saveWaveformViewerState(state); - waveformPane.getStreamList().clear(); - database.clear(); - if (filesToLoad.size() > 0) - loadDatabase(state); + reloadDatabase(); } } + }); fileMonitor.removeFileChangeListener(this); } + public void reloadDatabase() { + Map state = new HashMap<>(); + saveWaveformViewerState(state); + waveformPane.getStreamList().clear(); + database.clear(); + if (filesToLoad.size() > 0) + loadDatabase(state, 0L); + } + /** * Sets the part input. *