Commit 6b4c06cf authored by Aurelien Pupier's avatar Aurelien Pupier
Browse files

BS-9388: don't use the CustomFeedbackXYLayoutEditPolicy when moving

LabelEditPart but NonResizableLabelEditpolicy. Now use a custom
NonResiableLabelEditPolicy in order to avoid to move label in another
pool. There are still issues when moving in another lane (perhaps
subprocess too?)
parent cacfaea3
/**
* Copyright (C) 2014 Bonitasoft S.A.
* import org.bonitasoft.studio.common.emf.tools.ModelHelper;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.requests.ChangeBoundsRequest;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
ense, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.common.gmf;
import org.bonitasoft.studio.common.emf.tools.ModelHelper;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.requests.ChangeBoundsRequest;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
public class ChangeBoundsRequestUtil {
public static boolean isMovingToAnotherProcess(final EditPart host, final ChangeBoundsRequest request) {
//find the target EditPart on which we will move the getHost()
if (host.getViewer().findObjectAt(request.getLocation()) instanceof IGraphicalEditPart) {
final IGraphicalEditPart target = (IGraphicalEditPart) host.getViewer().findObjectAt(request.getLocation());
EObject source = null;
for (final Object e : request.getEditParts()) {
source = ((IGraphicalEditPart) e).resolveSemanticElement();
}
return areInSameProcess(source, target.resolveSemanticElement());
}
return true;
}
private static boolean areInSameProcess(final EObject o, final EObject hostObject) {
return ModelHelper.getParentProcess(o).equals(ModelHelper.getParentProcess(hostObject));
}
}
/**
* Copyright (C) 2010 BonitaSoft S.A.
* BonitaSoft, 31 rue Gustave Eiffel - 38000 Grenoble
*
* Copyright (C) 2010-2014 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.common.gmf;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
import org.eclipse.gmf.runtime.diagram.ui.figures.LabelLocator;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.View;
/**
* @author Baptiste Mesta
*
*/
public class CustomEventLabelEditPart extends LabelEditPart {
/**
* @param view
*/
public CustomEventLabelEditPart(View view) {
super(view);
}
/**
* @param view
*/
public CustomEventLabelEditPart(final View view) {
super(view);
}
/**
* @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#createDefaultEditPolicies()
*/
@Override
protected void createDefaultEditPolicies() {
super.createDefaultEditPolicies();
installEditPolicy(
EditPolicy.PRIMARY_DRAG_ROLE,
new CustomNonResizableLabelEditPolicy());
}
public void refreshBounds() {
IFigure refFigure = ((GraphicalEditPart) getParent()).getFigure();
int dx = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE
.getLocation_X())).intValue();
int dy = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE
.getLocation_Y())).intValue();
Point offset = new Point(dx, dy);
if(getFigure().getParent() != null){
getFigure().getParent().setConstraint(getFigure(),
new LabelLocator(refFigure, offset, getKeyPoint()) {
@Override
public void refreshBounds() {
final IFigure refFigure = ((GraphicalEditPart) getParent()).getFigure();
final int dx = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE
.getLocation_X())).intValue();
final int dy = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE
.getLocation_Y())).intValue();
final Point offset = new Point(dx, dy);
if(getFigure().getParent() != null){
getFigure().getParent().setConstraint(getFigure(),
new LabelLocator(refFigure, offset, getKeyPoint()) {
public void relocate(IFigure target) {
Point location = getReferencePoint().getTranslated(
getOffset());
location.translate(-target.getBounds().width / 2, 0);
target.setLocation(location);
target.setSize(new Dimension(
target.getPreferredSize().width, target
.getPreferredSize().height));
}
@Override
public void relocate(final IFigure target) {
final Point location = getReferencePoint().getTranslated(
getOffset());
location.translate(-target.getBounds().width / 2, 0);
target.setLocation(location);
target.setSize(new Dimension(
target.getPreferredSize().width, target
.getPreferredSize().height));
}
protected Point getReferencePoint() {
return getLabelLocation(parent);
}
});
}
}
@Override
protected Point getReferencePoint() {
return getLabelLocation(parent);
}
});
}
}
@Override
public Point getReferencePoint() {
return getLabelLocation(((GraphicalEditPart) getParent()).getFigure());
}
@Override
public Point getReferencePoint() {
return getLabelLocation(((GraphicalEditPart) getParent()).getFigure());
}
protected Point getLabelLocation(IFigure parent) {
return parent.getBounds().getBottom();
}
protected Point getLabelLocation(final IFigure parent) {
return parent.getBounds().getBottom();
}
}
/**
* Copyright (C) 2014 Bonitasoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.common.gmf;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.UnexecutableCommand;
import org.eclipse.gef.requests.ChangeBoundsRequest;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy;
public class CustomNonResizableLabelEditPolicy extends NonResizableLabelEditPolicy {
@Override
protected Command getMoveCommand(final ChangeBoundsRequest request) {
if (moveNotAllowed(request)) {
return UnexecutableCommand.INSTANCE;
}
return super.getMoveCommand(request);
}
private boolean moveNotAllowed(final ChangeBoundsRequest request) {
return !ChangeBoundsRequestUtil.isMovingToAnotherProcess(getHost(), request);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment