Skip to content

Package: AbstractFilteredReferenceAction

AbstractFilteredReferenceAction

nameinstructionbranchcomplexitylinemethod
AbstractFilteredReferenceAction(EditingDomain, EStructuralFeature.Setting, IItemPropertyDescriptor, Shell)
M: 117 C: 0
0%
M: 12 C: 0
0%
M: 7 C: 0
0%
M: 27 C: 0
0%
M: 1 C: 0
0%
getShell()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2013 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: * Eugen Neufeld - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.spi.editor.controls;
15:
16: import java.net.URL;
17:
18: import org.eclipse.emf.ecore.EReference;
19: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
20: import org.eclipse.emf.ecp.edit.internal.swt.Activator;
21: import org.eclipse.emf.ecp.edit.internal.swt.util.OverlayImageDescriptor;
22: import org.eclipse.emf.ecp.edit.spi.swt.actions.ECPSWTAction;
23: import org.eclipse.emf.edit.domain.EditingDomain;
24: import org.eclipse.emf.edit.provider.ComposedImage;
25: import org.eclipse.emf.edit.provider.IItemLabelProvider;
26: import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
27: import org.eclipse.jface.resource.ImageDescriptor;
28: import org.eclipse.swt.graphics.Image;
29: import org.eclipse.swt.widgets.Shell;
30:
31: /**
32: * A {@link ECPSWTAction} allowing to set a reference.
33: *
34: * @since 1.5
35: *
36: */
37: public abstract class AbstractFilteredReferenceAction extends ECPSWTAction {
38:         private final Shell shell;
39:
40:         /**
41:          * Returns the used {@link Shell}.
42:          *
43:          * @return the shell
44:          */
45:         protected Shell getShell() {
46:                 return shell;
47:         }
48:
49:         /**
50:          * Constructor.
51:          *
52:          * @param editingDomain the editing domain to use
53:          * @param setting the setting to use
54:          * @param descriptor the property descriptor
55:          * @param shell the shell
56:          */
57:         public AbstractFilteredReferenceAction(EditingDomain editingDomain, Setting setting,
58:                 IItemPropertyDescriptor descriptor, Shell shell) {
59:                 super(editingDomain, setting);
60:                 this.shell = shell;
61:
62:                 final EReference eReference = (EReference) setting.getEStructuralFeature();
63:                 Object obj = null;
64:•                if (!eReference.getEReferenceType().isAbstract()) {
65:                         obj = eReference.getEReferenceType().getEPackage().getEFactoryInstance()
66:                                 .create(eReference.getEReferenceType());
67:                 }
68:                 final IItemLabelProvider labelProvider = descriptor.getLabelProvider(obj);
69:                 Object labelProviderImageResult = labelProvider.getImage(obj);
70:•                if (ComposedImage.class.isInstance(labelProviderImageResult)) {
71:                         labelProviderImageResult = ((ComposedImage) labelProviderImageResult).getImages()
72:                                 .get(0);
73:                 }
74:
75:•                final Image image = Activator.getImage(obj == null ? null : (URL) labelProviderImageResult);
76:                 String overlayString = "icons/link_overlay.png"; //$NON-NLS-1$
77:•                if (eReference.isContainment()) {
78:                         overlayString = "icons/containment_overlay.png"; //$NON-NLS-1$
79:                 }
80:                 final ImageDescriptor addOverlay = Activator.getImageDescriptor(overlayString);
81:                 final OverlayImageDescriptor imageDescriptor = new OverlayImageDescriptor(image, addOverlay,
82:                         OverlayImageDescriptor.LOWER_RIGHT);
83:                 setImageDescriptor(imageDescriptor);
84:
85:                 String attribute = descriptor.getDisplayName(eReference);
86:                 // make singular attribute labels
87:•                if (attribute.endsWith("ies")) { //$NON-NLS-1$
88:                         attribute = attribute.substring(0, attribute.length() - 3) + "y"; //$NON-NLS-1$
89:•                } else if (attribute.endsWith("s")) { //$NON-NLS-1$
90:                         attribute = attribute.substring(0, attribute.length() - 1);
91:                 }
92:
93:                 setToolTipText("Link " + attribute); //$NON-NLS-1$
94:
95:         }
96: }