Package fr.zenexity.pdt.editors

Examples of fr.zenexity.pdt.editors.EditorHelper


//  @SuppressWarnings("restriction")
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    EditorHelper editor = EditorHelper.getCurrent(event);
    IProject project = editor.getProject();
    IJavaProject jProject = JavaCore.create(project);
   
    if(editor != null) {
      String relativePath = ((IFileEditorInput) editor.textEditor.getEditorInput()).getFile().getProjectRelativePath().toString();
      if (relativePath.startsWith("app/japidviews/") && relativePath.endsWith(".java")) {
        // bran: if we are in the japid derived Java template code, let's switch back to the html view
        String jFile = DirUtil.mapJavaToSrc(relativePath);
        IFile f = project.getFile(jFile);
        try {
          FilesAccess.openFile(f);
        } catch (CoreException e) {
          PlayPlugin.showError(e);
        }
        return null;   
      }
    }
   
    boolean useJapid = true;

    String line;
    String viewName = null;
    String title = editor.getTitle();
    String controllerName = title.replace(".java", "");

    String packageName = "";
    IEditorInput editorInput = editor.textEditor.getEditorInput();
   
    ITextSelection selection = (ITextSelection) editor.textEditor.getSelectionProvider().getSelection();
    IJavaElement elem = JavaUI.getEditorInputJavaElement(editorInput);
    ICompilationUnit unit = null;
    if (elem instanceof ICompilationUnit) {
      unit = (ICompilationUnit) elem;
      try {
        IPackageDeclaration[] packs = unit.getPackageDeclarations();
        if (packs.length < 1) {
          info("This action can only apply to controllers.");
          return null;
        } else {
          packageName = packs[0].getElementName();
          if (!packageName.startsWith("controllers")) {
            info("This action can only apply to controllers.");
            return null;
          }
        }
       
        // get the class declaration line
        IType type = unit.getType(controllerName);
        ITypeHierarchy superTypes = type.newSupertypeHierarchy(null);
//        String name = JapidController.class.getName(); // this will require play.jar
        String name = "cn.bran.play.JapidController";
        IType japidController = jProject.findType(name);
        if (superTypes.contains(japidController)) {
          useJapid = true;
        }
        else {
          useJapid = false;
        }
       
//        String superclassName = type.getSuperclassName();
//        if (superclassName.toLowerCase().contains("japid")) {
//          useJapid = true;
//        }
       
        // current selected elem
            IJavaElement[] elements= unit.codeSelect(selection.getOffset(), selection.getLength());
            if (elements.length > 0) {
              // TODO extract the current selection to tell if the cursor in on renderJapidXXX line
              System.out.println(elements);
            }

      } catch (JavaModelException e) {
        e.printStackTrace();
      }
    } else {
      System.out.println(elem.getElementType() + ":" + elem.getElementName());
    }

    viewName = getEnclosingActionName(selection, unit);

    int lineNo = editor.getCurrentLineNo();
    line = editor.getLine(lineNo);
    if (line.contains("render")) {
      if (!line.contains("renderJapid")) {
        Pattern pt = Pattern.compile("\"(.*)\"");
        Matcher m = pt.matcher(line);
        if (m.find()) {
View Full Code Here


   * TODO: bran: parse @{namespace.controller.action()}
   */
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    String action = null;
    EditorHelper editor = EditorHelper.getCurrent(event);
    if(editor == null) {
      return null;
    }
    else {
      action = fromView(editor);
View Full Code Here

  }

  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {

    EditorHelper editor = EditorHelper.getCurrent(event);
    if (editor != null) {
      fromEditor(event, editor);
      return null;
    }
View Full Code Here


  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    String jFile = null;
    EditorHelper editor = EditorHelper.getCurrent(event);
    if(editor != null) {
      String relativePath = ((IFileEditorInput) editor.textEditor.getEditorInput()).getFile().getProjectRelativePath().toString();
      jFile = DirUtil.mapSrcToJava(relativePath);
      IFile f = editor.getProject().getFile(jFile);
      try {
        FilesAccess.openFile(f);
      } catch (CoreException e) {
        PlayPlugin.showError(e);
      }
View Full Code Here

    }
    IDE.gotoMarker(editor, marker);
  }

  public static void goToLineContaining(IEditorPart editorPart, String text) {
    EditorHelper editor = new EditorHelper((ITextEditor) editorPart);
    String line;
    int lineNo = -1;
    int i = 0;
    int length = editor.lineCount();
    IDocument doc = editor.getDocument();
    try {
      while (i < length && lineNo < 0) {
        line = doc.get(doc.getLineOffset(i), doc.getLineLength(i));
        if (line.contains(text)) {
          lineNo = i;
View Full Code Here

  }

  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    EditorHelper editor = EditorHelper.getCurrent(event);
    IProject project = editor.getProject();
   
    String viewName = null;
    String title = editor.getTitle();
    String controllerName = title.replace(".java", "");

    String packageName = "";
    IEditorInput editorInput = editor.textEditor.getEditorInput();
   
View Full Code Here

TOP

Related Classes of fr.zenexity.pdt.editors.EditorHelper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.