blob: 44a0fdb30cce29d2c0244989f2ab4630b7487511 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2011-2016 EclipseSource Muenchen GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Martin Fleck - initial API and implementation
******************************************************************************/
package org.eclipse.emfforms.internal.editor.genmodel.service;
import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage;
import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
import org.eclipse.emf.ecp.view.spi.context.ViewModelService;
import org.eclipse.emf.ecp.view.spi.model.VElement;
import org.eclipse.emf.ecp.view.spi.model.VView;
/**
* This {@link ViewModelService} sets all views not related to the {@link GenModelPackage} to read-only.
* This avoids, for instance, that the user can make changes to the referenced Ecore model shown in the GenModel editor.
*
* @author Martin Fleck
*
*/
public class GenModelReadonlyViewModelService implements ViewModelService {
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.ecp.view.spi.context.ViewModelService#instantiate(org.eclipse.emf.ecp.view.spi.context.ViewModelContext)
*/
@Override
public void instantiate(ViewModelContext context) {
final VElement viewModel = context.getViewModel();
if (!(viewModel instanceof VView)) {
return; // this service only works on views
}
final VView view = (VView) viewModel;
if (!GenModelPackage.eNS_URI.equals(view.getRootEClass().getEPackage().getNsURI())) {
view.setReadonly(true);
}
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.ecp.view.spi.context.ViewModelService#dispose()
*/
@Override
public void dispose() {
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.ecp.view.spi.context.ViewModelService#getPriority()
*/
@Override
public int getPriority() {
return 0;
}
}