Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: fe0f9715813fa742d74e4384d0e9ab5eb632e27b (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
/*****************************************************************************
 * Copyright (c) 2015 CEA LIST and others.
 * 
 * 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:
 *   CEA LIST - Initial API and implementation
 *   Jérémie Tatibouet (CEA LIST)
 *   
 *****************************************************************************/

package org.eclipse.papyrus.uml.alf.properties.xtext.sheet.ui.listeners;

import org.eclipse.papyrus.uml.alf.transaction.commit.ScenarioFactory;
import org.eclipse.papyrus.uml.alf.properties.xtext.sheet.AdvancedEditingPropertySection;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.uml2.uml.NamedElement;

public class EditorFocusListener extends FocusAdapter {


	private AdvancedEditingPropertySection section;

	public EditorFocusListener(AdvancedEditingPropertySection section) {
		this.section = section;
	}

	/**
	 * When the ALF editor looses the focus, this triggers the execution of a backup sequence.
	 * This backup sequence saves the current state of the textual definition of the current model element.
	 * Modifications introduced in text are not propagated in the current model element.
	 */
	@Override
	public void focusLost(FocusEvent event) {
		/* 1. Retrieve the alf editor */
		StyledText alfEditor = null;
		if (event.getSource() instanceof StyledText) {
			alfEditor = (StyledText) event.getSource();
		}
		/* 2. Save the textual representation */
		if (alfEditor != null) {
			ScenarioFactory.getInstance().createSaveScenario().
					execute((NamedElement) this.section.getContextObject(), alfEditor.getText());
		}

	}
}

Back to the top