Skip to content

Package: CreateNewModelElementStrategy$Provider

CreateNewModelElementStrategy$Provider

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2018 EclipseSource Muenchen GmbH 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 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * lucas - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.ui.view.swt.reference;
15:
16: import org.eclipse.emf.ecore.EClass;
17: import org.eclipse.emf.ecore.EObject;
18: import org.eclipse.emf.ecore.EReference;
19: import org.eclipse.emf.ecore.util.EcoreUtil;
20: import org.eclipse.emfforms.bazaar.Vendor;
21: import org.eclipse.emfforms.common.Optional;
22:
23: /**
24: * A {@link org.eclipse.emf.ecp.ui.view.swt.DefaultReferenceService DefaultReferenceService}
25: * <em>customization strategy</em> to add one or more new elements to a reference of an owner.
26: *
27: * @author Lucas Koehler
28: * @see org.eclipse.emf.ecp.ui.view.swt.DefaultReferenceService DefaultReferenceService
29: * @since 1.17
30: */
31: public interface CreateNewModelElementStrategy {
32:
33:         /**
34:          * Default strategy that creates a new model element based on the sub classes of the reference type. If
35:          * there is more than one, a selection dialog is shown.
36:          */
37:         CreateNewModelElementStrategy DEFAULT = new CreateNewModelElementStrategy() {
38:
39:                 @Override
40:                 public Optional<EObject> createNewModelElement(EObject owner, EReference reference) {
41:                         final EClass referenceType = reference.getEReferenceType();
42:                         if (referenceType.isAbstract()) {
43:                                 return Optional.empty();
44:                         }
45:                         return Optional.of(EcoreUtil.create(referenceType));
46:                 }
47:         };
48:
49:         /**
50:          * Create a new model element in the reference of the given owner.
51:          *
52:          * @param owner The {@link EObject} that contains the reference
53:          * @param reference The reference for which a new model element should be created
54:          * @return The created model element or <code>null</code> if none was created
55:          */
56:         Optional<EObject> createNewModelElement(EObject owner, EReference reference);
57:
58:         /**
59:          * Specific Bazaar vendor interface for add new model elements strategies.
60:          *
61:          * @since 1.16
62:          */
63:         public interface Provider extends Vendor<CreateNewModelElementStrategy> {
64:                 // Nothing to add to the super interface
65:         }
66:
67: }