| /******************************************************************************* |
| * 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.commands.Command; |
| import org.eclipse.stem.model.ui.editor.vismodel.CompartmentElement; |
| import org.eclipse.stem.model.ui.editor.vismodel.ModelElement; |
| |
| /** |
| * GEF command to add a new CompartmentElement to the existing Model |
| */ |
| public class CompartmentCreateCommand extends Command |
| { |
| private CompartmentElement comaprtment; |
| private ModelElement model; |
| private Rectangle bounds; |
| |
| public CompartmentCreateCommand(CompartmentElement comaprtment, ModelElement model, |
| Rectangle bounds) { |
| this.comaprtment = comaprtment; |
| this.model = model; |
| this.bounds = bounds; |
| setLabel("Create Compartment"); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.gef.commands.Command#canExecute() |
| */ |
| public boolean canExecute() { |
| return comaprtment != null && model != null && bounds != null; |
| } |
| |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.gef.commands.Command#execute() |
| */ |
| public void execute() { |
| comaprtment.setX(bounds.x()); |
| comaprtment.setY(bounds.y()); |
| comaprtment.setWidth(bounds.width()); |
| comaprtment.setHeight(bounds.height()); |
| redo(); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.gef.commands.Command#redo() |
| */ |
| public void redo() { |
| model.addCompartment(comaprtment); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.gef.commands.Command#undo() |
| */ |
| public void undo() { |
| model.removeCompartment(comaprtment); |
| } |
| |
| } |