diff --git a/org.fortiss.tooling.base.ui/META-INF/MANIFEST.MF b/org.fortiss.tooling.base.ui/META-INF/MANIFEST.MF index 42280c20dac8696d2d983387342bc6c3f3fef1cb..2492dbdeffc8235f398f3633019d7c9d9dcbe6f0 100644 --- a/org.fortiss.tooling.base.ui/META-INF/MANIFEST.MF +++ b/org.fortiss.tooling.base.ui/META-INF/MANIFEST.MF @@ -17,7 +17,6 @@ Export-Package: org.fortiss.tooling.base.ui, org.fortiss.tooling.base.ui.annotation.view, org.fortiss.tooling.base.ui.annotation.view.generic, org.fortiss.tooling.base.ui.annotation.view.generic.filter, - org.fortiss.tooling.base.ui.compose, org.fortiss.tooling.base.ui.contentprovider, org.fortiss.tooling.base.ui.dialog, org.fortiss.tooling.base.ui.dnd.gef, diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/compose/.ratings b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/compose/.ratings deleted file mode 100644 index ef161cfb92f38f97856ab39e1691224e0f897f6c..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/compose/.ratings +++ /dev/null @@ -1 +0,0 @@ -ConstraintBasedProcessCompositor.java 6b98bc9c8096ff6553ffc49040a0919dadb20bae GREEN diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/compose/ConstraintBasedProcessCompositor.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/compose/ConstraintBasedProcessCompositor.java deleted file mode 100644 index 6b98bc9c8096ff6553ffc49040a0919dadb20bae..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/compose/ConstraintBasedProcessCompositor.java +++ /dev/null @@ -1,100 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2011 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.base.ui.compose; - -import static org.eclipse.emf.ecore.util.EcoreUtil.delete; -import static org.fortiss.tooling.base.ui.utils.ConstraintsBaseUIUtils.deactivateConfiguration; -import static org.fortiss.tooling.base.utils.ConstraintsBaseUtils.getDefaultConfig; -import static org.fortiss.tooling.base.utils.ConstraintsBaseUtils.isDefaultConfiguration; - -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.eclipse.emf.ecore.EObject; -import org.fortiss.tooling.base.model.element.ConstraintConfiguration; -import org.fortiss.tooling.base.model.element.IConstraintBasedProcess; -import org.fortiss.tooling.kernel.extension.IElementCompositor; -import org.fortiss.tooling.kernel.extension.data.IElementCompositionContext; -import org.fortiss.tooling.kernel.extension.data.Prototype; -import org.fortiss.tooling.kernel.model.IProjectRootElement; -import org.fortiss.tooling.kernel.model.constraints.IConstraintInstanceContainer; - -/** - * {@link IElementCompositor} implementation for the {@link IProjectRootElement} s. - * - * @author hoelzl - */ -public class ConstraintBasedProcessCompositor<CBP extends IConstraintBasedProcess> - implements IElementCompositor<CBP> { - - /** {@inheritDoc} */ - @Override - public boolean canCompose(CBP container, EObject contained, - IElementCompositionContext context) { - return contained instanceof ConstraintConfiguration; - } - - /** {@inheritDoc} */ - @Override - public boolean compose(CBP container, EObject contained, IElementCompositionContext context) { - ConstraintConfiguration config = (ConstraintConfiguration)contained; - Stream<ConstraintConfiguration> configNamesStream = container.getConfigurations().stream(); - List<String> existingNames = - configNamesStream.map(c -> c.getName()).collect(Collectors.toList()); - String name = config.getName(); - while(existingNames.contains(name)) { - name += " bis"; - } - config.setName(name); - container.getConfigurations().add(config); - return true; - } - - /** {@inheritDoc} */ - @Override - public boolean canComposePrototype(Prototype prototype) { - // As of now constraint configurations should never be added by prototype. - return false; - } - - /** {@inheritDoc} */ - @Override - public boolean canDecompose(EObject contained) { - return contained instanceof ConstraintConfiguration && - !isDefaultConfiguration((ConstraintConfiguration)contained); - } - - /** {@inheritDoc} */ - @Override - public boolean decompose(EObject contained) { - if(contained.eContainer() instanceof IConstraintBasedProcess) { - IConstraintBasedProcess cbdp = (IConstraintBasedProcess)contained.eContainer(); - if(contained.equals(cbdp.getCurrentObjective())) { - ConstraintConfiguration defaultConfig = getDefaultConfig(cbdp); - cbdp.setCurrentObjective(defaultConfig); - if(cbdp.eContainer() instanceof IConstraintInstanceContainer) { - IConstraintInstanceContainer cstrContainer = - (IConstraintInstanceContainer)cbdp.eContainer(); - deactivateConfiguration((ConstraintConfiguration)contained, cstrContainer, - defaultConfig); - } - } - } - delete(contained); - return true; - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/ConstraintBasedProcessEditor.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/ConstraintBasedProcessEditor.java deleted file mode 100644 index 155a5a7ac41c668ae7ef978e8be13b83f5abd67d..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/ConstraintBasedProcessEditor.java +++ /dev/null @@ -1,997 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2011 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.base.ui.editor; - -import static java.util.stream.Collectors.toList; -import static org.eclipse.core.runtime.IStatus.ERROR; -import static org.eclipse.emf.ecore.util.EcoreUtil.delete; -import static org.eclipse.jface.dialogs.ErrorDialog.openError; -import static org.fortiss.tooling.base.ui.editor.ConstraintBasedProcessEditorHelper.adjustColorIndex; -import static org.fortiss.tooling.base.ui.utils.ConstraintsBaseUIUtils.activateConfiguration; -import static org.fortiss.tooling.base.ui.utils.ConstraintsBaseUIUtils.deactivateConfiguration; -import static org.fortiss.tooling.base.utils.ConstraintsBaseUtils.DEFAULT_CONFIGURATION_NAME; -import static org.fortiss.tooling.base.utils.ConstraintsBaseUtils.getActiveConfigurationsTransitively; -import static org.fortiss.tooling.base.utils.ConstraintsBaseUtils.getActiveConstraintsTransitively; -import static org.fortiss.tooling.base.utils.ConstraintsBaseUtils.retrieveDefaultConfig; -import static org.fortiss.tooling.kernel.utils.EcoreUtils.disableNotificationsOf; -import static org.fortiss.tooling.kernel.utils.EcoreUtils.enableNotificationsOf; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Set; - -import org.conqat.ide.commons.ui.jface.TreeContentProviderBase; -import org.eclipse.core.runtime.Status; -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.EObject; -import org.eclipse.emf.ecore.util.EContentAdapter; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.CheckStateChangedEvent; -import org.eclipse.jface.viewers.CheckboxTreeViewer; -import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider; -import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.jface.viewers.ICheckStateListener; -import org.eclipse.jface.viewers.ICheckStateProvider; -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.StyledString; -import org.eclipse.jface.viewers.TextCellEditor; -import org.eclipse.jface.viewers.TreeViewerColumn; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerComparator; -import org.eclipse.jface.viewers.ViewerFilter; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.TreeColumn; -import org.fortiss.tooling.base.model.element.ConstraintConfiguration; -import org.fortiss.tooling.base.model.element.ElementFactory; -import org.fortiss.tooling.base.model.element.IConstraintBasedProcess; -import org.fortiss.tooling.base.ui.ToolingBaseUIActivator; -import org.fortiss.tooling.base.ui.editor.ConstraintBasedProcessEditorHelper.ConfigurationRefWithContextualConfiguration; -import org.fortiss.tooling.base.ui.editor.ConstraintBasedProcessEditorHelper.ConstraintWithContextualConfiguration; -import org.fortiss.tooling.base.ui.editor.ConstraintBasedProcessEditorHelper.GreenFontStyler; -import org.fortiss.tooling.base.ui.editor.ConstraintBasedProcessEditorHelper.NormalFontStyler; -import org.fortiss.tooling.base.ui.editor.ConstraintBasedProcessEditorHelper.RedFontStyler; -import org.fortiss.tooling.base.ui.editor.ConstraintBasedProcessEditorHelper.TreeStructureNode; -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.FailedConstraintInstanceStatus; -import org.fortiss.tooling.kernel.model.constraints.IConstraintInstanceContainer; -import org.fortiss.tooling.kernel.model.constraints.IConstraintInstanceStatus; -import org.fortiss.tooling.kernel.model.constraints.SuccessConstraintInstanceStatus; -import org.fortiss.tooling.kernel.model.constraints.impl.ConstraintInstanceImpl; -import org.fortiss.tooling.kernel.model.constraints.impl.ConstraintNameToChecksumImpl; -import org.fortiss.tooling.kernel.service.IConstraintService; -import org.fortiss.tooling.kernel.service.IElementCompositorService; -import org.fortiss.tooling.kernel.service.IPersistencyService; -import org.fortiss.tooling.kernel.ui.extension.base.EditorBase; -import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider; -import org.fortiss.tooling.kernel.ui.service.IActionService; -import org.fortiss.tooling.kernel.ui.service.IConstraintUIService; -import org.fortiss.tooling.kernel.ui.service.IContextMenuService; - -// TODO Refactor this huge class and provide a dedicated perspective (see #3189) -/** - * Editor for {@link IConstraintBasedProcess}s. - * - * @author aravantinos - */ -public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> - extends EditorBase<CBP> implements ContextMenuContextProvider, ISelectionProvider { - - /** Width of columns to display constraints. */ - private static final int COLUMN_WIDTH = 1300; - - /** {@inheritDoc} */ - @Override - public void addPartPropertyListener(IPropertyChangeListener listener) { - super.addPartPropertyListener(listener); - } - - /** Model context of the edited project. */ - private ITopLevelElement top; - - /** Constraint container for the edited project. */ - private IConstraintInstanceContainer cstrContainer; - - /** Tree viewer for the configurations. */ - private CheckboxTreeViewer treeViewer; - - /** Selection of the tree. */ - private ISelection selection; - - /** List of parent nodes. */ - private List<TreeStructureNode> parentList; - - /** Adapter for refreshing content. */ - private EContentAdapter refreshAdapter; - - /** {@inheritDoc} */ - @Override - public void createPartControl(Composite parent) { - top = IPersistencyService.getInstance().getTopLevelElementFor(editedObject); - getSite().setSelectionProvider(this); - retrieveDefaultConfig(editedObject); - cstrContainer = editedObject.getConstraintInstanceContainer(); - parent.setLayout(new GridLayout(1, true)); - createTree(parent); - MenuManager menuManager = IContextMenuService.getInstance().createDefaultContextMenu(this); - Menu menu = menuManager.createContextMenu(treeViewer.getTree()); - treeViewer.getTree().setMenu(menu); - createCurrentObjectivePart(parent); - refreshAdapter = new EContentAdapter() { - /** {@inheritDoc} */ - @Override - public void notifyChanged(Notification notification) { - treeViewer.refresh(); - } - }; - editedObject.eAdapters().add(refreshAdapter); - treeViewer.addFilter(new ViewerFilter() { - /** {@inheritDoc} */ - @Override - public boolean select(Viewer viewer, Object parentElement, Object element) { - if(element instanceof TreeStructureNode && - parentElement instanceof TreeStructureNode) { - return checkIfDuplicate(viewer, parentElement, element); - } - return true; - } - }); - } - - /** {@inheritDoc} */ - @Override - public void dispose() { - disableNotificationsOf(editedObject); - editedObject.eAdapters().remove(refreshAdapter); - enableNotificationsOf(editedObject); - super.dispose(); - } - - /** Create current the controls "Current objective:". */ - private void createCurrentObjectivePart(Composite parent) { - Composite currentObjComposite = new Composite(parent, SWT.None); - currentObjComposite.setLayout(new GridLayout(2, false)); - } - - /** Dummy object used to add new elements in the tree. */ - private static class DummyObject { - // Nothing to implement: just a marker class - } - - /** Content provider for the configuration tree. */ - private class ConfigTreeContentProvider extends TreeContentProviderBase { - - /** {@inheritDoc} */ - @Override - public Object getParent(Object inputElement) { - if(inputElement instanceof ConfigurationRefWithContextualConfiguration) { - ConfigurationRefWithContextualConfiguration input = - (ConfigurationRefWithContextualConfiguration)inputElement; - for(TreeStructureNode iterableElement : parentList) { - if(iterableElement.data instanceof ConfigurationRefWithContextualConfiguration) { - ConfigurationRefWithContextualConfiguration ref = - (ConfigurationRefWithContextualConfiguration)iterableElement.data; - if(ref.config.getName().equalsIgnoreCase(input.config.getName())) { - return iterableElement.parent; - } - } - } - } else if(inputElement instanceof TreeStructureNode) { - return ((TreeStructureNode)inputElement).parent; - } - return null; - } - - /** {@inheritDoc} */ - @Override - public Object[] getChildren(Object parentElement) { - - if(parentList == null) { - parentList = new ArrayList<TreeStructureNode>(); - } - if(parentElement instanceof IConstraintBasedProcess) { - IConstraintBasedProcess cbdp = (IConstraintBasedProcess)parentElement; - ArrayList<Object> configs = new ArrayList<>(); - configs.add(new DummyObject()); - configs.addAll(cbdp.getConfigurations()); - return configs.toArray(); - } else if(parentElement instanceof ConstraintConfiguration) { - - List<Object> types = new ArrayList<Object>(); - final IConstraintUIService cuis = IConstraintUIService.getInstance(); - Set<Class<? extends IConstraint>> availableCstrs = cuis.getAllConstraints(); - availableCstrs.removeAll(cuis.getAlwaysActivatedConstraints()); - - EList<ConstraintConfiguration> configs = editedObject.getConfigurations(); - if(configs.size() > 1) { - List<ConfigurationRefWithContextualConfiguration> configCollection = - configs.stream() - .map(t -> new ConfigurationRefWithContextualConfiguration(t, - (ConstraintConfiguration)parentElement)) - .collect(toList()); - List<ConfigurationRefWithContextualConfiguration> refs = configCollection; - refs.removeIf(c -> c.config.getName().equalsIgnoreCase(c.target.getName())); - refs.forEach(c -> { - parentList.add(new TreeStructureNode(parentElement, c)); - }); - types.add(refs); - } - - Set<Class<? extends IConstraint>> availableConstraints = cuis.getAllConstraints(); - - // Collecting the groups in the array list - List<String> groupName = new ArrayList<String>(); - for(Class<? extends IConstraint> c : availableConstraints) { - String constGroupName = IConstraintService.getInstance().getGroupName(c); - if(!groupName.contains(constGroupName)) { - groupName.add(constGroupName); - } - } - - // Collect the constraints for each of the groups. - for(String constraintGroupName : groupName) { - HashMap<String, String> constraintInfo = new HashMap<String, String>(); - for(Class<? extends IConstraint> c : availableConstraints) { - String cGroupName = IConstraintService.getInstance().getGroupName(c); - String desc = cuis.getDescription(c); - constraintMap.put(c.getName(), desc); - if(cGroupName.equalsIgnoreCase(constraintGroupName)) { - constraintInfo.put(c.getName(), cuis.getDescription(c)); - } - } - groupNameAndConstraints.put(constraintGroupName, constraintInfo); - } - // Add the constraint groups to the tree. - for(String constraintGroupName : groupNameAndConstraints.keySet()) { - types.add(new TreeStructureNode(parentElement, constraintGroupName)); - parentList.add(new TreeStructureNode(parentElement, constraintGroupName)); - } - - return types.toArray(); - } else if(parentElement instanceof List<?>) { - return ((List<?>)parentElement).toArray(); - } - - // Add the constraints to the tree based on the group name. - else if(parentElement instanceof TreeStructureNode) { - HashMap<String, String> constraintInfo = new HashMap<String, String>(); - List<TreeStructureNode> nodeList = new ArrayList<TreeStructureNode>(); - - Object stringNode = ((TreeStructureNode)parentElement).data; - if(groupNameAndConstraints.get(stringNode) != null) { - for(String constraintGroupName : groupNameAndConstraints.keySet()) { - if(stringNode.toString().equalsIgnoreCase(constraintGroupName.toString())) { - - HashMap<String, String> groupedConstraint = - groupNameAndConstraints.get(constraintGroupName); - for(String key : groupedConstraint.keySet()) { - constraintInfo.put(key, groupedConstraint.get(key)); - TreeStructureNode node = new TreeStructureNode(parentElement, key); - parentList.add(node); - nodeList.add(node); - } - } - } - } - return nodeList.toArray(); - } - return new Object[0]; - } - } - - /** This constraint map contains the name and the description of all of the constraints */ - private HashMap<String, String> constraintMap = new HashMap<String, String>(); - - /** This HashMap contains the groups and the the grouped constraints (as a HashMap) */ - private HashMap<String, HashMap<String, String>> groupNameAndConstraints = - new HashMap<String, HashMap<String, String>>(); - - /** Text labels for the tree of configurations. */ - private String getLabelText(Object element) { - if(element instanceof DummyObject) { - return "click to add a new configuration"; - } else if(element instanceof ConstraintConfiguration) { - return ((ConstraintConfiguration)element).getName(); - } else if(element instanceof ConstraintWithContextualConfiguration) { - IConstraintUIService cuis = IConstraintUIService.getInstance(); - return cuis.getDescription(((ConstraintWithContextualConfiguration)element).cstr); - } else if(element instanceof ConfigurationRefWithContextualConfiguration) { - return ((ConfigurationRefWithContextualConfiguration)element).target.getName(); - } else if(element instanceof List<?>) { - return "Required configurations"; - } else if(element instanceof TreeStructureNode) { - - Object stringNode = ((TreeStructureNode)element).data; - if(groupNameAndConstraints.containsKey(stringNode)) { - for(String constraintGroupName : groupNameAndConstraints.keySet()) { - if((stringNode.toString().equalsIgnoreCase(constraintGroupName.toString()))) { - return constraintGroupName + getInstanceCount(element); - } - } - } else if(constraintMap.containsKey(stringNode)) { - return constraintMap.get(stringNode); - } - } - return null; - } - - /** Check state provider for the tree of configurations. */ - private class ConfigTreeCheckStateProvider implements ICheckStateProvider { - - /** {@inheritDoc} */ - @Override - public boolean isGrayed(Object element) { - return false; - } - - /** {@inheritDoc} */ - @Override - public boolean isChecked(Object element) { - - if(element instanceof ConstraintWithContextualConfiguration) { - ConstraintWithContextualConfiguration cstrInContext = - (ConstraintWithContextualConfiguration)element; - IConstraintService cs = IConstraintService.getInstance(); - String name = cs.getName(cstrInContext.cstr); - HashMap<String, String> hashMap = groupNameAndConstraints.get(element.toString()); - return hashMap.keySet().contains(name); - } else if(element instanceof ConfigurationRefWithContextualConfiguration) { - - ConfigurationRefWithContextualConfiguration configRef = - (ConfigurationRefWithContextualConfiguration)element; - return configRef.config.getIncludedConfigurations().contains(configRef.target); - } else if(element instanceof TreeStructureNode) { - String stringNode = ((TreeStructureNode)element).data.toString(); - if(constraintMap.containsKey(stringNode)) { - ITreeContentProvider provider = - (ITreeContentProvider)treeViewer.getContentProvider(); - Object parent = provider.getParent(element); - Object parent2 = provider.getParent(parent); - ConstraintConfiguration config = ((ConstraintConfiguration)parent2); - EList<String> activeConstraints = config.getActiveConstraints(); - for(String string : activeConstraints) { - if(string.equalsIgnoreCase(stringNode)) { - return true; - } - } - } - } - return false; - } - } - - /** Check state listener for the tree of configurations. */ - private class ConfigTreeCheckStateListener implements ICheckStateListener { - /** {@inheritDoc} */ - @Override - public void checkStateChanged(CheckStateChangedEvent event) { - // Get object element from the state changed - Object element = event.getElement(); - IConstraintService cs = IConstraintService.getInstance(); - IConstraintUIService cuis = IConstraintUIService.getInstance(); - ConstraintConfiguration currentObj = editedObject.getCurrentObjective(); - if(element instanceof ConstraintWithContextualConfiguration) { - ConstraintWithContextualConfiguration cstrInContext = - (ConstraintWithContextualConfiguration)element; - String name = cs.getName(cstrInContext.cstr); - - top.runAsCommand(() -> { - if(event.getChecked()) { - - cstrInContext.config.getActiveConstraints().add(name); - List<ConstraintConfiguration> activeConfigs = - getActiveConfigurationsTransitively(currentObj, null); - if(activeConfigs.contains(cstrInContext.config)) { - cuis.activate(cstrInContext.cstr, cstrContainer); - } - } else { - cstrInContext.config.getActiveConstraints().remove(name); - List<Class<? extends IConstraint>> stillActiveCstrs = - getActiveConstraintsTransitively(currentObj, cstrInContext.config); - if(!stillActiveCstrs.contains(cstrInContext.cstr)) { - cuis.deactivate(cstrInContext.cstr, cstrContainer); - } - } - }); - } else if(element instanceof ConfigurationRefWithContextualConfiguration) { - - ConfigurationRefWithContextualConfiguration configRef = - (ConfigurationRefWithContextualConfiguration)element; - top.runAsCommand(() -> { - if(event.getChecked()) { - configRef.config.getIncludedConfigurations().add(configRef.target); - activateConfiguration(configRef.target, cstrContainer); - } else { - configRef.config.getIncludedConfigurations().remove(configRef.target); - deactivateConfiguration(configRef.target, cstrContainer, configRef.config); - } - }); - } - // Check if the constraint belongs to the constraints HashMap - else if(element instanceof TreeStructureNode) { - - ITreeContentProvider provider = - (ITreeContentProvider)treeViewer.getContentProvider(); - Object parent = provider.getParent(element); - Object parent2 = provider.getParent(parent); - ConstraintConfiguration config = ((ConstraintConfiguration)parent2); - String constraintName = ((TreeStructureNode)element).data.toString(); - if(constraintMap.containsKey(constraintName)) { - top.runAsNonDirtyingCommand(new Runnable() { - /** {@inheritDoc} */ - @Override - public void run() { - // Get the constraintName as a full class path (e.g., - // a.b.c.constraintName.Java) - if(event.getChecked()) { - config.getActiveConstraints().add(constraintName); - - List<ConstraintConfiguration> activeConfigs = - getActiveConfigurationsTransitively(config, null); - // If the set of active constraints is not empty, and the selected - // constraint is in the active constraints list - if(!activeConfigs.isEmpty() && activeConfigs.get(0) != null) { - // get all active constraints of the first configuration which - // is selected using activeConfigs.get(0) - EList<String> activeConstraints = - activeConfigs.get(0).getActiveConstraints(); - if(activeConstraints - .contains(cs.getConstraintByName(constraintName) - .getCanonicalName())) { - // Activate the constraint - cuis.activate(cs.getConstraintByName(constraintName), - cstrContainer); - } - } - } else { - clearConstraintInstance(cs, cuis, config, constraintName); - } - } - }); - } - } - treeViewer.refresh(); - } - } - - /** Tree for configurations. */ - private class ConfigTree extends CheckboxTreeViewer implements ISelectionChangedListener { - - /** Constructor. */ - public ConfigTree(Composite parent) { - super(parent); - getTree().setLayoutData(new GridData(800, 600)); - setContentProvider(new ConfigTreeContentProvider()); - setCheckStateProvider(new ConfigTreeCheckStateProvider()); - addCheckStateListener(new ConfigTreeCheckStateListener()); - } - - /** {@inheritDoc} */ - @Override - public void selectionChanged(SelectionChangedEvent event) { - selection = event.getSelection(); - IActionService.getInstance().refresh(); - } - } - - /** Creates the tree of configurations. */ - private void createTree(Composite parent) { - treeViewer = new ConfigTree(parent); - TreeColumn column = new TreeColumn(treeViewer.getTree(), SWT.LEFT); - column.setText("Constraint configurations"); - column.setWidth(COLUMN_WIDTH); - TreeViewerColumn onlyViewerColumn = new TreeViewerColumn(treeViewer, column); - onlyViewerColumn.setLabelProvider(new BoldColumnLabelProvider()); - - onlyViewerColumn.setEditingSupport(new EditingSupport(treeViewer) { - /** {@inheritDoc} */ - @Override - protected void setValue(Object element, Object value) { - if(element instanceof DummyObject) { - if(!alreadyExists((String)value)) { - ConstraintConfiguration newconfig = - ElementFactory.eINSTANCE.createConstraintConfiguration(); - newconfig.setName((String)value); - top.runAsCommand(() -> IElementCompositorService.getInstance() - .compose(editedObject, newconfig, null)); - } - } - if(element instanceof ConstraintConfiguration) { - ConstraintConfiguration config = (ConstraintConfiguration)element; - if(config.getName().equals(DEFAULT_CONFIGURATION_NAME) || - config.getName().equals(value)) { - return; - } - if(!alreadyExists((String)value)) { - top.runAsCommand( - () -> ((ConstraintConfiguration)element).setName((String)value)); - } - } - } - - /** {@inheritDoc} */ - @Override - protected Object getValue(Object element) { - return getLabelText(element); - } - - /** {@inheritDoc} */ - @Override - protected CellEditor getCellEditor(Object element) { - return new TextCellEditor((Composite)getViewer().getControl()); - } - - /** {@inheritDoc} */ - @Override - protected boolean canEdit(Object element) { - return element instanceof ConstraintConfiguration || - element instanceof DummyObject || constraintMap.containsKey(element); - } - }); - treeViewer.setUseHashlookup(true); - treeViewer.setComparator(new ConstraintComparator()); - treeViewer.setInput(editedObject); - } - - /** - * @param element - * the element to set color - * @return color instance that will be applied on the element - */ - public Color getConstraintBackgroundColor(Object element) { - // Get the complete path of the constraint class (e.g., a.b.c.constraint.java) - String constraintToFind = ((TreeStructureNode)element).data.toString(); - // If the constraint is in the active constraint list and the status is true - // than make the background color green - - EList<ConstraintInstance> constraintInstances = - editedObject.getConstraintInstanceContainer().getConstraintInstances(); - ITreeContentProvider provider = (ITreeContentProvider)treeViewer.getContentProvider(); - Object parent = provider.getParent(element); - Object parent2 = provider.getParent(parent); - ConstraintConfiguration config = ((ConstraintConfiguration)parent2); - - final Display display = Display.getCurrent(); - if(config.getName().equalsIgnoreCase(editedObject.getCurrentObjective().getName())) { - for(ConstraintInstance instance : constraintInstances) { - for(String constraintName : editedObject.getCurrentObjective() - .getActiveConstraints()) { - if(instance.getConstraintName().equalsIgnoreCase(constraintName) && - constraintToFind.equalsIgnoreCase(constraintName)) { - IConstraintInstanceStatus status = - IConstraintUIService.getInstance().getStatus(instance); - if(status instanceof SuccessConstraintInstanceStatus) { - return display.getSystemColor(SWT.COLOR_GREEN); - } else if(status instanceof FailedConstraintInstanceStatus) { - return display.getSystemColor(SWT.COLOR_RED); - } - } - } - } - } - return display.getSystemColor(SWT.COLOR_WHITE); - } - - /** - * Checks if the name already exists among current configurations, if so displays an error - * message and return true, otherwise returns false. - */ - private boolean alreadyExists(String name) { - List<String> configNames = - editedObject.getConfigurations().stream().map(c -> c.getName()).collect(toList()); - if(configNames.contains(name)) { - Status status = new Status(ERROR, ToolingBaseUIActivator.PLUGIN_ID, 0, - "A configuration with this name already exists.", null); - openError(Display.getCurrent().getActiveShell(), "Error", null, status); - return true; - } - return false; - } - - /** Comparator for the contents of the tree. */ - private class ConstraintComparator extends ViewerComparator { - - /** {@inheritDoc} */ - @Override - public int compare(Viewer viewer, Object e1, Object e2) { - if(e1 instanceof DummyObject) { - return -1; - } else if(e2 instanceof DummyObject) { - return 1; - } else if(e1 instanceof ConstraintConfiguration && - e2 instanceof ConstraintConfiguration) { - return ((ConstraintConfiguration)e1).getName() - .compareToIgnoreCase(((ConstraintConfiguration)e2).getName()); - } else if(e1 instanceof ConstraintWithContextualConfiguration && - e2 instanceof ConstraintWithContextualConfiguration) { - IConstraintUIService cuis = IConstraintUIService.getInstance(); - String desc1 = - cuis.getDescription(((ConstraintWithContextualConfiguration)e1).cstr); - String desc2 = - cuis.getDescription(((ConstraintWithContextualConfiguration)e2).cstr); - return desc1.compareToIgnoreCase(desc2); - } else if(e1 instanceof ConfigurationRefWithContextualConfiguration && - e2 instanceof ConfigurationRefWithContextualConfiguration) { - String n1 = ((ConfigurationRefWithContextualConfiguration)e1).target.getName(); - String n2 = ((ConfigurationRefWithContextualConfiguration)e2).target.getName(); - return n1.compareToIgnoreCase(n2); - } else if(e1 instanceof TreeStructureNode && e2 instanceof TreeStructureNode) { - String n1 = ((TreeStructureNode)e1).parent.toString(); - String n2 = ((TreeStructureNode)e2).parent.toString(); - return n1.compareToIgnoreCase(n2); - } - return super.compare(viewer, e1, e2); - } - } - - /** {@inheritDoc} */ - @Override - public EObject getSelectedModelElement() { - if(getSelectedModelElementList().isEmpty()) { - return null; - } - // Returns the first element, which is ensured to exist by the previous statement. - Object selected = getSelectedModelElementList().get(0); - return selected instanceof EObject ? (EObject)selected : null; - } - - /** {@inheritDoc} */ - @SuppressWarnings("unchecked") - @Override - public List<EObject> getSelectedModelElementList() { - boolean isStructured = selection instanceof StructuredSelection; - return isStructured ? ((StructuredSelection)selection).toList() : new ArrayList<>(); - } - - /** {@inheritDoc} */ - @Override - public void addSelectionChangedListener(ISelectionChangedListener listener) { - // Not supported - } - - /** {@inheritDoc} */ - @Override - public ISelection getSelection() { - return selection == null ? new StructuredSelection() : selection; - } - - /** {@inheritDoc} */ - @Override - public void removeSelectionChangedListener(ISelectionChangedListener listener) { - // Not supported - } - - /** {@inheritDoc} */ - @Override - public void setSelection(ISelection selection) { - // Not supported - } - - /** - * If the constraint is unchecked from the tree remove the - * constraint from the active constraints list and constraint instance list - * - * @param cs - * constraintService - * @param cuis - * constraintUIService - * @param config - * the configuration in which the constraint remains - * @param constraintName - * the name of the constraint - */ - private void clearConstraintInstance(IConstraintService cs, IConstraintUIService cuis, - ConstraintConfiguration config, String constraintName) { - - config.getActiveConstraints().remove(constraintName); - // If the constraint is still not active - EList<String> stillActiveConstraints = config.getActiveConstraints(); - if(!stillActiveConstraints - .contains(cs.getConstraintByName(constraintName).getCanonicalName())) { - Class<? extends IConstraint> constrainttoDeActivate = - cs.getConstraintByName(constraintName); - // Deactivate the constraint - cuis.deactivate(constrainttoDeActivate, cstrContainer); - - ITopLevelElement modelContext = - IPersistencyService.getInstance().getTopLevelElementFor(editedObject); - modelContext.runAsNonDirtyingCommand(() -> { - - TreeIterator<EObject> allContents = - editedObject.getCurrentObjective().eResource().getAllContents(); - EList<EObject> eContents = editedObject.getCurrentObjective().eContents(); - List<EObject> duplicateList = new ArrayList<EObject>(); - duplicateList.addAll(eContents); - List<Object> toRemove = new ArrayList<Object>(); - - while(allContents.hasNext()) { - EObject next = allContents.next(); - - if(next instanceof ConstraintNameToChecksumImpl && - next.toString().contains(constraintName)) { - toRemove.add(next); - } - if(next instanceof ConstraintInstanceImpl && - next.toString().contains(constraintName)) { - toRemove.add(next); - } - } - toRemove.forEach(c -> { - duplicateList.remove(c); - delete((EObject)c); - }); - }); - } - } - - /** - * @param viewer - * the tree viewer - * @param parentElement - * the parent element of the given element - * @param element - * the element to consider - * @return the decision on whether the constraint was checked in previous dependent configs or - * not - */ - private boolean checkIfDuplicate(Viewer viewer, Object parentElement, Object element) { - ITreeContentProvider provider = (ITreeContentProvider)treeViewer.getContentProvider(); - - ConstraintConfiguration config = - ((ConstraintConfiguration)provider.getParent(parentElement)); - List<Class<? extends IConstraint>> activeConstraintsTransitively = - getActiveConstraintsTransitively(config, null); - List<String> constraintList = activeConstraintsTransitively.stream() - .map((item) -> item.getName()).collect(toList()); - - for(String string : constraintList) { - if(!config.getActiveConstraints().contains(string) && - ((TreeStructureNode)element).data.toString().equalsIgnoreCase(string)) { - return false; - } - } - - return true; - } - - /** @return the concatenated string containing the score for the configuration. */ - private String getInstanceCount(Object element) { - String constraintGroupName = ((TreeStructureNode)element).data.toString(); - // If the constraint is in the active constraint list and the status is true - // than make the background color green - - int successCount = 0; - int failCount = 0; - HashMap<String, String> hashMap = groupNameAndConstraints.get(constraintGroupName); - EList<ConstraintInstance> constraintInstances = - editedObject.getConstraintInstanceContainer().getConstraintInstances(); - ITreeContentProvider provider = (ITreeContentProvider)treeViewer.getContentProvider(); - Object parent = provider.getParent(element); - ConstraintConfiguration config = ((ConstraintConfiguration)parent); - - EList<String> activeConstraints = config.getActiveConstraints(); - List<Class<? extends IConstraint>> stillActiveCstrs = - getActiveConstraintsTransitively(config, null); - - int duplicateSize = stillActiveCstrs.stream() - .filter(c -> !(activeConstraints.contains(c.getName()))).collect(toList()).size(); - if(config.getName().equalsIgnoreCase(editedObject.getCurrentObjective().getName())) { - for(ConstraintInstance instance : constraintInstances) { - for(String constraintName : editedObject.getCurrentObjective() - .getActiveConstraints()) { - if(instance.getConstraintName().equalsIgnoreCase(constraintName) && - (hashMap.containsKey(constraintName))) { - IConstraintInstanceStatus status = - IConstraintUIService.getInstance().getStatus(instance); - if(status instanceof SuccessConstraintInstanceStatus) { - successCount++; - } - } - } - } - - int totalNumOfGrpConstraints = hashMap.size() - duplicateSize; - return "[ " + successCount + " / " + failCount + "/" + totalNumOfGrpConstraints + " ]"; - } - return ""; - } - - /** Text labels for the tree of configurations. */ - private StyledString getStylizedLabel(Object element) { - if(element instanceof DummyObject) { - return new StyledString("click to add a new configuration"); - } else if(element instanceof ConstraintConfiguration) { - return new StyledString(((ConstraintConfiguration)element).getName()); - } else if(element instanceof ConstraintBasedProcessEditorHelper.ConstraintWithContextualConfiguration) { - IConstraintUIService cuis = IConstraintUIService.getInstance(); - return new StyledString(cuis.getDescription( - ((ConstraintBasedProcessEditorHelper.ConstraintWithContextualConfiguration)element).cstr)); - } else if(element instanceof ConfigurationRefWithContextualConfiguration) { - return new StyledString( - ((ConfigurationRefWithContextualConfiguration)element).target.getName()); - } else if(element instanceof List<?>) { - return new StyledString("Required configurations"); - } else if(element instanceof TreeStructureNode) { - - Object stringNode = ((TreeStructureNode)element).data; - if(groupNameAndConstraints.containsKey(stringNode)) { - for(String constraintGroupName : groupNameAndConstraints.keySet()) { - if((stringNode.toString().equalsIgnoreCase(constraintGroupName.toString()))) { - - ArrayList<Integer> instanceCountList = getInstanceCount2(element); - int constarintNameLength = constraintGroupName.length(); - if(instanceCountList == null) { - StyledString finalString = new StyledString(constraintGroupName); - adjustColorIndex(groupNameAndConstraints.keySet().size()); - finalString.setStyle(0, finalString.length(), new NormalFontStyler()); - return finalString; - } - // the elements are stored in the list sequentially- success count, fail - // count and total number of instances - String successfulConst = Integer.toString(instanceCountList.get(0)); - int successLength = successfulConst.length(); - String failedConst = Integer.toString(instanceCountList.get(1)); - String totalConst = Integer.toString(instanceCountList.get(2)); - int failCountLength = failedConst.length(); - // creating the string with all the counts - if(instanceCountList.size() == 3) { - - StyledString finalString = new StyledString(constraintGroupName + "[" + - successfulConst + "/" + failedConst + "/" + totalConst + "]"); - adjustColorIndex(groupNameAndConstraints.keySet().size()); - - finalString.setStyle(0, finalString.length(), new NormalFontStyler()); - finalString.setStyle(constarintNameLength + 1, successLength, - new GreenFontStyler()); - finalString.setStyle(constarintNameLength + 2 + successLength, - failCountLength, new RedFontStyler()); - return finalString; - } - } - } - } else if(constraintMap.containsKey(stringNode)) { - return new StyledString(constraintMap.get(stringNode)); - } - } - return null; - } - - /** Class to create stylized string for labels of the tree. */ - private class BoldColumnLabelProvider extends DelegatingStyledCellLabelProvider { - /** {@inheritDoc} */ - @Override - public Color getForeground(Object element) { - return null; - } - - /** {@inheritDoc} */ - @Override - public Color getBackground(Object element) { - if(element instanceof TreeStructureNode) { - if(constraintMap.containsKey(((TreeStructureNode)element).data.toString())) { - // Ask for the constraint color based on status - return getConstraintBackgroundColor(element); - } - } - return null; - } - - /** Class for generating stylized text. */ - public BoldColumnLabelProvider() { - super(new IStyledLabelProvider() { - /** {@inheritDoc} */ - @Override - public Image getImage(Object element) { - return null; - } - - /** {@inheritDoc} */ - @Override - public StyledString getStyledText(Object element) { - return getStylizedLabel(element); - } - - /** {@inheritDoc} */ - @Override - public void addListener(ILabelProviderListener listener) { - return; - } - - /** {@inheritDoc} */ - @Override - public void dispose() { - return; - } - - /** {@inheritDoc} */ - @Override - public boolean isLabelProperty(Object element, String property) { - return false; - } - - /** {@inheritDoc} */ - @Override - public void removeListener(ILabelProviderListener listener) { - return; - } - }); - } - } - - /** - * @param element - * the group name element - * @return array list of integer containing success count, fail count, and total count - */ - private ArrayList<Integer> getInstanceCount2(Object element) { - String constraintGroupName = ((TreeStructureNode)element).data.toString(); - // If the constraint is in the active constraint list and the status is true - // than make the background color green - - int successCount = 0; - int failCount = 0; - HashMap<String, String> hashMap = groupNameAndConstraints.get(constraintGroupName); - EList<ConstraintInstance> constraintInstances = - editedObject.getConstraintInstanceContainer().getConstraintInstances(); - ITreeContentProvider provider = (ITreeContentProvider)treeViewer.getContentProvider(); - Object parent = provider.getParent(element); - ConstraintConfiguration config = ((ConstraintConfiguration)parent); - - if(config.getName().equalsIgnoreCase(editedObject.getCurrentObjective().getName())) { - for(ConstraintInstance instance : constraintInstances) { - for(String constraintName : editedObject.getCurrentObjective() - .getActiveConstraints()) { - if(instance.getConstraintName().equalsIgnoreCase(constraintName) && - (hashMap.containsKey(constraintName))) { - IConstraintInstanceStatus status = - IConstraintUIService.getInstance().getStatus(instance); - if(status instanceof SuccessConstraintInstanceStatus) { - successCount++; - } - if(status instanceof FailedConstraintInstanceStatus) { - failCount++; - } - } - } - } - ArrayList<Integer> countList = new ArrayList<Integer>(); - countList.add(new Integer(successCount)); - countList.add(new Integer(failCount)); - countList.add(new Integer(hashMap.size())); - return countList; - } - return null; - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/ConstraintBasedProcessEditorHelper.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/ConstraintBasedProcessEditorHelper.java deleted file mode 100644 index 11d48e8a2aecd48eea259a42ef1192c4b292a334..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/ConstraintBasedProcessEditorHelper.java +++ /dev/null @@ -1,217 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2017 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.base.ui.editor; - -import static org.eclipse.jface.resource.FontDescriptor.createFrom; - -import org.eclipse.jface.resource.FontDescriptor; -import org.eclipse.jface.viewers.StyledString.Styler; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.TextStyle; -import org.eclipse.swt.widgets.Display; -import org.fortiss.tooling.base.model.element.ConstraintConfiguration; -import org.fortiss.tooling.kernel.extension.IConstraint; - -// TODO Refactor together with ConstraintBasedProcessEditor and provide a dedicated perspective (see #3189) -/** - * This class is a helper class that provides, 1) the colors for the constraint groups, - * 2) manage the references between the constraint configurations and - * 3) manages the tree manipulation that is used to visualize the constraintsGroups, - * constraintConfigurations and constraints. - * - * @author abid - * - */ -public class ConstraintBasedProcessEditorHelper { - - /** Color Array for at least seven groups. */ - private static int[] colorArray = - {SWT.COLOR_DARK_GREEN, SWT.COLOR_DARK_BLUE, SWT.COLOR_DARK_YELLOW, SWT.COLOR_BLACK, - SWT.COLOR_DARK_RED, SWT.COLOR_GREEN, SWT.COLOR_CYAN}; - - /** Counter for the colorArray */ - private static int colorCtr = 0; - - /** Reference to a constraint configuration. */ - private static class WithContextualConfiguration { - - /** Contextual constraint configuration. */ - ConstraintConfiguration config; - - /** Constructor. */ - public WithContextualConfiguration(ConstraintConfiguration config) { - this.config = config; - } - } - - /** Constraint accompanied with a configuration providing the context. */ - public static class ConstraintWithContextualConfiguration extends WithContextualConfiguration { - - /** Constraint. */ - /* package */Class<? extends IConstraint> cstr; - - /** Constructor. */ - public ConstraintWithContextualConfiguration(Class<? extends IConstraint> cstr, - ConstraintConfiguration config) { - super(config); - this.cstr = cstr; - } - } - - /** - * Configuration accompanied with another configuration providing the context. - * Intent is that the contained configuration is a dependency of the context one. - */ - public static class ConfigurationRefWithContextualConfiguration - extends WithContextualConfiguration { - - /** Constraint. */ - /* package */ConstraintConfiguration target; - - /** Constructor. */ - public ConfigurationRefWithContextualConfiguration(ConstraintConfiguration configRef, - ConstraintConfiguration config) { - super(config); - this.target = configRef; - } - - /** {@inheritDoc} */ - @Override - public boolean equals(Object obj) { - if(obj instanceof ConfigurationRefWithContextualConfiguration) { - // current target name - String currentTargetName = this.target.getName(); - // contextualRef Target of the configuration - String configRefTrgtObjName = - ((ConfigurationRefWithContextualConfiguration)obj).target.getName(); - // current configuration - String currentConfigName = this.config.getName(); - // contextualRef Object of the configuration - String configRefObjName = - ((ConfigurationRefWithContextualConfiguration)obj).config.getName(); - return currentTargetName.equalsIgnoreCase(configRefTrgtObjName) && - currentConfigName.equalsIgnoreCase(configRefObjName); - } - return false; - } - - /** {@inheritDoc} */ - @Override - public int hashCode() { - return target.hashCode(); - } - } - - /** Class to manipulate and store parent of elements. */ - public static class TreeStructureNode { - - /** Parent object variable. */ - /* package */Object parent; - - /** Data object variable. */ - /* package */Object data; - - /** Constructor. */ - public TreeStructureNode(Object parent, Object children) { - this.parent = parent; - this.data = children; - } - - /** {@inheritDoc} */ - @Override - public boolean equals(Object obj) { - if(obj instanceof TreeStructureNode) { - // the current tree node to be compared with - String currentStructureNode = this.data.toString(); - // the tree node to be checked - String treeStructureNode = ((TreeStructureNode)obj).data.toString(); - // parent of the current tree node - String currentParentNode = this.parent.toString(); - // parent of the object that needs to be checked - String objectParentNode = ((TreeStructureNode)obj).parent.toString(); - return currentStructureNode.equalsIgnoreCase(treeStructureNode) && - currentParentNode.equalsIgnoreCase(objectParentNode); - } - return false; - } - - /** {@inheritDoc} */ - @Override - public int hashCode() { - return parent.hashCode(); - } - } - - /** Styler class to create colored bold labels for constraint group name. */ - public static class NormalFontStyler extends Styler { - - /** Counter to keep track of currently used color in color array. */ - private int colorIndex = 0; - - /** Constructor. */ - public NormalFontStyler() { - this.colorIndex = colorCtr; - } - - /** {@inheritDoc} */ - @Override - public void applyStyles(final TextStyle textStyle) { - - FontDescriptor boldDescriptor = createFrom(new FontData()).setStyle(SWT.BOLD); - Font boldFont = boldDescriptor.createFont(Display.getCurrent()); - textStyle.font = boldFont; - textStyle.foreground = Display.getCurrent().getSystemColor(colorArray[colorIndex]); - } - } - - /** Styler class to create red color labels. */ - public static class RedFontStyler extends Styler { - /** {@inheritDoc} */ - @Override - public void applyStyles(final TextStyle textStyle) { - FontDescriptor boldDescriptor = createFrom(new FontData()).setStyle(SWT.BOLD); - Font boldFont = boldDescriptor.createFont(Display.getCurrent()); - textStyle.font = boldFont; - textStyle.foreground = Display.getCurrent().getSystemColor(SWT.COLOR_DARK_RED); - } - } - - /** Styler class to create green color labels. */ - public static class GreenFontStyler extends Styler { - /** {@inheritDoc} */ - @Override - public void applyStyles(final TextStyle textStyle) { - FontDescriptor boldDescriptor = createFrom(new FontData()).setStyle(SWT.BOLD); - Font boldFont = boldDescriptor.createFont(Display.getCurrent()); - textStyle.font = boldFont; - textStyle.foreground = Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GREEN); - } - } - - /** - * This function is responsible for updating the color of the constraints groups as they are - * added by updating the color counter (i.e., ColorCtr) - * - * @param groupSize - * is the size of the constraints groups - */ - public static void adjustColorIndex(int groupSize) { - colorCtr++; - colorCtr %= groupSize; - } -} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/utils/ConstraintsBaseUIUtils.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/utils/ConstraintsBaseUIUtils.java deleted file mode 100644 index 713512da44cc0ebd9bcd5c11abee87c86c94088d..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/utils/ConstraintsBaseUIUtils.java +++ /dev/null @@ -1,273 +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.base.ui.utils; - -import static org.fortiss.tooling.base.utils.ConstraintsBaseUtils.getActiveConstraintsTransitively; -import static org.fortiss.tooling.base.utils.ConstraintsBaseUtils.removeFromConstraintInstanceContainer; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.Function; - -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.util.EContentAdapter; -import org.fortiss.tooling.base.model.base.ConstraintBasedProcess; -import org.fortiss.tooling.base.model.element.ConstraintConfiguration; -import org.fortiss.tooling.base.model.element.IConstraintBasedProcess; -import org.fortiss.tooling.kernel.extension.IConstraint; -import org.fortiss.tooling.kernel.extension.data.ITopLevelElement; -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.service.IConstraintService; -import org.fortiss.tooling.kernel.service.IPersistencyService; -import org.fortiss.tooling.kernel.service.listener.IPersistencyServiceListener; -import org.fortiss.tooling.kernel.ui.service.IConstraintUIService; -import org.fortiss.tooling.kernel.utils.EcoreUtils; - -/** - * Utility methods related to constraints. - * - * @author aravantinos - */ -public class ConstraintsBaseUIUtils { - - /** Factorized behaviour. */ - public static void doActivateAll(IConstraintInstanceContainer cstrContainer, - IConstraintBasedProcess cbdProcess) { - // First activate the constraints which should always be activated - for(Class<? extends IConstraint> cstrClass : IConstraintUIService.getInstance() - .getAlwaysActivatedConstraints()) { - IConstraintUIService.getInstance().activate(cstrClass, cstrContainer); - } - // Then activate the constraints of the current objective - ConstraintConfiguration currentObj = cbdProcess.getCurrentObjective(); - if(currentObj != null) { - List<Class<? extends IConstraint>> activeCstrs = - getActiveConstraintsTransitively(currentObj, null); - for(Class<? extends IConstraint> cstrClass : activeCstrs) { - IConstraintUIService.getInstance().activate(cstrClass, cstrContainer); - } - } - } - - /** - * Activates all constraints which are active in the given configuration, potentially adding new - * constraint instances to the provided container. - */ - public static void activateConfiguration(ConstraintConfiguration config, - IConstraintInstanceContainer cstrContainer) { - for(Class<? extends IConstraint> cstr : getActiveConstraintsTransitively(config, null)) { - IConstraintUIService.getInstance().activate(cstr, cstrContainer); - } - } - - /** - * Activates all constraints which are active in the given configuration - * (non-transitively). - */ - public static void activateOneConfiguration(ConstraintConfiguration config, - IConstraintInstanceContainer cstrContainer) { - List<Class<? extends IConstraint>> configConstraints = new ArrayList<>(); - for(String name : config.getActiveConstraints()) { - configConstraints.add(IConstraintService.getInstance().getConstraintByName(name)); - } - for(Class<? extends IConstraint> cstr : configConstraints) { - IConstraintUIService.getInstance().activate(cstr, cstrContainer); - } - } - - /** - * Deactivates all constraints which are active in the given configuration, if they are not - * still active in the provided context. - */ - public static void deactivateConfiguration(ConstraintConfiguration config, - IConstraintInstanceContainer cstrContainer, ConstraintConfiguration context) { - List<Class<? extends IConstraint>> stillActiveConstraints = - getActiveConstraintsTransitively(context, config); - for(Class<? extends IConstraint> cstr : getActiveConstraintsTransitively(config, null)) { - if(!stillActiveConstraints.contains(cstr)) { - IConstraintUIService.getInstance().deactivate(cstr, cstrContainer); - } - } - } - - /** - * Deactivates all constraints which are active in the given configuration - */ - public static void deactivateConfiguration(ConstraintConfiguration config, - IConstraintInstanceContainer cstrContainer) { - for(Class<? extends IConstraint> cstr : getActiveConstraintsTransitively(config, null)) { - IConstraintUIService.getInstance().deactivate(cstr, cstrContainer); - } - } - - /** - * Deactivates all constraints which are active in the given configuration - * (non-transitively). - */ - public static void deactivateOneConfiguration(ConstraintConfiguration config, - IConstraintInstanceContainer cstrContainer) { - List<Class<? extends IConstraint>> configConstraints = new ArrayList<>(); - for(String name : config.getActiveConstraints()) { - configConstraints.add(IConstraintService.getInstance().getConstraintByName(name)); - } - for(Class<? extends IConstraint> cstr : configConstraints) { - IConstraintUIService.getInstance().deactivate(cstr, cstrContainer); - } - } - - /** - * Factorized behavior to install the various listeners necessary for constraints. - * This made in a generic manner so that the client only needs to give a function providing - * access to a {@link ConstraintBasedProcess} given a {@link ITopLevelElement}. The rest is for - * free. - */ - public static class ConstraintBasedProcessAwareActivator { - /** - * Function to access a {@link ConstraintBasedProcess} given a {@link ITopLevelElement}. - * Project-dependent. - */ - private Function<ITopLevelElement, ConstraintBasedProcess> getConstraintBasedProcess; - - /** Constructor. */ - public ConstraintBasedProcessAwareActivator( - Function<ITopLevelElement, ConstraintBasedProcess> getConstraintBasedProcess) { - this.getConstraintBasedProcess = getConstraintBasedProcess; - } - - /** Start the kernel. */ - public void start() { - for(ITopLevelElement top : IPersistencyService.getInstance().getTopLevelElements()) { - installListener(top); - activateAllConstraints(top); - } - IPersistencyService.getInstance() - .addTopLevelElementListener(new ConstraintBasedDevelopmentProcessListener()); - } - - /** Go through all constraints in <code>top</code> and (re-)activates them. */ - private void activateAllConstraints(ITopLevelElement top) { - ConstraintBasedProcess cbp = getConstraintBasedProcess.apply(top); - if(cbp != null) { - IConstraintInstanceContainer cic = cbp.getConstraintInstanceContainer(); - try { - doActivateAll(cic, cbp); - // The only case where the activation above can trigger a model change is if it - // is discovered that constraints shall be added. - // This should not happen in most cases: the constraint was normally active when - // the project was left and therefore the constraint should already be present. - // However there is a case where this is not the case: when AF3 developers added - // a new constraint and start then AF3 for the first time; then the constraint - // has to be added (sort of migration of the model actually). In such a case the - // line above will trigger an exception because not run in a command. That is - // the whole reason for the catch block thereafter. - // Note that we do not run the activation directly in a command because we do - // not want to mark the model as dirty for nothing. - } catch(IllegalStateException e) { - top.runAsCommand(() -> doActivateAll(cic, cbp)); - } - } - } - - /** - * Install the listener triggering activation of constraints for the given top level - * element. - * Returns the installed listener. - */ - private void installListener(ITopLevelElement top) { - ConstraintBasedProcess cbp = getConstraintBasedProcess.apply(top); - if(cbp == null) { - return; - } - IConstraintInstanceContainer cic = cbp.getConstraintInstanceContainer(); - EContentAdapter listener = new EContentAdapter() { - - private boolean isAlreadyAddingMissingConstraints = false; - - /** {@inheritDoc} */ - @Override - public void notifyChanged(Notification notification) { - super.notifyChanged(notification); - if(isTouch(notification) || isAlreadyAddingMissingConstraints) { - return; - } - // Do not react to change of status. - if(notification.getNewValue() instanceof IConstraintInstanceStatus) { - return; - } - if(notification.getEventType() == Notification.REMOVE && - notification.getOldValue() instanceof IConstrained) { - IConstrained constrained = (IConstrained)notification.getOldValue(); - removeFromConstraintInstanceContainer(constrained); - } - isAlreadyAddingMissingConstraints = true; - IConstraintUIService.getInstance().addMissingConstraintInstances(cic); - isAlreadyAddingMissingConstraints = false; - } - }; - top.getRootModelElement().eAdapters().add(listener); - } - - /** - * Listener to (re)activate constraints when the project changes. - * Typically to install adequate constraints when a new element was added to the project. - */ - private class ConstraintBasedDevelopmentProcessListener - implements IPersistencyServiceListener { - - /** {@inheritDoc} */ - @Override - public void topLevelElementLoaded(ITopLevelElement element) { - // ignore - } - - /** {@inheritDoc} */ - @Override - public void topLevelElementAdded(ITopLevelElement element) { - installListener(element); - } - - /** {@inheritDoc} */ - @Override - public void topLevelElementContentChanged(ITopLevelElement element) { - // Not our concern. - } - - /** {@inheritDoc} */ - @Override - public void topLevelElementRemoved(ITopLevelElement element) { - // Not our concern - } - } - - /** - * @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; - } - } -} diff --git a/org.fortiss.tooling.base/model/.ratings b/org.fortiss.tooling.base/model/.ratings index 8f58ba1ffdf1ae83053ebe17d4e5b7e85db128e1..a14484332c6f194fa6e1e2dc001bc8a240b3aa5b 100644 --- a/org.fortiss.tooling.base/model/.ratings +++ b/org.fortiss.tooling.base/model/.ratings @@ -1 +1 @@ -base.ecore 598ac2f27293be7344b762471a3570f45e63950d GREEN +base.ecore 6ba521f3458eaf64fc3ee0359e236c9a1201d259 YELLOW diff --git a/org.fortiss.tooling.base/model/base.ecore b/org.fortiss.tooling.base/model/base.ecore index 598ac2f27293be7344b762471a3570f45e63950d..6ba521f3458eaf64fc3ee0359e236c9a1201d259 100644 --- a/org.fortiss.tooling.base/model/base.ecore +++ b/org.fortiss.tooling.base/model/base.ecore @@ -181,26 +181,6 @@ <eGenericType eTypeParameter="#//element/IDerivedAnnotation/T"/> </eOperations> </eClassifiers> - <eClassifiers xsi:type="ecore:EClass" name="IConstraintBasedProcess" abstract="true" - interface="true"> - <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel"> - <details key="documentation" value="Marker interface for metaclasses to describe constraint-based development processes.

TODO (refs #3469) Clarify relation to constraint metaclasses in tooling.kernel."/> - </eAnnotations> - <eStructuralFeatures xsi:type="ecore:EReference" name="currentObjective" eType="#//element/ConstraintConfiguration"/> - <eStructuralFeatures xsi:type="ecore:EReference" name="constraintInstanceContainer" - eType="ecore:EClass platform:/resource/org.fortiss.tooling.kernel/model/kernel.ecore#//constraints/IConstraintInstanceContainer"/> - <eStructuralFeatures xsi:type="ecore:EReference" name="configurations" upperBound="-1" - eType="#//element/ConstraintConfiguration" containment="true"/> - </eClassifiers> - <eClassifiers xsi:type="ecore:EClass" name="ConstraintConfiguration" eSuperTypes="platform:/resource/org.fortiss.tooling.kernel/model/kernel.ecore#//INamedElement"> - <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel"> - <details key="documentation" value="Hierarchical description of constraint configuration.

TODO (refs #3469): Clarify relation to constraint metaclasses in tooling.kernel."/> - </eAnnotations> - <eStructuralFeatures xsi:type="ecore:EAttribute" name="activeConstraints" upperBound="-1" - eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> - <eStructuralFeatures xsi:type="ecore:EReference" name="includedConfigurations" - upperBound="-1" eType="#//element/ConstraintConfiguration"/> - </eClassifiers> </eSubpackages> <eSubpackages name="layout" nsURI="http://www.fortiss.org/tooling/base/model/layout" nsPrefix="org-fortiss-tooling-base-model-layout"> @@ -478,16 +458,6 @@ <eTypeArguments eTypeParameter="#//base/DerivedAnnotationBase/T"/> </eGenericSuperTypes> </eClassifiers> - <eClassifiers xsi:type="ecore:EClass" name="ConstraintInstanceContainer" eSuperTypes="platform:/resource/org.fortiss.tooling.kernel/model/kernel.ecore#//constraints/IConstraintInstanceContainer"> - <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel"> - <details key="documentation" value="@deprecated Currently unused. TODO (refs #3469) Caveat: Base class is defined in tooling.kernel."/> - </eAnnotations> - </eClassifiers> - <eClassifiers xsi:type="ecore:EClass" name="ConstraintBasedProcess" eSuperTypes="#//element/IConstraintBasedProcess"> - <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel"> - <details key="documentation" value="Base class for {@link IConstraintBasedProcess}es.

TODO (refs #3469): Clarify relation to constraint metaclasses in tooling.kernel."/> - </eAnnotations> - </eClassifiers> </eSubpackages> <eSubpackages name="visualization" nsURI="http://www.fortiss.org/tooling/base/model/visualization" nsPrefix="org-fortiss-tooling-base-model-visualization"> diff --git a/org.fortiss.tooling.base/model/base.genmodel b/org.fortiss.tooling.base/model/base.genmodel index fde899af767217ec4ed05483e87703bb3c21cbce..bad9184d77c98d6e78195c936dc9172436d47b6e 100644 --- a/org.fortiss.tooling.base/model/base.genmodel +++ b/org.fortiss.tooling.base/model/base.genmodel @@ -58,18 +58,6 @@ <genOperations ecoreOperation="base.ecore#//element/IDerivedAnnotation/isUserAnnotatedValuePreferred"/> <genOperations ecoreOperation="base.ecore#//element/IDerivedAnnotation/getUserAnnotatedValue"/> </genClasses> - <genClasses image="false" ecoreClass="base.ecore#//element/IConstraintBasedProcess"> - <genFeatures notify="false" createChild="false" propertySortChoices="true" - ecoreFeature="ecore:EReference base.ecore#//element/IConstraintBasedProcess/currentObjective"/> - <genFeatures notify="false" createChild="false" propertySortChoices="true" - ecoreFeature="ecore:EReference base.ecore#//element/IConstraintBasedProcess/constraintInstanceContainer"/> - <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference base.ecore#//element/IConstraintBasedProcess/configurations"/> - </genClasses> - <genClasses image="false" ecoreClass="base.ecore#//element/ConstraintConfiguration"> - <genFeatures createChild="false" ecoreFeature="ecore:EAttribute base.ecore#//element/ConstraintConfiguration/activeConstraints"/> - <genFeatures notify="false" createChild="false" propertySortChoices="true" - ecoreFeature="ecore:EReference base.ecore#//element/ConstraintConfiguration/includedConfigurations"/> - </genClasses> </nestedGenPackages> <nestedGenPackages prefix="Layout" basePackage="org.fortiss.tooling.base.model" disposableProviderFactory="true" ecorePackage="base.ecore#//layout"> @@ -172,8 +160,6 @@ <genOperations ecoreOperation="base.ecore#//base/DerivedAnnotationBase/getUserAnnotatedValue" body="return null;"/> </genClasses> - <genClasses ecoreClass="base.ecore#//base/ConstraintInstanceContainer"/> - <genClasses ecoreClass="base.ecore#//base/ConstraintBasedProcess"/> </nestedGenPackages> <nestedGenPackages prefix="Visualization" basePackage="org.fortiss.tooling.base.model" disposableProviderFactory="true" ecorePackage="base.ecore#//visualization"> diff --git a/org.fortiss.tooling.base/src/org/fortiss/tooling/base/compose/ConstraintInstanceContainerCompositor.java b/org.fortiss.tooling.base/src/org/fortiss/tooling/base/compose/ConstraintInstanceContainerCompositor.java deleted file mode 100644 index 9cb23f13c6cddba18ac7f9dcfd1afd9e7bce4d77..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.base/src/org/fortiss/tooling/base/compose/ConstraintInstanceContainerCompositor.java +++ /dev/null @@ -1,71 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2011 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.base.compose; - -import static org.eclipse.emf.ecore.util.EcoreUtil.delete; -import static org.fortiss.tooling.base.utils.ConstraintsBaseUtils.removeFromConstraintInstanceContainer; - -import org.eclipse.emf.ecore.EObject; -import org.fortiss.tooling.kernel.extension.IElementCompositor; -import org.fortiss.tooling.kernel.extension.data.IElementCompositionContext; -import org.fortiss.tooling.kernel.extension.data.Prototype; -import org.fortiss.tooling.kernel.model.constraints.ConstraintInstance; -import org.fortiss.tooling.kernel.model.constraints.IConstraintInstanceContainer; - -/** - * {@link IElementCompositor} implementation for {@link IConstraintInstanceContainer}s. - * - * @author hoelzl - */ -public class ConstraintInstanceContainerCompositor<CIC extends IConstraintInstanceContainer> - implements IElementCompositor<CIC> { - - /** {@inheritDoc} */ - @Override - public boolean canCompose(CIC container, EObject contained, - IElementCompositionContext context) { - return contained instanceof ConstraintInstance; - } - - /** {@inheritDoc} */ - @Override - public boolean compose(CIC container, EObject contained, IElementCompositionContext context) { - ConstraintInstance c = (ConstraintInstance)contained; - container.getConstraintInstances().add(c); - return true; - } - - /** {@inheritDoc} */ - @Override - public boolean canComposePrototype(Prototype prototype) { - // As of now constraints should never be added by prototype. - return false; - } - - /** {@inheritDoc} */ - @Override - public boolean canDecompose(EObject contained) { - return contained instanceof ConstraintInstance; - } - - /** {@inheritDoc} */ - @Override - public boolean decompose(EObject contained) { - removeFromConstraintInstanceContainer((ConstraintInstance)contained); - delete(contained); - return true; - } -} diff --git a/org.fortiss.tooling.base/src/org/fortiss/tooling/base/utils/ConstraintsBaseUtils.java b/org.fortiss.tooling.base/src/org/fortiss/tooling/base/utils/ConstraintsBaseUtils.java deleted file mode 100644 index bba938b43756ce6f35c338f6cef21c3ab5d49a9d..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.base/src/org/fortiss/tooling/base/utils/ConstraintsBaseUtils.java +++ /dev/null @@ -1,191 +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.base.utils; - -import static org.fortiss.tooling.kernel.utils.ConstraintsUtils.getConstraintInstanceContainer; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.emf.common.util.EList; -import org.fortiss.tooling.base.model.element.ConstraintConfiguration; -import org.fortiss.tooling.base.model.element.ElementFactory; -import org.fortiss.tooling.base.model.element.IConstraintBasedProcess; -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.IConstrained; -import org.fortiss.tooling.kernel.model.constraints.IConstraintInstanceContainer; -import org.fortiss.tooling.kernel.service.IConstraintService; -import org.fortiss.tooling.kernel.service.IPersistencyService; - -/** - * Utils for constraints. - * - * @author aravantinos - */ -public class ConstraintsBaseUtils { - - /** Name of the default configuration. */ - public static final String DEFAULT_CONFIGURATION_NAME = "Default configuration"; - - /** Removes constraints on <code>c</code> from <code>container</code>. */ - public static void removeFromConstraintInstanceContainer(IConstrained c) { - EList<ConstraintInstance> toRemove = c.getConstraintInstances(); - if(toRemove.isEmpty()) { - // Then there is nothing to do - return; - } - // get(0) because we just checked that the list is not empty, and because the assumption is - // made that the constraint instance container is the same for all the instances in the - // list. - IConstraintInstanceContainer container = getConstraintInstanceContainer(toRemove.get(0)); - container.getConstraintInstances().removeAll(toRemove); - for(ConstraintInstance constraint : toRemove) { - for(IConstrained constrained : constraint.getConstraineds()) { - // c needs to be treated separately to avoid concurrent modifications - if(constrained != null && !constrained.equals(c)) { - constrained.getConstraintInstances().remove(constraint); - } - } - } - c.getConstraintInstances().clear(); - } - - /** - * Removes the constraint instance from its container. Also removes it from its constrained - * elements. - */ - public static void removeFromConstraintInstanceContainer(ConstraintInstance ci) { - IConstraintInstanceContainer container = getConstraintInstanceContainer(ci); - if(container != null) { - container.getConstraintInstances().remove(ci); - } - for(IConstrained cstrd : ci.getConstraineds()) { - cstrd.getConstraintInstances().remove(ci); - } - } - - /** - * If <code>config</code> is not already in <code>configList</code>, adds it and its included - * configurations. - * - * <code>exception</code> allows to avoid considering one particular configuration. - * Leave <code>null</code> if irrelevant. - */ - public static void addConfigurationTransitively(List<ConstraintConfiguration> configList, - ConstraintConfiguration config, ConstraintConfiguration exception) { - if(!configList.contains(config) && !config.equals(exception)) { - configList.add(config); - for(ConstraintConfiguration subConfig : config.getIncludedConfigurations()) { - addConfigurationTransitively(configList, subConfig, exception); - } - } - } - - /** - * Returns all the configurations included in <code>config</code> transitively, including - * <code>config</code> itself. - * - * <code>exception</code> allows to avoid considering one particular configuration. - * Leave <code>null</code> if irrelevant. - */ - public static List<ConstraintConfiguration> getActiveConfigurationsTransitively( - ConstraintConfiguration config, ConstraintConfiguration exception) { - List<ConstraintConfiguration> res = new ArrayList<>(); - addConfigurationTransitively(res, config, exception); - return res; - } - - /** - * Returns the names of all the constraints active in the given configuration. - * - * <code>exception</code> allows to avoid considering one particular configuration. - * Leave <code>null</code> if irrelevant. - */ - public static List<String> getActiveConstraintNamesTransitively(ConstraintConfiguration config, - ConstraintConfiguration exception) { - List<ConstraintConfiguration> configs = - getActiveConfigurationsTransitively(config, exception); - List<String> res = new ArrayList<>(); - for(ConstraintConfiguration subConfig : configs) { - res.addAll(subConfig.getActiveConstraints()); - } - return res; - } - - /** - * Returns all the constraints active in the given configuration. - * - * <code>exception</code> allows to avoid considering one particular configuration. - * Leave <code>null</code> if irrelevant. - */ - public static List<Class<? extends IConstraint>> getActiveConstraintsTransitively( - ConstraintConfiguration config, ConstraintConfiguration exception) { - List<String> names = getActiveConstraintNamesTransitively(config, exception); - List<Class<? extends IConstraint>> res = new ArrayList<>(); - for(String name : names) { - res.add(IConstraintService.getInstance().getConstraintByName(name)); - } - return res; - } - - /** True if the given configuration is the default one. */ - public static boolean isDefaultConfiguration(ConstraintConfiguration c) { - return c.getName().equals(DEFAULT_CONFIGURATION_NAME); - } - - /** Gets the default configuration of the given constraint-based development process. */ - public static ConstraintConfiguration getDefaultConfig(IConstraintBasedProcess cbp) { - EList<ConstraintConfiguration> configs = cbp.getConfigurations(); - for(ConstraintConfiguration config : configs) { - if(isDefaultConfiguration(config)) { - return config; - } - } - return null; - } - - /** Adds a default configuration to the given process and returns it for information. */ - public static ConstraintConfiguration addDefaultConfig(IConstraintBasedProcess cbp) { - ConstraintConfiguration newDefaultConfig = - ElementFactory.eINSTANCE.createConstraintConfiguration(); - newDefaultConfig.setName(DEFAULT_CONFIGURATION_NAME); - cbp.getConfigurations().add(newDefaultConfig); - return newDefaultConfig; - } - - /** Gets the default configuration if existing, or creates one otherwise. */ - public static ConstraintConfiguration retrieveDefaultConfig(IConstraintBasedProcess cbp) { - ConstraintConfiguration defaultConfig = getDefaultConfig(cbp); - if(defaultConfig != null) { - return defaultConfig; - } - ITopLevelElement top = IPersistencyService.getInstance().getTopLevelElementFor(cbp); - top.runAsCommand(() -> addDefaultConfig(cbp)); - return getDefaultConfig(cbp); - } - - /** - * Initializes a {@link IConstraintBasedProcess}. Needs a {@link IConstraintInstanceContainer}. - */ - public static void initializeConstraintBasedProcess(IConstraintBasedProcess cbp, - IConstraintInstanceContainer cic) { - ConstraintConfiguration defaultConfig = addDefaultConfig(cbp); - cbp.setCurrentObjective(defaultConfig); - cbp.setConstraintInstanceContainer(cic); - } -} diff --git a/org.fortiss.tooling.kernel.ui/plugin.xml b/org.fortiss.tooling.kernel.ui/plugin.xml index 8f76e8c6d6cd0bad21b7a515806f273ba7cd679a..f84dd2cdad77ebdb72f81b1b3276d21dfba748ce 100644 --- a/org.fortiss.tooling.kernel.ui/plugin.xml +++ b/org.fortiss.tooling.kernel.ui/plugin.xml @@ -116,30 +116,11 @@ </propertySection> </propertySections> </extension> - <extension - point="org.eclipse.ui.decorators"> - <decorator - class="org.fortiss.tooling.kernel.ui.internal.ConstraintLabelDecorator" - id="org.fortiss.tooling.kernel.ui.internal.ConstraintLabelDecorator" - label="Constraint Decorator" - lightweight="true" - location="BOTTOM_LEFT" - state="true"> - <enablement> - <objectClass - name="org.eclipse.emf.ecore.EObject"> - </objectClass> - </enablement> - </decorator> - </extension> <extension point="org.fortiss.tooling.kernel.ui.contextMenuContribution"> <contextMenuContribution contributor="org.fortiss.tooling.kernel.ui.internal.views.NavigatorNewMenu"> </contextMenuContribution> - <contextMenuContribution - contributor="org.fortiss.tooling.kernel.ui.internal.views.ConstraintMenu"> - </contextMenuContribution> </extension> <extension point="org.eclipse.ui.perspectives"> @@ -150,15 +131,6 @@ name="Storage"> </perspective> </extension> - <extension - point="org.fortiss.tooling.kernel.ui.modelElementHandler"> - <modelElementHandler - handler="org.fortiss.tooling.kernel.ui.extension.base.ConstraintUIBases$ConstraintHandler"> - <modelElementClass - modelElementClass="org.fortiss.tooling.kernel.model.constraints.ConstraintInstance"> - </modelElementClass> - </modelElementHandler> - </extension> <extension point="org.fortiss.tooling.kernel.uiMessageHandler"> <uiMessageHandler handler="org.fortiss.tooling.kernel.ui.extension.base.DialogMessageHandler"> diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/.ratings b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/.ratings index 0f71fc3dd92acfc4197b5dc1400f09fe10e33967..e3dae57d37ce91f7898d85eb9774c665040a8e9f 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/.ratings +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/.ratings @@ -1,5 +1,4 @@ IAllocationEditPartFactory.java 7d30a6b77cc04191fcd516260ff10d4128f7f3ad GREEN -IConstraintUI.java e2cfa44697a95333601a8df131a169aaee85e9b5 GREEN IContextMenuContributor.java 0f09c76662c154cf52ddab61b417e82a42854162 GREEN IContextMenuMultiSelectionContributor.java 125b31dd38009bc2095b7e6bc860e946e39f58c4 GREEN IEditPartFactory.java 5729715847f553d95a5bad4a9211c7e6f458badd GREEN 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/.ratings b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/.ratings index a7f01cec28ced8ee225518f34ad81234c4f6d8a3..3776fb18b863e417da1104e086324e0e0cd6c1fc 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/.ratings +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/.ratings @@ -1,4 +1,3 @@ -ConstraintUIBases.java 3676a600e0866091db9798763c6eee97eec5b55b GREEN ContextMenuSubMenuContributorBase.java 6275d96fe8690d9d4744bcbaef3c7d14ba8e30ff GREEN DialogMessageHandler.java 8714da09a777c8557de0a5c48ff68c340f9fa91d GREEN EObjectActionBase.java 4ef9f8be59e64d4838acc9e268d418ba5d94fa1a GREEN 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 e61bcd66e8b7e1f52185aeeec04e87a887296375..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 -ModelEditorBindingService.java 577f5db41abf240291434dbad6bc6b0fde1eeb2b 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/.ratings b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/handler/.ratings index 90ff45a0a408bb5fa6f1cb93b69a980e20e74555..7603b3de5398117aa2b0d0afd8b299f9f63c8c9c 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/handler/.ratings +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/handler/.ratings @@ -1,8 +1,6 @@ AllocationEditPartFactoryServiceIntrospectionDetailsUIHandler.java 944cc4d5db305ceba7ca1f1f1957a5160511a228 GREEN ConnectionCompositorServiceIntrospectionDetailsUIHandler.java bf4744afe94f1b97c2f8442466c10d4969b81854 GREEN ConstraintCheckerServiceIntrospectionDetailsUIHandler.java 33758640bc77148162b88143dd1ed758a12bcf30 GREEN -ConstraintServiceIntrospectionDetailsUIHandler.java 8695a09d5a6047d1a478c1d48a49f1e3072caadd GREEN -ConstraintUIServiceIntrospectionDetailsUIHandler.java bc5fff880e84fac2fa8e1bc43b67cfb2ce907f97 GREEN ContextMenuServiceIntrospectionDetailsUIHandler.java 33f39e000e14a9c2661ca280e82139593852be7c GREEN CopyClassNameToClipBoardRunnable.java 884555c7026c466d3401b272fc64b9f693074950 GREEN EObjectAware2IntrospectionDetailsUIHandlerBase.java 18aefde758dc370f564a535d71bab9afc8bdf91f GREEN 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/.ratings b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/introspection/items/.ratings index 434543b49938dd77aef9d3a96ab693d4cdefb459..cf998a62cc03308101d57266a57e1116a2e3850f 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/introspection/items/.ratings +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/introspection/items/.ratings @@ -1,5 +1,4 @@ AllocationEditPartFactoryServiceIntrospectionDetailsItem.java e2067b2d95c270a9aed82a2368177d76b0144d79 GREEN -ConstraintUIServiceIntrospectionDetailsItem.java c143c6113a5bc3c69c6652055e6f703a170d9794 GREEN ContextMenuServiceIntrospectionDetailsItem.java ce7c725510e986b99fcddb40676cf6a5e7c2351d GREEN EditPartFactoryServiceIntrospectionDetailsItem.java f11316c73b6de0e254c4e319e063065e598d5c96 GREEN ModelEditorBindingServiceIntrospectionDetailsItem.java b241c242f5d8597542d9b63276b64ac2ca81ec7d GREEN 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/.ratings b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/views/.ratings index 4ef64c3de26f956c75e25f1106d5b0a80fbf821f..75283430c8346ab6dfc5341b8e549540588a4d82 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/views/.ratings +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/views/.ratings @@ -1,4 +1,3 @@ -ConstraintMenu.java 55bb88600b21e832109460f14fe8f09a18056fcc GREEN DoubleClick.java fd00e7737c0bad903433c0adb67dad92220ff451 GREEN GenericNewMenu.java 7e0dd435cb5ca6d4b486235ec17eef3e5c7aa5f6 GREEN LibraryView.java 44107622da7bcf431e1177e462d711646488957f GREEN 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/.ratings b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/service/.ratings index fd22b149f0941e9eed55e12988c6bc503e54c1e8..ac88577cf756cac95c8f570ad76c78098a9ea3ba 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/service/.ratings +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/service/.ratings @@ -1,6 +1,5 @@ IActionService.java 22eafafc8708cbff7f855f7b1b9bef042c127f25 GREEN IAllocationEditPartFactoryService.java ac7243a8ff8a6c3f71937ecf3e63a04e271ca1d5 GREEN -IConstraintUIService.java 07df6b9553bf04f8c414c976dc630e6a1dd5ec96 GREEN IContextMenuService.java cfb6b8237b6cd2b0e461991a9ceb95969f330265 GREEN IEditPartFactoryService.java c448bff63fb81f57037c9f1dc5319859c12d0c4d GREEN IMarkerService.java d433e838e387dd2fe61b8dea7395ebb7203ae39b GREEN 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/.ratings b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/util/.ratings index f0fcdeb321a83a3554b17b564ff8d377d5cc8dbd..fd2078b766355261bbefb4db4293b6e65ecb2c06 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/util/.ratings +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/util/.ratings @@ -1,5 +1,4 @@ ActionUtils.java 4553e487264e3d1f86f4767da4a7400cce4b9a5d GREEN -ConstraintsUIUtils.java 69d5e08bbf768baf2790380e36f1020ef826a33e GREEN CopyPasteUtils.java bbc5cf9c9dc03ebf8dc75d42c919fe6eb60b388e GREEN DataBindingUtils.java 631c47881caa13fc567679a7e4416eb777af0713 GREEN DragAndDropUtils.java 7aab91518aa12d76533a345bf6ed0be9ac7ff0e5 GREEN 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); - } - } -} diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/extension/IConstraint.java b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/extension/IConstraint.java deleted file mode 100644 index e5e95efa8b06b30d6feffd9a2033e5caa3e710e9..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/extension/IConstraint.java +++ /dev/null @@ -1,54 +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.extension; - -import org.fortiss.tooling.kernel.model.constraints.ConstraintInstance; -import org.fortiss.tooling.kernel.model.constraints.IConstrained; -import org.fortiss.tooling.kernel.model.constraints.IConstraintInstanceStatus; -import org.fortiss.tooling.kernel.service.IConstraintService; - -/** - * Interface for constraints as required by {@link IConstraintService}. - */ -public interface IConstraint { - - /** Verify the given constraint instance. */ - IConstraintInstanceStatus verify(ConstraintInstance ci); - - /** - * Hook to preprocess <code>cstrd</code> before computing its checksum. Typically useful to - * remove items which should not be considered when computing the checksum, e.g., layout - * information. - */ - void preprocessBeforeChecksum(IConstrained cstrd); - - /** Cancels the last verification of <code>ci</code>. */ - void cancel(ConstraintInstance ci); - - /** - * Adds a constraint instance to the provided element. - * - * Subclasses shall return <code>null</code> if the provided element should not be constrained - * (whatever is the reason: the constraint is only judge here). - */ - ConstraintInstance addConstraintInstanceIfNeeded(IConstrained cstrd); - - /** - * @return The name of the Group. This method will be implemented in all of the classes that - * implements this interface - */ - String getGroup(); -} diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/extension/base/ConstraintBases.java b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/extension/base/ConstraintBases.java deleted file mode 100644 index 93b4743cc1f5e2677635e644663ba934ef7f7f4e..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/extension/base/ConstraintBases.java +++ /dev/null @@ -1,134 +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.extension.base; - -import static org.fortiss.tooling.kernel.utils.ConstraintsUtils.createConstraintInstance; -import static org.fortiss.tooling.kernel.utils.ConstraintsUtils.createOutdatedStatus; -import static org.fortiss.tooling.kernel.utils.ConstraintsUtils.getConstrained; -import static org.fortiss.tooling.kernel.utils.ConstraintsUtils.getConstraintInstanceOfType; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.emf.common.util.EMap; -import org.eclipse.emf.common.util.TreeIterator; -import org.eclipse.emf.ecore.EObject; -import org.fortiss.tooling.kernel.extension.IConstraint; -import org.fortiss.tooling.kernel.model.constraints.ConstraintInstance; -import org.fortiss.tooling.kernel.model.constraints.IConstrained; -import org.fortiss.tooling.kernel.model.constraints.IConstraintInstanceContainer; -import org.fortiss.tooling.kernel.model.constraints.IConstraintInstanceStatus; - -/** - * Base for {@link IConstraint}. - * - * @author aravantinos - */ -public class ConstraintBases { - /** Most generic base. */ - public abstract static class ConstraintBase implements IConstraint { - - /** Returns the constraint instance container in the context of the given object. */ - abstract public IConstraintInstanceContainer getConstraintInstanceContainer(EObject obj); - - /** {@inheritDoc} */ - @Override - public void preprocessBeforeChecksum(IConstrained cstrd) { - cstrd.getConstraintInstances().clear(); - cstrd.getChecksumsPerConstraintName().clear(); - // By default, we remove all the constraint-related information. - TreeIterator<EObject> it = cstrd.eAllContents(); - List<EMap<String, BigInteger>> toClears = new ArrayList<>(); - while(it.hasNext()) { - EObject obj = it.next(); - if(obj instanceof IConstrained) { - ((IConstrained)obj).getConstraintInstances().clear(); - toClears.add(((IConstrained)obj).getChecksumsPerConstraintName()); - } - } - toClears.stream().forEach(toClear -> toClear.clear()); - } - - /** {@inheritDoc} */ - @Override - public void cancel(ConstraintInstance ci) { - // By default - and generally - nothing to do. Not all constraints are so heavy that - // they deserve to have a cancellation procedure. - } - - /** {@inheritDoc} */ - @Override - public ConstraintInstance addConstraintInstanceIfNeeded(IConstrained constrained) { - if(getConstraintInstanceOfType(constrained, this) != null) { - return null; - } - ConstraintInstance ci = createConstraintInstanceIfNeeded(constrained); - if(ci != null) { - createOutdatedStatus(ci); - } - if(ci != null) { - IConstraintInstanceContainer ciContainer = - getConstraintInstanceContainer(constrained); - ciContainer.getConstraintInstances().add(ci); - } - return ci; - } - - /** - * Creates and return a constraint instance on the provided element. - * - * Subclasses shall return <code>null</code> if the provided element should not be - * constrained (whatever is the reason: the constraint is only judge here). - */ - public abstract ConstraintInstance - createConstraintInstanceIfNeeded(IConstrained constrained); - } - - /** - * Base for a constraint which is as close as possible to the old constraint system: - * - the constrained element contains all the information necessary for the constraint - * (nothing stored in the constraint instance) - * - only one element is constrained - */ - public static abstract class ConstraintCheckerBase extends ConstraintBase { - /** {@inheritDoc} */ - @Override - public IConstraintInstanceStatus verify(ConstraintInstance ci) { - IConstrained constrained = getConstrained(ci); - return isApplicable(constrained) ? verify(constrained) : null; - } - - /** Verify the given constrained element. */ - public abstract IConstraintInstanceStatus verify(IConstrained constrained); - - /** Determines whether this constraint is applicable to the given model element. */ - public abstract boolean isApplicable(IConstrained constrained); - - /** {@inheritDoc} */ - @Override - public ConstraintInstance addConstraintInstanceIfNeeded(IConstrained constrained) { - return isApplicable(constrained) ? super.addConstraintInstanceIfNeeded(constrained) - : null; - } - - /** {@inheritDoc} */ - @Override - public ConstraintInstance createConstraintInstanceIfNeeded(IConstrained constrained) { - return createConstraintInstance(this.getClass(), constrained); - } - } -} diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/internal/.ratings b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/internal/.ratings index 2f69b2046501b5917850e19477bc500f81ea116c..95a442ad4aea705c31e35a4f2b5c4016bc201a16 100644 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/internal/.ratings +++ b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/internal/.ratings @@ -1,7 +1,6 @@ CommandStackService.java 957bda69b5feb91f002aed4d25ed334e92801e7e GREEN ConnectionCompositorService.java d69a60cd7a3d06e91d24fd32b9c00125ea71e0dd GREEN ConstraintCheckerService.java 459b5eb717598e7e8bb71a0c87e57ea85cb00e4b GREEN -ConstraintService.java 139187909523300c80a22be920329f1c9d0fb654 GREEN DummyTopLevelElement.java 8394597464707992cd053e68129bb87ce9f696db GREEN ElementCompositorService.java 98c5d27e09881e60aa4f87c1ac0c7787cdec9f7c GREEN LibraryPrototypeProvider.java b77eddbdca78f561ffb1233e98817be361c690ae GREEN @@ -10,6 +9,6 @@ LoggingService.java da784259f7b456b54bf75c41ec268f64919ce78d GREEN MigrationService.java 2f800eac9793aa736089a802bbfc2c4c1c09770d GREEN PersistencyService.java 103eef642c038ef63fa49b743d803aaa3fea2724 GREEN PrototypeService.java 18c3db05ab11f189a9711bf241c3c7f35c954a9e GREEN -ToolingKernelInternal.java d624a5f6b237ce993e150e2b8d1b4390e3fc8f7a GREEN +ToolingKernelInternal.java f6e7114825748683c7f1d040b41ab854a6c4d79b GREEN TransformationService.java 3cdb86fe920158f93cd9466c6ef9697b2dd8ca7f GREEN TutorialService.java 675d3f365ce062869f86baa3779d50687674bda0 GREEN diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/internal/ConstraintService.java b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/internal/ConstraintService.java deleted file mode 100644 index 139187909523300c80a22be920329f1c9d0fb654..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/internal/ConstraintService.java +++ /dev/null @@ -1,350 +0,0 @@ -package org.fortiss.tooling.kernel.internal; - -import static java.util.Collections.emptyList; -import static org.eclipse.emf.ecore.xmi.XMLResource.OPTION_PROCESS_DANGLING_HREF; -import static org.eclipse.emf.ecore.xmi.XMLResource.OPTION_PROCESS_DANGLING_HREF_DISCARD; -import static org.fortiss.tooling.kernel.utils.EcoreUtils.copy; -import static org.fortiss.tooling.kernel.utils.LoggingUtils.warning; - -import java.io.ByteArrayOutputStream; -import java.io.FileOutputStream; -import java.io.ObjectOutputStream; -import java.lang.reflect.InvocationTargetException; -import java.math.BigInteger; -import java.security.MessageDigest; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.emf.common.util.EMap; -import org.eclipse.emf.common.util.TreeIterator; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; -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.introspection.items.ConstraintVerificationServiceIntrospectionDetailsItem; -import org.fortiss.tooling.kernel.model.INamedElement; -import org.fortiss.tooling.kernel.model.constraints.ConstraintInstance; -import org.fortiss.tooling.kernel.model.constraints.IConstrained; -import org.fortiss.tooling.kernel.model.constraints.IConstraintInstanceStatus; -import org.fortiss.tooling.kernel.service.IConstraintService; -import org.fortiss.tooling.kernel.service.IKernelIntrospectionSystemService; -import org.fortiss.tooling.kernel.service.IPersistencyService; - -/** - * Implementation of {@link IConstraintService}. - * - * @author aravantinos - */ -public final class ConstraintService implements IIntrospectiveKernelService, IConstraintService { - - /** The singleton instance. */ - private static final ConstraintService INSTANCE = new ConstraintService(); - - /** Stores the set of registered constraint classes by name. */ - protected final Map<String, Class<? extends IConstraint>> handlerMap = - new HashMap<String, Class<? extends IConstraint>>(); - - /** Stores the set of registered constraints classes instantiations. */ - protected final Map<Class<? extends IConstraint>, IConstraint> instanceMap = - new HashMap<Class<? extends IConstraint>, IConstraint>(); - - /** Returns singleton instance of the service. */ - public static ConstraintService getInstance() { - return INSTANCE; - } - - /** Starts the service. */ - public void startService() { - IKernelIntrospectionSystemService.getInstance().registerService(this); - } - - /** Initializes the service by setting up the handler map. */ - public void initializeService() { - // nothing to do here - } - - /** {@inheritDoc} */ - @Override - public void registerConstraint(Class<? extends IConstraint> cstrClass) { - String name = cstrClass.getName(); - Class<? extends IConstraint> existingCstr = handlerMap.get(name); - if(existingCstr != null) { - warning(ToolingKernelActivator.getDefault(), - "Encountered more than one registered constraint with name " + name); - } - handlerMap.put(name, cstrClass); - try { - instanceMap.put(cstrClass, cstrClass.getConstructor().newInstance()); - } catch(InstantiationException | IllegalAccessException | IllegalArgumentException | - InvocationTargetException | NoSuchMethodException | SecurityException e) { - warning(ToolingKernelActivator.getDefault(), - "Instanciation of " + cstrClass.getName() + " threw an exception."); - } - } - - /** {@inheritDoc} */ - @Override - public String getIntrospectionDescription() { - return getIntrospectionLabel() + "\n\nThe service deals with constraints over AF3 models." + - "\nA constraint is a function over a model element (the \"constrained\" element) which returns true or false." + - "\nThe application of a constraint to a given model element is called a \"constraint instance\"." + - "\nContrarily to usual constraint systems, constraint instances are a first-class citizen for this service" + - "\nbecause it allows us to store the status of the constraint on the given element as well as the checksum of the constrained element." + - "\n\nThe service provides the following:" + - "\n- verification of a constraint instance," + - "\n- cancellation of a constraint instance verification (if provided by the relevant verifier)," + - "\n- check whether a constraint instance is up to date," + - "\n- provide a list of possible \"quick fixes\" for a given constraint instance in case it failed," + - "\n- complete a given project with instances of a given constraint if necessary" + - "\n (it is however advised to use instead, if possible, the equivalent function of the UI service which also installs" + - "\n the added constraint instances)." + - "\n\nThis service is fed with classes of type IConstraint." + - "\nSuch classes are responsible of the verification of constraints which return a status of the following form:" + - "\n- SUCCESS means the verification succeeded" + - "\n- FAIL means the verification failed" + - "\n- ERROR means the verification could not be run (typically because an error happened)" + - "\n- OUTDATED means the constrained items have changed and the constraint instance should be verified. " + - "\n- null if it is irrelevant to check the constraint - whatever is the reason. " + - "\nDo not hesitate to extend these statuses to define your own," + - "\nfor instance to provide more information about failure (thus possibly allowing automatic fixes)." + - "\n\nThe class org.fortiss.af3.project.utils.ConstraintsProjectUtils.AF3ProjectConstraintCheckerBase should" + - "\ngenerally provide a sufficient initial implementation." + - "\n\nSee the developer wiki page \"Add a new constraint on a metamodel\"" + - " for detailed documentation on developing a new sort of constraint."; - } - - /** {@inheritDoc} */ - @Override - public void verify(ConstraintInstance ci) { - IConstraint verifier = getConstraint(ci); - if(verifier != null) { - ITopLevelElement modelContext = - IPersistencyService.getInstance().getTopLevelElementFor(ci); - // It can happen that <code>modelContext</code> is null, e.g., if the verification is - // triggered while the constraint is actually being removed. - if(modelContext == null) { - return; - } - modelContext.runAsCommand(() -> { - // We update the checksums before verification to avoid detecting some fake changes - // during the verification. - updateChecksums(ci); - IConstraintInstanceStatus status = verifier.verify(ci); - ci.setStatus(status); - // And we also update the checksums after in case the verification had some side - // effects... - updateChecksums(ci); - currentlyUpdating.remove(ci); - }); - } - } - - /** Returns the short name of the constraint of the given instance. */ - private String cstrShortName(ConstraintInstance ci) { - int dolIndex = ci.getConstraintName().lastIndexOf('$'); - int dotIndex = ci.getConstraintName().lastIndexOf('.'); - return ci.getConstraintName().substring(Math.max(dotIndex, dolIndex) + 1); - } - - /** {@inheritDoc} */ - @Override - public boolean isUpToDate(ConstraintInstance ci) { - if(ci == null) { - // silently return in case of a null constraint instance - return true; - } - for(IConstrained c : ci.getConstraineds()) { - BigInteger computeCheckSum = computeCheckSum(c, ci); - EMap<String, BigInteger> checksumMap = c.getChecksumsPerConstraintName(); - BigInteger storedChecksum = checksumMap.get(ci.getConstraintName()); - if(computeCheckSum == null || !computeCheckSum.equals(storedChecksum)) { - return false; - } - } - return true; - } - - /** Updates all the checksums of <code>ci</code>. */ - private void updateChecksums(ConstraintInstance ci) { - for(IConstrained c : ci.getConstraineds()) { - c.getChecksumsPerConstraintName().put(ci.getConstraintName(), computeCheckSum(c, ci)); - } - } - - /** - * Path to a directory where to store the constrained elements which are actually checksummed. - * This is useful since it is essential to control very precisely how checksums are computed. - * If equal to the empty string, debug is deactivated. - * This string should however only be set to a non-empty string on a local machine, never - * committed! - */ - private static final String DEBUG_FOLDER = null; - - /** Number used to annotate the traces when debugging is active. */ - private int debug_trace_number = 0; - - /** - * Returns the checksum of <code>constrained</code>. Note that <code>ci</code> is necessary - * because it has a potential impact on what is relevant for the checksum or not. - */ - protected BigInteger computeCheckSum(IConstrained constrained, ConstraintInstance ci) { - if(constrained == null) { - return null; - } - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - final EObject hashRelevant = getChecksumRelevantEObject(constrained, ci); - try(ObjectOutputStream oos = new ObjectOutputStream(baos)) { - final ResourceSet rset = new ResourceSetImpl(); - - Resource resource = rset.createResource(URI.createURI("temp")); - resource.getContents().add(hashRelevant); - Map<String, String> options = new HashMap<>(); - - // The option below is to allow computing the hashsum of an incomplete ecore sub-model, - // which is wanted in case parts of the model which are not checksum relevant are still - // referred to. - options.put(OPTION_PROCESS_DANGLING_HREF, OPTION_PROCESS_DANGLING_HREF_DISCARD); - - resource.save(oos, options); - MessageDigest m = MessageDigest.getInstance("SHA1"); - m.update(baos.toByteArray()); - BigInteger res = new BigInteger(1, m.digest()); - if(DEBUG_FOLDER != null) { - String filePrefix = DEBUG_FOLDER + "/trace" + debug_trace_number++; - String nameCstr = cstrShortName(ci); - String nameCstrd = constrained instanceof INamedElement - ? ((INamedElement)constrained).getName() : constrained.toString(); - String fileName = filePrefix + "_" + nameCstr + "_" + nameCstrd + ".xml"; - try(FileOutputStream file = new FileOutputStream(fileName); - ObjectOutputStream oos2 = new ObjectOutputStream(file)) { - resource.save(oos2, options); - oos2.writeUTF("\nCHECKSUM: " + res.toString()); - } - } - resource.getContents().remove(hashRelevant); - resource.delete(options); - return res; - } catch(Exception e) { - e.printStackTrace(); - return null; - } - } - - /** - * Returns the object to be used to compute the checksum. - * Generally, all statuses and checksums are removed. Each constraint can also provide - * specific adaptations. - */ - protected EObject getChecksumRelevantEObject(IConstrained constrained, ConstraintInstance ci) { - IConstrained res = copy(constrained); - res.getChecksumsPerConstraintName().clear(); - IConstraint verifier = getConstraint(ci); - if(verifier != null) { - verifier.preprocessBeforeChecksum(res); - } - return res; - } - - /** @return The registered constraint whose <code>ci</code> is a constraint instance of. */ - protected IConstraint getConstraint(ConstraintInstance ci) { - return instanceMap.get(handlerMap.get(ci.getConstraintName())); - } - - /** {@inheritDoc} */ - @Override - public void cancel(ConstraintInstance ci) { - getConstraint(ci).cancel(ci); - } - - /** {@inheritDoc} */ - @Override - public String getIntrospectionLabel() { - return "Constraint Service"; - } - - /** {@inheritDoc} */ - @Override - public IIntrospectionDetailsItem getDetailsItem() { - return new ConstraintVerificationServiceIntrospectionDetailsItem(instanceMap.values()); - } - - /** {@inheritDoc} */ - @Override - public boolean showInIntrospectionNavigation() { - return true; - } - - /** {@inheritDoc} */ - @Override - public Collection<IIntrospectionItem> getIntrospectionItems() { - return emptyList(); - } - - /** {@inheritDoc} */ - @Override - public List<ConstraintInstance> addMissingConstraintsInstances(ITopLevelElement top, - Class<? extends IConstraint> cstrClass) { - List<ConstraintInstance> addedConstraints = new ArrayList<ConstraintInstance>(); - IConstraint cstr = instanceMap.get(cstrClass); - TreeIterator<EObject> it = top.getRootModelElement().eAllContents(); - while(it.hasNext()) { - EObject elt = it.next(); - if(elt instanceof IConstrained) { - ConstraintInstance ci = cstr.addConstraintInstanceIfNeeded((IConstrained)elt); - if(ci != null) { - addedConstraints.add(ci); - } - } - } - return addedConstraints; - } - - /** {@inheritDoc} */ - @Override - public String getName(Class<? extends IConstraint> cstrClass) { - return cstrClass.getName(); - } - - /** {@inheritDoc} */ - @Override - public Class<? extends IConstraint> getConstraintByName(String name) { - return handlerMap.get(name); - } - - /** - * List of constraint instances being currently updated, to prevent triggering twice an update - * which is already on its way. - */ - List<ConstraintInstance> currentlyUpdating = new ArrayList<>(); - - /** {@inheritDoc} */ - @Override - public boolean isUpdating(ConstraintInstance ci) { - return currentlyUpdating.contains(ci); - } - - /** {@inheritDoc} */ - @Override - public void markAsUpdating(ConstraintInstance ci) { - currentlyUpdating.add(ci); - } - - /** {@inheritDoc} */ - @Override - public String getGroupName(Class<? extends IConstraint> cstrClass) { - if(instanceMap.get(cstrClass).getGroup() != null) { - return instanceMap.get(cstrClass).getGroup().trim().toString(); - } - return ""; - } -} diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/internal/ToolingKernelInternal.java b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/internal/ToolingKernelInternal.java index d624a5f6b237ce993e150e2b8d1b4390e3fc8f7a..f6e7114825748683c7f1d040b41ab854a6c4d79b 100644 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/internal/ToolingKernelInternal.java +++ b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/internal/ToolingKernelInternal.java @@ -35,7 +35,6 @@ public final class ToolingKernelInternal { CommandStackService.getInstance().initializeService(); ConnectionCompositorService.getInstance().initializeService(); ConstraintCheckerService.getInstance().initializeService(); - ConstraintService.getInstance().initializeService(); ElementCompositorService.getInstance().initializeService(); MigrationService.getInstance().initializeService(); LibraryService.getInstance().initializeService(); @@ -56,7 +55,6 @@ public final class ToolingKernelInternal { CommandStackService.getInstance().startService(); ConnectionCompositorService.getInstance().startService(); ConstraintCheckerService.getInstance().startService(); - ConstraintService.getInstance().startService(); ElementCompositorService.getInstance().startService(); MigrationService.getInstance().startService(); LibraryService.getInstance().startService(); diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/introspection/items/ConstraintVerificationServiceIntrospectionDetailsItem.java b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/introspection/items/ConstraintVerificationServiceIntrospectionDetailsItem.java deleted file mode 100644 index 9499a4b7ffa68d0090bb27e8cd9da13381f298c7..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/introspection/items/ConstraintVerificationServiceIntrospectionDetailsItem.java +++ /dev/null @@ -1,51 +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.introspection.items; - -import java.util.Collection; - -import org.fortiss.tooling.kernel.extension.IConstraint; -import org.fortiss.tooling.kernel.introspection.IIntrospectionDetailsItem; -import org.fortiss.tooling.kernel.service.IConstraintService; - -/** - * {@link IIntrospectionDetailsItem} for the {@link IConstraintService}. - * - * @author aravantinos - */ -public class ConstraintVerificationServiceIntrospectionDetailsItem - implements IIntrospectionDetailsItem { - - /** Read-only copy of the services handler list. */ - protected final Collection<IConstraint> handlerSet; - - /** Constructor. */ - public ConstraintVerificationServiceIntrospectionDetailsItem( - Collection<IConstraint> handlerSet) { - this.handlerSet = handlerSet; - } - - /** Returns the first registration classes. */ - public Collection<IConstraint> getHandlerKeyClasses() { - return handlerSet; - } - - /** Returns the registered constraint of the given name. */ - public IConstraint getHandler(String name) { - return handlerSet.stream().filter(c -> name.equals(c.getClass().getName())).findFirst() - .get(); - } -} diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/IConstraintService.java b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/IConstraintService.java deleted file mode 100644 index d55c3e25b8cef7e2f7c555adec7ff31e28449370..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/IConstraintService.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.fortiss.tooling.kernel.service; - -import java.util.List; - -import org.fortiss.tooling.kernel.extension.IConstraint; -import org.fortiss.tooling.kernel.extension.data.ITopLevelElement; -import org.fortiss.tooling.kernel.internal.ConstraintService; -import org.fortiss.tooling.kernel.model.constraints.ConstraintInstance; -import org.fortiss.tooling.kernel.model.constraints.OutdatedConstraintInstanceStatus; - -/** - * The verification service allows to register constraints. See KISS documentation for more details. - */ -public interface IConstraintService { - - /** Returns the service instance. */ - public static IConstraintService getInstance() { - return ConstraintService.getInstance(); - } - - /** - * Verifies the constraint instance <code>ci</code>. The service always runs the verification - * in a command. Should not yield any "useless" change because verification should always update - * the constraint instance status and the checksums anyways. - */ - void verify(ConstraintInstance ci); - - /** - * Tries to cancel the last verification of the constraint instance <code>ci</code>. The actual - * actions to take upon cancellation are up to the constraint. - */ - void cancel(ConstraintInstance ci); - - /** - * @return <code>true</code> if the constraint instance <code>ci</code> is up to date. - * This does not just look at the status but computes a diff between the constrained - * element and the one for which the constraint instance was last time checked. In the - * standard case, it is enough to call IConstraintVerificationUIService.getStatus and - * see if the result is an instance of {@link OutdatedConstraintInstanceStatus}. You - * should use <code>isUpToDate</code> *only if - * IConstraintVerificationUIService.getStatus does not provide the information you - * want*. - */ - boolean isUpToDate(ConstraintInstance ci); - - /** - * Completes <code>top</code> with missing constraints instances of constraint handled by - * <code>cstrClass</code>, if applicable. - * - * @return List of added constraints instances. - * - */ - List<ConstraintInstance> addMissingConstraintsInstances(ITopLevelElement top, - Class<? extends IConstraint> cstrClass); - - /** Returns the name of the given constraint, usable for serialization. */ - public String getName(Class<? extends IConstraint> cstrClass); - - /** - * @param cstrClass - * @return name of the group that a particular constraint belong to - */ - public String getGroupName(Class<? extends IConstraint> cstrClass); - - /** Returns a constraint, given its name. */ - public Class<? extends IConstraint> getConstraintByName(String name); - - /** Registers the given verifier with the service. */ - void registerConstraint(Class<? extends IConstraint> cstrClass); - - /** <code>true</code> if the given instance is queued for update. */ - boolean isUpdating(ConstraintInstance ci); - - /** - * Marks the given instance as being queued for update. - * - * ONLY FOR INTERNAL USE. - */ - void markAsUpdating(ConstraintInstance ci); -} diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/.ratings b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/.ratings index a14d336f35b4b272093a2fc62dcf8c95d8cadab7..8fb040ffbf08c91fe3c8dea473975346c23c28b3 100644 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/.ratings +++ b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/.ratings @@ -1,5 +1,4 @@ CompositionUtils.java 34c0a191bd0fb4176c94b4d61abb5c88a679d5e8 GREEN -ConstraintsUtils.java 0f8be020f2ca4bb08931c32452163c04a28e30ce GREEN EMFResourceUtils.java 979d0e1f4f66a2b3e715d2da0ebef6493f547fd7 GREEN EcoreSerializerBase.java 0a0c2969d793d2e68094c55c8f7b0a662ef6e5d5 GREEN EcoreUtils.java 18416b5c214410a02eb35596fd807a1cc27d6b35 GREEN @@ -10,6 +9,6 @@ JavaUtils.java 65cdadfb9137a240ad59992eacf53a15b7f20804 GREEN KernelModelElementUtils.java fded09befe7e543fc04ea5184ffc1c8a309d7a66 GREEN LoggingUtils.java 0e0aa5d466d80ea29cfc7e91178b23a5cdd4ddf7 GREEN PrototypesUtils.java ec75bed75cfc5103f1f38e3a29df86f729428775 GREEN -ResourceUtils.java e31eda3fdbedd2e44c85d471f717b14f92a3c663 GREEN +ResourceUtils.java 7f4941a83115dfbed75eb58b79c0a372fe1cbb94 GREEN TransformationUtils.java 552d3a9d56d34450be781af828efe0b8aa5d359e GREEN UniqueIDUtils.java 665955b1790c1bd1c2087e23114da920bfec2265 GREEN diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/ConstraintsUtils.java b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/ConstraintsUtils.java deleted file mode 100644 index 0f8be020f2ca4bb08931c32452163c04a28e30ce..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/ConstraintsUtils.java +++ /dev/null @@ -1,224 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2011 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.utils; - -import java.util.NoSuchElementException; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.common.util.TreeIterator; -import org.eclipse.emf.ecore.EObject; -import org.fortiss.tooling.kernel.extension.IConstraint; -import org.fortiss.tooling.kernel.model.IIdLabeled; -import org.fortiss.tooling.kernel.model.constraints.ConstraintInstance; -import org.fortiss.tooling.kernel.model.constraints.ConstraintsFactory; -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.service.IConstraintService; - -/** - * Utility methods for dealing with constraints. - * - * @author aravantinos - */ -public class ConstraintsUtils { - - /** - * Returns the container of <code>ci</code>. Assumes that it is of type - * {@link IConstraintInstanceContainer}! - */ - public static IConstraintInstanceContainer - getConstraintInstanceContainer(ConstraintInstance ci) { - return (IConstraintInstanceContainer)ci.eContainer(); - } - - /** - * Defines <code>constrained</code> as the <code>i</code>-th constrained model element of - * <code>ci</code>. Leaves the other elements as they are if they exist, fill them with - * <code>constrained</code> till <code>i</code> otherwise (we cannot set to <code>null</code>). - */ - public static void setConstrainedElement(ConstraintInstance ci, IConstrained constrained, - int i) { - EList<IConstrained> constraineds = ci.getConstraineds(); - for(int j = constraineds.size(); j <= i; j++) { - constraineds.add(j, constrained); - } - if(!constrained.getConstraintInstances().contains(ci)) { - constrained.getConstraintInstances().add(ci); - } - } - - /** @return the first constraint instance of type <code>cstr</code> in <code>c</code>. */ - public static ConstraintInstance getConstraintInstanceOfType(IConstrained c, IConstraint cstr) { - return getConstraintInstanceOfType(c, cstr.getClass()); - } - - /** @return the first constraint instance of type <code>cstr</code> in <code>c</code>. */ - public static ConstraintInstance getConstraintInstanceOfType(IConstrained c, - Class<? extends IConstraint> cstrClass) { - try { - String name = cstrClass.getName(); - return c.getConstraintInstances().stream() - .filter(x -> name.equals(x.getConstraintName())).findFirst().get(); - } catch(NoSuchElementException e) { - return null; - } - } - - /** Exception which embeds a constraint error status. */ - public static class ErrorEmbeddingException extends RuntimeException { - - /** The embedded error. */ - public ErrorConstraintInstanceStatus error; - - /** Constructor. */ - public ErrorEmbeddingException(ErrorConstraintInstanceStatus error) { - super(); - this.error = error; - } - } - - /** @return A "success" status. */ - public static SuccessConstraintInstanceStatus createSuccessStatus() { - return ConstraintsFactory.eINSTANCE.createSuccessConstraintInstanceStatus(); - } - - /** @return A "outdated" status for <code>ci</code>. */ - public static OutdatedConstraintInstanceStatus createOutdatedStatus(ConstraintInstance ci) { - OutdatedConstraintInstanceStatus status; - if(ci.getStatus() instanceof OutdatedConstraintInstanceStatus) { - status = (OutdatedConstraintInstanceStatus)ci.getStatus(); - } else { - status = ConstraintsFactory.eINSTANCE.createOutdatedConstraintInstanceStatus(); - ci.setStatus(status); - } - return status; - } - - /** @return A "outdated" status. */ - public static OutdatedConstraintInstanceStatus createOutdatedStatus() { - return ConstraintsFactory.eINSTANCE.createOutdatedConstraintInstanceStatus(); - } - - /** @return A "fail" status. */ - public static FailedConstraintInstanceStatus createFailStatus() { - return ConstraintsFactory.eINSTANCE.createFailedConstraintInstanceStatus(); - } - - /** @return An "error" status. */ - public static ErrorConstraintInstanceStatus createErrorStatus() { - return ConstraintsFactory.eINSTANCE.createErrorConstraintInstanceStatus(); - } - - /** @return the first element constrained by <code>ci</code> */ - public static IConstrained getFirstConstrained(ConstraintInstance ci) { - try { - // get(0) because the constraint instance shall contain at least one constrained element - // (responsibility of the caller!) and because we want the first element. - return ci.getConstraineds().get(0); - } catch(IndexOutOfBoundsException e) { - return null; - } - } - - /** Sets the first constrained element of <code>ci</code> to <code>constrained</code>. */ - public static void setFirstConstrained(ConstraintInstance ci, IConstrained constrained) { - setConstrainedElement(ci, constrained, 0); - } - - /** @return the second element constrained by <code>ci</code> */ - public static IConstrained getSecondConstrained(ConstraintInstance ci) { - try { - // get(1) because the constraint instance shall contain at least one constrained element - // (responsibility of the caller!) and because we want the first element. - return ci.getConstraineds().get(1); - } catch(IndexOutOfBoundsException e) { - return null; - } - } - - /** Sets the second constrained element of <code>ci</code> to <code>constrained</code>. */ - public static void setSecondConstrained(ConstraintInstance ci, IConstrained constrained) { - setConstrainedElement(ci, constrained, 1); - } - - /** - * @return the element constrained by <code>ci</code>. - * Use this function if your constraint constrains only one element! - */ - public static IConstrained getConstrained(ConstraintInstance ci) { - return getFirstConstrained(ci); - } - - /** - * Sets the constrained element of <code>ci</code> to <code>constrained</code>. - * Use this function if your constraint constrains only one element! - */ - public static void setConstrained(ConstraintInstance ci, IConstrained constrained) { - setConstrainedElement(ci, constrained, 0); - } - - /** - * @return a constraint instance of type <code>cstrClass</code> constraining - * <code>constrained</code> - */ - public static ConstraintInstance createConstraintInstance( - Class<? extends IConstraint> cstrClass, IConstrained constrained) { - ConstraintInstance ci = ConstraintsFactory.eINSTANCE.createConstraintInstance(); - ci.setConstraintName(cstrClass.getName()); - setConstrained(ci, constrained); - createOutdatedStatus(ci); - return ci; - } - - /** - * @return a constraint instance of type <code>cstrClass</code> constraining - * <code>constrained1</code> and <code>constrained2</code>. - */ - public static ConstraintInstance createConstraintInstance( - Class<? extends IConstraint> cstrClass, IConstrained constrained1, - IConstrained constrained2) { - ConstraintInstance c = ConstraintsFactory.eINSTANCE.createConstraintInstance(); - c.setConstraintName(IConstraintService.getInstance().getName(cstrClass)); - setFirstConstrained(c, constrained1); - setSecondConstrained(c, constrained2); - createOutdatedStatus(c); - return c; - } - - /** @return a successful status if <code>b</code> is true, a fail status otherwise */ - static public IConstraintInstanceStatus successIfTrue(boolean b) { - return b ? createSuccessStatus() : createFailStatus(); - } - - /** Removes the IDs of the given object and of its sub-elements. */ - public static void filterIDs(EObject obj) { - if(obj instanceof IIdLabeled) { - ((IIdLabeled)obj).setId(0); - } - TreeIterator<EObject> it = obj.eAllContents(); - while(it.hasNext()) { - EObject elt = it.next(); - if(elt instanceof IIdLabeled) { - ((IIdLabeled)elt).setId(0); - } - } - } -} diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/ResourceUtils.java b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/ResourceUtils.java index e31eda3fdbedd2e44c85d471f717b14f92a3c663..7f4941a83115dfbed75eb58b79c0a372fe1cbb94 100644 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/ResourceUtils.java +++ b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/ResourceUtils.java @@ -117,11 +117,11 @@ public final class ResourceUtils { for(ManyReference ref : forwardManyReferences) { Object[] values = ref.getValues(); - for(String id : (String[])values) { + for(Object id : values) { EObject obj; try { - obj = xmlResource.getEObject(id); + obj = xmlResource.getEObject((String)id); } catch(RuntimeException exception) { obj = null; }