fix CLI invocation (at least on MacOS)

This commit is contained in:
Eyck Jentzsch 2020-11-29 14:06:33 +01:00
parent 70ccf35fe4
commit 4d8e7a3cd1
2 changed files with 26 additions and 16 deletions

View File

@ -13,6 +13,7 @@ package com.minres.scviewer.e4.application;
import java.io.IOException; import java.io.IOException;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.contexts.IEclipseContext;
@ -30,8 +31,10 @@ import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState; import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
import org.eclipse.equinox.app.IApplicationContext; import org.eclipse.equinox.app.IApplicationContext;
import org.eclipse.osgi.service.datalocation.Location; import org.eclipse.osgi.service.datalocation.Location;
import org.eclipse.swt.widgets.Display;
import org.osgi.service.event.Event; import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler; import org.osgi.service.event.EventHandler;
import org.eclipse.e4.core.services.log.Logger;
import com.minres.scviewer.e4.application.options.Options; import com.minres.scviewer.e4.application.options.Options;
import com.minres.scviewer.e4.application.options.Options.Multiplicity; import com.minres.scviewer.e4.application.options.Options.Multiplicity;
@ -45,6 +48,8 @@ import com.minres.scviewer.e4.application.options.Options.Separator;
**/ **/
public class E4LifeCycle { public class E4LifeCycle {
@Inject private Logger logger;
/** /**
* Post construct. * Post construct.
* *
@ -70,10 +75,9 @@ public class E4LifeCycle {
.addOption("clearPersistedState", Multiplicity.ZERO_OR_ONE) .addOption("clearPersistedState", Multiplicity.ZERO_OR_ONE)
.addOption("c", Separator.BLANK, Multiplicity.ZERO_OR_ONE); .addOption("c", Separator.BLANK, Multiplicity.ZERO_OR_ONE);
if (!opt.check(Options.DEFAULT_SET, true, false)) { if (!opt.check(Options.DEFAULT_SET, true, false)) {
System.err.println(opt.getCheckErrors()); logger.error(opt.getCheckErrors());
System.exit(1); System.exit(1);
} }
final String confFile =opt.getSet().isSet("c")?opt.getSet().getOption("c").getResultValue(0):"";
eventBroker.subscribe(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE, new EventHandler() { eventBroker.subscribe(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE, new EventHandler() {
@Override @Override
@ -84,7 +88,8 @@ public class E4LifeCycle {
if(isLocked) if(isLocked)
instanceLocation.release(); instanceLocation.release();
} catch (IOException e) { } } catch (IOException e) { }
if(opt.getSet().getData().size()>0) { if(!opt.getSet().getData().isEmpty()) {
Display.getCurrent().timerExec (100, () -> {
MApplication app= workbenchContext.get(MApplication.class); MApplication app= workbenchContext.get(MApplication.class);
EModelService modelService = workbenchContext.get(EModelService.class); EModelService modelService = workbenchContext.get(EModelService.class);
EPartService partService= workbenchContext.get(EPartService.class); EPartService partService= workbenchContext.get(EPartService.class);
@ -96,7 +101,9 @@ public class E4LifeCycle {
partService.showPart(part, PartState.ACTIVATE); partService.showPart(part, PartState.ACTIVATE);
IEclipseContext ctx = part.getContext(); IEclipseContext ctx = part.getContext();
ctx.modify("input", opt.getSet().getData()); ctx.modify("input", opt.getSet().getData());
String confFile =opt.getSet().isSet("c")?opt.getSet().getOption("c").getResultValue(0):"";
ctx.modify("config", confFile); //$NON-NLS-1$ ctx.modify("config", confFile); //$NON-NLS-1$
});
} }
} }
}); });
@ -109,6 +116,7 @@ public class E4LifeCycle {
*/ */
@PreSave @PreSave
void preSave(IEclipseContext workbenchContext) { void preSave(IEclipseContext workbenchContext) {
/* nothing to be done here */
} }
/** /**
@ -118,6 +126,7 @@ public class E4LifeCycle {
*/ */
@ProcessAdditions @ProcessAdditions
void processAdditions(IEclipseContext workbenchContext) { void processAdditions(IEclipseContext workbenchContext) {
/* nothing to be done here */
} }
/** /**
@ -127,5 +136,6 @@ public class E4LifeCycle {
*/ */
@ProcessRemovals @ProcessRemovals
void processRemovals(IEclipseContext workbenchContext) { void processRemovals(IEclipseContext workbenchContext) {
/* nothing to be done here */
} }
} }

View File

@ -22,7 +22,7 @@ import org.eclipse.e4.ui.workbench.modeling.EPartService;
*/ */
@SuppressWarnings("restriction") @SuppressWarnings("restriction")
public class ThemeSetHandler { public class ThemeSetHandler {
final static String PARAMTER_ID = "com.minres.scviewer.e4.application.command.theme.parameter.id"; //$NON-NLS-1$ static final String PARAMTER_ID = "com.minres.scviewer.e4.application.command.theme.parameter.id"; //$NON-NLS-1$
@CanExecute @CanExecute
public boolean canExecute(EPartService partService) { public boolean canExecute(EPartService partService) {