| /***************************************************************************** |
| * Copyright (c) 2019 CEA LIST. |
| * |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Xavier Le Pallec (for CEA LIST) xlepallec@lilo.org - Bug 558456 |
| * |
| *****************************************************************************/ |
| |
| package org.eclipse.papyrus.uml.diagram.clazz.lf.autosizeableclasses.statemachine; |
| |
| import java.util.HashMap; |
| import java.util.Map; |
| |
| import org.eclipse.gef.EditPart; |
| import org.eclipse.gef.RootEditPart; |
| |
| /** |
| * This class defines a mechanism to store a state machine for each class |
| * diagram with an indexation based on the root edit part of the diagram. A |
| * HashMap is used for that. |
| */ |
| public class StateMachineManager { |
| |
| static StateMachineManager INSTANCE = new StateMachineManager(); |
| private Map<RootEditPart, StateMachine> stateMachines; |
| |
| /** |
| * Get access to the manager (singleton). |
| * |
| * @return the state machine manager. |
| */ |
| public static StateMachineManager getInstance() { |
| return INSTANCE; |
| } |
| |
| /** |
| * the basic constructor only creates the dedicated hashmap. |
| */ |
| public StateMachineManager() { |
| stateMachines = new HashMap<>(); |
| } |
| |
| /** |
| * This method gets the state machine associated to the diagram where the edit |
| * part (parameter) is. |
| * |
| * @param editPart an edit part representing an element of a diagram. |
| * @return the state machine associated to the diagram where the edit part |
| * (parameter) is. |
| */ |
| public StateMachine getStateMachine(EditPart editPart) { |
| return getStateMachine(editPart.getRoot()); |
| } |
| |
| /** |
| * This method gets the state machine associated to the diagram represented by |
| * the root edit part (parameter). |
| * |
| * @param rootEditPart the edit part associated to a diagram |
| * @return the state machine associated to the diagram represented by the root |
| * edit part. |
| */ |
| public StateMachine getStateMachine(RootEditPart rootEditPart) { |
| StateMachine stateMachine = stateMachines.get(rootEditPart); |
| if (stateMachine == null) { |
| stateMachine = new StateMachine(rootEditPart); |
| stateMachines.put(rootEditPart, stateMachine); |
| } |
| return stateMachine; |
| } |
| |
| } |