Skip to content
Snippets Groups Projects
Commit 99dd186b authored by Vincent Aravantinos's avatar Vincent Aravantinos
Browse files

new form of contracts

refs 2334
parent 5285bd4d
No related branches found
No related tags found
No related merge requests found
Showing
with 623 additions and 0 deletions
org.fortiss.tooling.kernel.ui/trunk/icons/constraintErrorOverlay.png

559 B

org.fortiss.tooling.kernel.ui/trunk/icons/constraintFailOverlay.png

872 B

org.fortiss.tooling.kernel.ui/trunk/icons/constraintOutdatedOverlay.png

612 B

......@@ -6,6 +6,7 @@
<extension-point id="editPartFactory" name="Edit Part Factory" schema="schema/editPartFactory.exsd"/>
<extension-point id="contextMenuContribution" name="Context Menu Contribution" schema="schema/contextMenuContribution.exsd"/>
<extension-point id="allocationEditPartFactory" name="Allocation Edit Part Factory" schema="schema/allocationEditPartFactory.exsd"/>
<extension-point id="constraintVerifierUI" name="Constraint Verifier UI" schema="schema/constraintVerifierUI.exsd"/>
<extension
point="org.eclipse.ui.editors">
<editor
......@@ -124,6 +125,19 @@
</objectClass>
</enablement>
</decorator>
<decorator
class="org.fortiss.tooling.kernel.ui.internal.ConstraintLabelDecorator"
id="org.fortiss.tooling.kernel.ui.internal.ConstraintLabelDecorator"
label="Constraint Decorator"
lightweight="true"
location="TOP_LEFT"
state="true">
<enablement>
<objectClass
name="org.fortiss.tooling.kernel.model.constraints.IConstrained">
</objectClass>
</enablement>
</decorator>
</extension>
<extension
point="org.fortiss.tooling.kernel.ui.contextMenuContribution">
......
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.fortiss.tooling.kernel.ui" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="org.fortiss.tooling.kernel.ui" id="constraintVerifierUI" name="Constraint Verifier UI"/>
</appinfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>
<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<sequence>
<element ref="constraintVerifierUI" minOccurs="1" maxOccurs="unbounded"/>
</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="constraintVerifierUI">
<complexType>
<sequence minOccurs="1" maxOccurs="unbounded">
<element ref="constraint" minOccurs="1" maxOccurs="unbounded"/>
</sequence>
<attribute name="constraintVerifierUI" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.fortiss.tooling.kernel.ui.extension.IConstraintVerifierUI"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="constraint">
<complexType>
<attribute name="constraint" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.fortiss.tooling.kernel.model.constraints.IConstraint"/>
</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>
</schema>
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2015 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.extension;
import org.fortiss.tooling.kernel.model.constraints.IConstraint;
import org.fortiss.tooling.kernel.model.constraints.IConstraintVerificationStatus;
import org.fortiss.tooling.kernel.service.base.IEObjectAware;
/**
* Interface for the GUI of constraint verifiers.
*
* @author aravantinos
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 011835D3C52A01134B1FCA85229D6859
*/
public interface IConstraintVerifierUI<T extends IConstraint> extends IEObjectAware<T> {
/**
* Action to take when trying to open the given status. <code>canOpen</code> should be called
* before to know if the status can be opened.
*
* @return true if the status could indeed be open, false if it needs further handling.
*/
public boolean openStatus(IConstraintVerificationStatus status);
/** True if the given status can be open. */
public boolean canOpen(IConstraintVerificationStatus status);
/**
* @param status
* @return a short user-friendly description explaining the status.
*/
public String getMessage(IConstraintVerificationStatus status);
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2016 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.internal;
import org.eclipse.jface.viewers.BaseLabelProvider;
import org.eclipse.jface.viewers.IDecoration;
import org.eclipse.jface.viewers.ILightweightLabelDecorator;
import org.fortiss.tooling.kernel.model.constraints.IConstrained;
import org.fortiss.tooling.kernel.ui.ToolingKernelUIActivator;
import org.fortiss.tooling.kernel.ui.service.IMarkerService;
import org.fortiss.tooling.kernel.ui.util.ConstraintsUtils;
import org.fortiss.tooling.kernel.ui.util.ConstraintsUtils.ClassifiedStatuses;
/**
* Label decorator for the {@link IMarkerService} decorations: errors, warnings, etc.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 22615D52E9BB387F51B1C3BE8A43207F
*/
public final class ConstraintLabelDecorator extends BaseLabelProvider implements
ILightweightLabelDecorator {
/** {@inheritDoc} */
@Override
public void decorate(Object element, IDecoration decoration) {
if(element instanceof IConstrained) {
IConstrained constrained = (IConstrained)element;
ClassifiedStatuses classifiedStatuses =
ConstraintsUtils.getClassifiedStatuses(constrained);
if(!classifiedStatuses.failedStatuses.isEmpty()) {
decoration.addOverlay(ToolingKernelUIActivator
.getImageDescriptor("icons/constraintFailOverlay.png"));
} else if(!classifiedStatuses.errorStatuses.isEmpty()) {
decoration.addOverlay(ToolingKernelUIActivator
.getImageDescriptor("icons/constraintErrorOverlay.png"));
} else if(!classifiedStatuses.outdatedStatuses.isEmpty()) {
decoration.addOverlay(ToolingKernelUIActivator
.getImageDescriptor("icons/constraintOutdatedOverlay.png"));
} else if(!classifiedStatuses.failedStatuses.isEmpty()) {
decoration.addOverlay(null);
}
}
}
}
package org.fortiss.tooling.kernel.ui.internal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.util.EContentAdapter;
import org.fortiss.tooling.kernel.ToolingKernelActivator;
import org.fortiss.tooling.kernel.extension.IEclipseResourcePostLoadProvider;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.model.constraints.ConstrainedWithChecksum;
import org.fortiss.tooling.kernel.model.constraints.ConstraintsPackage;
import org.fortiss.tooling.kernel.model.constraints.IAutoCheck;
import org.fortiss.tooling.kernel.model.constraints.IConstrained;
import org.fortiss.tooling.kernel.model.constraints.IConstraint;
import org.fortiss.tooling.kernel.model.constraints.IConstraintVerificationStatus;
import org.fortiss.tooling.kernel.model.constraints.OutdatedVerificationStatus;
import org.fortiss.tooling.kernel.service.IConstraintVerificationService;
import org.fortiss.tooling.kernel.service.IPersistencyService;
import org.fortiss.tooling.kernel.service.base.EObjectAwareServiceBase;
import org.fortiss.tooling.kernel.ui.extension.IConstraintVerifierUI;
import org.fortiss.tooling.kernel.ui.service.IConstraintVerificationUIService;
import org.fortiss.tooling.kernel.ui.util.ConstraintsUtils;
import org.fortiss.tooling.kernel.utils.EcoreUtils;
import org.fortiss.tooling.kernel.utils.LoggingUtils;
/**
* Implementation of {@link IConstraintVerificationService}.
*
* @author aravantinos
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 220B5753C9EEEF2B9E972690D285AFA9
*/
public final class ConstraintVerificationUIService extends
EObjectAwareServiceBase<IConstraintVerifierUI<IConstraint>> implements
IConstraintVerificationUIService, IEclipseResourcePostLoadProvider {
/**
* @param constraint
* @return the first registered verifier which provides a GUI for the verifier of
* <code>constraint</code>
*/
private IConstraintVerifierUI<IConstraint> getFirstVerifier(IConstraint constraint) {
List<IConstraintVerifierUI<IConstraint>> list =
getRegisteredHandlers(constraint.getClass());
if(list == null || list.isEmpty()) {
LoggingUtils.error(ToolingKernelActivator.getDefault(), String.format(
"Cannot find verifierUI for constraint %s", constraint.getClass()));
return null;
}
// get(0) because we know the list is not empty and because we want the first element
return list.get(0);
}
/** {@inheritDoc} */
@Override
public void openStatus(IConstraintVerificationStatus status) {
IConstraintVerifierUI<IConstraint> verifier = getFirstVerifier(status.getConstraint());
verifier.openStatus(status);
}
/** {@inheritDoc} */
@Override
public boolean canOpen(IConstraintVerificationStatus status) {
if(status != null) {
IConstraintVerifierUI<IConstraint> verifier = getFirstVerifier(status.getConstraint());
return verifier.canOpen(status);
}
return false;
}
/**
* {@inheritDoc}
*
* Installs all the required notifiers.
*/
@Override
public void postModelLoadRun(ITopLevelElement element) {
TreeIterator<EObject> tree = element.getRootModelElement().eAllContents();
while(tree.hasNext()) {
EObject next = tree.next();
if(next instanceof IConstraint) {
installNotifiers((IConstraint)next);
}
}
}
/** {@inheritDoc} */
@Override
public void installNotifiers(IConstraint constraint) {
new ConstrainedAdapters(constraint);
}
/** Adapter for changes on constrained elements. */
private static class ConstrainedAdapters {
/** Map containing the adapter of each constrained element. */
Map<IConstrained, Adapter> constrainedAdapterMap;
/** Constructor. */
public ConstrainedAdapters(IConstraint constraint) {
constrainedAdapterMap = new HashMap<IConstrained, Adapter>();
for(ConstrainedWithChecksum cwc : constraint.getConstrainedsWithChecksum()) {
IConstrained constrained = cwc.getConstrained();
Adapter adapter = new EContentAdapter() {
@Override
public void notifyChanged(Notification notification) {
super.notifyChanged(notification);
if(isTouch(notification)) {
return;
}
if(constraintRemoved(notification, constrained)) {
return;
}
constraintOutdated(constraint, notification);
}
};
constrained.eAdapters().add(adapter);
constrainedAdapterMap.put(constrained, adapter);
}
}
/**
* @param constraint
* @param notification
* If <code>constraint</code> is outdated because its verification status has
* just been changed, we do not want to change the status to outdated...
*/
private boolean skipConstraintSelfNotification(IConstraint constraint,
Notification notification) {
String n = ConstraintsPackage.eINSTANCE.getIConstraint_VerificationStatus().getName();
if(notification.getNotifier() != null && notification.getNotifier().equals(constraint)) {
if(notification.getFeature() instanceof EReference) {
return(n.equals(((ENamedElement)notification.getFeature()).getName()));
}
}
return false;
}
/**
* @param constraint
* @return <code>true</code> if <code>constraint</code> is outdated and has been handled as
* such.
*/
private boolean constraintOutdated(IConstraint constraint, Notification notification) {
if(skipConstraintSelfNotification(constraint, notification)) {
return false;
}
if(!IConstraintVerificationService.INSTANCE.isUpToDate(constraint)) {
if(constraint instanceof IAutoCheck) {
ITopLevelElement modelContext =
IPersistencyService.INSTANCE.getTopLevelElementFor(constraint);
modelContext.runAsCommand(new Runnable() {
@Override
public void run() {
IConstraintVerificationService.INSTANCE.verify(constraint);
}
});
} else if(!(constraint.getVerificationStatus() instanceof OutdatedVerificationStatus)) {
ConstraintsUtils.createOutdatedVerificationStatus(constraint);
}
return true;
}
return false;
}
/**
* @param notification
* @param constrained
* @return true if the notification is a consequence of a constraint of
* <code>constrained</code> having been removed.
*/
private boolean constraintRemoved(Notification notification, IConstrained constrained) {
if(notification.getEventType() != Notification.REMOVE) {
return false;
}
if(!notification.getNotifier().equals(constrained)) {
return false;
}
if(notification.getFeature() instanceof EReference) {
String name = ((ENamedElement)notification.getFeature()).getName();
if(name.equals(ConstraintsPackage.eINSTANCE.getIConstrained_Constraints().getName())) {
constrained.eAdapters().remove(constrainedAdapterMap.get(constrained));
constrainedAdapterMap.remove(constrained);
return true;
}
}
return true;
}
}
/**
* @param notification
* @return true if <code>notification</code> is not relevant and should be skipped
*/
private static boolean isTouch(Notification notification) {
// Notifications which do not notify about a model change.
if(notification.isTouch()) {
return true;
}
// Notifications initiated by the the AF3 kernel which are only GUI related.
if(notification.getEventType() == EcoreUtils.KERNEL_EMF_EVENT_TYPE_COUNT) {
return true;
}
return false;
}
/** {@inheritDoc} */
@Override
protected String getExtensionPointName() {
return "org.fortiss.tooling.kernel.ui.constraintVerifierUI";
}
/** {@inheritDoc} */
@Override
protected String getConfigurationElementName() {
return "constraintVerifierUI";
}
/** {@inheritDoc} */
@Override
protected String getHandlerClassAttribute() {
return "constraintVerifierUI";
}
/** {@inheritDoc} */
@Override
protected String getClassAttribute() {
return "constraint";
}
/** {@inheritDoc} */
@Override
protected String getClassConfigurationElement() {
return "constraint";
}
}
package org.fortiss.tooling.kernel.ui.service;
import org.fortiss.tooling.kernel.model.constraints.IConstraint;
import org.fortiss.tooling.kernel.model.constraints.IConstraintVerificationStatus;
import org.fortiss.tooling.kernel.service.IConstraintVerificationService;
import org.fortiss.tooling.kernel.ui.internal.ConstraintVerificationUIService;
/**
* GUI aspects of {@link IConstraintVerificationService}.
*
* @author aravantinos
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 07DB0EA202D19FE3C1407B53B01F974F
*/
public interface IConstraintVerificationUIService {
/** Returns the singleton instance of the service. */
public static final IConstraintVerificationUIService INSTANCE =
new ConstraintVerificationUIService();
/** Action to take when trying to open the given status. */
public void openStatus(IConstraintVerificationStatus status);
/** True if the given status can be open. */
public boolean canOpen(IConstraintVerificationStatus status);
/** Install the notifiers required for the given constraint. */
public void installNotifiers(IConstraint constraint);
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2015 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.util;
import java.util.ArrayList;
import java.util.List;
import org.fortiss.tooling.kernel.model.constraints.ConstraintsFactory;
import org.fortiss.tooling.kernel.model.constraints.ErrorVerificationStatus;
import org.fortiss.tooling.kernel.model.constraints.FailVerificationStatus;
import org.fortiss.tooling.kernel.model.constraints.IConstrained;
import org.fortiss.tooling.kernel.model.constraints.IConstraint;
import org.fortiss.tooling.kernel.model.constraints.IConstraintVerificationStatus;
import org.fortiss.tooling.kernel.model.constraints.OutdatedVerificationStatus;
import org.fortiss.tooling.kernel.model.constraints.SuccessVerificationStatus;
/**
* Utility functions for constraints.
*
* @author aravantinos
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 6D5AD8843A4CA208840DD7AA8E3968C2
*/
public class ConstraintsUtils {
/**
* @param constraint
* @return An "outdated" verification status for <code>constraint</code>.
*/
public static OutdatedVerificationStatus
createOutdatedVerificationStatus(IConstraint constraint) {
OutdatedVerificationStatus status =
ConstraintsFactory.eINSTANCE.createOutdatedVerificationStatus();
// The order if these two lines matter: otherwise we might get to some inconsistent state in
// case some GUI element (like a table summarizing the status of all constraints) listens to
// changes to the constraint.
status.setConstraint(constraint);
constraint.setVerificationStatus(status);
return status;
}
/** Gathers some statuses by verification status. */
public static class ClassifiedStatuses {
/** Failed constraints. */
public List<FailVerificationStatus> failedStatuses;
/** Error statuses (constraint could not be checked). */
public List<ErrorVerificationStatus> errorStatuses;
/** Outdated statuses. */
public List<OutdatedVerificationStatus> outdatedStatuses;
/** Successful constraints. */
public List<SuccessVerificationStatus> successStatuses;
/** Constructor. */
public ClassifiedStatuses() {
failedStatuses = new ArrayList<FailVerificationStatus>();
errorStatuses = new ArrayList<ErrorVerificationStatus>();
outdatedStatuses = new ArrayList<OutdatedVerificationStatus>();
successStatuses = new ArrayList<SuccessVerificationStatus>();
}
}
/**
* @param constrained
* @return {@link ClassifiedStatuses} corresponding to <code>constrained</code>.
*/
public static ClassifiedStatuses getClassifiedStatuses(IConstrained constrained) {
ClassifiedStatuses res = new ClassifiedStatuses();
for(IConstraint constraint : constrained.getConstraints()) {
IConstraintVerificationStatus status = constraint.getVerificationStatus();
if(status instanceof FailVerificationStatus) {
res.failedStatuses.add((FailVerificationStatus)status);
}
if(status instanceof ErrorVerificationStatus) {
res.errorStatuses.add((ErrorVerificationStatus)status);
}
if(status instanceof OutdatedVerificationStatus) {
res.outdatedStatuses.add((OutdatedVerificationStatus)status);
}
if(status instanceof SuccessVerificationStatus) {
res.successStatuses.add((SuccessVerificationStatus)status);
}
}
return res;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment