|
Lines 16-23
Link Here
|
| 16 |
import org.eclipse.emf.ecp.core.ECPProject; |
16 |
import org.eclipse.emf.ecp.core.ECPProject; |
| 17 |
import org.eclipse.emf.ecp.core.ECPProjectManager; |
17 |
import org.eclipse.emf.ecp.core.ECPProjectManager; |
| 18 |
import org.eclipse.emf.ecp.core.util.observer.ECPObserverBus; |
18 |
import org.eclipse.emf.ecp.core.util.observer.ECPObserverBus; |
| 19 |
import org.eclipse.emf.ecp.core.util.observer.IECPProjectObjectsChangedObserver; |
19 |
import org.eclipse.emf.ecp.core.util.observer.IECPProjectPreDeleteObserver; |
| 20 |
import org.eclipse.emf.ecp.core.util.observer.IECPProjectsChangedUIObserver; |
|
|
| 21 |
import org.eclipse.emf.ecp.emfstore.core.internal.EMFStoreProvider; |
20 |
import org.eclipse.emf.ecp.emfstore.core.internal.EMFStoreProvider; |
| 22 |
import org.eclipse.emf.ecp.emfstore.internal.ui.Activator; |
21 |
import org.eclipse.emf.ecp.emfstore.internal.ui.Activator; |
| 23 |
import org.eclipse.emf.ecp.spi.core.InternalProject; |
22 |
import org.eclipse.emf.ecp.spi.core.InternalProject; |
|
Lines 30-106
Link Here
|
| 30 |
import org.eclipse.jface.viewers.ILabelProviderListener; |
29 |
import org.eclipse.jface.viewers.ILabelProviderListener; |
| 31 |
import org.eclipse.jface.viewers.ILightweightLabelDecorator; |
30 |
import org.eclipse.jface.viewers.ILightweightLabelDecorator; |
| 32 |
|
31 |
|
| 33 |
import java.util.Arrays; |
|
|
| 34 |
import java.util.HashMap; |
32 |
import java.util.HashMap; |
| 35 |
import java.util.HashSet; |
|
|
| 36 |
import java.util.Map; |
33 |
import java.util.Map; |
| 37 |
import java.util.Set; |
|
|
| 38 |
|
34 |
|
| 39 |
/** |
35 |
/** |
| 40 |
* @author Eugen Neufeld |
36 |
* @author Eugen Neufeld |
| 41 |
*/ |
37 |
*/ |
| 42 |
public class EMFStoreDirtyDecorator implements ILightweightLabelDecorator, CommitObserver { |
38 |
public class EMFStoreDirtyDecorator implements ILightweightLabelDecorator, CommitObserver, IECPProjectPreDeleteObserver { |
| 43 |
|
39 |
|
| 44 |
private String dirtyPath = "icons/dirty.png"; |
40 |
private String dirtyPath = "icons/dirty.png"; |
| 45 |
private Map<InternalProject, EMFStoreDirtyObserver> observers = new HashMap<InternalProject, EMFStoreDirtyObserver>(); |
41 |
private Map<ECPProject, EMFStoreDirtyObserver> observers = new HashMap<ECPProject, EMFStoreDirtyObserver>(); |
| 46 |
|
42 |
|
|
|
43 |
/** |
| 44 |
* Instantiates a new EMFStoreDirtyDecorator. |
| 45 |
*/ |
| 47 |
public EMFStoreDirtyDecorator() { |
46 |
public EMFStoreDirtyDecorator() { |
| 48 |
EMFStoreDirtyDecoratorConnector con = new EMFStoreDirtyDecoratorConnector(); |
47 |
super(); |
| 49 |
ECPObserverBus.getInstance().register(con); |
48 |
ECPObserverBus.getInstance().register(this); |
| 50 |
} |
|
|
| 51 |
|
| 52 |
private class EMFStoreDirtyDecoratorConnector implements IECPProjectObjectsChangedObserver, |
| 53 |
IECPProjectsChangedUIObserver { |
| 54 |
|
| 55 |
/** {@inheritDoc} */ |
| 56 |
public Object[] objectsChanged(ECPProject project, Object[] objects) throws Exception { |
| 57 |
if (project.getRepository() == null) { |
| 58 |
return null; |
| 59 |
} |
| 60 |
Set<EObject> allObjects = new HashSet<EObject>(); |
| 61 |
for (EMFStoreDirtyObserver observer : observers.values()) { |
| 62 |
allObjects.addAll(observer.getLastAffected()); |
| 63 |
} |
| 64 |
return allObjects.toArray(); |
| 65 |
} |
| 66 |
|
| 67 |
/** {@inheritDoc} */ |
| 68 |
public void projectsChanged(ECPProject[] oldProjects, ECPProject[] newProjects) throws Exception { |
| 69 |
Set<ECPProject> removed = new HashSet<ECPProject>(Arrays.asList(oldProjects)); |
| 70 |
removed.removeAll(Arrays.asList(newProjects)); |
| 71 |
|
| 72 |
for (ECPProject project : removed) { |
| 73 |
observers.remove(project); |
| 74 |
EMFStoreDirtyDecoratorCachedTree.getInstance(project).clear(); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
/** {@inheritDoc} */ |
| 79 |
public void projectChanged(ECPProject project, boolean opened) throws Exception { |
| 80 |
// Do nothing |
| 81 |
} |
| 82 |
|
| 83 |
/** {@inheritDoc} */ |
| 84 |
public void objectsChanged(ECPProject project, Object[] objects, boolean structural) throws Exception { |
| 85 |
// Do nothing |
| 86 |
} |
| 87 |
|
| 88 |
} |
49 |
} |
| 89 |
|
50 |
|
| 90 |
/** {@inheritDoc} */ |
51 |
/** {@inheritDoc} */ |
| 91 |
public void decorate(Object element, IDecoration decoration) { |
52 |
public void decorate(Object element, IDecoration decoration) { |
| 92 |
|
|
|
| 93 |
if (element instanceof ECPProject) { |
53 |
if (element instanceof ECPProject) { |
| 94 |
InternalProject project = (InternalProject) element; |
54 |
InternalProject project = (InternalProject) element; |
|
|
55 |
if (ECPProjectManager.INSTANCE.getProject(project.getName()) == null) { |
| 56 |
return; |
| 57 |
} |
| 95 |
ProjectSpace projectSpace = EMFStoreProvider.INSTANCE.getProjectSpace(project); |
58 |
ProjectSpace projectSpace = EMFStoreProvider.INSTANCE.getProjectSpace(project); |
| 96 |
|
59 |
|
| 97 |
if (!observers.containsKey(element)) { |
60 |
if (!observers.containsKey(element)) { |
| 98 |
EMFStoreDirtyObserver emfStoreDirtyObserver = new EMFStoreDirtyObserver(projectSpace, project); |
61 |
EMFStoreDirtyObserver emfStoreDirtyObserver = new EMFStoreDirtyObserver(projectSpace, project); |
| 99 |
projectSpace.getOperationManager().addOperationListener(emfStoreDirtyObserver); |
62 |
projectSpace.getOperationManager().addOperationListener(emfStoreDirtyObserver); |
| 100 |
observers.put(project, emfStoreDirtyObserver); |
63 |
observers.put((ECPProject) element, emfStoreDirtyObserver); |
| 101 |
} |
64 |
} |
| 102 |
if (project.isOpen() && EMFStoreProvider.INSTANCE.getProjectSpace(project).isShared() |
65 |
if (project.isOpen() && EMFStoreProvider.INSTANCE.getProjectSpace(project).isShared() |
| 103 |
&& EMFStoreDirtyDecoratorCachedTree.getInstance(project).getRootValue().shouldDisplayDirtyIndicator()) { |
66 |
&& EMFStoreDirtyDecoratorCachedTree.getInstance(project).getRootValue() > 0) { |
| 104 |
decoration.addOverlay(Activator.getImageDescriptor(dirtyPath), IDecoration.BOTTOM_LEFT); |
67 |
decoration.addOverlay(Activator.getImageDescriptor(dirtyPath), IDecoration.BOTTOM_LEFT); |
| 105 |
} |
68 |
} |
| 106 |
} |
69 |
} |
|
Lines 112-122
Link Here
|
| 112 |
} catch (IllegalArgumentException iae) { |
75 |
} catch (IllegalArgumentException iae) { |
| 113 |
// ignore |
76 |
// ignore |
| 114 |
} |
77 |
} |
| 115 |
if (project != null |
78 |
if (project != null && project.isOpen() && EMFStoreProvider.INSTANCE.getProjectSpace(project).isShared() |
| 116 |
&& project.isOpen() |
79 |
&& EMFStoreDirtyDecoratorCachedTree.getInstance(project).getCachedValue(element) > 0) { |
| 117 |
&& EMFStoreProvider.INSTANCE.getProjectSpace(project).isShared() |
|
|
| 118 |
&& EMFStoreDirtyDecoratorCachedTree.getInstance(project).getCachedValue(element) |
| 119 |
.shouldDisplayDirtyIndicator()) { |
| 120 |
decoration.addOverlay(Activator.getImageDescriptor(dirtyPath), IDecoration.BOTTOM_LEFT); |
80 |
decoration.addOverlay(Activator.getImageDescriptor(dirtyPath), IDecoration.BOTTOM_LEFT); |
| 121 |
} else { |
81 |
} else { |
| 122 |
decoration.addOverlay(null); |
82 |
decoration.addOverlay(null); |
|
Lines 153-156
Link Here
|
| 153 |
ECPProject project = EMFStoreProvider.INSTANCE.getProject(projectSpace); |
113 |
ECPProject project = EMFStoreProvider.INSTANCE.getProject(projectSpace); |
| 154 |
EMFStoreDirtyDecoratorCachedTree.getInstance(project).clear(); |
114 |
EMFStoreDirtyDecoratorCachedTree.getInstance(project).clear(); |
| 155 |
} |
115 |
} |
|
|
116 |
|
| 117 |
/** {@inheritDoc} */ |
| 118 |
public void projectDelete(ECPProject project) { |
| 119 |
EMFStoreDirtyDecoratorCachedTree.getInstance(project).clear(); |
| 120 |
observers.remove(project); |
| 121 |
} |
| 156 |
} |
122 |
} |