Example usage for com.intellij.openapi.ui Messages getQuestionIcon

List of usage examples for com.intellij.openapi.ui Messages getQuestionIcon

Introduction

In this page you can find the example usage for com.intellij.openapi.ui Messages getQuestionIcon.

Prototype

@NotNull
    public static Icon getQuestionIcon() 

Source Link

Usage

From source file:com.intellij.uiDesigner.designSurface.InsertComponentProcessor.java

License:Apache License

private boolean checkAddLibraryDependency(final ComponentItem item, final LibraryOrderEntry libraryOrderEntry) {
    int rc = Messages.showYesNoCancelDialog(myEditor,
            UIDesignerBundle.message("add.library.dependency.prompt", item.getClassName(),
                    libraryOrderEntry.getPresentableName(), myEditor.getModule().getName()),
            UIDesignerBundle.message("add.library.dependency.title"), Messages.getQuestionIcon());
    if (rc == Messages.CANCEL) {
        return false;
    }/*  ww w .j a  v  a  2 s  . c  o m*/
    if (rc == Messages.YES) {
        ApplicationManager.getApplication().runWriteAction(new Runnable() {
            @Override
            public void run() {
                final ModifiableRootModel model = ModuleRootManager.getInstance(myEditor.getModule())
                        .getModifiableModel();
                if (libraryOrderEntry.isModuleLevel()) {
                    copyModuleLevelLibrary(libraryOrderEntry.getLibrary(), model);
                } else {
                    model.addLibraryEntry(libraryOrderEntry.getLibrary());
                }
                model.commit();
            }
        });
    }
    return true;
}

From source file:com.intellij.uiDesigner.FormEditingUtil.java

License:Apache License

public static void deleteRowOrColumn(final GuiEditor editor, final RadContainer container,
        final int[] cellsToDelete, final boolean isRow) {
    Arrays.sort(cellsToDelete);//from   w ww.ja v  a 2s.c o  m
    final int[] cells = ArrayUtil.reverseArray(cellsToDelete);
    if (!editor.ensureEditable()) {
        return;
    }

    Runnable runnable = new Runnable() {
        public void run() {
            if (!GridChangeUtil.canDeleteCells(container, cells, isRow)) {
                Set<RadComponent> componentsInColumn = new HashSet<RadComponent>();
                for (RadComponent component : container.getComponents()) {
                    GridConstraints c = component.getConstraints();
                    for (int cell : cells) {
                        if (c.contains(isRow, cell)) {
                            componentsInColumn.add(component);
                            break;
                        }
                    }
                }

                if (componentsInColumn.size() > 0) {
                    String message = isRow
                            ? UIDesignerBundle.message("delete.row.nonempty", componentsInColumn.size(),
                                    cells.length)
                            : UIDesignerBundle.message("delete.column.nonempty", componentsInColumn.size(),
                                    cells.length);

                    final int rc = Messages.showYesNoDialog(editor, message,
                            isRow ? UIDesignerBundle.message("delete.row.title")
                                    : UIDesignerBundle.message("delete.column.title"),
                            Messages.getQuestionIcon());
                    if (rc != Messages.YES) {
                        return;
                    }

                    deleteComponents(componentsInColumn, false);
                }
            }

            for (int cell : cells) {
                container.getGridLayoutManager().deleteGridCells(container, cell, isRow);
            }
            editor.refreshAndSave(true);
        }
    };
    CommandProcessor.getInstance().executeCommand(editor.getProject(), runnable,
            isRow ? UIDesignerBundle.message("command.delete.row")
                    : UIDesignerBundle.message("command.delete.column"),
            null);
}

From source file:com.intellij.uiDesigner.inspections.AssignMnemonicFix.java

License:Apache License

public void run() {
    IProperty textProperty = FormInspectionUtil.findProperty(myComponent, SwingProperties.TEXT);
    StringDescriptor descriptor = (StringDescriptor) textProperty.getPropertyValue(myComponent);
    String value = StringDescriptorManager.getInstance(myComponent.getModule()).resolve(myComponent,
            descriptor);/*from w  w  w.  ja v  a  2s  .  c o  m*/
    String[] variants = fillMnemonicVariants(SupportCode.parseText(value).myText);
    String result = Messages.showEditableChooseDialog(
            UIDesignerBundle.message("inspection.missing.mnemonics.quickfix.prompt"),
            UIDesignerBundle.message("inspection.missing.mnemonics.quickfix.title"), Messages.getQuestionIcon(),
            variants, variants[0], null);
    if (result != null) {
        if (!myEditor.ensureEditable()) {
            return;
        }
        FormInspectionUtil.updateStringPropertyValue(myEditor, myComponent, (IntroStringProperty) textProperty,
                descriptor, result);
    }
}

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;//from   ww w  .j ava  2s.  c  o 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.DeleteComponentAction.java

License:Apache License

public void actionPerformed(AnActionEvent e) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    ComponentItem selectedItem = e.getData(ComponentItem.DATA_KEY);
    GroupItem groupItem = e.getData(GroupItem.DATA_KEY);
    if (project == null || selectedItem == null || groupItem == null)
        return;/*from w  w  w. j  av  a  2  s  .co m*/

    if (!selectedItem.isRemovable()) {
        Messages.showInfoMessage(project, UIDesignerBundle.message("error.cannot.remove.default.palette"),
                CommonBundle.getErrorTitle());
        return;
    }

    int rc = Messages.showYesNoDialog(project,
            UIDesignerBundle.message("delete.component.prompt", selectedItem.getClassShortName()),
            UIDesignerBundle.message("delete.component.title"), Messages.getQuestionIcon());
    if (rc != 0)
        return;

    final Palette palette = Palette.getInstance(project);
    palette.removeItem(groupItem, selectedItem);
    palette.fireGroupsChanged();
}

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 w  ww  .j a va  2  s  . com*/

    // 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.editors.string.StringEditorDialog.java

License:Apache License

private static String promptNewKeyName(final Project project, final PropertiesFile propFile, final String key) {
    String newName;//from  w  w  w .  j a  v  a  2 s. c o m
    int index = 0;
    do {
        index++;
        newName = key + index;
    } while (propFile.findPropertyByKey(newName) != null);

    InputValidator validator = new InputValidator() {
        public boolean checkInput(String inputString) {
            return inputString.length() > 0 && propFile.findPropertyByKey(inputString) == null;
        }

        public boolean canClose(String inputString) {
            return checkInput(inputString);
        }
    };
    return Messages.showInputDialog(project, UIDesignerBundle.message("edit.text.unique.key.prompt"),
            UIDesignerBundle.message("edit.text.multiple.usages.title"), Messages.getQuestionIcon(), newName,
            validator);
}

From source file:com.intellij.uiDesigner.propertyInspector.properties.BindingProperty.java

License:Apache License

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;//  ww  w .  j a  v  a  2s.c o m

    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();
}

From source file:com.intellij.uiDesigner.propertyInspector.properties.CustomCreateProperty.java

License:Apache License

protected void setValueImpl(final RadComponent component, final Boolean value) throws Exception {
    if (value.booleanValue() && component.getBinding() == null) {
        String initialBinding = BindingProperty.getDefaultBinding(component);
        String binding = Messages.showInputDialog(component.getProject(),
                UIDesignerBundle.message("custom.create.field.name.prompt"),
                UIDesignerBundle.message("custom.create.title"), Messages.getQuestionIcon(), initialBinding,
                new IdentifierValidator(component.getProject()));
        if (binding == null) {
            return;
        }//from w  w w .ja v  a2 s . c  o m
        try {
            new BindingProperty(component.getProject()).setValue(component, binding);
        } catch (Exception e1) {
            LOG.error(e1);
        }
    }
    component.setCustomCreate(value.booleanValue());
    if (value.booleanValue()) {
        final IRootContainer root = FormEditingUtil.getRoot(component);
        if (root.getClassToBind() != null && Utils.getCustomCreateComponentCount(root) == 1) {
            final PsiClass aClass = FormEditingUtil.findClassToBind(component.getModule(),
                    root.getClassToBind());
            if (aClass != null && FormEditingUtil.findCreateComponentsMethod(aClass) == null) {
                generateCreateComponentsMethod(aClass);
            }
        }
    }
}

From source file:com.intellij.uiDesigner.snapShooter.CreateSnapShotAction.java

License:Apache License

public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
    if (project == null || view == null) {
        return;/*from   www  .j a va2s.c om*/
    }

    final PsiDirectory dir = view.getOrChooseDirectory();
    if (dir == null)
        return;

    final SnapShotClient client = new SnapShotClient();
    List<RunnerAndConfigurationSettings> appConfigurations = new ArrayList<RunnerAndConfigurationSettings>();
    RunnerAndConfigurationSettings snapshotConfiguration = null;
    boolean connected = false;

    ApplicationConfigurationType cfgType = ApplicationConfigurationType.getInstance();
    List<RunnerAndConfigurationSettings> racsi = RunManager.getInstance(project)
            .getConfigurationSettingsList(cfgType);

    for (RunnerAndConfigurationSettings config : racsi) {
        if (config.getConfiguration() instanceof ApplicationConfiguration) {
            ApplicationConfiguration appConfig = (ApplicationConfiguration) config.getConfiguration();
            appConfigurations.add(config);
            if (appConfig.ENABLE_SWING_INSPECTOR) {
                SnapShooterConfigurationSettings settings = SnapShooterConfigurationSettings.get(appConfig);
                snapshotConfiguration = config;
                if (settings.getLastPort() > 0) {
                    try {
                        client.connect(settings.getLastPort());
                        connected = true;
                    } catch (IOException ex) {
                        connected = false;
                    }
                }
            }
            if (connected)
                break;
        }
    }

    if (snapshotConfiguration == null) {
        snapshotConfiguration = promptForSnapshotConfiguration(project, appConfigurations);
        if (snapshotConfiguration == null)
            return;
    }

    if (!connected) {
        int rc = Messages.showYesNoDialog(project, UIDesignerBundle.message("snapshot.run.prompt"),
                UIDesignerBundle.message("snapshot.title"), Messages.getQuestionIcon());
        if (rc == 1)
            return;
        final ApplicationConfiguration appConfig = (ApplicationConfiguration) snapshotConfiguration
                .getConfiguration();
        final SnapShooterConfigurationSettings settings = SnapShooterConfigurationSettings.get(appConfig);
        settings.setNotifyRunnable(new Runnable() {
            public void run() {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        Messages.showMessageDialog(project, UIDesignerBundle.message("snapshot.prepare.notice"),
                                UIDesignerBundle.message("snapshot.title"), Messages.getInformationIcon());
                        try {
                            client.connect(settings.getLastPort());
                        } catch (IOException ex) {
                            Messages.showMessageDialog(project,
                                    UIDesignerBundle.message("snapshot.connection.error"),
                                    UIDesignerBundle.message("snapshot.title"), Messages.getErrorIcon());
                            return;
                        }
                        runSnapShooterSession(client, project, dir, view);
                    }
                });
            }
        });

        try {
            final ProgramRunner runner = RunnerRegistry.getInstance().getRunner(DefaultRunExecutor.EXECUTOR_ID,
                    appConfig);
            LOG.assertTrue(runner != null, "Runner MUST not be null!");
            Executor executor = DefaultRunExecutor.getRunExecutorInstance();
            runner.execute(new ExecutionEnvironment(executor, runner, snapshotConfiguration, project));
        } catch (ExecutionException ex) {
            Messages.showMessageDialog(project, UIDesignerBundle.message("snapshot.run.error", ex.getMessage()),
                    UIDesignerBundle.message("snapshot.title"), Messages.getErrorIcon());
        }
    } else {
        runSnapShooterSession(client, project, dir, view);
    }
}