trace/tracebuilder/com.nokia.tracebuilder.view/src/com/nokia/tracebuilder/view/ListNavigator.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 navigator, which is used when a list contains more elements than should be shown at a time
       
    17 *
       
    18 */
       
    19 package com.nokia.tracebuilder.view;
       
    20 
       
    21 import com.nokia.tracebuilder.action.TraceViewActionProvider;
       
    22 
       
    23 /**
       
    24  * List navigator, which is used when a list contains more elements than should
       
    25  * be shown at a time
       
    26  * 
       
    27  */
       
    28 final class ListNavigator extends WrapperBase {
       
    29 
       
    30 	/**
       
    31 	 * Action provider
       
    32 	 */
       
    33 	private ListNavigatorActionProvider actionProvider;
       
    34 
       
    35 	/**
       
    36 	 * Index of the first element currently visible
       
    37 	 */
       
    38 	private int startIndex;
       
    39 
       
    40 	/**
       
    41 	 * Number of visible elements
       
    42 	 */
       
    43 	private int visibleCount;
       
    44 
       
    45 	/**
       
    46 	 * Total number of elements
       
    47 	 */
       
    48 	private int totalCount;
       
    49 
       
    50 	/**
       
    51 	 * Constructor
       
    52 	 * 
       
    53 	 * @param parent
       
    54 	 *            the parent wrapper
       
    55 	 * @param updater
       
    56 	 *            the update notifier
       
    57 	 */
       
    58 	protected ListNavigator(ListWrapper parent, WrapperUpdater updater) {
       
    59 		super(parent, updater);
       
    60 		actionProvider = new ListNavigatorActionProvider(parent);
       
    61 	}
       
    62 
       
    63 	/*
       
    64 	 * (non-Javadoc)
       
    65 	 * 
       
    66 	 * @see com.nokia.tracebuilder.view.WrapperBase#getChildren()
       
    67 	 */
       
    68 	@Override
       
    69 	public Object[] getChildren() {
       
    70 		return new Object[0];
       
    71 	}
       
    72 
       
    73 	/*
       
    74 	 * (non-Javadoc)
       
    75 	 * 
       
    76 	 * @see com.nokia.tracebuilder.view.WrapperBase#hasChildren()
       
    77 	 */
       
    78 	@Override
       
    79 	public boolean hasChildren() {
       
    80 		return false;
       
    81 	}
       
    82 
       
    83 	/**
       
    84 	 * Gets the start index of visible elements
       
    85 	 * 
       
    86 	 * @return the start index
       
    87 	 */
       
    88 	int getStartIndex() {
       
    89 		return startIndex;
       
    90 	}
       
    91 
       
    92 	/**
       
    93 	 * Gets the number of visible elements
       
    94 	 * 
       
    95 	 * @return the visible element count
       
    96 	 */
       
    97 	int getVisibleCount() {
       
    98 		return visibleCount;
       
    99 	}
       
   100 
       
   101 	/**
       
   102 	 * Gets the total length of elements
       
   103 	 * 
       
   104 	 * @return the total count
       
   105 	 */
       
   106 	int getTotalCount() {
       
   107 		return totalCount;
       
   108 	}
       
   109 
       
   110 	/**
       
   111 	 * Gets the action provider interface
       
   112 	 * 
       
   113 	 * @return the action provider
       
   114 	 */
       
   115 	public TraceViewActionProvider getActionProvider() {
       
   116 		return actionProvider;
       
   117 	}
       
   118 
       
   119 	/**
       
   120 	 * Sets the index to currently visible area
       
   121 	 * 
       
   122 	 * @param startIndex
       
   123 	 * @param visibleCount
       
   124 	 * @param totalCount
       
   125 	 */
       
   126 	void setIndex(int startIndex, int visibleCount, int totalCount) {
       
   127 		this.startIndex = startIndex;
       
   128 		this.visibleCount = visibleCount;
       
   129 		this.totalCount = totalCount;
       
   130 		if (startIndex + visibleCount >= totalCount) {
       
   131 			actionProvider.setNextEnabled(false);
       
   132 			actionProvider.setPreviousEnabled(true);
       
   133 		} else if (startIndex == 0) {
       
   134 			actionProvider.setNextEnabled(true);
       
   135 			actionProvider.setPreviousEnabled(false);
       
   136 		} else {
       
   137 			actionProvider.setNextEnabled(true);
       
   138 			actionProvider.setPreviousEnabled(true);
       
   139 		}
       
   140 	}
       
   141 
       
   142 }