/** * Returns whether the provided value is compatible with this parameter * type. An object is compatible with a parameter type if the object is an * instance of the class defined as the parameter's type class. * * @param value * an object to check for compatibility with this parameter type; * may be <code>null</code>. * @return <code>true</code> if the value is compatible with this type, * <code>false</code> otherwise * @throws NotDefinedException * if the parameter type is not currently defined */ public boolean isCompatible(Object value) throws NotDefinedException { if (!isDefined()) { throw new NotDefinedException( "Cannot use isCompatible() with an undefined ParameterType"); //$NON-NLS-1$ } return isInstanceOf(value, type); }
/** * Gets the command {@link ParameterType} with the given identifier. If no * such command parameter type currently exists, then the command parameter * type will be created (but will be undefined). * * @param parameterTypeId * The identifier to find; must not be <code>null</code> and * must not be zero-length. * @return The {@link ParameterType} with the given identifier; this value * will never be <code>null</code>, but it might be undefined. * @since 3.2 */ public ParameterType getParameterType(final String parameterTypeId) { checkId(parameterTypeId); ParameterType parameterType = parameterTypesById.get(parameterTypeId); if (parameterType == null) { parameterType = new ParameterType(parameterTypeId); parameterTypesById.put(parameterTypeId, parameterType); parameterType.addListener(this); } return parameterType; }
/** * Adds a listener to this parameter type that will be notified when its * state changes. * * @param listener * The listener to be added; must not be <code>null</code>. */ public final void addListener(final IParameterTypeListener listener) { addListenerObject(listener); }
/** * Notifies all listeners that this parameter type has changed. This sends * the given event to all of the listeners, if any. * * @param event * The event to send to the listeners; must not be * <code>null</code>. */ private final void fireParameterTypeChanged(final ParameterTypeEvent event) { if (event == null) { throw new NullPointerException( "Cannot send a null event to listeners."); //$NON-NLS-1$ } if (!isListenerAttached()) { return; } final Object[] listeners = getListeners(); for (int i = 0; i < listeners.length; i++) { final IParameterTypeListener listener = (IParameterTypeListener) listeners[i]; listener.parameterTypeChanged(event); } }
/** * Convert the parameter's value according to it's type. * * @param command * @param parameterId * @param value * @return converted value * @see org.eclipse.e4.ui.model.application.commands.MCommandParameter#getTypeId() */ private Object convertParameterValue(Command command, String parameterId, String value) { try { ParameterType parameterType = command.getParameterType(parameterId); if (parameterType != null) { AbstractParameterValueConverter valueConverter = parameterType.getValueConverter(); if (valueConverter != null) { return valueConverter.convertToObject(value); } } } catch (NotDefinedException e) { } catch (ParameterValueConversionException e) { } return value; }
/** * {@inheritDoc} * * @since 3.2 */ @Override public final void parameterTypeChanged(final ParameterTypeEvent parameterTypeEvent) { if (parameterTypeEvent.isDefinedChanged()) { final ParameterType parameterType = parameterTypeEvent.getParameterType(); final String parameterTypeId = parameterType.getId(); final boolean parameterTypeIdAdded = parameterType.isDefined(); if (parameterTypeIdAdded) { definedParameterTypeIds.add(parameterTypeId); } else { definedParameterTypeIds.remove(parameterTypeId); } fireCommandManagerChanged(new CommandManagerEvent(this, parameterTypeId, parameterTypeIdAdded, true)); } }
/** * Makes this parameter type become undefined. Notification is sent to all * listeners. */ @Override public final void undefine() { string = null; final boolean definedChanged = defined; defined = false; type = null; parameterTypeConverter = null; fireParameterTypeChanged(new ParameterTypeEvent(this, definedChanged)); }
/** * Returns the value converter associated with this parameter, if any. * * @return The parameter value converter, or <code>null</code> if there is * no value converter for this parameter. * @throws NotDefinedException * if the parameter type is not currently defined */ public final AbstractParameterValueConverter getValueConverter() throws NotDefinedException { if (!isDefined()) { throw new NotDefinedException( "Cannot use getValueConverter() with an undefined ParameterType"); //$NON-NLS-1$ } return parameterTypeConverter; }
ParameterType parmType = cmd.getParameterType(cmdParm.getId()); if (parmType != null) { parmModel.setTypeId(parmType.getId());
} else { AbstractParameterValueConverter valueConverter = parameterType .getValueConverter(); if (valueConverter != null) { String val = valueConverter.convertToString(entry.getValue());
/** * {@inheritDoc} * * @since 3.2 */ @Override public final void parameterTypeChanged(final ParameterTypeEvent parameterTypeEvent) { if (parameterTypeEvent.isDefinedChanged()) { final ParameterType parameterType = parameterTypeEvent.getParameterType(); final String parameterTypeId = parameterType.getId(); final boolean parameterTypeIdAdded = parameterType.isDefined(); if (parameterTypeIdAdded) { definedParameterTypeIds.add(parameterTypeId); } else { definedParameterTypeIds.remove(parameterTypeId); } fireCommandManagerChanged(new CommandManagerEvent(this, parameterTypeId, parameterTypeIdAdded, true)); } }
/** * Notifies all listeners that this parameter type has changed. This sends * the given event to all of the listeners, if any. * * @param event * The event to send to the listeners; must not be * <code>null</code>. */ private final void fireParameterTypeChanged(final ParameterTypeEvent event) { if (event == null) { throw new NullPointerException( "Cannot send a null event to listeners."); //$NON-NLS-1$ } if (!isListenerAttached()) { return; } for (Object listener : getListeners()) { final IParameterTypeListener parameterTypeListener = (IParameterTypeListener) listener; parameterTypeListener.parameterTypeChanged(event); } }
/** * Makes this parameter type become undefined. Notification is sent to all * listeners. */ @Override public final void undefine() { string = null; final boolean definedChanged = defined; defined = false; type = null; parameterTypeConverter = null; fireParameterTypeChanged(new ParameterTypeEvent(this, definedChanged)); }
/** * Returns the value converter associated with this parameter, if any. * * @return The parameter value converter, or <code>null</code> if there is * no value converter for this parameter. * @throws NotDefinedException * if the parameter type is not currently defined */ public final AbstractParameterValueConverter getValueConverter() throws NotDefinedException { if (!isDefined()) { throw new NotDefinedException( "Cannot use getValueConverter() with an undefined ParameterType"); //$NON-NLS-1$ } return parameterTypeConverter; }
} else { AbstractParameterValueConverter valueConverter = parameterType .getValueConverter(); if (valueConverter != null) { String val = valueConverter.convertToString(entry.getValue());
/** * {@inheritDoc} * * @since 3.2 */ @Override public void parameterTypeChanged(final ParameterTypeEvent parameterTypeEvent) { if (parameterTypeEvent.isDefinedChanged()) { final ParameterType parameterType = parameterTypeEvent.getParameterType(); final String parameterTypeId = parameterType.getId(); final boolean parameterTypeIdAdded = parameterType.isDefined(); if (parameterTypeIdAdded) { definedParameterTypeIds.add(parameterTypeId); } else { definedParameterTypeIds.remove(parameterTypeId); } fireCommandManagerChanged(new CommandManagerEvent(this, parameterTypeId, parameterTypeIdAdded, true)); } }
/** * Returns whether the provided value is compatible with this parameter * type. An object is compatible with a parameter type if the object is an * instance of the class defined as the parameter's type class. * * @param value * an object to check for compatibility with this parameter type; * may be <code>null</code>. * @return <code>true</code> if the value is compatible with this type, * <code>false</code> otherwise * @throws NotDefinedException * if the parameter type is not currently defined */ public boolean isCompatible(Object value) throws NotDefinedException { if (!isDefined()) { throw new NotDefinedException( "Cannot use isCompatible() with an undefined ParameterType"); //$NON-NLS-1$ } return isInstanceOf(value, type); }
/** * Notifies all listeners that this parameter type has changed. This sends * the given event to all of the listeners, if any. * * @param event * The event to send to the listeners; must not be * <code>null</code>. */ private final void fireParameterTypeChanged(final ParameterTypeEvent event) { if (event == null) { throw new NullPointerException( "Cannot send a null event to listeners."); //$NON-NLS-1$ } if (!isListenerAttached()) { return; } final Object[] listeners = getListeners(); for (int i = 0; i < listeners.length; i++) { final IParameterTypeListener listener = (IParameterTypeListener) listeners[i]; listener.parameterTypeChanged(event); } }
/** * Gets the command {@link ParameterType} with the given identifier. If no * such command parameter type currently exists, then the command parameter * type will be created (but will be undefined). * * @param parameterTypeId * The identifier to find; must not be <code>null</code> and * must not be zero-length. * @return The {@link ParameterType} with the given identifier; this value * will never be <code>null</code>, but it might be undefined. * @since 3.2 */ public final ParameterType getParameterType(final String parameterTypeId) { checkId(parameterTypeId); ParameterType parameterType = parameterTypesById.get(parameterTypeId); if (parameterType == null) { parameterType = new ParameterType(parameterTypeId); parameterTypesById.put(parameterTypeId, parameterType); parameterType.addListener(this); } return parameterType; }