Skip to content

Package: RuleRepositoryEditor

RuleRepositoryEditor

nameinstructionbranchcomplexitylinemethod
RuleRepositoryEditor()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
dispose()
M: 46 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
getToolbarActions()
M: 22 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
loadResource(IEditorInput)
M: 28 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
registerEcore(ResourceSet)
M: 45 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2016 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.rulerepository.tooling;
15:
16: import java.io.IOException;
17: import java.util.LinkedList;
18: import java.util.List;
19:
20: import org.eclipse.core.runtime.IStatus;
21: import org.eclipse.core.runtime.Status;
22: import org.eclipse.emf.ecore.resource.Resource;
23: import org.eclipse.emf.ecore.resource.ResourceSet;
24: import org.eclipse.emf.ecore.util.EcoreUtil;
25: import org.eclipse.emf.ecp.ide.spi.util.EcoreHelper;
26: import org.eclipse.emf.ecp.ide.spi.util.ViewModelHelper;
27: import org.eclipse.emf.ecp.view.spi.model.VView;
28: import org.eclipse.emf.ecp.view.spi.model.reporting.StatusReport;
29: import org.eclipse.emfforms.internal.editor.Activator;
30: import org.eclipse.emfforms.internal.editor.toolbaractions.LoadEcoreAction;
31: import org.eclipse.emfforms.spi.editor.GenericEditor;
32: import org.eclipse.jface.action.Action;
33: import org.eclipse.ui.IEditorInput;
34: import org.eclipse.ui.PartInitException;
35:
36: /**
37: * RuleRepositoryEditor.
38: *
39: * @author Eugen Neufeld
40: *
41: */
42: @SuppressWarnings("restriction")
43: public class RuleRepositoryEditor extends GenericEditor {
44:
45:         /**
46:          * Returns the toolbar actions for this editor.
47:          *
48:          * @return A list of actions to show in the Editor's Toolbar
49:          */
50:         @Override
51:         protected List<Action> getToolbarActions() {
52:                 final List<Action> result = new LinkedList<>();
53:•                if (!isEditable(getEditorInput())) {
54:                         // If the input isn't editable, toolbar actions shouldn't be available
55:                         return result;
56:                 }
57:
58:                 result.add(new LoadEcoreAction(getResourceSet(), "Load ViewModel")); //$NON-NLS-1$
59:
60:                 // result.addAll(readToolbarActions());
61:                 return result;
62:         }
63:
64:         private void registerEcore(ResourceSet resourceSet) throws IOException {
65:•                for (final Resource resource : resourceSet.getResources()) {
66:•                        if (resource.getContents().isEmpty()) {
67:                                 continue;
68:                         }
69:•                        if (!VView.class.isInstance(resource.getContents().get(0))) {
70:                                 continue;
71:                         }
72:•                        for (final String ecorePath : ViewModelHelper.getEcorePaths(resource)) {
73:•                                if (ecorePath == null) {
74:                                         return;
75:                                 }
76:                                 EcoreHelper.registerEcore(ecorePath);
77:                         }
78:                 }
79:                 // resolve all proxies
80:                 EcoreUtil.resolveAll(resourceSet);
81:         }
82:
83:         @Override
84:         protected ResourceSet loadResource(IEditorInput editorInput) {
85:                 try {
86:                         final ResourceSet result = super.loadResource(editorInput);
87:                         registerEcore(result);
88:                         return super.loadResource(editorInput);
89:                 } catch (final IOException | PartInitException ex) {
90:                         Activator.getDefault().getReportService().report(
91:                                 new StatusReport(new Status(IStatus.ERROR, Activator.PLUGIN_ID, ex.getMessage(), ex)));
92:                 }
93:                 return null;
94:         }
95:
96:         @Override
97:         public void dispose() {
98:•                for (final Resource resource : getResourceSet().getResources()) {
99:•                        if (resource.getContents().isEmpty()) {
100:                                 continue;
101:                         }
102:•                        if (!VView.class.isInstance(resource.getContents().get(0))) {
103:                                 continue;
104:                         }
105:•                        for (final String ecorePath : ViewModelHelper.getEcorePaths(resource)) {
106:•                                if (ecorePath == null) {
107:                                         return;
108:                                 }
109:                                 EcoreHelper.unregisterEcore(ecorePath);
110:                         }
111:                 }
112:                 super.dispose();
113:         }
114: }