Example usage for com.intellij.openapi.ui DialogBuilder setOkOperation

List of usage examples for com.intellij.openapi.ui DialogBuilder setOkOperation

Introduction

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

Prototype

public void setOkOperation(Runnable runnable) 

Source Link

Usage

From source file:com.urswolfer.intellij.plugin.gerrit.ui.diff.CustomizableFrameDiffTool.java

License:Apache License

public void show(DiffRequest request) {
    Collection hints = request.getHints();
    boolean shouldOpenDialog = shouldOpenDialog(hints);
    if (shouldOpenDialog) {
        final DialogBuilder builder = new DialogBuilder(request.getProject());
        DiffPanelImpl diffPanel = createDiffPanelIfShouldShow(request, builder.getWindow(), builder, true);
        if (diffPanel == null) {
            Disposer.dispose(builder);/*from ww  w  .  j  a v a 2 s. c  o  m*/
            return;
        }
        if (hints.contains(DiffTool.HINT_DIFF_IS_APPROXIMATE)) {
            diffPanel.setPatchAppliedApproximately(); // todo read only and not variants
        }
        final Runnable onOkRunnable = request.getOnOkRunnable();
        if (onOkRunnable != null) {
            builder.setOkOperation(new Runnable() {
                @Override
                public void run() {
                    builder.getDialogWrapper().close(0);
                    onOkRunnable.run();
                }
            });
        } else {
            builder.removeAllActions();
        }
        builder.setCenterPanel(diffPanel.getComponent());
        builder.setPreferredFocusComponent(diffPanel.getPreferredFocusedComponent());
        builder.setTitle(request.getWindowTitle());
        builder.setDimensionServiceKey(request.getGroupKey());

        new AnAction() {
            public void actionPerformed(final AnActionEvent e) {
                builder.getDialogWrapper().close(0);
            }
        }.registerCustomShortcutSet(
                new CustomShortcutSet(
                        KeymapManager.getInstance().getActiveKeymap().getShortcuts("CloseContent")),
                diffPanel.getComponent());
        showDiffDialog(builder, hints);
    } else {
        final FrameWrapper frameWrapper = new FrameWrapper(request.getProject(), request.getGroupKey());
        DiffPanelImpl diffPanel = createDiffPanelIfShouldShow(request, frameWrapper.getFrame(), frameWrapper,
                true);
        if (diffPanel == null) {
            Disposer.dispose(frameWrapper);
            return;
        }
        if (hints.contains(DiffTool.HINT_DIFF_IS_APPROXIMATE)) {
            diffPanel.setPatchAppliedApproximately();
        }
        frameWrapper.setTitle(request.getWindowTitle());
        DiffUtil.initDiffFrame(diffPanel.getProject(), frameWrapper, diffPanel, diffPanel.getComponent());

        new AnAction() {
            public void actionPerformed(final AnActionEvent e) {
                frameWrapper.getFrame().dispose();
            }
        }.registerCustomShortcutSet(
                new CustomShortcutSet(
                        KeymapManager.getInstance().getActiveKeymap().getShortcuts("CloseContent")),
                diffPanel.getComponent());

        frameWrapper.show();
    }
}

From source file:manuylov.maxim.ocaml.toolWindow.OCamlToolWindowSettingsAction.java

License:Open Source License

public void showSettingsDialog() {
    final OCamlSettings settings = OCamlSettings.getInstance(myProject);
    final OCamlToolWindowSettingsForm settingsForm = new OCamlToolWindowSettingsForm(myProject);
    settingsForm.setSelectedSdk(settings.getTopLevelSdk());
    settingsForm.setCmdParams(settings.getTopLevelCmdOptions());
    settingsForm.setWorkingDirectory(settings.getTopLevelCmdWorkingDir());

    final DialogBuilder dialogBuilder = new DialogBuilder(myProject);
    dialogBuilder.setCenterPanel(settingsForm.getRootPanel());
    dialogBuilder.addOkAction().setText("Ok");
    dialogBuilder.addCancelAction().setText("Cancel");
    dialogBuilder.setPreferredFocusComponent(settingsForm.getSdkComboBox());
    dialogBuilder.setTitle("OCaml Top Level Console Settings");
    dialogBuilder.setOkOperation(new Runnable() {
        public void run() {
            settings.setTopLevelSdk(settingsForm.getSelectedSdk());
            settings.setTopLevelCmdOptions(settingsForm.getCmdParams());
            settings.setTopLevelCmdWorkingDir(settingsForm.getWorkingDirectory());
            dialogBuilder.getWindow().setVisible(false);
            if (myAction != null) {
                myAction.run();//from   www .jav a2  s .  co  m
            }
        }
    });
    dialogBuilder.show();
}

From source file:org.intellij.plugins.intelliLang.inject.AbstractLanguageInjectionSupport.java

License:Apache License

@Nullable
protected static BaseInjection showDefaultInjectionUI(final Project project, BaseInjection injection) {
    final BaseInjectionPanel panel = new BaseInjectionPanel(injection, project);
    panel.reset();/*www .  j av  a 2 s.co m*/
    final DialogBuilder builder = new DialogBuilder(project);
    LanguageInjectionSupport support = InjectorUtils.findInjectionSupport(injection.getSupportId());
    if (support != null && support instanceof AbstractLanguageInjectionSupport) {
        builder.setHelpId(((AbstractLanguageInjectionSupport) support).getHelpId());
    }
    builder.addOkAction();
    builder.addCancelAction();
    builder.setDimensionServiceKey("#org.intellij.plugins.intelliLang.inject.config.ui.BaseInjectionDialog");
    builder.setCenterPanel(panel.getComponent());
    builder.setTitle(EditInjectionSettingsAction.EDIT_INJECTION_TITLE);
    builder.setOkOperation(new Runnable() {
        public void run() {
            try {
                panel.apply();
                builder.getDialogWrapper().close(DialogWrapper.OK_EXIT_CODE);
            } catch (Exception e) {
                final Throwable cause = e.getCause();
                final String message = e.getMessage() + (cause != null ? "\n  " + cause.getMessage() : "");
                Messages.showErrorDialog(project, message, "Unable to Save");
            }
        }
    });
    if (builder.show() == DialogWrapper.OK_EXIT_CODE) {
        return injection;
    }
    return null;
}

From source file:org.intellij.plugins.intelliLang.inject.java.JavaLanguageInjectionSupport.java

License:Apache License

private static BaseInjection showInjectionUI(final Project project,
        final MethodParameterInjection methodParameterInjection) {
    final AbstractInjectionPanel panel = new MethodParameterPanel(methodParameterInjection, project);
    panel.reset();/*from ww w  .ja v  a2 s . c om*/
    final DialogBuilder builder = new DialogBuilder(project);
    builder.setHelpId("reference.settings.injection.language.injection.settings.java.parameter");
    builder.addOkAction();
    builder.addCancelAction();
    builder.setCenterPanel(panel.getComponent());
    builder.setTitle(EditInjectionSettingsAction.EDIT_INJECTION_TITLE);
    builder.setOkOperation(new Runnable() {
        public void run() {
            panel.apply();
            builder.getDialogWrapper().close(DialogWrapper.OK_EXIT_CODE);
        }
    });
    if (builder.show() == DialogWrapper.OK_EXIT_CODE) {
        return new BaseInjection(methodParameterInjection.getSupportId()).copyFrom(methodParameterInjection);
    }
    return null;
}

From source file:org.intellij.plugins.intelliLang.inject.xml.XmlLanguageInjectionSupport.java

License:Apache License

@Nullable
private static BaseInjection showInjectionUI(final Project project, final BaseInjection xmlInjection) {
    final DialogBuilder builder = new DialogBuilder(project);
    final AbstractInjectionPanel panel;
    if (xmlInjection instanceof XmlTagInjection) {
        panel = new XmlTagPanel((XmlTagInjection) xmlInjection, project);
        builder.setHelpId("reference.settings.injection.language.injection.settings.xml.tag");
    } else if (xmlInjection instanceof XmlAttributeInjection) {
        panel = new XmlAttributePanel((XmlAttributeInjection) xmlInjection, project);
        builder.setHelpId("reference.settings.injection.language.injection.settings.xml.attribute");
    } else//w w  w.jav  a 2s.co m
        throw new AssertionError();
    panel.reset();
    builder.addOkAction();
    builder.addCancelAction();
    builder.setCenterPanel(panel.getComponent());
    builder.setTitle(EditInjectionSettingsAction.EDIT_INJECTION_TITLE);
    builder.setOkOperation(new Runnable() {
        public void run() {
            panel.apply();
            builder.getDialogWrapper().close(DialogWrapper.OK_EXIT_CODE);
        }
    });
    if (builder.show() == DialogWrapper.OK_EXIT_CODE) {
        return new AbstractTagInjection().copyFrom(xmlInjection);
    }
    return null;
}

From source file:org.mvnsearch.snippet.plugin.actions.CreateSnippetFileAction.java

License:Apache License

public void actionPerformed(AnActionEvent event) {
    final Project project = event.getData(PlatformDataKeys.PROJECT);
    final PsiElement psiElement = event.getData(LangDataKeys.PSI_ELEMENT);
    if (psiElement instanceof PsiDirectory) {
        final SnippetFileCreationForm form = new SnippetFileCreationForm();
        final DialogBuilder builder = new DialogBuilder(project);
        builder.setTitle("Create file from snippet");
        builder.setCenterPanel(form.getRootPanel());
        builder.setOkOperation(new Runnable() {
            public void run() {
                String result = generateFile((PsiDirectory) psiElement, form.getMnemonic(), form.getFileName(),
                        project);/*from   w w w .ja  v  a 2 s.  c  o m*/
                if (StringUtil.isEmpty(result)) { //create successfully
                    builder.getDialogWrapper().close(1);
                } else { //failed
                    builder.setTitle(result);
                }
            }
        });
        builder.showModal(true);
    }
}

From source file:org.mvnsearch.snippet.plugin.actions.EditSnippetAction.java

License:Apache License

/**
 * create or save snippet/*w ww .  j  a v  a  2s  .c  o m*/
 *
 * @param event event
 */
public void actionPerformed(final AnActionEvent event) {
    Project project = event.getData(PlatformDataKeys.PROJECT);
    final SearchPanelForm searchPanelForm = getSearchPanelForm(event);
    final Snippet currentSnippet = searchPanelForm.getCurrentSnippet();
    editForm.fillInfo(searchPanelForm.getSelectedAgent(), currentSnippet);
    //new snippet for edit
    final Snippet newSnippet = currentSnippet == null ? searchPanelForm.getSelectedAgent().constructNewSnippet()
            : currentSnippet;
    final DialogBuilder builder = new DialogBuilder(project);
    builder.setTitle("Snippet Edit(All Field Required)");
    builder.setCenterPanel(editForm.getRootPanel());
    builder.setOkActionEnabled(true);
    builder.setOkOperation(new Runnable() {
        public void run() {
            if (editForm.isInvalid()) {
                builder.setTitle("Please fill requried fields!");
                return;
            }
            builder.getDialogWrapper().close(1);
            editForm.fillSnippet(newSnippet);
            searchPanelForm.getSelectedAgent().updateSnippet(newSnippet);
            getSearchPanelForm(event).refreshSnippetInfo();
        }
    });
    builder.showModal(true);
}