1// BEGIN LICENSE BLOCK
2// Version: CMPL 1.1
3//
4// The contents of this file are subject to the Cisco-style Mozilla Public
5// License Version 1.1 (the "License"); you may not use this file except
6// in compliance with the License.  You may obtain a copy of the License
7// at www.eclipse-clp.org/license.
8//
9// Software distributed under the License is distributed on an "AS IS"
10// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
11// the License for the specific language governing rights and limitations
12// under the License.
13//
14// The Original Code is  The ECLiPSe Constraint Logic Programming System.
15// The Initial Developer of the Original Code is  Cisco Systems, Inc.
16// Portions created by the Initial Developer are
17// Copyright (C) 2006 Cisco Systems, Inc.  All Rights Reserved.
18//
19// Contributor(s):
20//
21// END LICENSE BLOCK
22
23package com.parctechnologies.eclipse.visualisation;
24import com.parctechnologies.eclipse.*;
25import java.util.*;
26
27public abstract class UpdateEvent extends VisEvent
28{
29  private String interestSpecName;
30  private List elementsUpdating;
31  private static String forwardString = "forward";
32  private static String backString = "back";
33
34  static VisEvent parseFromCompoundTerm(CompoundTerm term)
35    throws VisException
36  {
37    if(term.functor().equals("update") &&
38       term.arity() == 4)
39    {
40      if(forwardString.equals(((Atom)term.arg(3)).functor()))
41      {
42        return(ForwardUpdateEvent.parseFromCompoundTerm(term));
43      }
44      if(backString.equals(((Atom)term.arg(3)).functor()))
45      {
46        return(BackUpdateEvent.parseFromCompoundTerm(term));
47      }
48    }
49    throw(new VisException("Could not parse update event from "+term));
50  }
51
52  /**
53   * Given a list of ECLiPSe 'element(Index)' terms return a list
54   * of 'Index' terms
55   */
56  protected static List getIndiciesUpdating(List elementsUpdating) {
57    ArrayList result =
58      new ArrayList(elementsUpdating.size());
59    for(Iterator it = elementsUpdating.iterator(); it.hasNext(); ) {
60      CompoundTerm element = (CompoundTerm)it.next();
61      result.add( element.arg(1) );
62    }
63    return result;
64  }
65
66  public String getInterestSpecName()
67  {
68    return(interestSpecName);
69  }
70
71  public List getElementsUpdating()
72  {
73    return(elementsUpdating);
74  }
75
76  protected void setInterestSpecName(String interestSpecName)
77  {
78    this.interestSpecName = interestSpecName;
79  }
80
81  protected void setElementsUpdating(List elementsUpdating)
82  {
83    this.elementsUpdating = elementsUpdating;
84  }
85
86}
87