blob: c473974144e86c718e49de8c46eed0e1da8d0a1c (
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/*****************************************************************************
* Copyright (c) 2016 CEA LIST 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:
* Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.infra.internationalization.commands;
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.EMFEditPlugin;
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;
/**
* This allows to define a command to reset the feature value needed.
*/
public class ResetNameTransactionalCommand extends AbstractTransactionalCommand {
/**
* The owner to modify.
*/
private EObject owner;
/**
* The feature tu reset.
*/
private EStructuralFeature feature;
/**
* This caches the label.
*/
protected static final String LABEL = EMFEditPlugin.INSTANCE.getString("_UI_SetCommand_label");
/**
* Constructor.
*
* @param domain
* The current editing domain.
* @param owner
* The owner to modify.
* @param feature
* The feature to reset.
*/
public ResetNameTransactionalCommand(final TransactionalEditingDomain domain, final EObject owner,
final EStructuralFeature feature) {
super(domain, LABEL, null);
this.owner = owner;
this.feature = feature;
}
/**
* {@inheritDoc}
*
* @see org.eclipse.core.commands.operations.AbstractOperation#canExecute()
*/
@Override
public boolean canExecute() {
return null != this.owner.eClass().getEStructuralFeature(feature.getFeatureID())
&& null != this.owner.eGet(this.feature);
}
/**
* {@inheritDoc}
*
* @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor,
* org.eclipse.core.runtime.IAdaptable)
*/
@Override
protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info)
throws ExecutionException {
final Object oldValue = this.owner.eGet(this.feature);
this.owner.eSet(feature, null);
this.owner.eSet(feature, oldValue);
return CommandResult.newOKCommandResult(this.owner);
}
}
|