Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 85d0621e51503211310c952b33abb095d0e41e40 (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
/**
 * 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.papyrus.emf.facet.util.ui.internal.exported.util.widget.command;

import org.eclipse.core.commands.Command;
import org.eclipse.papyrus.emf.facet.util.ui.internal.exported.util.dialog.AbstractDialog;
import org.eclipse.papyrus.emf.facet.util.ui.internal.exported.util.dialog.AbstractMainDialog;
import org.eclipse.papyrus.emf.facet.util.ui.internal.exported.util.widget.AbstractWidget;
import org.eclipse.papyrus.emf.facet.util.ui.internal.exported.widget.IAbstractWidget;
import org.eclipse.papyrus.emf.facet.util.ui.utils.WidgetProperties;
import org.eclipse.swt.widgets.Composite;

/**
 * This abstract class provides all the necessary methods for the creation of a
 * widget. The widget must return a {@link Command} (with the method
 * {@link #getCommand()}) that will be executed when the "ok" button of the
 * dialog will be pressed.</p>
 * 
 * The widget have to get all the necessary properties for the creation of the
 * element (with the command). To get all the properties, the widget have to add
 * all the subwidgets he needs for the edition of the command. Each subwidget
 * {@link AbstractWidget} will edit a specific property of the
 * {@link WidgetProperties}.
 * 
 * @since 0.3
 */
public abstract class AbstractCommandWidget extends AbstractWidget implements ICommandWidget {

	/**
	 * Constructor. Initialize the {@link IFacetCommandFactory} for the creation
	 * of the command.
	 * 
	 * @param parent
	 *            the parent {@link AbstractDialog} of this widget.
	 * @param editingDomain
	 *            the current editing domain.
	 * @param properties
	 *            The {@link WidgetProperties} provided by the
	 *            {@link AbstractMainDialog} that the widget had to edit.
	 */
	public AbstractCommandWidget(final Composite parent) {
		super(parent);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.papyrus.emf.facet.util.ui.internal.exported.util.widget.command.ICommandWidget#getCommand()
	 */
	public abstract Object getCommand();

	@Override
	public String getError() {
		String result = null;
		for (final IAbstractWidget widgets : this.getSubWidgets()) {
			final String error = widgets.getError();
			if (error != null) {
				result = error;
				break;
			}
		}
		return result;
	}


	public abstract void onDialogValidation();
	
	public <A> A adapt(final Class<A> adapterType) {
		A result = null;
		if (adapterType.isInstance(this)) {
			@SuppressWarnings("unchecked")
			final A adapted = (A) this;
			result = adapted;
		}
		return result;
	}

}

Back to the top