| /** |
| * Copyright (c) 2011-2014 EclipseSource Muenchen GmbH and others. |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * EclipseSource Munich - initial API and implementation |
| */ |
| package org.eclipse.emf.ecp.makeithappen.application.sample.e4.parts; |
| |
| import javax.annotation.PostConstruct; |
| |
| import org.eclipse.emf.ecore.EClass; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.emf.ecore.util.EcoreUtil; |
| import org.eclipse.emf.ecp.makeithappen.model.task.TaskPackage; |
| 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; |
| |
| /** |
| * Example Part for displaying a Forms Editor for an EObject. |
| */ |
| public class SamplePart { |
| |
| private EObject getDummyEObject() { |
| // Replace this with your own model EClass to test the application with a custom model |
| final EClass eClass = TaskPackage.eINSTANCE.getUser(); |
| return EcoreUtil.create(eClass); |
| } |
| |
| /** |
| * Render the editor. |
| * |
| * @param parent the {@link Composite} to render to |
| */ |
| @PostConstruct |
| public void createComposite(Composite parent) { |
| final EObject dummyObject = getDummyEObject(); |
| 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, dummyObject); |
| content.layout(); |
| } catch (final ECPRendererException e) { |
| e.printStackTrace(); |
| } |
| parent.layout(); |
| } |
| } |