public static void createBindingField(final GuiEditor editor, final RadComponent insertedComponent) { // Try to create field in the corresponding bound class final String classToBind = editor.getRootContainer().getClassToBind(); if (classToBind != null) { final PsiClass aClass = FormEditingUtil.findClassToBind(editor.getModule(), classToBind); if (aClass != null && aClass.findFieldByName(insertedComponent.getBinding(), true) == null) { if (!FileModificationService.getInstance().preparePsiElementForWrite(aClass)) { return; } ApplicationManager.getApplication().runWriteAction( new Runnable() { public void run() { CreateFieldFix.runImpl(editor.getProject(), editor.getRootContainer(), aClass, insertedComponent.getComponentClassName(), insertedComponent.getBinding(), false, // silently skip all errors (if any) null); } } ); } } }
public static void createBindingField(final GuiEditor editor, final RadComponent insertedComponent) { // Try to create field in the corresponding bound class final String classToBind = editor.getRootContainer().getClassToBind(); if(classToBind != null) { final PsiClass aClass = FormEditingUtil.findClassToBind(editor.getModule(), classToBind); if(aClass != null && aClass.findFieldByName(insertedComponent.getBinding(), true) == null) { if(!FileModificationService.getInstance().preparePsiElementForWrite(aClass)) { return; } ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { CreateFieldFix.runImpl(editor.getProject(), editor.getRootContainer(), aClass, insertedComponent.getComponentClassName(), insertedComponent.getBinding(), false, // silently skip all errors (if any) null); } }); } } }
public static void updateBoundFieldName(final RadRootContainer root, final String oldName, final String newName, final String fieldClassName) { final String classToBind = root.getClassToBind(); if (classToBind == null) return; final Project project = root.getProject(); if (newName.length() == 0) { checkRemoveUnusedField(root, oldName, FormEditingUtil.getNextSaveUndoGroupId(project)); return; } final PsiClass aClass = JavaPsiFacade.getInstance(project).findClass(classToBind, GlobalSearchScope.allScope(project)); if(aClass == null){ return; } if(oldName == null) { if (aClass.findFieldByName(newName, true) == null) { CreateFieldFix.runImpl(project, root, aClass, fieldClassName, newName, false, FormEditingUtil.getNextSaveUndoGroupId(project)); } return; } final PsiField oldField = aClass.findFieldByName(oldName, true); if(oldField == null){ return; } if(aClass.findFieldByName(newName, true) != null) { checkRemoveUnusedField(root, oldName, FormEditingUtil.getNextSaveUndoGroupId(project)); return; } // Show question to the user if (!isFieldUnreferenced(oldField)) { final int option = Messages.showYesNoDialog(project, MessageFormat.format(UIDesignerBundle.message("message.rename.field"), oldName, newName), UIDesignerBundle.message("title.rename"), Messages.getQuestionIcon() ); if(option != Messages.YES/*Yes*/){ return; } } // Commit document before refactoring starts GuiEditor editor = DesignerToolWindowManager.getInstance(project).getActiveFormEditor(); if (editor != null) { editor.refreshAndSave(false); } PsiDocumentManager.getInstance(project).commitAllDocuments(); if (!CommonRefactoringUtil.checkReadOnlyStatus(project, aClass)) { return; } final RenameProcessor processor = new RenameProcessor(project, oldField, newName, true, true); processor.run(); }
public static void updateBoundFieldName(final RadRootContainer root, final String oldName, final String newName, final String fieldClassName) { final String classToBind = root.getClassToBind(); if (classToBind == null) return; final Project project = root.getProject(); if (newName.length() == 0) { checkRemoveUnusedField(root, oldName, FormEditingUtil.getNextSaveUndoGroupId(project)); return; } final PsiClass aClass = JavaPsiFacade.getInstance(project).findClass(classToBind, GlobalSearchScope.allScope(project)); if(aClass == null){ return; } if(oldName == null) { if (aClass.findFieldByName(newName, true) == null) { CreateFieldFix.runImpl(project, root, aClass, fieldClassName, newName, false, FormEditingUtil.getNextSaveUndoGroupId(project)); } return; } final PsiField oldField = aClass.findFieldByName(oldName, true); if(oldField == null){ return; } if(aClass.findFieldByName(newName, true) != null) { checkRemoveUnusedField(root, oldName, FormEditingUtil.getNextSaveUndoGroupId(project)); return; } // Show question to the user if (!isFieldUnreferenced(oldField)) { final int option = Messages.showYesNoDialog(project, MessageFormat.format(UIDesignerBundle.message("message.rename.field"), oldName, newName), UIDesignerBundle.message("title.rename"), Messages.getQuestionIcon() ); if(option != 0/*Yes*/){ return; } } // Commit document before refactoring starts GuiEditor editor = UIDesignerToolWindowManager.getInstance(project).getActiveFormEditor(); if (editor != null) { editor.refreshAndSave(false); } PsiDocumentManager.getInstance(project).commitAllDocuments(); if (!CommonRefactoringUtil.checkReadOnlyStatus(project, aClass)) { return; } final RenameProcessor processor = new RenameProcessor(project, oldField, newName, true, true); processor.run(); }
public static void updateBoundFieldName(final RadRootContainer root, final String oldName, final String newName, final String fieldClassName) { final String classToBind = root.getClassToBind(); if (classToBind == null) return; final Project project = root.getProject(); if (newName.length() == 0) { checkRemoveUnusedField(root, oldName, FormEditingUtil.getNextSaveUndoGroupId(project)); return; } final PsiClass aClass = JavaPsiFacade.getInstance(project).findClass(classToBind, GlobalSearchScope.allScope(project)); if(aClass == null){ return; } if(oldName == null) { if (aClass.findFieldByName(newName, true) == null) { CreateFieldFix.runImpl(project, root, aClass, fieldClassName, newName, false, FormEditingUtil.getNextSaveUndoGroupId(project)); } return; } final PsiField oldField = aClass.findFieldByName(oldName, true); if(oldField == null){ return; } if(aClass.findFieldByName(newName, true) != null) { checkRemoveUnusedField(root, oldName, FormEditingUtil.getNextSaveUndoGroupId(project)); return; } // Show question to the user if (!isFieldUnreferenced(oldField)) { final int option = Messages.showYesNoDialog(project, MessageFormat.format(UIDesignerBundle.message("message.rename.field"), oldName, newName), UIDesignerBundle.message("title.rename"), Messages.getQuestionIcon() ); if(option != 0/*Yes*/){ return; } } // Commit document before refactoring starts GuiEditor editor = DesignerToolWindowManager.getInstance(project).getActiveFormEditor(); if (editor != null) { editor.refreshAndSave(false); } PsiDocumentManager.getInstance(project).commitAllDocuments(); if (!CommonRefactoringUtil.checkReadOnlyStatus(project, aClass)) { return; } final RenameProcessor processor = new RenameProcessor(project, oldField, newName, true, true); processor.run(); }