org.netbeans.jemmy.operators.ContainerOperator Java Examples

The following examples show how to use org.netbeans.jemmy.operators.ContainerOperator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AntSanityTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Evaluates simple expression during debugging session.
 */
public void evaluateExpression() throws IllegalAccessException, InvocationTargetException, InterruptedException, InvalidExpressionException {
    TopComponentOperator variablesView = new TopComponentOperator(new ContainerOperator(MainWindowOperator.getDefault(), VIEW_CHOOSER), "Variables");
    JToggleButtonOperator showEvaluationResultButton = new JToggleButtonOperator(variablesView, 0);
    showEvaluationResultButton.clickMouse();
    TopComponentOperator evaluationResultView = new TopComponentOperator("Evaluation Result");
    new Action("Debug|Evaluate Expression...", null).perform();
    TopComponentOperator expressionEvaluator = new TopComponentOperator("Evaluate Expression");
    JEditorPaneOperator expressionEditor = new JEditorPaneOperator(expressionEvaluator);
    new EventTool().waitNoEvent(1000);
    expressionEditor.setText("\"If n is: \" + n + \", then n + 1 is: \" + (n + 1)");
    JPanel buttonsPanel = (JPanel) expressionEvaluator.getComponent(2);
    JButton expressionEvaluatorButton = (JButton) buttonsPanel.getComponent(1);
    assertEquals("Evaluate code fragment (Ctrl + Enter)", expressionEvaluatorButton.getToolTipText());
    expressionEvaluatorButton.doClick();
    JTableOperator variablesTable = new JTableOperator(evaluationResultView);
    assertValue(variablesTable, 0, 2, "\"If n is: 50, then n + 1 is: 51\"");
    assertEquals("\"If n is: \" + n + \", then n + 1 is: \" + (n + 1)", variablesTable.getValueAt(0, 0).toString().trim());
}
 
Example #2
Source File: AntSanityTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that it is possible to add watches.
 */
public void newWatch() throws IllegalAccessException, InvocationTargetException, InvalidExpressionException {
    Node projectNode = new ProjectsTabOperator().getProjectRootNode(DEBUG_TEST_PROJECT_ANT);
    Node testFile = new Node(new SourcePackagesNode(projectNode), "advanced|VariablesTest.java");
    new OpenAction().perform(testFile);
    EditorOperator eo = new EditorOperator("VariablesTest.java");
    eo.setCaretPositionToLine(49);
    new ToggleBreakpointAction().perform();
    MainWindowOperator.StatusTextTracer stt = MainWindowOperator.getDefault().getStatusTextTracer();
    stt.start();
    new DebugJavaFileAction().perform(testFile);
    stt.waitText("Thread main stopped at VariablesTest.java:49");
    stt.stop();
    new ActionNoBlock("Debug|New Watch...", null).perform();
    NbDialogOperator newWatchDialog = new NbDialogOperator("New Watch");
    new JEditorPaneOperator(newWatchDialog, 0).setText("n");
    newWatchDialog.ok();
    TopComponentOperator variablesView = new TopComponentOperator(new ContainerOperator(MainWindowOperator.getDefault(), VIEW_CHOOSER), "Variables");
    JTableOperator variablesTable = new JTableOperator(variablesView);
    assertEquals("n", variablesTable.getValueAt(0, 0).toString());
    org.openide.nodes.Node.Property property = (org.openide.nodes.Node.Property) variablesTable.getValueAt(0, 2);
    assertEquals("50", property.getValue());
    JPopupMenuOperator menu = new JPopupMenuOperator(variablesTable.callPopupOnCell(0, 0));
    menu.pushMenu("Delete All");
}
 
Example #3
Source File: MainWindowOperatorTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Test of dragNDropToolbar method. Tries to move toolbar down and checks
 * whether main window is enlarged. */
public void testDragNDropToolbar() throws InterruptedException {
    // need toolbar container to check drag and drop operation
    Component toolbarPool = mainWindowOper.findSubComponent(new ComponentChooser() {

        @Override
        public boolean checkComponent(Component comp) {
            return comp.getClass().getName().equals("org.openide.awt.ToolbarPool");
        }

        @Override
        public String getDescription() {
            return "org.openide.awt.ToolbarPool";
        }
    });
    ContainerOperator toolbarOper = mainWindowOper.getToolbar(0);
    int heightOrig = toolbarPool.getHeight();
    mainWindowOper.dragNDropToolbar(toolbarOper, 0, heightOrig);
    assertTrue("Toolbar not moved down - main window height the same.",
            heightOrig != toolbarPool.getHeight());
}
 
Example #4
Source File: ToggleButtonDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests a group of radio buttons
 *
 * @param parent container containing the buttons
 * @param radioButtonCount number of radio buttons
 * @param selectedRadioButton initial selected radio button
 */
private void testRadioButtons(ContainerOperator<?> parent, int radioButtonCount, SelectedRadioButton selectedRadioButton) {
    JRadioButtonOperator[] jrbo = new JRadioButtonOperator[radioButtonCount];
    for (int i = 0; i < radioButtonCount; i++) {
        jrbo[i] = new JRadioButtonOperator(parent, i);
        if (selectedRadioButton != null && selectedRadioButton.apply(jrbo[i].getText(), i)) {
            assertTrue("Radio Button " + i + " is initially selected", jrbo[i].isSelected());
        } else {
            assertFalse("Radio Button " + i + " is initially not selected", jrbo[i].isSelected());
        }
    }

    for (int i = 0; i < radioButtonCount; i++) {
        jrbo[i].push();
        jrbo[i].waitSelected(true);

        for (int j = 0; j < radioButtonCount; j++) {
            if (i != j) {
                jrbo[j].waitSelected(false);
            }
        }
    }
}
 
Example #5
Source File: SurroundTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testLoggerLogging() {
       String file = "Surround";
openSourceFile("org.netbeans.test.java.hints.HintsTest",file);        
       OptionsOperator oo = OptionsOperator.invoke();
       oo.selectEditor();
       JTabbedPaneOperator jtpo = new JTabbedPaneOperator(oo);
       jtpo.selectPage("Hints");
       JSplitPaneOperator jspo = new JSplitPaneOperator(oo);       
       JTreeOperator jto = new JTreeOperator(jtpo);
       selectHintNode(jto,"errors","Surround with try-catch");                
       JCheckBoxOperator chbox1 = new JCheckBoxOperator(new ContainerOperator((Container)jspo.getRightComponent()),"Use org.openide.util.Exceptions.printStackTrace" );
       chBoxSetSelected(chbox1, false);
       JCheckBoxOperator chbox2 = new JCheckBoxOperator(new ContainerOperator((Container)jspo.getRightComponent()),"Use java.util.logging.Logger");
       chBoxSetSelected(chbox2, true);
       oo.ok();
       new EventTool().waitNoEvent(1000);
       editor = new EditorOperator(file);
editor.setCaretPosition(18,1);
String pattern = ".*"+
       "try \\{.*"+
       "    FileReader fr = new FileReader\\(\"file\"\\);.*"+
       "\\} catch \\(FileNotFoundException ex\\) \\{.*"+
       "    Logger.getLogger\\(Surround.class.getName\\(\\)\\).log\\(Level.SEVERE, null, ex\\);.*"+
       "\\}.*";        
       useHint("Surround Statement",new String[]{"Add throws","Surround Block","Surround Statement"},pattern);
   }
 
Example #6
Source File: SurroundTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testNoLogging() {
       String file = "Surround";
openSourceFile("org.netbeans.test.java.hints.HintsTest",file);        
       OptionsOperator oo = OptionsOperator.invoke();
       oo.selectEditor();
       JTabbedPaneOperator jtpo = new JTabbedPaneOperator(oo);
       jtpo.selectPage("Hints");
       JSplitPaneOperator jspo = new JSplitPaneOperator(oo);       
       JTreeOperator jto = new JTreeOperator(jtpo);                        
       selectHintNode(jto,"errors","Surround with try-catch");
       JCheckBoxOperator chbox1 = new JCheckBoxOperator(new ContainerOperator((Container)jspo.getRightComponent()),"Use org.openide.util.Exceptions.printStackTrace" );        
       chBoxSetSelected(chbox1, false);        
       JCheckBoxOperator chbox2 = new JCheckBoxOperator(new ContainerOperator((Container)jspo.getRightComponent()),"Use java.util.logging.Logger");        
       chBoxSetSelected(chbox2, false);        
       oo.ok();        
       new EventTool().waitNoEvent(1000);
       editor = new EditorOperator(file);
editor.setCaretPosition(18,1);
String pattern = ".*"+
       "try \\{.*"+
       "    FileReader fr = new FileReader\\(\"file\"\\);.*"+
       "\\} catch \\(FileNotFoundException ex\\) \\{.*"+
       "    ex.printStackTrace\\(\\);.*"+
       "\\}.*";        
       useHint("Surround Statement",new String[]{"Add throws","Surround Block","Surround Statement"},pattern);
   }
 
Example #7
Source File: CodeTemplatesOperator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public CodeTemplatesOperator setContext(Set<String> set) {
    JTabbedPaneOperator tabbedPane = getTabbedPane();
    tabbedPane.selectPage("Contexts");
    ContainerOperator<JEditorPane> selectedComponent = new ContainerOperator<>((Container)tabbedPane.getSelectedComponent());
    JListOperator list = new JListOperator(selectedComponent);
    for (int i = 0; i < list.getModel().getSize(); i++) {
        JCheckBox checkBox = (JCheckBox) list.getRenderedComponent(i);
        String contextName = checkBox.getText();
        list.scrollToItem(i);
        if(!checkBox.isSelected() && set.contains(contextName)) {
            list.selectItem(i);
        } else if(checkBox.isSelected() && !set.contains(contextName)) {
            list.selectItem(i);
        }            
    }   
    return this;
    
}
 
Example #8
Source File: ToggleButtonDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void testToggleButtons(JFrameOperator jfo) {
    ComponentChooser directionPanelChooser = new ByClassChooser(DirectionPanel.class);

    String text_Position = LayoutControlPanel.TEXT_POSITION;
    ContainerOperator<?> textPositionContainer = getLabeledContainerOperator(jfo, text_Position);
    ContainerOperator<?> directionPanelOperator = new ContainerOperator<>(textPositionContainer, directionPanelChooser);
    testRadioButtons(directionPanelOperator, 9, (t, i) -> i == 5);

    // Unfortunately, both directionPanels are in the same parent container
    // so we have to use indexes here.
    // There is no guarantee that if the UI changes, the code would be still
    // valid in terms of which directionPanel is checked first. However, it
    // does guarantee that two different directionPanels are checked.
    String content_Alignment = LayoutControlPanel.CONTENT_ALIGNMENT;
    ContainerOperator<?> contentAlignmentContainer = getLabeledContainerOperator(jfo, content_Alignment);
    ContainerOperator<?> directionPanelOperator2 = new ContainerOperator<>(contentAlignmentContainer, directionPanelChooser,
            contentAlignmentContainer.getSource() == textPositionContainer.getSource() ? 1 : 0);
    testRadioButtons(directionPanelOperator2, 9, (t, i) -> i == 4);

}
 
Example #9
Source File: ToggleButtonDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Will change the state of the CheckBox then change back to initial state.
 *
 * @param parent
 * @param text
 * @param expectedValue
 * @throws Exception
 */
private void testCheckBox(ContainerOperator<?> parent, String text, boolean expectedValue) {

    System.out.println("Testing " + text);
    parent.setComparator(EXACT_STRING_COMPARATOR);
    JCheckBoxOperator jcbo = new JCheckBoxOperator(parent, text);
    jcbo.waitSelected(expectedValue);

    // click check box (toggle the state)
    jcbo.push();
    jcbo.waitSelected(!expectedValue);

    jcbo.push();
    jcbo.waitSelected(expectedValue);
}
 
Example #10
Source File: TopComponentOperator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean isUnder(ContainerOperator cont, Component c) {
    if (cont == null) {
        return true;
    }
    Component comp = cont.getSource();
    while (comp != c && c != null) {
        c = c.getParent();
    }
    return (comp == c);
}
 
Example #11
Source File: TopComponentOperator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Waits for index-th TopComponent with given name in IDE registry.
 * It throws JemmyException when TopComponent is not find until timeout
 * expires.
 * @param cont container where to search
 * @param name name of TopComponent
 * @param index index of TopComponent
 * @param subchooser ComponentChooser to determine exact TopComponent
 * @return TopComponent instance or throws JemmyException if not found
 * @see #findTopComponent
 */
protected static JComponent waitTopComponent(final ContainerOperator cont, final String name, final int index, final ComponentChooser subchooser) {
    try {
        Waiter waiter = new Waiter(new Waitable() {

            @Override
            public Object actionProduced(Object obj) {
                return findTopComponent(cont, name, index, subchooser);
            }

            @Override
            public String getDescription() {
                return ("Wait TopComponent with name=" + name
                        + " index=" + String.valueOf(index)
                        + (subchooser == null ? "" : " subchooser=" + subchooser.getDescription())
                        + " loaded");
            }
        });
        Timeouts times = JemmyProperties.getCurrentTimeouts().cloneThis();
        times.setTimeout("Waiter.WaitingTime", times.getTimeout("ComponentOperator.WaitComponentTimeout"));
        waiter.setTimeouts(times);
        waiter.setOutput(JemmyProperties.getCurrentOutput());
        return ((JComponent) waiter.waitAction(null));
    } catch (InterruptedException e) {
        return (null);
    }
}
 
Example #12
Source File: TopComponentOperator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Container findTabDisplayer() {
    return ContainerOperator.findContainer(findTabbedAdapter(), new ComponentChooser() {

        @Override
        public boolean checkComponent(Component comp) {
            return comp.getClass().getName().endsWith("TabDisplayer");
        }

        @Override
        public String getDescription() {
            return "org.netbeans.swing.tabcontrol.TabDisplayer";
        }
    });
}
 
Example #13
Source File: MainWindowOperatorTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Test of getToolbarButton method. Finds Build toolbar and checks if
 * getToolbarButton(1) returns Build Main Project button. */
public void testGetToolbarButtonInt() {
    ContainerOperator toolbarOper = mainWindowOper.getToolbar("File"); // NOI18N        

    String tooltip = mainWindowOper.getToolbarButton(toolbarOper, 0).getToolTipText();
    String expected = Bundle.getString("org.netbeans.modules.project.ui.actions.Bundle",
            "LBL_NewFileAction_Tooltip");
    assertTrue("Wrong toolbar button.", tooltip.indexOf(expected) != -1);
}
 
Example #14
Source File: JSplitPaneDriver.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void expandTo(JSplitPaneOperator oper, int index) {
    ContainerOperator<?> divOper = oper.getDivider();
    JButtonOperator bo
            = new JButtonOperator((JButton) divOper.
                    waitSubComponent(new JButtonOperator.JButtonFinder(ComponentSearcher.
                            getTrueChooser("JButton")),
                            index));
    bo.copyEnvironment(divOper);
    ButtonDriver bdriver = DriverManager.getButtonDriver(bo);
    bdriver.push(bo);
    bdriver.push(bo);
}
 
Example #15
Source File: OutlineViewOperator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates new instance for the first TreeTable in container.
     * @param contOper container where to find TreeTable
     * @param index int index
     */
    public OutlineViewOperator(ContainerOperator contOper, int index) {
        super(contOper);
//	this((JTable)
//	     waitComponent(contOper,
//			   new OutlineViewFinder(ComponentSearcher.
//                                               getTrueChooser("Any OutlineView")),
//			   index));
//	copyEnvironment(contOper);
        waitComponent(contOper, new OutlineViewFinder(ComponentSearcher.getTrueChooser("Any OutlineView")), index);
    }
 
Example #16
Source File: TreeTableOperator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates new instance for the first TreeTable in container.
    * @param contOper container where to find TreeTable
    * @param index int index
    */
   public TreeTableOperator(ContainerOperator contOper, int index) {
this((JTable)
     waitComponent(contOper, 
		   new TreeTableFinder(ComponentSearcher.
                                              getTrueChooser("Any TreeTable")),
		   index));
copyEnvironment(contOper);
   }
 
Example #17
Source File: EditorPanelOperator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void closePopup() {
    if (isPopupVisible) {
        ContainerOperator containerOperator = new ContainerOperator(panel);
        containerOperator.pressMouse();
        new EventTool().waitNoEvent(100);
        containerOperator.releaseMouse();
        isPopupVisible = false;
    }
}
 
Example #18
Source File: EditorWindowOperator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** If the leftmost visible tab is partially hidden, it clicks on it. 
 * Otherwise it does nothing.
 * @return true if tabs were moved, false otherwise
 */
public static boolean jumpLeft() {
    if(btLeft().isEnabled()) {
        Container cont = getEditor().findTabDisplayer();
        // click left corner
        new ContainerOperator(cont).clickMouse(cont.getX()+1, cont.getY()+cont.getHeight()/2, 1);
        return true;
    }
    return false;
}
 
Example #19
Source File: TabbedPaneDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void testTabs(JFrameOperator mainFrame, String tabPlacement) throws Exception {
    ContainerOperator<?> rbCont = getLabeledContainerOperator(mainFrame, TAB_PLACEMENT);
    new JRadioButtonOperator(rbCont, tabPlacement).doClick();

    final String[] tabTitles = new String[]{CAMILLE, MIRANDA, EWAN, BOUNCE};
    for (int i = 0; i < tabTitles.length; i++) {
        String pageTitle = tabTitles[i];
        JTabbedPaneOperator tabOperator = new JTabbedPaneOperator(mainFrame);
        tabOperator.setVerification(true);
        tabOperator.selectPage(pageTitle);
    }
}
 
Example #20
Source File: ToggleButtonDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
    new ClassReference(ToggleButtonDemo.class.getCanonicalName()).startApplication();

    JFrameOperator mainFrame = new JFrameOperator(ToggleButtonDemo.class.getAnnotation(DemoProperties.class).value());
    JTabbedPaneOperator tabPane = new JTabbedPaneOperator(mainFrame);

    // Radio Button Toggles
    testRadioButtons(getBorderTitledJPanelOperator(mainFrame, TEXT_RADIO_BUTTONS), 3, null);
    testRadioButtons(getBorderTitledJPanelOperator(mainFrame, IMAGE_RADIO_BUTTONS), 3, null);
    testRadioButtons(getLabeledContainerOperator(mainFrame, PAD_AMOUNT), 3, (t, i) -> DEFAULT.equals(t));

    // switch to the Check Boxes Tab
    tabPane.selectPage(CHECK_BOXES);

    // Check Box Toggles
    ContainerOperator<?> textCheckBoxesJPanel = getBorderTitledJPanelOperator(mainFrame, TEXT_CHECKBOXES);
    testCheckBox(textCheckBoxesJPanel, CHECK1, false);
    testCheckBox(textCheckBoxesJPanel, CHECK2, false);
    testCheckBox(textCheckBoxesJPanel, CHECK3, false);

    ContainerOperator<?> imageCheckBoxesJPanel = getBorderTitledJPanelOperator(mainFrame, IMAGE_CHECKBOXES);
    testCheckBox(imageCheckBoxesJPanel, CHECK1, false);
    testCheckBox(imageCheckBoxesJPanel, CHECK2, false);
    testCheckBox(imageCheckBoxesJPanel, CHECK3, false);

    ContainerOperator<?> displayOptionsContainer = getLabeledContainerOperator(mainFrame, DISPLAY_OPTIONS);
    testCheckBox(displayOptionsContainer, PAINT_BORDER, false);
    testCheckBox(displayOptionsContainer, PAINT_FOCUS, true);
    testCheckBox(displayOptionsContainer, ENABLED, true);
    testCheckBox(displayOptionsContainer, CONTENT_FILLED, true);

    // Direction Button Toggles
    testToggleButtons(mainFrame);
}
 
Example #21
Source File: JSplitPaneDriver.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void moveDividerTo(JSplitPaneOperator oper, ScrollAdjuster adj) {
    ContainerOperator<?> divOper = oper.getDivider();
    /* workaround */
    if (oper.getDividerLocation() == -1) {
        moveTo(oper, divOper, divOper.getCenterX() - 1, divOper.getCenterY() - 1);
        if (oper.getDividerLocation() == -1) {
            moveTo(oper, divOper, divOper.getCenterX() + 1, divOper.getCenterY() + 1);
        }
    }
    if (oper.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
        moveOnce(oper, divOper, adj, 0, oper.getWidth());
    } else {
        moveOnce(oper, divOper, adj, 0, oper.getHeight());
    }
}
 
Example #22
Source File: TextFieldDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void dateTextField(JFrameOperator jfo) throws Exception {
    JTextFieldOperator jtfo = new JTextFieldOperator(jfo,
            new ByClassChooser(JFormattedTextField.class));
    ContainerOperator<?> containerOperator = new ContainerOperator<>(jtfo.getParent());
    JButtonOperator jbo = new JButtonOperator(containerOperator, GO);
    JLabelOperator dowLabel = new JLabelOperator(containerOperator);
    Calendar calendar = Calendar.getInstance(Locale.ENGLISH);

    // Check default date Day of the Week
    jbo.push();
    dowLabel.waitText(calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.ENGLISH));

    // Check Custom Day of the Week
    calendar.set(2012, 9, 11); // Represents "Oct 11, 2012"
    Date date = calendar.getTime();
    String dateString = jtfo.getQueueTool().invokeAndWait(
            new QueueTool.QueueAction<String>("Formatting the value using JFormattedTextField formatter") {

        @Override
        public String launch() throws Exception {
            return ((JFormattedTextField) jtfo.getSource()).getFormatter().valueToString(date);
        }
    });
    System.out.println("dateString = " + dateString);
    jtfo.enterText(dateString);

    jbo.push();
    dowLabel.waitText("Thursday");
}
 
Example #23
Source File: HintsTestCase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setInPlaceCreation(boolean inPlace) {
    OptionsOperator oo = OptionsOperator.invoke();
    oo.selectEditor();
    JTabbedPaneOperator jtpo = new JTabbedPaneOperator(oo);
    jtpo.selectPage("Hints");
    JSplitPaneOperator jspo = new JSplitPaneOperator(oo);
    JTreeOperator jto = new JTreeOperator(jtpo);
    selectHintNode(jto, "errors", "Create Local Variable");
    JCheckBoxOperator chbox1 = new JCheckBoxOperator(new ContainerOperator((Container) jspo.getRightComponent()), "Create Local Variable In Place");
    chBoxSetSelected(chbox1, inPlace);
    oo.ok();
}
 
Example #24
Source File: GuiTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean excludedContains(String item) {
    int delay = 1000;
    OptionsOperator oo = null;            
    try {
        oo = OptionsOperator.invoke();
        oo.selectEditor();
        JTabbedPane jtp = (JTabbedPane) oo.findSubComponent(new JTabbedPaneOperator.JTabbedPaneFinder());
        JTabbedPaneOperator jtpo = new JTabbedPaneOperator(jtp);
        Container page = (Container) jtpo.selectPage("Code Completion");
        ContainerOperator jco = new ContainerOperator(page);
        new EventTool().waitNoEvent(delay);
        
        JComboBox jcb = (JComboBox) jco.findSubComponent(new JComboBoxOperator.JComboBoxFinder());
        JComboBoxOperator jcbo = new JComboBoxOperator(jcb);       
        jcbo.selectItem("text/x-java");
        new EventTool().waitNoEvent(delay);
        
        JList jl = (JList) jco.findSubComponent(new JListOperator.JListFinder());
        JListOperator jlo = new JListOperator(jl);
        for (int i = 0; i < jlo.getModel().getSize(); i++) {
            String actItem = jlo.getModel().getElementAt(i).toString();
            if(item.equals(actItem)) {
                return true;
            }                
        }
        return false;
        
    } finally {
        if(oo!=null) {
            oo.close();
        }
    }
}
 
Example #25
Source File: CodeTemplatesOperator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Set<String> getContexts() {
    Set<String> result = new HashSet<>();
    JTabbedPaneOperator tabbedPane = getTabbedPane();
    tabbedPane.selectPage("Contexts");
    ContainerOperator<JEditorPane> selectedComponent = new ContainerOperator<>((Container)tabbedPane.getSelectedComponent());
    JListOperator list = new JListOperator(selectedComponent);
    for (int i = 0; i < list.getModel().getSize(); i++) {
        JCheckBox checkBox = (JCheckBox) list.getRenderedComponent(i);            
        if(checkBox.isSelected())  {
            result.add(checkBox.getText());                
        }                         
    }        
    return result;
}
 
Example #26
Source File: RefactoringResultOperator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public JTree getPreviewTree() {
    ContainerOperator ct = new ContainerOperator(getRefactoringPanel());
    JSplitPaneOperator splitPane = new JSplitPaneOperator(ct);
    JComponent leftComponent = (JComponent) splitPane.getLeftComponent();
    JScrollPane jScrollPane = JScrollPaneOperator.findJScrollPane(leftComponent);
    javax.swing.JViewport viewport = jScrollPane.getViewport();
    return (JTree) viewport.getComponent(0);
}
 
Example #27
Source File: CodeTemplatesOperator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JEditorPaneOperator getEditorOnTab(final String tabName) {
    JTabbedPaneOperator tabbedPane = getTabbedPane();
    tabbedPane.selectPage(tabName);
    ContainerOperator<JEditorPane> selectedComponent = new ContainerOperator<>((Container)tabbedPane.getSelectedComponent());
    JEditorPaneOperator jepo = new JEditorPaneOperator(selectedComponent);
    return jepo;
}
 
Example #28
Source File: CodeTemplatesOperator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void switchToTemplates() {
    optionsOperator.selectEditor();
    Component findComponent = optionsOperator.findSubComponent(new JTabbedPaneOperator.JTabbedPaneFinder());
    JTabbedPaneOperator tabbedPane = new JTabbedPaneOperator((JTabbedPane) findComponent);
    tabbedPane.selectPage("Code Templates");
    panel = new ContainerOperator<>((Container) tabbedPane.getSelectedComponent());
}
 
Example #29
Source File: JSplitPaneDriver.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void moveOnce(JSplitPaneOperator oper,
        ContainerOperator<?> divOper,
        ScrollAdjuster adj,
        int leftPosition,
        int rightPosition) {
    int currentPosition = 0;
    if (oper.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
        currentPosition = (int) (divOper.getLocationOnScreen().getX()
                - oper.getLocationOnScreen().getX());
    } else {
        currentPosition = (int) (divOper.getLocationOnScreen().getY()
                - oper.getLocationOnScreen().getY());
    }
    int nextPosition = 0;
    if (adj.getScrollDirection() == ScrollAdjuster.DECREASE_SCROLL_DIRECTION) {
        nextPosition = (currentPosition + leftPosition) / 2;
        moveToPosition(oper, divOper, nextPosition - currentPosition);
        if (currentPosition
                == ((adj.getScrollOrientation() == JSplitPane.HORIZONTAL_SPLIT)
                        ? (int) (divOper.getLocationOnScreen().getX()
                        - oper.getLocationOnScreen().getX())
                        : (int) (divOper.getLocationOnScreen().getY()
                        - oper.getLocationOnScreen().getY()))) {
            return;
        }
        moveOnce(oper, divOper, adj, leftPosition, currentPosition);
    } else if (adj.getScrollDirection() == ScrollAdjuster.INCREASE_SCROLL_DIRECTION) {
        nextPosition = (currentPosition + rightPosition) / 2;
        moveToPosition(oper, divOper, nextPosition - currentPosition);
        if (currentPosition
                == ((adj.getScrollOrientation() == JSplitPane.HORIZONTAL_SPLIT)
                        ? (int) (divOper.getLocationOnScreen().getX()
                        - oper.getLocationOnScreen().getX())
                        : (int) (divOper.getLocationOnScreen().getY()
                        - oper.getLocationOnScreen().getY()))) {
            return;
        }
        moveOnce(oper, divOper, adj, currentPosition, rightPosition);
    } else { // (currentLocation == dividerLocation) - stop point
        return;
    }
}
 
Example #30
Source File: OptionsTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testOptionsCategories() {
    OptionsOperator oo = OptionsOperator.invoke();//open options

    Component optionsPanel = oo.findSubComponent(getCompChooser("org.netbeans.modules.options.OptionsPanel"));
    //we need container to be able to traverse inside   
    Container optionsContainer = ContainerOperator.findContainerUnder(optionsPanel);
    ArrayList<Component> optionsCategories = new ArrayList<Component>();
    optionsCategories.addAll(Utilities.findComponentsInContainer(
            optionsContainer,
            getCompChooser("org.netbeans.modules.options.OptionsPanel$CategoryButton"),
            true));
    optionsCategories.addAll(Utilities.findComponentsInContainer(
            optionsContainer,
            getCompChooser("org.netbeans.modules.options.OptionsPanel$NimbusCategoryButton"),
            true));

    NbMenuItem ideOptions = new NbMenuItem(getName());//let store it in NbMenuItem TODO: refactor to make it simplier
    ArrayList<NbMenuItem> categories = new ArrayList<NbMenuItem>();
    NbMenuItem miscCategory = null;//remember the miscellanous because you will add the subcategories to it
    for (Component component : optionsCategories) {
        NbMenuItem optionsCategory = new NbMenuItem(((JLabel) component).getText());
        categories.add(optionsCategory);
        if (optionsCategory.getName().equals("Miscellaneous")) {//NOI18N
            miscCategory = optionsCategory;
        }
    }
    ideOptions.setSubmenu(categories);

    oo.selectMiscellaneous();//switch to Miscelenous

    JTabbedPane miscellaneousPanel = (JTabbedPane) oo.findSubComponent(getCompChooser("javax.swing.JTabbedPane"));

    ArrayList<NbMenuItem> miscCategories = new ArrayList<NbMenuItem>();
    for (int i = 0; i < miscellaneousPanel.getTabCount(); i++) {
        NbMenuItem miscCategoryItem = new NbMenuItem();
        miscCategoryItem.setName(miscellaneousPanel.getTitleAt(i));//
        miscCategories.add(miscCategoryItem);
    }
    miscCategory.setSubmenu(miscCategories);

    //load categories order from golden file
    LogFiles logFiles = new LogFiles();
    PrintStream ideFileStream = null;
    PrintStream goldenFileStream = null;

    try {
        ideFileStream = logFiles.getIdeFileStream();
        goldenFileStream = logFiles.getGoldenFileStream();

        //read the golden file
        NbMenuItem goldenOptions = Utilities.parseSubTreeByLines(getGoldenFile("options", "options-categories").getAbsolutePath());
        goldenOptions.setName(getName());

        //make a diff
        Utilities.printMenuStructure(ideFileStream, ideOptions, "  ", 100);
        Utilities.printMenuStructure(goldenFileStream, goldenOptions, "  ", 100);

        Manager.getSystemDiff().diff(logFiles.pathToIdeLogFile, logFiles.pathToGoldenLogFile, logFiles.pathToDiffLogFile);
        String message = Utilities.readFileToString(logFiles.pathToDiffLogFile);
        assertFile(message, logFiles.pathToGoldenLogFile, logFiles.pathToIdeLogFile, logFiles.pathToDiffLogFile);
    } catch (IOException ex) {
        ex.printStackTrace(System.err);
    } finally {
        ideFileStream.close();
        goldenFileStream.close();
    }
}