package jetbrains.mps.plugin;

/*Generated by MPS */

import jetbrains.mps.annotations.GeneratedClass;
import jetbrains.mps.ide.navigation.CodeNavigationProvider;
import java.rmi.RemoteException;
import jetbrains.mps.ide.ThreadUtils;
import com.intellij.openapi.application.ApplicationManager;

@GeneratedClass(node = "r:20925211-384c-4c5f-b751-56b79dd3b32e(jetbrains.mps.plugin)/8632185942131072152", model = "r:20925211-384c-4c5f-b751-56b79dd3b32e(jetbrains.mps.plugin)")
public class IdeaCodeNavigationProvider implements CodeNavigationProvider {
  public IdeaCodeNavigationProvider() {
  }
  @Override
  public boolean navigate(final String projectPath, final String fileName, final int startLine, final int startPosition, final int endLine, final int endPosition) {
    final boolean[] result = new boolean[]{false};
    Runnable runnable = new Runnable() {
      @Override
      public void run() {
        try {
          IProjectHandler handler = MPSPlugin.getInstance().getProjectHandler(projectPath);
          if (handler != null) {
            handler.open(fileName, startLine, startPosition, endLine, endPosition);
            result[0] = true;
          }
        } catch (RemoteException e) {
          e.printStackTrace();
        }
      }
    };
    if (ThreadUtils.isInEDT()) {
      ApplicationManager.getApplication().executeOnPooledThread(runnable);
    } else {
      runnable.run();
    }
    return result[0];
  }
}
