alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  
insertTag("\n", -1); // /*!!! #36306 hack insertTag(" insertTag(" insertTag(" insertTag(" insertTag(" *
  • types pref at caret position *
  • triggers code completion *
  • enters index-th element from completion list *
  • types suf at caret position * * @param pref prefix * @param suf sufix * @param index index of inserting item, -1 => */ final protected void insertTag(String pref, String suf, int index) { insert(pref); if (index < 0) { showCompl(NO_WAIT); } else { showCompl(NO_EMPTY); } for (int i = 0; i < index; i++) { down(); } if (index > -1) { enter(); } //!!! sometime completion doesn't finish on time sleepTest(500); insert(suf); } /** Types a text at caret position * * @param txt String */ protected final void insert(String txt) { editor.txtEditorPane().typeText(txt); } /** Moves caret about x lines and y rows * * @param x delta X * @param y delta Y */ protected final void move(int x, int y) { col += y; editor.setCaretPosition(editor.getLineNumber() + x, col); } /** Saves the document */ protected final void save() { editor.save(); } /** Clears the document */ protected final void clearText() { col = 0; JTextComponentOperator text = new JTextComponentOperator(editor); text.setText("X"); //!!! because clearText is to slow. text.clearText(); } /** Triggers code completion in given mode. *
      *
    • NO_WAIT - only trigger completion and continue *
    • EMPTY - trigger completion and wait for completion list *
    • NO_EMPTY - trigger completion and wait for non-empty completion list *
    */ protected final void showCompl(int mode) { editor.pressKey(KeyEvent.VK_SPACE, InputEvent.CTRL_MASK); if (mode == NO_WAIT) { return; } else if (mode == NO_EMPTY) { waitCompl(1); } else if (mode == EMPTY) { waitCompl(0); } } /** Triggers code completion and checks if completion list contains at least * minSize items. * @param minSize */ protected final void checkCompletion(int minSize) { showCompl(NO_WAIT); waitCompl(minSize); esc(); } /** Waits completion list with at least minSize items. * @param minSize - nuber of items */ private void waitCompl(int minSize) { CompletionChooser completionChoser = new CompletionChooser(minSize); ListCompletionView completionView = (ListCompletionView) ComponentOperator .waitComponent((Container) editor.getWindowContainerOperator().getSource() , completionChoser); int size = completionView.getModel().getSize(); } /** Searches for a completion listh with at least minSize items */ private class CompletionChooser implements ComponentChooser { int minSize; public CompletionChooser() { this(0); } public CompletionChooser(int minSize) { this.minSize = minSize; } public boolean checkComponent(Component component) { //System.out.println("> " + component); if (component instanceof ListCompletionView) { ListCompletionView cmpl = (ListCompletionView) component; if (cmpl.getModel().getSize() >= minSize) return true; } return false; } public String getDescription() { return("Instace of ScrollCompletionPane"); } } // KEYS /** Deletes given number of characters from current caret possition. * Position of caret will not change. * @param length number of characters to be deleted */ protected final void delete(int len) { editor.delete(len); } /** Deletes given number of characters before current caret possition. * @param length number of characters to be deleted */ protected final void backSp(int len) { for (int i = 0; i < len; i++) { editor.pushKey(KeyEvent.VK_BACK_SPACE); } } /** Presses key [ESC] */ protected final void esc() { editor.pressKey(KeyEvent.VK_ESCAPE); } /** Presses key [ENTER] */ protected final void enter() { editor.pressKey(KeyEvent.VK_ENTER); } /** Presses key [DOWN] */ protected final void down() { editor.pressKey(KeyEvent.VK_DOWN); } /** Presses key [UP] */ protected final void up() { editor.pressKey(KeyEvent.VK_UP); } /** Presses key [LEFT] */ protected final void left() { editor.pressKey(KeyEvent.VK_LEFT); } /** Presses key [RIGHT] */ protected final void right() { editor.pressKey(KeyEvent.VK_RIGHT); } /** Presses key [END] */ protected final void end() { editor.pressKey(KeyEvent.VK_END); } /** Main method for debuging purpose * * @param args */ public static void main(String[] args) { //JamController.setFast(false); DEBUG = true; TestRunner.run(CompletionJTest.class); } }
  • What this is

    This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

    Other links

    The source code

    /*
     *                 Sun Public License Notice
     *
     * The contents of this file are subject to the Sun Public License
     * Version 1.0 (the "License"). You may not use this file except in
     * compliance with the License. A copy of the License is available at
     * http://www.sun.com/
     *
     * The Original Code is NetBeans. The Initial Developer of the Original
     * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
     * Microsystems, Inc. All Rights Reserved.
     */
    package org.netbeans.modules.xml.text.completion;
    
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.event.InputEvent;
    import java.awt.event.KeyEvent;
    import junit.textui.TestRunner;
    import org.netbeans.editor.ext.ListCompletionView;
    import org.netbeans.jellytools.EditorOperator;
    import org.netbeans.jellytools.NewWizardOperator;
    import org.netbeans.jemmy.ComponentChooser;
    import org.netbeans.jemmy.operators.ComponentOperator;
    import org.netbeans.jemmy.operators.JTextComponentOperator;
    import org.netbeans.modules.xml.text.syntax.XMLOptions;
    import org.netbeans.tests.xml.JXTest;
    import org.openide.loaders.DataObject;
    import org.openide.options.SystemOption;
    
    /**
     * 

    *

    * * *
    XML Module Jemmy Test: CompletionJTest *
    *
    *

    What it tests:
    * * - basic functionality of XML code completion
    * *

    How it works:
    * * Creates simple XML document by code completion. * *

    Settings:
    * none
    * *

    Output (Golden file):
    * XML documents
    * *
    To Do:
    * none
    * *

    Created on April 03, 2003, 12:33 PM *

    */ public class CompletionJTest extends JXTest { // constants for showCompl() method private static int NO_WAIT = 0; private static int EMPTY = 1; private static int NO_EMPTY = 2; /** Caret Column Position */ int col; /** Editor Operator */ EditorOperator editor; /** * Creates new CoreTemplatesTest * @param testName */ public CompletionJTest(String testName) { super(testName); } /** Main test method. */ public void test() { String folder; String name = "Document"; String ext = "xml"; XMLOptions options; DataObject dao; try { folder = getFilesystemName() + DELIM + getDataPackageName(DELIM); options = (XMLOptions) SystemOption.findObject(XMLOptions.class, true); options.setCompletionAutoPopup(false); dao = TestUtil.THIS.findData(name + "." + ext); if (dao != null) dao.delete(); // catalog is only real XML template in the module :-( NewWizardOperator.create("XML" + DELIM + "OASIS XML Catalog", folder, name); editor = new EditorOperator(name); } catch (Exception ex) { log("Cannot setup test.", ex); } clearText(); editor.txtEditorPane().setText("" + "\n" + "\n"); insert(" showCompl(NO_EMPTY); enter(); insert(">\n"); // insertTag("<", ">\n", 1); //Test page /*!!! #36306 hack insertTag(" insertTag(" insertTag("<", ">\n", 0); //

    Test

    insertTag("Test", -1); insertTag(" insertTag("\n", 1); //
    12
    ... this post is sponsored by my books ...

    #1 New Release!

    FP Best Seller

     

    new blog posts

     

    Copyright 1998-2021 Alvin Alexander, alvinalexander.com
    All Rights Reserved.

    A percentage of advertising revenue from
    pages under the /java/jwarehouse URI on this website is
    paid back to open source projects.