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.
16 package com
.intellij
.uiDesigner
.propertyInspector
.properties
;
18 import com
.intellij
.openapi
.util
.Condition
;
19 import com
.intellij
.uiDesigner
.FormEditingUtil
;
20 import com
.intellij
.uiDesigner
.SwingProperties
;
21 import com
.intellij
.uiDesigner
.inspections
.FormInspectionUtil
;
22 import com
.intellij
.uiDesigner
.propertyInspector
.IntrospectedProperty
;
23 import com
.intellij
.uiDesigner
.propertyInspector
.PropertyEditor
;
24 import com
.intellij
.uiDesigner
.propertyInspector
.PropertyRenderer
;
25 import com
.intellij
.uiDesigner
.propertyInspector
.editors
.ComponentEditor
;
26 import com
.intellij
.uiDesigner
.propertyInspector
.renderers
.ComponentRenderer
;
27 import com
.intellij
.uiDesigner
.radComponents
.RadComponent
;
28 import com
.intellij
.uiDesigner
.radComponents
.RadRootContainer
;
29 import com
.intellij
.uiDesigner
.radComponents
.RadScrollPane
;
30 import com
.intellij
.uiDesigner
.snapShooter
.SnapshotContext
;
31 import org
.jetbrains
.annotations
.NonNls
;
32 import org
.jetbrains
.annotations
.NotNull
;
36 import java
.lang
.reflect
.Method
;
39 * The value of the property is the string ID of the referenced component.
42 public class IntroComponentProperty
extends IntrospectedProperty
<String
> {
43 private final ComponentRenderer myRenderer
= new ComponentRenderer();
44 private ComponentEditor myEditor
;
45 @NonNls private static final String CLIENT_PROPERTY_KEY_PREFIX
= "IntroComponentProperty_";
46 private final Class myPropertyType
;
47 private final Condition
<RadComponent
> myFilter
;
49 public IntroComponentProperty(String name
,
53 Condition
<RadComponent
> filter
,
54 final boolean storeAsClient
) {
55 super(name
, readMethod
, writeMethod
, storeAsClient
);
56 myPropertyType
= propertyType
;
60 @NotNull public PropertyRenderer
<String
> getRenderer() {
64 public PropertyEditor
<String
> getEditor() {
65 if (myEditor
== null) {
66 myEditor
= new ComponentEditor(myPropertyType
, myFilter
);
71 @Override public String
getValue(final RadComponent component
) {
72 return (String
) component
.getDelegee().getClientProperty(CLIENT_PROPERTY_KEY_PREFIX
+ getName());
75 @Override protected void setValueImpl(final RadComponent component
, final String value
) throws Exception
{
76 component
.getDelegee().putClientProperty(CLIENT_PROPERTY_KEY_PREFIX
+ getName(), value
);
77 if (getName().equals(SwingProperties
.LABEL_FOR
) && !component
.isLoadingProperties() && component
.getModule() != null) {
78 updateLabelForBinding(component
);
82 void updateLabelForBinding(final RadComponent component
) {
83 String value
= getValue(component
);
84 String text
= FormInspectionUtil
.getText(component
.getModule(), component
);
85 if (text
!= null && value
!= null) {
86 RadRootContainer root
= (RadRootContainer
) FormEditingUtil
.getRoot(component
);
88 RadComponent valueComponent
= (RadComponent
)FormEditingUtil
.findComponent(root
, value
);
89 if (valueComponent
!= null) {
90 if (valueComponent
instanceof RadScrollPane
&& ((RadScrollPane
) valueComponent
).getComponentCount() == 1) {
91 valueComponent
= ((RadScrollPane
) valueComponent
).getComponent(0);
93 BindingProperty
.checkCreateBindingFromText(valueComponent
, text
);
99 @Override public void resetValue(RadComponent component
) throws Exception
{
100 setValue(component
, null);
101 markTopmostModified(component
, false);
104 @Override public void importSnapshotValue(final SnapshotContext context
, final JComponent component
, final RadComponent radComponent
) {
107 value
= (Component
) myReadMethod
.invoke(component
, EMPTY_OBJECT_ARRAY
);
109 catch (Exception e
) {
112 if (value
!= null && value
instanceof JComponent
) {
113 context
.registerComponentProperty(component
, getName(), (JComponent
) value
);