update copyright
[fedora-idea.git] / plugins / ui-designer / src / com / intellij / uiDesigner / binding / ChangeBoundFieldTypeFix.java
blob6462cf499d5cd15e154b394e77660de29cd4ff45
1 /*
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;
30 /**
31 * @author Eugene Zhuravlev
32 * Date: Jun 15, 2005
34 public class ChangeBoundFieldTypeFix implements IntentionAction {
35 private final PsiField myField;
36 private final PsiType myTypeToSet;
38 public ChangeBoundFieldTypeFix(PsiField field, PsiType typeToSet) {
39 myField = field;
40 myTypeToSet = typeToSet;
43 @NotNull
44 public String getText() {
45 return QuickFixBundle.message("uidesigner.change.bound.field.type");
48 @NotNull
49 public String getFamilyName() {
50 return getText();
53 public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
54 return true;
57 public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
58 CommandProcessor.getInstance().executeCommand(myField.getProject(), new Runnable() {
59 public void run() {
60 try {
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(){
66 public void run() {
67 Messages.showErrorDialog(myField.getProject(),
68 QuickFixBundle.message("cannot.change.field.exception", myField.getName(), e.getLocalizedMessage()),
69 CommonBundle.getErrorTitle());
71 });
74 }, getText(), null);
77 public boolean startInWriteAction() {
78 return true;