sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi/src/com/nokia/carbide/cpp/internal/pi/visual/GenericTable.java
changeset 2 b9ab3b238396
child 5 844b047e260d
equal deleted inserted replaced
1:1050670c6980 2:b9ab3b238396
       
     1 /*
       
     2  * Copyright (c) 2009 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 the License "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  */
       
    17 
       
    18 package com.nokia.carbide.cpp.internal.pi.visual;
       
    19 
       
    20 import java.awt.Toolkit;
       
    21 import java.awt.datatransfer.Clipboard;
       
    22 import java.awt.datatransfer.StringSelection;
       
    23 import java.util.ArrayList;
       
    24 import java.util.Enumeration;
       
    25 import java.util.Vector;
       
    26 
       
    27 import org.eclipse.jface.viewers.CheckboxTableViewer;
       
    28 import org.eclipse.jface.wizard.Wizard;
       
    29 import org.eclipse.jface.wizard.WizardDialog;
       
    30 import org.eclipse.swt.SWT;
       
    31 import org.eclipse.swt.events.KeyEvent;
       
    32 import org.eclipse.swt.events.KeyListener;
       
    33 import org.eclipse.swt.events.SelectionAdapter;
       
    34 import org.eclipse.swt.events.SelectionEvent;
       
    35 import org.eclipse.swt.widgets.Decorations;
       
    36 import org.eclipse.swt.widgets.Display;
       
    37 import org.eclipse.swt.widgets.Menu;
       
    38 import org.eclipse.swt.widgets.MenuItem;
       
    39 import org.eclipse.swt.widgets.Table;
       
    40 import org.eclipse.swt.widgets.TableColumn;
       
    41 import org.eclipse.swt.widgets.TableItem;
       
    42 import org.eclipse.ui.PlatformUI;
       
    43 
       
    44 import com.nokia.carbide.cpp.internal.pi.actions.SaveSamples;
       
    45 import com.nokia.carbide.cpp.internal.pi.actions.SetThresholdsDialog;
       
    46 import com.nokia.carbide.cpp.internal.pi.interfaces.ISaveSamples;
       
    47 import com.nokia.carbide.cpp.internal.pi.interfaces.ISaveTable;
       
    48 import com.nokia.carbide.cpp.internal.pi.model.ProfiledGeneric;
       
    49 import com.nokia.carbide.cpp.internal.pi.save.SaveTableWizard;
       
    50 
       
    51 
       
    52 public abstract class GenericTable
       
    53 {
       
    54 	// table column IDs in hopes it's quicker than comparing characters
       
    55 	protected static final int COLUMN_ID_THREAD         =  1;
       
    56 	protected static final int COLUMN_ID_BINARY         =  2;
       
    57 	protected static final int COLUMN_ID_FUNCTION       =  3;
       
    58 	protected static final int COLUMN_ID_SHOW           =  4;
       
    59 	protected static final int COLUMN_ID_PERCENT_LOAD   =  5;
       
    60 //	protected static final int COLUMN_ID_COLOR          =  6;
       
    61 	protected static final int COLUMN_ID_SAMPLE_COUNT   =  7;
       
    62 	protected static final int COLUMN_ID_PATH           =  8;
       
    63 	protected static final int COLUMN_ID_IN_BINARY      =  9;
       
    64 	protected static final int COLUMN_ID_IN_BINARY_PATH = 10;
       
    65 	protected static final int COLUMN_ID_START_ADDR     = 11;
       
    66 	protected static final int COLUMN_ID_PRIORITY       = 12;
       
    67 	
       
    68 	// these are never used as actual column headers - they indicate a double sort
       
    69 	protected static final int COLUMN_ID_FULL_PATH      = 13;
       
    70 	protected static final int COLUMN_ID_FULL_IN_PATH   = 14;
       
    71 
       
    72 	protected static final int COLOR_COLUMN_INDEX = 0;
       
    73 	
       
    74 	// table column headings
       
    75 	protected static final String COLUMN_HEAD_THREAD       = Messages.getString("GenericTable.thread"); //$NON-NLS-1$
       
    76 	protected static final String COLUMN_HEAD_BINARY       = Messages.getString("GenericTable.binary"); //$NON-NLS-1$
       
    77 	protected static final String COLUMN_HEAD_FUNCTION     = Messages.getString("GenericTable.function"); //$NON-NLS-1$
       
    78 	protected static final String COLUMN_HEAD_SHOW         = Messages.getString("GenericTable.show");	// square root symbol used as check symbol //$NON-NLS-1$
       
    79 	protected static final String COLUMN_HEAD_PERCENT_LOAD = Messages.getString("GenericTable.load"); //$NON-NLS-1$
       
    80 //	protected static final String COLUMN_HEAD_COLOR        = "Color";
       
    81 	public    static final String COLUMN_HEAD_SAMPLE_COUNT = Messages.getString("GenericTable.samples"); //$NON-NLS-1$
       
    82 	protected static final String COLUMN_HEAD_PATH         = Messages.getString("GenericTable.path"); //$NON-NLS-1$
       
    83 	protected static final String COLUMN_HEAD_IN_BINARY    = Messages.getString("GenericTable.inBinary"); //$NON-NLS-1$
       
    84 	protected static final String COLUMN_HEAD_IN_BINARY_PATH = Messages.getString("GenericTable.pathOfBinary"); //$NON-NLS-1$
       
    85 	protected static final String COLUMN_HEAD_START_ADDR   = Messages.getString("GenericTable.startAddr"); //$NON-NLS-1$
       
    86 	protected static final String COLUMN_HEAD_PRIORITY     = Messages.getString("GenericTable.priority"); //$NON-NLS-1$
       
    87 	protected static final String COLUMN_HEAD_MEMORY_CHUNKS = Messages.getString("GenericTable.chunks"); //$NON-NLS-1$
       
    88 	protected static final String COLUMN_HEAD_MEMORY_STACK  = Messages.getString("GenericTable.stackHeap"); //$NON-NLS-1$
       
    89 	protected static final String COLUMN_HEAD_MEMORY_TOTAL  = Messages.getString("GenericTable.memoryTotal"); //$NON-NLS-1$
       
    90 	protected static final String COLUMN_HEAD_MEMORY_NAME   = Messages.getString("GenericTable.threadProcess"); //$NON-NLS-1$
       
    91 
       
    92 	// table column widths
       
    93 	protected static final int COLUMN_WIDTH_SHOW           =  40;
       
    94 	protected static final int COLUMN_WIDTH_PERCENT_LOAD   =  52;
       
    95 //	protected static final int COLUMN_WIDTH_COLOR_MIN      =  22;
       
    96 //	protected static final int COLUMN_WIDTH_COLOR_MAX      =  60;
       
    97     protected static final int COLUMN_WIDTH_THREAD_NAME    = 300;
       
    98     protected static final int COLUMN_WIDTH_FUNCTION_NAME  = 300;
       
    99     protected static final int COLUMN_WIDTH_BINARY_NAME    = 130;
       
   100     protected static final int COLUMN_WIDTH_PATH           = 250;
       
   101     protected static final int COLUMN_WIDTH_START_ADDRESS  =  80;
       
   102     protected static final int COLUMN_WIDTH_SAMPLE_COUNT   =  84;
       
   103     protected static final int COLUMN_WIDTH_HEAP           =  80;
       
   104     protected static final int COLUMN_WIDTH_STACK          =  80;
       
   105     protected static final int COLUMN_WIDTH_PRIORITY       =  85;
       
   106     protected static final int COLUMN_WIDTH_IN_BINARY      =  65;
       
   107     protected static final int COLUMN_WIDTH_IN_BINARY_PATH =  80;
       
   108     protected static final int COLUMN_WIDTH_8_DIGIT_HEX    = 100;
       
   109 	protected static final int COLUMN_WIDTH_MEMORY_CHUNKS  =  80;
       
   110 	protected static final int COLUMN_WIDTH_MEMORY_STACK   =  80;
       
   111 	protected static final int COLUMN_WIDTH_MEMORY_TOTAL   =  80;
       
   112 	protected static final int COLUMN_WIDTH_MEMORY_NAME    = 300;
       
   113     
       
   114     // colors are now included with the checkbox column
       
   115     protected static final int COLOR_COLUMN = 0;
       
   116     
       
   117 	// NOTE: This text value must be unique to this column, but not
       
   118 	// discernible to the eye. It is used to find the checkbox column
       
   119     // when you have a table item without its column number
       
   120     protected static final String SHOW_ITEM_VALUE = Messages.getString("GenericTable.space"); //$NON-NLS-1$
       
   121     
       
   122     // type of checkbox column - none, just a checkbox, checkbox with visible text
       
   123     protected static final int CHECKBOX_NONE    = 0;
       
   124     protected static final int CHECKBOX_NO_TEXT = 1;
       
   125     protected static final int CHECKBOX_TEXT    = 2;
       
   126     
       
   127     // create a CheckboxTableViewer, which contains a Table
       
   128 	protected CheckboxTableViewer tableViewer;
       
   129     protected Table table;
       
   130 
       
   131     protected Vector<ProfiledGeneric> tableItemData = new Vector<ProfiledGeneric>();
       
   132     protected Vector<Object> columnData    = new Vector<Object>();
       
   133     
       
   134     // provide a routine for actions relating to the table
       
   135     abstract public void action(String actionString);
       
   136 	
       
   137 	// pop-up menu for table
       
   138 	protected Menu contextMenu;
       
   139 	
       
   140 	// class for matching samples against checked items in an table
       
   141 	public class AllInclude {
       
   142 		public int totalItems;					// total number of threads, binaries, etc.
       
   143 		public ArrayList<Object> list = null;	// threads, binaries, etc. checked
       
   144 	}
       
   145 
       
   146 	//optimized for performance, grrr
       
   147 	Object[] finalValues = null;
       
   148 	public Object[] getSelectedValues()
       
   149 	{
       
   150  		Display.getDefault().syncExec(new Runnable(){
       
   151 			public void run(){
       
   152 				if ((table == null) || (table.isDisposed()))
       
   153 					finalValues = new Object[0];
       
   154 				else {
       
   155 					Object[] values = new Object[table.getSelectionCount()];
       
   156 					TableItem[] selectedItems = table.getSelection();
       
   157 					for (int i = 0; i < values.length; i++)
       
   158 					{
       
   159 					    values[i] = selectedItems[i].getData();
       
   160 					}
       
   161 					
       
   162 					finalValues = values;
       
   163 				}
       
   164 			}
       
   165 		});
       
   166 		return finalValues;
       
   167 	}
       
   168     
       
   169     //Only used in custom traces
       
   170     public Object[] getSelectedValueString()
       
   171 	{
       
   172 		if (table == null)
       
   173 			return new Object[0];
       
   174 		
       
   175 		Object[] values = new Object[table.getSelectionCount()];
       
   176 		TableItem[] selectedItems = table.getSelection();
       
   177 		for (int i = 0; i < values.length; i++)
       
   178 		{
       
   179 			if (selectedItems[i].getData() instanceof ProfiledGeneric) {
       
   180 				values[i] = ((ProfiledGeneric)selectedItems[i].getData()).getNameString();
       
   181 			}
       
   182 		}
       
   183 		return values;
       
   184 	}
       
   185     
       
   186 	public void setSelectedIndices(int[] indices)
       
   187 	{
       
   188 		if ((indices == null) || (table == null))
       
   189 			return;
       
   190 
       
   191 	    // only select the indicated indices
       
   192         table.deselectAll();
       
   193         for (int j = 0; j < indices.length; j++)
       
   194         {
       
   195             table.select(indices[j]);
       
   196         }
       
   197 	}
       
   198 	
       
   199 	public void setSelectedIndicesXOR(int[] indices)
       
   200 	{
       
   201 		if ((indices == null) || (table == null))
       
   202 			return;
       
   203 
       
   204 		// reverse the selection status of the indicated indices
       
   205         for (int j = 0; j < indices.length; j++)
       
   206         {
       
   207             if (table.isSelected(indices[j]))
       
   208             {
       
   209                 table.deselect(indices[j]);
       
   210             }
       
   211             else
       
   212             {
       
   213                 table.select(indices[j]);
       
   214             }
       
   215         }
       
   216 	}
       
   217 	
       
   218 	public Integer getIndex(Object anObject)
       
   219 	{
       
   220 		if (anObject == null)
       
   221 			return null;
       
   222 
       
   223 	    int counter = 0;
       
   224 	    Enumeration<ProfiledGeneric> e = tableItemData.elements();
       
   225 	    while (e.hasMoreElements())
       
   226 	    {
       
   227 	        if (e.nextElement().equals(anObject))
       
   228 	        {
       
   229 	            return new Integer(counter);
       
   230 	        }
       
   231 	        counter++;
       
   232 	    }
       
   233 	    return null;
       
   234 	}
       
   235 	
       
   236 	public int[] getIndices(Object[] objects)
       
   237 	{
       
   238 	    if (objects == null)
       
   239 	    	return null;
       
   240 	    
       
   241 	    int indexCount = 0;
       
   242         int[] indices = new int[objects.length];
       
   243 	    for (int i = 0; i < objects.length; i++)
       
   244 	    {
       
   245 	        Integer index = getIndex(objects[i]);
       
   246 	        if (index != null)
       
   247 	        {
       
   248 	            indices[i] = index.intValue();
       
   249 	            indexCount++;
       
   250 	        }
       
   251 	    }
       
   252 	    if (indexCount != 0)
       
   253 	        return indices;
       
   254 	    else
       
   255 	        return null;
       
   256 	}
       
   257 	
       
   258 	public Menu getTablePopupMenu(Decorations parent, boolean enableSelected) {
       
   259 	    Menu tablePopupMenu = new Menu(parent, SWT.POP_UP);
       
   260 
       
   261 	    getCheckRows(tablePopupMenu, enableSelected);
       
   262 		new MenuItem(tablePopupMenu, SWT.SEPARATOR);
       
   263 		getRecolorItem(tablePopupMenu, Messages.getString("GenericTable.items"), enableSelected); //$NON-NLS-1$
       
   264 		new MenuItem(tablePopupMenu, SWT.SEPARATOR);
       
   265 		getChangeThresholds(tablePopupMenu);
       
   266 		tablePopupMenu.setVisible(true);
       
   267 
       
   268 		return tablePopupMenu;
       
   269 	}
       
   270 
       
   271 	public class TableKeyListener implements KeyListener {
       
   272 
       
   273 		// listener for ctrl-A (select all rows), ctrl-C (copy highlighted rows to clipboard), etc.
       
   274 		public void keyPressed(KeyEvent event) {
       
   275 			// check for exact match of CTRL-A/CTRL-C/etc. (do not match CTRL-SHIFT-A, for example)
       
   276 			if (event.stateMask == SWT.CTRL) {
       
   277 				if (event.character == 1) { // Ctrl-A
       
   278 					action("selectAll"); //$NON-NLS-1$
       
   279 				} else if (event.character == 3) { // Ctrl-C
       
   280 					action("copy"); //$NON-NLS-1$
       
   281 				}
       
   282 			}
       
   283 		}
       
   284 
       
   285 		public void keyReleased(KeyEvent event) {
       
   286 		}
       
   287 		
       
   288 	}
       
   289 
       
   290 	protected MenuItem getSortFullPathItem(Menu menu, boolean enabled) {
       
   291 	    MenuItem fullPathItem = new MenuItem(menu, SWT.PUSH);
       
   292 
       
   293 	    fullPathItem.setText(Messages.getString("GenericTable.sortByPath")); //$NON-NLS-1$
       
   294 		fullPathItem.setEnabled(enabled);
       
   295 
       
   296 		if (enabled) {
       
   297 			fullPathItem.addSelectionListener(new SelectionAdapter() { 
       
   298 				public void widgetSelected(SelectionEvent e) {
       
   299 				    action("sortfullpath"); //$NON-NLS-1$
       
   300 				}
       
   301 			});
       
   302 		}
       
   303 
       
   304 		return fullPathItem;
       
   305 	}
       
   306 
       
   307 	protected MenuItem getSortInFullPathItem(Menu menu, boolean enabled) {
       
   308 	    MenuItem fullPathItem = new MenuItem(menu, SWT.PUSH);
       
   309 
       
   310 		fullPathItem.setText(Messages.getString("GenericTable.sortByInPath")); //$NON-NLS-1$
       
   311 		fullPathItem.setEnabled(enabled);
       
   312 		
       
   313 		if (enabled) {
       
   314 			fullPathItem.addSelectionListener(new SelectionAdapter() { 
       
   315 				public void widgetSelected(SelectionEvent e) {
       
   316 				    action("sortinfullpath"); //$NON-NLS-1$
       
   317 				}
       
   318 			});
       
   319 		}
       
   320 
       
   321 		return fullPathItem;
       
   322 	}
       
   323 
       
   324 	protected MenuItem getSelectAllItem(Menu menu, boolean enabled) {
       
   325 	    MenuItem selectAllItem = new MenuItem(menu, SWT.PUSH);
       
   326 	    
       
   327 		selectAllItem.setText(Messages.getString("GenericTable.selectAll")); //$NON-NLS-1$
       
   328 		selectAllItem.setEnabled(enabled);
       
   329 		
       
   330 		if (enabled) {
       
   331 			selectAllItem.addSelectionListener(new SelectionAdapter() { 
       
   332 				public void widgetSelected(SelectionEvent e) {
       
   333 				    action("selectAll"); //$NON-NLS-1$
       
   334 				}
       
   335 			});
       
   336 		}
       
   337 		
       
   338 		return selectAllItem;
       
   339 	}
       
   340 
       
   341 	protected MenuItem getCopyItem(Menu menu, boolean enabled) {
       
   342 	    MenuItem copyItem = new MenuItem(menu, SWT.PUSH);
       
   343 	    
       
   344 		copyItem.setText(Messages.getString("GenericTable.copy")); //$NON-NLS-1$
       
   345 		copyItem.setEnabled(enabled);
       
   346 		
       
   347 		if (enabled) {
       
   348 			copyItem.addSelectionListener(new SelectionAdapter() { 
       
   349 				public void widgetSelected(SelectionEvent e) {
       
   350 				    action("copy"); //$NON-NLS-1$
       
   351 				}
       
   352 			});
       
   353 		}
       
   354 		
       
   355 		return copyItem;
       
   356 	}
       
   357 
       
   358 	protected MenuItem getCopyTableItem(Menu menu, boolean enabled) {
       
   359 	    MenuItem copyTableItem = new MenuItem(menu, SWT.PUSH);
       
   360 
       
   361 		copyTableItem.setText(Messages.getString("GenericTable.copyTable")); //$NON-NLS-1$
       
   362 		copyTableItem.setEnabled(enabled);
       
   363 		
       
   364 		if (enabled) {
       
   365 			copyTableItem.addSelectionListener(new SelectionAdapter() { 
       
   366 				public void widgetSelected(SelectionEvent e) {
       
   367 					action("copyTable"); //$NON-NLS-1$
       
   368 				}
       
   369 			});
       
   370 		}
       
   371 	
       
   372 		return copyTableItem;
       
   373 	}
       
   374 	
       
   375 	protected MenuItem getSaveTableItem(Menu menu, boolean enabled) {
       
   376 	    MenuItem saveTableItem = new MenuItem(menu, SWT.PUSH);
       
   377 
       
   378 		saveTableItem.setText(Messages.getString("GenericTable.saveTable")); //$NON-NLS-1$
       
   379 		saveTableItem.setEnabled(enabled);
       
   380 		
       
   381 		if (enabled) {
       
   382 			saveTableItem.addSelectionListener(new SelectionAdapter() { 
       
   383 				public void widgetSelected(SelectionEvent e) {
       
   384 					action("saveTable"); //$NON-NLS-1$
       
   385 				}
       
   386 			});
       
   387 		}
       
   388 	
       
   389 		return saveTableItem;
       
   390 	}
       
   391 
       
   392 	private MenuItem getAddRows(Menu menu, boolean enabled) {
       
   393 	    MenuItem addRows = new MenuItem(menu, SWT.PUSH);
       
   394 	    
       
   395 		addRows.setText(Messages.getString("GenericTable.checkHighlighted")); //$NON-NLS-1$
       
   396 		addRows.setEnabled(enabled);
       
   397 
       
   398 		if (enabled) {
       
   399 			addRows.addSelectionListener(new SelectionAdapter() { 
       
   400 				public void widgetSelected(SelectionEvent e) {
       
   401 				    action("add"); //$NON-NLS-1$
       
   402 				}
       
   403 			});
       
   404 		}
       
   405 
       
   406 		return addRows;
       
   407 	}
       
   408 
       
   409 	private MenuItem getRemoveRows(Menu menu, boolean enabled) {
       
   410 	    MenuItem removeRows = new MenuItem(menu, SWT.PUSH);
       
   411 	    
       
   412 		removeRows.setText(Messages.getString("GenericTable.uncheckHighlighted")); //$NON-NLS-1$
       
   413 		removeRows.setEnabled(enabled);
       
   414 		
       
   415 		if (enabled) {
       
   416 			removeRows.addSelectionListener(new SelectionAdapter() { 
       
   417 				public void widgetSelected(SelectionEvent e) {
       
   418 				    action("remove"); //$NON-NLS-1$
       
   419 				}
       
   420 			});
       
   421 		}
       
   422 
       
   423 		return removeRows;
       
   424 	}
       
   425 
       
   426 	private MenuItem getAddAllRows(Menu menu) {
       
   427 	    MenuItem addAllRows = new MenuItem(menu, SWT.PUSH);
       
   428 	    
       
   429 		addAllRows.setText(Messages.getString("GenericTable.checkAll")); //$NON-NLS-1$
       
   430 		addAllRows.addSelectionListener(new SelectionAdapter() { 
       
   431 			public void widgetSelected(SelectionEvent e) {
       
   432 			    action("addall"); //$NON-NLS-1$
       
   433 			}
       
   434 		});
       
   435 		return addAllRows;
       
   436 	}
       
   437 
       
   438 	private MenuItem getRemoveAllRows(Menu menu) {
       
   439 	    MenuItem removeAllRows = new MenuItem(menu, SWT.PUSH);
       
   440 
       
   441 		removeAllRows.setText(Messages.getString("GenericTable.uncheckAll")); //$NON-NLS-1$
       
   442 		removeAllRows.addSelectionListener(new SelectionAdapter() { 
       
   443 			public void widgetSelected(SelectionEvent e) {
       
   444 			    action("removeall"); //$NON-NLS-1$
       
   445 			}
       
   446 		});
       
   447 		return removeAllRows;
       
   448 	}
       
   449 
       
   450 	public void getCheckRows(Menu menu, boolean enableSelected) {
       
   451 		// check highlighted items
       
   452 		getAddRows(menu, enableSelected);
       
   453 		
       
   454 		// uncheck highlighted items
       
   455 		getRemoveRows(menu, enableSelected);
       
   456 		
       
   457 		// check all rows
       
   458 		getAddAllRows(menu);
       
   459 		
       
   460 		// uncheck all rows
       
   461 		getRemoveAllRows(menu);
       
   462 	}
       
   463 	
       
   464 	protected MenuItem getRecolorItem(Menu menu, String itemType, boolean enabled) {
       
   465 	    MenuItem recolorItem = new MenuItem(menu, SWT.PUSH);
       
   466 
       
   467 	    recolorItem.setText(Messages.getString("GenericTable.recolor1") + itemType + Messages.getString("GenericTable.recolor2")); //$NON-NLS-1$ //$NON-NLS-2$
       
   468 	    recolorItem.setEnabled(enabled);
       
   469 	    
       
   470 	    if (enabled) {
       
   471 	    	recolorItem.addSelectionListener(new SelectionAdapter() { 
       
   472 				public void widgetSelected(SelectionEvent e) {
       
   473 				    action("recolor"); //$NON-NLS-1$
       
   474 				}
       
   475 			});
       
   476 	    }
       
   477 
       
   478 	    return recolorItem;
       
   479 	}
       
   480 
       
   481 	protected MenuItem getChangeThresholds(Menu menu) {
       
   482 	    MenuItem thresholdItem = new MenuItem(menu, SWT.PUSH);
       
   483 
       
   484 		thresholdItem.setText(Messages.getString("GenericTable.changeThresholds")); //$NON-NLS-1$
       
   485 		thresholdItem.addSelectionListener(new SelectionAdapter() { 
       
   486 			public void widgetSelected(SelectionEvent e) {
       
   487 				// get the original thresholds
       
   488 				// get the new thresholds
       
   489 				new SetThresholdsDialog(e.display);
       
   490 			}
       
   491 		});
       
   492 		return thresholdItem;
       
   493 	}
       
   494 
       
   495 	protected MenuItem getSourceLookUpItem(Menu menu, String itemType) {
       
   496 	    MenuItem sourceLookupItem = new MenuItem(menu, SWT.PUSH);
       
   497 
       
   498 	    sourceLookupItem.setText(Messages.getString("GenericTable.sourcelookup"));	//$NON-NLS-1$
       
   499 		sourceLookupItem.addSelectionListener(new SelectionAdapter() { 
       
   500 			public void widgetSelected(SelectionEvent e) {
       
   501 			    action("sourceLookup"); //$NON-NLS-1$
       
   502 			}
       
   503 		});
       
   504 		return sourceLookupItem;
       
   505 	}	
       
   506 
       
   507 	protected MenuItem getDisabledSourceLookUpItem(Menu menu, String itemType) {
       
   508 	    MenuItem disabledSourceLookupItem = new MenuItem(menu, SWT.PUSH);
       
   509 
       
   510 	    disabledSourceLookupItem.setText(Messages.getString("GenericTable.sourcelookup"));	//$NON-NLS-1$
       
   511 		disabledSourceLookupItem.setEnabled(false);
       
   512 		return disabledSourceLookupItem;
       
   513 	}
       
   514 	
       
   515 	
       
   516 	protected String copyHeading(Table table, int checkboxType, String separator, String ending)
       
   517 	{
       
   518 		String copyString = ""; //$NON-NLS-1$
       
   519 		String addString;
       
   520 		int[] columnOrder = table.getColumnOrder();
       
   521 		
       
   522 		for (int i = 0; i < table.getColumnCount(); i++) {
       
   523 			TableColumn tableColumn = table.getColumn(columnOrder[i]);
       
   524 			if (i > 0)
       
   525 				copyString += separator;
       
   526 			
       
   527 			// Note: this code assumes that the original column 0 has the checkbox
       
   528 			if (columnOrder[i] == 0 && checkboxType != CHECKBOX_NONE) {
       
   529 				copyString += Messages.getString("GenericTable.checked");  //$NON-NLS-1$
       
   530 				if (checkboxType == CHECKBOX_TEXT) {
       
   531 					copyString += separator;
       
   532 					addString = tableColumn.getText();
       
   533 					if (addString.indexOf(separator) == -1)
       
   534 						copyString += addString;
       
   535 					else
       
   536 						copyString += "\"" + addString + "\""; //$NON-NLS-1$ //$NON-NLS-2$
       
   537 				}
       
   538 			}
       
   539 			else {
       
   540 				copyString += tableColumn.getText();
       
   541 			}
       
   542 		}
       
   543 		
       
   544 		return copyString + ending;
       
   545 	}
       
   546 
       
   547 	protected String copySelected(Table table, int checkboxType, String separator, String ending)
       
   548 	{
       
   549 		String copyString = ""; //$NON-NLS-1$
       
   550 		int[] columnOrder = table.getColumnOrder();
       
   551 		boolean[] isHex   = (boolean[]) table.getData("isHex"); //$NON-NLS-1$
       
   552 
       
   553 		int selectionCount = table.getSelectionCount();
       
   554 		
       
   555 		for (int i = 0; (selectionCount > 0) && i < table.getItemCount(); i++)
       
   556 		{
       
   557 			if (table.isSelected(i))
       
   558 			{
       
   559 				selectionCount--;
       
   560 				copyString += copyRow(isHex, table.getItem(i), checkboxType, table.getColumnCount(), columnOrder, separator) + ending;
       
   561 			}
       
   562 		}
       
   563 		
       
   564 		return copyString;
       
   565 	}
       
   566 
       
   567 	protected String copyTable(Table table, int checkboxType, String separator, String ending)
       
   568 	{
       
   569 		String copyString = ""; //$NON-NLS-1$
       
   570 		int[] columnOrder = table.getColumnOrder();
       
   571 		boolean[] isHex   = (boolean[]) table.getData("isHex"); //$NON-NLS-1$
       
   572 
       
   573 		for (int i = 0; i < table.getItemCount(); i++)
       
   574 			copyString += copyRow(isHex, table.getItem(i), checkboxType, table.getColumnCount(), columnOrder, separator) + ending;
       
   575 		
       
   576 		return copyString;
       
   577 	}
       
   578 	
       
   579 	protected String copyRow(boolean[] isHex, TableItem item, int checkboxType, int columnCount, int[] columnOrder, String separator)
       
   580 	{
       
   581 		String copyString = ""; //$NON-NLS-1$
       
   582 		String addString;
       
   583 		for (int i = 0; i < columnCount; i++) {
       
   584 			if (i > 0)
       
   585 				copyString += separator;
       
   586 			
       
   587 			int realColumn = columnOrder[i];
       
   588 			
       
   589 			// Note: this code assumes that the original column 0 has the checkbox
       
   590 			if (realColumn == 0 && checkboxType != CHECKBOX_NONE) {
       
   591 				copyString += item.getChecked() ? Messages.getString("GenericTable.true") : Messages.getString("GenericTable.false"); //$NON-NLS-1$ //$NON-NLS-2$
       
   592 				if (checkboxType == CHECKBOX_TEXT) {
       
   593 					copyString += separator;
       
   594 					addString = item.getText(realColumn);
       
   595 					if ((isHex != null) && (isHex.length > realColumn) && isHex[realColumn] && addString.length() > 0) {
       
   596 						String string = "00000000" + addString; //$NON-NLS-1$
       
   597 						copyString += "0x" + string.substring(string.length() - 8); //$NON-NLS-1$
       
   598 					}
       
   599 					else {
       
   600 						if (addString.indexOf(separator) == -1)
       
   601 							copyString += addString;
       
   602 						else
       
   603 							copyString += "\"" + addString + "\""; //$NON-NLS-1$ //$NON-NLS-2$
       
   604 					}
       
   605 				}
       
   606 			}
       
   607 			else {
       
   608 				addString = item.getText(realColumn);
       
   609 				if ((isHex != null) && (isHex.length > realColumn) && isHex[realColumn] && addString.length() > 0) {
       
   610 					String string = "00000000" + addString; //$NON-NLS-1$
       
   611 					copyString += "0x" + string.substring(string.length() - 8); //$NON-NLS-1$
       
   612 				}
       
   613 				else {
       
   614 					if (addString.indexOf(separator) == -1)
       
   615 						copyString += addString;
       
   616 					else
       
   617 						copyString += "\"" + addString + "\""; //$NON-NLS-1$ //$NON-NLS-2$
       
   618 				}
       
   619 			}
       
   620 		}
       
   621 		
       
   622 		return copyString;
       
   623 	}
       
   624 
       
   625 	public CheckboxTableViewer getTableViewer() {
       
   626 		return this.tableViewer;
       
   627 	}
       
   628 
       
   629 	public Table getTable() {
       
   630 		return this.table;
       
   631 	}
       
   632 
       
   633     protected void actionSelectAll()
       
   634     {
       
   635         this.table.selectAll();
       
   636         this.table.redraw();
       
   637     }
       
   638     
       
   639     public String getCopyString(Table table, int checkboxType, boolean copyTable, String separator, String ending)
       
   640     {
       
   641 		// copy all (copyTable == true) or part of a single table to the clipboard or to a file
       
   642         String copyString;
       
   643 
       
   644 		// copy the column headings, followed by the desired table rows
       
   645 		if (copyTable) {
       
   646 			copyString = copyHeading(table, checkboxType, separator, ending);
       
   647 			copyString += copyTable(table, checkboxType, separator, ending);
       
   648 		}
       
   649 		else
       
   650 			copyString = copySelected(table, checkboxType, separator, ending);
       
   651 		
       
   652 		return copyString;
       
   653     }
       
   654     
       
   655     // class to pass table to the save wizard
       
   656     public class SaveTableString implements ISaveTable {
       
   657     	private Table table;
       
   658     	private int checkboxType;
       
   659     	private String separator;
       
   660     	private String ending;
       
   661     	
       
   662     	public SaveTableString(Table table, int checkboxType, String separator, String ending) {
       
   663     		this.table        = table;
       
   664     		this.checkboxType = checkboxType;
       
   665     		this.separator    = separator;
       
   666     		this.ending       = ending;
       
   667 		}
       
   668 
       
   669     	public String getData() {
       
   670 			return getCopyString(table, checkboxType, true, separator, ending);
       
   671 		}
       
   672     }
       
   673 
       
   674 	protected void actionCopyOrSave(boolean doCopy, Table table, int checkboxType, boolean copyTable, String separator, String ending)
       
   675 	{
       
   676 		// copy all (copyTable == true) or part of a single table to the clipboard or to a file
       
   677 		if (doCopy) {
       
   678 			// change the clipboard contents
       
   679 	        Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
       
   680 	        String copyString = getCopyString(table, checkboxType, copyTable, separator, ending);
       
   681 			StringSelection contents = new StringSelection(copyString);
       
   682 	        cb.setContents(contents, contents);
       
   683 		} else {
       
   684 			// save to a file
       
   685 			SaveTableString getString = new SaveTableString(table, checkboxType, separator, ending);
       
   686 			WizardDialog dialog;
       
   687 			Wizard wizard = new SaveTableWizard(getString);
       
   688 			dialog = new WizardDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), wizard);
       
   689 	    	dialog.open();
       
   690 		}
       
   691 	}
       
   692 
       
   693 	protected void actionSaveSamples(ISaveSamples saveSamples)
       
   694 	{
       
   695 		new SaveSamples(saveSamples);
       
   696 	}
       
   697 }