Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4071b5c5e63c3e1df01803a8f51dc2ff5869dc8b (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
/**
 * 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 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *  	Alban Ménager (Soft-Maint) - Bug 387470 - [EFacet][Custom] Editors
 *  	Grégoire Dupé (Mia-Software) - Bug 387470 - [EFacet][Custom] Editors
 */
package org.eclipse.papyrus.emf.facet.util.ui.internal.exported.util.widget.component.getorcreate;

import org.eclipse.jface.window.Window;
import org.eclipse.papyrus.emf.facet.util.ui.internal.exported.wizard.IExtendedWizard;
import org.eclipse.papyrus.emf.facet.util.ui.utils.PropertyElement2;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;

/**
 * Has the same goal than {@link AbstractGetOrCreateElementWithButtonWidget} but
 * especially for dialogs.
 *
 * @since 0.3
 */
public abstract class AbstractGetOrCreateElementWithWizardButtonWidget<T extends Object, W extends IExtendedWizard>
		extends AbstractGetOrCreateElementWithButtonWidget<T, W> {

	protected AbstractGetOrCreateElementWithWizardButtonWidget(
			final Composite parent,
			final PropertyElement2<T> propertyElement) {
		super(parent, propertyElement);
	}

	@Override
	public W onButtonPressed() {
		final W wizard = createIWizard();
		Display.getDefault().asyncExec(new Runnable() {
			public void run() {
				final int openResult = wizard.open();
				// TODO The wizard closing events must be cached by the use of
				// call back pattern. The use of this pattern must be done in
				// the subclass of this class, like in
				// org.eclipse.papyrus.emf.facet.util.ui.internal.exported.util.widget.component.getorcreate.AbstractGetOrCreateElementWithWizardButtonWidget<ETypedElement>
				// The following if statement and the methods 'onWizardCommited'
				// 'onWizardCanceled' must be removed (replaced by the use of
				// call backs)
				if (openResult == Window.OK) {
					onWizardCommited(wizard);
				} else {
					onWizardCanceled();
				}
			}
		});
		return createSynchronizedWizard(wizard);
	}

	/**
	 * Create the wizard for the selection of the type.
	 *
	 * @return the wizard.
	 */
	protected abstract W createIWizard();

	/**
	 * Action to do when the dialog opened with the button "..." is closed with
	 * the "Ok" button.
	 *
	 * @param selectETypeDialog
	 */
	protected abstract void onWizardCommited(W wizard);

	/**
	 * Action to do when the dialog opened with the button "..." is closed with
	 * the "Cancel" button.
	 */
	protected abstract void onWizardCanceled();

	protected abstract W createSynchronizedWizard(final W wizard);

}

Back to the top