trace/tracebuilder/com.nokia.tracebuilder/src/com/nokia/tracebuilder/engine/TraceLocationList.java
changeset 10 ed1c9f64298a
equal deleted inserted replaced
9:14dc2103a631 10:ed1c9f64298a
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 * List of trace locations
       
    17 *
       
    18 */
       
    19 package com.nokia.tracebuilder.engine;
       
    20 
       
    21 import java.util.ArrayList;
       
    22 
       
    23 /**
       
    24  * List of trace locations.
       
    25  * 
       
    26  */
       
    27 public class TraceLocationList extends LocationListBase {
       
    28 
       
    29 	/**
       
    30 	 * Location list listeners
       
    31 	 */
       
    32 	private ArrayList<TraceLocationListListener> listeners = new ArrayList<TraceLocationListListener>();
       
    33 
       
    34 	/**
       
    35 	 * List title, returned by getTitle
       
    36 	 */
       
    37 	private String listTitle;
       
    38 
       
    39 	/**
       
    40 	 * Constructor
       
    41 	 */
       
    42 	TraceLocationList() {
       
    43 	}
       
    44 
       
    45 	/**
       
    46 	 * Constructor
       
    47 	 * 
       
    48 	 * @param listTitle
       
    49 	 *            the title of this location list
       
    50 	 */
       
    51 	TraceLocationList(String listTitle) {
       
    52 		this.listTitle = listTitle;
       
    53 	}
       
    54 
       
    55 	/**
       
    56 	 * Adds a location to this list.
       
    57 	 * 
       
    58 	 * @param location
       
    59 	 *            the location to be added
       
    60 	 */
       
    61 	void addLocation(TraceLocation location) {
       
    62 		if (TraceBuilderConfiguration.ASSERTIONS_ENABLED) {
       
    63 			if (contains(location)) {
       
    64 				TraceBuilderGlobals.getEvents().postCriticalAssertionFailed(
       
    65 						"Duplicate trace location", //$NON-NLS-1$
       
    66 						location.getConvertedName());
       
    67 			}
       
    68 		}
       
    69 		location.setLocationList(this);
       
    70 		add(location);
       
    71 		fireLocationAdded(location);
       
    72 		location.runValidityCheck();
       
    73 	}
       
    74 
       
    75 	/**
       
    76 	 * Removes a location from this list.
       
    77 	 * 
       
    78 	 * @param location
       
    79 	 *            the location to be removed
       
    80 	 */
       
    81 	void removeLocation(TraceLocation location) {
       
    82 		if (remove(location)) {
       
    83 			fireLocationRemoved(location);
       
    84 			location.setLocationList(null);
       
    85 		}
       
    86 	}
       
    87 
       
    88 	/**
       
    89 	 * Adds a location list listener to this object
       
    90 	 * 
       
    91 	 * @param listener
       
    92 	 *            the listener interface
       
    93 	 */
       
    94 	public void addLocationListListener(TraceLocationListListener listener) {
       
    95 		listeners.add(listener);
       
    96 	}
       
    97 
       
    98 	/**
       
    99 	 * Removes the location list listener
       
   100 	 * 
       
   101 	 * @param listener
       
   102 	 *            the listener interface
       
   103 	 */
       
   104 	public void removeLocationListListener(TraceLocationListListener listener) {
       
   105 		listeners.remove(listener);
       
   106 	}
       
   107 
       
   108 	/**
       
   109 	 * Creates locationAdded event to location list listeners
       
   110 	 * 
       
   111 	 * @param location
       
   112 	 *            the location that was added
       
   113 	 */
       
   114 	private void fireLocationAdded(TraceLocation location) {
       
   115 		for (TraceLocationListListener l : listeners) {
       
   116 			l.locationAdded(location);
       
   117 		}
       
   118 	}
       
   119 
       
   120 	/**
       
   121 	 * Creates locationRemoved event to location list listeners
       
   122 	 * 
       
   123 	 * @param location
       
   124 	 *            the location that was added
       
   125 	 */
       
   126 	void fireLocationRemoved(TraceLocation location) {
       
   127 		for (TraceLocationListListener l : listeners) {
       
   128 			l.locationRemoved(location);
       
   129 		}
       
   130 	}
       
   131 
       
   132 	/**
       
   133 	 * Gets the list title or null
       
   134 	 * 
       
   135 	 * @return the list title
       
   136 	 */
       
   137 	public String getListTitle() {
       
   138 		return listTitle;
       
   139 	}
       
   140 
       
   141 }