CatalogPart.java 1.5 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package de.hftstuttgart.buildingphysics.application.parts;

import java.io.IOException;

import javax.annotation.PostConstruct;

import org.eclipse.e4.ui.di.Persist;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecp.ui.view.ECPRendererException;
import org.eclipse.emf.ecp.ui.view.swt.ECPSWTViewRenderer;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;

/**
 * Part for displaying a Forms Editor for a Building Physics Catalog.
 */
public class CatalogPart {
	private Resource catalogResource;
	
	@PostConstruct
	public void createComposite(MApplication application, Composite parent) {
		catalogResource = application.getContext().get(Resource.class);
		EObject energyCatalog = catalogResource.getContents().get(0);
		try {
			final Composite content = new Composite(parent, SWT.NONE);
			content.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
			content.setLayout(GridLayoutFactory.fillDefaults().margins(10, 10).create());
			ECPSWTViewRenderer.INSTANCE.render(content, energyCatalog);
			content.layout();
		} catch (final ECPRendererException e) {
			e.printStackTrace();
		}
		parent.layout();
	}
	
	@Persist
	public void save() {
		System.out.println("Saved " + catalogResource);
		try {
			catalogResource.save(null);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}