Skip to content

Package: EditNewObjectDialog

EditNewObjectDialog

nameinstructionbranchcomplexitylinemethod
EditNewObjectDialog(Shell, EObject)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
configureShell(Shell)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
createDialogArea(Composite)
M: 12 C: 95
89%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 2 C: 20
91%
M: 0 C: 1
100%
isResizable()
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2019 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 Nuefeld - initial API and implementation, bug 551103
13: * Christian W. Damus - bug 529542
14: ******************************************************************************/
15: package org.eclipse.emf.ecp.ui.view.swt.reference;
16:
17: import org.eclipse.emf.ecore.EObject;
18: import org.eclipse.emf.ecp.ui.view.ECPRendererException;
19: import org.eclipse.emf.ecp.ui.view.swt.ECPSWTViewRenderer;
20: import org.eclipse.emf.ecp.view.internal.swt.Activator;
21: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
22: import org.eclipse.emf.ecp.view.spi.context.ViewModelContextFactory;
23: import org.eclipse.emf.ecp.view.spi.provider.ViewProviderHelper;
24: import org.eclipse.emf.ecp.view.spi.swt.reporting.RenderingFailedReport;
25: import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
26: import org.eclipse.jface.dialogs.Dialog;
27: import org.eclipse.jface.layout.GridDataFactory;
28: import org.eclipse.jface.layout.GridLayoutFactory;
29: import org.eclipse.swt.SWT;
30: import org.eclipse.swt.custom.ScrolledComposite;
31: import org.eclipse.swt.graphics.Point;
32: import org.eclipse.swt.widgets.Composite;
33: import org.eclipse.swt.widgets.Control;
34: import org.eclipse.swt.widgets.Shell;
35:
36: /** Custom dialog used for displaying a newly created EObject. */
37: class EditNewObjectDialog extends Dialog {
38:
39:         private final EObject eObject;
40:
41:         /**
42:          * Initializes me.
43:          *
44:          * @param parentshell my parent shell
45:          * @param eObject the object to present for editing
46:          */
47:         EditNewObjectDialog(Shell parentshell, EObject eObject) {
48:                 super(parentshell);
49:
50:                 this.eObject = eObject;
51:         }
52:
53:         @Override
54:         protected void configureShell(Shell shell) {
55:                 super.configureShell(shell);
56:                 shell.setText(eObject.eClass().getName());
57:         }
58:
59:         @Override
60:         protected boolean isResizable() {
61:                 return true;
62:         }
63:
64:         @Override
65:         protected Control createDialogArea(Composite parent) {
66:                 final Composite composite = (Composite) super.createDialogArea(parent);
67:                 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).hint(450, 250)
68:                         .applyTo(composite);
69:
70:                 final ScrolledComposite scrolledComposite = new ScrolledComposite(composite, SWT.H_SCROLL
71:                         | SWT.V_SCROLL);
72:                 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(scrolledComposite);
73:                 scrolledComposite.setExpandVertical(true);
74:                 scrolledComposite.setExpandHorizontal(true);
75:
76:                 final Composite content = new Composite(scrolledComposite, SWT.NONE);
77:                 GridLayoutFactory.fillDefaults().applyTo(content);
78:                 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(content);
79:
80:                 // Create a new root context. It will get the best available reference service,
81:                 // which usually is the default
82:                 final ViewModelContext vmc = ViewModelContextFactory.INSTANCE.createViewModelContext(
83:                         ViewProviderHelper.getView(eObject, null), eObject);
84:
85:•                if (AdapterFactoryEditingDomain.getEditingDomainFor(eObject).isReadOnly(eObject.eResource())) {
86:                         vmc.getViewModel().setReadonly(true);
87:                 }
88:                 try {
89:                         ECPSWTViewRenderer.INSTANCE.render(content, vmc);
90:                 } catch (final ECPRendererException ex) {
91:                         Activator.getDefault().getReportService().report(new RenderingFailedReport(ex));
92:                 }
93:
94:                 scrolledComposite.setContent(content);
95:                 final Point point = content.computeSize(SWT.DEFAULT, SWT.DEFAULT);
96:                 scrolledComposite.setMinSize(point);
97:                 scrolledComposite.layout(true);
98:
99:                 return composite;
100:         }
101:
102: }