diff options
author | René Brandstetter | 2013-10-16 15:49:06 +0000 |
---|---|---|
committer | Lars Vogel | 2013-10-21 10:40:30 +0000 |
commit | 3edacc00de18769c4cf426e12ccedd3e6945d72c (patch) | |
tree | d7c7c1d24a04339f4f935f54362578a04bf93166 | |
parent | c75fa917899356c6676e614505e9fe1e95ab6304 (diff) | |
download | org.eclipse.e4.tools-3edacc00de18769c4cf426e12ccedd3e6945d72c.tar.gz org.eclipse.e4.tools-3edacc00de18769c4cf426e12ccedd3e6945d72c.tar.xz org.eclipse.e4.tools-3edacc00de18769c4cf426e12ccedd3e6945d72c.zip |
Bug 419442 – [Model-Editor] Creating a Command-Parameter without
entering a Name causes a NPE on startup of the application
Set the name of a new command to a generated default value
instead of leaving it null. The CommandParameterEditor will
display a warning if the CommandParameter Name or the
CommandParameter ID is empty.
Change-Id: Ib327e2e6c9ca5be24ed5edfbe5c2f3d055ebae4f
Signed-off-by: René Brandstetter <Rene.Brandstetter@gmx.net>
4 files changed, 25 insertions, 3 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java index 8a78ad12..0d4b8efe 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java @@ -79,6 +79,7 @@ public class Messages { public String CommandEditor_ParameterId; public String CommandEditor_Category; public String CommandEditor_AddCommandParameter; + public String CommandEditor_NewCommandParameter; public String DirectMenuItemEditor_Label; public String DirectMenuItemEditor_Description; @@ -642,4 +643,4 @@ public class Messages { public String ModelEditor_ExtractFragment_NoParentId; public String KeyBindingEditor_SequenceLowercase; public String ModelTooling_CommandId_tooltip; -}
\ No newline at end of file +} diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties index 2395d438..3dceed69 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties @@ -78,6 +78,7 @@ CommandEditor_ParameterOptional_No=no CommandEditor_ParameterId=ID CommandEditor_Category=Category CommandEditor_AddCommandParameter=Command Parameter +CommandEditor_NewCommandParameter=Command Parameter {0} DirectMenuItemEditor_Label=DirectMenuItem DirectMenuItemEditor_Description=DirectMenuItem bla bla bla diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/CommandEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/CommandEditor.java index bcbe9b6d..289ba0c8 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/CommandEditor.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/CommandEditor.java @@ -10,6 +10,7 @@ ******************************************************************************/ package org.eclipse.e4.tools.emf.ui.internal.common.component; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; import javax.annotation.PostConstruct; @@ -65,6 +66,7 @@ public class CommandEditor extends AbstractComponentEditor { private EMFDataBindingContext context; private EStackLayout stackLayout; private List<Action> actions = new ArrayList<Action>(); + private MessageFormat newCommandParameterName; private IEMFEditListProperty COMMAND__PARAMETERS = EMFEditProperties.list(getEditingDomain(), CommandsPackageImpl.Literals.COMMAND__PARAMETERS); @@ -81,6 +83,8 @@ public class CommandEditor extends AbstractComponentEditor { handleAddCommandParameter(); } }); + + newCommandParameterName = new MessageFormat(Messages.CommandEditor_NewCommandParameter); } @Override @@ -327,6 +331,7 @@ public class CommandEditor extends AbstractComponentEditor { protected void handleAddCommandParameter() { MCommandParameter param = MCommandsFactory.INSTANCE.createCommandParameter(); setElementId(param); + param.setName(newCommandParameterName.format(new Object[] { getParameterCount() })); Command cmd = AddCommand.create(getEditingDomain(), getMaster().getValue(), CommandsPackageImpl.Literals.COMMAND__PARAMETERS, param); @@ -342,4 +347,19 @@ public class CommandEditor extends AbstractComponentEditor { l.addAll(actions); return l; } + + /** + * Returns the current amount of {@link MCommandParameter}s the edited + * {@link MCommand} has. + * + * @return the amount of {@link MCommandParameter}s of the edited + * {@link MCommand} + */ + private int getParameterCount() { + // getChildList() will always create a new IObservableList and + // this method uses the normal EMF way to retrieve the count manually. + EObject command = (EObject) getMaster().getValue(); + List<?> commandParameters = (List<?>) command.eGet(CommandsPackageImpl.Literals.COMMAND__PARAMETERS); + return commandParameters.size(); + } } diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/CommandParameterEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/CommandParameterEditor.java index ffea0eb2..0422276e 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/CommandParameterEditor.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/CommandParameterEditor.java @@ -134,8 +134,8 @@ public class CommandParameterEditor extends AbstractComponentEditor { return folder; } - ControlFactory.createTextField(parent, Messages.ModelTooling_Common_Id, master, context, textProp, EMFEditProperties.value(getEditingDomain(), ApplicationPackageImpl.Literals.APPLICATION_ELEMENT__ELEMENT_ID)); - ControlFactory.createTextField(parent, Messages.CommandParameterEditor_Name, master, context, textProp, EMFEditProperties.value(getEditingDomain(), CommandsPackageImpl.Literals.COMMAND_PARAMETER__NAME)); + ControlFactory.createTextField(parent, Messages.ModelTooling_Common_Id, master, context, textProp, EMFEditProperties.value(getEditingDomain(), ApplicationPackageImpl.Literals.APPLICATION_ELEMENT__ELEMENT_ID), Messages.ModelTooling_Empty_Warning); + ControlFactory.createTextField(parent, Messages.CommandParameterEditor_Name, master, context, textProp, EMFEditProperties.value(getEditingDomain(), CommandsPackageImpl.Literals.COMMAND_PARAMETER__NAME), Messages.ModelTooling_Empty_Warning); ControlFactory.createTextField(parent, Messages.CommandParameterEditor_TypeId, master, context, textProp, EMFEditProperties.value(getEditingDomain(), CommandsPackageImpl.Literals.COMMAND_PARAMETER__TYPE_ID)); { |