Search in sources :

Example 1 with IntegerProperty

use of com.xpn.xwiki.objects.IntegerProperty in project xwiki-platform by xwiki.

the class R73000XWIKI12277DataMigration method migrateProperty.

private void migrateProperty(StringProperty typeProperty, BaseObject object, Session session) throws HibernateException {
    // Create the new property value and assign it to the owning object.
    IntegerProperty terminalProperty = new IntegerProperty();
    int value = 1;
    if ("space".equals(typeProperty.getValue())) {
        value = 0;
    }
    terminalProperty.setValue(value);
    terminalProperty.setName("terminal");
    terminalProperty.setObject(object);
    // Save the new property.
    session.saveOrUpdate(terminalProperty);
    // Delete the old property.
    session.delete(typeProperty);
}
Also used : IntegerProperty(com.xpn.xwiki.objects.IntegerProperty)

Example 2 with IntegerProperty

use of com.xpn.xwiki.objects.IntegerProperty in project xwiki-platform by xwiki.

the class BooleanClass method displaySelectEdit.

public void displaySelectEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
    select select = new select(prefix + name, 1);
    select.setAttributeFilter(new XMLAttributeValueFilter());
    select.setName(prefix + name);
    select.setID(prefix + name);
    select.setDisabled(isDisabled());
    String String0 = getDisplayValue(context, 0);
    String String1 = getDisplayValue(context, 1);
    int nb1 = 1;
    int nb2 = 2;
    option[] options;
    if (getDefaultValue() == -1) {
        options = new option[] { new option("---", ""), new option(String1, "1"), new option(String0, "0") };
        options[0].addElement("---");
        options[1].addElement(XMLUtils.escape(String1));
        options[2].addElement(XMLUtils.escape(String0));
    } else {
        options = new option[] { new option(String1, "1"), new option(String0, "0") };
        options[0].addElement(XMLUtils.escape(String1));
        options[1].addElement(XMLUtils.escape(String0));
        nb1 = 0;
        nb2 = 1;
    }
    for (option option : options) {
        option.setAttributeFilter(new XMLAttributeValueFilter());
    }
    try {
        IntegerProperty prop = (IntegerProperty) object.safeget(name);
        Integer ivalue = (prop == null) ? null : (Integer) prop.getValue();
        if (ivalue != null) {
            int value = ivalue.intValue();
            if (value == 1) {
                options[nb1].setSelected(true);
            } else if (value == 0) {
                options[nb2].setSelected(true);
            }
        } else {
            int value = getDefaultValue();
            if (value == 1) {
                options[nb1].setSelected(true);
            } else if (value == 0) {
                options[nb2].setSelected(true);
            } else if (value == -1) {
                options[0].setSelected(true);
            }
        }
    } catch (Exception e) {
        // This should not happen
        e.printStackTrace();
    }
    select.addElement(options);
    buffer.append(select.toString());
}
Also used : IntegerProperty(com.xpn.xwiki.objects.IntegerProperty) org.apache.ecs.xhtml.select(org.apache.ecs.xhtml.select) XMLAttributeValueFilter(com.xpn.xwiki.internal.xml.XMLAttributeValueFilter) org.apache.ecs.xhtml.option(org.apache.ecs.xhtml.option)

Example 3 with IntegerProperty

use of com.xpn.xwiki.objects.IntegerProperty in project xwiki-platform by xwiki.

the class BooleanClass method displayView.

@Override
public void displayView(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
    IntegerProperty prop = (IntegerProperty) object.safeget(name);
    if (prop == null) {
        return;
    }
    Integer iValue = (Integer) prop.getValue();
    if (iValue != null) {
        int value = iValue.intValue();
        buffer.append(getDisplayValue(context, value));
    }
}
Also used : IntegerProperty(com.xpn.xwiki.objects.IntegerProperty)

Example 4 with IntegerProperty

use of com.xpn.xwiki.objects.IntegerProperty in project xwiki-platform by xwiki.

the class BooleanClass method displayRadioEdit.

public void displayRadioEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
    String StringNone = getDisplayValue(context, 2);
    String StringTrue = getDisplayValue(context, 1);
    String StringFalse = getDisplayValue(context, 0);
    div[] inputs;
    input radioNone = new input(input.radio, prefix + name, "");
    radioNone.setAttributeFilter(new XMLAttributeValueFilter());
    input radioTrue = new input(input.radio, prefix + name, "1");
    radioTrue.setAttributeFilter(new XMLAttributeValueFilter());
    input radioFalse = new input(input.radio, prefix + name, "0");
    radioFalse.setAttributeFilter(new XMLAttributeValueFilter());
    radioNone.setDisabled(isDisabled());
    radioTrue.setDisabled(isDisabled());
    radioFalse.setDisabled(isDisabled());
    label labelNone = new label();
    label labelTrue = new label();
    label labelFalse = new label();
    div divNone = new div();
    div divTrue = new div();
    div divFalse = new div();
    labelNone.addElement(radioNone);
    labelNone.addElement(StringNone);
    divNone.addElement(labelNone);
    labelTrue.addElement(radioTrue);
    labelTrue.addElement(StringTrue);
    divTrue.addElement(labelTrue);
    labelFalse.addElement(radioFalse);
    labelFalse.addElement(StringFalse);
    divFalse.addElement(labelFalse);
    radioNone.setID(prefix + name + "_none");
    labelNone.setFor(prefix + name + "_none");
    radioTrue.setID(prefix + name);
    labelTrue.setFor(prefix + name);
    radioFalse.setID(prefix + name + "_false");
    labelFalse.setFor(prefix + name + "_false");
    if (getDefaultValue() == -1) {
        inputs = new div[] { divNone, divTrue, divFalse };
    } else {
        inputs = new div[] { divTrue, divFalse };
    }
    try {
        IntegerProperty prop = (IntegerProperty) object.safeget(name);
        Integer ivalue = (prop == null) ? null : (Integer) prop.getValue();
        if (ivalue != null) {
            int value = ivalue.intValue();
            if (value == 1) {
                radioTrue.setChecked(true);
            } else if (value == 0) {
                radioFalse.setChecked(true);
            }
        } else {
            int value = getDefaultValue();
            if (value == 1) {
                radioTrue.setChecked(true);
            } else if (value == 0) {
                radioFalse.setChecked(true);
            } else if (value == -1) {
                radioNone.setChecked(true);
            }
        }
    } catch (Exception e) {
        // This should not happen
        e.printStackTrace();
    }
    for (div input : inputs) {
        buffer.append(input.toString());
    }
}
Also used : org.apache.ecs.xhtml.div(org.apache.ecs.xhtml.div) org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) IntegerProperty(com.xpn.xwiki.objects.IntegerProperty) XMLAttributeValueFilter(com.xpn.xwiki.internal.xml.XMLAttributeValueFilter) org.apache.ecs.xhtml.label(org.apache.ecs.xhtml.label)

Example 5 with IntegerProperty

use of com.xpn.xwiki.objects.IntegerProperty in project xwiki-platform by xwiki.

the class PropertyConverterTest method doubleToInteger.

/**
 * @see XWIKI-8649: Error when changing the number type of a field from an application
 */
@Test
public void doubleToInteger() throws Exception {
    // The number property whose type has changed from Double to Integer.
    NumberClass numberClass = mock(NumberClass.class);
    IntegerProperty integerProperty = mock(IntegerProperty.class);
    when(numberClass.newProperty()).thenReturn(integerProperty);
    when(numberClass.getNumberType()).thenReturn("integer");
    DoubleProperty doubleProperty = mock(DoubleProperty.class);
    when(doubleProperty.getValue()).thenReturn(3.5);
    assertEquals(integerProperty, this.mocker.getComponentUnderTest().convertProperty(doubleProperty, numberClass));
    verify(integerProperty).setValue(3);
}
Also used : IntegerProperty(com.xpn.xwiki.objects.IntegerProperty) NumberClass(com.xpn.xwiki.objects.classes.NumberClass) DoubleProperty(com.xpn.xwiki.objects.DoubleProperty) Test(org.junit.Test)

Aggregations

IntegerProperty (com.xpn.xwiki.objects.IntegerProperty)10 XMLAttributeValueFilter (com.xpn.xwiki.internal.xml.XMLAttributeValueFilter)3 Test (org.junit.Test)3 BaseProperty (com.xpn.xwiki.objects.BaseProperty)2 DoubleProperty (com.xpn.xwiki.objects.DoubleProperty)2 NumberClass (com.xpn.xwiki.objects.classes.NumberClass)2 org.apache.ecs.xhtml.input (org.apache.ecs.xhtml.input)2 BaseObject (com.xpn.xwiki.objects.BaseObject)1 FloatProperty (com.xpn.xwiki.objects.FloatProperty)1 LongProperty (com.xpn.xwiki.objects.LongProperty)1 StringProperty (com.xpn.xwiki.objects.StringProperty)1 org.apache.ecs.xhtml.div (org.apache.ecs.xhtml.div)1 org.apache.ecs.xhtml.label (org.apache.ecs.xhtml.label)1 org.apache.ecs.xhtml.option (org.apache.ecs.xhtml.option)1 org.apache.ecs.xhtml.select (org.apache.ecs.xhtml.select)1 ContextualLocalizationManager (org.xwiki.localization.ContextualLocalizationManager)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1