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 395917
Collapse All | Expand All

(-)src/org/eclipse/emf/ecp/emfstore/internal/ui/Activator.java (-5 lines)
Lines 1-6 Link Here
1
package org.eclipse.emf.ecp.emfstore.internal.ui;
1
package org.eclipse.emf.ecp.emfstore.internal.ui;
2
2
3
import org.eclipse.emf.ecp.core.util.observer.ECPObserverBus;
4
import org.eclipse.emf.ecp.emfstore.internal.ui.decorator.EMFStoreDirtyObserver;
3
import org.eclipse.emf.ecp.emfstore.internal.ui.decorator.EMFStoreDirtyObserver;
5
4
6
import org.eclipse.core.runtime.CoreException;
5
import org.eclipse.core.runtime.CoreException;
Lines 26-39 Link Here
26
	public void start(BundleContext context) throws Exception {
25
	public void start(BundleContext context) throws Exception {
27
		super.start(context);
26
		super.start(context);
28
		instance = this;
27
		instance = this;
29
30
		dirtyObserver = new EMFStoreDirtyObserver();
31
		ECPObserverBus.getInstance().register(dirtyObserver);
32
	}
28
	}
33
29
34
	@Override
30
	@Override
35
	public void stop(BundleContext context) throws Exception {
31
	public void stop(BundleContext context) throws Exception {
36
		ECPObserverBus.getInstance().unregister(dirtyObserver);
37
		instance = null;
32
		instance = null;
38
		super.stop(context);
33
		super.stop(context);
39
	}
34
	}
(-)src/org/eclipse/emf/ecp/emfstore/internal/ui/decorator/EMFStoreDirtyDecorator.java (-8 / +12 lines)
Lines 37-59 Link Here
37
	/** {@inheritDoc} */
37
	/** {@inheritDoc} */
38
	public void decorate(Object element, IDecoration decoration) {
38
	public void decorate(Object element, IDecoration decoration) {
39
39
40
		if (element instanceof ECPProject) {
41
			InternalProject project = (InternalProject) element;
42
			ProjectSpace projectSpace = EMFStoreProvider.INSTANCE.getProjectSpace(project);
43
			projectSpace.getOperationManager().addOperationListener(new EMFStoreDirtyObserver(projectSpace, project));
44
45
			if (project.isOpen() && EMFStoreProvider.INSTANCE.getProjectSpace(project).isShared()
46
				&& EMFStoreDirtyDecoratorCachedTree.getInstance(project).getRootValue() > 0) {
47
				decoration.addOverlay(Activator.getImageDescriptor(dirtyPath), IDecoration.BOTTOM_LEFT);
48
			}
49
		}
50
40
		if (element instanceof EObject) {
51
		if (element instanceof EObject) {
41
			InternalProject project = ECPUtil.getECPProject(element, InternalProject.class);
52
			InternalProject project = ECPUtil.getECPProject(element, InternalProject.class);
42
			if (project != null && project.isOpen() && EMFStoreProvider.INSTANCE.getProjectSpace(project).isShared()
53
			if (project != null && project.isOpen() && EMFStoreProvider.INSTANCE.getProjectSpace(project).isShared()
43
				&& EMFStoreDirtyDecoratorCachedTree.getInstance(project).getCachedValue(element) == Boolean.TRUE) {
54
				&& EMFStoreDirtyDecoratorCachedTree.getInstance(project).getCachedValue(element) > 0) {
44
				decoration.addOverlay(Activator.getImageDescriptor(dirtyPath), IDecoration.BOTTOM_LEFT);
55
				decoration.addOverlay(Activator.getImageDescriptor(dirtyPath), IDecoration.BOTTOM_LEFT);
45
			}
56
			}
46
57
47
			return;
58
			return;
48
		}
59
		}
49
60
50
		if (element instanceof ECPProject) {
51
			InternalProject project = (InternalProject) element;
52
			if (project.isOpen() && EMFStoreProvider.INSTANCE.getProjectSpace(project).isShared()
53
				&& EMFStoreDirtyDecoratorCachedTree.getInstance(project).getRootValue() == Boolean.TRUE) {
54
				decoration.addOverlay(Activator.getImageDescriptor(dirtyPath), IDecoration.BOTTOM_LEFT);
55
			}
56
		}
57
	}
61
	}
58
62
59
	/** {@inheritDoc} */
63
	/** {@inheritDoc} */
(-)src/org/eclipse/emf/ecp/emfstore/internal/ui/decorator/EMFStoreDirtyDecoratorCachedTree.java (-9 / +17 lines)
Lines 12-17 Link Here
12
 *******************************************************************************/
12
 *******************************************************************************/
13
package org.eclipse.emf.ecp.emfstore.internal.ui.decorator;
13
package org.eclipse.emf.ecp.emfstore.internal.ui.decorator;
14
14
15
import org.eclipse.emf.ecore.EObject;
15
import org.eclipse.emf.ecp.core.ECPProject;
16
import org.eclipse.emf.ecp.core.ECPProject;
16
import org.eclipse.emf.ecp.ui.common.AbstractCachedTree;
17
import org.eclipse.emf.ecp.ui.common.AbstractCachedTree;
17
import org.eclipse.emf.ecp.ui.common.CachedTreeNode;
18
import org.eclipse.emf.ecp.ui.common.CachedTreeNode;
Lines 26-32 Link Here
26
 * @author emueller
27
 * @author emueller
27
 * 
28
 * 
28
 */
29
 */
29
public final class EMFStoreDirtyDecoratorCachedTree extends AbstractCachedTree<Boolean> {
30
public final class EMFStoreDirtyDecoratorCachedTree extends AbstractCachedTree<Integer> {
30
31
31
	private static Map<ECPProject, EMFStoreDirtyDecoratorCachedTree> cashedTrees = new HashMap<ECPProject, EMFStoreDirtyDecoratorCachedTree>();
32
	private static Map<ECPProject, EMFStoreDirtyDecoratorCachedTree> cashedTrees = new HashMap<ECPProject, EMFStoreDirtyDecoratorCachedTree>();
32
33
Lines 57-63 Link Here
57
	/**
58
	/**
58
	 * 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.
59
	 */
60
	 */
60
	public class CachedDirtyStateTreeNode extends CachedTreeNode<Boolean> {
61
	public class CachedDirtyStateTreeNode extends CachedTreeNode<Integer> {
61
62
62
		/**
63
		/**
63
		 * Constructor.
64
		 * Constructor.
Lines 65-71 Link Here
65
		 * @param value
66
		 * @param value
66
		 *            the initial value for this entry
67
		 *            the initial value for this entry
67
		 */
68
		 */
68
		public CachedDirtyStateTreeNode(Boolean value) {
69
		public CachedDirtyStateTreeNode(Integer value) {
69
			super(value);
70
			super(value);
70
		}
71
		}
71
72
Lines 74-87 Link Here
74
		 */
75
		 */
75
		@Override
76
		@Override
76
		public void update() {
77
		public void update() {
77
			for (Boolean isDirty : values()) {
78
			for (Integer isDirty : values()) {
78
				if (isDirty) {
79
				if (isDirty > 0) {
79
					setValue(isDirty);
80
					setValue(isDirty);
80
					return;
81
					return;
81
				}
82
				}
82
			}
83
			}
83
84
84
			setValue(false);
85
			setValue(0);
85
		}
86
		}
86
	}
87
	}
87
88
Lines 89-104 Link Here
89
	 * {@inheritDoc}
90
	 * {@inheritDoc}
90
	 */
91
	 */
91
	@Override
92
	@Override
92
	public Boolean getDefaultValue() {
93
	public Integer getDefaultValue() {
93
		return Boolean.FALSE;
94
		return 0;
94
	}
95
	}
95
96
96
	/**
97
	/**
97
	 * {@inheritDoc}
98
	 * {@inheritDoc}
98
	 */
99
	 */
99
	@Override
100
	@Override
100
	public CachedTreeNode<Boolean> createdCachedTreeNode(Boolean t) {
101
	public CachedTreeNode<Integer> createdCachedTreeNode(Integer t) {
101
		return new CachedDirtyStateTreeNode(t);
102
		return new CachedDirtyStateTreeNode(t);
102
	}
103
	}
103
104
105
	public void addOperation(EObject eObject) {
106
		update(eObject, getCachedValue(eObject) + 1);
107
	}
108
109
	public void removeOperation(EObject eObject) {
110
		update(eObject, getCachedValue(eObject) - 1);
111
	}
104
}
112
}
(-)src/org/eclipse/emf/ecp/emfstore/internal/ui/decorator/EMFStoreDirtyObserver.java (-29 / +37 lines)
Lines 13-65 Link Here
13
package org.eclipse.emf.ecp.emfstore.internal.ui.decorator;
13
package org.eclipse.emf.ecp.emfstore.internal.ui.decorator;
14
14
15
import org.eclipse.emf.ecore.EObject;
15
import org.eclipse.emf.ecore.EObject;
16
import org.eclipse.emf.ecp.core.ECPProject;
17
import org.eclipse.emf.ecp.core.util.observer.IECPProjectsChangedUIObserver;
18
import org.eclipse.emf.ecp.emfstore.core.internal.EMFStoreProvider;
19
import org.eclipse.emf.ecp.spi.core.InternalProject;
16
import org.eclipse.emf.ecp.spi.core.InternalProject;
20
17
import org.eclipse.emf.emfstore.client.model.ProjectSpace;
21
import java.util.HashSet;
18
import org.eclipse.emf.emfstore.client.model.observers.OperationObserver;
19
import org.eclipse.emf.emfstore.common.model.ModelElementId;
20
import org.eclipse.emf.emfstore.common.model.Project;
21
import org.eclipse.emf.emfstore.server.model.versioning.operations.AbstractOperation;
22
22
23
/**
23
/**
24
 * Project change observer that marks elements as dirty.
24
 * Project change observer that marks elements as dirty.
25
 */
25
 */
26
public class EMFStoreDirtyObserver implements IECPProjectsChangedUIObserver {
26
public class EMFStoreDirtyObserver implements OperationObserver {
27
27
28
	private HashSet<Object> excludedObjects;
28
	private ProjectSpace projectSpace;
29
	private InternalProject internalProject;
29
30
30
	/**
31
	/**
31
	 * Default constructor.
32
	 * Default constructor.
33
	 * 
34
	 * @param project
32
	 */
35
	 */
33
	public EMFStoreDirtyObserver() {
36
	public EMFStoreDirtyObserver(ProjectSpace projectSpace, InternalProject project) {
34
37
		this.projectSpace = projectSpace;
38
		internalProject = project;
35
	}
39
	}
36
40
37
	// BEGIN SUPRESS CATCH EXCEPTION
41
	/*
38
	public void projectsChanged(ECPProject[] oldProjects, ECPProject[] newProjects) throws Exception {
42
	 * (non-Javadoc)
43
	 * @see
44
	 * org.eclipse.emf.emfstore.client.model.observers.OperationObserver#operationExecuted(org.eclipse.emf.emfstore.
45
	 * server.model.versioning.operations.AbstractOperation)
46
	 */
47
	public void operationExecuted(AbstractOperation operation) {
48
		for (ModelElementId modelElementId : operation.getAllInvolvedModelElements()) {
49
			Project project = projectSpace.getProject();
50
			EObject element = project.getModelElement(modelElementId);
39
51
40
	}
52
			EMFStoreDirtyDecoratorCachedTree.getInstance(internalProject).addOperation(element);
41
42
	public void projectChanged(ECPProject project, boolean opened) throws Exception {
43
44
	}
45
46
	public void objectsChanged(ECPProject project, Object[] objects, boolean structural) throws Exception {
47
48
		if (EMFStoreProvider.INSTANCE.getProjectSpace((InternalProject) project).isShared()) {
49
			return;
50
		}
53
		}
51
		// for all changed objects
52
		for (Object object : objects) {
53
			// not an eobject then do nothing
54
			if (!(object instanceof EObject)) {
55
				continue;
56
			}
57
54
58
			EObject eObject = (EObject) object;
55
	}
59
56
60
			EMFStoreDirtyDecoratorCachedTree.getInstance(project).update(eObject, Boolean.TRUE);
57
	/*
58
	 * (non-Javadoc)
59
	 * @see
60
	 * org.eclipse.emf.emfstore.client.model.observers.OperationObserver#operationUnDone(org.eclipse.emf.emfstore.server
61
	 * .model.versioning.operations.AbstractOperation)
62
	 */
63
	public void operationUnDone(AbstractOperation operation) {
64
		for (ModelElementId modelElementId : operation.getAllInvolvedModelElements()) {
65
			Project project = projectSpace.getProject();
66
			EObject element = project.getModelElement(modelElementId);
61
67
68
			EMFStoreDirtyDecoratorCachedTree.getInstance(internalProject).removeOperation(element);
62
		}
69
		}
70
63
	}
71
	}
64
72
65
	// END SUPRESS CATCH EXCEPTION
73
	// END SUPRESS CATCH EXCEPTION

Return to bug 395917