Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6169e1e61c6a4a310ecef2066ddb95f45474a59f (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:
 *    Gregoire Dupe (Mia-Software) - Bug 386387 - [CustomizedTreeContentProvider] The TreeElements are not preserved between two calls to getElements()
 *******************************************************************************/
package org.eclipse.papyrus.emf.facet.custom.ui.internal;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.papyrus.emf.facet.custom.ui.internal.exception.CustomizedContentProviderRuntimeException;
import org.eclipse.papyrus.emf.facet.util.core.DebugUtils;
import org.eclipse.osgi.util.NLS;
import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.internal.treeproxy.EAttributeTreeElement;
import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.internal.treeproxy.EObjectTreeElement;
import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.internal.treeproxy.EReferenceTreeElement;
import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.internal.treeproxy.EStructuralFeatureTreeElement;

public class TreeElementAdapter implements Adapter {

	private static final boolean DEBUG = DebugUtils.getDebugStatus(Activator
		.getDefault());

	private final EObjectTreeElement treeElement;

	public TreeElementAdapter(final EObjectTreeElement treeElement) {
		this.treeElement = treeElement;
	}

	public void notifyChanged(final Notification notification) {
		DebugUtils.debug(DEBUG,
			"Modified element=" + this.treeElement.getEObject()); //$NON-NLS-1$
		DebugUtils.debug(DEBUG,
			"Notification feature=" + notification.getFeature()); //$NON-NLS-1$
		for (Object subElement : this.treeElement
			.getSfTreeElmement()) {
			if( subElement instanceof EStructuralFeatureTreeElement){
				final EStructuralFeature feature = getSF((EStructuralFeatureTreeElement)subElement);
			if (feature.equals(notification.getFeature())) {
				((EStructuralFeatureTreeElement)subElement).getReferedEObjectTE().clear();
				DebugUtils.debug(
					DEBUG,
					NLS.bind(
						"Cleanning= {0}::{1}", //$NON-NLS-1$
						feature.getContainerClass().getName(),
						feature.getName()));
			}
		}
	}
}

private static EStructuralFeature getSF(
	final EStructuralFeatureTreeElement structFeatuteTE) {
	EStructuralFeature result;
	if (structFeatuteTE instanceof EAttributeTreeElement) {
		final EAttributeTreeElement eAttributeTE = (EAttributeTreeElement) structFeatuteTE;
		result = eAttributeTE.getEAttribute();
	} else if (structFeatuteTE instanceof EReferenceTreeElement) {
		final EReferenceTreeElement eReferenceTE = (EReferenceTreeElement) structFeatuteTE;
		result = eReferenceTE.getEReference();
	} else {
		throw new CustomizedContentProviderRuntimeException(
			"Illegal agrument: " + structFeatuteTE); //$NON-NLS-1$
	}
	return result;
}

public Notifier getTarget() {
	return null;
}

public void setTarget(final Notifier newTarget) {
	// Nothing to do
}

public boolean isAdapterForType(final Object type) {
	return false;
}

}

Back to the top