diff options
author | Ansgar Radermacher | 2018-10-05 12:58:17 +0000 |
---|---|---|
committer | Patrick Tessier | 2018-10-19 07:46:27 +0000 |
commit | 50d8e30590f967ded03041be10e8cbcfc2414a76 (patch) | |
tree | cdf7688c62db16b78d2a7ebffa4f1b290b61b354 /plugins | |
parent | 65a7b3c413b602f2b2eaa40fd7d7b9035f32029f (diff) | |
download | org.eclipse.papyrus-50d8e30590f967ded03041be10e8cbcfc2414a76.tar.gz org.eclipse.papyrus-50d8e30590f967ded03041be10e8cbcfc2414a76.tar.xz org.eclipse.papyrus-50d8e30590f967ded03041be10e8cbcfc2414a76.zip |
Bug 539754 - [Customization] Improve error messages
- Add error messages
- Use ClassLoaderHelper instead of directly using bundle.loadClass.
Signed-off-by: Ansgar Radermacher <ansgar.radermacher@cea.fr>
Diffstat (limited to 'plugins')
2 files changed, 23 insertions, 24 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/GMFDiagramViewTypeHelper.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/GMFDiagramViewTypeHelper.java index 4870767af69..a5e7cb15026 100755 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/GMFDiagramViewTypeHelper.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/GMFDiagramViewTypeHelper.java @@ -11,22 +11,21 @@ * Contributors: * Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation * Christian W. Damus - bug 527580 - * + * Ansgar Radermacher - bug 539754 + * *****************************************************************************/ package org.eclipse.papyrus.infra.gmfdiag.common.helper; -import org.eclipse.core.runtime.Platform; -import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.gmf.runtime.notation.Diagram; import org.eclipse.papyrus.infra.gmfdiag.common.AbstractPapyrusGmfCreateDiagramCommandHandler; import org.eclipse.papyrus.infra.gmfdiag.common.Activator; import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils; import org.eclipse.papyrus.infra.gmfdiag.representation.PapyrusDiagram; +import org.eclipse.papyrus.infra.tools.util.ClassLoaderHelper; import org.eclipse.papyrus.infra.viewpoints.policy.AbstractViewTypeHelper; import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker; import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype; -import org.osgi.framework.Bundle; /** * Represents the dynamic contribution of a policy to menus @@ -49,26 +48,15 @@ public class GMFDiagramViewTypeHelper extends AbstractViewTypeHelper<PapyrusDiag /** * {@inheritDoc} - * + * * @since 3.100 */ @Override protected ViewPrototype doGetPrototypeFor(PapyrusDiagram diagramKind) { String commandClassName = diagramKind.getCreationCommandClass(); if (commandClassName != null) { - Class<?> creationCommandClass = null; - - URI uri = diagramKind.eResource().getURI(); - if (uri.isPlatformPlugin()) { - String bundleName = uri.segment(1); - Bundle bundle = Platform.getBundle(bundleName); - try { - creationCommandClass = bundle.loadClass(diagramKind.getCreationCommandClass()); - } catch (ClassNotFoundException e) { - Activator.log.error(e); - } - } - + Class<?> creationCommandClass = ClassLoaderHelper.loadClass(commandClassName); + if (creationCommandClass != null) { AbstractPapyrusGmfCreateDiagramCommandHandler command; try { @@ -77,9 +65,14 @@ public class GMFDiagramViewTypeHelper extends AbstractViewTypeHelper<PapyrusDiag Activator.log.error(e); return null; } - + String language = diagramKind.getLanguage().getId(); return new DiagramPrototype(diagramKind, language, command); + } else { + // ClassLoaderHelper should have already logged an exception, but without stating diagram kind + Activator.log.error(new ClassNotFoundException( + String.format("Can not load creation command class %s for diagramKind %s.", //$NON-NLS-1$ + commandClassName, diagramKind.getName()))); } } return null; @@ -87,7 +80,7 @@ public class GMFDiagramViewTypeHelper extends AbstractViewTypeHelper<PapyrusDiag /** * {@inheritDoc} - * + * * @since 3.2 */ @Override diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramUtils.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramUtils.java index 19616c59eb9..9018362751d 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramUtils.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramUtils.java @@ -13,6 +13,8 @@ * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation * Benoit Maggi (Cea) benoit.maggi@cea.fr - Add utility to get the containing diagram * Christian W. Damus - bug 527580 + * Ansgar Radermacher - bug 539754 + * *****************************************************************************/ package org.eclipse.papyrus.infra.gmfdiag.common.utils; @@ -178,13 +180,13 @@ public class DiagramUtils { /** * Gets the prototype of a {@code diagram} according to a given policy {@code checker}. - * + * * @param diagram * a diagram * @param checker * a policy checker * @return the policy {@code checker}'s prototype for the {@code diagram} - * + * * @since 3.2 */ public static ViewPrototype getPrototype(Diagram diagram, PolicyChecker checker) { @@ -262,8 +264,12 @@ public class DiagramUtils { pvs = (PapyrusDiagramStyle) diagram.createStyle(StylePackage.Literals.PAPYRUS_DIAGRAM_STYLE); pvs.setDiagramKindId(prototype.getRepresentationKind().getId()); } - } else - throw new IllegalArgumentException("The diagram's type differs from the prototype's implementation id"); + } else { + throw new IllegalArgumentException( + String.format("The diagram type (=%s) differs from the prototype's implementation id (=%s)", //$NON-NLS-1$ + diagram.getType(), + prototype.getRepresentationKind().getImplementationID())); + } } |