Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0e033a75c3fe175de3bca15728802137184a3363 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*****************************************************************************
 * Copyright (c) 2011 CEA LIST.
 *
 * 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:
 *
 *		CEA LIST - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.uml.diagram.component.custom.command;

import java.util.Collections;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.command.SetCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.uml.diagram.common.commands.SemanticAdapter;

/**
 * this command is used to set a value of a view during the execution
 * as deferred command
 *
 */
public class DeferredSetViewCommand extends AbstractTransactionalCommand {

	private EStructuralFeature feature;
	private Object value;
	private SemanticAdapter semanticAdapter;

	/**
	 *
	 * Constructor.
	 *
	 * @param domain
	 *            the transactional command
	 * @param semanticAdapter
	 *            the semanticadapter that wrap the view
	 * @param feature
	 *            the ecore feature
	 * @param value
	 *            the value that will be associated
	 */
	public DeferredSetViewCommand(TransactionalEditingDomain domain, SemanticAdapter semanticAdapter, EStructuralFeature feature, Object value) {
		super(domain, "DeferredSetCommand", Collections.emptyList());
		this.semanticAdapter = semanticAdapter;
		this.feature = feature;
		this.value = value;
	}

	@Override
	protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
		SetCommand cmd = new SetCommand(this.getEditingDomain(), (EObject) semanticAdapter.getAdapter(View.class), feature, value);
		cmd.canExecute();
		cmd.execute();
		return CommandResult.newOKCommandResult();

	}
}

Back to the top