View Javadoc
1   /*****************************************************************************
2    * Copyright (c) 2015 CEA LIST and others.
3    * 
4    * All rights reserved. This program and the accompanying materials
5    * are made available under the terms of the Eclipse Public License v1.0
6    * which accompanies this distribution, and is available at
7    * http://www.eclipse.org/legal/epl-v10.html
8    *
9    * Contributors:
10   *  Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
11   *   
12   *****************************************************************************/
13  
14  package org.eclipse.papyrus.sysml14.diagram.common.command;
15  
16  import org.eclipse.core.commands.ExecutionException;
17  import org.eclipse.core.runtime.IAdaptable;
18  import org.eclipse.core.runtime.IProgressMonitor;
19  import org.eclipse.gmf.runtime.common.core.command.CommandResult;
20  import org.eclipse.gmf.runtime.common.core.command.ICommand;
21  import org.eclipse.gmf.runtime.emf.type.core.commands.ConfigureElementCommand;
22  import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
23  import org.eclipse.papyrus.infra.services.edit.utils.GMFCommandUtils;
24  import org.eclipse.uml2.uml.Property;
25  import org.eclipse.uml2.uml.Type;
26  
27  /**
28   * Configure a part with the created/selected type
29   */
30  public class ConfigurePartCommand extends ConfigureElementCommand {
31  
32  
33  	private Type partType;
34  	private ICommand typeCreationCommand;
35  
36  
37  	/**
38  	 * Constructor.
39  	 *
40  	 * @param request configuration request
41  	 * @param partType the featuring type of the part
42  	 * @param typeCreationCommand if needed create the type
43  	 */
44  	public ConfigurePartCommand(ConfigureRequest request, Type partType, ICommand typeCreationCommand) {
45  		super(request);
46  		this.partType= partType;
47  		this.typeCreationCommand = typeCreationCommand;
48  	}
49  
50  	@Override
51  	protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
52  
53  		Property part = (Property) getElementToEdit();
54  		if (partType != null) {
55  			part.setType(partType);
56  		} else {
57  			Type newType = (Type) GMFCommandUtils.getCommandEObjectResult(typeCreationCommand);
58  			part.setType(newType);
59  		}
60  		return CommandResult.newOKCommandResult(part);
61  	}
62  }