| //------------------------------------------------------------------------------ |
| // Copyright (c) 2005, 2007 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 implementation |
| //------------------------------------------------------------------------------ |
| /** |
| * |
| */ |
| package org.eclipse.epf.diagramming.base.commands; |
| |
| import java.util.List; |
| import java.util.Map; |
| |
| import org.eclipse.core.commands.ExecutionException; |
| import org.eclipse.core.runtime.IAdaptable; |
| import org.eclipse.core.runtime.IProgressMonitor; |
| import org.eclipse.draw2d.geometry.Rectangle; |
| import org.eclipse.emf.transaction.TransactionalEditingDomain; |
| import org.eclipse.epf.diagramming.base.actions.ActionIds; |
| import org.eclipse.epf.diagramming.edit.parts.ActivityPartitionEditPart; |
| import org.eclipse.gef.EditPart; |
| import org.eclipse.gef.GraphicalEditPart; |
| import org.eclipse.gmf.runtime.common.core.command.CommandResult; |
| import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil; |
| import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand; |
| import org.eclipse.gmf.runtime.notation.NotationPackage; |
| import org.eclipse.gmf.runtime.notation.View; |
| |
| /** |
| * @author Shashidhar Kannoori |
| * |
| */ |
| public class OrientationCommand extends AbstractTransactionalCommand { |
| |
| private String orientation; |
| private EditPart editPart; |
| |
| /** |
| * @param domain |
| * @param label |
| * @param affectedFiles |
| */ |
| public OrientationCommand(TransactionalEditingDomain domain, String label, |
| EditPart editPart, String orientation) { |
| |
| super(domain, "Orientation", getWorkspaceFiles(((View)editPart.getModel()).eContainer())); |
| this.orientation = orientation; |
| this.editPart = editPart; |
| |
| setResult(CommandResult.newOKCommandResult(editPart.getModel())); |
| } |
| |
| /** |
| * @param domain |
| * @param label |
| * @param options |
| * @param affectedFiles |
| */ |
| public OrientationCommand(TransactionalEditingDomain domain, String label, |
| Map options, List affectedFiles) { |
| super(domain, label, options, affectedFiles); |
| // TODO Auto-generated constructor stub |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) |
| */ |
| protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
| IAdaptable info) throws ExecutionException { |
| if(orientation == ActionIds.ACTION_V_ORIENTATION){ |
| GraphicalEditPart part = (GraphicalEditPart)editPart; |
| Rectangle bounds = part.getFigure().getBounds(); |
| if (bounds != null) { |
| ViewUtil.setStructuralFeatureValue((View)part.getModel(),NotationPackage.eINSTANCE.getSize_Width(), new Integer(bounds.height)); |
| ViewUtil.setStructuralFeatureValue((View)part.getModel(),NotationPackage.eINSTANCE.getSize_Height(), new Integer(bounds.width)); |
| } |
| } |
| return CommandResult.newOKCommandResult(); |
| } |
| |
| public boolean canExecute() { |
| if(editPart instanceof ActivityPartitionEditPart) |
| return true; |
| else |
| return false; |
| } |
| } |