| /***************************************************************************** |
| * 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.associationlabellayout.edit.parts; |
| |
| import org.eclipse.draw2d.Connection; |
| import org.eclipse.draw2d.geometry.Point; |
| import org.eclipse.gef.editparts.AbstractConnectionEditPart; |
| import org.eclipse.gmf.runtime.notation.NotationPackage; |
| import org.eclipse.papyrus.infra.gmfdiag.common.locator.PapyrusLabelLocator; |
| import org.eclipse.papyrus.uml.diagram.clazz.lf.associationlabellayout.preferences.Settings; |
| |
| /** |
| * This class is used to centralize and delegate operations about locators of |
| * the association end * edit parts. The class aims at: |
| * <UL> |
| * <LI>Checking if a locator has been created and associated to the edit |
| * part</LI> |
| * <LI>Initializing the locator</LI> |
| * <LI>Checking Papyrus preferences to see whether the locators of this plug-in |
| * will be used or not</LI> |
| * </UL> |
| * |
| */ |
| public class LocatorManager { |
| |
| private AccessForLocatorManager accessForLocatorManager; |
| private boolean activated; |
| |
| /** |
| * Each locator manager is associated to an edit part. Here, in order to access |
| * different types of edit parts (with not enough things in common), we have |
| * defined and used an interface {@link AccessForLocatorManager} for this common |
| * access/association. |
| * |
| * @param editPart edit part that implements our specific interface {@link AccessForLocatorManager} |
| */ |
| public LocatorManager(AccessForLocatorManager editPart) { |
| this.accessForLocatorManager = editPart; |
| activated = Settings.getInstance().isActivated(); |
| } |
| |
| /** |
| * This method is called by association end * edit part at the first refreshBounds invocation. |
| * It will invoke the {@link LocatorManager#initializeLocator()} method if there is no locator in the edit part. |
| */ |
| protected void connectSpecificLocatorIfActivated() { |
| hasActivationStatusChanged(); |
| if (Settings.getInstance().isActivated()) { |
| PapyrusLabelLocator locator = accessForLocatorManager.getLocator(); |
| if (locator == null) { |
| initializeLocator(); |
| } |
| } |
| } |
| |
| /** |
| * This method just stores the plug-in activation status and/or see whether it has changed or not in order to reset locator (and it will be re-created at the next refreshBounds of the edit part). |
| */ |
| protected void hasActivationStatusChanged() { |
| if (Settings.getInstance().isActivated() != activated) { |
| accessForLocatorManager.setLocator(null); |
| activated = Settings.getInstance().isActivated(); |
| } |
| } |
| |
| /** |
| * Reuse a part of the implementation of super class for the locator initialization, but with different types of objects for figure and locator. |
| */ |
| protected void initializeLocator() { |
| int dx = ((Integer) accessForLocatorManager.getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); |
| int dy = ((Integer) accessForLocatorManager.getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); |
| |
| Point offset = new Point(dx, dy); |
| |
| if (accessForLocatorManager.getParent() instanceof AbstractConnectionEditPart) { |
| |
| Connection connectionFigure = AbstractConnectionEditPart.class.cast(accessForLocatorManager.getParent()).getConnectionFigure(); |
| |
| if (accessForLocatorManager.getLocator() == null) { |
| accessForLocatorManager.initializeLocator(connectionFigure, offset); |
| } |
| } |
| } |
| } |