OpenHandler.java 1.03 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package de.hftstuttgart.buildingphysics.application.handlers;

import javax.inject.Named;

import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.swt.widgets.Shell;


public class OpenHandler {
	@Execute
	public void execute(MApplication application, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
			EPartService partService) {

		final String pathToCatalog = HandlerUtils.openFileDialog(shell);

		if (pathToCatalog != null) {
			final AdapterFactoryEditingDomain domain = HandlerUtils.createEditingDomain();
			System.out.println("Open catalog: " + pathToCatalog);
			final Resource catalogResource = domain.loadResource("file://" + pathToCatalog);
			HandlerUtils.createNewPartWithCatalog(application.getContext(), partService, catalogResource);
		}
	}
}