src/main/java/xelfi/debugger/ThreadsView.java
author Jaroslav Tulach <jaroslav.tulach@xelfi.cz>
Tue, 17 Jan 2017 21:12:37 +0100
branchDirtyFix
changeset 10 fe294d0f1297
parent 0 189280700bc7
permissions -rw-r--r--
Making the project compilable
     1 /**
     2  * ThreadsView
     3  *
     4  * @author Roman Blazevic
     5  * @version 970208
     6  */
     7 
     8 package xelfi.debugger;
     9 
    10 import java.awt.*;
    11 import xelfi.top.TopDialog;
    12 import xelfi.top.TopLevel;
    13 
    14 /*
    15  * This is a view on the data given by the Debugger.
    16  * It is a view on thread groups and threads in the debugged application.
    17  */
    18 
    19 public class ThreadsView extends TopDialog
    20 {
    21 	private Debugger document;
    22 	private List list;
    23 
    24 	static final int KEY_ENTER = 10;
    25 
    26 	static final int HINT_COMPLETE_UPDATE = 0;
    27 
    28 	/**
    29 	 * ThreadsView constructor.
    30 	 *
    31 	 * debugger - the document for this view
    32 	 */
    33 	ThreadsView(Debugger debugger)
    34 	{
    35 		super(TopLevel.getMenu(), false);
    36 		setTitle("Threads");
    37 		//super("Threads");
    38  		setBackground(Color.lightGray);
    39 
    40 		document = debugger;
    41 		list = new List();
    42 		add("Center", list);
    43 	}
    44 
    45 	/**
    46 	 * My handleEvent() implementation.
    47 	 */
    48 	public boolean handleEvent(Event event)
    49 	{
    50 		if (event.id == Event.KEY_PRESS && event.key == 18) // Ctrl+R - refresh
    51 		{
    52 			update(HINT_COMPLETE_UPDATE, -1);
    53 			return true;
    54 		}
    55 
    56 		if (!(event.id == Event.KEY_PRESS && event.key == KEY_ENTER)
    57 			&& !(event.id == Event.ACTION_EVENT))
    58 			return super.handleEvent(event);
    59 
    60 		int selectedIndex = list.getSelectedIndex();
    61 
    62 		if (selectedIndex == -1)
    63 			return true;
    64 
    65 	/*        RemoteThreadGroup[] rtg = document.getThreadGroups();
    66 
    67 		if (rtg == null)
    68 		{
    69 			Output output = TopLevel.getOutput();
    70 
    71 			update(HINT_COMPLETE_UPDATE, -1);
    72 			output.show();
    73 			output.println("\"Threads\" window was out of date and updated");
    74 			return true;
    75 		}
    76 
    77 		RemoteThreadGroup ctg = null;
    78 		RemoteThread ct = null;
    79 		int lineIndex = 0;
    80 		int threadGroupIndex = 1;
    81 
    82 		for(int i = 0; i < rtg.length; i++)
    83 			try
    84 			{
    85 				// without "system" thread groups (system and main groups)
    86 				if (rtg[i].getName().compareTo("system") == 0 ||
    87 					rtg[i].getName().compareTo("main") == 0)
    88 					continue;
    89 
    90 				String string = " ["+(threadGroupIndex)+"] "+rtg[i].getName();
    91 
    92 				if (!list.getItem(lineIndex).equals(string))
    93 				{
    94 					Output output = TopLevel.getOutput();
    95 
    96 					update(HINT_COMPLETE_UPDATE, -1);
    97 					output.show();
    98 					output.println("\"Threads\" window was out of date and updated");
    99 					return true;
   100 				}
   101 				else
   102 					if (lineIndex == selectedIndex)
   103 						return true;
   104 
   105 				RemoteThread rt[] = rtg[i].listThreads(true);
   106 
   107 				threadGroupIndex++;
   108 				lineIndex++;
   109 
   110 				for(int j = 0; j < rt.length; j++)
   111 				{
   112 					string = "      "+rt[j].getName()+" : "+rt[j].getStatus();
   113 
   114 					if (lineIndex == selectedIndex && list.getItem(lineIndex).equals(string))
   115 					{
   116 						ct = rt[j];
   117 						break;
   118 					}
   119 
   120 					lineIndex++;
   121 				}
   122 
   123 				if (ct != null) // it was finally found
   124 				{
   125 					ctg = rtg[i];
   126 					break;
   127 				}
   128 			}
   129 			catch(Exception e)
   130 			{
   131 				e.printStackTrace();
   132 			}
   133 
   134 			if (ct == null)
   135 			{
   136 				Output output = TopLevel.getOutput();
   137 
   138 				update(HINT_COMPLETE_UPDATE, -1);
   139 				output.show();
   140 				output.println("\"Threads\" window was out of date and updated");
   141 				return true;
   142 			}
   143 
   144 			try
   145 			{
   146 				if (ct.getStatus().equals("at breakpoint")
   147 					//|| ct.getStatus().equals("suspended")
   148 					)
   149 					document.threadChosen(ctg, ct);
   150 				else
   151 				{
   152 					Output output = TopLevel.getOutput();
   153 
   154 					output.show();
   155 					output.println("thread is not at breakpoint");
   156 					//output.println("thread is not suspended or at breakpoint");
   157 					return true;
   158 				}
   159 			}
   160 			catch(Exception e)
   161 			{
   162 				e.printStackTrace();
   163 			}*/
   164 
   165 		return true;
   166 	}
   167 
   168 	/**
   169 	 * This method is called when the content of the view must be
   170 	 * updated.
   171 	 */
   172 	void update(int hint, int index)
   173 	{
   174 		if (!isVisible())
   175 			return;
   176 
   177 		if (hint != HINT_COMPLETE_UPDATE)
   178 		{
   179 			System.out.println("unsupported hint");
   180 			return;
   181 		}
   182 
   183         return;
   184 		
   185 	}
   186 
   187 	/**
   188 	 * My show() implementation.
   189 	 */
   190 	public void show()
   191 	{
   192 		super.show();
   193 	}
   194 }