trace/tracebuilder/com.nokia.tracebuilder.view/src/com/nokia/tracebuilder/view/TraceWrapper.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 * Wrapper for one trace object
       
    17 *
       
    18 */
       
    19 package com.nokia.tracebuilder.view;
       
    20 
       
    21 import com.nokia.tracebuilder.engine.LastKnownLocationList;
       
    22 import com.nokia.tracebuilder.engine.TraceLocationList;
       
    23 import com.nokia.tracebuilder.model.Trace;
       
    24 import com.nokia.tracebuilder.model.TraceParameter;
       
    25 
       
    26 /**
       
    27  * Wrapper for one trace object
       
    28  * 
       
    29  * @see com.nokia.tracebuilder.model.Trace
       
    30  */
       
    31 final class TraceWrapper extends TraceObjectWrapper {
       
    32 
       
    33 	/**
       
    34 	 * Last known location list wrapper
       
    35 	 */
       
    36 	private LastKnownLocationListWrapper LastKnownLocationListWrapper;
       
    37 
       
    38 	/**
       
    39 	 * List of object parameters
       
    40 	 */
       
    41 	private TraceParameterListWrapper parameterListWrapper;
       
    42 
       
    43 	/**
       
    44 	 * Location list wrapper
       
    45 	 */
       
    46 	private TraceLocationListWrapper locationListWrapper;
       
    47 
       
    48 	/**
       
    49 	 * Default constructor
       
    50 	 * 
       
    51 	 * @param trace
       
    52 	 *            the trace
       
    53 	 * @param parent
       
    54 	 *            parent wrapper
       
    55 	 * @param updater
       
    56 	 *            the update notifier
       
    57 	 */
       
    58 	TraceWrapper(Trace trace, WrapperBase parent, WrapperUpdater updater) {
       
    59 		super(trace, parent, updater);
       
    60 		addParameterList();
       
    61 		TraceLocationList list = trace.getExtension(TraceLocationList.class);
       
    62 		if (list != null) {
       
    63 			setLocationList(list);
       
    64 		}
       
    65 		LastKnownLocationList plist = trace
       
    66 				.getExtension(LastKnownLocationList.class);
       
    67 		if (plist != null) {
       
    68 			setLastKnownLocationList(plist);
       
    69 		}
       
    70 	}
       
    71 
       
    72 	/*
       
    73 	 * (non-Javadoc)
       
    74 	 * 
       
    75 	 * @see com.nokia.tracebuilder.view.TraceObjectWrapper#delete()
       
    76 	 */
       
    77 	@Override
       
    78 	void delete() {
       
    79 		if (locationListWrapper != null && !contains(locationListWrapper)) {
       
    80 			locationListWrapper.delete();
       
    81 		}
       
    82 		if (LastKnownLocationListWrapper != null
       
    83 				&& !contains(LastKnownLocationListWrapper)) {
       
    84 			LastKnownLocationListWrapper.delete();
       
    85 		}
       
    86 		super.delete();
       
    87 	}
       
    88 
       
    89 	/**
       
    90 	 * Creates and adds the parameter list
       
    91 	 */
       
    92 	void addParameterList() {
       
    93 		Trace trace = (Trace) getTraceObject();
       
    94 		parameterListWrapper = new TraceParameterListWrapper(trace, this,
       
    95 				getUpdater());
       
    96 		if (trace.hasParameters()) {
       
    97 			add(parameterListWrapper);
       
    98 		}
       
    99 	}
       
   100 
       
   101 	/**
       
   102 	 * Adds a parameter to the parameter list
       
   103 	 * 
       
   104 	 * @param parameter
       
   105 	 *            the parameter to be added
       
   106 	 * @return the wrapper which needs to be refreshed
       
   107 	 */
       
   108 	WrapperBase addParameter(TraceParameter parameter) {
       
   109 		if (parameterListWrapper.hasChildren()) {
       
   110 			// If parameters already exist, the parameter list is updated
       
   111 			parameterListWrapper.addParameter(parameter);
       
   112 		} else {
       
   113 			// If not, the parameter list is added
       
   114 			parameterListWrapper.addParameter(parameter);
       
   115 			add(parameterListWrapper);
       
   116 		}
       
   117 		return this;
       
   118 	}
       
   119 
       
   120 	/**
       
   121 	 * Removes a parameter
       
   122 	 * 
       
   123 	 * @param parameter
       
   124 	 *            the parameter to be removed
       
   125 	 * @return the wrapper which needs to be refreshed
       
   126 	 */
       
   127 	WrapperBase removeParameter(TraceParameter parameter) {
       
   128 		parameterListWrapper.removeParameter(parameter);
       
   129 		// If the parameter list no longer contains elements, it is removed
       
   130 		if (!parameterListWrapper.hasChildren()) {
       
   131 			hide(parameterListWrapper);
       
   132 		}
       
   133 		return this;
       
   134 	}
       
   135 
       
   136 	/**
       
   137 	 * Sets the last known location list to this object
       
   138 	 * 
       
   139 	 * @param list
       
   140 	 *            the location list
       
   141 	 * @return the wrapper to be updated
       
   142 	 */
       
   143 	WrapperBase setLastKnownLocationList(LastKnownLocationList list) {
       
   144 		if (list != null) {
       
   145 			if (LastKnownLocationListWrapper == null) {
       
   146 				LastKnownLocationListWrapper = new LastKnownLocationListWrapper(
       
   147 						list, this, getUpdater());
       
   148 				if (LastKnownLocationListWrapper.hasChildren()) {
       
   149 					add(LastKnownLocationListWrapper);
       
   150 				}
       
   151 			} else {
       
   152 				if (LastKnownLocationListWrapper.getLocationList() != list) {
       
   153 					LastKnownLocationListWrapper.updateLocationList(list);
       
   154 				}
       
   155 			}
       
   156 		} else {
       
   157 			if (LastKnownLocationListWrapper != null) {
       
   158 				LastKnownLocationListWrapper.updateLocationList(null);
       
   159 				hide(LastKnownLocationListWrapper);
       
   160 			}
       
   161 		}
       
   162 		return this;
       
   163 	}
       
   164 
       
   165 	/**
       
   166 	 * Shows the last known locations list
       
   167 	 */
       
   168 	void showLastKnownLocationList() {
       
   169 		add(LastKnownLocationListWrapper);
       
   170 	}
       
   171 
       
   172 	/**
       
   173 	 * Hides the last known locations list
       
   174 	 */
       
   175 	void hideLastKnownLocationList() {
       
   176 		hide(LastKnownLocationListWrapper);
       
   177 	}
       
   178 
       
   179 	/**
       
   180 	 * Sets the location list to this object
       
   181 	 * 
       
   182 	 * @param list
       
   183 	 *            the location list
       
   184 	 * @return the wrapper to be updated
       
   185 	 */
       
   186 	WrapperBase setLocationList(TraceLocationList list) {
       
   187 		if (list != null) {
       
   188 			if (locationListWrapper == null) {
       
   189 				locationListWrapper = new TraceLocationListWrapper(list, this,
       
   190 						getUpdater());
       
   191 				if (locationListWrapper.hasChildren()) {
       
   192 					add(locationListWrapper);
       
   193 				}
       
   194 			} else {
       
   195 				if (locationListWrapper.getLocationList() != list) {
       
   196 					locationListWrapper.updateLocationList(list);
       
   197 				}
       
   198 			}
       
   199 		} else {
       
   200 			if (locationListWrapper != null) {
       
   201 				locationListWrapper.updateLocationList(null);
       
   202 				hide(locationListWrapper);
       
   203 			}
       
   204 		}
       
   205 		return this;
       
   206 	}
       
   207 
       
   208 	/**
       
   209 	 * Shows the location list
       
   210 	 */
       
   211 	void showLocationList() {
       
   212 		add(locationListWrapper);
       
   213 	}
       
   214 
       
   215 	/**
       
   216 	 * Hides the location list
       
   217 	 */
       
   218 	void hideLocationList() {
       
   219 		hide(locationListWrapper);
       
   220 	}
       
   221 
       
   222 	/**
       
   223 	 * Gets the location list wrapper
       
   224 	 * 
       
   225 	 * @return the list wrapper
       
   226 	 */
       
   227 	TraceLocationListWrapper getLocationListWrapper() {
       
   228 		return locationListWrapper;
       
   229 	}
       
   230 
       
   231 }