You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GoToLineThread.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* *******************************************************************
  2. * Copyright (c) 1999-2001 Xerox Corporation,
  3. * 2002 Palo Alto Research Center, Incorporated (PARC).
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Public License v 2.0
  7. * which accompanies this distribution and is available at
  8. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * Helen Hawkins Converted to new interface (bug 148190)
  13. * ******************************************************************/
  14. package org.aspectj.ajde.ui.swing;
  15. import javax.swing.SwingUtilities;
  16. import org.aspectj.ajde.Ajde;
  17. import org.aspectj.ajde.EditorAdapter;
  18. import org.aspectj.bridge.IMessage;
  19. import org.aspectj.bridge.Message;
  20. /**
  21. * Used to ensure that a source line has been seeked to. Will repeatedly attempt
  22. * to seek to the line until this has succeeded.
  23. *
  24. * @author Mik Kersten
  25. */
  26. public class GoToLineThread extends Thread {
  27. private EditorAdapter editorAdapter = null;
  28. private int lineNumber = 0;
  29. private String fileToSeekTo = "";
  30. private boolean finished = false;
  31. public boolean isFinished() {
  32. return finished;
  33. }
  34. public boolean needsRetry() {
  35. return !this.isAlive() && !finished;
  36. }
  37. public GoToLineThread(String fileToSeekTo, int lineNumber, EditorAdapter editorAdapter) {
  38. this.lineNumber = lineNumber;
  39. this.fileToSeekTo = fileToSeekTo;
  40. this.editorAdapter = editorAdapter;
  41. }
  42. public void run() {
  43. while(true) {
  44. String file = editorAdapter.getCurrFile();
  45. if (file != null) {
  46. if (file.equals(this.fileToSeekTo)) {
  47. try {
  48. SwingUtilities.invokeAndWait( new Runnable() {
  49. public void run() {
  50. editorAdapter.showSourceLine(lineNumber, true);
  51. }
  52. });
  53. } catch (Exception e) {
  54. Message msg = new Message("Could not seek to line.",IMessage.ERROR,e,null);
  55. Ajde.getDefault().getMessageHandler().handleMessage(msg);
  56. }
  57. finished = true;
  58. break;
  59. }
  60. shortPause();
  61. }
  62. }
  63. }
  64. private void shortPause() {
  65. try {
  66. Thread.sleep(100);
  67. } catch (InterruptedException e) {
  68. throw new RuntimeException(e.getMessage());
  69. }
  70. }
  71. }