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

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

Introduction

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

Prototype

protected DialogWrapper(boolean canBeParent) 

Source Link

Document

Creates modal DialogWrapper .

Usage

From source file:com.intellij.codeInspection.ex.EntryPointsManagerImpl.java

License:Apache License

@Override
public void configureAnnotations() {
    final List<String> list = new ArrayList<String>(ADDITIONAL_ANNOTATIONS);
    final JPanel listPanel = SpecialAnnotationsUtil.createSpecialAnnotationsListControl(list,
            "Do not check if annotated by", true);
    new DialogWrapper(myProject) {
        {/*from   w ww.  j a  v a 2s.  co  m*/
            init();
            setTitle("Configure annotations");
        }

        @Override
        protected JComponent createCenterPanel() {
            return listPanel;
        }

        @Override
        protected void doOKAction() {
            ADDITIONAL_ANNOTATIONS.clear();
            ADDITIONAL_ANNOTATIONS.addAll(list);
            DaemonCodeAnalyzer.getInstance(myProject).restart();
            super.doOKAction();
        }
    }.show();
}

From source file:com.intellij.codeInspection.i18n.I18nInspection.java

License:Apache License

@SuppressWarnings({ "NonStaticInitializer" })
private DialogWrapper createIgnoreExceptionsConfigurationDialog(final Project project,
        final JTextField specifiedExceptions) {
    return new DialogWrapper(true) {
        private AddDeleteListPanel myPanel;
        {/* w w w  . j ava2 s. com*/
            setTitle(CodeInsightBundle
                    .message("inspection.i18n.option.ignore.for.specified.exception.constructor.arguments"));
            init();
        }

        @Override
        protected JComponent createCenterPanel() {
            final String[] ignored = ignoreForSpecifiedExceptionConstructors.split(",");
            final List<String> initialList = new ArrayList<String>();
            if (ignored != null) {
                for (String e : ignored) {
                    if (e.length() > 0)
                        initialList.add(e);
                }
            }
            myPanel = new AddDeleteListPanel<String>(null, initialList) {
                @Override
                protected String findItemToAdd() {
                    final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
                    TreeClassChooser chooser = TreeClassChooserFactory.getInstance(project)
                            .createInheritanceClassChooser(CodeInsightBundle.message(
                                    "inspection.i18n.option.ignore.for.specified.exception.constructor.arguments"),
                                    scope,
                                    JavaPsiFacade.getInstance(project).findClass("java.lang.Throwable", scope),
                                    true, true, null);
                    chooser.showDialog();
                    PsiClass selectedClass = chooser.getSelected();
                    return selectedClass != null ? selectedClass.getQualifiedName() : null;
                }
            };
            return myPanel;
        }

        @Override
        protected void doOKAction() {
            StringBuilder buf = new StringBuilder();
            final Object[] exceptions = myPanel.getListItems();
            for (Object exception : exceptions) {
                buf.append(",").append(exception);
            }
            specifiedExceptions.setText(buf.length() > 0 ? buf.substring(1) : buf.toString());
            super.doOKAction();
        }
    };
}

From source file:com.intellij.internal.validation.TestDnd.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    new DialogWrapper(getEventProject(e)) {
        {//from  ww w .  j  a  va  2s.c o  m
            setTitle("DnD Test");
            setSize(600, 500);
            init();
        }

        @Nullable
        @Override
        protected JComponent createCenterPanel() {
            JBList list = new JBList(
                    new String[] { "1111111", "222222", "333333", "44444", "555555555555555555555555" });
            DnDSupport.createBuilder(list).setBeanProvider(new Function<DnDActionInfo, DnDDragStartBean>() {
                @Override
                public DnDDragStartBean fun(DnDActionInfo info) {
                    return new DnDDragStartBean("something");
                }
            }).setImageProvider(new Function<DnDActionInfo, DnDImage>() {
                @Override
                public DnDImage fun(DnDActionInfo info) {
                    return new DnDImage(IconUtil.toImage(AllIcons.Icon32));
                }
            }).install();

            return list;
        }
    }.show();
}

From source file:com.intellij.internal.validation.TestMacMessagesAction.java

License:Apache License

@Override
public void actionPerformed(final AnActionEvent e) {
    new DialogWrapper(e.getProject()) {
        {//from   w  w w  .j  a v a 2s  . c o m
            setSize(500, 500);
            setTitle("Dialog 1");
            init();
        }

        @Nullable
        @Override
        protected JComponent createCenterPanel() {
            final JButton button = new JButton("Click me");
            button.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent event) {
                    new DialogWrapper(e.getProject()) {
                        {
                            setSize(400, 400);
                            setTitle("Dialog 2");
                            init();
                        }

                        @Nullable
                        @Override
                        protected JComponent createCenterPanel() {
                            final JButton b = new JButton("Click me again " + num);
                            num++;
                            b.addActionListener(new ActionListener() {
                                @Override
                                public void actionPerformed(ActionEvent e) {
                                    Messages.showYesNoDialog(b, "Blah-blah", "Error",
                                            Messages.getQuestionIcon());
                                }
                            });
                            return b;
                        }
                    }.show();
                }
            });
            return button;
        }
    }.show();
}

From source file:com.intellij.ui.ShowUIDefaultsAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    final UIDefaults defaults = UIManager.getDefaults();
    Enumeration keys = defaults.keys();
    final Object[][] data = new Object[defaults.size()][2];
    int i = 0;//from w  w  w . j  a  va  2 s.  c  o m
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        data[i][0] = key;
        data[i][1] = defaults.get(key);
        i++;
    }

    Arrays.sort(data, new Comparator<Object[]>() {
        @Override
        public int compare(Object[] o1, Object[] o2) {
            return StringUtil.naturalCompare(o1[0].toString(), o2[0].toString());
        }
    });

    final Project project = getEventProject(e);
    new DialogWrapper(project) {
        {
            setTitle("Edit LaF Defaults");
            setModal(false);
            init();
        }

        public JBTable myTable;

        @Nullable
        @Override
        public JComponent getPreferredFocusedComponent() {
            return myTable;
        }

        @Nullable
        @Override
        protected String getDimensionServiceKey() {
            return project == null ? null : "UI.Defaults.Dialog";
        }

        @Override
        protected JComponent createCenterPanel() {
            final JBTable table = new JBTable(new DefaultTableModel(data, new Object[] { "Name", "Value" }) {
                @Override
                public boolean isCellEditable(int row, int column) {
                    return column == 1 && getValueAt(row, column) instanceof Color;
                }
            }) {
                @Override
                public boolean editCellAt(int row, int column, EventObject e) {
                    if (isCellEditable(row, column) && e instanceof MouseEvent) {
                        final Object color = getValueAt(row, column);
                        final Color newColor = ColorPicker.showDialog(this, "Choose Color", (Color) color, true,
                                null, true);
                        if (newColor != null) {
                            final ColorUIResource colorUIResource = new ColorUIResource(newColor);
                            final Object key = getValueAt(row, 0);
                            UIManager.put(key, colorUIResource);
                            setValueAt(colorUIResource, row, column);
                        }
                    }
                    return false;
                }
            };
            table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
                @Override
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                        boolean hasFocus, int row, int column) {
                    final JPanel panel = new JPanel(new BorderLayout());
                    final JLabel label = new JLabel(value == null ? "" : value.toString());
                    panel.add(label, BorderLayout.CENTER);
                    if (value instanceof Color) {
                        final Color c = (Color) value;
                        label.setText(String.format("[r=%d,g=%d,b=%d] hex=0x%s", c.getRed(), c.getGreen(),
                                c.getBlue(), ColorUtil.toHex(c)));
                        label.setForeground(ColorUtil.isDark(c) ? Color.white : Color.black);
                        panel.setBackground(c);
                        return panel;
                    } else if (value instanceof Icon) {
                        try {
                            final Icon icon = new IconWrap((Icon) value);
                            if (icon.getIconHeight() <= 20) {
                                label.setIcon(icon);
                            }
                            label.setText(String.format("(%dx%d) %s)", icon.getIconWidth(),
                                    icon.getIconHeight(), label.getText()));
                        } catch (Throwable e1) {//
                        }
                        return panel;
                    } else if (value instanceof Border) {
                        try {
                            final Insets i = ((Border) value).getBorderInsets(null);
                            label.setText(String.format("[%d, %d, %d, %d] %s", i.top, i.left, i.bottom, i.right,
                                    label.getText()));
                            return panel;
                        } catch (Exception ignore) {
                        }
                    }
                    return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                }
            });
            final JBScrollPane pane = new JBScrollPane(table);
            new TableSpeedSearch(table, new PairFunction<Object, Cell, String>() {
                @Nullable
                @Override
                public String fun(Object o, Cell cell) {
                    return cell.column == 1 ? null : String.valueOf(o);
                }
            });
            table.setShowGrid(false);
            final JPanel panel = new JPanel(new BorderLayout());
            panel.add(pane, BorderLayout.CENTER);
            myTable = table;
            TableUtil.ensureSelectionExists(myTable);
            return panel;
        }
    }.show();
}