Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 70d514518f0de3226a44bc25cbd5563fa8998d75 (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
/*******************************************************************************
 * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) 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:
 *     Soyatec - initial API and implementation
 *******************************************************************************/
package org.eclipse.papyrus.xwt.core;

import java.util.HashMap;

import org.eclipse.core.databinding.observable.IChangeListener;
import org.eclipse.papyrus.xwt.XWT;
import org.eclipse.papyrus.xwt.internal.utils.LoggerManager;
import org.eclipse.papyrus.xwt.internal.utils.UserData;
import org.eclipse.swt.widgets.Widget;

public abstract class TriggerBase {

	public final static TriggerBase[] EMPTY_ARRAY = new TriggerBase[0];

	protected TriggerAction[] entryActions;

	protected TriggerAction[] exitActions;

	public TriggerAction[] getEntryActions() {
		if(entryActions == null) {
			return TriggerAction.EMPTY_ARRAY;
		}
		return entryActions;
	}

	public void setEntryActions(TriggerAction[] entryActions) {
		this.entryActions = entryActions;
	}

	public TriggerAction[] getExitActions() {
		if(exitActions == null) {
			return TriggerAction.EMPTY_ARRAY;
		}
		return exitActions;
	}

	public void setExitActions(TriggerAction[] exitActions) {
		this.exitActions = exitActions;
	}

	public abstract void on(Object target);

	public abstract void prepare(Object target);

	abstract class AbstractChangeListener implements IChangeListener {

		protected HashMap<SetterBase, Object> oldvalues = null;

		protected Object element;

		public AbstractChangeListener(Object element) {
			this.element = element;
		}

		protected void restoreValues() {
			if(oldvalues == null) {
				return;
			}
			for(SetterBase setter : oldvalues.keySet()) {
				setter.undo(element, oldvalues.get(setter));
			}
		}
	}

	public static Object getElementByName(Object target, String elementName) {
		if(elementName != null && elementName.length() > 0) {
			Widget widget = UserData.getWidget(target);
			if(widget != null) {
				Object element = XWT.findElementByName(widget, elementName);
				if(element != null) {
					return element;
				}
				LoggerManager.log("EventTrigger: Source \n" + elementName + "\n is not found in " + target.getClass().getName());
			}
		}
		return target;
	}

}

Back to the top