blob: 6aac43ccb0a2c6771f05ef10b92d8ad361fe5cb7 [file] [log] [blame]
/**
* Copyright (c) 2017 protos software gmbh (http://www.protos.de).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* CONTRIBUTORS:
* Juergen Haug (initial contribution)
*/
package org.eclipse.etrice.ui.behavior.fsm.provider;
import com.google.common.base.Objects;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap;
import com.google.inject.Injector;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.etrice.core.fsm.fSM.ModelComponent;
import org.eclipse.etrice.core.fsm.fSM.StateGraph;
import org.eclipse.etrice.core.fsm.util.FSMHelpers;
import org.eclipse.etrice.ui.behavior.fsm.editor.AbstractFSMDiagramTypeProvider;
import org.eclipse.etrice.ui.behavior.fsm.support.util.FSMSupportUtil;
import org.eclipse.etrice.ui.common.base.support.DiagramAccessBase;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.PictogramLink;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.services.ILinkService;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ListExtensions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
/**
* Provides the {@linkplain PictogramElement} objects of the base class diagram.
* This is a reverse mapping from room business objects to linked base diagram pictograms.
*
* TODO: use fsmgenmodel instead
*/
@SuppressWarnings("all")
public class BaseDiagramProvider {
private final Multimap<EObject, PictogramElement> baseDiagramBusinessObjs = ArrayListMultimap.<EObject, PictogramElement>create();
private final FSMHelpers fsmHelpers = FSMSupportUtil.getInstance().getFSMHelpers();
public BaseDiagramProvider(final AbstractFSMDiagramTypeProvider diagramTypeProvider) {
Injector _injector = diagramTypeProvider.getInjector();
final DiagramAccessBase diagramAccess = _injector.<DiagramAccessBase>getInstance(DiagramAccessBase.class);
ILinkService _linkService = Graphiti.getLinkService();
Diagram _diagram = diagramTypeProvider.getDiagram();
EObject _businessObjectForLinkedPictogramElement = _linkService.getBusinessObjectForLinkedPictogramElement(_diagram);
final ModelComponent mc = ((ModelComponent) _businessObjectForLinkedPictogramElement);
Diagram _diagram_1 = diagramTypeProvider.getDiagram();
Resource _eResource = _diagram_1.eResource();
final ResourceSet rs = _eResource.getResourceSet();
ArrayList<ModelComponent> _newArrayList = CollectionLiterals.<ModelComponent>newArrayList();
final Procedure1<ArrayList<ModelComponent>> _function = (ArrayList<ModelComponent> it) -> {
ModelComponent base = mc.getBase();
while (((base != null) && it.add(base))) {
ModelComponent _base = base.getBase();
base = _base;
}
};
final ArrayList<ModelComponent> baseClasses = ObjectExtensions.<ArrayList<ModelComponent>>operator_doubleArrow(_newArrayList, _function);
List<ModelComponent> _reverseView = ListExtensions.<ModelComponent>reverseView(baseClasses);
final Consumer<ModelComponent> _function_1 = (ModelComponent base) -> {
final Diagram baseDiagram = diagramAccess.getDiagram(base, rs);
boolean _notEquals = (!Objects.equal(baseDiagram, null));
if (_notEquals) {
Map<EObject, Collection<EStructuralFeature.Setting>> _find = EcoreUtil.ExternalCrossReferencer.find(baseDiagram);
final BiConsumer<EObject, Collection<EStructuralFeature.Setting>> _function_2 = (EObject targetEObj, Collection<EStructuralFeature.Setting> eFeatureSetting) -> {
final Function1<EStructuralFeature.Setting, EObject> _function_3 = (EStructuralFeature.Setting it) -> {
return it.getEObject();
};
Iterable<EObject> _map = IterableExtensions.<EStructuralFeature.Setting, EObject>map(eFeatureSetting, _function_3);
Iterable<PictogramLink> _filter = Iterables.<PictogramLink>filter(_map, PictogramLink.class);
final Function1<PictogramLink, PictogramElement> _function_4 = (PictogramLink it) -> {
return it.getPictogramElement();
};
Iterable<PictogramElement> _map_1 = IterableExtensions.<PictogramLink, PictogramElement>map(_filter, _function_4);
final Consumer<PictogramElement> _function_5 = (PictogramElement pe) -> {
this.put(mc, targetEObj, pe);
};
_map_1.forEach(_function_5);
};
_find.forEach(_function_2);
EList<Resource> _resources = rs.getResources();
Resource _eResource_1 = baseDiagram.eResource();
_resources.remove(_eResource_1);
}
};
_reverseView.forEach(_function_1);
}
private boolean put(final ModelComponent mc, final EObject obj, final PictogramElement value) {
boolean _xblockexpression = false;
{
if ((obj instanceof StateGraph)) {
boolean _isTopLevel = this.fsmHelpers.isTopLevel(((StateGraph)obj));
if (_isTopLevel) {
StateGraph _stateMachine = mc.getStateMachine();
this.baseDiagramBusinessObjs.put(_stateMachine, value);
}
}
_xblockexpression = this.baseDiagramBusinessObjs.put(obj, value);
}
return _xblockexpression;
}
public Collection<PictogramElement> getPictograms(final EObject roomObj) {
Collection<PictogramElement> _xifexpression = null;
boolean _equals = Objects.equal(roomObj, null);
if (_equals) {
_xifexpression = CollectionLiterals.<PictogramElement>emptyList();
} else {
_xifexpression = this.baseDiagramBusinessObjs.get(roomObj);
}
return _xifexpression;
}
}