本文整理汇总了Java中org.eclipse.emf.edit.command.CommandParameter类的典型用法代码示例。如果您正苦于以下问题:Java CommandParameter类的具体用法?Java CommandParameter怎么用?Java CommandParameter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CommandParameter类属于org.eclipse.emf.edit.command包,在下文中一共展示了CommandParameter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.eclipse.emf.edit.command.CommandParameter; //导入依赖的package包/类
@Override
public void run() {
InputDialog inputDialog = new InputDialog(null, "Provide String", "Provide a new Name for the EClass", eclass.getName(), null);
int open = inputDialog.open();
if (open == Dialog.OK) {
String newName = inputDialog.getValue();
Resource resource = eclass.eResource();
ResourceSet resourceSet = resource.getResourceSet();
TransactionalEditingDomain domain = TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain(resourceSet);
try{
if (domain != null){
Command setCommand = domain.createCommand(SetCommand.class, new CommandParameter(eclass,
EcorePackage.Literals.ENAMED_ELEMENT__NAME, newName));
domain.getCommandStack().execute(setCommand);
try {
resource.save(Collections.emptyMap());
} catch (IOException e) {
e.printStackTrace();
}
}
}finally{
domain.dispose();
}
}
}
示例2: createCommand
import org.eclipse.emf.edit.command.CommandParameter; //导入依赖的package包/类
@Override
public Command createCommand(Object object, final EditingDomain domain, Class<? extends Command> commandClass, CommandParameter commandParameter) {
final ReferencedObjectRow row = (ReferencedObjectRow) object;
if (SetCommand.class == commandClass) {
return createSetCommand(row, domain, commandParameter);
} else if (AddCommand.class == commandClass) {
return createAddCommand(row, domain, commandParameter);
}
return super.createCommand(object, domain, commandClass, commandParameter);
}
示例3: createAddCommand
import org.eclipse.emf.edit.command.CommandParameter; //导入依赖的package包/类
private Command createAddCommand(final ReferencedObjectRow row, final EditingDomain domain, CommandParameter commandParameter) {
final CompoundCommand cmd = new CompoundCommand();
for (EPlanElement pe : getPlanElements(commandParameter.getCollection())) {
new PlanVisitor() {
@Override
protected void visit(EPlanElement element) {
EObject data = element.getData();
if (data != null) {
for (EReference r : data.eClass().getEReferences()) {
EObject reference = row.getReference();
if (r.getEReferenceType().isSuperTypeOf(reference.eClass())) {
if (r.isMany()) {
cmd.append(AddCommand.create(domain, data, r, Collections.singletonList(reference)));
} else {
cmd.append(SetCommand.create(domain, data, r, reference));
}
}
}
}
}
}.visitAll(pe);
}
if (!cmd.isEmpty()) {
return cmd;
} else {
return null;
}
}
示例4: createSetCommand
import org.eclipse.emf.edit.command.CommandParameter; //导入依赖的package包/类
private Command createSetCommand(final ReferencedObjectRow row, final EditingDomain domain, CommandParameter commandParameter) {
final CompoundCommand cmd = new CompoundCommand();
for (EPlanElement pe : getPlanElements(commandParameter.getValue())) {
new PlanVisitor() {
@Override
protected void visit(EPlanElement element) {
EObject data = element.getData();
if (data != null) {
for (EReference r : data.eClass().getEReferences()) {
EObject reference = row.getReference();
if (r.getEReferenceType().isSuperTypeOf(reference.eClass())) {
if (r.isMany()) {
cmd.append(SetCommand.create(domain, data, r, Collections.singletonList(reference)));
} else {
cmd.append(SetCommand.create(domain, data, r, reference));
}
}
}
}
}
}.visitAll(pe);
}
if (!cmd.isEmpty()) {
return cmd;
} else {
return null;
}
}
示例5: createCommand
import org.eclipse.emf.edit.command.CommandParameter; //导入依赖的package包/类
@Override
public Command createCommand(Object object, final EditingDomain domain, Class<? extends Command> commandClass, CommandParameter commandParameter) {
final FeatureValueRow row = (FeatureValueRow) object;
if (SetCommand.class == commandClass) {
return createSetCommand(row, domain, commandParameter);
} else if (AddCommand.class == commandClass) {
return createAddCommand(row, domain, commandParameter);
}
return super.createCommand(object, domain, commandClass, commandParameter);
}
示例6: createAddCommand
import org.eclipse.emf.edit.command.CommandParameter; //导入依赖的package包/类
private Command createAddCommand(final FeatureValueRow row, final EditingDomain domain, CommandParameter commandParameter) {
final CompoundCommand cmd = new CompoundCommand();
for (EPlanElement pe : getPlanElements(commandParameter.getCollection())) {
new PlanVisitor() {
@Override
protected void visit(EPlanElement element) {
EObject data = element.getData();
if (data != null) {
String valueLiteral = row.getValueLiteral();
String featureName = row.getFeatureName();
EClass eClass = data.eClass();
EStructuralFeature feature = eClass.getEStructuralFeature(featureName);
if (feature != null) {
Object value = null;
if (feature instanceof EAttribute) {
EAttribute eAttribute = (EAttribute)feature;
value = EcoreUtil.createFromString(eAttribute.getEAttributeType(), valueLiteral);
} else {
LogUtil.error("value for attribute literal impossible");
}
if (value != null) {
if (feature.isMany()) {
cmd.append(AddCommand.create(domain, data, feature, Collections.singletonList(value)));
} else {
cmd.append(SetCommand.create(domain, data, feature, value));
}
}
}
}
}
}.visitAll(pe);
}
if (!cmd.isEmpty()) {
return cmd;
}
return null;
}
示例7: createSetCommand
import org.eclipse.emf.edit.command.CommandParameter; //导入依赖的package包/类
private Command createSetCommand(final FeatureValueRow row, final EditingDomain domain, CommandParameter commandParameter) {
final CompoundCommand cmd = new CompoundCommand();
for (EPlanElement pe : getPlanElements(commandParameter.getValue())) {
new PlanVisitor() {
@Override
protected void visit(EPlanElement element) {
EObject data = element.getData();
if (data != null) {
String valueLiteral = row.getValueLiteral();
String featureName = row.getFeatureName();
EClass eClass = data.eClass();
EStructuralFeature feature = eClass.getEStructuralFeature(featureName);
if (feature != null) {
Object value = null;
if (feature instanceof EAttribute) {
EAttribute eAttribute = (EAttribute)feature;
value = EcoreUtil.createFromString(eAttribute.getEAttributeType(), valueLiteral);
} else {
LogUtil.error("value for EReference literal impossible");
}
if (value != null) {
if (feature.isMany()) {
cmd.append(SetCommand.create(domain, data, feature, Collections.singletonList(value)));
} else {
cmd.append(SetCommand.create(domain, data, feature, value));
}
}
}
}
}
}.visitAll(pe);
}
if (!cmd.isEmpty()) {
return cmd;
}
return super.createCommand(row, domain, SetCommand.class, commandParameter);
}
示例8: copyAndPasteFromClipboardCommand
import org.eclipse.emf.edit.command.CommandParameter; //导入依赖的package包/类
/**
* Tests the copy to clipboard and paste from clipboard command.
*/
@Test
public void copyAndPasteFromClipboardCommand() {
final TestElement leafSection = Create.testElement();
final TestElement actor = Create.testElement();
leafSection.getContainedElements().add(actor);
new EMFStoreCommand() {
@Override
protected void doRun() {
getProject().addModelElement(leafSection);
}
}.run(false);
final EditingDomain editingDomain = ESWorkspaceProviderImpl.getInstance().getEditingDomain();
// copy to clipboard
final Collection<EObject> toCopy = new ArrayList<EObject>();
toCopy.add(actor);
final Command copyCommand = editingDomain.createCommand(CopyToClipboardCommand.class, new CommandParameter(
null,
null, toCopy));
editingDomain.getCommandStack().execute(copyCommand);
// paste from clipboard
final Command pasteCommand = editingDomain.createCommand(PasteFromClipboardCommand.class, new CommandParameter(
leafSection, TestmodelPackage.Literals.TEST_ELEMENT__CONTAINED_ELEMENTS, Collections.emptyList(),
CommandParameter.NO_INDEX));
editingDomain.getCommandStack().execute(pasteCommand);
final EObject copyOfTestElement = leafSection.getContainedElements().get(1);
final ModelElementId actorId = ModelUtil.getProject(actor).getModelElementId(actor);
final ModelElementId copyOfTestElementId = ModelUtil.getProject(copyOfTestElement).getModelElementId(
copyOfTestElement);
assertTrue(actorId.equals(actorId));
assertTrue(!copyOfTestElementId.equals(actorId));
}
示例9: copyAndPasteFromClipboardCommandDirectCreation
import org.eclipse.emf.edit.command.CommandParameter; //导入依赖的package包/类
/**
* Tests the copy to clipboard and paste from clipboard command.
*/
@Test
public void copyAndPasteFromClipboardCommandDirectCreation() {
final TestElement leafSection = Create.testElement();
final TestElement actor = Create.testElement();
leafSection.getContainedElements().add(actor);
new EMFStoreCommand() {
@Override
protected void doRun() {
getProject().addModelElement(leafSection);
}
}.run(false);
final EditingDomain editingDomain = ESWorkspaceProviderImpl.getInstance().getEditingDomain();
// copy
final Command command = CopyToClipboardCommand.create(editingDomain, actor);
editingDomain.getCommandStack().execute(command);
// paste
final Command pasteCommand = PasteFromClipboardCommand.create(editingDomain, leafSection,
TestmodelPackage.Literals.TEST_ELEMENT__CONTAINED_ELEMENTS, CommandParameter.NO_INDEX);
editingDomain.getCommandStack().execute(pasteCommand);
final EObject copyOfTestElementRead = leafSection.getContainedElements().get(1);
final ModelElementId actorId = ModelUtil.getProject(actor).getModelElementId(actor);
final ModelElementId copyOfTestElementReadId = ModelUtil.getProject(copyOfTestElementRead).getModelElementId(
copyOfTestElementRead);
assertFalse(actorId.equals(copyOfTestElementReadId));
}
示例10: copyAndPasteCommandDirectCreation
import org.eclipse.emf.edit.command.CommandParameter; //导入依赖的package包/类
/**
* Tests the copy and paste commands.
*/
@Test
public void copyAndPasteCommandDirectCreation() {
final TestElement leafSection = Create.testElement();
final TestElement actor = Create.testElement();
leafSection.getContainedElements().add(actor);
new EMFStoreCommand() {
@Override
protected void doRun() {
getProject().addModelElement(leafSection);
}
}.run(false);
final EditingDomain editingDomain = ESWorkspaceProviderImpl.getInstance().getEditingDomain();
// copy
final Command command = CopyCommand.create(editingDomain, actor);
editingDomain.getCommandStack().execute(command);
// paste
final TestElement copyOfTestElement = (TestElement) command.getResult().toArray()[0];
final Collection<TestElement> toPaste = new ArrayList<TestElement>();
toPaste.add(copyOfTestElement);
final Command pasteCommand = AddCommand.create(editingDomain, leafSection,
TestmodelPackage.Literals.TEST_ELEMENT__CONTAINED_ELEMENTS, toPaste, CommandParameter.NO_INDEX);
editingDomain.getCommandStack().execute(pasteCommand);
final EObject copyOfTestElementRead = leafSection.getContainedElements().get(1);
final ModelElementId actorId = ModelUtil.getProject(actor).getModelElementId(actor);
final ModelElementId copyOfTestElementReadId = ModelUtil.getProject(copyOfTestElementRead).getModelElementId(
copyOfTestElementRead);
assertFalse(actorId.equals(copyOfTestElementReadId));
}
示例11: removeCommand
import org.eclipse.emf.edit.command.CommandParameter; //导入依赖的package包/类
/**
* Tests the remove command.
*/
@Test
public void removeCommand() {
final TestElement leafSection = Create.testElement();
final TestElement actor = Create.testElement();
leafSection.getContainedElements().add(actor);
new EMFStoreCommand() {
@Override
protected void doRun() {
getProject().addModelElement(leafSection);
}
}.run(false);
final EditingDomain editingDomain = ESWorkspaceProviderImpl.getInstance().getEditingDomain();
// remove
final Collection<TestElement> toRemove = new ArrayList<TestElement>();
toRemove.add(actor);
final Command copyCommand = editingDomain.createCommand(RemoveCommand.class, new CommandParameter(leafSection,
TestmodelPackage.Literals.TEST_ELEMENT__CONTAINED_ELEMENTS, toRemove));
if (copyCommand.canExecute()) {
editingDomain.getCommandStack().execute(copyCommand);
} else {
fail(COMMAND_NOT_EXECUTABLE);
}
assertEquals(0, leafSection.getContainedElements().size());
assertTrue(editingDomain.getCommandStack().canUndo());
// undo the command
editingDomain.getCommandStack().undo();
assertEquals(1, leafSection.getContainedElements().size());
assertTrue(editingDomain.getCommandStack().canRedo());
// redo the command
editingDomain.getCommandStack().redo();
assertEquals(0, leafSection.getContainedElements().size());
}
示例12: getNewChildDescriptor
import org.eclipse.emf.edit.command.CommandParameter; //导入依赖的package包/类
/**
* Returns the new child descriptor for creating a new child of the given feature for the given object.
*
* @param eObject the object a child should created for
* @param childFeature the feature of the children
* @return the {@link CommandParameter} (new child descriptor)
*/
public static CommandParameter getNewChildDescriptor(EObject eObject, EStructuralFeature childFeature) {
EditingDomain editingDomain = getEditingDomain(eObject);
ItemProviderAdapter itemProvider = getItemProvider(eObject);
for (Object object : itemProvider.getNewChildDescriptors(eObject, editingDomain, null)) {
CommandParameter childDescriptor = (CommandParameter) object;
if (childDescriptor.getFeature() == childFeature) {
return childDescriptor;
}
}
return null;
}
示例13: createCommand
import org.eclipse.emf.edit.command.CommandParameter; //导入依赖的package包/类
@Override
public Command createCommand ( final Object object, final EditingDomain domain, final Class<? extends Command> commandClass, final CommandParameter commandParameter )
{
// TODO Auto-generated method stub
return super.createCommand ( object, domain, commandClass, commandParameter );
}
示例14: selectionChanged
import org.eclipse.emf.edit.command.CommandParameter; //导入依赖的package包/类
/**
* This implements {@link org.eclipse.jface.viewers.ISelectionChangedListener},
* handling {@link org.eclipse.jface.viewers.SelectionChangedEvent}s by querying for the children and siblings
* that can be added to the selected object and updating the menus accordingly.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
public void selectionChanged(SelectionChangedEvent event) {
// Remove any menu items for old selection.
//
if (createChildMenuManager != null) {
depopulateManager(createChildMenuManager, createChildActions);
}
if (createSiblingMenuManager != null) {
depopulateManager(createSiblingMenuManager, createSiblingActions);
}
if (createPolicyMenuManager != null) {
depopulateManager(createPolicyMenuManager, createSiblingActions);
}
// Query the new selection for appropriate new child/sibling descriptors
//
Collection<?> newChildDescriptors = null;
Collection<?> newSiblingDescriptors = null;
ISelection selection = event.getSelection();
if (selection instanceof IStructuredSelection && ((IStructuredSelection)selection).size() == 1) {
Object object = ((IStructuredSelection)selection).getFirstElement();
EditingDomain domain = ((IEditingDomainProvider)activeEditorPart).getEditingDomain();
newChildDescriptors = domain.getNewChildDescriptors(object, null);
newSiblingDescriptors = domain.getNewChildDescriptors(null, object);
}
Collection<Object> newPolicyDescriptors = new LinkedList<Object>();
if (newChildDescriptors != null) {
for(Object p: newChildDescriptors) {
if (p instanceof CommandParameter && ((CommandParameter)p).value instanceof SchedulingPolicy) {
newPolicyDescriptors.add(p);
}
}
}
createPolicyActions = generateCreateChildActions(newPolicyDescriptors, selection);
// Generate actions for selection; populate and redraw the menus.
//
createChildActions = generateCreateChildActions(newChildDescriptors, selection);
createSiblingActions = generateCreateSiblingActions(newSiblingDescriptors, selection);
if (createChildMenuManager != null) {
populateManager(createChildMenuManager, createChildActions, null);
createChildMenuManager.update(true);
}
if (createSiblingMenuManager != null) {
populateManager(createSiblingMenuManager, createSiblingActions, null);
createSiblingMenuManager.update(true);
}
if (createPolicyMenuManager != null) {
populateManager(createPolicyMenuManager, createPolicyActions, null);
createPolicyMenuManager.update(true);
}
}
示例15: PlanElementDelegatingWrapperItemProvider
import org.eclipse.emf.edit.command.CommandParameter; //导入依赖的package包/类
public PlanElementDelegatingWrapperItemProvider(Object value, Object owner, AdapterFactory adapterFactory) {
super(value, owner, null, CommandParameter.NO_INDEX, adapterFactory);
}