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
.util
.xml
.ui
;
18 import com
.intellij
.openapi
.util
.text
.StringUtil
;
19 import com
.intellij
.util
.ReflectionUtil
;
20 import com
.intellij
.util
.xml
.DomElement
;
21 import com
.intellij
.util
.xml
.GenericDomValue
;
22 import com
.intellij
.util
.xml
.reflect
.DomFixedChildDescription
;
23 import org
.jetbrains
.annotations
.NotNull
;
25 import javax
.swing
.table
.DefaultTableCellRenderer
;
26 import javax
.swing
.table
.TableCellEditor
;
27 import javax
.swing
.table
.TableCellRenderer
;
32 public class ChildGenericValueColumnInfo
<T
extends DomElement
> extends DomColumnInfo
<T
, String
> {
33 private final TableCellEditor myEditor
;
34 private final DomFixedChildDescription myChildDescription
;
36 public ChildGenericValueColumnInfo(final String name
,
37 @NotNull final DomFixedChildDescription description
,
38 final TableCellRenderer renderer
,
39 final TableCellEditor editor
) {
40 super(name
, renderer
);
42 myChildDescription
= description
;
45 public ChildGenericValueColumnInfo(final String name
, final DomFixedChildDescription description
, final TableCellEditor editor
) {
46 this(name
, description
, new DefaultTableCellRenderer(), editor
);
49 public boolean equals(final Object o
) {
50 if (this == o
) return true;
51 if (o
== null || getClass() != o
.getClass()) return false;
52 if (!super.equals(o
)) return false;
54 final ChildGenericValueColumnInfo that
= (ChildGenericValueColumnInfo
)o
;
56 if (!myChildDescription
.equals(that
.myChildDescription
)) return false;
61 public int hashCode() {
62 int result
= super.hashCode();
63 result
= 31 * result
+ myChildDescription
.hashCode();
67 public final TableCellEditor
getEditor(T value
) {
71 public final Class
<T
> getColumnClass() {
72 return (Class
<T
>)ReflectionUtil
.getRawType(myChildDescription
.getType());
75 public TableCellRenderer
getCustomizedRenderer(final T domElement
, final TableCellRenderer renderer
) {
76 assert domElement
.isValid();
77 return getErrorableCellRenderer(renderer
, domElement
);
80 public DefaultTableCellRenderer
getErrorableCellRenderer(final TableCellRenderer renderer
, final T domElement
) {
81 return new ErrorableTableCellRenderer
<GenericDomValue
>(getGenericValue(domElement
), renderer
, domElement
);
84 public void setValue(final T o
, final String aValue
) {
85 getGenericValue(o
).setStringValue(aValue
);
88 protected final GenericDomValue
getGenericValue(final T o
) {
89 return (GenericDomValue
)myChildDescription
.getValues(o
).get(0);
92 public final String
valueOf(T object
) {
93 if (!object
.isValid()) return null;
94 final String stringValue
= getGenericValue(object
).getStringValue();
95 return StringUtil
.isEmpty(stringValue
) ?
getEmptyValuePresentation(object
) : stringValue
;
98 protected final DomFixedChildDescription
getChildDescription() {
99 return myChildDescription
;
102 protected String
getEmptyValuePresentation(T object
) {