blob: 8b8f58406618cbc3a571eac2a7595177030f6d55 [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.AssociationMultiplicitySourceEditPart;
import org.eclipse.papyrus.uml.diagram.clazz.lf.associationlabellayout.locators.source.SourceLocatorFactory;
/**
* This alternative implementation of AssociationMultiplicitySourceEditPart is
* mainly motivated to bypass the access to the corresponding figure (source
* 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.source.MultiplicitySourceLabelLocator}.<BR>
*
*/
public class SelfLaidOutAssociationMultiplicitySourceEditPart extends AssociationMultiplicitySourceEditPart
implements AccessForLocatorManager {
private LocatorManager locatorManager;
/**
* Inherited constructor.
*
* @param view (legacy)
*/
public SelfLaidOutAssociationMultiplicitySourceEditPart(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.source.MultiplicitySourceLabelLocator})
* if it is the first refreshBounds. The creation of this instance is done
* through the
* {@link SelfLaidOutAssociationMultiplicitySourceEditPart#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 source multiplicity.
*/
public void initializeLocator(Connection connectionFigure, Point offset) {
papyrusLabelLocator = SourceLocatorFactory.getInstance().createMultiplicitySourceLabelLocator(connectionFigure, offset, getKeyPoint());
}
/**
* This method gets the corresponding figure for this source multiplicity. It
* asks the AssociationFigure (PrimaryShape) for that.
*/
@Override
public IFigure getFigure() {
return AssociationEditPart.class.cast(getParent()).getPrimaryShape().getMultiplicitySourceLabel();
}
/**
* This method gets the locator (i.e. layout manager) for this source
* multiplicity.
*/
@Override
public PapyrusLabelLocator getLocator() {
return this.papyrusLabelLocator;
}
/**
* This method sets the locator (i.e. layout manager) for this source
* multiplicity.
*/
@Override
public void setLocator(PapyrusLabelLocator locator) {
this.papyrusLabelLocator = locator;
}
}