Search in sources :

Example 1 with DialogWrapper

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

the class CertificateManager method showAcceptDialog.

public static boolean showAcceptDialog(@NotNull final Callable<? extends DialogWrapper> dialogFactory) {
    Application app = ApplicationManager.getApplication();
    final CountDownLatch proceeded = new CountDownLatch(1);
    final AtomicBoolean accepted = new AtomicBoolean();
    final AtomicReference<DialogWrapper> dialogRef = new AtomicReference<>();
    Runnable showDialog = () -> {
        // skip if certificate was already rejected due to timeout or interrupt
        if (proceeded.getCount() == 0) {
            return;
        }
        try {
            DialogWrapper dialog = dialogFactory.call();
            dialogRef.set(dialog);
            accepted.set(dialog.showAndGet());
        } catch (Exception e) {
            LOG.error(e);
        } finally {
            proceeded.countDown();
        }
    };
    if (app.isDispatchThread()) {
        showDialog.run();
    } else {
        app.invokeLater(showDialog, ModalityState.any());
    }
    try {
        // IDEA-123467 and IDEA-123335 workaround
        boolean inTime = proceeded.await(DIALOG_VISIBILITY_TIMEOUT, TimeUnit.MILLISECONDS);
        if (!inTime) {
            DialogWrapper dialog = dialogRef.get();
            if (dialog == null || !dialog.isShowing()) {
                LOG.debug("After " + DIALOG_VISIBILITY_TIMEOUT + " ms dialog was not shown. " + "Rejecting certificate. Current thread: " + Thread.currentThread().getName());
                proceeded.countDown();
                return false;
            } else {
                // if dialog is already shown continue waiting
                proceeded.await();
            }
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        proceeded.countDown();
    }
    return accepted.get();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Application(com.intellij.openapi.application.Application) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) KeyStoreException(java.security.KeyStoreException) KeyManagementException(java.security.KeyManagementException) FileNotFoundException(java.io.FileNotFoundException) BadPaddingException(javax.crypto.BadPaddingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 2 with DialogWrapper

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

the class CreatePatchFromChangesAction method createPatch.

public static void createPatch(Project project, String commitMessage, List<Change> changeCollection) {
    project = project == null ? ProjectManager.getInstance().getDefaultProject() : project;
    final CreatePatchCommitExecutor executor = CreatePatchCommitExecutor.getInstance(project);
    CommitSession commitSession = executor.createCommitSession();
    if (commitSession instanceof CommitSessionContextAware) {
        ((CommitSessionContextAware) commitSession).setContext(new CommitContext());
    }
    DialogWrapper sessionDialog = new SessionDialog(executor.getActionText(), project, commitSession, changeCollection, commitMessage);
    if (!sessionDialog.showAndGet()) {
        return;
    }
    preloadContent(project, changeCollection);
    commitSession.execute(changeCollection, commitMessage);
}
Also used : CreatePatchCommitExecutor(com.intellij.openapi.vcs.changes.patch.CreatePatchCommitExecutor) SessionDialog(com.intellij.openapi.vcs.changes.ui.SessionDialog) DialogWrapper(com.intellij.openapi.ui.DialogWrapper)

Example 3 with DialogWrapper

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

the class PluginHeaderPanel method createUIComponents.

private void createUIComponents() {
    myInstallButton = new JButton() {

        private final int TOP_BOTTOM_BORDER = JBUI.scale(2);

        private final int LEFT_RIGHT_BORDER = JBUI.scale(8);

        private final int H_GAP = JBUI.scale(4);

        private final int ICON_SIZE = getIcon().getIconWidth();

        {
            setOpaque(false);
            setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        }

        @Override
        public Dimension getPreferredSize() {
            final FontMetrics metrics = getFontMetrics(getFont());
            final int textWidth = metrics.stringWidth(getText());
            final int width = LEFT_RIGHT_BORDER + ICON_SIZE + H_GAP + textWidth + LEFT_RIGHT_BORDER;
            final int height = TOP_BOTTOM_BORDER + Math.max(ICON_SIZE, metrics.getHeight()) + TOP_BOTTOM_BORDER;
            return new Dimension(width, height);
        }

        @Override
        public void paint(Graphics g2) {
            final Graphics2D g = (Graphics2D) g2;
            final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
            final int w = g.getClipBounds().width;
            final int h = g.getClipBounds().height;
            int borderArc = JBUI.scale(7);
            int border = JBUI.scale(1);
            int buttonArc = borderArc - border;
            g.setPaint(getBackgroundBorderPaint());
            g.fillRoundRect(0, 0, w, h, borderArc, borderArc);
            g.setPaint(getBackgroundPaint());
            g.fillRoundRect(border, border, w - 2 * border, h - 2 * border, buttonArc, buttonArc);
            g.setColor(getButtonForeground());
            g.drawString(getText(), LEFT_RIGHT_BORDER + ICON_SIZE + H_GAP, getBaseline(w, h));
            getIcon().paintIcon(this, g, LEFT_RIGHT_BORDER, (getHeight() - getIcon().getIconHeight()) / 2);
            config.restore();
        }

        private Color getButtonForeground() {
            switch(myActionId) {
                case UPDATE:
                    return new JBColor(Gray._240, Gray._210);
                case INSTALL:
                    return new JBColor(Gray._240, Gray._210);
                case RESTART:
                case UNINSTALL:
                    return new JBColor(Gray._0, Gray._210);
            }
            return new JBColor(Gray._80, Gray._60);
        }

        private Paint getBackgroundPaint() {
            switch(myActionId) {
                case UPDATE:
                    return new JBGradientPaint(this, new JBColor(0x629ee1, 0x629ee1), new JBColor(0x3a5bb5, 0x3a5bb5));
                case INSTALL:
                    return new JBGradientPaint(this, new JBColor(0x60cc69, 0x519557), new JBColor(0x326529, 0x28462f));
                case RESTART:
                case UNINSTALL:
                    return UIUtil.isUnderDarcula() ? new JBGradientPaint(this, UIManager.getColor("Button.darcula.color1"), UIManager.getColor("Button.darcula.color2")) : Gray._240;
            }
            return Gray._238;
        }

        private Paint getBackgroundBorderPaint() {
            switch(myActionId) {
                case UPDATE:
                    return new JBColor(new Color(0xa6b4cd), Gray._85);
                case INSTALL:
                    return new JBColor(new Color(201, 223, 201), Gray._70);
                case RESTART:
                case UNINSTALL:
                    return new JBColor(Gray._220, Gray._100.withAlpha(180));
            }
            return Gray._208;
        }

        @Override
        public String getText() {
            switch(myActionId) {
                case UPDATE:
                    return "Update";
                case INSTALL:
                    return "Install";
                case UNINSTALL:
                    return "Uninstall";
                case RESTART:
                    return "Restart " + ApplicationNamesInfo.getInstance().getFullProductName();
            }
            return super.getText();
        }

        @Override
        public Icon getIcon() {
            switch(myActionId) {
                case UPDATE:
                    return AllIcons.General.DownloadPlugin;
                case INSTALL:
                    return AllIcons.General.DownloadPlugin;
                case UNINSTALL:
                    return AllIcons.Actions.Delete;
                case RESTART:
                    return AllIcons.Actions.Restart;
            }
            return super.getIcon();
        }
    };
    myInstallButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            switch(myActionId) {
                case UPDATE:
                case INSTALL:
                    Runnable setPlugin = () -> setPlugin(myPlugin);
                    new InstallPluginAction(myManager.getAvailable(), myManager.getInstalled()).install(setPlugin, setPlugin, true);
                    break;
                case UNINSTALL:
                    UninstallPluginAction.uninstall(myManager.getInstalled(), true, myPlugin);
                    break;
                case RESTART:
                    if (myManager != null) {
                        myManager.apply();
                    }
                    final DialogWrapper dialog = DialogWrapper.findInstance(KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner());
                    if (dialog != null && dialog.isModal()) {
                        dialog.close(DialogWrapper.OK_EXIT_CODE);
                    }
                    TransactionGuard.getInstance().submitTransactionLater(ApplicationManager.getApplication(), () -> {
                        DialogWrapper settings = DialogWrapper.findInstance(IdeFocusManager.findInstance().getFocusOwner());
                        if (settings instanceof SettingsDialog) {
                            ((SettingsDialog) settings).doOKAction();
                        }
                        ApplicationManager.getApplication().restart();
                    });
                    break;
            }
            setPlugin(myPlugin);
        }
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) JBColor(com.intellij.ui.JBColor) GraphicsConfig(com.intellij.openapi.ui.GraphicsConfig) JBGradientPaint(com.intellij.ui.JBGradientPaint) JBGradientPaint(com.intellij.ui.JBGradientPaint) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) SettingsDialog(com.intellij.openapi.options.newEditor.SettingsDialog) ActionListener(java.awt.event.ActionListener) JBGradientPaint(com.intellij.ui.JBGradientPaint) JBColor(com.intellij.ui.JBColor)

Example 4 with DialogWrapper

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

the class AppUIUtil method showPrivacyPolicyAgreement.

/**
   * @param htmlText Updated version of Privacy Policy text if any.
   *                 If it's {@code null}, the standard text from bundled resources would be used.
   */
public static void showPrivacyPolicyAgreement(@NotNull String htmlText) {
    DialogWrapper dialog = new DialogWrapper(true) {

        @Nullable
        @Override
        protected JComponent createCenterPanel() {
            JPanel centerPanel = new JPanel(new BorderLayout(JBUI.scale(5), JBUI.scale(5)));
            JEditorPane viewer = SwingHelper.createHtmlViewer(true, null, JBColor.WHITE, JBColor.BLACK);
            viewer.setFocusable(true);
            viewer.addHyperlinkListener(new HyperlinkAdapter() {

                @Override
                protected void hyperlinkActivated(HyperlinkEvent e) {
                    URL url = e.getURL();
                    if (url != null) {
                        BrowserUtil.browse(url);
                    } else {
                        SwingHelper.scrollToReference(viewer, e.getDescription());
                    }
                }
            });
            viewer.setText(htmlText);
            StyleSheet styleSheet = ((HTMLDocument) viewer.getDocument()).getStyleSheet();
            styleSheet.addRule("body {font-family: \"Segoe UI\", Tahoma, sans-serif;}");
            styleSheet.addRule("body {margin-top:0;padding-top:0;}");
            styleSheet.addRule("body {font-size:" + JBUI.scaleFontSize(13) + "pt;}");
            styleSheet.addRule("h2, em {margin-top:" + JBUI.scaleFontSize(20) + "pt;}");
            styleSheet.addRule("h1, h2, h3, p, h4, em {margin-bottom:0;padding-bottom:0;}");
            styleSheet.addRule("p, h1 {margin-top:0;padding-top:" + JBUI.scaleFontSize(6) + "pt;}");
            styleSheet.addRule("li {margin-bottom:" + JBUI.scaleFontSize(6) + "pt;}");
            styleSheet.addRule("h2 {margin-top:0;padding-top:" + JBUI.scaleFontSize(13) + "pt;}");
            viewer.setCaretPosition(0);
            viewer.setBorder(JBUI.Borders.empty(0, 5, 5, 5));
            centerPanel.add(new JLabel("Please read and accept these terms and conditions:"), BorderLayout.NORTH);
            centerPanel.add(new JBScrollPane(viewer, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
            return centerPanel;
        }

        @Override
        protected void createDefaultActions() {
            super.createDefaultActions();
            init();
            setOKButtonText("Accept");
            setCancelButtonText("Reject and Exit");
            setAutoAdjustable(false);
        }

        @Override
        public void doCancelAction() {
            super.doCancelAction();
            ApplicationEx application = ApplicationManagerEx.getApplicationEx();
            if (application == null) {
                System.exit(Main.PRIVACY_POLICY_REJECTION);
            } else {
                ((ApplicationImpl) application).exit(true, true, false);
            }
        }
    };
    dialog.setModal(true);
    dialog.setTitle(ApplicationNamesInfo.getInstance().getFullProductName() + " Privacy Policy Agreement");
    dialog.setSize(JBUI.scale(509), JBUI.scale(395));
    dialog.show();
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) HTMLDocument(javax.swing.text.html.HTMLDocument) ApplicationImpl(com.intellij.openapi.application.impl.ApplicationImpl) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) URL(java.net.URL) StyleSheet(javax.swing.text.html.StyleSheet) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 5 with DialogWrapper

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

the class ChangeProjectIconAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    List<AnAction> elements = getSelectedElements(e);
    String path = ((ReopenProjectAction) elements.get(0)).getProjectPath();
    final ChangeProjectIconForm form = new ChangeProjectIconForm(path);
    DialogWrapper dialog = new DialogWrapper(null) {

        {
            init();
        }

        @Nullable
        @Override
        protected JComponent createCenterPanel() {
            return form.myRootPanel;
        }
    };
    dialog.show();
    if (dialog.isOK()) {
        try {
            form.apply();
        } catch (IOException e1) {
            System.out.println(e1);
        }
    }
}
Also used : ReopenProjectAction(com.intellij.ide.ReopenProjectAction) IOException(java.io.IOException) AnAction(com.intellij.openapi.actionSystem.AnAction) DialogWrapper(com.intellij.openapi.ui.DialogWrapper)

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