package org.plantuml.idea.action;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.actionSystem.ex.ComboBoxAction;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.plantuml.idea.util.UIUtils;

import javax.swing.*;

/**
 * Author: Eugene Steinberg
 * Date: 3/3/13
 */
public class SelectPageAction extends ComboBoxAction {
    private int numPages = 1;
    ComboBoxButton button;

    @NotNull
    protected DefaultActionGroup createPopupActionGroup(JComponent button) {
        this.button = (ComboBoxButton) button;
        DefaultActionGroup group = new DefaultActionGroup();

        for (int i = 0; i < numPages; i++) {
            group.add(new SetPageAction(i));
        }

        return group;
    }

    public void setNumPages(int numPages) {
        this.numPages = numPages;
    }

    public void setPage(int page) {
        if (button != null) {
            button.setText(getDisplayPage(page));
        }
    }

    private static String getDisplayPage(int page) {
        return Integer.toString(page + 1);
    }


    private class SetPageAction extends AnAction {
        private int page = 0;

        private SetPageAction(int page) {
            super(getDisplayPage(page));
            this.page = page;
        }

        @Override
        public void actionPerformed(AnActionEvent anActionEvent) {
            final Project project = anActionEvent.getProject();
            if (project != null) {
                UIUtils.getToolWindow(project).setPage(project, page);
                setPage(page);
            }
        }
    }
}

@@ -248,32 +248,92 @@
 ComboBoxAction;%0A
+import com.intellij.openapi.application.ApplicationManager;%0A
 import com.intel
@@ -1065,24 +1065,30 @@
 oid setPage(
+final 
 int page) %7B%0A
@@ -1109,32 +1109,179 @@
 tton != null) %7B%0A
+            ApplicationManager.getApplication().invokeLater(new Runnable() %7B%0A                @Override%0A                public void run() %7B%0A        
             butt
@@ -1306,32 +1306,66 @@
 layPage(page));%0A
+                %7D%0A            %7D);%0A
         %7D%0A    %7D%0A

Fix thread safety exception in select page action