2015-10-22 00:05:29 +02:00
|
|
|
/*******************************************************************************
|
2015-10-22 00:25:12 +02:00
|
|
|
* Copyright (c) 2015 MINRES Technologies GmbH and others.
|
2015-10-22 00:05:29 +02:00
|
|
|
* 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:
|
2015-10-22 00:25:12 +02:00
|
|
|
* MINRES Technologies GmbH - initial API and implementation
|
2015-10-22 00:05:29 +02:00
|
|
|
*******************************************************************************/
|
|
|
|
package com.minres.scviewer.e4.application.handlers;
|
|
|
|
|
|
|
|
import java.io.File;
|
2020-03-29 15:14:02 +02:00
|
|
|
import java.util.List;
|
2015-10-22 00:05:29 +02:00
|
|
|
|
|
|
|
import org.eclipse.e4.core.contexts.IEclipseContext;
|
|
|
|
import org.eclipse.e4.core.di.annotations.Execute;
|
|
|
|
import org.eclipse.e4.ui.model.application.MApplication;
|
|
|
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
|
|
|
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
|
|
|
|
import org.eclipse.e4.ui.workbench.modeling.EModelService;
|
|
|
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
|
|
|
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
|
2020-03-29 15:14:02 +02:00
|
|
|
import org.eclipse.jface.window.Window;
|
2015-10-22 00:05:29 +02:00
|
|
|
import org.eclipse.swt.widgets.Shell;
|
2017-01-23 22:53:14 +01:00
|
|
|
|
|
|
|
import com.minres.scviewer.e4.application.Messages;
|
2020-03-29 15:14:02 +02:00
|
|
|
import com.minres.scviewer.e4.application.parts.FileBrowserDialog;
|
2015-10-22 00:05:29 +02:00
|
|
|
public class OpenHandler {
|
|
|
|
|
|
|
|
@Execute
|
|
|
|
public void execute(Shell shell, MApplication app, EModelService modelService, EPartService partService){
|
2020-03-29 15:14:02 +02:00
|
|
|
FileBrowserDialog dlg = new FileBrowserDialog(shell);
|
2020-03-30 11:31:51 +02:00
|
|
|
//dlg.create();
|
2020-03-29 17:15:41 +02:00
|
|
|
dlg.setFilterExtensions (new String []{Messages.OpenHandler_0, "*"});
|
2020-03-29 15:14:02 +02:00
|
|
|
if (dlg.open() != Window.OK) return;
|
|
|
|
List<File> files = dlg.getSelectedFiles();
|
2020-03-17 12:54:38 +01:00
|
|
|
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$
|
2015-10-22 00:05:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|