diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/IConstraintUI.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/IConstraintUI.java deleted file mode 100644 index e2cfa44697a95333601a8df131a169aaee85e9b5..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/IConstraintUI.java +++ /dev/null @@ -1,91 +0,0 @@ -/*-------------------------------------------------------------------------+ -| 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 java.util.List; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.fortiss.tooling.kernel.model.constraints.ConstraintInstance; -import org.fortiss.tooling.kernel.model.constraints.IConstraintInstanceStatus; -import org.fortiss.tooling.kernel.ui.service.IConstraintUIService.IFix; - -/** - * Interface for the GUI of constraints. - * - * @author aravantinos - */ -public interface IConstraintUI { - - /** - * Action to take when trying to open the given constraint instance. <code>canOpen</code> should - * be called before in order to know if the status can be opened. - * - * @return true if the constraint instance could indeed be open, false if it needs further - * handling. - */ - public boolean openStatus(ConstraintInstance ci, IConstraintInstanceStatus s); - - /** True if the constraint instance can be open. */ - boolean canOpen(ConstraintInstance ci, IConstraintInstanceStatus s); - - /** Method to execute when a constraint instance gets outdated. */ - public void onOutdate(ConstraintInstance ci); - - /** - * Returns a short user-friendly description for the current status of the constraint instance. - */ - public String getMessage(ConstraintInstance ci, IConstraintInstanceStatus s); - - /** - * Returns a list of possible automatic fixes for the given constraint instance. A constraint - * instance should be candidate to fixing if its status is anything but successful or outdated. - */ - List<IFix> fixes(ConstraintInstance ci, IConstraintInstanceStatus s); - - /** - * Set to <code>true</code> if you want that a failure of your constraint be displayed as a - * warning rather than as an error. - */ - public boolean displayAsWarning(); - - /** Gets a general description for the constraint type. */ - String getDescription(); - - /** - * Same as <code>getDescription</code> but allows to make use of additional instance-specific - * information. - */ - public String getDescription(ConstraintInstance ci); - - /** Returns the image descriptor to be used as icon image. */ - public ImageDescriptor getIconImageDescriptor(); - - /** - * Way for the constraint to indicate that the verification is often time consuming. - * This triggers a few goodies: - * - wait 1s before triggering the constraint autocheck (if relevant) - * - display a warning popup in case of first trigger of the verification - * TODO(2703) make instead an event "onActivate" in order to allow customization. For instance - * one could check if Z3 is present or not. - */ - public boolean isTimeConsuming(); - - /** - * True if this constraint shall be always activated (and therefore the user shall not be - * offered the possibility to control whether the constraint is active or not). - */ - public boolean shouldBeManuallyActivated(); -} diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/ConstraintUIBases.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/ConstraintUIBases.java deleted file mode 100644 index 3676a600e0866091db9798763c6eee97eec5b55b..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/ConstraintUIBases.java +++ /dev/null @@ -1,286 +0,0 @@ -/*-------------------------------------------------------------------------+ -| 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.base; - -import static org.fortiss.tooling.kernel.ui.util.ConstraintsUIUtils.triggerMarkersRefresh; -import static org.fortiss.tooling.kernel.utils.ConstraintsUtils.createOutdatedStatus; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Shell; -import org.fortiss.tooling.kernel.model.constraints.ConstraintInstance; -import org.fortiss.tooling.kernel.model.constraints.ErrorConstraintInstanceStatus; -import org.fortiss.tooling.kernel.model.constraints.FailedConstraintInstanceStatus; -import org.fortiss.tooling.kernel.model.constraints.IConstraintInstanceStatus; -import org.fortiss.tooling.kernel.model.constraints.OutdatedConstraintInstanceStatus; -import org.fortiss.tooling.kernel.service.IConstraintService; -import org.fortiss.tooling.kernel.ui.extension.IConstraintUI; -import org.fortiss.tooling.kernel.ui.service.IConstraintUIService; -import org.fortiss.tooling.kernel.ui.service.IConstraintUIService.IFix; -import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService; - -/** - * Base classes for constraint verification GUI. - * - * @author aravantinos - */ -public class ConstraintUIBases { - - /** Base class for constraint verification GUI. */ - public static abstract class ConstraintUIBase implements IConstraintUI { - /** {@inheritDoc} */ - @Override - public boolean canOpen(ConstraintInstance ci, IConstraintInstanceStatus status) { - return status instanceof OutdatedConstraintInstanceStatus; - } - - /** {@inheritDoc} */ - @Override - public String getDescription(ConstraintInstance ci) { - return this.getDescription(); - } - - /** {@inheritDoc} */ - @Override - public List<IFix> fixes(ConstraintInstance ci, IConstraintInstanceStatus status) { - // No fix by default, it is however strongly recommended to override in order to improve - // user experience. - return new ArrayList<IFix>(); - } - - /** {@inheritDoc} */ - @Override - public boolean openStatus(ConstraintInstance ci, IConstraintInstanceStatus status) { - if(!canOpen(ci, status)) { - return false; - } - if(status instanceof OutdatedConstraintInstanceStatus) { - IConstraintService.getInstance().verify(ci); - IConstraintInstanceStatus currentStatus = - IConstraintUIService.getInstance().getStatus(ci); - if(currentStatus instanceof ErrorConstraintInstanceStatus && canOpen(ci, status)) { - openStatus(ci, currentStatus); - } - return true; - } - if(status instanceof FailedConstraintInstanceStatus || - status instanceof ErrorConstraintInstanceStatus) { - List<IFix> fixes = IConstraintUIService.getInstance().fixes(ci); - Shell shell = Display.getCurrent().getActiveShell(); - int result = new FixDialog(shell, status, getMessage(ci, status), fixes).open(); - if(fixes.size() == 1 && result == 0) { - // get(0) because the size is equal to 1 by the previous test - fixes.get(0).runFix(status); - } else if(result > 1) { - // In this case, result = 0 iff the dialog was cancelled, 1 iff the dialog was - // OK, or any number greater than 1 to select a given fix, hence the result-2 - // below. - fixes.get(result - 2).runFix(status); - } - return true; - } - return false; - } - - /** {@inheritDoc} */ - @Override - public boolean isTimeConsuming() { - return false; - } - - /** Dialog presenting the error/failure and the possible fix(es). */ - private static class FixDialog extends MessageDialog { - /** List of possible fixes. */ - List<IFix> fixes; - - /** Constructor. */ - public FixDialog(Shell parentShell, IConstraintInstanceStatus s, String msg, - List<IFix> fixes) { - super(parentShell, getTitle(s), null, msg, getIconType(s), getButtons(fixes), 1); - this.fixes = fixes; - } - - /** - * Returns the buttons to display: "OK" is always displayed. In addition, if there is - * only one fix, we provide one button for this fix. If there is more than one - * possible fixes, they will displayed instead horizontally (via getCustomArea). - */ - private static String[] getButtons(List<IFix> fixes) { - String[] res = new String[fixes.size() == 1 ? 2 : 1]; - if(fixes.size() == 1) { - // get(0) because the size is equal to 1 by the previous test - res[0] = "Fix: " + fixes.get(0).getDescription(); - } - res[res.length - 1] = "OK"; - return res; - } - - /** Returns the icon type corresponding to <code>s</code>. */ - private static String getTitle(IConstraintInstanceStatus s) { - if(s instanceof FailedConstraintInstanceStatus) { - return "Verification of constraint failed"; - } - return "Error during constraint verification"; - } - - /** Returns the icon type corresponding to <code>s</code>. */ - private static int getIconType(IConstraintInstanceStatus s) { - return s instanceof FailedConstraintInstanceStatus ? MessageDialog.WARNING : ERROR; - } - - /** {@inheritDoc} */ - @Override - protected Control createCustomArea(Composite parent) { - if(fixes.size() <= 1) { - return null; - } - Group buttonGroup = new Group(parent, SWT.NONE); - buttonGroup.setLayout(new GridLayout()); - buttonGroup.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, true, false)); - buttonGroup.setText("Possible fixes"); - for(IFix fix : fixes) { - Button button = new Button(buttonGroup, SWT.None); - button.setText(fix.getDescription()); - button.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent event) { - buttonPressed(fixes.indexOf(fix) + 1); - } - }); - } - // Does not matter what we return as long as it's not null - return buttonGroup; - } - } - - /** {@inheritDoc} */ - @Override - public String getMessage(ConstraintInstance ci, IConstraintInstanceStatus status) { - IConstraintInstanceStatus s = IConstraintUIService.getInstance().getStatus(ci); - // Default message. Inheriting classes SHOULD specialize. - String name = IModelElementHandlerService.getInstance().getName(s.getConstraint()); - String pre = s instanceof ErrorConstraintInstanceStatus ? "Error while checking" - : "Unsatisfied"; - return pre + " constraint" + (name == null ? "." : ": \"" + name + "\""); - } - - /** {@inheritDoc} */ - @Override - public void onOutdate(ConstraintInstance ci) { - // By default, we just set the status to outdated - createOutdatedStatus(ci); - } - - /** {@inheritDoc} */ - @Override - public boolean shouldBeManuallyActivated() { - return false; - } - - /** {@inheritDoc} */ - @Override - public boolean displayAsWarning() { - // By default, constraints failures are displayed as error not as warnings - return false; - } - - /** {@inheritDoc} */ - @Override - public ImageDescriptor getIconImageDescriptor() { - return null; - } - } - - /** - * Base class for constraint verifier UIs which automatically trigger a new check when the - * constraint gets outdated. - */ - public static abstract class ConstraintUIBaseAutocheck extends ConstraintUIBase { - - /** {@inheritDoc} */ - @Override - public void onOutdate(ConstraintInstance ci) { - Display display = Display.getDefault(); - String name = "Verifying " + ConstraintUIBaseAutocheck.this.getDescription(); - Job latestJob = new Job(name) { - /** {@inheritDoc} */ - @Override - protected IStatus run(IProgressMonitor monitor) { - try { - display.asyncExec(() -> IConstraintService.getInstance().cancel(ci)); - IConstraintService.getInstance().verify(ci); - display.asyncExec(() -> triggerMarkersRefresh(ci)); - return Status.OK_STATUS; - } catch(IllegalArgumentException e) { - // This sort of exception might happen, not sure why, but we *in no case* - // want to throw an error message to the user in case of some failure - // resulting of a constraint check which he did not explicitly triggered - return Status.CANCEL_STATUS; - } - } - }; - // If the constraint is considered time consuming, we wait 1s before starting the job - // because user modifications can go faster than the check. - latestJob.schedule(isTimeConsuming() ? 1000 : 0); - } - - /** {@inheritDoc} */ - @Override - public boolean canOpen(ConstraintInstance ci, IConstraintInstanceStatus status) { - return false; - } - } - - /** Handler for constraints. */ - public static class ConstraintHandler extends ModelElementHandlerBase<ConstraintInstance> { - - /** {@inheritDoc} */ - @Override - public String getName(ConstraintInstance element) { - return getDescription(element); - } - - /** {@inheritDoc} */ - @Override - public ImageDescriptor getIconImageDescriptor() { - // This method will actually never be called - return null; - } - - /** {@inheritDoc} */ - @Override - public ImageDescriptor getIconImageDescriptor(ConstraintInstance element) { - return IConstraintUIService.getInstance().getIconImageDescriptor(element); - } - } -} diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/.ratings b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/.ratings index 4ea2eb911c9c55e937b880dbeaf7c166dd8ac547..4fe5ae19062526bb33cd7efe44bd12d9d85587b6 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/.ratings +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/.ratings @@ -1,12 +1,10 @@ ActionService.java e29126b5947c9fd2f1d82bb87001b9d0ead50c3b GREEN AllocationEditPartFactoryService.java 81bd227736013f1157ba9d0f79a9f3deefe10064 GREEN -ConstraintLabelDecorator.java ac138bfc97ea3b2f8fde0497ade915e4cd942af1 GREEN -ConstraintUIService.java 433e35bb1c9bbc628c6ee070ff45632400becf4a GREEN ContextMenuService.java ca3c899293f25b70ce8e5f0d86ca2f9683329d81 GREEN EditPartFactoryService.java e9180c0020f1769d9e24ef3c08f9ca5599dbc5c3 GREEN -MarkerService.java b01b7706034691683df7bbc2e7828c42574b3147 GREEN +MarkerService.java 208f97f3ccabf0947702a17ddca23d8766a268f4 GREEN ModelEditorBindingService.java 948fcdc298a74e366351ad8835a145af6cd238be GREEN ModelElementHandlerService.java 07a30545ad687ff0fe13bf7a9348c41fb03e0b2c GREEN NavigatorService.java 2b1361eac805996e22e5409dafff9707fbac3376 GREEN -ToolingKernelUIInternal.java 38903445a9084b7908716a00f41621dfb3126fca GREEN +ToolingKernelUIInternal.java a70d19883dfb315d860233156d8524cf1ac2952f GREEN TutorialUIService.java b1d632eca91b4feb583f3930cd6ee4722dd9bfed GREEN diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/ConstraintLabelDecorator.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/ConstraintLabelDecorator.java deleted file mode 100644 index ac138bfc97ea3b2f8fde0497ade915e4cd942af1..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/ConstraintLabelDecorator.java +++ /dev/null @@ -1,60 +0,0 @@ -/*-------------------------------------------------------------------------+ -| 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 static org.fortiss.tooling.kernel.ui.ESharedImages.ERROR_OVERLAY; -import static org.fortiss.tooling.kernel.ui.ESharedImages.FATAL_OVERLAY; -import static org.fortiss.tooling.kernel.ui.ESharedImages.WARNING_OVERLAY; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.viewers.BaseLabelProvider; -import org.eclipse.jface.viewers.IDecoration; -import org.eclipse.jface.viewers.ILightweightLabelDecorator; -import org.fortiss.tooling.kernel.extension.data.IConstraintViolation.ESeverity; -import org.fortiss.tooling.kernel.ui.service.IMarkerService; -import org.fortiss.tooling.kernel.ui.util.ConstraintsUIUtils; - -/** - * Label decorator for the {@link IMarkerService} decorations: errors, warnings, etc. - * - * @author hoelzl - */ -public final class ConstraintLabelDecorator extends BaseLabelProvider - implements ILightweightLabelDecorator { - - /** {@inheritDoc} */ - @Override - public void decorate(Object element, IDecoration decoration) { - if(element instanceof EObject) { - ESeverity sev = - IMarkerService.getInstance().getHighestViolationSeverity((EObject)element); - sev = ConstraintsUIUtils.augmentSeverityWithConstraintSeverity(sev, (EObject)element); - switch(sev) { - case FATAL: - decoration.addOverlay(FATAL_OVERLAY.getImageDescriptor()); - break; - case ERROR: - decoration.addOverlay(ERROR_OVERLAY.getImageDescriptor()); - break; - case WARNING: - decoration.addOverlay(WARNING_OVERLAY.getImageDescriptor()); - break; - default: - // ignore info and debug - } - } - } -} diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/ConstraintUIService.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/ConstraintUIService.java deleted file mode 100644 index 433e35bb1c9bbc628c6ee070ff45632400becf4a..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/ConstraintUIService.java +++ /dev/null @@ -1,475 +0,0 @@ -package org.fortiss.tooling.kernel.ui.internal; - -import static java.util.Collections.emptyList; -import static org.fortiss.tooling.kernel.ui.util.ConstraintsUIUtils.displayTimeConsumptionWarning; -import static org.fortiss.tooling.kernel.ui.util.ConstraintsUIUtils.triggerMarkerRefresh; -import static org.fortiss.tooling.kernel.ui.util.ConstraintsUIUtils.triggerMarkersRefresh; -import static org.fortiss.tooling.kernel.utils.LoggingUtils.warning; - -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.util.EList; -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.eclipse.jface.resource.ImageDescriptor; -import org.fortiss.tooling.kernel.ToolingKernelActivator; -import org.fortiss.tooling.kernel.extension.IConstraint; -import org.fortiss.tooling.kernel.extension.data.ITopLevelElement; -import org.fortiss.tooling.kernel.introspection.IIntrospectionDetailsItem; -import org.fortiss.tooling.kernel.introspection.IIntrospectionItem; -import org.fortiss.tooling.kernel.introspection.IIntrospectiveKernelService; -import org.fortiss.tooling.kernel.model.constraints.ConstraintInstance; -import org.fortiss.tooling.kernel.model.constraints.ConstraintsPackage; -import org.fortiss.tooling.kernel.model.constraints.IConstrained; -import org.fortiss.tooling.kernel.model.constraints.IConstraintInstanceContainer; -import org.fortiss.tooling.kernel.model.constraints.IConstraintInstanceStatus; -import org.fortiss.tooling.kernel.model.constraints.OutdatedConstraintInstanceStatus; -import org.fortiss.tooling.kernel.service.IConstraintService; -import org.fortiss.tooling.kernel.service.IKernelIntrospectionSystemService; -import org.fortiss.tooling.kernel.service.IPersistencyService; -import org.fortiss.tooling.kernel.ui.ToolingKernelUIActivator; -import org.fortiss.tooling.kernel.ui.extension.IConstraintUI; -import org.fortiss.tooling.kernel.ui.internal.introspection.items.ConstraintUIServiceIntrospectionDetailsItem; -import org.fortiss.tooling.kernel.ui.service.IConstraintUIService; -import org.fortiss.tooling.kernel.ui.util.ConstraintsUIUtils; -import org.fortiss.tooling.kernel.utils.EcoreUtils; -import org.fortiss.tooling.kernel.utils.LoggingUtils; - -/** - * Implementation of {@link IConstraintUIService}. - * - * @author aravantinos - */ -public final class ConstraintUIService - implements IConstraintUIService, IIntrospectiveKernelService { - - /** The singleton service instance. */ - private static ConstraintUIService INSTANCE = new ConstraintUIService(); - - /** Stores the string to class handler map. */ - protected final Map<String, Class<? extends IConstraint>> string2cstrMap = - new HashMap<String, Class<? extends IConstraint>>(); - - /** Stores the non-UI class to UI class handler map. */ - protected final Map<Class<? extends IConstraint>, Class<? extends IConstraintUI>> cstr2cstrUIMap = - new HashMap<Class<? extends IConstraint>, Class<? extends IConstraintUI>>(); - - /** Stores the UI-class to instance handler map. */ - protected final Map<Class<? extends IConstraintUI>, IConstraintUI> instanceMap = - new HashMap<Class<? extends IConstraintUI>, IConstraintUI>(); - - /** Returns the service instance. */ - public static ConstraintUIService getInstance() { - return INSTANCE; - } - - /** Activates logging to observe when constraints get outdated. */ - private static final boolean DEBUG = false; - - /** Starts the service. */ - public void startService() { - IKernelIntrospectionSystemService.getInstance().registerService(this); - List<ITopLevelElement> tops = IPersistencyService.getInstance().getTopLevelElements(); - for(ITopLevelElement top : tops) { - TreeIterator<EObject> tree = top.getRootModelElement().eAllContents(); - while(tree.hasNext()) { - EObject next = tree.next(); - if(next instanceof ConstraintInstance) { - install((ConstraintInstance)next); - } - } - } - } - - /** {@inheritDoc} */ - @Override - public void registerConstraintUI(Class<? extends IConstraintUI> cstrUIClass, - Class<? extends IConstraint> cstrClass) { - String name = cstrClass.getName(); - if(string2cstrMap.get(name) != null) { - warning(ToolingKernelActivator.getDefault(), - "Encountered more than one registered constraint UI associated with " + name); - } - string2cstrMap.put(name, cstrClass); - cstr2cstrUIMap.put(cstrClass, cstrUIClass); - try { - instanceMap.put(cstrUIClass, cstrUIClass.getConstructor().newInstance()); - } catch(InstantiationException | IllegalAccessException | IllegalArgumentException | - InvocationTargetException | NoSuchMethodException | SecurityException e) { - warning(ToolingKernelActivator.getDefault(), - "Instanciation of " + cstrUIClass.getName() + " threw an exception."); - } - } - - /** Initializes the service by setting up the handler map. */ - public void initializeService() { - // nothing to do here - } - - /** {@inheritDoc} */ - @Override - public String getIntrospectionDescription() { - return getIntrospectionLabel() + - "\n\nThis service deals with the UI aspects of constraints." + - "\n\nIt provides the following:" + - "\n- inform whether a constraint instance can be open or not," + - "\n- open the status of a constraint instance," + - "\n- \"install\" a constraint instance, i.e., sets listeners on the constrained element(s) in order" + - "\n to automatically detect when a constraint is outdated," + - "\n- inform, for a given constraint instance, whether it should display an error or a warning in case of non-satisfaction," + - "\n- provide a user-friendly short description for a constraint (useful in various automatic messages)," + - "\n- provide an icon for a given constraint (useful in the context menu)," + - "\n- give the status of a given constraint instance - taking into account whether the constraint is activated or not," + - "\n- activate a given constraint," + "\n- deactivate a given constraint," + - "\n- give the list of all available constraints," + - "\n- give the list of constraints which should always be activated - by opposition to those which should be explicitly activated by the user," + - "\n- give the list of constraints which are currently activated - by the user or automatically," + - "\n- complete a given project with instances of a given constraint if necessary." + - "\n\nThis service is \"fed\" by classes of type IConstraintUI." + - "\n\nThe class org.fortiss.tooling.kernel.ui.extension.base.ConstraintVerifierUIBaseAutocheck should" + - "\ngenerally provide a sufficient initial implementation. You are however strongly encouraged" + - "\nto extend this class to provide a better feedback to the user (e.g., with detailed errors)." + - "\n\nSee the developer wiki page \"Add a new constraint on a metamodel\"" + - " for detailed documentation on developing a new sort of constraint."; - } - - /** @return the first registered constraint UI corresponding to <code>ci</code>. */ - private IConstraintUI getConstraintUI(ConstraintInstance ci) { - Class<? extends IConstraint> cstr = string2cstrMap.get(ci.getConstraintName()); - Class<? extends IConstraintUI> cstrUI = cstr2cstrUIMap.get(cstr); - return instanceMap.get(cstrUI); - } - - /** {@inheritDoc} */ - @Override - public void openStatus(ConstraintInstance ci) { - getConstraintUI(ci).openStatus(ci, getStatus(ci)); - triggerMarkersRefresh(ci); - } - - /** {@inheritDoc} */ - @Override - public boolean canOpen(ConstraintInstance ci) { - IConstraintUI verifier = getConstraintUI(ci); - return verifier.canOpen(ci, getStatus(ci)); - } - - /** Map containing the adapters of each constrained element. */ - Map<IConstrained, Adapter> constrainedAdapterMap = new HashMap<IConstrained, Adapter>(); - - /** Installed constraints, sorted by adapters. */ - Map<Adapter, List<ConstraintInstance>> installedConstraintInstances = new HashMap<>(); - - /** {@inheritDoc} */ - @Override - public void install(ConstraintInstance ci) { - triggerMarkersRefresh(ci); - for(IConstrained constrained : ci.getConstraineds()) { - Adapter currentAdapter = constrainedAdapterMap.get(constrained); - if(currentAdapter == null) { - currentAdapter = new EContentAdapter() { - @Override - public void notifyChanged(Notification notification) { - super.notifyChanged(notification); - if(isTouch(notification) || constraintRemoved(notification, constrained)) { - return; - } - List<ConstraintInstance> outdatedConstraintInstances = new ArrayList<>(); - for(ConstraintInstance ci : installedConstraintInstances.get(this)) { - if(getStatus(ci) != null) { - constraintOutdated(ci, notification); - outdatedConstraintInstances.add(ci); - } - } - triggerMarkersRefresh(outdatedConstraintInstances); - } - }; - constrained.eAdapters().add(currentAdapter); - constrainedAdapterMap.put(constrained, currentAdapter); - installedConstraintInstances.put(currentAdapter, new ArrayList<>()); - } - installedConstraintInstances.get(currentAdapter).add(ci); - } - } - - /** - * Checks if <code>notification</code> denotes a change entailing that <code>ci</code> is - * outdated. If so updates the status to outdated or triggers an automatic check if the - * <code>autocheck</code> field of the constraint is <code>true</code>. - * - * @return <code>true</code> iff <code>notification</code> indeed entailed that <code>ci</code> - * is outdated. - */ - private boolean constraintOutdated(ConstraintInstance ci, Notification notification) { - if(skipStatusChangeNotification(ci, notification)) { - return false; - } - if(!IConstraintService.getInstance().isUpToDate(ci)) { - if(DEBUG) { - String msg = "Constraint instance " + ci.toString() + " is outdated."; - LoggingUtils.info(ToolingKernelUIActivator.getDefault(), msg); - } - if(!IConstraintService.getInstance().isUpdating(ci)) { - IConstraintService.getInstance().markAsUpdating(ci); - getConstraintUI(ci).onOutdate(ci); - return true; - } - } - return false; - } - - /** - * @return true iff <code>notification</code> denotes a change of the <code>ci</code>'s - * status. - */ - private boolean skipStatusChangeNotification(ConstraintInstance ci, Notification notification) { - String n = ConstraintsPackage.eINSTANCE.getConstraintInstance_Status().getName(); - if(notification.getNotifier() != null && notification.getNotifier().equals(ci)) { - if(notification.getFeature() instanceof EReference) { - return(n.equals(((ENamedElement)notification.getFeature()).getName())); - } - } - return false; - } - - /** - * @return true if the notification is a consequence of a constraint of <code>constrained</code> - * being 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_ConstraintInstances().getName())) { - Adapter cstrdAdapter = constrainedAdapterMap.get(constrained); - List<ConstraintInstance> cis = installedConstraintInstances.get(cstrdAdapter); - // To check!!! notification.getOldValue() should be the removed ConstraintInstance - cis.remove(notification.getOldValue()); - if(cis.isEmpty()) { - constrained.eAdapters().remove(cstrdAdapter); - constrainedAdapterMap.remove(constrained); - } - return true; - } - } - return true; - } - - /** @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 - public IIntrospectionDetailsItem getDetailsItem() { - Map<String, Class<? extends IConstraintUI>> handlerMap = new HashMap<>(); - for(Entry<String, Class<? extends IConstraint>> entry : string2cstrMap.entrySet()) { - Class<? extends IConstraintUI> cstrUIClass = cstr2cstrUIMap.get(entry.getValue()); - handlerMap.put(entry.getKey(), cstrUIClass); - } - return new ConstraintUIServiceIntrospectionDetailsItem(handlerMap); - } - - /** {@inheritDoc} */ - @Override - public String getIntrospectionLabel() { - return "Constraint UI Service"; - } - - /** Activated constraints per top level element. */ - private static Map<ITopLevelElement, Set<Class<? extends IConstraint>>> activatedConstraints = - new HashMap<>(); - - /** {@inheritDoc} */ - @Override - public IConstraintInstanceStatus getStatus(ConstraintInstance ci) { - ITopLevelElement top = IPersistencyService.getInstance().getTopLevelElementFor(ci); - boolean isActivated = false; - Set<Class<? extends IConstraint>> set = activatedConstraints.get(top); - if(set != null) { - for(Class<? extends IConstraint> id : set) { - if(id.getName().equals(ci.getConstraintName())) { - isActivated = true; - } - } - } - return isActivated ? ci.getStatus() : null; - } - - /** {@inheritDoc} */ - @Override - public Set<Class<? extends IConstraint>> getAllConstraints() { - return cstr2cstrUIMap.keySet(); - } - - /** {@inheritDoc} */ - @Override - public Set<Class<? extends IConstraint>> getActivatedConstraints(ITopLevelElement top) { - Set<Class<? extends IConstraint>> res = activatedConstraints.get(top); - return res != null ? res : new HashSet<>(); - } - - /** {@inheritDoc} */ - @Override - public void activate(Class<? extends IConstraint> cstrClass, - IConstraintInstanceContainer cstrContainer) { - ITopLevelElement top = - IPersistencyService.getInstance().getTopLevelElementFor(cstrContainer); - if(!activatedConstraints.containsKey(top)) { - activatedConstraints.put(top, new HashSet<>()); - } - activatedConstraints.get(top).add(cstrClass); - List<ConstraintInstance> addeds = - IConstraintService.getInstance().addMissingConstraintsInstances(top, cstrClass); - IConstraintUI cstrUI = instanceMap.get(cstr2cstrUIMap.get(cstrClass)); - if(!addeds.isEmpty() && cstrUI.isTimeConsuming()) { - displayTimeConsumptionWarning(cstrClass); - } - // Install notifiers for newly added constraints - for(ConstraintInstance added : addeds) { - IConstraintUIService.getInstance().install(added); - } - EList<ConstraintInstance> cstrs = cstrContainer.getConstraintInstances(); - Predicate<ConstraintInstance> isID = c -> cstrClass.getName().equals(c.getConstraintName()); - List<ConstraintInstance> idCstrs = cstrs.stream().filter(isID).collect(Collectors.toList()); - update(idCstrs); - } - - /** {@inheritDoc} */ - @Override - public void addMissingConstraintInstances(IConstraintInstanceContainer cstrContainer) { - ITopLevelElement top = - IPersistencyService.getInstance().getTopLevelElementFor(cstrContainer); - List<ConstraintInstance> addeds = new ArrayList<ConstraintInstance>(); - for(Class<? extends IConstraint> cstrClass : getActivatedConstraints(top)) { - addeds.addAll(IConstraintService.getInstance().addMissingConstraintsInstances(top, - cstrClass)); - IConstraintService.getInstance().addMissingConstraintsInstances(top, cstrClass); - } - // Install notifiers for newly added constraints - for(ConstraintInstance added : addeds) { - IConstraintUIService.getInstance().install(added); - } - update(addeds); - } - - /** Checks the constraints among the given list of constraint instances. */ - private void update(List<ConstraintInstance> cis) { - // Checks all the constraints: the newly added and the already existing ones which are now - // activated. - for(ConstraintInstance ci : cis) { - // No need to check if it turns out the status is already known from a previous - // activation. - if(!IConstraintService.getInstance().isUpdating(ci) && - (!IConstraintService.getInstance().isUpToDate(ci) || - ci.getStatus() instanceof OutdatedConstraintInstanceStatus)) { - getConstraintUI(ci).onOutdate(ci); - } - } - ConstraintsUIUtils.triggerMarkersRefresh(cis); - } - - /** {@inheritDoc} */ - @Override - public void deactivate(Class<? extends IConstraint> cstrClass, - IConstraintInstanceContainer cstrContainer) { - ITopLevelElement top = - IPersistencyService.getInstance().getTopLevelElementFor(cstrContainer); - activatedConstraints.get(top).remove(cstrClass); - triggerMarkerRefresh(cstrClass, cstrContainer); - } - - /** {@inheritDoc} */ - @Override - public String getDescription(Class<? extends IConstraint> cstrClass) { - IConstraintUI cstrUI = instanceMap.get(cstr2cstrUIMap.get(cstrClass)); - return cstrUI == null ? null : cstrUI.getDescription(); - } - - /** {@inheritDoc} */ - @Override - public boolean showInIntrospectionNavigation() { - return true; - } - - /** {@inheritDoc} */ - @Override - public Collection<IIntrospectionItem> getIntrospectionItems() { - return emptyList(); - } - - /** {@inheritDoc} */ - @Override - public ImageDescriptor getIconImageDescriptor(ConstraintInstance ci) { - Class<? extends IConstraint> cstrClass = string2cstrMap.get(ci.getConstraintName()); - IConstraintUI cstrUI = instanceMap.get(cstr2cstrUIMap.get(cstrClass)); - return cstrUI == null ? null : cstrUI.getIconImageDescriptor(); - } - - /** {@inheritDoc} */ - @Override - public boolean shallDisplayAsWarning(ConstraintInstance constraint) { - return getConstraintUI(constraint).displayAsWarning(); - } - - /** {@inheritDoc} */ - @Override - public Set<Class<? extends IConstraint>> getAlwaysActivatedConstraints() { - HashSet<Class<? extends IConstraint>> res = new HashSet<>(); - for(Entry<Class<? extends IConstraint>, Class<? extends IConstraintUI>> entry : cstr2cstrUIMap - .entrySet()) { - if(!instanceMap.get(entry.getValue()).shouldBeManuallyActivated()) { - res.add(entry.getKey()); - } - } - return res; - } - - /** {@inheritDoc} */ - @Override - public String getDescription(ConstraintInstance ci) { - Class<? extends IConstraint> cstrClass = string2cstrMap.get(ci.getConstraintName()); - return instanceMap.get(cstr2cstrUIMap.get(cstrClass)).getDescription(ci); - } - - /** {@inheritDoc} */ - @Override - public List<IFix> fixes(ConstraintInstance ci) { - List<IFix> fixes = null; - IConstraintUI cstr = getConstraintUI(ci); - if(cstr != null) { - fixes = cstr.fixes(ci, ci.getStatus()); - } - return fixes != null ? fixes : new ArrayList<IFix>(); - } -} diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/MarkerService.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/MarkerService.java index b01b7706034691683df7bbc2e7828c42574b3147..208f97f3ccabf0947702a17ddca23d8766a268f4 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/MarkerService.java +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/MarkerService.java @@ -18,7 +18,6 @@ package org.fortiss.tooling.kernel.ui.internal; import static java.util.Collections.emptyList; import static java.util.Collections.sort; import static org.fortiss.tooling.kernel.ui.ToolingKernelUIActivator.getImageDescriptor; -import static org.fortiss.tooling.kernel.ui.util.ConstraintsUIUtils.augmentSeverityWithConstraintSeverity; import static org.fortiss.tooling.kernel.utils.EcoreUtils.postRefreshNotification; import java.util.ArrayList; @@ -41,7 +40,6 @@ import org.eclipse.ui.progress.UIJob; import org.fortiss.tooling.kernel.extension.data.IConstraintViolation; import org.fortiss.tooling.kernel.extension.data.IConstraintViolation.ESeverity; import org.fortiss.tooling.kernel.extension.data.ITopLevelElement; -import org.fortiss.tooling.kernel.model.constraints.IConstrained; import org.fortiss.tooling.kernel.service.IConstraintCheckerService; import org.fortiss.tooling.kernel.service.IPersistencyService; import org.fortiss.tooling.kernel.service.listener.IPersistencyServiceListener; @@ -168,9 +166,6 @@ public class MarkerService implements IMarkerService, IPersistencyServiceListene return ESeverity.lowest(); } ESeverity sev = getCacheEntry(top).getHighestSeverity(element); - if(element instanceof IConstrained) { - sev = augmentSeverityWithConstraintSeverity(sev, element); - } return sev; } diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/ToolingKernelUIInternal.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/ToolingKernelUIInternal.java index 38903445a9084b7908716a00f41621dfb3126fca..a70d19883dfb315d860233156d8524cf1ac2952f 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/ToolingKernelUIInternal.java +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/ToolingKernelUIInternal.java @@ -29,7 +29,6 @@ public final class ToolingKernelUIInternal { printPhase("Tooling Kernel UI initializing ..."); ActionService.getInstance().initializeService(); AllocationEditPartFactoryService.getInstance().initializeService(); - ConstraintUIService.getInstance().initializeService(); ContextMenuService.getInstance().initializeService(); EditPartFactoryService.getInstance().initializeService(); MarkerService.getInstance().initializeService(); @@ -45,7 +44,6 @@ public final class ToolingKernelUIInternal { printPhase("Tooling Kernel UI starting ..."); ActionService.getInstance().startService(); AllocationEditPartFactoryService.getInstance().startService(); - ConstraintUIService.getInstance().startService(); ContextMenuService.getInstance().startService(); EditPartFactoryService.getInstance().startService(); MarkerService.getInstance().startService(); diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/.ratings b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/.ratings index cf783a7ef376170862fac66dc2f0ee007c206a64..5be567a381cb00bbd092fd15f0bedb8d6e158f38 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/.ratings +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/.ratings @@ -1,2 +1,2 @@ DetailsUIHandlerBase.java d3d2038cee67f61ca0be7e0c832ffc95771cee0f GREEN -KISSDetailsUIRegistry.java 89716fced381fa2b8e64cd8bcd81fa22495973d9 GREEN +KISSDetailsUIRegistry.java 4ae512082e0a7751f9da1d631b1bba44c2e5e8c4 GREEN diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/KISSDetailsUIRegistry.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/KISSDetailsUIRegistry.java index 89716fced381fa2b8e64cd8bcd81fa22495973d9..4ae512082e0a7751f9da1d631b1bba44c2e5e8c4 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/KISSDetailsUIRegistry.java +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/KISSDetailsUIRegistry.java @@ -21,7 +21,6 @@ import org.fortiss.tooling.kernel.introspection.IIntrospectionDetailsItem; import org.fortiss.tooling.kernel.introspection.IIntrospectionItem; import org.fortiss.tooling.kernel.introspection.items.ConnectionCompositorServiceIntrospectionDetailsItem; import org.fortiss.tooling.kernel.introspection.items.ConstraintCheckerServiceIntrospectionDetailsItem; -import org.fortiss.tooling.kernel.introspection.items.ConstraintVerificationServiceIntrospectionDetailsItem; import org.fortiss.tooling.kernel.introspection.items.EclipseResourceStorageServiceIntrospectionDetailsItem; import org.fortiss.tooling.kernel.introspection.items.ElementCompositorServiceIntrospectionDetailsItem; import org.fortiss.tooling.kernel.introspection.items.LibraryServiceIntrospectionDetailsItem; @@ -32,8 +31,6 @@ import org.fortiss.tooling.kernel.introspection.items.TransformationServiceIntro import org.fortiss.tooling.kernel.ui.internal.introspection.details.handler.AllocationEditPartFactoryServiceIntrospectionDetailsUIHandler; import org.fortiss.tooling.kernel.ui.internal.introspection.details.handler.ConnectionCompositorServiceIntrospectionDetailsUIHandler; import org.fortiss.tooling.kernel.ui.internal.introspection.details.handler.ConstraintCheckerServiceIntrospectionDetailsUIHandler; -import org.fortiss.tooling.kernel.ui.internal.introspection.details.handler.ConstraintServiceIntrospectionDetailsUIHandler; -import org.fortiss.tooling.kernel.ui.internal.introspection.details.handler.ConstraintUIServiceIntrospectionDetailsUIHandler; import org.fortiss.tooling.kernel.ui.internal.introspection.details.handler.ContextMenuServiceIntrospectionDetailsUIHandler; import org.fortiss.tooling.kernel.ui.internal.introspection.details.handler.EclipseResourceStorageProviderIntrospectionDetailsUIHandler; import org.fortiss.tooling.kernel.ui.internal.introspection.details.handler.EditPartFactoryServiceIntrospectionDetailsUIHandler; @@ -46,7 +43,6 @@ import org.fortiss.tooling.kernel.ui.internal.introspection.details.handler.Pers import org.fortiss.tooling.kernel.ui.internal.introspection.details.handler.PrototypeServiceIntrospectionDetailsUIHandler; import org.fortiss.tooling.kernel.ui.internal.introspection.details.handler.TransformationServiceIntrospectionDetailsUIHandler; import org.fortiss.tooling.kernel.ui.internal.introspection.items.AllocationEditPartFactoryServiceIntrospectionDetailsItem; -import org.fortiss.tooling.kernel.ui.internal.introspection.items.ConstraintUIServiceIntrospectionDetailsItem; import org.fortiss.tooling.kernel.ui.internal.introspection.items.ContextMenuServiceIntrospectionDetailsItem; import org.fortiss.tooling.kernel.ui.internal.introspection.items.EditPartFactoryServiceIntrospectionDetailsItem; import org.fortiss.tooling.kernel.ui.internal.introspection.items.ModelEditorBindingServiceIntrospectionDetailsItem; @@ -100,10 +96,6 @@ public final class KISSDetailsUIRegistry { new PersistencyServiceIntrospectionDetailsUIHandler()); registerHandler(TransformationServiceIntrospectionDetailsItem.class, new TransformationServiceIntrospectionDetailsUIHandler()); - registerHandler(ConstraintVerificationServiceIntrospectionDetailsItem.class, - new ConstraintServiceIntrospectionDetailsUIHandler()); - registerHandler(ConstraintUIServiceIntrospectionDetailsItem.class, - new ConstraintUIServiceIntrospectionDetailsUIHandler()); } /** Registers the given composite */ diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/handler/ConstraintServiceIntrospectionDetailsUIHandler.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/handler/ConstraintServiceIntrospectionDetailsUIHandler.java deleted file mode 100644 index 8695a09d5a6047d1a478c1d48a49f1e3072caadd..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/handler/ConstraintServiceIntrospectionDetailsUIHandler.java +++ /dev/null @@ -1,90 +0,0 @@ -/*-------------------------------------------------------------------------+ -| 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.introspection.details.handler; - -import org.conqat.ide.commons.ui.jface.TreeContentProviderBase; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.TableLabelProviderBase; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.ScrolledComposite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.swt.widgets.TreeColumn; -import org.fortiss.tooling.kernel.extension.IConstraint; -import org.fortiss.tooling.kernel.introspection.items.ConstraintVerificationServiceIntrospectionDetailsItem; -import org.fortiss.tooling.kernel.service.IConstraintService; - -/** - * Introspection UI handler for the {@link IConstraintService}. - * - * @author hoelzl - */ -public final class ConstraintServiceIntrospectionDetailsUIHandler - extends EObjectAwareIntrospectionDetailsUIHandlerBase { - - /** {@inheritDoc} */ - @Override - public Control createComposite(ScrolledComposite parent) { - String heading = "Type to search registered constraint:"; - return createFilteredTreeInTabFolder(parent, heading, "", "Registered constraints"); - } - - /** {@inheritDoc} */ - @Override - protected void createTreeColumns(Tree tree) { - TreeColumn col0 = new TreeColumn(tree, SWT.LEFT); - col0.setText("Constraint"); - col0.setWidth(900); - } - - /** {@inheritDoc} */ - @Override - protected ITreeContentProvider createContentProvider() { - return new TreeContentProviderBase() { - - /** {@inheritDoc} */ - @Override - public Object[] getChildren(Object parentElement) { - if(parentElement == getInputObject()) { - return getInputObject().getHandlerKeyClasses().toArray(); - } - return new Object[0]; - } - }; - } - - /** {@inheritDoc} */ - @Override - protected ITableLabelProvider createLabelProvider() { - return new TableLabelProvider(); - } - - /** Table label provider for handler registrations with two classes. */ - protected static class TableLabelProvider extends TableLabelProviderBase { - /** {@inheritDoc} */ - @Override - public String getColumnText(Object element, int columnIndex) { - return element instanceof IConstraint ? element.getClass().getName() : ""; - } - } - - /** {@inheritDoc} */ - @Override - protected ConstraintVerificationServiceIntrospectionDetailsItem getInputObject() { - return (ConstraintVerificationServiceIntrospectionDetailsItem)dataItem; - } -} diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/handler/ConstraintUIServiceIntrospectionDetailsUIHandler.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/handler/ConstraintUIServiceIntrospectionDetailsUIHandler.java deleted file mode 100644 index bc5fff880e84fac2fa8e1bc43b67cfb2ce907f97..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/handler/ConstraintUIServiceIntrospectionDetailsUIHandler.java +++ /dev/null @@ -1,103 +0,0 @@ -/*-------------------------------------------------------------------------+ -| 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.introspection.details.handler; - -import java.util.Map.Entry; - -import org.conqat.ide.commons.ui.jface.TreeContentProviderBase; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.TableLabelProviderBase; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.ScrolledComposite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.swt.widgets.TreeColumn; -import org.fortiss.tooling.kernel.service.IConnectionCompositorService; -import org.fortiss.tooling.kernel.ui.internal.introspection.items.ConstraintUIServiceIntrospectionDetailsItem; - -/** - * Introspection UI handler for the {@link IConnectionCompositorService}. - * - * @author hoelzl - */ -public final class ConstraintUIServiceIntrospectionDetailsUIHandler - extends EObjectAwareIntrospectionDetailsUIHandlerBase { - - /** {@inheritDoc} */ - @Override - public Control createComposite(ScrolledComposite parent) { - String heading = "Type to search registered constraint UI's:"; - return createFilteredTreeInTabFolder(parent, heading, "", "Registered constraint UI's"); - } - - /** {@inheritDoc} */ - @Override - protected void createTreeColumns(Tree tree) { - TreeColumn col0 = new TreeColumn(tree, SWT.LEFT); - col0.setText("Constraint UI"); - col0.setWidth(600); - - TreeColumn col1 = new TreeColumn(tree, SWT.LEFT); - col1.setText("Matching constraint"); - col1.setWidth(300); - } - - /** {@inheritDoc} */ - @Override - protected ITreeContentProvider createContentProvider() { - return new TreeContentProviderBase() { - - /** {@inheritDoc} */ - @Override - public Object[] getChildren(Object parentElement) { - if(parentElement == getInputObject()) { - return getInputObject().getHandlerKeyClasses().toArray(); - } - return new Object[0]; - } - }; - } - - /** {@inheritDoc} */ - @Override - protected ITableLabelProvider createLabelProvider() { - return new TableLabelProvider(); - } - - /** Table label provider for handler registrations with two classes. */ - protected static class TableLabelProvider extends TableLabelProviderBase { - /** {@inheritDoc} */ - @Override - public String getColumnText(Object element, int columnIndex) { - if(element instanceof Entry<?, ?>) { - switch(columnIndex) { - case 0: - return (String)((Entry<?, ?>)element).getKey(); - case 1: - return ((Class<?>)((Entry<?, ?>)element).getValue()).getName(); - } - } - return ""; - } - } - - /** {@inheritDoc} */ - @Override - protected ConstraintUIServiceIntrospectionDetailsItem getInputObject() { - return (ConstraintUIServiceIntrospectionDetailsItem)dataItem; - } -} diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/introspection/items/ConstraintUIServiceIntrospectionDetailsItem.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/introspection/items/ConstraintUIServiceIntrospectionDetailsItem.java deleted file mode 100644 index c143c6113a5bc3c69c6652055e6f703a170d9794..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/introspection/items/ConstraintUIServiceIntrospectionDetailsItem.java +++ /dev/null @@ -1,52 +0,0 @@ -/*-------------------------------------------------------------------------+ -| 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.introspection.items; - -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import org.fortiss.tooling.kernel.introspection.IIntrospectionDetailsItem; -import org.fortiss.tooling.kernel.ui.extension.IConstraintUI; -import org.fortiss.tooling.kernel.ui.service.IConstraintUIService; - -/** - * {@link IIntrospectionDetailsItem} for {@link IConstraintUIService}. - * - * @author hoelzl - */ -public final class ConstraintUIServiceIntrospectionDetailsItem - implements IIntrospectionDetailsItem { - - /** Read-only copy of the services handler maps. */ - protected final Map<String, Class<? extends IConstraintUI>> handlerMap; - - /** Constructor. */ - public ConstraintUIServiceIntrospectionDetailsItem( - Map<String, Class<? extends IConstraintUI>> handlerMap) { - this.handlerMap = handlerMap; - } - - /** Returns the registered constraint UI's along with their non-UI counterparts. */ - public Set<Entry<String, Class<? extends IConstraintUI>>> getHandlerKeyClasses() { - return handlerMap.entrySet(); - } - - /** Returns the handler list for the given registration class. */ - public Class<? extends IConstraintUI> getHandler(String regClass) { - return handlerMap.get(regClass); - } -} diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/views/ConstraintMenu.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/views/ConstraintMenu.java deleted file mode 100644 index 55bb88600b21e832109460f14fe8f09a18056fcc..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/views/ConstraintMenu.java +++ /dev/null @@ -1,315 +0,0 @@ -/*-------------------------------------------------------------------------+ -| 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.views; - -import static java.util.Collections.emptyList; -import static org.eclipse.jface.resource.ImageDescriptor.createFromImage; - -import java.util.List; -import java.util.stream.Collectors; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.ActionContributionItem; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IContributionItem; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.DecorationOverlayIcon; -import org.eclipse.jface.viewers.IDecoration; -import org.eclipse.swt.graphics.Image; -import org.fortiss.tooling.kernel.model.constraints.ConstraintInstance; -import org.fortiss.tooling.kernel.model.constraints.ErrorConstraintInstanceStatus; -import org.fortiss.tooling.kernel.model.constraints.FailedConstraintInstanceStatus; -import org.fortiss.tooling.kernel.model.constraints.IConstrained; -import org.fortiss.tooling.kernel.model.constraints.IConstraintInstanceStatus; -import org.fortiss.tooling.kernel.model.constraints.OutdatedConstraintInstanceStatus; -import org.fortiss.tooling.kernel.model.constraints.SuccessConstraintInstanceStatus; -import org.fortiss.tooling.kernel.service.ICommandStackService; -import org.fortiss.tooling.kernel.ui.ESharedImages; -import org.fortiss.tooling.kernel.ui.ToolingKernelUIActivator; -import org.fortiss.tooling.kernel.ui.extension.IContextMenuContributor; -import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler; -import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider; -import org.fortiss.tooling.kernel.ui.service.IConstraintUIService; -import org.fortiss.tooling.kernel.ui.service.IConstraintUIService.IFix; -import org.fortiss.tooling.kernel.ui.service.IContextMenuService; -import org.fortiss.tooling.kernel.ui.service.IModelEditorBindingService; -import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService; - -/** - * Context menu for constraints. - * - * @author hoelzl - */ -public class ConstraintMenu implements IContextMenuContributor { - - /** {@inheritDoc} */ - @Override - public List<IContributionItem> getContributedItems(EObject selectedObject, - ContextMenuContextProvider contextProvider) { - if(!(selectedObject instanceof IConstrained)) { - return emptyList(); - } - return ((IConstrained)selectedObject).getConstraintInstances().stream() - .filter(ci -> shouldGetMenuEntry(ci)) - .map(ci -> constraintToAction(ci, (IConstrained)selectedObject)) - .collect(Collectors.toList()); - } - - /** - * <code>true</code> iff <code>ci</code> should get a menu entry, i.e., if not successful and - * activated. - */ - private boolean shouldGetMenuEntry(ConstraintInstance ci) { - IConstraintInstanceStatus status = IConstraintUIService.getInstance().getStatus(ci); - return !(status == null || status instanceof SuccessConstraintInstanceStatus); - } - - /** - * Returns the submenu or menu entry corresponding to the status of <code>ci</code>. - * <code>elt</code> is needed to prevent displaying an entry to go to <code>elt</code> (not - * hurtful, but useless, since the user is already seeing it). - */ - private IContributionItem constraintToAction(ConstraintInstance ci, IConstrained elt) { - IConstraintInstanceStatus status = IConstraintUIService.getInstance().getStatus(ci); - ConstraintSubMenuBase m; - if(status instanceof FailedConstraintInstanceStatus) { - m = new KnowMoreAboutFailingConstraintAction(ci, elt); - } else if(status instanceof ErrorConstraintInstanceStatus) { - m = new CheckErrorConstraintAction(ci, elt); - } else if(status instanceof OutdatedConstraintInstanceStatus) { - m = new CheckOutdatedConstraintAction(ci, elt); - } else { - // should not happen - return null; - } - if(m.getItems().length == 0) { - Action a = new Action(m.getMenuText(), m.getImageDescriptor()) { - // nothing to do - }; - return new ActionContributionItem(a); - } - if(m.getItems().length == 1 && m.getTopActionContribution() != null) { - IAction uniqueAction = m.getTopActionContribution().getAction(); - String txt = m.getMenuText(); - String newText = txt + " -> " + uniqueAction.getText(); - uniqueAction.setText(newText); - uniqueAction.setImageDescriptor(m.getImageDescriptor()); - return m.getTopActionContribution(); - } - return m; - } - - /** {@inheritDoc} */ - @Override - public String getMenuSectionID() { - return IContextMenuService.BEFORE_GLOBAL_MENU_SECTION_ID; - } - - /** Action to "go to" a given constrained element. */ - private static class GoToConstrained extends Action { - - /** The constrained element to open. */ - private IConstrained cstrd; - - /** Constructor. */ - public GoToConstrained(IConstrained cstrd) { - super("Go to " + IModelElementHandlerService.getInstance().getName(cstrd), - createFromImage(IModelElementHandlerService.getInstance().getIcon(cstrd))); - this.cstrd = cstrd; - } - - /** {@inheritDoc} */ - @Override - public void run() { - IModelElementHandler<EObject> handler = - IModelElementHandlerService.getInstance().getModelElementHandler(cstrd); - EObject eltToOpen = - handler == null ? cstrd : handler.handleOpenModelElementRequest(cstrd); - IModelEditorBindingService.getInstance().openInEditor(eltToOpen); - } - } - - /** Get the icon of the prototype. */ - public static String getText(ConstraintInstance ci, String suffix) { - return "\"" + IConstraintUIService.getInstance().getDescription(ci) + "\": " + suffix; - } - - /** Get the icon of the prototype. */ - public static ImageDescriptor getIcon(ConstraintInstance ci, ImageDescriptor overlay) { - ImageDescriptor imgd = IConstraintUIService.getInstance().getIconImageDescriptor(ci); - Image img = imgd == null ? null : imgd.createImage(); - if(img == null) { - if(IConstraintUIService.getInstance().shallDisplayAsWarning(ci)) { - return ESharedImages.WARNING.getImageDescriptor(); - } - return ESharedImages.ERROR.getImageDescriptor(); - } - ImageDescriptor[] descriptors = new ImageDescriptor[5]; - descriptors[IDecoration.BOTTOM_LEFT] = overlay; - return new DecorationOverlayIcon(img, descriptors); - } - - /** Get the correct overlay for the given constraint. */ - private static ImageDescriptor getOverlay(ConstraintInstance ci) { - if(IConstraintUIService.getInstance().shallDisplayAsWarning(ci)) { - return ESharedImages.WARNING_OVERLAY.getImageDescriptor(); - } - return ESharedImages.ERROR_OVERLAY.getImageDescriptor(); - } - - /** Base for action involved in a constraint submenu. */ - private static class ConstraintSubMenuBase extends MenuManager { - /** The constraint. */ - protected ConstraintInstance ci; - - /** - * The action to get more information about the constraint status. - * The same action allows to update an outdated constraint status (there is no - * "more information" to get out of an outdated constraint); it is stored in a field to - * allow the "update" action to change the icon and the text going with it. - */ - protected ActionContributionItem moreInfoAction; - - /** Constructor. */ - public ConstraintSubMenuBase(ConstraintInstance ci, IConstrained selectedElt, String suffix, - ImageDescriptor overlay) { - super(getText(ci, suffix), getIcon(ci, overlay), null); - this.ci = ci; - if(IConstraintUIService.getInstance().canOpen(ci)) { - moreInfoAction = new ActionContributionItem(new OpenStatusAction()); - this.add(moreInfoAction); - } - for(IConstrained cstrd : ci.getConstraineds()) { - if(!selectedElt.equals(cstrd)) { - this.add(new ActionContributionItem(new GoToConstrained(cstrd))); - } - } - } - - /** - * @return The top action contribution. Useful in case we get aware that there is only one - * contribution and we therefore want to present it without going through a submenu. - */ - public ActionContributionItem getTopActionContribution() { - if(this.getItems()[0] instanceof ActionContributionItem) { - return (ActionContributionItem)this.getItems()[0]; - } - return null; - } - - /** Action to update a constraint. Assumes the status *can be open*. */ - protected class OpenStatusAction extends Action { - - /** Constructor. */ - public OpenStatusAction() { - super("More information...", - ToolingKernelUIActivator.getImageDescriptor("icons/info.gif")); - } - - /** {@inheritDoc} */ - @Override - public void run() { - IConstraintInstanceStatus status = IConstraintUIService.getInstance().getStatus(ci); - if(status instanceof OutdatedConstraintInstanceStatus) { - ICommandStackService.getInstance().runAsCommand(ci, new Runnable() { - @Override - public void run() { - IConstraintUIService.getInstance().openStatus(ci); - } - }); - } else { - IConstraintUIService.getInstance().openStatus(ci); - } - } - } - } - - /** Action for creating a new prototype. */ - private static class CheckOutdatedConstraintAction extends ConstraintSubMenuBase { - - /** Constructor. */ - public CheckOutdatedConstraintAction(ConstraintInstance ci, IConstrained selectedElt) { - super(ci, selectedElt, "Outdated", ESharedImages.WARNING_OVERLAY.getImageDescriptor()); - IAction action = moreInfoAction.getAction(); - action.setImageDescriptor(ToolingKernelUIActivator.getImageDescriptor("icons/ok.png")); - action.setText("Check"); - } - } - - /** Action for knowing more about some unsuccessful constraint. */ - private static class KnowMoreAboutUnsuccessfulConstraintAction extends ConstraintSubMenuBase { - - /** Constructor. */ - public KnowMoreAboutUnsuccessfulConstraintAction(ConstraintInstance ci, - IConstrained selectedElt, String suffix) { - super(ci, selectedElt, suffix, getOverlay(ci)); - List<IFix> fixes = IConstraintUIService.getInstance().fixes(ci); - if(fixes != null) { - for(IFix fix : fixes) { - this.add(new ActionContributionItem(new FixAction(fix))); - } - } - } - - /** Action to update a constraint. */ - private class FixAction extends Action { - - /** The fix to achieve. */ - IFix fix; - - /** Constructor. */ - public FixAction(IFix fix) { - super(fix.getDescription(), - ToolingKernelUIActivator.getImageDescriptor("icons/fix.png")); - this.fix = fix; - } - - /** {@inheritDoc} */ - @Override - public void run() { - ICommandStackService.getInstance().runAsCommand(ci, new Runnable() { - @Override - public void run() { - fix.runFix(IConstraintUIService.getInstance().getStatus(ci)); - } - }); - } - } - } - - /** Action for knowing more about a failing constraint. */ - private static class KnowMoreAboutFailingConstraintAction - extends KnowMoreAboutUnsuccessfulConstraintAction { - - /** Constructor. */ - public KnowMoreAboutFailingConstraintAction(ConstraintInstance ci, - IConstrained selectedElt) { - super(ci, selectedElt, "Unsatisfied"); - } - } - - /** Action for knowing more about a constraint yielding an error. */ - private static class CheckErrorConstraintAction - extends KnowMoreAboutUnsuccessfulConstraintAction { - - /** Constructor. */ - public CheckErrorConstraintAction(ConstraintInstance ci, IConstrained selectedElt) { - super(ci, selectedElt, "Error encountered"); - } - } -} diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/service/IConstraintUIService.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/service/IConstraintUIService.java deleted file mode 100644 index 07df6b9553bf04f8c414c976dc630e6a1dd5ec96..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/service/IConstraintUIService.java +++ /dev/null @@ -1,112 +0,0 @@ -package org.fortiss.tooling.kernel.ui.service; - -import java.util.List; -import java.util.Set; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.fortiss.tooling.kernel.extension.IConstraint; -import org.fortiss.tooling.kernel.extension.data.ITopLevelElement; -import org.fortiss.tooling.kernel.model.constraints.ConstraintInstance; -import org.fortiss.tooling.kernel.model.constraints.IConstraintInstanceContainer; -import org.fortiss.tooling.kernel.model.constraints.IConstraintInstanceStatus; -import org.fortiss.tooling.kernel.service.IConstraintService; -import org.fortiss.tooling.kernel.ui.extension.IConstraintUI; -import org.fortiss.tooling.kernel.ui.internal.ConstraintUIService; - -/** - * GUI aspects of {@link IConstraintService}. - * - * @author aravantinos - */ -public interface IConstraintUIService { - - /** Returns the service instance. */ - public static IConstraintUIService getInstance() { - return ConstraintUIService.getInstance(); - } - - /** Action to take when trying to open the (status of the given) constraint instance. */ - void openStatus(ConstraintInstance ci); - - /** True if the (status of the) given constraint instance can be open. */ - boolean canOpen(ConstraintInstance ci); - - /** - * Install the given constraint instance: install notifiers and triggers an "onOutdate" event. - */ - void install(ConstraintInstance ci); - - /** - * True if a failure of the given constraint instance shall be displayed as a warning instead of - * as an error. - */ - boolean shallDisplayAsWarning(ConstraintInstance ci); - - /** Returns a description for the given constraint. */ - String getDescription(Class<? extends IConstraint> c); - - /** Returns a description for the given constraint instance. */ - String getDescription(ConstraintInstance ci); - - /** Returns the image descriptor to be used as icon image for the given constraint instance. */ - ImageDescriptor getIconImageDescriptor(ConstraintInstance c); - - /** - * Browse the elements in the context of the given container, adds constraints instances if - * relevant and install them. - */ - void addMissingConstraintInstances(IConstraintInstanceContainer cstrContainer); - - /** - * Returns the status of the given constraint instance, possibly returns <code>null</code> if - * the constraint instance is not activated. - */ - IConstraintInstanceStatus getStatus(ConstraintInstance ci); - - /** - * Returns a list of possible automatic fixes for <code>ci</code>. A constraint instance should - * be candidate to fixing if it is anything but successful or outdated. - */ - List<IFix> fixes(ConstraintInstance ci); - - /** Interface for a "fix". */ - public interface IFix { - /** - * Description of the fix. Useful to allow the user distinguish the fix in case there are - * several. - */ - String getDescription(); - - /** Fixes (the constraint instance of) <code>status</code>. */ - void runFix(IConstraintInstanceStatus status); - } - - /** Returns a list of all available constraints. */ - Set<Class<? extends IConstraint>> getAllConstraints(); - - /** Returns a list of constraints which should always be activated. */ - Set<Class<? extends IConstraint>> getAlwaysActivatedConstraints(); - - /** Returns a list of all constraints which are activated for the given top element. */ - Set<Class<? extends IConstraint>> getActivatedConstraints(ITopLevelElement top); - - /** - * Activates the constraint <code>cstr</code> in the context of the given constraints container. - */ - void activate(Class<? extends IConstraint> cstr, IConstraintInstanceContainer cstrContainer); - - /** - * Deactivates the constraint <code>cstr</code> in the context of the given constraints - * container. - * The constraint container is necessary to retrieve the constraints whose markers need to be - * deactivated. - */ - void deactivate(Class<? extends IConstraint> cstr, IConstraintInstanceContainer cstrContainer); - - /** - * Registers the constraint UI part with the kernel and associates it with its non-UI - * counterpart. The non-UI counterpart should however be registered separately. - */ - void registerConstraintUI(Class<? extends IConstraintUI> cstrUI, - Class<? extends IConstraint> cstr); -} diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/util/ConstraintsUIUtils.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/util/ConstraintsUIUtils.java deleted file mode 100644 index 69d5e08bbf768baf2790380e36f1020ef826a33e..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/util/ConstraintsUIUtils.java +++ /dev/null @@ -1,337 +0,0 @@ -/*-------------------------------------------------------------------------+ -| 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 static org.fortiss.tooling.kernel.extension.data.IConstraintViolation.SEVERITY_DIRECT_COMPARATOR; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.function.Consumer; -import java.util.function.Function; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.ColumnLabelProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.fortiss.tooling.kernel.extension.IConstraint; -import org.fortiss.tooling.kernel.extension.data.IConstraintViolation; -import org.fortiss.tooling.kernel.extension.data.IConstraintViolation.ESeverity; -import org.fortiss.tooling.kernel.model.constraints.ConstraintInstance; -import org.fortiss.tooling.kernel.model.constraints.ErrorConstraintInstanceStatus; -import org.fortiss.tooling.kernel.model.constraints.FailedConstraintInstanceStatus; -import org.fortiss.tooling.kernel.model.constraints.IConstrained; -import org.fortiss.tooling.kernel.model.constraints.IConstraintInstanceContainer; -import org.fortiss.tooling.kernel.model.constraints.IConstraintInstanceStatus; -import org.fortiss.tooling.kernel.model.constraints.OutdatedConstraintInstanceStatus; -import org.fortiss.tooling.kernel.model.constraints.SuccessConstraintInstanceStatus; -import org.fortiss.tooling.kernel.ui.service.IConstraintUIService; -import org.fortiss.tooling.kernel.ui.service.IConstraintUIService.IFix; -import org.fortiss.tooling.kernel.utils.EcoreUtils; - -/** - * Utility functions for constraints. - * - * @author aravantinos - */ -public class ConstraintsUIUtils { - - /** Gathers some statuses by verification status. */ - public static class ClassifiedStatuses { - - /** Failed constraints. */ - public List<FailedConstraintInstanceStatus> failedStatuses; - - /** Error statuses (constraint could not be checked). */ - public List<ErrorConstraintInstanceStatus> errorStatuses; - - /** Outdated statuses. */ - public List<OutdatedConstraintInstanceStatus> outdatedStatuses; - - /** Successful constraints. */ - public List<SuccessConstraintInstanceStatus> successStatuses; - - /** Constructor. */ - public ClassifiedStatuses() { - failedStatuses = new ArrayList<FailedConstraintInstanceStatus>(); - errorStatuses = new ArrayList<ErrorConstraintInstanceStatus>(); - outdatedStatuses = new ArrayList<OutdatedConstraintInstanceStatus>(); - successStatuses = new ArrayList<SuccessConstraintInstanceStatus>(); - } - } - - /** Returns {@link ClassifiedStatuses} corresponding to <code>constrained</code>. */ - public static ClassifiedStatuses getClassifiedStatuses(IConstrained constrained) { - ClassifiedStatuses res = new ClassifiedStatuses(); - for(ConstraintInstance constraint : constrained.getConstraintInstances()) { - IConstraintInstanceStatus status = - IConstraintUIService.getInstance().getStatus(constraint); - if(status instanceof FailedConstraintInstanceStatus) { - res.failedStatuses.add((FailedConstraintInstanceStatus)status); - } - if(status instanceof ErrorConstraintInstanceStatus) { - res.errorStatuses.add((ErrorConstraintInstanceStatus)status); - } - if(status instanceof OutdatedConstraintInstanceStatus) { - res.outdatedStatuses.add((OutdatedConstraintInstanceStatus)status); - } - if(status instanceof SuccessConstraintInstanceStatus) { - res.successStatuses.add((SuccessConstraintInstanceStatus)status); - } - } - return res; - } - - /** Returns {@link ESeverity} corresponding to the status of the constraint <code>c</code> */ - public static ESeverity getConstraintSeverity(ConstraintInstance c) { - IConstraintInstanceStatus status = IConstraintUIService.getInstance().getStatus(c); - if(IConstraintUIService.getInstance().shallDisplayAsWarning(c)) { - if(status instanceof FailedConstraintInstanceStatus || - status instanceof OutdatedConstraintInstanceStatus) { - return ESeverity.WARNING; - } - return ESeverity.lowest(); - } - if(status instanceof FailedConstraintInstanceStatus) { - return ESeverity.ERROR; - } else if(status instanceof ErrorConstraintInstanceStatus) { - return ESeverity.ERROR; - } else if(status instanceof OutdatedConstraintInstanceStatus) { - return ESeverity.WARNING; - } else { - return ESeverity.lowest(); - } - } - - /** Returns severity corresponding to the status of the constraints of <code>c</code>. */ - public static ESeverity getSeverity(IConstrained c) { - try { - return c.getConstraintInstances().stream().map(cstr -> getConstraintSeverity(cstr)) - .sorted(IConstraintViolation.SEVERITY_DIRECT_COMPARATOR).findFirst().get(); - } catch(Exception e) { - return null; - } - } - - /** - * Returns the maximum severity between <code>sev</code> and the severity resulting of possibly - * unsatisfied constraints on <code>modelElement</code>. - */ - public static ESeverity augmentSeverityWithConstraintSeverity(ESeverity sev, - EObject modelElement) { - if(modelElement instanceof IConstrained) { - ESeverity sev2 = ConstraintsUIUtils.getSeverity((IConstrained)modelElement); - if(sev == null || (sev2 != null && SEVERITY_DIRECT_COMPARATOR.compare(sev2, sev) < 0)) { - sev = sev2; - } - } - return sev == null ? ESeverity.lowest() : sev; - } - - /** - * Sends (kernel-specific) refresh notifications to the constrained elements to trigger a - * refresh of the marker decorations. - */ - public static void triggerMarkersRefresh(ConstraintInstance ci) { - List<IConstrained> constraineds = new ArrayList<IConstrained>(); - // We first collect separately the constrained objects because - unfortunately for some - // unknown reason - the following notification seems to trigger a change of the list of - // constrained objects. - constraineds.addAll(ci.getConstraineds()); - constraineds.stream().forEach(constrained -> { - if(constrained != null) { - EcoreUtils.postRefreshNotification(constrained); - } - }); - } - - /** - * Sends (kernel-specific) refresh notifications to every element constrained by a constraint - * instance of the given list. - */ - public static void triggerMarkersRefresh(List<ConstraintInstance> cis) { - Set<IConstrained> constraineds = new HashSet<IConstrained>(); - for(ConstraintInstance ci : cis) { - for(IConstrained cstrd : ci.getConstraineds()) { - if(cstrd != null) { - constraineds.add(cstrd); - } - } - } - constraineds.stream().forEach(cstrd -> EcoreUtils.postRefreshNotification(cstrd)); - } - - /** - * Calls <code>triggerMarkersRefresh</code> on every constraint of <code>cstrContainer</code> - * matching <code>id</code>. - */ - public static void triggerMarkerRefresh(Class<? extends IConstraint> cstrClass, - IConstraintInstanceContainer cstrContainer) { - for(ConstraintInstance c : cstrContainer.getConstraintInstances()) { - if(c.getConstraintName().equals(cstrClass.getName())) { - triggerMarkersRefresh(c); - } - } - } - - /** Returns a standard text describing the status of <code>c</code>. */ - public static String getText(ConstraintInstance c) { - if(c == null) { - return ""; - } - String mainMsg = "ERROR"; - IConstraintInstanceStatus status = IConstraintUIService.getInstance().getStatus(c); - if(status == null) { - mainMsg = "NOT APPLICABLE"; - } else if(status instanceof SuccessConstraintInstanceStatus) { - mainMsg = "SUCCESS"; - } else if(status instanceof FailedConstraintInstanceStatus) { - mainMsg = "FAIL"; - } else if(status instanceof OutdatedConstraintInstanceStatus) { - mainMsg = "OUTDATED"; - } - return mainMsg; - } - - /** Returns a standard "hint" indicating possible action on the status of <code>c</code>. */ - public static String getHint(ConstraintInstance c) { - if(c == null) { - return ""; - } - IConstraintInstanceStatus status = IConstraintUIService.getInstance().getStatus(c); - if(status instanceof OutdatedConstraintInstanceStatus) { - return "(double-click to update)"; - } else if(IConstraintUIService.getInstance().canOpen(c)) { - return "(double-click for more details)"; - } - return ""; - } - - /** Returns a standard color corresponding to the status of <code>c</code>. */ - public static Color getColor(ConstraintInstance c) { - Display display = Display.getCurrent(); - if(c == null) { - return null; - } - IConstraintInstanceStatus status = IConstraintUIService.getInstance().getStatus(c); - if(status == null) { - return null; - } else if(status instanceof FailedConstraintInstanceStatus || - status instanceof ErrorConstraintInstanceStatus) { - return display.getSystemColor(SWT.COLOR_RED); - } else if(status instanceof SuccessConstraintInstanceStatus) { - return display.getSystemColor(SWT.COLOR_GREEN); - } - return display.getSystemColor(SWT.COLOR_GRAY); - } - - /** A label provider for the status of an {@link ConstraintInstance}. */ - public static class StatusLabelProvider extends ColumnLabelProvider { - - /** See constructor. */ - private boolean withHint; - - /** Function to retrieve a constraint from the embedded objects. */ - private Function<Object, ConstraintInstance> getConstraint; - - /** - * Constructor. - * - * @param withHint - * <code>true</code> if you want to display hints like "double-click for more - * details" in the status. If you set it to <code>true</code>, you are - * responsible for providing the corresponding behaviour (e.g., that - * double-clicking will open the status). - * @param getConstraint - * Function returning a constraint from the object to be provided. - */ - public StatusLabelProvider(boolean withHint, - Function<Object, ConstraintInstance> getConstraint) { - super(); - this.getConstraint = getConstraint; - this.withHint = withHint; - } - - /** {@inheritDoc} */ - @Override - public String getText(Object element) { - ConstraintInstance cstr = getConstraint.apply(element); - // the following call CANNOT BE INLINED - String mainMsg = ConstraintsUIUtils.getText(cstr); - return mainMsg + (withHint ? " " + ConstraintsUIUtils.getHint(cstr) : ""); - } - - /** {@inheritDoc} */ - @Override - public Color getBackground(Object element) { - ConstraintInstance cstr = getConstraint.apply(element); - return ConstraintsUIUtils.getColor(cstr); - } - } - - /** Returns <code>true</code> iff <code>constraint</code> is active. */ - public static boolean isConstraintActive(ConstraintInstance constraint) { - return IConstraintUIService.getInstance().getStatus(constraint) != null; - } - - /** - * Standard warning message to display when a resource-consuming check is activated for the - * first time. - */ - public static void displayTimeConsumptionWarning(Class<? extends IConstraint> cstrClass) { - Display d = Display.getCurrent(); - d = d == null ? Display.getDefault() : d; - Shell shell = d.getActiveShell(); - String title = "Background operation about to start"; - String msg = "AutoFOCUS will now go through your project to check that "; - msg += IConstraintUIService.getInstance().getDescription(cstrClass) + ". "; - msg += "This might slow down your system.\n\n"; - msg += "Note that this is a one-time thing: once the check is activated, "; - msg += "subsequent runs should be unnoticed."; - MessageDialog.openWarning(shell, title, msg); - } - - /** Base for fixes. */ - public static class FixBase implements IFix { - /** The description. */ - private String description; - - /** The fix itself. */ - private Consumer<IConstraintInstanceStatus> fix; - - /** Constructor. */ - public FixBase(String description, Consumer<IConstraintInstanceStatus> fix) { - this.description = description; - this.fix = fix; - } - - /** {@inheritDoc} */ - @Override - public String getDescription() { - return description; - } - - /** {@inheritDoc} */ - @Override - public void runFix(IConstraintInstanceStatus status) { - fix.accept(status); - } - } -}