diff --git a/org.fortiss.tooling.kernel/trunk/META-INF/MANIFEST.MF b/org.fortiss.tooling.kernel/trunk/META-INF/MANIFEST.MF index 170081c08ff143c34395f0cf2bfce48c4265ee2f..95b10c8ffbb64bd47f318d9de17399482740e528 100644 --- a/org.fortiss.tooling.kernel/trunk/META-INF/MANIFEST.MF +++ b/org.fortiss.tooling.kernel/trunk/META-INF/MANIFEST.MF @@ -23,4 +23,5 @@ Export-Package: org.fortiss.tooling.kernel, org.fortiss.tooling.kernel.model, org.fortiss.tooling.kernel.model.impl, org.fortiss.tooling.kernel.model.util, - org.fortiss.tooling.kernel.services + org.fortiss.tooling.kernel.services, + org.fortiss.tooling.kernel.util diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/CommandStackService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/CommandStackService.java index f60a0e5cbb8c1f7d96dd4ccad3f83d661dacf682..efb972e5ce2c1a2fa511615e7ca3955568f9986d 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/CommandStackService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/CommandStackService.java @@ -29,6 +29,7 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.edit.command.ChangeCommand; import org.fortiss.tooling.kernel.ToolingKernelActivator; import org.fortiss.tooling.kernel.services.ICommandStackService; +import org.fortiss.tooling.kernel.util.ProjectRootElementUtils; import org.unicase.ecp.model.ECPWorkspaceManager; import org.unicase.ecp.model.NoWorkspaceException; import org.unicase.ecp.model.workSpaceModel.ECPProject; @@ -85,31 +86,36 @@ public class CommandStackService implements ICommandStackService { runner.run(); } }; - commandStackMap.get(getECPProject(target)).execute(chgCommand); + commandStackMap.get(ProjectRootElementUtils.getECPProject(target)) + .execute(chgCommand); } /** {@inheritDoc} */ @Override public boolean canUndo(EObject target) { - return commandStackMap.get(getECPProject(target)).canUndo(); + return commandStackMap.get( + ProjectRootElementUtils.getECPProject(target)).canUndo(); } /** {@inheritDoc} */ @Override public boolean canRedo(EObject target) { - return commandStackMap.get(getECPProject(target)).canRedo(); + return commandStackMap.get( + ProjectRootElementUtils.getECPProject(target)).canRedo(); } /** {@inheritDoc} */ @Override public void undo(EObject target) { - commandStackMap.get(getECPProject(target)).undo(); + commandStackMap.get(ProjectRootElementUtils.getECPProject(target)) + .undo(); } /** {@inheritDoc} */ @Override public void redo(EObject target) { - commandStackMap.get(getECPProject(target)).redo(); + commandStackMap.get(ProjectRootElementUtils.getECPProject(target)) + .redo(); } /** @@ -137,20 +143,6 @@ public class CommandStackService implements ICommandStackService { }; } - /** - * Returns the model element's ECP project or <code>null</code> . - */ - private ECPProject getECPProject(EObject target) { - try { - return ECPWorkspaceManager.getInstance().getWorkSpace() - .getProject(target); - } catch (Exception e) { - LoggingUtils.error(ToolingKernelActivator.getDefault(), - "Unable to find ECP project!", e); - } - return null; - } - /** Adds the command stack for the given project. */ private void addCommandStack(ECPProject project) { BasicCommandStack cmdStack = (BasicCommandStack) project diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/util/ProjectRootElementUtils.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/util/ProjectRootElementUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..5356f04db20a2fda060fd74662f164495b2a698b --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/util/ProjectRootElementUtils.java @@ -0,0 +1,63 @@ +/*--------------------------------------------------------------------------+ +$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.util; + +import org.conqat.ide.commons.ui.logging.LoggingUtils; +import org.conqat.lib.commons.reflect.ReflectionUtils; +import org.eclipse.emf.ecore.EObject; +import org.fortiss.tooling.kernel.ToolingKernelActivator; +import org.fortiss.tooling.kernel.model.IProjectRootElement; +import org.unicase.ecp.model.ECPWorkspaceManager; +import org.unicase.ecp.model.workSpaceModel.ECPProject; +import org.unicase.workspace.ProjectSpace; + +/** + * Utility methods for accessing {@link IProjectRootElement}s. + * + * @author hoelzlf + * @author $Author$ + * @version $Rev$ + * @levd.rating RED Rev: + */ +public final class ProjectRootElementUtils { + + /** + * Returns the model element's ECP project or <code>null</code> . + */ + public static ECPProject getECPProject(EObject element) { + try { + return ECPWorkspaceManager.getInstance().getWorkSpace() + .getProject(element); + } catch (Exception e) { + LoggingUtils.error(ToolingKernelActivator.getDefault(), + "Unable to find ECP project!", e); + } + return null; + } + + /** + * Returns the instance of a project root element corresponding to the given + * class. + */ + public static <T extends IProjectRootElement> T getRootElement( + EObject element, Class<T> clazz) { + ECPProject project = getECPProject(element); + return ReflectionUtils.pickInstanceOf(clazz, ((ProjectSpace) project + .getRootObject()).getProject().getAllModelElements()); + } +}