|
Lines 1-5
Link Here
|
| 1 |
package org.eclipse.emf.ecp.emfstore.core.internal; |
1 |
package org.eclipse.emf.ecp.emfstore.core.internal; |
| 2 |
|
2 |
|
|
|
3 |
import org.eclipse.emf.common.notify.Notification; |
| 4 |
import org.eclipse.emf.common.notify.NotifyingList; |
| 5 |
import org.eclipse.emf.common.notify.impl.AdapterImpl; |
| 3 |
import org.eclipse.emf.common.util.EList; |
6 |
import org.eclipse.emf.common.util.EList; |
| 4 |
import org.eclipse.emf.ecore.EObject; |
7 |
import org.eclipse.emf.ecore.EObject; |
| 5 |
import org.eclipse.emf.ecp.core.ECPProject; |
8 |
import org.eclipse.emf.ecp.core.ECPProject; |
|
Lines 14-19
Link Here
|
| 14 |
import org.eclipse.emf.emfstore.client.model.ProjectSpace; |
17 |
import org.eclipse.emf.emfstore.client.model.ProjectSpace; |
| 15 |
import org.eclipse.emf.emfstore.client.model.WorkspaceManager; |
18 |
import org.eclipse.emf.emfstore.client.model.WorkspaceManager; |
| 16 |
import org.eclipse.emf.emfstore.server.model.ProjectInfo; |
19 |
import org.eclipse.emf.emfstore.server.model.ProjectInfo; |
|
|
20 |
|
| 21 |
import java.util.HashMap; |
| 22 |
import java.util.Map; |
| 17 |
|
23 |
|
| 18 |
public class EMFStoreProvider extends DefaultProvider |
24 |
public class EMFStoreProvider extends DefaultProvider |
| 19 |
{ |
25 |
{ |
|
Lines 46-60
Link Here
|
| 46 |
if (parent instanceof InternalProject) |
52 |
if (parent instanceof InternalProject) |
| 47 |
{ |
53 |
{ |
| 48 |
InternalProject project = (InternalProject)parent; |
54 |
InternalProject project = (InternalProject)parent; |
| 49 |
String projectSpaceID = project.getProperties().getValue(EMFStoreProvider.PROP_PROJECTSPACEID); |
55 |
ProjectSpace projectSpace = getProjectSpace(project); |
| 50 |
EList<ProjectSpace> projectSpaces = WorkspaceManager.getInstance().getCurrentWorkspace().getProjectSpaces(); |
56 |
|
| 51 |
for (ProjectSpace projectSpace : projectSpaces) |
57 |
childrenList.addChildren(projectSpace.getProject().getModelElements()); |
| 52 |
{ |
58 |
// TODO: provide interface at emfstore |
| 53 |
if (projectSpace.getIdentifier().equals(projectSpaceID)) |
59 |
NotifyingList<EObject> modelElements = (NotifyingList<EObject>)projectSpace.getProject().getModelElements(); |
| 54 |
{ |
60 |
modelElements.getNotifier(); |
| 55 |
childrenList.addChildren(projectSpace.getProject().getModelElements()); |
|
|
| 56 |
} |
| 57 |
} |
| 58 |
|
61 |
|
| 59 |
} |
62 |
} |
| 60 |
if (parent instanceof InternalRepository) |
63 |
if (parent instanceof InternalRepository) |
|
Lines 91-106
Link Here
|
| 91 |
throw new UnsupportedOperationException(); |
94 |
throw new UnsupportedOperationException(); |
| 92 |
} |
95 |
} |
| 93 |
|
96 |
|
| 94 |
public void addRootElement(ECPProject project, EObject rootElement) |
97 |
public EList<EObject> getElements(ECPProject ecpProject) |
| 95 |
{ |
98 |
{ |
| 96 |
String id = project.getProperties().getValue(EMFStoreProvider.PROP_PROJECTSPACEID); |
99 |
ProjectSpace projectSpace = getProjectSpace(ecpProject); |
| 97 |
EList<ProjectSpace> projectSpaces = WorkspaceManager.getInstance().getCurrentWorkspace().getProjectSpaces(); |
100 |
return projectSpace.getProject().getModelElements(); |
| 98 |
for (ProjectSpace projectSpace : projectSpaces) |
101 |
} |
|
|
102 |
|
| 103 |
private Map<ECPProject, ProjectSpace> cachedProjectSpaces = new HashMap<ECPProject, ProjectSpace>(); |
| 104 |
|
| 105 |
private AdapterImpl adapter; |
| 106 |
|
| 107 |
/** |
| 108 |
* Method for caching the loading of {@link ProjectSpace} |
| 109 |
* |
| 110 |
* @return {@link EList} of {@link ProjectSpace} |
| 111 |
*/ |
| 112 |
private ProjectSpace getProjectSpace(ECPProject ecpProject) |
| 113 |
{ |
| 114 |
if (!cachedProjectSpaces.containsKey(ecpProject)) |
| 99 |
{ |
115 |
{ |
| 100 |
if (projectSpace.getIdentifier().equals(id)) |
116 |
|
|
|
117 |
EList<ProjectSpace> projectSpaces = WorkspaceManager.getInstance().getCurrentWorkspace().getProjectSpaces(); |
| 118 |
for (ProjectSpace projectSpace : projectSpaces) |
| 101 |
{ |
119 |
{ |
| 102 |
projectSpace.getProject().addModelElement(rootElement); |
120 |
String projectSpaceID = ecpProject.getProperties().getValue(EMFStoreProvider.PROP_PROJECTSPACEID); |
|
|
121 |
if (projectSpace.getIdentifier().equals(projectSpaceID)) |
| 122 |
{ |
| 123 |
cachedProjectSpaces.put(ecpProject, projectSpace); |
| 124 |
} |
| 103 |
} |
125 |
} |
| 104 |
} |
126 |
} |
|
|
127 |
return cachedProjectSpaces.get(ecpProject); |
| 128 |
|
| 129 |
} |
| 130 |
|
| 131 |
@Override |
| 132 |
public void handleLifecycle(ECPModelContext context, LifecycleEvent event) |
| 133 |
{ |
| 134 |
switch (event) |
| 135 |
{ |
| 136 |
case INIT: |
| 137 |
handleInit(context); |
| 138 |
break; |
| 139 |
case DISPOSE: |
| 140 |
handelDispose(context); |
| 141 |
default: |
| 142 |
break; |
| 143 |
} |
| 144 |
// TODO Trace properly |
| 145 |
String providerClass = getClass().getSimpleName(); |
| 146 |
String contextClass = context.getClass().getSimpleName(); |
| 147 |
System.out.println(providerClass + " received " + event + " for " + contextClass + " " + context); |
| 148 |
} |
| 149 |
|
| 150 |
/** |
| 151 |
* @param context |
| 152 |
*/ |
| 153 |
private void handelDispose(ECPModelContext context) |
| 154 |
{ |
| 155 |
if (context instanceof InternalProject) |
| 156 |
{ |
| 157 |
ProjectSpace projectSpace = getProjectSpace((ECPProject)context); |
| 158 |
|
| 159 |
projectSpace.getProject().eAdapters().remove(adapter); |
| 160 |
|
| 161 |
} |
| 162 |
|
| 163 |
} |
| 164 |
|
| 165 |
/** |
| 166 |
* @param context |
| 167 |
*/ |
| 168 |
private void handleInit(final ECPModelContext context) |
| 169 |
{ |
| 170 |
if (context instanceof InternalProject) |
| 171 |
{ |
| 172 |
ProjectSpace projectSpace = getProjectSpace((ECPProject)context); |
| 173 |
|
| 174 |
adapter = new AdapterImpl() |
| 175 |
{ |
| 176 |
@Override |
| 177 |
public void notifyChanged(Notification notification) |
| 178 |
{ |
| 179 |
((InternalProject)context).notifyObjectsChanged(new Object[] { context }); |
| 180 |
} |
| 181 |
}; |
| 182 |
|
| 183 |
projectSpace.getProject().eAdapters().add(adapter); |
| 184 |
|
| 185 |
} |
| 186 |
|
| 105 |
} |
187 |
} |
| 106 |
} |
188 |
} |