Examples of JavaEditor


Examples of org.eclipse.jdt.internal.ui.javaeditor.JavaEditor

    final IDocument document = textViewer.getDocument();
    if (document == null) {
      return null;
    }
   
    final JavaEditor javaEditor = (JavaEditor) getAdapter(JavaEditor.class);
    Assert.isNotNull(javaEditor);

    String wicketId = null;
    String wcName = null;
    /* java file region, html file region, properties file region */
 
View Full Code Here

Examples of org.eclipse.jdt.internal.ui.javaeditor.JavaEditor

     */
    @Test
    public void testSwitchToJavaFile() {
        Preferences.setTemplateFileExtension(LoomConstants.HTML_FILE_EXTENSION);
        EditorFileOpener.getInstance().switchToTemplateOrJavaFile(templateFile);
        JavaEditor currentEditor = (JavaEditor) getActiveEditor();
        IFileEditorInput input = (IFileEditorInput) currentEditor.getEditorInput();
        Assert.assertEquals("Wizard.java", input.getFile().getName());
    }
View Full Code Here

Examples of org.eclipse.jdt.internal.ui.javaeditor.JavaEditor

    final IDocument document = textViewer.getDocument();
    if (document == null) {
      return null;
    }
    final JavaEditor editor = (JavaEditor) getAdapter(JavaEditor.class);
    Assert.isNotNull(editor);

    String wicketId = null;
    String wcName = null;
    /* java file region, html file region, properties file region */
 
View Full Code Here

Examples of org.eclipse.jdt.internal.ui.javaeditor.JavaEditor

    public static void standardize(IEditorPart editor) {
        if (!(editor instanceof JavaEditor)) {
            return;
        }

        JavaEditor textEditor = (JavaEditor) editor;
        int caretPosition = textEditor.getViewer().getSelectedRange().x;

        IDocument document = textEditor.getDocumentProvider().getDocument(
                textEditor.getEditorInput());
        StringBuffer buffer = new StringBuffer(document.get());

        // Replace tabs with spaces
        for (int i = 0; i >= 0;) {
            i = buffer.indexOf("\t", i);
            if (i >= 0) {
                try {
                    document.replace(i, 1, "    ");
                    buffer.replace(i, i + 1, "    ");
                    if (i < caretPosition) {
                        caretPosition += 3;
                    }
                    i += 3;
                } catch (BadLocationException e) {
                    OutputConsole.outputError(e.getMessage());
                }
                i++;
            }
        }

        // Remove trailing spaces
        boolean finished = false;
        for (int eolPos = 0; !finished;) {
            char chr = '\0';

            int bufLength = buffer.length();
            int eolSize = 1;
            for (; eolPos < bufLength; eolPos++) {
                chr = buffer.charAt(eolPos);
                if (chr == '\n' || chr == '\r') {
                    break;
                }
            }

            if (eolPos == bufLength) {
                finished = true;
            } else {
                if (chr == '\r' && eolPos + 1 < bufLength
                        && buffer.charAt(eolPos + 1) == '\n') {
                    eolSize++;
                    eolPos++;
                }
            }

            int spaceStart = eolPos - eolSize;
            for (; spaceStart >= 0; spaceStart--) {
                if (buffer.charAt(spaceStart) != ' ') {
                    break;
                }
            }
            if (spaceStart + eolSize < eolPos) {
                try {
                    document.replace(spaceStart + 1, eolPos
                            - (spaceStart + eolSize), "");
                    buffer.replace(spaceStart + 1, eolPos - eolSize + 1, "");
                    if (eolPos < caretPosition) {
                        caretPosition -= eolPos - (spaceStart + eolSize);
                    } else if (spaceStart < caretPosition
                            && eolPos >= caretPosition) {
                        caretPosition -= caretPosition - (spaceStart + 1);
                    }
                    eolPos = spaceStart + eolSize;
                } catch (BadLocationException e) {
                    OutputConsole.outputError(e.getMessage());
                }
            }
            eolPos++;
        }

        // Add a new line to the end of file
        int docLength = document.getLength();
        try {
            if (docLength == 0
                    || (!document.get(docLength - 1, 1).equals("\n") && !document
                            .get(docLength - 1, 1).equals("\r"))) {
                document.replace(docLength, 0, "\n");
            }
        } catch (BadLocationException e) {
            OutputConsole.outputError(e.getMessage());
        }

        textEditor.getViewer().setSelectedRange(caretPosition, 0);
    }
View Full Code Here

Examples of org.eclipse.jdt.internal.ui.javaeditor.JavaEditor

        if (runnable == null) {
            return;
        }

        JavaEditor editor = _editor;

        if (editor == null) {
            return;
        }

        IWorkbenchPartSite site = editor.getSite();

        if (site == null) {
            return;
        }
View Full Code Here

Examples of org.eclipse.jdt.internal.ui.javaeditor.JavaEditor

  /**
   * Tests when the editor is no longer the active part:
   */
  @Test
  public void testEditorDeactivated() throws Exception {
    final JavaEditor editor = closeAndOpenEditor();

    // Set the editor to select the package declaration:
    int offset = getDocument(editor).get().indexOf(pkg.getElementName());
    int len = pkg.getElementName().length();
    editor.getSelectionProvider().setSelection(new TextSelection(offset, len));

    // Run the tracker to capture the event:
    long preStart = System.currentTimeMillis();
    tracker.setEnabled(true); // Start
    long postStart = System.currentTimeMillis();

    Thread.sleep(20);

    long preEnd = System.currentTimeMillis();
    // Sets another view to be active to cause the editor to lose focus:
    editor.getSite().getPage().showView(getRandomView().getId());
    long postEnd = System.currentTimeMillis();

    // One data should be in the collection (the selected package declaration):
    assertEquals(1, tracker.getData().size());
    JavaEvent event = tracker.getData().iterator().next();
View Full Code Here

Examples of org.eclipse.jdt.internal.ui.javaeditor.JavaEditor

   * Tests that events are recorded properly with the different states of the
   * editor.
   */
  @Test
  public void testEditorDeactivatedThenActivated() throws Exception {
    JavaEditor editor = closeAndOpenEditor();

    // Set the editor to select the package declaration:
    int offset = getDocument(editor).get().indexOf(pkg.getElementName());
    int len = pkg.getElementName().length();
    editor.getSelectionProvider().setSelection(new TextSelection(offset, len));

    // Now run the tracker to capture the event:
    long preStart = System.currentTimeMillis();
    tracker.setEnabled(true);
    long postStart = System.currentTimeMillis();

    Thread.sleep(20);

    long preEnd = System.currentTimeMillis();
    editor.getSite().getPage().showView(getRandomView().getId());
    long postEnd = System.currentTimeMillis();

    // One data should be in the collection (the selected package declaration):
    assertEquals(1, tracker.getData().size());
    JavaEvent event = tracker.getData().iterator().next();

    long start = event.getInterval().getStartMillis();
    long end = event.getInterval().getEndMillis();
    checkTime(preStart, start, postStart, preEnd, end, postEnd);
    assertEquals(getElementAtOffset(editor), event.getElement());

    // Now we activate the editor again to see if the tracker will start to
    // track events again:
    tracker.flushData();

    preStart = System.currentTimeMillis();
    editor.getSite().getPage().activate(editor);
    postStart = System.currentTimeMillis();

    Thread.sleep(20);

    preEnd = System.currentTimeMillis();
    editor.getSite().getPage().showView(getRandomView().getId());
    postEnd = System.currentTimeMillis();

    // One data should be in the collection (the selected package declaration):
    assertEquals(1, tracker.getData().size());
    event = tracker.getData().iterator().next();
View Full Code Here

Examples of org.eclipse.jdt.internal.ui.javaeditor.JavaEditor

  /**
   * Test when the user changes from working on a Java element to another.
   */
  @Test
  public void testElementChanged() throws Exception {
    JavaEditor editor = closeAndOpenEditor();

    // Set the editor to select the package declaration:
    IDocument document = getDocument(editor);
    int offset = document.get().indexOf(pkg.getElementName());
    int len = pkg.getElementName().length();
    editor.getSelectionProvider().setSelection(new TextSelection(offset, len));

    // Keeps the reference of the package declaration for testing latter:
    final IJavaElement element = getElementAtOffset(editor);

    // Run the tracker to capture the event:
    long preStart = System.currentTimeMillis();
    tracker.setEnabled(true);
    long postStart = System.currentTimeMillis();

    Thread.sleep(20);

    // Change the element the user is working on:
    offset = document.get().indexOf(unit.getTypes()[0].getElementName());
    int line = document.getLineOfOffset(offset);
    StyledText text = editor.getViewer().getTextWidget();
    text.setCaretOffset(document.getLineOffset(line));
    text.insert(" ");

    long preEnd = System.currentTimeMillis();
    text.notifyListeners(SWT.KeyDown, new Event());
View Full Code Here

Examples of org.eclipse.jdt.internal.ui.javaeditor.JavaEditor

   * When the tracker is set to enable, but if there is no active workbench
   * window, no data will be collected.
   */
  @Test
  public void testEnable_noActiveWorkbenchWindow() throws Exception {
    JavaEditor editor = closeAndOpenEditor();

    // Set the editor to select the package declaration:
    int offset = getDocument(editor).get().indexOf(unit.getElementName());
    int len = unit.getElementName().length();
    editor.getSelectionProvider().setSelection(new TextSelection(offset, len));

    // Open a new shell to cause the workbench window to lose focus:
    Shell shell = null;
    try {
      shell = new Shell(Display.getCurrent());
View Full Code Here

Examples of org.eclipse.jdt.internal.ui.javaeditor.JavaEditor

    }
  }

  @Test
  public void testEnableThenDisable() throws Exception {
    JavaEditor editor = closeAndOpenEditor();

    // Set the editor to select the package declaration:
    String className = unit.getTypes()[0].getElementName();
    int offset = getDocument(editor).get().indexOf(className);
    int len = className.length();
    editor.getSelectionProvider().setSelection(new TextSelection(offset, len));

    // Run the tracker to capture the event:
    long preStart = System.currentTimeMillis();
    tracker.setEnabled(true);
    long postStart = System.currentTimeMillis();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.