/**
  * Return whether an event was generated. Assumes a SemanticRecorder is active.
  *
  * @throws RecordingFailedException if an error was encountered.
  */
 private boolean saveSemanticEvent() throws RecordingFailedException {
   Log.log("Storing event from current semantic recorder");
   try {
     Step step = semanticRecorder.getStep();
     if (step != null) {
       insertStep(step);
       setStatus("Added " + step);
     } else {
       setStatus("No semantic event found, events skipped");
     }
     semanticRecorder = null;
     return step != null;
   } catch (BugReport bug) {
     // changed to windowtester exception
     //   throw new RecordingFailedException(bug);
     throw new com.windowtester.swing.recorder.RecordingFailedException(bug);
   } catch (Exception e) {
     Log.log("Recording failed when saving action: " + e);
     // 1/3/07 kp: change message to windowtester message
     // String msg = Strings.get("editor.recording.exception");
     String msg = "Windowtester recording exception";
     //     throw new RecordingFailedException(new BugReport(msg, e));
     throw new com.windowtester.swing.recorder.RecordingFailedException(new BugReport(msg, e));
   }
 }
  /**
   * Handle an event. This can either be ignored or contribute to the recording. For a given event,
   * if no current semantic recorder is active, select one based on the event's component. If the
   * semantic recorder accepts the event, then it is used to consume each subsequent event, until
   * its recordEvent method returns true, indicating that the semantic event has completed.
   */
  protected void recordEvent(java.awt.AWTEvent event) throws RecordingFailedException {

    // Discard any key/button release events at the start of the recording.
    if (steps.size() == 0 && event.getID() == KeyEvent.KEY_RELEASED) {
      Log.log("Ignoring initial release event");
      return;
    }

    SemanticRecorder newRecorder = null;

    // Process extraneous key modifiers used to simulate mouse buttons
    // Only check events while we have no semantic recorder, though,
    // because we wish to ignore everything between the modifiers
    if (Platform.isMacintosh() && semanticRecorder == null) {
      if (pruneClickModifiers(event)) return;
    }

    if (semanticRecorder == null) {
      SemanticRecorder sr =
          (event.getSource() instanceof Component)
              ? getSemanticRecorder((Component) event.getSource())
              // Use ComponentRecorder for MenuComponents
              : getSemanticRecorder(Component.class);
      if (sr.accept(event)) {
        semanticRecorder = newRecorder = sr;
        setStatus("Recording semantic event with " + sr);
        if (event.getSource() instanceof JInternalFrame) {
          // Ideally, adding an extra listener would be done by the
          // JInternalFrameRecorder, but the object needs more state
          // than is available to the recorder (notably to be able
          // to send events to the primary recorder).  If something
          // else turns up similar to this, then the EventRecorder
          // should be made available to the semantic recorders.
          //
          // Must add a listener, since COMPONENT_HIDDEN is not sent
          // on JInternalFrame close (1.4.1).
          JInternalFrame f = (JInternalFrame) event.getSource();
          new InternalFrameWatcher(f);
        }
      }
    }

    // If we're currently recording a semantic event, continue to do so
    if (semanticRecorder != null) {
      boolean consumed = semanticRecorder.record(event);
      boolean finished = semanticRecorder.isFinished();
      if (finished) {
        Log.debug("Semantic recorder is finished");
        saveSemanticEvent();
      }
      // If not consumed, need to check for semantic recorder (again)
      // (but avoid recursing indefinitely)
      if (!consumed && newRecorder == null) {
        Log.debug("Event was not consumed, parse it again");
        recordEvent(event);
      }
    } else {
      captureRawEvent(event);
    }
  }
Beispiel #3
0
  /**
   * Copies the gold folder to the runtime workspace CONTRACT: folder exists in the devspace,
   * goldFolder has been set In this implementation, the gold folder is copied from
   * bin/test/GoldFolder
   */
  public static void copyGoldFolder() {
    /* goldFolder (location where goldfolder should go in runspace) must not be null */
    Assert.assertTrue(goldFolder != null);

    Bundle model2testsBundle = EclipsePlugin.getDefault().getBundle();
    /* this is the source for our goldfolder in the devspace that we're copying to the runspace */
    URL gfURL = model2testsBundle.getEntry("/");

    /* devspace GoldFolder must exist */
    // Assert.assertTrue(goldFolder.exists());
    // Assert.assertTrue(gf.exists());
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot workspaceRoot = workspace.getRoot();
    IPath rootPath = workspaceRoot.getLocation();
    try {
      gfURL = Platform.asLocalURL(gfURL);
    } catch (IOException e) {
      e.printStackTrace();
    }
    System.out.println("URL path: " + gfURL.getPath());
    System.out.println("URL file: " + gfURL.getFile());
    System.out.println("URL ref: " + gfURL.getRef());
    File srcDir = new File(gfURL.getPath(), "GoldFolder");
    Path p = new Path(gfURL.getPath());
    IResource igf = ((Workspace) workspace).newResource(p, IResource.FOLDER);
    IPath gfpath = goldFolder.getFullPath();
    File destDir = new File(gfpath.toOSString());
    /* Make sure both of these directories exist */
    System.out.println("Source directory exists: " + srcDir.exists());
    /* destination directory shouldn't exist because we're going to create it */
    // System.out.println ("Dest directory exists: " + destDir.exists());
    /* Since assert isn't working for the moment... */
    if (!srcDir.exists()) {
      System.out.println("GoldFolder not found");
      Log.log("GoldFolder not found");
      Assert.fail("GoldFolder not found");
    }
    //		Assert.assertTrue("Source goldfolder does not exist", srcDir.exists());
    //		Assert.assertTrue("Destination goldfolder does not exist", destDir.exists());
    copyFolder(srcDir, destDir);
  }
 public void terminate() throws RecordingFailedException {
   Log.log("EventRecorder terminated");
   if (semanticRecorder != null) {
     saveSemanticEvent();
   }
 }