2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com
.intellij
.uiDesigner
.propertyInspector
.properties
;
19 import com
.intellij
.uiDesigner
.propertyInspector
.Property
;
20 import com
.intellij
.uiDesigner
.propertyInspector
.PropertyEditor
;
21 import com
.intellij
.uiDesigner
.propertyInspector
.PropertyRenderer
;
22 import com
.intellij
.uiDesigner
.propertyInspector
.editors
.IntEditor
;
23 import com
.intellij
.uiDesigner
.propertyInspector
.renderers
.LabelPropertyRenderer
;
24 import com
.intellij
.uiDesigner
.radComponents
.RadComponent
;
25 import com
.intellij
.util
.ArrayUtil
;
26 import org
.jetbrains
.annotations
.NonNls
;
27 import org
.jetbrains
.annotations
.NotNull
;
29 import java
.lang
.reflect
.Method
;
31 public final class IntFieldProperty
extends Property
<RadComponent
, Integer
> {
32 private final LabelPropertyRenderer
<Integer
> myRenderer
;
33 private final IntEditor myEditor
;
34 @NotNull private final Property myParent
;
35 private final String myFieldName
;
36 private final Object myTemplateValue
;
37 @NonNls private static final String METHOD_CLONE
= "clone";
39 public IntFieldProperty(@NotNull final Property parent
, @NonNls final String fieldName
, final int lowBoundary
, final Object templateValue
) {
40 super(parent
, fieldName
);
42 myFieldName
= fieldName
;
43 myTemplateValue
= templateValue
;
44 myRenderer
= new LabelPropertyRenderer
<Integer
>();
45 myEditor
= new IntEditor(lowBoundary
);
48 public Integer
getValue(final RadComponent component
) {
49 //noinspection unchecked
50 final Object parentValue
= myParent
.getValue(component
);
51 if (parentValue
== null) return 0;
53 return parentValue
.getClass().getField(myFieldName
).getInt(parentValue
);
56 throw new RuntimeException(e
);
60 protected void setValueImpl(final RadComponent component
,final Integer value
) throws Exception
{
61 //noinspection unchecked
62 Object parentValue
= myParent
.getValue(component
);
63 if (parentValue
== null) {
64 parentValue
= myTemplateValue
;
67 final Method method
= parentValue
.getClass().getMethod(METHOD_CLONE
, ArrayUtil
.EMPTY_CLASS_ARRAY
);
68 parentValue
= method
.invoke(parentValue
);
70 parentValue
.getClass().getField(myFieldName
).setInt(parentValue
, value
.intValue());
71 //noinspection unchecked
72 myParent
.setValue(component
, parentValue
);
76 public PropertyRenderer
<Integer
> getRenderer() {
80 public PropertyEditor
<Integer
> getEditor() {