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
.UIFormXmlConstants
;
20 import com
.intellij
.uiDesigner
.XmlWriter
;
21 import com
.intellij
.uiDesigner
.propertyInspector
.IntrospectedProperty
;
22 import com
.intellij
.uiDesigner
.propertyInspector
.PropertyEditor
;
23 import com
.intellij
.uiDesigner
.propertyInspector
.PropertyRenderer
;
24 import com
.intellij
.uiDesigner
.propertyInspector
.editors
.ListModelEditor
;
25 import com
.intellij
.uiDesigner
.propertyInspector
.renderers
.LabelPropertyRenderer
;
26 import com
.intellij
.uiDesigner
.radComponents
.RadComponent
;
27 import com
.intellij
.uiDesigner
.snapShooter
.SnapshotContext
;
28 import org
.jetbrains
.annotations
.NonNls
;
29 import org
.jetbrains
.annotations
.NotNull
;
32 import java
.lang
.reflect
.Method
;
37 public class IntroListModelProperty
extends IntrospectedProperty
<String
[]> {
38 private LabelPropertyRenderer
<String
[]> myRenderer
;
39 private ListModelEditor myEditor
;
40 @NonNls private static final String CLIENT_PROPERTY_KEY_PREFIX
= "IntroListModelProperty_";
42 public IntroListModelProperty(final String name
, final Method readMethod
, final Method writeMethod
, final boolean storeAsClient
) {
43 super(name
, readMethod
, writeMethod
, storeAsClient
);
46 public void write(final String
[] value
, final XmlWriter writer
) {
47 for(String s
: value
) {
48 writer
.startElement(UIFormXmlConstants
.ELEMENT_ITEM
);
49 writer
.addAttribute(UIFormXmlConstants
.ATTRIBUTE_VALUE
, s
);
55 public PropertyRenderer
<String
[]> getRenderer() {
56 if (myRenderer
== null) {
57 myRenderer
= new MyRenderer();
62 public PropertyEditor
<String
[]> getEditor() {
63 if (myEditor
== null) {
64 myEditor
= new ListModelEditor(getName());
69 @Override public String
[] getValue(final RadComponent component
) {
70 final String
[] strings
= (String
[])component
.getDelegee().getClientProperty(CLIENT_PROPERTY_KEY_PREFIX
+ getName());
71 if (strings
== null) {
77 @Override protected void setValueImpl(final RadComponent component
, final String
[] value
) throws Exception
{
78 component
.getDelegee().putClientProperty(CLIENT_PROPERTY_KEY_PREFIX
+ getName(), value
);
79 DefaultComboBoxModel model
= new DefaultComboBoxModel();
80 for(String s
: value
) {
83 invokeSetter(component
, model
);
87 public void importSnapshotValue(final SnapshotContext context
, final JComponent component
, final RadComponent radComponent
) {
90 listModel
= (ListModel
)myReadMethod
.invoke(component
, EMPTY_OBJECT_ARRAY
);
95 if (listModel
== null || listModel
.getSize() == 0) return;
96 String
[] values
= new String
[listModel
.getSize()];
97 for(int i
=0; i
<listModel
.getSize(); i
++) {
98 final Object value
= listModel
.getElementAt(i
);
99 if (!(value
instanceof String
)) {
102 values
[i
] = (String
) value
;
105 setValue(radComponent
, values
);
107 catch (Exception e
) {
112 private static class MyRenderer
extends LabelPropertyRenderer
<String
[]> {
113 @Override protected void customize(final String
[] value
) {
114 setText(ListModelEditor
.listValueToString(value
));