Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 395957
Collapse All | Expand All

(-)src/org/eclipse/emf/ecp/emfstore/internal/ui/decorator/EMFStoreDirtyDecorator.java (-5 / +21 lines)
Lines 27-38 Link Here
27
import org.eclipse.jface.viewers.ILabelProviderListener;
27
import org.eclipse.jface.viewers.ILabelProviderListener;
28
import org.eclipse.jface.viewers.ILightweightLabelDecorator;
28
import org.eclipse.jface.viewers.ILightweightLabelDecorator;
29
29
30
import java.util.HashSet;
31
import java.util.Set;
32
30
/**
33
/**
31
 * @author Eugen Neufeld
34
 * @author Eugen Neufeld
32
 */
35
 */
33
public class EMFStoreDirtyDecorator implements ILightweightLabelDecorator, CommitObserver {
36
public class EMFStoreDirtyDecorator implements ILightweightLabelDecorator, CommitObserver {
34
37
35
	private String dirtyPath = "icons/dirty.png";
38
	private String dirtyPath = "icons/dirty.png";
39
	private Set<InternalProject> observers = new HashSet<InternalProject>();
36
40
37
	/** {@inheritDoc} */
41
	/** {@inheritDoc} */
38
	public void decorate(Object element, IDecoration decoration) {
42
	public void decorate(Object element, IDecoration decoration) {
Lines 40-57 Link Here
40
		if (element instanceof ECPProject) {
44
		if (element instanceof ECPProject) {
41
			InternalProject project = (InternalProject) element;
45
			InternalProject project = (InternalProject) element;
42
			ProjectSpace projectSpace = EMFStoreProvider.INSTANCE.getProjectSpace(project);
46
			ProjectSpace projectSpace = EMFStoreProvider.INSTANCE.getProjectSpace(project);
43
			projectSpace.getOperationManager().addOperationListener(new EMFStoreDirtyObserver(projectSpace, project));
44
47
48
			if (!observers.contains(element)) {
49
				projectSpace.getOperationManager().addOperationListener(
50
					new EMFStoreDirtyObserver(projectSpace, project));
51
				observers.add(project);
52
			}
45
			if (project.isOpen() && EMFStoreProvider.INSTANCE.getProjectSpace(project).isShared()
53
			if (project.isOpen() && EMFStoreProvider.INSTANCE.getProjectSpace(project).isShared()
46
				&& EMFStoreDirtyDecoratorCachedTree.getInstance(project).getRootValue() > 0) {
54
				&& EMFStoreDirtyDecoratorCachedTree.getInstance(project).getRootValue().shouldDisplayDirtyIndicator()) {
47
				decoration.addOverlay(Activator.getImageDescriptor(dirtyPath), IDecoration.BOTTOM_LEFT);
55
				decoration.addOverlay(Activator.getImageDescriptor(dirtyPath), IDecoration.BOTTOM_LEFT);
48
			}
56
			}
49
		}
57
		}
50
58
51
		if (element instanceof EObject) {
59
		if (element instanceof EObject) {
52
			InternalProject project = ECPUtil.getECPProject(element, InternalProject.class);
60
			InternalProject project = null;
53
			if (project != null && project.isOpen() && EMFStoreProvider.INSTANCE.getProjectSpace(project).isShared()
61
			try {
54
				&& EMFStoreDirtyDecoratorCachedTree.getInstance(project).getCachedValue(element) > 0) {
62
				project = ECPUtil.getECPProject(element, InternalProject.class);
63
			} catch (IllegalArgumentException iae) {
64
				// ignore
65
			}
66
			if (project != null
67
				&& project.isOpen()
68
				&& EMFStoreProvider.INSTANCE.getProjectSpace(project).isShared()
69
				&& EMFStoreDirtyDecoratorCachedTree.getInstance(project).getCachedValue(element)
70
					.shouldDisplayDirtyIndicator()) {
55
				decoration.addOverlay(Activator.getImageDescriptor(dirtyPath), IDecoration.BOTTOM_LEFT);
71
				decoration.addOverlay(Activator.getImageDescriptor(dirtyPath), IDecoration.BOTTOM_LEFT);
56
			}
72
			}
57
73
(-)src/org/eclipse/emf/ecp/emfstore/internal/ui/decorator/EMFStoreDirtyDecoratorCachedTree.java (-13 / +16 lines)
Lines 27-33 Link Here
27
 * @author emueller
27
 * @author emueller
28
 * 
28
 * 
29
 */
29
 */
30
public final class EMFStoreDirtyDecoratorCachedTree extends AbstractCachedTree<Integer> {
30
public final class EMFStoreDirtyDecoratorCachedTree extends AbstractCachedTree<EMFStoreDirtyTreeNode> {
31
31
32
	private static Map<ECPProject, EMFStoreDirtyDecoratorCachedTree> cashedTrees = new HashMap<ECPProject, EMFStoreDirtyDecoratorCachedTree>();
32
	private static Map<ECPProject, EMFStoreDirtyDecoratorCachedTree> cashedTrees = new HashMap<ECPProject, EMFStoreDirtyDecoratorCachedTree>();
33
33
Lines 58-64 Link Here
58
	/**
58
	/**
59
	 * Cached tree node that stores the dirty state of a model element managed by EMFStore.
59
	 * Cached tree node that stores the dirty state of a model element managed by EMFStore.
60
	 */
60
	 */
61
	public class CachedDirtyStateTreeNode extends CachedTreeNode<Integer> {
61
	public class CachedDirtyStateTreeNode extends CachedTreeNode<EMFStoreDirtyTreeNode> {
62
62
63
		/**
63
		/**
64
		 * Constructor.
64
		 * Constructor.
Lines 66-72 Link Here
66
		 * @param value
66
		 * @param value
67
		 *            the initial value for this entry
67
		 *            the initial value for this entry
68
		 */
68
		 */
69
		public CachedDirtyStateTreeNode(Integer value) {
69
		public CachedDirtyStateTreeNode(EMFStoreDirtyTreeNode value) {
70
			super(value);
70
			super(value);
71
		}
71
		}
72
72
Lines 75-88 Link Here
75
		 */
75
		 */
76
		@Override
76
		@Override
77
		public void update() {
77
		public void update() {
78
			for (Integer isDirty : values()) {
78
			for (EMFStoreDirtyTreeNode node : values()) {
79
				if (isDirty > 0) {
79
				if (node.getChangeCount() > 0 || node.isChildChanges()) {
80
					setValue(isDirty);
80
					getValue().setChildChanges(true);
81
					return;
81
					return;
82
				}
82
				}
83
			}
83
			}
84
84
			getValue().setChildChanges(false);
85
			setValue(0);
86
		}
85
		}
87
	}
86
	}
88
87
Lines 90-112 Link Here
90
	 * {@inheritDoc}
89
	 * {@inheritDoc}
91
	 */
90
	 */
92
	@Override
91
	@Override
93
	public Integer getDefaultValue() {
92
	public EMFStoreDirtyTreeNode getDefaultValue() {
94
		return 0;
93
		return new EMFStoreDirtyTreeNode(0, false);
95
	}
94
	}
96
95
97
	/**
96
	/**
98
	 * {@inheritDoc}
97
	 * {@inheritDoc}
99
	 */
98
	 */
100
	@Override
99
	@Override
101
	public CachedTreeNode<Integer> createdCachedTreeNode(Integer t) {
100
	public CachedTreeNode<EMFStoreDirtyTreeNode> createdCachedTreeNode(EMFStoreDirtyTreeNode t) {
102
		return new CachedDirtyStateTreeNode(t);
101
		return new CachedDirtyStateTreeNode(t);
103
	}
102
	}
104
103
105
	public void addOperation(EObject eObject) {
104
	public void addOperation(EObject eObject) {
106
		update(eObject, getCachedValue(eObject) + 1);
105
		EMFStoreDirtyTreeNode node = getCachedValue(eObject);
106
		node.setChangeCount(node.getChangeCount() + 1);
107
		update(eObject, node);
107
	}
108
	}
108
109
109
	public void removeOperation(EObject eObject) {
110
	public void removeOperation(EObject eObject) {
110
		update(eObject, getCachedValue(eObject) - 1);
111
		EMFStoreDirtyTreeNode node = getCachedValue(eObject);
112
		node.setChangeCount(node.getChangeCount() - 1);
113
		update(eObject, node);
111
	}
114
	}
112
}
115
}
(-)src/org/eclipse/emf/ecp/emfstore/internal/ui/decorator/EMFStoreDirtyObserver.java (-2 / +28 lines)
Lines 36-41 Link Here
36
	public EMFStoreDirtyObserver(ProjectSpace projectSpace, InternalProject project) {
36
	public EMFStoreDirtyObserver(ProjectSpace projectSpace, InternalProject project) {
37
		this.projectSpace = projectSpace;
37
		this.projectSpace = projectSpace;
38
		internalProject = project;
38
		internalProject = project;
39
40
		if (!projectSpace.isShared()) {
41
			return;
42
		}
43
		for (AbstractOperation operation : projectSpace.getOperations()) {
44
			for (ModelElementId modelElementId : operation.getAllInvolvedModelElements()) {
45
				EObject element = projectSpace.getProject().getModelElement(modelElementId);
46
				EMFStoreDirtyDecoratorCachedTree.getInstance(internalProject).addOperation(element);
47
			}
48
		}
49
39
	}
50
	}
40
51
41
	/*
52
	/*
Lines 45-55 Link Here
45
	 * server.model.versioning.operations.AbstractOperation)
56
	 * server.model.versioning.operations.AbstractOperation)
46
	 */
57
	 */
47
	public void operationExecuted(AbstractOperation operation) {
58
	public void operationExecuted(AbstractOperation operation) {
59
60
		if (!projectSpace.isShared()) {
61
			return;
62
		}
63
48
		for (ModelElementId modelElementId : operation.getAllInvolvedModelElements()) {
64
		for (ModelElementId modelElementId : operation.getAllInvolvedModelElements()) {
49
			Project project = projectSpace.getProject();
65
			Project project = projectSpace.getProject();
66
50
			EObject element = project.getModelElement(modelElementId);
67
			EObject element = project.getModelElement(modelElementId);
51
68
52
			EMFStoreDirtyDecoratorCachedTree.getInstance(internalProject).addOperation(element);
69
			if (element != null) {
70
				EMFStoreDirtyDecoratorCachedTree.getInstance(internalProject).addOperation(element);
71
			}
53
		}
72
		}
54
73
55
	}
74
	}
Lines 61-71 Link Here
61
	 * .model.versioning.operations.AbstractOperation)
80
	 * .model.versioning.operations.AbstractOperation)
62
	 */
81
	 */
63
	public void operationUnDone(AbstractOperation operation) {
82
	public void operationUnDone(AbstractOperation operation) {
83
84
		if (!projectSpace.isShared()) {
85
			return;
86
		}
87
64
		for (ModelElementId modelElementId : operation.getAllInvolvedModelElements()) {
88
		for (ModelElementId modelElementId : operation.getAllInvolvedModelElements()) {
65
			Project project = projectSpace.getProject();
89
			Project project = projectSpace.getProject();
66
			EObject element = project.getModelElement(modelElementId);
90
			EObject element = project.getModelElement(modelElementId);
67
91
68
			EMFStoreDirtyDecoratorCachedTree.getInstance(internalProject).removeOperation(element);
92
			if (element != null) {
93
				EMFStoreDirtyDecoratorCachedTree.getInstance(internalProject).removeOperation(element);
94
			}
69
		}
95
		}
70
96
71
	}
97
	}
(-)src/org/eclipse/emf/ecp/emfstore/internal/ui/decorator/EMFStoreDirtyTreeNode.java (+35 lines)
Added Link Here
1
package org.eclipse.emf.ecp.emfstore.internal.ui.decorator;
2
3
/**
4
 * @author Tobias Verhoeven
5
 */
6
public class EMFStoreDirtyTreeNode {
7
8
	private int changeCount;
9
	private boolean childChanges;
10
11
	public EMFStoreDirtyTreeNode(int changeCount, boolean childChanges) {
12
		this.changeCount = changeCount;
13
		this.childChanges = childChanges;
14
	}
15
16
	public boolean shouldDisplayDirtyIndicator() {
17
		return childChanges || changeCount > 0;
18
	}
19
20
	public int getChangeCount() {
21
		return changeCount;
22
	}
23
24
	public void setChangeCount(int changeCount) {
25
		this.changeCount = changeCount;
26
	}
27
28
	public boolean isChildChanges() {
29
		return childChanges;
30
	}
31
32
	public void setChildChanges(boolean childChanges) {
33
		this.childChanges = childChanges;
34
	}
35
}

Return to bug 395957