List of usage examples for com.intellij.openapi.ui Messages showErrorDialog
public static void showErrorDialog(@Nullable Component component, String message, @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title)
From source file:com.intellij.uiDesigner.actions.PreviewFormAction.java
License:Apache License
private static void runPreviewProcess(final String tempPath, final PathsList sources, final Module module, final VirtualFile formFile, @Nullable final Locale stringDescriptorLocale) { // 3. Now we are ready to launch Java process final JavaParameters parameters = new JavaParameters(); parameters.getClassPath().add(tempPath); parameters.getClassPath().add(PathManager.findFileInLibDirectory("jgoodies-forms.jar").getAbsolutePath()); final List<String> paths = sources.getPathList(); for (final String path : paths) { parameters.getClassPath().add(path); }//from w ww . jav a2s . c o m try { parameters.configureByModule(module, JavaParameters.JDK_AND_CLASSES); } catch (CantRunException e) { Messages.showErrorDialog(module.getProject(), UIDesignerBundle.message("error.cannot.preview.form", formFile.getPath().replace('/', File.separatorChar), e.getMessage()), CommonBundle.getErrorTitle()); return; } parameters.setMainClass("FormPreviewFrame"); parameters.setWorkingDirectory(tempPath); if (stringDescriptorLocale != null && stringDescriptorLocale.getDisplayName().length() > 0) { parameters.getVMParametersList().add("-Duser.language=" + stringDescriptorLocale.getLanguage()); } try { final RunProfile profile = new MyRunProfile(module, parameters, tempPath, UIDesignerBundle.message("progress.preview.started", formFile.getPresentableUrl())); ProgramRunner defaultRunner = RunnerRegistry.getInstance().getRunner(DefaultRunExecutor.EXECUTOR_ID, profile); LOG.assertTrue(defaultRunner != null); Executor executor = DefaultRunExecutor.getRunExecutorInstance(); defaultRunner.execute(new ExecutionEnvironment(profile, executor, module.getProject(), null)); } catch (ExecutionException e) { Messages.showErrorDialog(module.getProject(), UIDesignerBundle.message("error.cannot.preview.form", formFile.getPath().replace('/', File.separatorChar), e.getMessage()), CommonBundle.getErrorTitle()); } }
From source file:com.intellij.uiDesigner.binding.ChangeBoundFieldTypeFix.java
License:Apache License
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { CommandProcessor.getInstance().executeCommand(myField.getProject(), new Runnable() { public void run() { try { final PsiManager manager = myField.getManager(); myField.getTypeElement().replace(JavaPsiFacade.getInstance(manager.getProject()) .getElementFactory().createTypeElement(myTypeToSet)); } catch (final IncorrectOperationException e) { ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { Messages.showErrorDialog( myField.getProject(), QuickFixBundle.message("cannot.change.field.exception", myField.getName(), e.getLocalizedMessage()), CommonBundle.getErrorTitle()); }/*from w w w . j a v a2 s.c o m*/ }); } } }, getText(), null); }
From source file:com.intellij.uiDesigner.clientProperties.ConfigureClientPropertiesDialog.java
License:Apache License
@Nullable protected JComponent createCenterPanel() { myClassTree = new Tree(); myClassTree.setRootVisible(false);//from w ww . j a va2 s . c o m myClassTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { final TreePath leadSelectionPath = e.getNewLeadSelectionPath(); if (leadSelectionPath == null) return; final DefaultMutableTreeNode node = (DefaultMutableTreeNode) leadSelectionPath .getLastPathComponent(); mySelectedClass = (Class) node.getUserObject(); updateSelectedProperties(); } }); myClassTree.setCellRenderer(new ColoredTreeCellRenderer() { public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; if (node.getUserObject() instanceof Class) { Class cls = (Class) node.getUserObject(); if (cls != null) { append(cls.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES); } } } }); fillClassTree(); myPropertiesTable = new JBTable(); myPropertiesTable.setModel(myTableModel); mySplitter = new Splitter(false, Float.valueOf(myPropertiesComponent.getValue(SPLITTER_PROPORTION_PROPERTY, "0.5f"))); mySplitter.setFirstComponent( ToolbarDecorator.createDecorator(myClassTree).setAddAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { ClassNameInputDialog dlg = new ClassNameInputDialog(myProject, mySplitter); dlg.show(); if (dlg.getExitCode() == OK_EXIT_CODE) { String className = dlg.getClassName(); if (className.length() == 0) return; final Class aClass; try { aClass = Class.forName(className); } catch (ClassNotFoundException ex) { Messages.showErrorDialog(mySplitter, UIDesignerBundle.message("client.properties.class.not.found", className), UIDesignerBundle.message("client.properties.title")); return; } if (!JComponent.class.isAssignableFrom(aClass)) { Messages.showErrorDialog( mySplitter, UIDesignerBundle .message("client.properties.class.not.component", className), UIDesignerBundle.message("client.properties.title")); return; } myManager.addClientPropertyClass(className); fillClassTree(); } } }).setRemoveAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { if (mySelectedClass != null) { myManager.removeClientPropertyClass(mySelectedClass); fillClassTree(); } } }).setToolbarPosition(SystemInfo.isMac ? ActionToolbarPosition.BOTTOM : ActionToolbarPosition.RIGHT) .createPanel()); mySplitter.setSecondComponent(ToolbarDecorator.createDecorator(myPropertiesTable).disableUpDownActions() .setAddAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { AddClientPropertyDialog dlg = new AddClientPropertyDialog(myProject); dlg.show(); if (dlg.getExitCode() == OK_EXIT_CODE) { ClientPropertiesManager.ClientProperty[] props = myManager .getClientProperties(mySelectedClass); for (ClientPropertiesManager.ClientProperty prop : props) { if (prop.getName().equalsIgnoreCase(dlg.getEnteredProperty().getName())) { Messages.showErrorDialog(mySplitter, UIDesignerBundle.message("client.properties.already.defined", prop.getName()), UIDesignerBundle.message("client.properties.title")); return; } } myManager.addConfiguredProperty(mySelectedClass, dlg.getEnteredProperty()); updateSelectedProperties(); } } }).setRemoveAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { int row = myPropertiesTable.getSelectedRow(); if (row >= 0 && row < mySelectedProperties.length) { myManager.removeConfiguredProperty(mySelectedClass, mySelectedProperties[row].getName()); updateSelectedProperties(); if (mySelectedProperties.length > 0) { if (row >= mySelectedProperties.length) row--; myPropertiesTable.getSelectionModel().setSelectionInterval(row, row); } } } }).createPanel()); return mySplitter; }
From source file:com.intellij.uiDesigner.designSurface.InsertComponentProcessor.java
License:Apache License
private boolean validateNestedFormInsert(final ComponentItem item) { PsiFile boundForm = item.getBoundForm(); if (boundForm != null) { try {/*from www.j av a 2 s .co m*/ final String formName = FormEditingUtil.buildResourceName(boundForm); final String targetForm = FormEditingUtil.buildResourceName(myEditor.getPsiFile()); Utils.validateNestedFormLoop(formName, new PsiNestedFormLoader(myEditor.getModule()), targetForm); } catch (Exception ex) { Messages.showErrorDialog(myEditor, ex.getMessage(), CommonBundle.getErrorTitle()); return false; } } return true; }
From source file:com.intellij.uiDesigner.palette.AddGroupAction.java
License:Apache License
public void actionPerformed(AnActionEvent e) { Project project = e.getData(CommonDataKeys.PROJECT); if (project == null) return;// w ww . j a v a 2 s .co m // Ask group name final String groupName = Messages.showInputDialog(project, UIDesignerBundle.message("message.enter.group.name"), UIDesignerBundle.message("title.add.group"), Messages.getQuestionIcon()); if (groupName == null) { return; } Palette palette = Palette.getInstance(project); // Check that name of the group is unique final ArrayList<GroupItem> groups = palette.getGroups(); for (int i = groups.size() - 1; i >= 0; i--) { if (groupName.equals(groups.get(i).getName())) { Messages.showErrorDialog(project, UIDesignerBundle.message("error.group.name.unique"), CommonBundle.getErrorTitle()); return; } } final GroupItem groupToBeAdded = new GroupItem(groupName); ArrayList<GroupItem> newGroups = new ArrayList<GroupItem>(groups); newGroups.add(groupToBeAdded); palette.setGroups(newGroups); }
From source file:com.intellij.uiDesigner.palette.ComponentItemDialog.java
License:Apache License
private boolean saveNestedForm() { VirtualFile formFile = ResourceFileUtil.findResourceFileInProject(myProject, myTfNestedForm.getText()); if (formFile == null) { Messages.showErrorDialog(getWindow(), UIDesignerBundle.message("add.component.cannot.load.form", myTfNestedForm.getText()), CommonBundle.getErrorTitle()); return false; }//w ww. ja va2 s .c o m LwRootContainer lwRootContainer; try { lwRootContainer = Utils.getRootContainer(formFile.getInputStream(), null); } catch (Exception e) { Messages.showErrorDialog(getWindow(), e.getMessage(), CommonBundle.getErrorTitle()); return false; } if (lwRootContainer.getClassToBind() == null) { Messages.showErrorDialog(getWindow(), UIDesignerBundle.message("add.component.form.not.bound"), CommonBundle.getErrorTitle()); return false; } if (lwRootContainer.getComponent(0).getBinding() == null) { Messages.showErrorDialog(getWindow(), UIDesignerBundle.message("add.component.root.not.bound"), CommonBundle.getErrorTitle()); return false; } PsiClass psiClass = JavaPsiFacade.getInstance(myProject).findClass(lwRootContainer.getClassToBind(), GlobalSearchScope.projectScope(myProject)); if (psiClass != null) { myItemToBeEdited.setClassName(getClassOrInnerName(psiClass)); } else { myItemToBeEdited.setClassName(lwRootContainer.getClassToBind()); } return true; }
From source file:com.intellij.uiDesigner.palette.EditGroupAction.java
License:Apache License
public void actionPerformed(AnActionEvent e) { Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); GroupItem groupToBeEdited = GroupItem.DATA_KEY.getData(e.getDataContext()); if (groupToBeEdited == null || project == null) return;/*from www . jav a2 s. c om*/ // Ask group name final String groupName = Messages.showInputDialog(project, UIDesignerBundle.message("edit.enter.group.name"), UIDesignerBundle.message("title.edit.group"), Messages.getQuestionIcon(), groupToBeEdited.getName(), null); if (groupName == null || groupName.equals(groupToBeEdited.getName())) { return; } Palette palette = Palette.getInstance(project); final ArrayList<GroupItem> groups = palette.getGroups(); for (int i = groups.size() - 1; i >= 0; i--) { if (groupName.equals(groups.get(i).getName())) { Messages.showErrorDialog(project, UIDesignerBundle.message("error.group.name.unique"), CommonBundle.getErrorTitle()); return; } } groupToBeEdited.setName(groupName); palette.fireGroupsChanged(); }
From source file:com.intellij.uiDesigner.propertyInspector.properties.BindingProperty.java
License:Apache License
public static void checkRemoveUnusedField(final RadRootContainer rootContainer, final String fieldName, final Object undoGroupId) { final PsiField oldBindingField = findBoundField(rootContainer, fieldName); if (oldBindingField == null) { return;// w w w .j a v a 2 s. com } final Project project = oldBindingField.getProject(); final PsiClass aClass = oldBindingField.getContainingClass(); if (isFieldUnreferenced(oldBindingField)) { if (!CommonRefactoringUtil.checkReadOnlyStatus(project, aClass)) { return; } ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { CommandProcessor.getInstance().executeCommand(project, new Runnable() { public void run() { try { oldBindingField.delete(); } catch (IncorrectOperationException e) { Messages.showErrorDialog(project, UIDesignerBundle .message("error.cannot.delete.unused.field", e.getMessage()), CommonBundle.getErrorTitle()); } } }, UIDesignerBundle.message("command.delete.unused.field"), undoGroupId); } }); } }
From source file:com.intellij.uiDesigner.quickFixes.ChangeFieldTypeFix.java
License:Apache License
public void run() { final PsiFile psiFile = myField.getContainingFile(); if (psiFile == null) return;//from www.j a v a 2s. c o m if (!FileModificationService.getInstance().preparePsiElementForWrite(psiFile)) return; ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { CommandProcessor.getInstance().executeCommand(myField.getProject(), new Runnable() { public void run() { try { final PsiManager manager = myField.getManager(); myField.getTypeElement().replace(JavaPsiFacade.getInstance(manager.getProject()) .getElementFactory().createTypeElement(myNewType)); } catch (final IncorrectOperationException e) { ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { Messages.showErrorDialog(myEditor, UIDesignerBundle.message("error.cannot.change.field.type", myField.getName(), e.getMessage()), CommonBundle.getErrorTitle()); } }); } } }, getName(), null); } }); }
From source file:com.intellij.uiDesigner.quickFixes.CreateClassToBindFix.java
License:Apache License
public void run() { final Project project = myEditor.getProject(); final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); final VirtualFile sourceRoot = fileIndex.getSourceRootForFile(myEditor.getFile()); if (sourceRoot == null) { Messages.showErrorDialog(myEditor, UIDesignerBundle.message("error.cannot.create.class.not.in.source.root"), CommonBundle.getErrorTitle()); return;// w w w .j a v a2 s .c o m } ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { CommandProcessor.getInstance().executeCommand(project, new Runnable() { public void run() { // 1. Create all necessary packages final int indexOfLastDot = myClassName.lastIndexOf('.'); final String packageName = myClassName.substring(0, indexOfLastDot != -1 ? indexOfLastDot : 0); final PsiDirectory psiDirectory; if (packageName.length() > 0) { final PackageWrapper packageWrapper = new PackageWrapper( PsiManager.getInstance(project), packageName); try { psiDirectory = RefactoringUtil.createPackageDirectoryInSourceRoot(packageWrapper, sourceRoot); LOG.assertTrue(psiDirectory != null); } catch (final IncorrectOperationException e) { ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { Messages.showErrorDialog(myEditor, UIDesignerBundle.message("error.cannot.create.package", packageName, e.getMessage()), CommonBundle.getErrorTitle()); } }); return; } } else { psiDirectory = PsiManager.getInstance(project).findDirectory(sourceRoot); LOG.assertTrue(psiDirectory != null); } // 2. Create class in the package try { final String name = myClassName .substring(indexOfLastDot != -1 ? indexOfLastDot + 1 : 0); final PsiClass aClass = JavaDirectoryService.getInstance().createClass(psiDirectory, name); createBoundFields(aClass); } catch (final IncorrectOperationException e) { ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { Messages.showErrorDialog(myEditor, UIDesignerBundle .message("error.cannot.create.class", packageName, e.getMessage()), CommonBundle.getErrorTitle()); } }); } } }, getName(), null); } }); }