Search in sources :

Example 1 with ApplicationConfigurationType

use of com.intellij.execution.application.ApplicationConfigurationType in project intellij-community by JetBrains.

the class CreateSnapShotAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
    if (project == null || view == null) {
        return;
    }
    final PsiDirectory dir = view.getOrChooseDirectory();
    if (dir == null)
        return;
    final SnapShotClient client = new SnapShotClient();
    List<RunnerAndConfigurationSettings> appConfigurations = new ArrayList<>();
    RunnerAndConfigurationSettings snapshotConfiguration = null;
    boolean connected = false;
    ApplicationConfigurationType cfgType = ApplicationConfigurationType.getInstance();
    List<RunnerAndConfigurationSettings> racsi = RunManager.getInstance(project).getConfigurationSettingsList(cfgType);
    for (RunnerAndConfigurationSettings config : racsi) {
        if (config.getConfiguration() instanceof ApplicationConfiguration) {
            ApplicationConfiguration appConfig = (ApplicationConfiguration) config.getConfiguration();
            appConfigurations.add(config);
            if (appConfig.ENABLE_SWING_INSPECTOR) {
                SnapShooterConfigurationSettings settings = SnapShooterConfigurationSettings.get(appConfig);
                snapshotConfiguration = config;
                if (settings.getLastPort() > 0) {
                    try {
                        client.connect(settings.getLastPort());
                        connected = true;
                    } catch (IOException ex) {
                        connected = false;
                    }
                }
            }
            if (connected)
                break;
        }
    }
    if (snapshotConfiguration == null) {
        snapshotConfiguration = promptForSnapshotConfiguration(project, appConfigurations);
        if (snapshotConfiguration == null)
            return;
    }
    if (!connected) {
        int rc = Messages.showYesNoDialog(project, UIDesignerBundle.message("snapshot.run.prompt"), UIDesignerBundle.message("snapshot.title"), Messages.getQuestionIcon());
        if (rc == Messages.NO)
            return;
        final ApplicationConfiguration appConfig = (ApplicationConfiguration) snapshotConfiguration.getConfiguration();
        final SnapShooterConfigurationSettings settings = SnapShooterConfigurationSettings.get(appConfig);
        settings.setNotifyRunnable(() -> SwingUtilities.invokeLater(() -> {
            Messages.showMessageDialog(project, UIDesignerBundle.message("snapshot.prepare.notice"), UIDesignerBundle.message("snapshot.title"), Messages.getInformationIcon());
            try {
                client.connect(settings.getLastPort());
            } catch (IOException ex) {
                Messages.showMessageDialog(project, UIDesignerBundle.message("snapshot.connection.error"), UIDesignerBundle.message("snapshot.title"), Messages.getErrorIcon());
                return;
            }
            runSnapShooterSession(client, project, dir, view);
        }));
        try {
            ExecutionEnvironmentBuilder.create(DefaultRunExecutor.getRunExecutorInstance(), snapshotConfiguration).buildAndExecute();
        } catch (ExecutionException ex) {
            Messages.showMessageDialog(project, UIDesignerBundle.message("snapshot.run.error", ex.getMessage()), UIDesignerBundle.message("snapshot.title"), Messages.getErrorIcon());
        }
    } else {
        runSnapShooterSession(client, project, dir, view);
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) IdeView(com.intellij.ide.IdeView) ApplicationConfigurationType(com.intellij.execution.application.ApplicationConfigurationType) Project(com.intellij.openapi.project.Project) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) ExecutionException(com.intellij.execution.ExecutionException) ApplicationConfiguration(com.intellij.execution.application.ApplicationConfiguration)

Aggregations

ExecutionException (com.intellij.execution.ExecutionException)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 ApplicationConfiguration (com.intellij.execution.application.ApplicationConfiguration)1 ApplicationConfigurationType (com.intellij.execution.application.ApplicationConfigurationType)1 IdeView (com.intellij.ide.IdeView)1 Project (com.intellij.openapi.project.Project)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1