Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a8acadb9ad71c65377ae73db3034197b80077b25 (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
/*****************************************************************************
 * Copyright (c) 2010 CEA LIST.
 *    
 * 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:
 *  Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
 *****************************************************************************/
package org.eclipse.papyrus.properties.runtime.propertyeditor;

import org.eclipse.gmf.runtime.common.core.service.IOperation;
import org.eclipse.gmf.runtime.common.core.service.IProvider;
import org.eclipse.papyrus.properties.runtime.Activator;
import org.eclipse.papyrus.properties.runtime.controller.PropertyEditorController;
import org.eclipse.swt.widgets.Composite;


/**
 * Operation that creates an {@link AbstractPropertyEditor} from a provider
 */
public class CreatePropertyEditorOperation implements IOperation {

	/** parent composite for the created widgets */
	protected Composite parent;

	/** identifier of the specific editor to find */
	protected final String editorIdentifier;

	/** indicates if the property to edit is multi-valued */
	protected final boolean multiValue;

	/** controller which requires the property editor creation */
	protected PropertyEditorController controller;

	/**
	 * Constructor.
	 * 
	 * @param controller
	 *        the controller that manages the created editor
	 * @param id
	 *        the identifier of the editor to find
	 */
	public CreatePropertyEditorOperation(PropertyEditorController controller, String id) {
		this.controller = controller;
		this.editorIdentifier = id;
		this.multiValue = false;
	}

	/**
	 * {@inheritDoc}
	 */
	public AbstractPropertyEditor execute(IProvider provider) {
		if(provider instanceof PropertyEditorProvider) {
			AbstractPropertyEditor editor = ((PropertyEditorProvider)provider).createPropertyEditor(editorIdentifier, controller);
			return editor;
		} else {
			Activator.log.error("CreatePropertyEditorOperation should execute on a PropertyEditorProvider", null);
		}
		return null;
	}

	/**
	 * Returns the identifier of the specific editor to find
	 * 
	 * @return the identifier of the specific editor to find. It can be <code>null</code>. In this case, feature should not be <code>null</code>
	 */
	public String getEditorIdentifier() {
		return editorIdentifier;
	}

	/**
	 * Returns <code>true</code> if the property to edit is multi-valued
	 * 
	 * @return <code>true</code> if the property to edit is multi-valued
	 */
	public boolean isMultiValue() {
		return multiValue;
	}

}

Back to the top