Example usage for com.intellij.openapi.ui DialogWrapper NEXT_USER_EXIT_CODE

List of usage examples for com.intellij.openapi.ui DialogWrapper NEXT_USER_EXIT_CODE

Introduction

In this page you can find the example usage for com.intellij.openapi.ui DialogWrapper NEXT_USER_EXIT_CODE.

Prototype

int NEXT_USER_EXIT_CODE

To view the source code for com.intellij.openapi.ui DialogWrapper NEXT_USER_EXIT_CODE.

Click Source Link

Document

If you use your own custom exit codes you have to start them with this constant.

Usage

From source file:com.android.tools.idea.uibuilder.property.NlIdPropertyItem.java

License:Apache License

@Override
public void setValue(Object value) {
    String newId = value != null ? stripIdPrefix(value.toString()) : "";
    String oldId = getValue();/*from  w w w.j av  a  2s.c  om*/
    XmlTag tag = getTag();

    if (ourRefactoringChoice != REFACTOR_NO && oldId != null && !oldId.isEmpty() && !newId.isEmpty()
            && !oldId.equals(newId) && tag != null && tag.isValid()) {
        // Offer rename refactoring?
        XmlAttribute attribute = tag.getAttribute(SdkConstants.ATTR_ID, SdkConstants.ANDROID_URI);
        if (attribute != null) {
            Module module = getModel().getModule();
            Project project = module.getProject();
            XmlAttributeValue valueElement = attribute.getValueElement();
            if (valueElement != null && valueElement.isValid()) {
                // Exact replace only, no comment/text occurrence changes since it is non-interactive
                ValueResourceElementWrapper wrapper = new ValueResourceElementWrapper(valueElement);
                RenameProcessor processor = new RenameProcessor(project, wrapper, NEW_ID_PREFIX + newId,
                        false /*comments*/, false /*text*/);
                processor.setPreviewUsages(false);
                // Do a quick usage search to see if we need to ask about renaming
                UsageInfo[] usages = processor.findUsages();
                if (usages.length > 0) {
                    int choice = ourRefactoringChoice;
                    if (choice == REFACTOR_ASK) {
                        DialogBuilder builder = createDialogBuilder(project);
                        builder.setTitle("Update Usages?");
                        JPanel panel = new JPanel(new BorderLayout()); // UGH!
                        JLabel label = new JLabel("<html>" + "Update usages as well?<br>"
                                + "This will update all XML references and Java R field references.<br>"
                                + "<br>" + "</html>");
                        panel.add(label, BorderLayout.CENTER);
                        JBCheckBox checkBox = new JBCheckBox("Don't ask again during this session");
                        panel.add(checkBox, BorderLayout.SOUTH);
                        builder.setCenterPanel(panel);
                        builder.setDimensionServiceKey("idPropertyDimension");
                        builder.removeAllActions();

                        DialogBuilder.CustomizableAction yesAction = builder.addOkAction();
                        yesAction.setText(Messages.YES_BUTTON);

                        builder.addActionDescriptor(dialogWrapper -> new AbstractAction(Messages.NO_BUTTON) {
                            @Override
                            public void actionPerformed(ActionEvent actionEvent) {
                                dialogWrapper.close(DialogWrapper.NEXT_USER_EXIT_CODE);
                            }
                        });
                        builder.addCancelAction();
                        int exitCode = builder.show();

                        choice = exitCode == DialogWrapper.OK_EXIT_CODE ? REFACTOR_YES
                                : exitCode == DialogWrapper.NEXT_USER_EXIT_CODE ? REFACTOR_NO
                                        : ourRefactoringChoice;

                        //noinspection AssignmentToStaticFieldFromInstanceMethod
                        ourRefactoringChoice = checkBox.isSelected() ? choice : REFACTOR_ASK;

                        if (exitCode == DialogWrapper.CANCEL_EXIT_CODE) {
                            return;
                        }
                    }

                    if (choice == REFACTOR_YES) {
                        processor.run();
                        return;
                    }
                }
            }
        }
    }

    super.setValue(!StringUtil.isEmpty(newId) ? NEW_ID_PREFIX + newId : null);
}

From source file:com.android.tools.idea.uibuilder.property.NlIdPropertyItemTest.java

License:Apache License

public void testSetValueDoNotChangeReferences() {
    when(myBuilder.show()).thenReturn(DialogWrapper.NEXT_USER_EXIT_CODE);
    myItem.setValue("label");

    assertThat(myTextView.getId()).isEqualTo("label");
    assertThat(myCheckBox1.getAttribute(ANDROID_URI, ATTR_LAYOUT_BELOW)).isEqualTo("@id/textView");
    assertThat(myCheckBox2.getAttribute(ANDROID_URI, ATTR_LAYOUT_TO_RIGHT_OF)).isEqualTo("@id/textView");

    // Change id again (verify no dialog shown since there are no references)
    verify(myBuilder, times(1)).show();//from ww  w .ja  va  2 s . c  om
    myItem.setValue("text");
    verify(myBuilder, times(1)).show();
}

From source file:org.cordovastudio.editors.designer.propertyTable.properties.IdProperty.java

License:Apache License

@Override
public void setValue(@NotNull final RadViewComponent component, final Object value) throws Exception {
    final String newId = value != null ? value.toString() : "";

    IdManager idManager = IdManager.get(component);
    final String oldId = component.getId();

    if (ourRefactoringChoice != REFACTOR_NO && oldId != null && !oldId.isEmpty() && !newId.isEmpty()
            && !oldId.equals(newId) && component.getTag().isValid()) {
        // Offer rename refactoring?
        XmlTag tag = component.getTag();
        XmlAttribute attribute = tag.getAttribute(ATTR_ID, CORDOVASTUDIO_URI);
        if (attribute != null) {
            Module module = RadModelBuilder.getModule(component);
            if (module != null) {
                XmlAttributeValue valueElement = attribute.getValueElement();
                if (valueElement != null && valueElement.isValid()) {
                    final Project project = module.getProject();
                    // Exact replace only, no comment/text occurrence changes since it is non-interactive
                    RenameProcessor processor = new RenameProcessor(project, valueElement, newId,
                            false /*comments*/, false /*text*/);
                    processor.setPreviewUsages(false);
                    // Do a quick usage search to see if we need to ask about renaming
                    UsageInfo[] usages = processor.findUsages();
                    if (usages.length > 0) {
                        int choice = ourRefactoringChoice;
                        if (choice == REFACTOR_ASK) {
                            DialogBuilder builder = new DialogBuilder(project);
                            builder.setTitle("Update Usages?");
                            JPanel panel = new JPanel(new BorderLayout()); // UGH!
                            JLabel label = new JLabel("<html>" + "Update usages as well?<br>"
                                    + "This will update all XML references and Java R field references.<br>"
                                    + "<br>" + "</html>");
                            panel.add(label, BorderLayout.CENTER);
                            JBCheckBox checkBox = new JBCheckBox("Don't ask again during this session");
                            panel.add(checkBox, BorderLayout.SOUTH);
                            builder.setCenterPanel(panel);
                            builder.setDimensionServiceKey("idPropertyDimension");
                            builder.removeAllActions();

                            DialogBuilder.CustomizableAction yesAction = builder.addOkAction();
                            yesAction.setText(Messages.YES_BUTTON);

                            builder.addActionDescriptor(new DialogBuilder.ActionDescriptor() {
                                @Override
                                public Action getAction(final DialogWrapper dialogWrapper) {
                                    return new AbstractAction(Messages.NO_BUTTON) {
                                        @Override
                                        public void actionPerformed(ActionEvent actionEvent) {
                                            dialogWrapper.close(DialogWrapper.NEXT_USER_EXIT_CODE);
                                        }
                                    };/*from   w  ww  . j  a  v a2  s.  c o  m*/
                                }
                            });
                            builder.addCancelAction();
                            int exitCode = builder.show();

                            choice = exitCode == DialogWrapper.OK_EXIT_CODE ? REFACTOR_YES
                                    : exitCode == DialogWrapper.NEXT_USER_EXIT_CODE ? REFACTOR_NO
                                            : ourRefactoringChoice;

                            if (!checkBox.isSelected()) {
                                ourRefactoringChoice = REFACTOR_ASK;
                            } else {
                                ourRefactoringChoice = choice;
                            }

                            if (exitCode == DialogWrapper.CANCEL_EXIT_CODE) {
                                return;
                            }
                        }

                        if (choice == REFACTOR_YES) {
                            processor.run();
                            // Fall through to also set the value in the layout editor property; otherwise we'll be out of sync
                        }
                    }
                }
            }
        }
    }

    if (idManager != null) {
        idManager.removeComponent(component, false);
    }

    //noinspection ConstantConditions
    super.setValue(component, value);

    if (idManager != null) {
        idManager.addComponent(component);
    }
}

From source file:org.moe.designer.propertyTable.IdProperty.java

License:Apache License

@Override
public void setValue(@NotNull final RadViewComponent component, final Object value) throws Exception {
    final String newId = value != null ? value.toString() : "";

    final String oldId = component.getId();

    if (ourRefactoringChoice != REFACTOR_NO && oldId != null && !oldId.isEmpty() && !newId.isEmpty()
            && !oldId.equals(newId) && component.getTag().isValid()) {
        // Offer rename refactoring?
        XmlTag tag = component.getTag();
        XmlAttribute attribute = tag.getAttribute(SdkConstants.ATTR_ID, SdkConstants.ANDROID_URI);
        if (attribute != null) {
            Module module = RadModelBuilder.getModule(component);
            if (module != null) {
                XmlAttributeValue valueElement = attribute.getValueElement();
                if (valueElement != null && valueElement.isValid()) {
                    final Project project = module.getProject();
                    // Exact replace only, no comment/text occurrence changes since it is non-interactive
                    RenameProcessor processor = new RenameProcessor(project, valueElement, newId,
                            false /*comments*/, false /*text*/);
                    processor.setPreviewUsages(false);
                    // Do a quick usage search to see if we need to ask about renaming
                    UsageInfo[] usages = processor.findUsages();
                    if (usages.length > 0) {
                        int choice = ourRefactoringChoice;
                        if (choice == REFACTOR_ASK) {
                            DialogBuilder builder = new DialogBuilder(project);
                            builder.setTitle("Update Usages?");
                            JPanel panel = new JPanel(new BorderLayout()); // UGH!
                            JLabel label = new JLabel("<html>" + "Update usages as well?<br>"
                                    + "This will update all XML references and Java R field references.<br>"
                                    + "<br>" + "</html>");
                            panel.add(label, BorderLayout.CENTER);
                            JBCheckBox checkBox = new JBCheckBox("Don't ask again during this session");
                            panel.add(checkBox, BorderLayout.SOUTH);
                            builder.setCenterPanel(panel);
                            builder.setDimensionServiceKey("idPropertyDimension");
                            builder.removeAllActions();

                            DialogBuilder.CustomizableAction yesAction = builder.addOkAction();
                            yesAction.setText(Messages.YES_BUTTON);

                            builder.addActionDescriptor(new DialogBuilder.ActionDescriptor() {
                                @Override
                                public Action getAction(final DialogWrapper dialogWrapper) {
                                    return new AbstractAction(Messages.NO_BUTTON) {
                                        @Override
                                        public void actionPerformed(ActionEvent actionEvent) {
                                            dialogWrapper.close(DialogWrapper.NEXT_USER_EXIT_CODE);
                                        }
                                    };//from   w w w .  j av a 2 s  .  co  m
                                }
                            });
                            builder.addCancelAction();
                            int exitCode = builder.show();

                            choice = exitCode == DialogWrapper.OK_EXIT_CODE ? REFACTOR_YES
                                    : exitCode == DialogWrapper.NEXT_USER_EXIT_CODE ? REFACTOR_NO
                                            : ourRefactoringChoice;

                            if (!checkBox.isSelected()) {
                                ourRefactoringChoice = REFACTOR_ASK;
                            } else {
                                ourRefactoringChoice = choice;
                            }

                            if (exitCode == DialogWrapper.CANCEL_EXIT_CODE) {
                                return;
                            }
                        }

                        if (choice == REFACTOR_YES) {
                            processor.run();
                            // Fall through to also set the value in the layout editor property; otherwise we'll be out of sync
                        }
                    }
                }
            }
        }
    }

    //noinspection ConstantConditions
    super.setValue(component, value);
}