function getConfigWidgetModeInternal()

in ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.directive.js [550:612]


        function getConfigWidgetModeInternal(item, val) {
            if (angular.element($document[0].activeElement).hasClass("form-control") && item.widgetMode) {
                // don't switch mode in mid-edit, e.g. if you are manually typing $brooklyn:component("x").config("y")
                // don't interrupt when the user has typed $brooklyn:component("x")!
                return item.widgetMode;
            }
            if (scope.state.config.codeModeActive[item.name] && item.widgetMode) {
                if (item.widgetMode.endsWith("-manual")) return item.widgetMode;
                return item.widgetMode+"-manual";
            }

            if (specEditor.isDsl(item.name)) {
                return scope.state.config.dslViewerManualOverride && scope.state.config.dslViewerManualOverride[item.name] ?
                    "dsl-manual" // causes default string editor
                    : "dsl-viewer";
            }

            if (!specEditor.defined(val)) val = scope.config[item.name];
            let type = baseType(item.type);

            // if actual value's type does not match declared type,
            // e.g. object is a map when declared type is object or string or something else,
            // we could render e.g. w map editor as a convenience;
            // but for now the logic is only based on the declared type

            if (type === 'java.lang.String') type = 'string';
            else if (type === 'java.lang.Boolean') type = 'boolean';
            else if (type === 'java.util.Map') type = 'map';
            else if (type === 'java.util.Set' || type === 'java.util.List' || type === 'java.util.Collection'
                || type==='list' || type==='set') type = 'array';
            else if (type === 'java.lang.Object') type = 'object';

            if (specEditor.defined(val)) {
                if (type === 'object') {
                    // object for anonymous keys; if contains an entity spec, use that editor.
                    // otherwise try as map (but if val is not object will revert in next block to map-manual, meaning string editor)
                    if (val.hasOwnProperty(REPLACED_DSL_ENTITYSPEC)) {
                        type = 'org.apache.brooklyn.api.entity.EntitySpec';
                    } else if (Array.isArray(val)) {
                        type = 'array';
                    } else if (typeof val==='object') {
                        type = 'map';
                    }
                }

                // override to use string editor if the editor doesn't support the value
                // (probably this is an error, though type-coercion might make it not so)
                if (type === 'boolean') {
                    if (typeof val !== type) return type + '-manual';  // causes default string editor
                } else if (type === 'map') {
                    if (typeof val !== 'object') return type + '-manual';  // causes default string editor
                } else if (type === 'array') {
                    if (!Array.isArray(val)) return type + '-manual';  // causes default string editor
                }
            }

            if (scope.state.config.codeModeActive[item.name]) {
                // code mode forces manual editor
                return type + '-manual';
            }

            return type;
        }