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
.editorActions
;
18 import com
.intellij
.CommonBundle
;
19 import com
.intellij
.codeInsight
.CodeInsightBundle
;
20 import com
.intellij
.ide
.util
.FQNameCellRenderer
;
21 import com
.intellij
.openapi
.project
.Project
;
22 import com
.intellij
.openapi
.ui
.DialogWrapper
;
23 import com
.intellij
.openapi
.ui
.VerticalFlowLayout
;
24 import com
.intellij
.psi
.PsiClass
;
29 class RestoreReferencesDialog
extends DialogWrapper
{
30 private final Object
[] myNamedElements
;
32 private Object
[] mySelectedElements
= PsiClass
.EMPTY_ARRAY
;
33 private boolean myContainsClassesOnly
= true;
35 public RestoreReferencesDialog(final Project project
, final Object
[] elements
) {
37 myNamedElements
= elements
;
38 for (Object element
: elements
) {
39 if (!(element
instanceof PsiClass
)) {
40 myContainsClassesOnly
= false;
44 if (myContainsClassesOnly
) {
45 setTitle(CodeInsightBundle
.message("dialog.import.on.paste.title"));
48 setTitle(CodeInsightBundle
.message("dialog.import.on.paste.title2"));
52 myList
.setSelectionInterval(0, myNamedElements
.length
- 1);
55 protected void doOKAction() {
56 Object
[] values
= myList
.getSelectedValues();
57 mySelectedElements
= new Object
[values
.length
];
58 System
.arraycopy(values
, 0, mySelectedElements
, 0, values
.length
);
62 protected JComponent
createCenterPanel() {
63 final JPanel panel
= new JPanel(new BorderLayout());
64 myList
= new JList(myNamedElements
);
65 myList
.setCellRenderer(new FQNameCellRenderer());
66 myList
.setBorder(BorderFactory
.createEtchedBorder());
67 panel
.add(new JScrollPane(myList
), BorderLayout
.CENTER
);
69 JTextArea area
= new JTextArea(myContainsClassesOnly ?
70 CodeInsightBundle
.message("dialog.paste.on.import.text") :
71 CodeInsightBundle
.message("dialog.paste.on.import.text2"));
72 area
.setEditable(false);
73 area
.setBackground(this.getContentPane().getBackground());
74 area
.setBorder(BorderFactory
.createEmptyBorder(5, 5, 5, 5));
75 panel
.add(area
, BorderLayout
.NORTH
);
77 final JPanel buttonPanel
= new JPanel(new VerticalFlowLayout());
78 final JButton okButton
= new JButton(CommonBundle
.getOkButtonText());
79 getRootPane().setDefaultButton(okButton
);
80 buttonPanel
.add(okButton
);
81 final JButton cancelButton
= new JButton(CommonBundle
.getCancelButtonText());
82 buttonPanel
.add(cancelButton
);
84 panel
.setPreferredSize(new Dimension(500, 400));
90 protected String
getDimensionServiceKey(){
91 return "#com.intellij.codeInsight.editorActions.RestoreReferencesDialog";
94 public Object
[] getSelectedElements(){
95 return mySelectedElements
;