Skip to content

Commit

Permalink
[2177] Disable editing of properties for a lib with read-only access
Browse files Browse the repository at this point in the history
Bug 2177

Conflicts:
	core/plugins/org.polarsys.capella.core.model.handler/META-INF/MANIFEST.MF

Change-Id: I4cea31a10d06f85fd7db6603d9d471222931d001
Signed-off-by: Ali Akar <ali.akar82@gmail.com>
  • Loading branch information
aliakar82 authored and pdulth committed Sep 12, 2018
1 parent 70e4459 commit 1942417
Show file tree
Hide file tree
Showing 8 changed files with 296 additions and 152 deletions.
Expand Up @@ -13,8 +13,7 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.emf.transaction,
org.polarsys.capella.common.libraries.gen;visibility:=reexport,
org.polarsys.capella.common.queries,
org.polarsys.capella.common.tools.report,
org.polarsys.capella.core.model.handler
org.polarsys.capella.common.tools.report
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Export-Package: org.polarsys.capella.common.libraries,
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2017 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2018 THALES GLOBAL SERVICES.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -22,12 +22,13 @@
import org.eclipse.emf.transaction.ResourceSetListenerImpl;
import org.eclipse.emf.transaction.RollbackException;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.sirius.viewpoint.DRefreshable;
import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
import org.polarsys.capella.common.libraries.AccessPolicy;
import org.polarsys.capella.common.libraries.Activator;
import org.polarsys.capella.common.libraries.ILibraryManager;
import org.polarsys.capella.common.libraries.IModel;
import org.polarsys.capella.common.tools.report.util.IReportManagerDefaultComponents;
import org.polarsys.capella.core.model.handler.command.CapellaResourceHelper;

/**
*/
Expand All @@ -40,29 +41,34 @@ public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws Rol
// Retrieve the model linked to the editing domain
IModel sourceModel = ILibraryManager.INSTANCE.getModel(domain);

HashSet<IModel> modifiedModels = new HashSet<IModel>();
HashSet<IModel> modifiedModels = new HashSet<>();

// for all notifications, if there is one which can't be modified, we rollback
for (Notification notification : event.getNotifications()) {
Object notifier = notification.getNotifier();

// Look only at semantic elements, not Diagram elements since Diagram elements are not shared by the library
if (CapellaResourceHelper.isSemanticElement(notifier)) {
if (isSemanticElement(notifier)) {
IModel model = ILibraryManager.INSTANCE.getModel((EObject) notifier);
if (model != null) {
if (!modifiedModels.contains(model)) {
if (sourceModel.getAccess(model) == AccessPolicy.READ_ONLY) {
if (!modifiedModels.contains(model) && sourceModel.getAccess(model) == AccessPolicy.READ_ONLY) {
Logger.getLogger(IReportManagerDefaultComponents.MODEL)
.error(Messages.ResourceAccessPolicyListener_RollbackReadOnly);
throw new RollbackException(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
Messages.ResourceAccessPolicyListener_RollbackReadOnly));
}
}
modifiedModels.add(model);
}
}
}
return null;
}

private boolean isSemanticElement(Object object) {
return (object instanceof EObject) && !isSiriusElement(object);
}

private static boolean isSiriusElement(Object object) {
return (object instanceof DRefreshable) || (object instanceof DRepresentationDescriptor);
}
}
8 changes: 6 additions & 2 deletions core/plugins/org.polarsys.capella.core.libraries/plugin.xml
Expand Up @@ -90,6 +90,10 @@
class="org.polarsys.capella.core.libraries.provider.LibrariesDerivedSemanticResourceProvider">
</derivedSemanticResourceProvider>
</extension>


<extension
point="org.polarsys.capella.core.model.handler.readOnlySectionHandler">
<readOnlySectionHandler
class="org.polarsys.capella.core.libraries.provider.LibAwareReadOnlySectionHandler">
</readOnlySectionHandler>
</extension>
</plugin>
@@ -0,0 +1,57 @@
/*******************************************************************************
* Copyright (c) 2018 THALES GLOBAL SERVICES.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Thales - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.core.libraries.provider;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.util.TransactionUtil;
import org.polarsys.capella.common.libraries.AccessPolicy;
import org.polarsys.capella.common.libraries.ILibraryManager;
import org.polarsys.capella.common.libraries.IModel;
import org.polarsys.capella.core.model.handler.provider.IReadOnlyListener;
import org.polarsys.capella.core.model.handler.provider.IReadOnlySectionHandler;

/**
* This implementation of the {@link IReadOnlySectionHandler} is aware about access policy of elements inside libraries.
* It's contributed to disable sections for elements of with read-only access policy.
*
*/
public class LibAwareReadOnlySectionHandler implements IReadOnlySectionHandler {

@Override
public void register(EObject semanticElement, IReadOnlyListener listener) {
// Do nothing
}

@Override
public void unregister(EObject semanticElement, IReadOnlyListener listener) {
// Do nothing
}

@Override
public boolean isLockedByOthers(EObject semanticElement) {
TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(semanticElement);
if(domain != null) {
return isLockedByOthers(ILibraryManager.INSTANCE.getModel(domain), ILibraryManager.INSTANCE.getModel(semanticElement));
}
return false;
}

private boolean isLockedByOthers(IModel domainModel, IModel elementModel) {
return domainModel != null && elementModel != null ? domainModel.getAccess(elementModel) == AccessPolicy.READ_ONLY : false;
}

@Override
public boolean isControllable(EObject semanticElement) {
TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(semanticElement);
return domain != null ? domain.isControllable(semanticElement) : false;
}
}
Expand Up @@ -12,7 +12,7 @@ Require-Bundle: com.google.guava,
org.polarsys.capella.core.data.gen;visibility:=reexport,
org.polarsys.capella.core.data.gen.edit,
org.polarsys.kitalpha.ad.metadata.model.edit,
org.polarsys.capella.common.libraries.gen,
org.polarsys.capella.common.libraries,
org.eclipse.sirius
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Expand Down
@@ -1,118 +1,117 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.polarsys.capella.core.model.handler" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="org.polarsys.capella.core.model.handler" id="readOnlySectionHandler" name="Read Only Section Handler"/>
</appInfo>
<documentation>
Read Only section handler.
This extension mustbe contributed only once.
</documentation>
</annotation>

<element name="extension">
<annotation>
<appInfo>
<meta.element />
</appInfo>
</annotation>
<complexType>
<sequence>
<element ref="readOnlySectionHandler"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>

</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>

<element name="readOnlySectionHandler">
<complexType>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
Must be contributed only once.
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn=":org.polarsys.capella.core.model.handler.provider.IReadOnlySectionHandler"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>

<annotation>
<appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>

<annotation>
<appInfo>
<meta.section type="examples"/>
</appInfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>

<annotation>
<appInfo>
<meta.section type="apiinfo"/>
</appInfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>

<annotation>
<appInfo>
<meta.section type="implementation"/>
</appInfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>

<annotation>
<appInfo>
<meta.section type="copyright"/>
</appInfo>
<documentation>
Copyright (c) 2006, 2014 THALES GLOBAL SERVICES.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html

Contributors:
Thales - initial API and implementation
</documentation>
</annotation>

</schema>
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.polarsys.capella.core.model.handler" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="org.polarsys.capella.core.model.handler" id="readOnlySectionHandler" name="Read Only Section Handler"/>
</appInfo>
<documentation>
Read Only section handler.
</documentation>
</annotation>

<element name="extension">
<annotation>
<appInfo>
<meta.element />
</appInfo>
</annotation>
<complexType>
<sequence>
<element ref="readOnlySectionHandler"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>

</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>

<element name="readOnlySectionHandler">
<complexType>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
Must be contributed only once.
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn=":org.polarsys.capella.core.model.handler.provider.IReadOnlySectionHandler"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>

<annotation>
<appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>

<annotation>
<appInfo>
<meta.section type="examples"/>
</appInfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>

<annotation>
<appInfo>
<meta.section type="apiinfo"/>
</appInfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>

<annotation>
<appInfo>
<meta.section type="implementation"/>
</appInfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>

<annotation>
<appInfo>
<meta.section type="copyright"/>
</appInfo>
<documentation>
Copyright (c) 2006, 2014 THALES GLOBAL SERVICES.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html

Contributors:
Thales - initial API and implementation
</documentation>
</annotation>

</schema>

0 comments on commit 1942417

Please sign in to comment.