Skip to content

Package: DetailDialog

DetailDialog

nameinstructionbranchcomplexitylinemethod
DetailDialog(Shell, EObject, VTableControl, VView)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
close()
M: 19 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
createButtonsForButtonBar(Composite)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
createDialogArea(Composite)
M: 117 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 27 C: 0
0%
M: 1 C: 0
0%
getDefaultText(EObject)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getInitialSize()
M: 33 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
init()
M: 28 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
isResizable()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
updateTitle()
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2014 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 - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.spi.table.swt;
15:
16: import org.eclipse.emf.common.notify.Adapter;
17: import org.eclipse.emf.common.notify.AdapterFactory;
18: import org.eclipse.emf.common.notify.Notification;
19: import org.eclipse.emf.common.notify.impl.AdapterImpl;
20: import org.eclipse.emf.ecore.EObject;
21: import org.eclipse.emf.ecp.ui.view.ECPRendererException;
22: import org.eclipse.emf.ecp.ui.view.swt.ECPSWTViewRenderer;
23: import org.eclipse.emf.ecp.view.internal.table.swt.Activator;
24: import org.eclipse.emf.ecp.view.spi.model.VView;
25: import org.eclipse.emf.ecp.view.spi.table.model.VTableControl;
26: import org.eclipse.emf.edit.provider.AdapterFactoryItemDelegator;
27: import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
28: import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
29: import org.eclipse.jface.dialogs.Dialog;
30: import org.eclipse.jface.dialogs.IDialogConstants;
31: import org.eclipse.jface.layout.GridDataFactory;
32: import org.eclipse.jface.layout.GridLayoutFactory;
33: import org.eclipse.swt.SWT;
34: import org.eclipse.swt.custom.ScrolledComposite;
35: import org.eclipse.swt.graphics.Point;
36: import org.eclipse.swt.layout.GridData;
37: import org.eclipse.swt.widgets.Composite;
38: import org.eclipse.swt.widgets.Control;
39: import org.eclipse.swt.widgets.Shell;
40:
41: /**
42: * A dialog allowing to edit an {@link EObject}.
43: *
44: * @author Eugen Neufeld
45: *
46: */
47: public class DetailDialog extends Dialog {
48:
49:         private final EObject selection;
50:         private Adapter objectChangeAdapter;
51:         private ComposedAdapterFactory composedAdapterFactory;
52:         private AdapterFactoryItemDelegator adapterFactoryItemDelegator;
53:         private final VView view;
54:
55:         /**
56:          * Creates a dialog allowing to edit an {@link EObject}.
57:          *
58:          * @param parentShell the {@link Shell} to use in the dialog
59:          * @param selection the {@link EObject} to edit
60:          * @param tableControl the {@link VTableControl}
61:          * @param view the view model for the detail dialog. May <b>not</b> be <code>null</code>.
62:          * @since 1.5
63:          */
64:         public DetailDialog(Shell parentShell, EObject selection, VTableControl tableControl, VView view) {
65:                 super(parentShell);
66:                 this.selection = selection;
67:                 this.view = view;
68:                 init();
69:         }
70:
71:         @Override
72:         protected boolean isResizable() {
73:                 return true;
74:         }
75:
76:         private void init() {
77:                 composedAdapterFactory = new ComposedAdapterFactory(new AdapterFactory[] {
78:                         new ReflectiveItemProviderAdapterFactory(),
79:                         new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE) });
80:                 adapterFactoryItemDelegator = new AdapterFactoryItemDelegator(
81:                         composedAdapterFactory);
82:         }
83:
84:         /**
85:          * {@inheritDoc}
86:          *
87:          * @see org.eclipse.jface.dialogs.Dialog#getInitialSize()
88:          */
89:         @Override
90:         protected Point getInitialSize() {
91:                 final Point p = super.getInitialSize();
92:                 int height = p.y;
93:                 int width = p.x;
94:•                if (height > 800) {
95:                         height = Math.round(height / 1.5f);
96:                 }
97:•                if (width < 600) {
98:                         width = Math.round(width * 1.5f);
99:                 }
100:                 return new Point(width, height);
101:         }
102:
103:         @Override
104:         protected Control createDialogArea(Composite parent) {
105:                 updateTitle();
106:                 final Composite composite = (Composite) super.createDialogArea(parent);
107:                 composite.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE));
108:                 final ScrolledComposite scrolledComposite = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL);
109:                 scrolledComposite.setBackground(composite.getBackground());
110:                 scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
111:                 scrolledComposite.setExpandVertical(true);
112:                 scrolledComposite.setExpandHorizontal(true);
113:
114:                 final Composite content = new Composite(scrolledComposite, SWT.NONE);
115:                 content.setBackground(composite.getBackground());
116:                 GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(false).applyTo(content);
117:                 GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(content);
118:
119:                 try {
120:•                        if (view == null) {
121:                                 ECPSWTViewRenderer.INSTANCE.render(content,
122:                                         selection);
123:                         } else {
124:                                 ECPSWTViewRenderer.INSTANCE.render(content,
125:                                         selection, view);
126:                         }
127:                 } catch (final ECPRendererException ex) {
128:                         Activator.getInstance().log(ex);
129:                 }
130:
131:                 scrolledComposite.setContent(content);
132:                 final Point point = content.computeSize(SWT.DEFAULT, SWT.DEFAULT);
133:                 content.setSize(point);
134:                 scrolledComposite.setMinSize(point);
135:
136:                 objectChangeAdapter = new AdapterImpl() {
137:
138:                         /**
139:                          * {@inheritDoc}
140:                          *
141:                          * @see org.eclipse.emf.common.notify.impl.AdapterImpl#notifyChanged(org.eclipse.emf.common.notify.Notification)
142:                          */
143:                         @Override
144:                         public void notifyChanged(Notification msg) {
145:                                 super.notifyChanged(msg);
146:                                 updateTitle();
147:                         }
148:
149:                 };
150:                 selection.eAdapters().add(objectChangeAdapter);
151:
152:                 return composite;
153:         }
154:
155:         private void updateTitle() {
156:                 getShell().setText(
157:                         getDefaultText(selection));
158:         }
159:
160:         @Override
161:         protected void createButtonsForButtonBar(Composite parent) {
162:                 createButton(parent, IDialogConstants.OK_ID, "OK", //$NON-NLS-1$
163:                         true);
164:         }
165:
166:         private String getDefaultText(EObject eObject) {
167:                 return adapterFactoryItemDelegator.getText(eObject);
168:         }
169:
170:         /**
171:          * {@inheritDoc}
172:          *
173:          * @see org.eclipse.jface.dialogs.Dialog#close()
174:          */
175:         @Override
176:         public boolean close() {
177:•                if (objectChangeAdapter != null) {
178:                         selection.eAdapters().remove(objectChangeAdapter);
179:                 }
180:•                if (composedAdapterFactory != null) {
181:                         composedAdapterFactory.dispose();
182:                 }
183:                 return super.close();
184:         }
185:
186: }