@Override protected EObject doRun(CDOTransaction transaction, CDOObject parent, ISelection selection) { ComposedAdapterFactory adapterFactory = CDOEditor.createAdapterFactory(true); try { BasicCommandStack commandStack = new BasicCommandStack(); ResourceSet resourceSet = transaction.getResourceSet(); EditingDomain editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack, resourceSet); CreateChildAction delegate = new CreateChildAction(editingDomain, selection, childDescriptor); delegate.run(); if (childDescriptor instanceof CommandParameter) { CommandParameter parameter = (CommandParameter) childDescriptor; Object value = parameter.getValue(); if (value instanceof EObject) { return (EObject) value; } } return null; } finally { adapterFactory.dispose(); } }
protected void fillMenu(final MenuManager menuManager) { final EditingDomain editingDomain = getEditingDomain(); final EObject base = (EObject) getBaseObservable().getValue(); if (base == null) { return; } final Collection<?> descriptors = editingDomain.getNewChildDescriptors(base, null); for (final Object descriptor : descriptors) { if (!(descriptor instanceof CommandParameter)) { continue; } final CommandParameter parameter = (CommandParameter) descriptor; if (parameter.getEStructuralFeature() != getEFeature()) { continue; } final IContributionItem item = new EditCommandContributionItem(parameter, editingDomain, getBaseObservable()) { @Override protected void executed(final Collection<?> result) { final Iterator<?> iter = result.iterator(); if (iter.hasNext()) { final Object value = iter.next(); if (fModelObservable.contains(value)) { fSingleSelectionObservable.setValue(value); } } } }; menuManager.add(item); } }
/** {@inheritDoc} */ @Override protected boolean isMine(final CommandParameter object) { if (object.getEReference() != null && (valids.size() + restricted.size() > 0)) { final EObject value = (EObject) object.getValue(); return isMyTargetType(value); } return true; }
/** * @param manager The menu manager responsible for the context menu * @param descriptors The menu items to be added * @param domain The editing domain of the current EObject * @param eObject The model element */ private void fillContextMenu( IMenuManager manager, Collection<?> descriptors, final EditingDomain domain, final EObject eObject) { for (final Object descriptor : descriptors) { final CommandParameter cp = (CommandParameter) descriptor; if (!CommandParameter.class.isInstance(descriptor)) { continue; } if (cp.getEReference() == null) { continue; } if (!cp.getEReference().isMany() && eObject.eIsSet(cp.getEStructuralFeature())) { continue; } else if (cp.getEReference().isMany() && cp.getEReference().getUpperBound() != -1 && cp.getEReference().getUpperBound() <= ((List<?>) eObject.eGet(cp.getEReference())).size()) { continue; } manager.add( new CreateChildAction(domain, new StructuredSelection(eObject), descriptor) { @Override public void run() { super.run(); final EReference reference = ((CommandParameter) descriptor).getEReference(); // if (!reference.isContainment()) { // domain.getCommandStack().execute( // AddCommand.create(domain, eObject.eContainer(), null, cp.getEValue())); // } domain .getCommandStack() .execute(AddCommand.create(domain, eObject, reference, cp.getEValue())); } }); } }