Search in sources :

Example 11 with DialogWrapper

use of com.intellij.openapi.ui.DialogWrapper in project intellij-community by JetBrains.

the class PsiDocumentManagerImplTest method testChangeDocumentThenEnterModalDialogThenCallPerformWhenAllCommittedShouldFireWhileInsideModal.

public void testChangeDocumentThenEnterModalDialogThenCallPerformWhenAllCommittedShouldFireWhileInsideModal() throws IOException {
    VirtualFile vFile = getVirtualFile(createTempFile("a.txt", "abc"));
    PsiFile psiFile = findFile(vFile);
    final Document document = getDocument(psiFile);
    final DialogWrapper dialog = new DialogWrapper(getProject()) {

        @Nullable
        @Override
        protected JComponent createCenterPanel() {
            return null;
        }
    };
    disposeOnTearDown(() -> dialog.close(DialogWrapper.OK_EXIT_CODE));
    ApplicationManager.getApplication().runWriteAction(() -> {
        // commit thread is paused
        document.setText("xx");
        LaterInvocator.enterModal(dialog);
    });
    assertNotSame(ModalityState.NON_MODAL, ApplicationManager.getApplication().getCurrentModalityState());
    // may or may not commit in background by default when modality changed
    waitTenSecondsForCommit(document);
    // but, when performWhenAllCommitted() in modal context called, should re-add documents into queue nevertheless
    boolean[] calledPerformWhenAllCommitted = new boolean[1];
    getPsiDocumentManager().performWhenAllCommitted(() -> calledPerformWhenAllCommitted[0] = true);
    // must commit now
    waitTenSecondsForCommit(document);
    assertTrue(getPsiDocumentManager().isCommitted(document));
    assertTrue(calledPerformWhenAllCommitted[0]);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) MockPsiFile(com.intellij.mock.MockPsiFile) Document(com.intellij.openapi.editor.Document) MockDocument(com.intellij.mock.MockDocument) DialogWrapper(com.intellij.openapi.ui.DialogWrapper)

Example 12 with DialogWrapper

use of com.intellij.openapi.ui.DialogWrapper in project intellij-community by JetBrains.

the class MacMessagesTest method actionPerformed.

@Override
public void actionPerformed(final AnActionEvent anActionEvent) {
    JDialog controlDialog = new JDialog();
    controlDialog.setTitle("Messages testing control panel");
    controlDialog.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
    controlDialog.setModal(false);
    controlDialog.setFocusableWindowState(false);
    controlDialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    Container cp = controlDialog.getContentPane();
    cp.setLayout(new FlowLayout());
    JButton showDialogWrapperButton = new JButton("Show a dialog wrapper");
    showDialogWrapperButton.setFocusable(false);
    FocusManagerImpl fmi = FocusManagerImpl.getInstance();
    final Project p = fmi.getLastFocusedFrame().getProject();
    showDialogWrapperButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            DialogWrapper dw = new SimpleDialogWrapper(p);
            dw.setTitle(dw.getWindow().getName());
            dw.show();
        }
    });
    JButton showMessageButton = new JButton("Show a message");
    showDialogWrapperButton.setFocusable(false);
    showMessageButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            showTestMessage(p);
        }
    });
    JButton showProgressIndicatorButton = new JButton("Show progress indicator");
    showProgressIndicatorButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final Task task = new Task.Modal(null, "Test task", true) {

                public void run(@NotNull final ProgressIndicator indicator) {
                    ApplicationManager.getApplication().invokeAndWait(() -> {
                        FocusManagerImpl fmi1 = FocusManagerImpl.getInstance();
                        final Project p1 = fmi1.getLastFocusedFrame().getProject();
                        showTestMessage(p1);
                    }, ModalityState.any());
                }

                @Override
                public void onCancel() {
                }
            };
            ProgressManager.getInstance().run(task);
        }
    });
    cp.add(showDialogWrapperButton);
    cp.add(showMessageButton);
    cp.add(showProgressIndicatorButton);
    controlDialog.pack();
    controlDialog.setVisible(true);
}
Also used : FocusManagerImpl(com.intellij.openapi.wm.impl.FocusManagerImpl) Task(com.intellij.openapi.progress.Task) ActionEvent(java.awt.event.ActionEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) Project(com.intellij.openapi.project.Project) ActionListener(java.awt.event.ActionListener) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 13 with DialogWrapper

use of com.intellij.openapi.ui.DialogWrapper in project intellij-community by JetBrains.

the class ShowUIDefaultsAction method actionPerformed.

@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;
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        data[i][0] = key;
        data[i][1] = defaults.get(key);
        i++;
    }
    Arrays.sort(data, (o1, o2) -> 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, (o, cell) -> 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();
}
Also used : EmptyIcon(com.intellij.util.ui.EmptyIcon) Arrays(java.util.Arrays) DefaultTableModel(javax.swing.table.DefaultTableModel) Enumeration(java.util.Enumeration) StringUtil(com.intellij.openapi.util.text.StringUtil) AnAction(com.intellij.openapi.actionSystem.AnAction) ColorUIResource(javax.swing.plaf.ColorUIResource) MouseEvent(java.awt.event.MouseEvent) JBScrollPane(com.intellij.ui.components.JBScrollPane) Border(javax.swing.border.Border) EventObject(java.util.EventObject) java.awt(java.awt) JBTable(com.intellij.ui.table.JBTable) Nullable(org.jetbrains.annotations.Nullable) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) PairFunction(com.intellij.util.PairFunction) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Project(com.intellij.openapi.project.Project) DumbAware(com.intellij.openapi.project.DumbAware) Comparator(java.util.Comparator) javax.swing(javax.swing) DefaultTableModel(javax.swing.table.DefaultTableModel) JBTable(com.intellij.ui.table.JBTable) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) Enumeration(java.util.Enumeration) MouseEvent(java.awt.event.MouseEvent) ColorUIResource(javax.swing.plaf.ColorUIResource) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) EventObject(java.util.EventObject) Project(com.intellij.openapi.project.Project) EventObject(java.util.EventObject) EmptyIcon(com.intellij.util.ui.EmptyIcon) Border(javax.swing.border.Border) Nullable(org.jetbrains.annotations.Nullable) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 14 with DialogWrapper

use of com.intellij.openapi.ui.DialogWrapper in project android by JetBrains.

the class AndroidUtils method showStackStace.

public static void showStackStace(@NotNull final Project project, @NotNull Throwable[] throwables) {
    final StringBuilder messageBuilder = new StringBuilder();
    for (Throwable t : throwables) {
        if (messageBuilder.length() > 0) {
            messageBuilder.append("\n\n");
        }
        messageBuilder.append(AndroidCommonUtils.getStackTrace(t));
    }
    final DialogWrapper wrapper = new DialogWrapper(project, false) {

        {
            init();
        }

        @Override
        protected JComponent createCenterPanel() {
            final JPanel panel = new JPanel(new BorderLayout());
            final JTextArea textArea = new JTextArea(messageBuilder.toString());
            textArea.setEditable(false);
            textArea.setRows(40);
            textArea.setColumns(70);
            panel.add(ScrollPaneFactory.createScrollPane(textArea));
            return panel;
        }
    };
    wrapper.setTitle("Stack Trace");
    wrapper.show();
}
Also used : DialogWrapper(com.intellij.openapi.ui.DialogWrapper)

Example 15 with DialogWrapper

use of com.intellij.openapi.ui.DialogWrapper in project intellij-community by JetBrains.

the class GitUntrackedFilesHelper method notifyUntrackedFilesOverwrittenBy.

/**
   * Displays notification about {@code untracked files would be overwritten by checkout} error.
   * Clicking on the link in the notification opens a simple dialog with the list of these files.
   * @param root
   * @param relativePaths
   * @param operation   the name of the Git operation that caused the error: {@code rebase, merge, checkout}.
   * @param description the content of the notification or null if the default content is to be used.
   */
public static void notifyUntrackedFilesOverwrittenBy(@NotNull final Project project, @NotNull final VirtualFile root, @NotNull Collection<String> relativePaths, @NotNull final String operation, @Nullable String description) {
    final String notificationTitle = StringUtil.capitalize(operation) + " failed";
    final String notificationDesc = description == null ? createUntrackedFilesOverwrittenDescription(operation, true) : description;
    final Collection<String> absolutePaths = GitUtil.toAbsolute(root, relativePaths);
    final List<VirtualFile> untrackedFiles = ContainerUtil.mapNotNull(absolutePaths, new Function<String, VirtualFile>() {

        @Override
        public VirtualFile fun(String absolutePath) {
            return GitUtil.findRefreshFileOrLog(absolutePath);
        }
    });
    VcsNotifier.getInstance(project).notifyError(notificationTitle, notificationDesc, new NotificationListener() {

        @Override
        public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
            if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                final String dialogDesc = createUntrackedFilesOverwrittenDescription(operation, false);
                String title = "Untracked Files Preventing " + StringUtil.capitalize(operation);
                if (untrackedFiles.isEmpty()) {
                    GitUtil.showPathsInDialog(project, absolutePaths, title, dialogDesc);
                } else {
                    DialogWrapper dialog;
                    dialog = new UntrackedFilesDialog(project, untrackedFiles, dialogDesc);
                    dialog.setTitle(title);
                    dialog.show();
                }
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HyperlinkEvent(javax.swing.event.HyperlinkEvent) Notification(com.intellij.notification.Notification) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) NotificationListener(com.intellij.notification.NotificationListener)

Aggregations

DialogWrapper (com.intellij.openapi.ui.DialogWrapper)37 Project (com.intellij.openapi.project.Project)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 ActionEvent (java.awt.event.ActionEvent)6 Nullable (org.jetbrains.annotations.Nullable)6 JBScrollPane (com.intellij.ui.components.JBScrollPane)5 ActionListener (java.awt.event.ActionListener)4 AnAction (com.intellij.openapi.actionSystem.AnAction)3 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)3 Document (com.intellij.openapi.editor.Document)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 MockDocument (com.intellij.mock.MockDocument)2 MockPsiFile (com.intellij.mock.MockPsiFile)2 javax.swing (javax.swing)2 HyperlinkEvent (javax.swing.event.HyperlinkEvent)2 NotNull (org.jetbrains.annotations.NotNull)2 AnnotationTargetUtil (com.intellij.codeInsight.AnnotationTargetUtil)1 DaemonCodeAnalyzer (com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)1 HighlightDisplayKey (com.intellij.codeInsight.daemon.HighlightDisplayKey)1