src/Tools/jEdit/src/session_dockable.scala
author wenzelm
Thu Sep 01 16:58:41 2011 +0200 (2011-09-01)
changeset 44641 101c117494cd
parent 44617 5db68864a967
child 44672 07dad1433cd7
permissions -rw-r--r--
sort wrt. theory name;
wenzelm@43282
     1
/*  Title:      Tools/jEdit/src/session_dockable.scala
wenzelm@39515
     2
    Author:     Makarius
wenzelm@39515
     3
wenzelm@39515
     4
Dockable window for prover session management.
wenzelm@39515
     5
*/
wenzelm@39515
     6
wenzelm@39515
     7
package isabelle.jedit
wenzelm@39515
     8
wenzelm@39515
     9
wenzelm@39515
    10
import isabelle._
wenzelm@39515
    11
wenzelm@39515
    12
import scala.actors.Actor._
wenzelm@44609
    13
import scala.swing.{FlowPanel, Button, TextArea, Label, ListView,
wenzelm@44609
    14
  ScrollPane, TabbedPane, Component, Swing}
wenzelm@39638
    15
import scala.swing.event.{ButtonClicked, SelectionChanged}
wenzelm@39593
    16
wenzelm@43520
    17
import java.lang.System
wenzelm@39593
    18
import java.awt.BorderLayout
wenzelm@44609
    19
import javax.swing.JList
wenzelm@39697
    20
import javax.swing.border.{BevelBorder, SoftBevelBorder}
wenzelm@39515
    21
wenzelm@39515
    22
import org.gjt.sp.jedit.View
wenzelm@39515
    23
wenzelm@39515
    24
wenzelm@39515
    25
class Session_Dockable(view: View, position: String) extends Dockable(view: View, position: String)
wenzelm@39515
    26
{
wenzelm@39591
    27
  /* main tabs */
wenzelm@39591
    28
wenzelm@43661
    29
  private val readme = new HTML_Panel("SansSerif", 14)
wenzelm@43661
    30
  readme.render_document(Isabelle_System.try_read(List(Path.explode("$JEDIT_HOME/README.html"))))
wenzelm@39591
    31
wenzelm@44609
    32
  val status = new ListView(Nil: List[String])
wenzelm@44609
    33
  status.peer.setLayoutOrientation(JList.VERTICAL_WRAP)
wenzelm@44609
    34
  status.selection.intervalMode = ListView.IntervalMode.Single
wenzelm@44609
    35
wenzelm@39629
    36
  private val syslog = new TextArea(Isabelle.session.syslog())
wenzelm@39591
    37
wenzelm@39591
    38
  private val tabs = new TabbedPane {
wenzelm@39591
    39
    pages += new TabbedPane.Page("README", Component.wrap(readme))
wenzelm@44609
    40
    pages += new TabbedPane.Page("Theory Status", new ScrollPane(status))
wenzelm@44609
    41
    pages += new TabbedPane.Page("System Log", new ScrollPane(syslog))
wenzelm@39638
    42
wenzelm@39638
    43
    selection.index =
wenzelm@39638
    44
    {
wenzelm@39638
    45
      val index = Isabelle.Int_Property("session-panel.selection", 0)
wenzelm@39638
    46
      if (index >= pages.length) 0 else index
wenzelm@39638
    47
    }
wenzelm@39638
    48
    listenTo(selection)
wenzelm@39638
    49
    reactions += {
wenzelm@39638
    50
      case SelectionChanged(_) =>
wenzelm@39638
    51
        Isabelle.Int_Property("session-panel.selection") = selection.index
wenzelm@39638
    52
    }
wenzelm@39591
    53
  }
wenzelm@39591
    54
wenzelm@39591
    55
  set_content(tabs)
wenzelm@39515
    56
wenzelm@39515
    57
wenzelm@39593
    58
  /* controls */
wenzelm@39593
    59
wenzelm@39635
    60
  val session_phase = new Label(Isabelle.session.phase.toString)
wenzelm@39697
    61
  session_phase.border = new SoftBevelBorder(BevelBorder.LOWERED)
wenzelm@39697
    62
  session_phase.tooltip = "Prover status"
wenzelm@39635
    63
wenzelm@39702
    64
  private val logic = Isabelle.logic_selector(Isabelle.Property("logic"))
wenzelm@39702
    65
  logic.listenTo(logic.selection)
wenzelm@39702
    66
  logic.reactions += {
wenzelm@39702
    67
    case SelectionChanged(_) => Isabelle.Property("logic") = logic.selection.item.name
wenzelm@39702
    68
  }
wenzelm@39702
    69
wenzelm@44335
    70
  private val controls = new FlowPanel(FlowPanel.Alignment.Right)(session_phase, logic)
wenzelm@39593
    71
  add(controls.peer, BorderLayout.NORTH)
wenzelm@39593
    72
wenzelm@39593
    73
wenzelm@44609
    74
  /* component state -- owned by Swing thread */
wenzelm@44609
    75
wenzelm@44617
    76
  private var nodes_status: Map[Document.Node.Name, String] = Map.empty
wenzelm@44609
    77
wenzelm@44615
    78
  private def handle_changed(changed_nodes: Set[Document.Node.Name])
wenzelm@44609
    79
  {
wenzelm@44609
    80
    Swing_Thread.now {
wenzelm@44613
    81
      // FIXME correlation to changed_nodes!?
wenzelm@44613
    82
      val state = Isabelle.session.current_state()
wenzelm@44613
    83
      state.recent_stable.map(change => change.version.get_finished) match {
wenzelm@44613
    84
        case None =>
wenzelm@44613
    85
        case Some(version) =>
wenzelm@44613
    86
          var nodes_status1 = nodes_status
wenzelm@44613
    87
          for {
wenzelm@44613
    88
            name <- changed_nodes
wenzelm@44613
    89
            node <- version.nodes.get(name)
wenzelm@44613
    90
            val status = Isar_Document.node_status(state, version, node)
wenzelm@44617
    91
          } nodes_status1 += (name -> status.toString)
wenzelm@44613
    92
wenzelm@44613
    93
          if (nodes_status != nodes_status1) {
wenzelm@44613
    94
            nodes_status = nodes_status1
wenzelm@44617
    95
            val order =
wenzelm@44641
    96
              Library.sort_wrt((name: Document.Node.Name) => name.theory,
wenzelm@44641
    97
                nodes_status.keySet.toList)
wenzelm@44617
    98
            status.listData = order.map(name => name.theory + " " + nodes_status(name))
wenzelm@44613
    99
          }
wenzelm@44609
   100
      }
wenzelm@44609
   101
    }
wenzelm@44609
   102
  }
wenzelm@44609
   103
wenzelm@44609
   104
wenzelm@39515
   105
  /* main actor */
wenzelm@39515
   106
wenzelm@39515
   107
  private val main_actor = actor {
wenzelm@39515
   108
    loop {
wenzelm@39515
   109
      react {
wenzelm@43721
   110
        case input: Isabelle_Process.Input =>
wenzelm@43721
   111
wenzelm@39589
   112
        case result: Isabelle_Process.Result =>
wenzelm@39625
   113
          if (result.is_syslog)
wenzelm@39625
   114
            Swing_Thread.now {
wenzelm@39629
   115
              val text = Isabelle.session.syslog()
wenzelm@39626
   116
              if (text != syslog.text) {
wenzelm@39626
   117
                syslog.text = text
wenzelm@39626
   118
              }
wenzelm@39625
   119
            }
wenzelm@39589
   120
wenzelm@39701
   121
        case phase: Session.Phase =>
wenzelm@39696
   122
          Swing_Thread.now { session_phase.text = " " + phase.toString + " " }
wenzelm@39635
   123
wenzelm@44609
   124
        case changed: Session.Commands_Changed => handle_changed(changed.nodes)
wenzelm@44609
   125
wenzelm@39515
   126
        case bad => System.err.println("Session_Dockable: ignoring bad message " + bad)
wenzelm@39515
   127
      }
wenzelm@39515
   128
    }
wenzelm@39515
   129
  }
wenzelm@39515
   130
wenzelm@39635
   131
  override def init() {
wenzelm@39635
   132
    Isabelle.session.raw_messages += main_actor
wenzelm@39635
   133
    Isabelle.session.phase_changed += main_actor
wenzelm@44609
   134
    Isabelle.session.commands_changed += main_actor
wenzelm@39635
   135
  }
wenzelm@39635
   136
wenzelm@39635
   137
  override def exit() {
wenzelm@39635
   138
    Isabelle.session.raw_messages -= main_actor
wenzelm@39635
   139
    Isabelle.session.phase_changed -= main_actor
wenzelm@44609
   140
    Isabelle.session.commands_changed -= main_actor
wenzelm@39635
   141
  }
wenzelm@39515
   142
}