Skip to content

Package: MEEditorPage$1

MEEditorPage$1

nameinstructionbranchcomplexitylinemethod
run()
M: 14 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
{...}
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2008-2011 Chair for Applied Software Engineering,
3: * Technische Universitaet Muenchen.
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: ******************************************************************************/
13: package org.eclipse.emf.ecp.editor.internal.e3;
14:
15: import org.eclipse.emf.common.notify.AdapterFactory;
16: import org.eclipse.emf.ecore.EObject;
17: import org.eclipse.emf.ecore.EStructuralFeature;
18: import org.eclipse.emf.ecp.edit.spi.DeleteService;
19: import org.eclipse.emf.ecp.editor.e3.ECPEditorContext;
20: import org.eclipse.emf.ecp.spi.ui.ECPDeleteServiceImpl;
21: import org.eclipse.emf.ecp.spi.ui.ECPReferenceServiceImpl;
22: import org.eclipse.emf.ecp.ui.view.ECPRendererException;
23: import org.eclipse.emf.ecp.ui.view.swt.ECPSWTView;
24: import org.eclipse.emf.ecp.ui.view.swt.ECPSWTViewRenderer;
25: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
26: import org.eclipse.emf.ecp.view.spi.context.ViewModelContextFactory;
27: import org.eclipse.emf.ecp.view.spi.model.VView;
28: import org.eclipse.emf.ecp.view.spi.provider.ViewProviderHelper;
29: import org.eclipse.emf.ecp.view.spi.swt.reporting.RenderingFailedReport;
30: import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
31: import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
32: import org.eclipse.jface.action.Action;
33: import org.eclipse.jface.action.ContributionManager;
34: import org.eclipse.swt.SWT;
35: import org.eclipse.swt.SWTException;
36: import org.eclipse.swt.layout.GridLayout;
37: import org.eclipse.swt.widgets.Composite;
38: import org.eclipse.ui.ISharedImages;
39: import org.eclipse.ui.PlatformUI;
40: import org.eclipse.ui.forms.IManagedForm;
41: import org.eclipse.ui.forms.editor.FormPage;
42: import org.eclipse.ui.forms.widgets.FormToolkit;
43: import org.eclipse.ui.forms.widgets.ScrolledForm;
44: import org.eclipse.ui.menus.IMenuService;
45:
46: /**
47: * The editor page for the {@link MEEditor}.
48: *
49: * @author helming
50: * @author shterev
51: * @author naughton
52: */
53: public class MEEditorPage extends FormPage {
54:
55:         private static final String TOOLBAR_ORG_ECLIPSE_EMF_ECP_EDITOR_INTERNAL_E3_ME_EDITOR_PAGE = "toolbar:org.eclipse.emf.ecp.editor.internal.e3.MEEditorPage"; //$NON-NLS-1$
56:         //
57:         private ScrolledForm form;
58:         //
59:         private final ECPEditorContext modelElementContext;
60:
61:         private ShortLabelProvider shortLabelProvider;
62:
63:         private ComposedAdapterFactory composedAdapterFactory;
64:         private ECPSWTView ecpView;
65:         private DeleteService deleteService;
66:
67:         /**
68:          * Default constructor.
69:          *
70:          * @param editor
71:          * the {@link MEEditor}
72:          * @param id
73:          * the {@link FormPage#id}
74:          * @param title
75:          * the title
76:          * @param ecpEditorContext
77:          * the {@link ECPEditorContext}
78:          * @param modelElement
79:          * the modelElement
80:          */
81:         public MEEditorPage(MEEditor editor, String id, String title, ECPEditorContext ecpEditorContext,
82:                 EObject modelElement) {
83:                 super(editor, id, title);
84:                 modelElementContext = ecpEditorContext;
85:
86:         }
87:
88:         /**
89:          * Default constructor.
90:          *
91:          * @param editor
92:          * the {@link MEEditor}
93:          * @param id
94:          * the {@link FormPage#id}
95:          * @param title
96:          * the title
97:          * @param modelElementContext
98:          * the {@link ECPEditorContext}
99:          * @param modelElement
100:          * the modelElement
101:          * @param problemFeature
102:          * the problemFeature
103:          */
104:         public MEEditorPage(MEEditor editor, String id, String title, ECPEditorContext modelElementContext,
105:                 EObject modelElement, EStructuralFeature problemFeature) {
106:                 this(editor, id, title, modelElementContext, modelElement);
107:         }
108:
109:         /**
110:          * {@inheritDoc}
111:          */
112:         @Override
113:         protected void createFormContent(IManagedForm managedForm) {
114:                 super.createFormContent(managedForm);
115:                 composedAdapterFactory = new ComposedAdapterFactory(new AdapterFactory[] {
116:                         new ReflectiveItemProviderAdapterFactory(),
117:                         new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE) });
118:                 shortLabelProvider = new ShortLabelProvider(composedAdapterFactory);
119:                 final FormToolkit toolkit = getEditor().getToolkit();
120:                 form = managedForm.getForm();
121:                 form.setShowFocusedControl(true);
122:                 toolkit.decorateFormHeading(form.getForm());
123:                 final Composite body = form.getBody();
124:                 body.setLayout(new GridLayout());
125:                 body.setBackground(body.getDisplay().getSystemColor(SWT.COLOR_WHITE));
126:                 body.setBackgroundMode(SWT.INHERIT_FORCE);
127:
128:                 final EObject domainObject = modelElementContext.getDomainObject();
129:                 final VView view = ViewProviderHelper.getView(domainObject, null);
130:                 deleteService = new ECPDeleteServiceImpl();
131:                 final ViewModelContext vmc = ViewModelContextFactory.INSTANCE.createViewModelContext(view, domainObject,
132:                         new ECPReferenceServiceImpl(), deleteService);
133:                 try {
134:                         ecpView = ECPSWTViewRenderer.INSTANCE.render(body, vmc);
135:                 } catch (final ECPRendererException ex) {
136:                         Activator.getDefault().getReportService().report(new RenderingFailedReport(ex));
137:                 }
138:
139:                 form.setImage(shortLabelProvider.getImage(modelElementContext.getDomainObject()));
140:                 createToolbar();
141:                 form.pack();
142:                 updateSectionTitle();
143:
144:         }
145:
146:         /**
147:          * Updates the name of the section.
148:          */
149:         public void updateSectionTitle() {
150:                 // Layout form
151:
152:                 String name = shortLabelProvider.getText(modelElementContext.getDomainObject());
153:
154:                 name += " [" + modelElementContext.getDomainObject().eClass().getName() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
155:                 try {
156:                         form.setText(name);
157:                 } catch (final SWTException e) {
158:                         // Catch in case editor is closed directly after change
159:                 }
160:         }
161:
162:         private void createToolbar() {
163:                 // We need to keep the cast to stay compatible (SRC) with Luna
164:                 @SuppressWarnings("cast")
165:                 final IMenuService menuService = (IMenuService) PlatformUI.getWorkbench().getService(IMenuService.class);
166:                 // sourceProvider = new AbstractSourceProvider() {
167:                 // public void dispose() {
168:                 // }
169:                 //
170:                 // @SuppressWarnings("rawtypes")
171:                 // public Map getCurrentState() {
172:                 // HashMap<Object, Object> map = new HashMap<Object, Object>();
173:                 // map.put(activeModelelement, modelElementContext.getModelElement());
174:                 // return map;
175:                 // }
176:                 //
177:                 // public String[] getProvidedSourceNames() {
178:                 // String[] namens = new String[1];
179:                 // namens[0] = activeModelelement;
180:                 // return namens;
181:                 // }
182:                 //
183:                 // };
184:                 //
185:                 // service = (IEvaluationService) PlatformUI.getWorkbench()
186:                 // .getService(IEvaluationService.class);
187:                 // service.addSourceProvider(sourceProvider);
188:
189:                 form.getToolBarManager().add(new Action("", Activator.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE)) { //$NON-NLS-1$
190:
191:                         @Override
192:                         public void run() {
193:                                 deleteService.deleteElement(modelElementContext.getDomainObject());
194:                                 MEEditorPage.this.getEditor().close(true);
195:                         }
196:                 });
197:                 menuService.populateContributionManager((ContributionManager) form.getToolBarManager(),
198:                         TOOLBAR_ORG_ECLIPSE_EMF_ECP_EDITOR_INTERNAL_E3_ME_EDITOR_PAGE);
199:                 form.getToolBarManager().update(true);
200:         }
201:
202:         /**
203:          * {@inheritDoc} This method is added to solve the focus bug of navigator. Every time that a ME is opened in editor,
204:          * navigator has to lose focus so that its action contributions are set correctly for next time.
205:          */
206:         @Override
207:         public void setFocus() {
208:                 // TODO
209:                 // editorPageContent.focus();
210:         }
211:
212:         /**
213:          * {@inheritDoc}
214:          */
215:         @Override
216:         public void dispose() {
217:                 if (ecpView != null) {
218:                         ecpView.dispose();
219:                 }
220:                 if (composedAdapterFactory != null) {
221:                         composedAdapterFactory.dispose();
222:                 }
223:                 if (shortLabelProvider != null) {
224:                         shortLabelProvider.dispose();
225:                 }
226:                 if (form != null) {
227:                         form.dispose();
228:                 }
229:                 super.dispose();
230:         }
231: }