001    // Java tool interface class NavigatorTool
002    // This file is generated automatically, please do not edit!
003    // generation time: Aug 17, 2007 11:11:44 AM
004    
005    package nl.cwi.sen1.gui.plugin;
006    
007    import java.util.HashSet;
008    import java.util.List;
009    import java.util.Set;
010    
011    import toolbus.SwingTool;
012    
013    import aterm.ATerm;
014    import aterm.ATermAppl;
015    import aterm.ATermFactory;
016    import aterm.ATermList;
017    
018    abstract public class NavigatorTool
019      extends SwingTool
020      implements NavigatorTif
021    {
022      // This table will hold the complete input signature
023      private Set<ATerm> sigTable = new HashSet<ATerm>();
024    
025      // Patterns that are used to match against incoming terms
026      private ATerm PselectModule0;
027      private ATerm PupdateModule0;
028      private ATerm PmarkModuleNormal0;
029      private ATerm PmarkModuleError0;
030      private ATerm PdeleteModule0;
031      private ATerm PshowPopup0;
032      private ATerm PrecAckEvent0;
033      private ATerm PrecTerminate0;
034    
035      // Mimic the constructor from the AbstractTool class
036      protected NavigatorTool(ATermFactory factory)
037      {
038        super(factory);
039        initSigTable();
040        initPatterns();
041      }
042    
043      // This method initializes the table with input signatures
044      private void initSigTable()
045      {
046        sigTable.add(factory.parse("rec-do(<navigator>,update-module(<term>,<file>))"));
047        sigTable.add(factory.parse("rec-do(<navigator>,delete-module(<term>))"));
048        sigTable.add(factory.parse("rec-do(<navigator>,select-module(<term>))"));
049        sigTable.add(factory.parse("rec-do(<navigator>,mark-module-error(<term>))"));
050        sigTable.add(factory.parse("rec-do(<navigator>,mark-module-normal(<term>))"));
051        sigTable.add(factory.parse("rec-do(<navigator>,show-popup(<term>,<list>))"));
052        sigTable.add(factory.parse("rec-ack-event(<navigator>,<term>)"));
053        sigTable.add(factory.parse("rec-terminate(<navigator>,<term>)"));
054      }
055    
056      // Initialize the patterns that are used to match against incoming terms
057      private void initPatterns()
058      {
059        PselectModule0 = factory.parse("rec-do(select-module(<term>))");
060        PupdateModule0 = factory.parse("rec-do(update-module(<term>,<term>))");
061        PmarkModuleNormal0 = factory.parse("rec-do(mark-module-normal(<term>))");
062        PmarkModuleError0 = factory.parse("rec-do(mark-module-error(<term>))");
063        PdeleteModule0 = factory.parse("rec-do(delete-module(<term>))");
064        PshowPopup0 = factory.parse("rec-do(show-popup(<term>,<term>))");
065        PrecAckEvent0 = factory.parse("rec-ack-event(<term>)");
066        PrecTerminate0 = factory.parse("rec-terminate(<term>)");
067      }
068    
069      // The generic handler calls the specific handlers
070      public ATerm handler(ATerm term)
071      {
072        List<?> result;
073    
074        result = term.match(PselectModule0);
075        if (result != null) {
076          selectModule((ATerm)result.get(0));
077          return null;
078        }
079        result = term.match(PupdateModule0);
080        if (result != null) {
081          updateModule((ATerm)result.get(0), (ATerm)result.get(1));
082          return null;
083        }
084        result = term.match(PmarkModuleNormal0);
085        if (result != null) {
086          markModuleNormal((ATerm)result.get(0));
087          return null;
088        }
089        result = term.match(PmarkModuleError0);
090        if (result != null) {
091          markModuleError((ATerm)result.get(0));
092          return null;
093        }
094        result = term.match(PdeleteModule0);
095        if (result != null) {
096          deleteModule((ATerm)result.get(0));
097          return null;
098        }
099        result = term.match(PshowPopup0);
100        if (result != null) {
101          showPopup((ATerm)result.get(0), (ATerm)result.get(1));
102          return null;
103        }
104        result = term.match(PrecAckEvent0);
105        if (result != null) {
106          recAckEvent((ATerm)result.get(0));
107          return null;
108        }
109        result = term.match(PrecTerminate0);
110        if (result != null) {
111          recTerminate((ATerm)result.get(0));
112          return null;
113        }
114    
115        notInInputSignature(term);
116        return null;
117      }
118    
119      // Check the input signature
120      public void checkInputSignature(ATermList sigs)
121      {
122        while(!sigs.isEmpty()) {
123          ATermAppl sig = (ATermAppl)sigs.getFirst();
124          sigs = sigs.getNext();
125          if (!sigTable.contains(sig)) {
126            // Sorry, but the term is not in the input signature!
127            notInInputSignature(sig);
128          }
129        }
130      }
131    
132      // This function is called when an input term
133      // was not in the input signature.
134      void notInInputSignature(ATerm t)
135      {
136        throw new RuntimeException("term not in input signature: " + t);
137      }
138    }