/** Call this once to start handling callbacks. */
  protected void startMonitoring() {
    AdvancedIncQueryEngine engine = engineForMatcher();

    engine.addLifecycleListener(engineLifecycleListener);
    engine.addModelUpdateListener(listener);
    listener.notifyChanged(ChangeLevel.MATCHSET);
  }
 @Override
 public void dispose() {
   super.dispose();
   AdvancedIncQueryEngine engine = key.getEngine();
   if (engine != null) {
     engine.removeLifecycleListener(taintListener);
   }
 }
  public PatternMatcherRootContent(RootContent parent, PatternMatcherRootContentKey key) {
    super(parent);
    this.children = new ContentChildren<PatternMatcherContent>();
    this.taintListener = new ContentEngineTaintListener();
    this.mapping = Maps.newHashMap();
    this.key = key;

    AdvancedIncQueryEngine engine = key.getEngine();
    if (engine == null) {
      key.setEngine(createEngine());
    }
    if (engine != null) {
      engine.addLifecycleListener(taintListener);
    }
  }
 @Override
 public void disposeService() throws ServiceException {
   // dispose all engines initialized through the service
   for (Entry<ModelSet, IncQueryEngine> entry : engines.entrySet()) {
     AdvancedIncQueryEngine.from(entry.getValue()).dispose();
   }
 }
  private AdvancedIncQueryEngine createEngine() {
    boolean wildcardMode =
        IncQueryGUIPlugin.getDefault()
            .getPreferenceStore()
            .getBoolean(PreferenceConstants.WILDCARD_MODE);
    boolean dynamicEMFMode =
        IncQueryGUIPlugin.getDefault()
            .getPreferenceStore()
            .getBoolean(PreferenceConstants.DYNAMIC_EMF_MODE);

    try {
      AdvancedIncQueryEngine engine =
          AdvancedIncQueryEngine.createUnmanagedEngine(
              key.getNotifier(), wildcardMode, dynamicEMFMode);
      return engine;
    } catch (IncQueryException e) {
      logger.log(
          new Status(
              IStatus.ERROR,
              IncQueryGUIPlugin.PLUGIN_ID,
              "Could not retrieve IncQueryEngine for " + key.getNotifier(),
              e));
      return null;
    }
  }
  @Test
  public void execute_update() throws IncQueryException, IOException {
    ResourceSet set = new ResourceSetImpl();

    URI uri = URI.createPlatformResourceURI("/tcp2/src/tcp2/c/Closed.java", true);
    Resource res = set.getResource(uri, true);
    Resource chartRes =
        set.createResource(
            URI.createFileURI(
                "/Users/stampie/git/programunderstanding-ttc2011/transformation/hu.bme.mit.viatra2.examples.reveng.tests/tcp2.inc.statemachine"));

    AdvancedIncQueryEngine engine = AdvancedIncQueryEngine.createUnmanagedEngine(new EMFScope(set));
    UnprocessedStateClassMatcher matcher2 = UnprocessedStateClassMatcher.on(engine);
    matcher2.forEachMatch(
        new UnprocessedStateClassProcessor() {

          @Override
          public void process(Class pCl) {
            System.out.println(pCl.getName());
          }
        });
    ReengineeringTransformation transformation =
        new ReengineeringTransformation(res, chartRes, engine);
    transformation.reengineer_update();

    //		System.out.println(Joiner.on("\n").join(chartRes.getAllContents()));

    chartRes.save(null);
  }
  public IncQueryEngine initializeEngine(ModelSet set) throws IncQueryException {
    Preconditions.checkArgument(
        !engines.containsKey(set), "IncQueryEngine already initialized for model " + set);
    BaseIndexOptions options =
        new BaseIndexOptions()
            .withResourceFilterConfiguration(
                new IBaseIndexResourceFilter() {

                  @Override
                  public boolean isResourceFiltered(Resource resource) {
                    URI uri = resource.getURI();
                    if (INDEXED_AUTHORITIES.contains(uri.authority())) {
                      return false;
                    }
                    return PATHMAP_SCHEME.equals(uri.scheme());
                  }
                });
    EMFScope scope = new EMFScope(set, options);
    AdvancedIncQueryEngine engine = AdvancedIncQueryEngine.createUnmanagedEngine(scope);
    engines.put(set, engine);
    return engine;
  }
 public boolean isTainted() {
   AdvancedIncQueryEngine engine = key.getEngine();
   return (engine == null) ? true : engine.isTainted();
 }