Skip to content

Package: WizardNewDataTemplateCreationPage

WizardNewDataTemplateCreationPage

nameinstructionbranchcomplexitylinemethod
WizardNewDataTemplateCreationPage(String, IStructuredSelection)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getInitialContents()
M: 18 C: 33
65%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 4 C: 8
67%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2018 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Eugen Neufeld - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.internal.datatemplate.tooling.wizard;
15:
16: import java.io.ByteArrayInputStream;
17: import java.io.ByteArrayOutputStream;
18: import java.io.IOException;
19: import java.io.InputStream;
20:
21: import org.eclipse.core.runtime.IStatus;
22: import org.eclipse.core.runtime.Platform;
23: import org.eclipse.core.runtime.Status;
24: import org.eclipse.emf.common.util.URI;
25: import org.eclipse.emf.ecore.resource.Resource;
26: import org.eclipse.emf.ecore.resource.ResourceSet;
27: import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
28: import org.eclipse.emfforms.datatemplate.DataTemplateFactory;
29: import org.eclipse.emfforms.datatemplate.TemplateCollection;
30: import org.eclipse.jface.viewers.IStructuredSelection;
31: import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
32: import org.osgi.framework.Bundle;
33: import org.osgi.framework.FrameworkUtil;
34:
35: /**
36: * The WizardNewFileCreationPage to create a new DataTemplate.
37: *
38: * @author Eugen Neufeld
39: *
40: */
41: public class WizardNewDataTemplateCreationPage extends WizardNewFileCreationPage {
42:
43:         /**
44:          * Default Constructor.
45:          *
46:          * @param pageName The name of the page
47:          * @param selection The initial selection
48:          */
49:         public WizardNewDataTemplateCreationPage(String pageName, IStructuredSelection selection) {
50:                 super(pageName, selection);
51:                 setFileExtension("datatemplate"); //$NON-NLS-1$
52:         }
53:
54:         @Override
55:         protected InputStream getInitialContents() {
56:                 try {
57:                         final TemplateCollection collection = DataTemplateFactory.eINSTANCE.createTemplateCollection();
58:                         final ResourceSet rs = new ResourceSetImpl();
59:                         final Resource r = rs.createResource(URI.createURI("VIRTUAL")); //$NON-NLS-1$
60:                         r.getContents().add(collection);
61:                         final ByteArrayOutputStream bos = new ByteArrayOutputStream();
62:                         r.save(bos, null);
63:                         final ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
64:                         return bis;
65:                 } catch (final IOException ex) {
66:                         // should not happen
67:                         final Bundle bundle = FrameworkUtil.getBundle(WizardNewDataTemplateCreationPage.class);
68:                         Platform.getLog(bundle).log(new Status(IStatus.ERROR, bundle.getSymbolicName(), ex.getMessage(), ex));
69:                 }
70:                 return null;
71:         }
72:
73: }