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
.codeInsight
.generation
.ui
;
18 import com
.intellij
.openapi
.project
.Project
;
19 import com
.intellij
.openapi
.ui
.DialogWrapper
;
20 import com
.intellij
.psi
.PsiField
;
21 import com
.intellij
.psi
.PsiNamedElement
;
22 import com
.intellij
.psi
.PsiSubstitutor
;
23 import com
.intellij
.psi
.util
.PsiFormatUtil
;
27 import java
.awt
.event
.MouseAdapter
;
28 import java
.awt
.event
.MouseEvent
;
33 public class SimpleFieldChooser
extends DialogWrapper
{
34 private final PsiField
[] myFields
;
37 public SimpleFieldChooser(PsiField
[] members
, Project project
) {
43 protected JComponent
createCenterPanel() {
44 final DefaultListModel model
= new DefaultListModel ();
45 for (PsiField member
: myFields
) {
46 model
.addElement(member
);
48 myList
= new JList(model
);
49 myList
.setCellRenderer(new MyListCellRenderer());
50 myList
.addMouseListener(
52 public void mouseClicked(MouseEvent e
) {
53 if (e
.getClickCount() == 2) {
54 if (myList
.getSelectedValues().length
> 0) {
62 myList
.setPreferredSize(new Dimension(300, 400));
66 public Object
[] getSelectedElements() {
67 return myList
.getSelectedValues();
70 private class MyListCellRenderer
extends DefaultListCellRenderer
{
71 public Component
getListCellRendererComponent(JList list
, Object value
, int index
, boolean isSelected
, boolean cellHasFocus
) {
73 super.getListCellRendererComponent(list
, value
, index
, isSelected
, cellHasFocus
);
74 if (value
instanceof PsiField
) {
75 PsiField field
= (PsiField
)value
;
76 icon
= field
.getIcon(0);
77 final String text
= PsiFormatUtil
.formatVariable(field
, PsiFormatUtil
.SHOW_NAME
| PsiFormatUtil
.SHOW_TYPE
, PsiSubstitutor
.EMPTY
);