Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 695550d8c44dadfd857e6b48e9e3db136789a4a1 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
 * Copyright (c) 2012 Mia-Software.
 *  
 * 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:
 *  	Alban Ménager (Soft-Maint) - Bug 387470 - [EFacet][Custom] Editors
 *  	Grégoire Dupé (Mia-Software) - Bug 387470 - [EFacet][Custom] Editors
 */
package org.eclipse.emf.facet.custom.sdk.ui.internal.util.widget.getorcreate;

import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.facet.custom.sdk.ui.internal.Activator;
import org.eclipse.emf.facet.efacet.core.IFacetSetCatalogManager;
import org.eclipse.emf.facet.efacet.core.IFacetSetCatalogManagerFactory;
import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.Facet;
import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetSet;
import org.eclipse.emf.facet.util.emf.ui.util.EditingUtil;
import org.eclipse.emf.facet.util.ui.internal.exported.dialog.IDialog;
import org.eclipse.emf.facet.util.ui.internal.exported.util.widget.command.AbstractGetOrCreateFilteredElementCommandWidget;
import org.eclipse.swt.widgets.Composite;

/**
 * This widget extends {@link AbstractGetOrCreateFilteredElementCommandWidget} and allow
 * the selection of a {@link Facet} that the Customization will customize. It
 * displays a selection window with a textfield to filter the element in the
 * selection window. Extending {@link AbstractGetOrCreateFilteredElementCommandWidget},
 * a [New...] button can be displayed. Here, no button is displayed because we
 * only select the extended facet into the existing facet.
 * <p/>
 * 
 * The selection window will be full up with the customization properties
 * returned by {@link IFacetSetCatalogManager}.
 */
public class GetFiltredCustomizedFacetWidget extends
		AbstractGetOrCreateFilteredElementCommandWidget<Facet, Object> {

	protected static final String TMP_NAME = Activator.getDefault()
			.getBundle().getSymbolicName()
			+ ".tmp"; //$NON-NLS-1$
	public static final File DEFAULT_FILE = new File(Platform
			.getStateLocation(Activator.getDefault().getBundle()).toOSString(),
			GetFiltredCustomizedFacetWidget.TMP_NAME);

	private final IFacetSetCatalogManager facetSetCatMan;

	/**
	 * Constructor.
	 * 
	 * @param parent
	 *            the parent of this composite.
	 * @param properties
	 *            the map of properties of the parent.
	 */
	public GetFiltredCustomizedFacetWidget(final Composite parent) {
		super(parent);
		this.facetSetCatMan = IFacetSetCatalogManagerFactory.DEFAULT
				.getOrCreateFacetSetCatalogManager(EditingUtil
						.createDefaultResource(
								GetFiltredCustomizedFacetWidget.DEFAULT_FILE)
						.getResourceSet());
	}

	@Override
	protected Map<String, Facet> getElements() {
		final Map<String, Facet> allFacets = new HashMap<String, Facet>();
		final Collection<FacetSet> facetSets = this.facetSetCatMan
				.getRegisteredFacetSets();
		for (final FacetSet facetSet : facetSets) {
			for (final EClassifier eClassifier : facetSet.getEClassifiers()) {
				if ((eClassifier instanceof Facet)
						&& (eClassifier.getName() != null)) {
					allFacets.put(eClassifier.getName(), (Facet) eClassifier);
				}
			}
		}
		return allFacets;
	}

	@Override
	public void notifyChanged() {
		// No action has to be done if a change appends.
	}

	@Override
	public Command getCommand() {
		// Here, this widget only return a selected element so, no command is
		// returned.
		return null;
	}

	@Override
	protected IDialog<Object> createDialog() {
		// No "New..." button.
		return null;
	}


	@Override
	public void onDialogValidation() {
		// Nothing.
	}

	/**
	 * @return
	 */
	public Facet getFacetSelected() {
		return getElementSelected();
	}

}

Back to the top