blob: fbc5b0215b09ae62af2ff41ba80299a4f7007f12 [file] [log] [blame]
/*****************************************************************************
* 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.IFigure;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.gmfdiag.common.locator.PapyrusLabelLocator;
import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.AssociationEditPart;
import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.AssociationMultiplicityTargetEditPart;
import org.eclipse.papyrus.uml.diagram.clazz.lf.associationlabellayout.locators.target.TargetLocatorFactory;
/**
* This alternative implementation of AssociationMultiplicityTargetEditPart is mainly
* motivated to bypass the access to the corresponding figure (target multiplicity
* {@link org.eclipse.papyrus.uml.diagram.clazz.lf.associationlabellayout.figures.SelfLaidOutWrappingLabel})
* and its associated locator
* {@link org.eclipse.papyrus.uml.diagram.clazz.lf.associationlabellayout.locators.target.MultiplicityTargetLabelLocator}.<BR>
*
*/
public class SelfLaidOutAssociationMultiplicityTargetEditPart extends AssociationMultiplicityTargetEditPart implements AccessForLocatorManager {
private LocatorManager locatorManager;
/**
* Inherited constructor.
*
* @param view (legacy)
*/
public SelfLaidOutAssociationMultiplicityTargetEditPart(View view) {
super(view);
locatorManager=new LocatorManager(this);
}
/**
* This method is called when an visual update is necessary. The main goal here
* is to create an instance of our locator
* ({@link org.eclipse.papyrus.uml.diagram.clazz.lf.associationlabellayout.locators.target.MultiplicityTargetLabelLocator})
* if it is the first refreshBounds. The creation of this instance is done
* through the {@link SelfLaidOutAssociationMultiplicityTargetEditPart#initializeLocator(Connection, Point)} method here but this method is called in the
* LocatorManager
* ({@link org.eclipse.papyrus.uml.diagram.clazz.lf.associationlabellayout.edit.parts.LocatorManager#connectSpecificLocatorIfActivated()}
*/
@Override
public void refreshBounds() {
locatorManager.connectSpecificLocatorIfActivated();
super.refreshBounds();
}
/**
* This method creates the (good) locator for this target multiplicity.
*/
public void initializeLocator(Connection connectionFigure, Point offset) {
papyrusLabelLocator = TargetLocatorFactory.getInstance().createMultiplicityTargetLabelLocator(connectionFigure, offset, getKeyPoint());
}
/**
* This method gets the corresponding figure for this target multiplicity. It asks the AssociationFigure (PrimaryShape) for that.
*/
@Override
public IFigure getFigure() {
return AssociationEditPart.class.cast(getParent()).getPrimaryShape().getMultiplicityTargetLabel();
}
/**
* This method gets the locator (i.e. layout manager) for this target multiplicity.
*/
@Override
public PapyrusLabelLocator getLocator() {
return this.papyrusLabelLocator;
}
/**
* This method sets the locator (i.e. layout manager) for this target multiplicity.
*/
@Override
public void setLocator(PapyrusLabelLocator locator) {
this.papyrusLabelLocator=locator;
}
}