From a49c61523dfbe82e183f0a0d2cce329a69637657 Mon Sep 17 00:00:00 2001 From: Vincent Lorenzo Date: Thu, 3 Apr 2014 16:50:52 +0200 Subject: 431918: java.lang.IndexOutOfBoundsException on a sysml model creation with only a table https://bugs.eclipse.org/bugs/show_bug.cgi?id=431918 --- .../handlers/AbstractCreateNattableEditorHandler.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/handlers/AbstractCreateNattableEditorHandler.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/handlers/AbstractCreateNattableEditorHandler.java index f7f18c4dede..ae4e19e6f0a 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/handlers/AbstractCreateNattableEditorHandler.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/handlers/AbstractCreateNattableEditorHandler.java @@ -21,6 +21,7 @@ import java.util.List; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.emf.common.command.Command; import org.eclipse.emf.common.util.URI; @@ -36,6 +37,7 @@ import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.papyrus.infra.core.editor.BackboneException; import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor; +import org.eclipse.papyrus.infra.core.resource.ModelSet; import org.eclipse.papyrus.infra.core.resource.NotFoundException; import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager; import org.eclipse.papyrus.infra.core.services.ServiceException; @@ -184,12 +186,13 @@ public abstract class AbstractCreateNattableEditorHandler extends AbstractHandle * The model where to save the TableInstance is not found. */ protected Table createEditorModel(final ServicesRegistry serviceRegistry, String name, String description) throws ServiceException, NotFoundException { - final TableConfiguration configuration = getDefaultTableEditorConfiguration(); - assert configuration != null; + final ModelSet modelSet = ServiceUtils.getInstance().getModelSet(serviceRegistry); + final TableConfiguration configuration = getDefaultTableEditorConfiguration(modelSet); + Assert.isNotNull(configuration); final Table table = TableHelper.createTable(configuration, null, name, description); //context null here, see bug 410357 // Save the model in the associated resource - final PapyrusNattableModel model = (PapyrusNattableModel)ServiceUtils.getInstance().getModelSet(serviceRegistry).getModelChecked(PapyrusNattableModel.MODEL_ID); + final PapyrusNattableModel model = (PapyrusNattableModel)modelSet.getModelChecked(PapyrusNattableModel.MODEL_ID); model.addPapyrusTable(table); table.setContext(getTableContext()); return table; @@ -198,12 +201,11 @@ public abstract class AbstractCreateNattableEditorHandler extends AbstractHandle /** * + * @param resourceSet TODO * @return * the configuration to use for the new table */ - protected TableConfiguration getDefaultTableEditorConfiguration() { - final EObject current = getSelection().get(0); - final ResourceSet resourceSet = current.eResource().getResourceSet(); + protected TableConfiguration getDefaultTableEditorConfiguration(ResourceSet resourceSet) { final Resource resource = resourceSet.getResource(getTableEditorConfigurationURI(), true); TableConfiguration tableConfiguration = null; if(resource.getContents().get(0) instanceof TableConfiguration) { -- cgit v1.2.3