| /******************************************************************************* |
| * Copyright (c) 2013 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.stem.model.ui.editor.commands; |
| |
| import org.eclipse.draw2d.geometry.Rectangle; |
| import org.eclipse.gef.RequestConstants; |
| import org.eclipse.gef.commands.Command; |
| import org.eclipse.gef.requests.ChangeBoundsRequest; |
| import org.eclipse.stem.model.ui.editor.vismodel.CompartmentElement; |
| |
| |
| public class CompartmentSetConstraintCommand extends Command { |
| private Rectangle newBounds; |
| private Rectangle oldBounds; |
| private ChangeBoundsRequest request; |
| private CompartmentElement compartment; |
| |
| public CompartmentSetConstraintCommand(CompartmentElement compartment, ChangeBoundsRequest request, |
| Rectangle newBounds) { |
| this.compartment = compartment; |
| this.request = request; |
| this.newBounds = newBounds.getCopy(); |
| setLabel("move / resize"); |
| } |
| |
| public boolean canExecute() { |
| Object type = request.getType(); |
| return (RequestConstants.REQ_MOVE.equals(type) |
| || RequestConstants.REQ_MOVE_CHILDREN.equals(type) |
| || RequestConstants.REQ_RESIZE.equals(type) |
| || RequestConstants.REQ_RESIZE_CHILDREN |
| .equals(type)); |
| } |
| |
| public void execute() { |
| oldBounds = new Rectangle(compartment.getX(), compartment.getY(), compartment.getWidth(), compartment.getHeight()); |
| redo(); |
| } |
| |
| public void redo() { |
| compartment.setX(newBounds.x()); |
| compartment.setY(newBounds.y()); |
| compartment.setWidth(newBounds.width()); |
| compartment.setHeight(newBounds.height()); |
| } |
| |
| public void undo() { |
| compartment.setX(oldBounds.x()); |
| compartment.setY(oldBounds.y()); |
| compartment.setWidth(oldBounds.width()); |
| compartment.setHeight(oldBounds.height()); |
| } |
| } |