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
.refactoring
.ui
;
18 import com
.intellij
.codeInsight
.daemon
.impl
.JavaReferenceImporter
;
19 import com
.intellij
.openapi
.editor
.Document
;
20 import com
.intellij
.openapi
.editor
.Editor
;
21 import com
.intellij
.openapi
.fileTypes
.StdFileTypes
;
22 import com
.intellij
.openapi
.project
.Project
;
23 import com
.intellij
.psi
.PsiCodeFragment
;
24 import com
.intellij
.psi
.PsiDocumentManager
;
25 import com
.intellij
.ui
.EditorTextField
;
28 import javax
.swing
.table
.TableCellEditor
;
34 public class CodeFragmentTableCellEditor
extends AbstractCellEditor
implements TableCellEditor
{
35 private Document myDocument
;
36 protected PsiCodeFragment myCodeFragment
;
37 private final Project myProject
;
38 private EditorTextField myEditorTextField
;
40 public CodeFragmentTableCellEditor(final Project project
) {
44 public Component
getTableCellEditorComponent(JTable table
, Object value
, boolean isSelected
, int row
, int column
) {
45 myCodeFragment
= (PsiCodeFragment
)value
;
47 myDocument
= PsiDocumentManager
.getInstance(myProject
).getDocument(myCodeFragment
);
48 myEditorTextField
= new EditorTextField(myDocument
, myProject
, StdFileTypes
.JAVA
) {
49 protected boolean shouldHaveBorder() {
53 return myEditorTextField
;
56 public PsiCodeFragment
getCellEditorValue() {
57 return myCodeFragment
;
60 public boolean stopCellEditing() {
61 final Editor editor
= myEditorTextField
.getEditor();
63 JavaReferenceImporter
.autoImportReferenceAtCursor(editor
, myCodeFragment
, true);
65 super.stopCellEditing();
66 PsiDocumentManager
.getInstance(myProject
).commitDocument(myDocument
);