Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 00b2d52b41f0ae086399cd9bfa8833f2e034f5f1 (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
/**********************************************************************************
 * Copyright (c) 2011 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:
 *  	Gabriel Barbier (Mia-Software) - initial API and implementation
 * 		Nicolas Guyomar (Mia-Software) - Bug 333652 Extension point offering the possibility to declare an EPackage browser
 ***********************************************************************************/
package org.eclipse.papyrus.emf.facet.util.emf.ui.internal.dialogs;

import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import org.eclipse.emf.ecore.EPackage;
import org.eclipse.papyrus.emf.facet.util.emf.ui.internal.Activator;
import org.eclipse.papyrus.emf.facet.util.emf.ui.internal.Messages;
import org.eclipse.papyrus.emf.facet.util.emf.ui.internal.utils.ImageProvider;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.papyrus.emf.facet.common.ui.internal.widgets.AnywhereFilterMatcher;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.ElementListSelectionDialog;

/**
 * A dialog which displays a list of URIs from the EMF package registry, and
 * allows the user to open one of them.
 * 
 * @author Gabriel Barbier
 */
public class UriSelectionDialog extends ElementListSelectionDialog {

	private static final String DIALOG_SETTINGS = "UriSelectionDialogSettings"; //$NON-NLS-1$
	private String uri = ""; //$NON-NLS-1$

	/**
	 * Constructor.
	 * 
	 * @param parent
	 *            the parent shell
	 */
	public UriSelectionDialog(final Shell parent) {
		super(parent, new LabelProvider());

		setTitle(Messages.DialogUriSelection_title_OpenModelFromEMFRegistry);
		setMessage(Messages.DialogUriSelection_RegisteredEPackages);

		final Set<String> uris = new TreeSet<String>();
		for (final Object name : ((Map<?, ?>) EPackage.Registry.INSTANCE)
				.keySet()) {
			uris.add((name).toString());
		}

		setElements(uris.toArray());
	}

	@Override
	protected Control createDialogArea(final Composite parent) {
		Composite composite = (Composite) super.createDialogArea(parent);
		this.fFilteredList.setFilterMatcher(new AnywhereFilterMatcher());
		return composite;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.ui.dialogs.SelectionStatusDialog#okPressed()
	 */
	@Override
	protected void okPressed() {
		super.okPressed();

		if (getResult().length > 0) {
			this.uri = getResult()[0].toString();
		}
	}

	public String getUriSelected() {
		return this.uri;
	}

	@Override
	protected void configureShell(final Shell shell) {
		super.configureShell(shell);
		shell.setImage(ImageProvider.getInstance().getEmfFacetLogo());
	}

	@Override
	protected IDialogSettings getDialogBoundsSettings() {
		IDialogSettings settings = Activator.getPlugin().getDialogSettings();
		IDialogSettings section = settings
				.getSection(UriSelectionDialog.DIALOG_SETTINGS);
		if (section == null) {
			section = settings
					.addNewSection(UriSelectionDialog.DIALOG_SETTINGS);
		}
		return section;
	}
}

Back to the top