name = "Toto",
global = true,
type = PropertyType.PROPERTY_SET,
+ property_set_name = "myset",
category = CoreProperties.CATEGORY_GENERAL),
@Property(
key = CoreProperties.PROJECT_LANGUAGE_PROPERTY,
* @since 3.3
*/
boolean multiValues() default false;
+
+ /**
+ * Name of the property set. Used only when type = <code>PropertyType.PROPERTY_SET</code>.
+ *
+ * @since 3.3
+ */
+ String property_set_name() default "";
}
private boolean onModule = false;
private boolean isGlobal = true;
private boolean multiValues;
+ private String property_set_name;
private PropertyDefinition(Property annotation) {
this.key = annotation.key();
this.type = fixType(annotation.key(), annotation.type());
this.options = annotation.options();
this.multiValues = annotation.multiValues();
+ this.property_set_name = annotation.property_set_name();
}
private static PropertyType fixType(String key, PropertyType type) {
public boolean isMultiValues() {
return multiValues;
}
+
+ /**
+ * @since 3.3
+ */
+ public String getProperty_set_name() {
+ return property_set_name;
+ }
}
assertThat(def.isOnProject()).isTrue();
assertThat(def.isOnModule()).isTrue();
assertThat(def.isMultiValues()).isTrue();
+ assertThat(def.getProperty_set_name()).isEmpty();
}
@Properties(@Property(key = "hello", name = "Hello", defaultValue = "world", description = "desc",
assertThat(def.isMultiValues()).isFalse();
}
+ @Properties(@Property(key = "hello", name = "Hello", type = PropertyType.PROPERTY_SET, property_set_name = "set1"))
+ static class WithPropertySet {
+ }
+
+ @Test
+ public void should_support_property_sets() {
+ Properties props = AnnotationUtils.getAnnotation(WithPropertySet.class, Properties.class);
+ Property prop = props.value()[0];
+
+ PropertyDefinition def = PropertyDefinition.create(prop);
+
+ assertThat(def.getType()).isEqualTo(PropertyType.PROPERTY_SET);
+ assertThat(def.getProperty_set_name()).isEqualTo("set1");
+ }
+
@Properties(@Property(key = "hello", name = "Hello"))
static class DefaultValues {
}
@Test
public void validate_single_select_list() {
- PropertyDefinition def = PropertyDefinition.create("foo", PropertyType.SINGLE_SELECT_LIST, new String[] {"de", "en"});
+ PropertyDefinition def = PropertyDefinition.create("foo", PropertyType.SINGLE_SELECT_LIST, new String[]{"de", "en"});
assertThat(def.validate(null).isValid()).isTrue();
assertThat(def.validate("").isValid()).isTrue();
def by_name(categories)
categories.sort_by { |category| category_name(category) }
end
+
+ def input_name(property)
+ h(property.key) + (property.multi_values ? '[]' : '')
+ end
+
+ def property_set_values(property)
+ PropertySet.findAll(property.property_set_name);
+ end
end
--- /dev/null
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2012 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# Sonar is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# Sonar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with {library}; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+#
+class PropertySet
+ def self.findAll(property_set_name)
+ [property_set_name + '1', property_set_name + '2']
+ end
+end
<% value = property_value(property) -%>
<% if property.multi_values -%>
<% value.each do |sub_value| -%>
- <%= render "settings/multi_value", :property => property, :value => sub_value -%>
+ <%= render "settings/multi_value", :property => property, :value => sub_value, :multi => true -%>
<% end -%>
<div class="template" style="display:none;">
- <%= render "settings/multi_value", :property => property, :value => nil -%>
+ <%= render "settings/multi_value", :property => property, :value => nil, :multi => true -%>
</div>
<button class="add_value"><%= message('settings.add') -%></button>
<br/>
<% else -%>
- <%= render "settings/type_#{property_type(property, value)}", :property => property, :value => value -%>
+ <%= render "settings/type_#{property_type(property, value)}", :property => property, :value => value, :multi => false -%>
<% end -%>
<% p = @updated_properties[property.key] if @updated_properties -%>
-<select name="<%= h property.getKey() -%>" id="input_<%= h property.getKey() -%>">
+<select name="<%= input_name(property) -%>" id="input_<%= h property.getKey() -%>">
<option value="" <%= 'selected' if value.blank? -%>><%= message('default') -%></option>
<option value="true" <%= 'selected' if value=='true' -%>><%= message('true') -%></option>
<option value="false" <%= 'selected' if value=='false' -%>><%= message('false') -%></option>
-<input type="text" name="<%= h property.getKey() -%>" value="<%= h value if value -%>" size="50" id="input_<%= h property.getKey() -%>"/>
\ No newline at end of file
+<input type="text" name="<%= input_name(property) -%>" value="<%= h value if value -%>" size="50" id="input_<%= h property.getKey() -%>"/>
\ No newline at end of file
-<input type="text" name="<%= h property.getKey() -%>" value="<%= h value if value -%>" size="50" id="input_<%= h property.getKey()-%>"/>
\ No newline at end of file
+<input type="text" name="<%= input_name(property) -%>" value="<%= h value if value -%>" size="50" id="input_<%= h property.getKey()-%>"/>
\ No newline at end of file
date = license.getExpirationDateAsString()
%>
<div class="width100">
- <textarea rows="6" name="<%= h property.getKey() -%>" id="input_<%= h property.getKey() -%>" style="float: left;width: 390px"><%= h value -%></textarea>
+ <textarea rows="6" name="<%= input_name(property) -%>" id="input_<%= h property.getKey() -%>" style="float: left;width: 390px"><%= h value -%></textarea>
<div style="margin-left: 400px">
<table>
-<select name="<%= h property.getKey() -%>" id="input_<%= h property.getKey() -%>">
+<select name="<%= input_name(property) -%>" id="input_<%= h property.getKey() -%>">
<option value=""><%= message('default') -%></option>
<%
metrics_per_domain={}
-<input type="password" name="<%= h property.getKey() -%>" value="<%= h value if value -%>" size="50" id="input_<%= h property.getKey() -%>"/>
\ No newline at end of file
+<input type="password" name="<%= input_name(property) -%>" value="<%= h value if value -%>" size="50" id="input_<%= h property.getKey() -%>"/>
\ No newline at end of file
-NOT IMPLEMENTED YET
\ No newline at end of file
+<select name="<%= input_name(property) -%>" id="input_<%= h property.key -%>">
+ <option value=""><%= message('default') -%></option>
+ <% property_set_values(property).each do |option| %>
+ <option value="<%= h option -%>" <%= 'selected' if value && value==option -%>><%= h option -%></option>
+ <% end %>
+ <option value="">New value...</option>
+</select>
-<input type="text" name="<%= h property.getKey() -%>" value="<%= h value if value -%>" size="50" id="input_<%= h property.getKey() -%>"/>
+<input type="text" name="<%= input_name(property) -%>" value="<%= h value if value -%>" size="50" id="input_<%= h property.getKey() -%>"/>
<%= link_to_function(image_tag('zoom.png'), "enlargeTextInput('#{property.getKey()}')", :class => 'nolink') -%>
\ No newline at end of file
-<select name="<%= h property.getKey() -%>" id="input_<%= h property.key-%>">
+<select name="<%= input_name(property) -%>" id="input_<%= h property.key-%>">
<option value=""><%= message('default') -%></option>
<% property.options.each do |option| %>
<option value="<%= h option -%>" <%= 'selected' if value && value==option -%>><%= h option -%></option>
-<input type="text" name="<%= h property.key -%>[]" value="<%= h value if value -%>" size="50" id="input_<%= property.key.parameterize -%>"/>
+<input type="text" name="<%= input_name(property) -%>" value="<%= h value if value -%>" size="50" id="input_<%= property.key.parameterize -%>"/>
<% unless property.multi_values -%>
<%= link_to_function(image_tag('zoom.png'), "enlargeTextInput('input_#{property.key.parameterize}')", :class => 'nolink') -%>
<% end -%>
-<textarea rows="5" cols="80" class="width100" name="<%= h property.getKey() -%>" id="input_<%= h property.getKey() -%>"><%= h value if value -%></textarea>
\ No newline at end of file
+<textarea rows="5" cols="80" class="width100" name="<%= input_name(property) -%>" id="input_<%= h property.getKey() -%>"><%= h value if value -%></textarea>
\ No newline at end of file