Skip to content
Snippets Groups Projects
Commit 8364d6bf authored by Florian Hölzl's avatar Florian Hölzl
Browse files

added TestModel.java and SimulatorStartup.java

refs 158
parent 4b21fa3f
No related branches found
No related tags found
No related merge requests found
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.internal;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.command.CommandStackListener;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
/**
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
final class DummyTopLevelElement implements ITopLevelElement {
/** Stores the root element. */
private final EObject root;
/** Constructor. */
public DummyTopLevelElement(EObject root) {
Assert.isNotNull(root);
Assert.isTrue(root.eResource() == null);
this.root = root;
}
/** {@inheritDoc} */
@Override
public EObject getRootModelElement() {
return root;
}
/** {@inheritDoc} */
@Override
public void runAsCommand(Runnable runner) {
runner.run();
}
/** {@inheritDoc} */
@Override
public void addCommandStackListener(CommandStackListener listener) {
// ignore
}
/** {@inheritDoc} */
@Override
public void removeCommandStackListener(CommandStackListener listener) {
// ignore
}
/** {@inheritDoc} */
@Override
public boolean canUndo() {
return false;
}
/** {@inheritDoc} */
@Override
public boolean canRedo() {
return false;
}
/** {@inheritDoc} */
@Override
public void undo() {
// ignore
}
/** {@inheritDoc} */
@Override
public void redo() {
// ignore
}
/** {@inheritDoc} */
@Override
public boolean isDirty() {
return false;
}
/** {@inheritDoc} */
@Override
public String getSaveableName() {
return "Dummy";
}
/** {@inheritDoc} */
@Override
public void doSave(IProgressMonitor monitor) {
// ignore
}
/** {@inheritDoc} */
@Override
public void prepareIDs(EObject modelElement) {
// ignore
}
}
......@@ -65,6 +65,9 @@ public class PersistencyService implements IPersistencyService {
/** Stores the top-level element contexts. */
private final List<ITopLevelElement> contextCache = new LinkedList<ITopLevelElement>();
/** Stores the dummy top-level element contexts. */
private Map<EObject, ITopLevelElement> dummyCache = null;
/** Stores the storage providers and their element caches. */
private final Map<ITopLevelElement, IStorageProvider> storageProviderCache = new HashMap<ITopLevelElement, IStorageProvider>();
......@@ -243,4 +246,25 @@ public class PersistencyService implements IPersistencyService {
}
}
}
/** {@inheritDoc} */
@Override
public void addDummyEObjectAsTopLevelElement(EObject dummyRoot) {
if (dummyCache == null) {
dummyCache = new HashMap<EObject, ITopLevelElement>();
}
DummyTopLevelElement dummy = new DummyTopLevelElement(dummyRoot);
dummyCache.put(dummyRoot, dummy);
contextCache.add(dummy);
}
/** {@inheritDoc} */
@Override
public void removeDummyTopLevelElement(EObject dummy) {
if (dummyCache == null || !dummyCache.containsKey(dummy)) {
return;
}
contextCache.remove(dummyCache.get(dummy));
dummyCache.remove(dummy);
}
}
......@@ -83,4 +83,16 @@ public interface IPersistencyService {
/** Notifies top-level element listeners about change of the given element. */
void notifyTopLevelElementChanged(ITopLevelElement element);
/**
* Adds the given EObject as a dummy top-level element. This method is
* intended for JUnit testing purposes only.
*/
public void addDummyEObjectAsTopLevelElement(EObject dummy);
/**
* Removes the given EObject from the dummy top-level elements. This method
* is intended for JUnit testing purposes only.²
*/
public void removeDummyTopLevelElement(EObject dummy);
}
......@@ -54,8 +54,7 @@ public final class ProjectRootElementUtils {
* <code>null</code> if no such element exists. The search is started from
* the given elements top-level parent.
*/
public static EObject findElementByName(String qualifiedName,
EObject parent) {
public static EObject findElementByName(String qualifiedName, EObject parent) {
StringTokenizer tizer = new StringTokenizer(qualifiedName, "/");
EObject current = IPersistencyService.INSTANCE.getTopLevelElementFor(
parent).getRootModelElement();
......@@ -84,12 +83,21 @@ public final class ProjectRootElementUtils {
* element exists.
*/
public static EObject findElementById(IIdLabeledReference reference) {
EObject root = IPersistencyService.INSTANCE.getTopLevelElementFor(
reference).getRootModelElement();
return findElementById(reference.getIdReference(),
IPersistencyService.INSTANCE.getTopLevelElementFor(reference)
.getRootModelElement());
}
/**
* Finds the model element referenced by the given
* {@link IIdLabeledReference} element or <code>null</code> if no such
* element exists.
*/
public static EObject findElementById(int id, EObject root) {
for (Iterator<EObject> iter = root.eAllContents(); iter.hasNext();) {
EObject eo = iter.next();
if (eo instanceof IIdLabeled
&& ((IIdLabeled) eo).getId() == reference.getIdReference()) {
if (eo instanceof IIdLabeled && ((IIdLabeled) eo).getId() == id) {
return eo;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment