Package: GenModelReadonlyViewModelService
GenModelReadonlyViewModelService
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
GenModelReadonlyViewModelService() |
|
|
|
|
|
||||||||||||||||||||
dispose() |
|
|
|
|
|
||||||||||||||||||||
getPriority() |
|
|
|
|
|
||||||||||||||||||||
instantiate(ViewModelContext) |
|
|
|
|
|
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: * Martin Fleck - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.internal.editor.genmodel.service;
15:
16: import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage;
17: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
18: import org.eclipse.emf.ecp.view.spi.context.ViewModelService;
19: import org.eclipse.emf.ecp.view.spi.model.VElement;
20: import org.eclipse.emf.ecp.view.spi.model.VView;
21:
22: /**
23: * This {@link ViewModelService} sets all views not related to the {@link GenModelPackage} to read-only.
24: * This avoids, for instance, that the user can make changes to the referenced Ecore model shown in the GenModel editor.
25: *
26: * @author Martin Fleck
27: *
28: */
29: public class GenModelReadonlyViewModelService implements ViewModelService {
30:
31:         /**
32:          * {@inheritDoc}
33:          *
34:          * @see org.eclipse.emf.ecp.view.spi.context.ViewModelService#instantiate(org.eclipse.emf.ecp.view.spi.context.ViewModelContext)
35:          */
36:         @Override
37:         public void instantiate(ViewModelContext context) {
38:                 final VElement viewModel = context.getViewModel();
39:•                if (!(viewModel instanceof VView)) {
40:                         return; // this service only works on views
41:                 }
42:
43:                 final VView view = (VView) viewModel;
44:•                if (!GenModelPackage.eNS_URI.equals(view.getRootEClass().getEPackage().getNsURI())) {
45:                         view.setReadonly(true);
46:                 }
47:         }
48:
49:         /**
50:          * {@inheritDoc}
51:          *
52:          * @see org.eclipse.emf.ecp.view.spi.context.ViewModelService#dispose()
53:          */
54:         @Override
55:         public void dispose() {
56:         }
57:
58:         /**
59:          * {@inheritDoc}
60:          *
61:          * @see org.eclipse.emf.ecp.view.spi.context.ViewModelService#getPriority()
62:          */
63:         @Override
64:         public int getPriority() {
65:                 return 0;
66:         }
67:
68: }