Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 394179 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/caps/AbstractTextComponent.java (+205 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2012 BREDEX GmbH.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     BREDEX GmbH - initial API and implementation 
10
 *******************************************************************************/
11
package org.eclipse.jubula.rc.common.caps;
12
13
import org.apache.commons.lang.StringUtils;
14
import org.eclipse.jubula.rc.common.exception.StepExecutionException;
15
import org.eclipse.jubula.rc.common.implclasses.MatchUtil;
16
import org.eclipse.jubula.rc.common.implclasses.Verifier;
17
import org.eclipse.jubula.rc.common.uiadapter.interfaces.ITextComponentAdapter;
18
import org.eclipse.jubula.tools.objects.event.EventFactory;
19
import org.eclipse.jubula.tools.objects.event.TestErrorEvent;
20
import org.eclipse.jubula.tools.utils.TimeUtil;
21
/**
22
 * Implementation of the CAPs from all Text like components.
23
 * @author BREDEX GmbH
24
 *
25
 */
26
public class AbstractTextComponent extends AbstractTextInputSupport {
27
28
    /**
29
     * Gets the specific adapter
30
     * @return the specific adapter
31
     */
32
    private ITextComponentAdapter getTextCompAdapter() {
33
        return (ITextComponentAdapter) getComponent();
34
    }
35
    
36
    /**
37
     * Sets the caret at the position <code>index</code>.
38
     * @param index The caret position
39
     */
40
    private void setCaretPosition(final int index) {
41
        if (index < 0) {
42
            throw new StepExecutionException("Invalid position: " + index, //$NON-NLS-1$
43
                EventFactory.createActionError(TestErrorEvent.INPUT_FAILED));
44
        }
45
        int index2 = 0;
46
        String text = getTextCompAdapter().getText();
47
        if (text != null) {
48
            index2 = index > text.length() ? text.length() : index;
49
        }
50
        getTextCompAdapter().setSelection(index2);
51
    }
52
    
53
    /**
54
     * @param text The text to insert at the current caret position
55
     */
56
    protected void insertText(final String text) {
57
        // Scroll it to visible first to ensure that the typing
58
        // performs correctly.
59
        getRobot().scrollToVisible(getComponent().getRealComponent(), null);
60
        getRobot().type(getComponent().getRealComponent(), text);
61
    }
62
    
63
    /**
64
     * Types <code>text</code> into the component. This replaces the shown
65
     * content.
66
     *
67
     * @param text the text to type in
68
     */
69
    public void gdReplaceText(String text) {
70
        gdSelect();
71
        if (StringUtils.EMPTY.equals(text)) {
72
            getRobot().keyStroke("DELETE"); //$NON-NLS-1$
73
        }
74
        insertText(text);
75
    }
76
77
    /**
78
     * Types <code>text</code> into the component.
79
     *
80
     * @param text the text to type in
81
     */
82
    public void gdInputText(String text) {
83
        if (!getTextCompAdapter().hasFocus()) {
84
            TimeUtil.delay(100);
85
            gdClick(1, 1);
86
        }
87
        insertText(text);
88
    }
89
    
90
    /**
91
     * Inserts <code>text</code> at the position <code>index</code>.
92
     *
93
     * @param text The text to insert
94
     * @param index The position for insertion
95
     */
96
    public void gdInsertText(String text, int index) {
97
        gdClick(1, 1);
98
        setCaretPosition(index);
99
        insertText(text);
100
    }
101
    
102
    /**
103
     * Inserts <code>text</code> before or after the first appearance of
104
     * <code>pattern</code>.
105
     * @param text The text to insert
106
     * @param pattern The pattern to find the position for insertion
107
     * @param operator Operator to select Matching Algorithm
108
     * @param after If <code>true</code>, the text will be inserted after the
109
     *            pattern, otherwise before the pattern.
110
     * @throws StepExecutionException If the pattern is invalid or cannot be found
111
     */
112
    public void gdInsertText(String text, String pattern, String operator, 
113
            boolean after)
114
        throws StepExecutionException {
115
        
116
        if (text == null) {
117
            throw new StepExecutionException(
118
                "The text to be inserted must not be null", EventFactory //$NON-NLS-1$
119
                    .createActionError());
120
        }
121
        final MatchUtil.FindResult matchedText = MatchUtil.getInstance().
122
            find(getTextCompAdapter().getText(), pattern, operator);
123
        
124
        if ((matchedText == null) || (matchedText.getStr() == null)) {
125
            throw new StepExecutionException("The pattern '" + pattern //$NON-NLS-1$
126
                + "' could not be found", //$NON-NLS-1$
127
                EventFactory.createActionError(TestErrorEvent.NOT_FOUND));
128
        }
129
130
        int index = matchedText.getPos();
131
        
132
        int insertPos = after ? index + matchedText.getStr().length() : index;
133
        gdInsertText(text, insertPos);
134
    }
135
    
136
137
        
138
    /**
139
     * select the whole text of the textfield by calling "selectAll()".
140
     */
141
    public void gdSelect() {
142
        gdClick(1, 1);
143
        // Wait a while. Without this, we got no selectAll sometimes!
144
        TimeUtil.delay(100);
145
        getTextCompAdapter().selectAll();
146
    }
147
    
148
    /**
149
     * Verifies the editable property.
150
     * @param editable The editable property to verify.
151
     */
152
    public void gdVerifyEditable(boolean editable) {
153
        Verifier.equals(editable, getTextCompAdapter().isEditable());
154
    }
155
        
156
    /**
157
     * Selects the first (not)appearance of <code>pattern</code> in the text
158
     * component's content.
159
     *
160
     * @param pattern The pattern to select
161
     * @param operator operator
162
     * @throws StepExecutionException
163
     *             If the pattern is invalid or cannot be found
164
     */
165
    public void gdSelect(final String pattern, String operator)
166
        throws StepExecutionException {
167
        gdClick(1, 1);
168
        final MatchUtil.FindResult matchedText = MatchUtil.getInstance().
169
            find(getTextCompAdapter().getText(), pattern, operator);
170
        if ((matchedText == null) || (matchedText.getStr().length() == 0)) {
171
            throw new StepExecutionException("Invalid pattern for insertion", //$NON-NLS-1$
172
                EventFactory.createActionError());
173
        }
174
        final int index = matchedText.getPos();
175
        if (operator.startsWith("not")) { //$NON-NLS-1$
176
            if (pattern.equals(getTextCompAdapter().getText())) {
177
                String msg = "The pattern '" + pattern //$NON-NLS-1$
178
                    + "' is equal to current text"; //$NON-NLS-1$
179
                throw new StepExecutionException(msg, EventFactory
180
                    .createActionError(TestErrorEvent
181
                        .EXECUTION_ERROR, new String[] {msg}));
182
            } else if (index > 0) {
183
                // select part before pattern
184
                getTextCompAdapter().setSelection(0, index);
185
            } else {
186
                // select part after pattern
187
                getTextCompAdapter().setSelection(
188
                        matchedText.getStr().length(),
189
                        getTextCompAdapter().getText().length());
190
            }
191
        } else {
192
            getTextCompAdapter().setSelection(index,
193
                    index + matchedText.getStr().length());
194
        }
195
    }
196
        
197
    /**
198
     * {@inheritDoc}
199
     */
200
    public String[] getTextArrayFromComponent() {
201
        return null;
202
    }
203
204
205
}
(-)a/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/caps/AbstractWidgetCAPs.java (+8 lines)
Lines 99-104 public abstract class AbstractWidgetCAPs extends AbstractUICAPs { Link Here
99
                    .setClickCount(count)
99
                    .setClickCount(count)
100
                    .setMouseButton(button));
100
                    .setMouseButton(button));
101
    }
101
    }
102
    
103
    /**
104
     * Clicks the center of the component with the MouseButton 1
105
     * @param count Number of mouse clicks
106
     */
107
    public void gdclick(int count) {
108
        gdClick(count, 1);
109
    }
102
    /**
110
    /**
103
     * clicks into a component.
111
     * clicks into a component.
104
     *
112
     *
(-)a/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/uiadapter/factory/GUIAdapterFactoryRegistry.java (-3 / +5 lines)
Lines 88-98 public class GUIAdapterFactoryRegistry { Link Here
88
        Class adapteeclass = objectToAdapt.getClass();
88
        Class adapteeclass = objectToAdapt.getClass();
89
        IUIAdapterFactory factory = (IUIAdapterFactory) m_registrationMap.
89
        IUIAdapterFactory factory = (IUIAdapterFactory) m_registrationMap.
90
                get(adapteeclass);
90
                get(adapteeclass);
91
        while (factory == null && adapteeclass != Object.class) {
91
        Class superclass = adapteeclass;
92
        while (factory == null && superclass != Object.class) {
92
            factory = (IUIAdapterFactory) m_registrationMap.
93
            factory = (IUIAdapterFactory) m_registrationMap.
93
                get(adapteeclass.getSuperclass());
94
                get(superclass);
95
            superclass = superclass.getSuperclass();
94
        }
96
        }
95
        
97
        // FIXME Here is missing the right Exception!!!
96
        return factory.getAdapter(objectToAdapt);
98
        return factory.getAdapter(objectToAdapt);
97
        
99
        
98
    }
100
    }
(-)a/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/uiadapter/interfaces/ITextComponentAdapter.java (+52 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2012 BREDEX GmbH.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     BREDEX GmbH - initial API and implementation 
10
 *******************************************************************************/
11
package org.eclipse.jubula.rc.common.uiadapter.interfaces;
12
/**
13
 * Interface for all needed methods which are needed from TextComponents
14
 * @author BREDEX GmbH
15
 *
16
 */
17
public interface ITextComponentAdapter extends ITextVerifiable {
18
19
    /**
20
     * Sets the caret to a specific position.
21
     * 
22
     * @param start The index at which the selection begins.
23
     */
24
    void setSelection(int start);
25
    /**
26
     * Selects text in the component.
27
     * 
28
     * @param start The index at which the selection begins.
29
     * @param end   The index at which the selection ends.
30
     */
31
    void setSelection(int start, int end);
32
33
    
34
    /**
35
     * 
36
     * @return the selectes text
37
     */
38
    String getSelectionText();
39
40
    /**
41
     * Selects all text in the component.
42
     */
43
    void selectAll();
44
45
    /**
46
     * 
47
     * @return the value if the Text Component is editable
48
     */
49
    boolean isEditable();
50
51
52
}
(-)a/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/swing/uiadapter/JTextComponentAdapter.java (+119 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2012 BREDEX GmbH.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     BREDEX GmbH - initial API and implementation 
10
 *******************************************************************************/
11
package org.eclipse.jubula.rc.swing.swing.uiadapter;
12
13
import javax.swing.text.JTextComponent;
14
15
import org.eclipse.jubula.rc.common.driver.IRunnable;
16
import org.eclipse.jubula.rc.common.uiadapter.interfaces.ITextComponentAdapter;
17
/**
18
 * Implementation of the Interface <code>ITextComponentAdapter</code> as a
19
 * adapter for the <code>JTextComponent</code> component.
20
 * @author BREDEX GmbH
21
 *
22
 */
23
public class JTextComponentAdapter extends WidgetAdapter
24
    implements ITextComponentAdapter {
25
    
26
    /** */
27
    private JTextComponent m_textComponent;
28
29
    /**
30
     * Creates an object with the adapted JTextComponent.
31
     * @param objectToAdapt 
32
     */
33
    public JTextComponentAdapter(Object objectToAdapt) {
34
        super(objectToAdapt);
35
        m_textComponent = (JTextComponent) objectToAdapt;
36
    }
37
38
    /**
39
     * {@inheritDoc}
40
     */
41
    public String getText() {
42
        return m_textComponent.getText();
43
    }
44
    
45
    /**
46
     * {@inheritDoc}
47
     */
48
    public void setSelection(final int position) {
49
        getEventThreadQueuer().invokeAndWait("setSelection", //$NON-NLS-1$
50
                new IRunnable() {
51
                    public Object run() {
52
                        m_textComponent.setCaretPosition(position);
53
                        return null;
54
                    }
55
                });
56
    }
57
    
58
    /**
59
     * {@inheritDoc}
60
     */
61
    public void setSelection(final int start, final int end) {
62
        getEventThreadQueuer().invokeAndWait("setSelection", //$NON-NLS-1$
63
                new IRunnable() {
64
                    public Object run() {
65
                        m_textComponent.setSelectionStart(start);
66
                        m_textComponent.setSelectionEnd(end);
67
                        return null;
68
                    }
69
                });
70
    }
71
72
    /**
73
     * {@inheritDoc}
74
     */
75
    public String getSelectionText() {
76
        String actual = (String)getEventThreadQueuer().invokeAndWait(
77
                "getSelectionText", new IRunnable() { //$NON-NLS-1$
78
                    public Object run() {
79
                        return m_textComponent.getSelectedText();
80
                    }
81
                });
82
        return actual;
83
    }
84
85
    /**
86
     * {@inheritDoc}
87
     */
88
    public void selectAll() {
89
        getRobot().keyStroke(getRobot().getSystemModifierSpec() + " A"); //$NON-NLS-1$
90
91
        if (!getText().equals(getSelectionText())) {
92
            getEventThreadQueuer().invokeAndWait(
93
                    "selectAll", new IRunnable() { //$NON-NLS-1$
94
                        public Object run() {
95
                            m_textComponent.selectAll();
96
                            return null;
97
                        }
98
                    });
99
        }
100
        
101
    }
102
103
    
104
    /**
105
     * {@inheritDoc}
106
     */
107
    public boolean isEditable() {
108
        return ((Boolean) getEventThreadQueuer().
109
                invokeAndWait("isEditable", new IRunnable() { //$NON-NLS-1$
110
                    public Object run() {
111
                        return m_textComponent.isEditable() 
112
                            && m_textComponent.isEnabled()
113
                                ? Boolean.TRUE : Boolean.FALSE; // see findBugs
114
                    }
115
                })).booleanValue();
116
    }
117
118
    
119
}
(-)a/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/swing/uiadapter/JTreeAdapter.java (-1 / +1 lines)
Lines 26-32 public class JTreeAdapter extends WidgetAdapter implements ITreeAdapter { Link Here
26
    
26
    
27
   
27
   
28
    /**
28
    /**
29
     * Creates an object with the adapted JMenu.
29
     * Creates an object with the adapted JTree.
30
     * @param objectToAdapt 
30
     * @param objectToAdapt 
31
     */
31
     */
32
    public JTreeAdapter(Object objectToAdapt) {
32
    public JTreeAdapter(Object objectToAdapt) {
(-)a/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/swing/uiadapter/factory/SwingAdapterFactory.java (-1 / +6 lines)
Lines 20-25 import javax.swing.JPopupMenu; Link Here
20
import javax.swing.JRadioButton;
20
import javax.swing.JRadioButton;
21
import javax.swing.JTable;
21
import javax.swing.JTable;
22
import javax.swing.JTree;
22
import javax.swing.JTree;
23
import javax.swing.text.JTextComponent;
23
24
24
import org.eclipse.jubula.rc.common.uiadapter.factory.IUIAdapterFactory;
25
import org.eclipse.jubula.rc.common.uiadapter.factory.IUIAdapterFactory;
25
import org.eclipse.jubula.rc.common.uiadapter.interfaces.IComponentAdapter;
26
import org.eclipse.jubula.rc.common.uiadapter.interfaces.IComponentAdapter;
Lines 29-34 import org.eclipse.jubula.rc.swing.swing.uiadapter.JMenuBarAdapter; Link Here
29
import org.eclipse.jubula.rc.swing.swing.uiadapter.JMenuItemAdapter;
30
import org.eclipse.jubula.rc.swing.swing.uiadapter.JMenuItemAdapter;
30
import org.eclipse.jubula.rc.swing.swing.uiadapter.JPopupMenuAdapter;
31
import org.eclipse.jubula.rc.swing.swing.uiadapter.JPopupMenuAdapter;
31
import org.eclipse.jubula.rc.swing.swing.uiadapter.JTableAdapter;
32
import org.eclipse.jubula.rc.swing.swing.uiadapter.JTableAdapter;
33
import org.eclipse.jubula.rc.swing.swing.uiadapter.JTextComponentAdapter;
32
import org.eclipse.jubula.rc.swing.swing.uiadapter.JTreeAdapter;
34
import org.eclipse.jubula.rc.swing.swing.uiadapter.JTreeAdapter;
33
/**
35
/**
34
 * This is the adapter factory for all swing components. It is
36
 * This is the adapter factory for all swing components. It is
Lines 48-54 public class SwingAdapterFactory implements IUIAdapterFactory { Link Here
48
        JButton.class, JCheckBox.class, JRadioButton.class,
50
        JButton.class, JCheckBox.class, JRadioButton.class,
49
        JMenuBar.class, JMenuItem.class, JTree.class , 
51
        JMenuBar.class, JMenuItem.class, JTree.class , 
50
        JCheckBox.class, JRadioButton.class, JTable.class, JPopupMenu.class,
52
        JCheckBox.class, JRadioButton.class, JTable.class, JPopupMenu.class,
51
        JList.class};
53
        JList.class, JTextComponent.class};
52
    
54
    
53
    /**
55
    /**
54
     * {@inheritDoc}
56
     * {@inheritDoc}
Lines 90-95 public class SwingAdapterFactory implements IUIAdapterFactory { Link Here
90
        } else if (objectToAdapt instanceof JPopupMenu) {
92
        } else if (objectToAdapt instanceof JPopupMenu) {
91
            returnvalue = new JPopupMenuAdapter(objectToAdapt);
93
            returnvalue = new JPopupMenuAdapter(objectToAdapt);
92
        
94
        
95
        } else if (objectToAdapt instanceof JTextComponent) {
96
            returnvalue = new JTextComponentAdapter(objectToAdapt);
97
        
93
        }
98
        }
94
        
99
        
95
        return returnvalue;
100
        return returnvalue;
(-)a/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/uiadapter/StyledTextAdapter.java (+151 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2012 BREDEX GmbH.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     BREDEX GmbH - initial API and implementation 
10
 *******************************************************************************/
11
package org.eclipse.jubula.rc.swt.uiadapter;
12
13
import org.eclipse.jubula.rc.common.driver.IRunnable;
14
import org.eclipse.jubula.rc.common.exception.StepExecutionException;
15
import org.eclipse.jubula.rc.common.logger.AutServerLogger;
16
import org.eclipse.jubula.rc.common.uiadapter.interfaces.ITextComponentAdapter;
17
import org.eclipse.jubula.tools.utils.EnvironmentUtils;
18
import org.eclipse.swt.custom.StyledText;
19
20
/**
21
 * Implementation of the Interface <code>ITextComponentAdapter</code> as a
22
 * adapter for the <code>StyledText</code> component.
23
 * @author BREDEX GmbH
24
 *
25
 */
26
public class StyledTextAdapter extends WidgetAdapter 
27
    implements ITextComponentAdapter {
28
    
29
    /** the logger */
30
    private static AutServerLogger log = new AutServerLogger(
31
        StyledTextAdapter.class);
32
    /** */
33
    private StyledText m_styledText;
34
    /**
35
     * 
36
     * @param objectToAdapt 
37
     */
38
    public StyledTextAdapter(Object objectToAdapt) {
39
        super(objectToAdapt);
40
        m_styledText = (StyledText) objectToAdapt;
41
    }
42
43
    /**
44
     * {@inheritDoc}
45
     */
46
    public String getText() {
47
        String actual = (String)getEventThreadQueuer().invokeAndWait(
48
                "getText", new IRunnable() { //$NON-NLS-1$
49
                    public Object run() {
50
                        return m_styledText.getText();
51
                    }
52
                });
53
        return actual;
54
    }
55
56
    /**
57
     * {@inheritDoc}
58
     */
59
    public void setSelection(final int start) {
60
        getEventThreadQueuer().invokeAndWait("setSelection", //$NON-NLS-1$
61
                new IRunnable() {
62
                    public Object run() {
63
                        m_styledText.setSelection(start);
64
                        return null;
65
                    }
66
                });
67
68
    }
69
70
    /**
71
     * {@inheritDoc}
72
     */
73
    public void setSelection(final int start, final int end) {
74
        getEventThreadQueuer().invokeAndWait("setSelection", //$NON-NLS-1$
75
                new IRunnable() {
76
                    public Object run() {
77
                        m_styledText.setSelection(start, end);
78
                        return null;
79
                    }
80
                });
81
82
    }
83
    
84
    /**
85
     * {@inheritDoc}
86
     */
87
    public String getSelectionText() {
88
        String actual = (String)getEventThreadQueuer().invokeAndWait(
89
                "getText", new IRunnable() { //$NON-NLS-1$
90
                    public Object run() {
91
                        return m_styledText.getSelectionText();
92
                    }
93
                });
94
        return actual;
95
    }
96
97
    /**
98
     * {@inheritDoc}
99
     */
100
    public void selectAll() {
101
        final String totalText = getText();
102
        
103
        // fix for https://bxapps.bredex.de/bugzilla/show_bug.cgi?id=201
104
        // The keystroke "command + a" sometimes causes an "a" to be entered
105
        // into the text field instead of selecting all text (or having no 
106
        // effect).
107
        if (!EnvironmentUtils.isMacOS()) {
108
            try {
109
                getRobot().keyStroke(getRobot().getSystemModifierSpec() + " A"); //$NON-NLS-1$
110
            } catch (StepExecutionException see) {
111
                /*This might happen under certain circumstances e.g. on MacOS X see
112
              bug 342691 */ 
113
                log.warn(see);
114
            }
115
        }
116
        
117
        if (!totalText.equals(getSelectionText())) {
118
            // the selection failed for some reason
119
            getEventThreadQueuer().invokeAndWait("text.selectAll", //$NON-NLS-1$
120
                    new IRunnable() {
121
                        public Object run() {
122
                            m_styledText.selectAll();
123
                            return null;
124
                        }
125
                    });
126
        }
127
        
128
        String selectionText = getSelectionText();
129
        if (!totalText.equals(selectionText)) {
130
            log.warn("SelectAll failed!\n"  //$NON-NLS-1$
131
                + "Total text: '" + totalText + "'\n"   //$NON-NLS-1$//$NON-NLS-2$
132
                + "Selected text: '" + selectionText + "'"); //$NON-NLS-1$ //$NON-NLS-2$
133
        }
134
135
    }
136
137
    /**
138
     * {@inheritDoc}
139
     */
140
    public boolean isEditable() {
141
        return ((Boolean)getEventThreadQueuer().invokeAndWait(
142
                "isEditable", //$NON-NLS-1$
143
                new IRunnable() {
144
                public Object run() {
145
                    return m_styledText.getEditable() 
146
                        && m_styledText.getEnabled()
147
                            ? Boolean.TRUE : Boolean.FALSE; // see findBugs
148
                }
149
            })).booleanValue();
150
    }
151
}
(-)a/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/uiadapter/TextComponentAdapter.java (+153 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2012 BREDEX GmbH.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     BREDEX GmbH - initial API and implementation 
10
 *******************************************************************************/
11
package org.eclipse.jubula.rc.swt.uiadapter;
12
13
import org.eclipse.jubula.rc.common.driver.IRunnable;
14
import org.eclipse.jubula.rc.common.exception.StepExecutionException;
15
import org.eclipse.jubula.rc.common.logger.AutServerLogger;
16
import org.eclipse.jubula.rc.common.uiadapter.interfaces.ITextComponentAdapter;
17
import org.eclipse.jubula.tools.utils.EnvironmentUtils;
18
import org.eclipse.swt.widgets.Text;
19
20
/**
21
 * Implementation of the Interface <code>ITextComponentAdapter</code> as a
22
 * adapter for the <code>Text</code> component.
23
 * @author BREDEX GmbH
24
 *
25
 */
26
public class TextComponentAdapter extends WidgetAdapter implements
27
        ITextComponentAdapter {
28
    
29
    /** the logger */
30
    private static AutServerLogger log = new AutServerLogger(
31
        TextComponentAdapter.class);
32
    
33
    /** */
34
    private Text m_textComponent;
35
    /**
36
     * 
37
     * @param objectToAdapt 
38
     */
39
    public TextComponentAdapter(Object objectToAdapt) {
40
        super(objectToAdapt);
41
        m_textComponent = (Text) objectToAdapt;
42
    }
43
44
    /**
45
     * {@inheritDoc}
46
     */
47
    public String getText() {
48
        String actual = (String)getEventThreadQueuer().invokeAndWait(
49
                "getText", new IRunnable() { //$NON-NLS-1$
50
                    public Object run() {
51
                        return m_textComponent.getText();
52
                    }
53
                });
54
        return actual;
55
    }
56
57
    /**
58
     * {@inheritDoc}
59
     */
60
    public void setSelection(final int start) {
61
        getEventThreadQueuer().invokeAndWait("setSelection", //$NON-NLS-1$
62
                new IRunnable() {
63
                    public Object run() {
64
                        m_textComponent.setSelection(start);
65
                        return null;
66
                    }
67
                });
68
69
    }
70
71
    /**
72
     * {@inheritDoc}
73
     */
74
    public void setSelection(final int start, final int end) {
75
        getEventThreadQueuer().invokeAndWait("setSelection", //$NON-NLS-1$
76
                new IRunnable() {
77
                    public Object run() {
78
                        m_textComponent.setSelection(start, end);
79
                        return null;
80
                    }
81
                });
82
83
    }
84
    
85
    /**
86
     * {@inheritDoc}
87
     */
88
    public String getSelectionText() {
89
        String actual = (String)getEventThreadQueuer().invokeAndWait(
90
                "getText", new IRunnable() { //$NON-NLS-1$
91
                    public Object run() {
92
                        return m_textComponent.getSelectionText();
93
                    }
94
                });
95
        return actual;
96
    }
97
98
    /**
99
     * {@inheritDoc}
100
     */
101
    public void selectAll() {
102
        final String totalText = getText();
103
        
104
        // fix for https://bxapps.bredex.de/bugzilla/show_bug.cgi?id=201
105
        // The keystroke "command + a" sometimes causes an "a" to be entered
106
        // into the text field instead of selecting all text (or having no 
107
        // effect).
108
        if (!EnvironmentUtils.isMacOS()) {
109
            try {
110
                getRobot().keyStroke(getRobot().getSystemModifierSpec() + " A"); //$NON-NLS-1$
111
            } catch (StepExecutionException see) {
112
                /*This might happen under certain circumstances e.g. on MacOS X see
113
              bug 342691 */ 
114
                log.warn(see);
115
            }
116
        }
117
        
118
        if (!totalText.equals(getSelectionText())) {
119
            // the selection failed for some reason
120
            getEventThreadQueuer().invokeAndWait("text.selectAll", //$NON-NLS-1$
121
                    new IRunnable() {
122
                        public Object run() {
123
                            m_textComponent.selectAll();
124
                            return null;
125
                        }
126
                    });
127
        }
128
        
129
        String selectionText = getSelectionText();
130
        if (!totalText.equals(selectionText)) {
131
            log.warn("SelectAll failed!\n"  //$NON-NLS-1$
132
                + "Total text: '" + totalText + "'\n"   //$NON-NLS-1$//$NON-NLS-2$
133
                + "Selected text: '" + selectionText + "'"); //$NON-NLS-1$ //$NON-NLS-2$
134
        }
135
136
    }
137
138
    /**
139
     * {@inheritDoc}
140
     */
141
    public boolean isEditable() {
142
        return ((Boolean)getEventThreadQueuer().invokeAndWait(
143
                "isEditable", //$NON-NLS-1$
144
                new IRunnable() {
145
                public Object run() {
146
                    return m_textComponent.getEditable() 
147
                        && m_textComponent.getEnabled()
148
                            ? Boolean.TRUE : Boolean.FALSE; // see findBugs
149
                }
150
            })).booleanValue();
151
    }
152
153
}
(-)a/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/uiadapter/factory/SWTAdapterFactory.java (-1 / +9 lines)
Lines 16-28 import org.eclipse.jubula.rc.swt.uiadapter.ButtonAdapter; Link Here
16
import org.eclipse.jubula.rc.swt.uiadapter.ListAdapter;
16
import org.eclipse.jubula.rc.swt.uiadapter.ListAdapter;
17
import org.eclipse.jubula.rc.swt.uiadapter.MenuAdapter;
17
import org.eclipse.jubula.rc.swt.uiadapter.MenuAdapter;
18
import org.eclipse.jubula.rc.swt.uiadapter.MenuItemAdapter;
18
import org.eclipse.jubula.rc.swt.uiadapter.MenuItemAdapter;
19
import org.eclipse.jubula.rc.swt.uiadapter.StyledTextAdapter;
19
import org.eclipse.jubula.rc.swt.uiadapter.TableAdapter;
20
import org.eclipse.jubula.rc.swt.uiadapter.TableAdapter;
21
import org.eclipse.jubula.rc.swt.uiadapter.TextComponentAdapter;
20
import org.eclipse.jubula.rc.swt.uiadapter.TreeAdapter;
22
import org.eclipse.jubula.rc.swt.uiadapter.TreeAdapter;
23
import org.eclipse.swt.custom.StyledText;
21
import org.eclipse.swt.widgets.Button;
24
import org.eclipse.swt.widgets.Button;
22
import org.eclipse.swt.widgets.List;
25
import org.eclipse.swt.widgets.List;
23
import org.eclipse.swt.widgets.Menu;
26
import org.eclipse.swt.widgets.Menu;
24
import org.eclipse.swt.widgets.MenuItem;
27
import org.eclipse.swt.widgets.MenuItem;
25
import org.eclipse.swt.widgets.Table;
28
import org.eclipse.swt.widgets.Table;
29
import org.eclipse.swt.widgets.Text;
26
import org.eclipse.swt.widgets.Tree;
30
import org.eclipse.swt.widgets.Tree;
27
31
28
/**
32
/**
Lines 35-41 public class SWTAdapterFactory implements IUIAdapterFactory { Link Here
35
    /** */
39
    /** */
36
    private static final Class[] SUPPORTEDCLASSES = 
40
    private static final Class[] SUPPORTEDCLASSES = 
37
            new Class[]{Button.class, Menu.class, MenuItem.class, Tree.class,
41
            new Class[]{Button.class, Menu.class, MenuItem.class, Tree.class,
38
                Table.class, List.class};
42
                Table.class, List.class, Text.class, StyledText.class};
39
    
43
    
40
    
44
    
41
    /**
45
    /**
Lines 62-67 public class SWTAdapterFactory implements IUIAdapterFactory { Link Here
62
            returnvalue = new TableAdapter(objectToAdapt);
66
            returnvalue = new TableAdapter(objectToAdapt);
63
        } else if (objectToAdapt instanceof List) {
67
        } else if (objectToAdapt instanceof List) {
64
            returnvalue = new ListAdapter(objectToAdapt);
68
            returnvalue = new ListAdapter(objectToAdapt);
69
        } else if (objectToAdapt instanceof Text) {
70
            returnvalue = new TextComponentAdapter(objectToAdapt);
71
        } else if (objectToAdapt instanceof StyledText) {
72
            returnvalue = new StyledTextAdapter(objectToAdapt);
65
        }
73
        }
66
        
74
        
67
        
75
        
(-)a/org.eclipse.jubula.toolkit.provider.swing/resources/xml/ComponentConfiguration.xml (-1 / +1 lines)
Lines 72-78 Link Here
72
	
72
	
73
	<toolkitComponent type="javax.swing.text.JTextComponent" visible="false">
73
	<toolkitComponent type="javax.swing.text.JTextComponent" visible="false">
74
		<realizes>guidancer.concrete.TextComponent</realizes>
74
		<realizes>guidancer.concrete.TextComponent</realizes>
75
		<testerClass>org.eclipse.jubula.rc.swing.swing.implclasses.JTextComponentImplClass</testerClass>
75
		<testerClass>org.eclipse.jubula.rc.common.caps.AbstractTextComponent</testerClass>
76
		<componentClass name="javax.swing.text.JTextComponent" />
76
		<componentClass name="javax.swing.text.JTextComponent" />
77
	</toolkitComponent>
77
	</toolkitComponent>
78
	
78
	
(-)a/org.eclipse.jubula.toolkit.provider.swt/resources/xml/ComponentConfiguration.xml (-3 / +2 lines)
Lines 172-184 Link Here
172
	
172
	
173
	<toolkitComponent type="org.eclipse.swt.widgets.Text" visible="false">
173
	<toolkitComponent type="org.eclipse.swt.widgets.Text" visible="false">
174
		<realizes>guidancer.abstract.SwtText</realizes>
174
		<realizes>guidancer.abstract.SwtText</realizes>
175
		<testerClass>org.eclipse.jubula.rc.swt.implclasses.TextImplClass</testerClass>
175
		<testerClass>org.eclipse.jubula.rc.common.caps.AbstractTextComponent</testerClass>
176
		<componentClass name="org.eclipse.swt.widgets.Text" />
176
		<componentClass name="org.eclipse.swt.widgets.Text" />
177
	</toolkitComponent>
177
	</toolkitComponent>
178
	
178
	
179
	<toolkitComponent type="org.eclipse.swt.custom.StyledText" visible="false">
179
	<toolkitComponent type="org.eclipse.swt.custom.StyledText" visible="false">
180
		<realizes>guidancer.abstract.SwtText</realizes>
180
		<realizes>guidancer.abstract.SwtText</realizes>
181
		<testerClass>org.eclipse.jubula.rc.swt.implclasses.StyledTextImplClass</testerClass>
181
		<testerClass>org.eclipse.jubula.rc.common.caps.AbstractTextComponent</testerClass>
182
		<componentClass name="org.eclipse.swt.custom.StyledText" />
182
		<componentClass name="org.eclipse.swt.custom.StyledText" />
183
	</toolkitComponent>
183
	</toolkitComponent>
184
	
184
	
185
- 

Return to bug 394179