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
.binding
;
18 import com
.intellij
.CommonBundle
;
19 import com
.intellij
.codeInsight
.daemon
.QuickFixBundle
;
20 import com
.intellij
.codeInsight
.intention
.IntentionAction
;
21 import com
.intellij
.openapi
.application
.ApplicationManager
;
22 import com
.intellij
.openapi
.command
.CommandProcessor
;
23 import com
.intellij
.openapi
.editor
.Editor
;
24 import com
.intellij
.openapi
.project
.Project
;
25 import com
.intellij
.openapi
.ui
.Messages
;
26 import com
.intellij
.psi
.*;
27 import com
.intellij
.util
.IncorrectOperationException
;
28 import org
.jetbrains
.annotations
.NotNull
;
31 * @author Eugene Zhuravlev
34 public class ChangeBoundFieldTypeFix
implements IntentionAction
{
35 private final PsiField myField
;
36 private final PsiType myTypeToSet
;
38 public ChangeBoundFieldTypeFix(PsiField field
, PsiType typeToSet
) {
40 myTypeToSet
= typeToSet
;
44 public String
getText() {
45 return QuickFixBundle
.message("uidesigner.change.bound.field.type");
49 public String
getFamilyName() {
53 public boolean isAvailable(@NotNull Project project
, Editor editor
, PsiFile file
) {
57 public void invoke(@NotNull Project project
, Editor editor
, PsiFile file
) throws IncorrectOperationException
{
58 CommandProcessor
.getInstance().executeCommand(myField
.getProject(), new Runnable() {
61 final PsiManager manager
= myField
.getManager();
62 myField
.getTypeElement().replace(JavaPsiFacade
.getInstance(manager
.getProject()).getElementFactory().createTypeElement(myTypeToSet
));
64 catch (final IncorrectOperationException e
) {
65 ApplicationManager
.getApplication().invokeLater(new Runnable(){
67 Messages
.showErrorDialog(myField
.getProject(),
68 QuickFixBundle
.message("cannot.change.field.exception", myField
.getName(), e
.getLocalizedMessage()),
69 CommonBundle
.getErrorTitle());
77 public boolean startInWriteAction() {