Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 223950 Details for
Bug 394179
Enhancement: Refactoring and generalization of the RC Swing and SWT
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Implementation of text components
TextArea.patch (text/plain), 35.42 KB, created by
Marvin Mueller
on 2012-11-26 07:13:57 EST
(
hide
)
Description:
Implementation of text components
Filename:
MIME Type:
Creator:
Marvin Mueller
Created:
2012-11-26 07:13:57 EST
Size:
35.42 KB
patch
obsolete
>From d5e8c078ebfd452a063bedd9be3a13466038a3f8 Mon Sep 17 00:00:00 2001 >From: Marvin Mueller <marvin.mueller@bredex.de> >Date: Thu, 22 Nov 2012 16:09:29 +0100 >Subject: [PATCH 3/3] Adding support for Text Components > >--- > .../rc/common/caps/AbstractTextComponent.java | 205 +++++++++++++++++++++ > .../jubula/rc/common/caps/AbstractWidgetCAPs.java | 8 + > .../factory/GUIAdapterFactoryRegistry.java | 8 +- > .../interfaces/ITextComponentAdapter.java | 52 ++++++ > .../swing/uiadapter/JTextComponentAdapter.java | 119 ++++++++++++ > .../rc/swing/swing/uiadapter/JTreeAdapter.java | 2 +- > .../uiadapter/factory/SwingAdapterFactory.java | 7 +- > .../jubula/rc/swt/uiadapter/StyledTextAdapter.java | 151 +++++++++++++++ > .../rc/swt/uiadapter/TextComponentAdapter.java | 153 +++++++++++++++ > .../swt/uiadapter/factory/SWTAdapterFactory.java | 10 +- > .../resources/xml/ComponentConfiguration.xml | 2 +- > .../resources/xml/ComponentConfiguration.xml | 4 +- > 12 files changed, 712 insertions(+), 9 deletions(-) > create mode 100644 org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/caps/AbstractTextComponent.java > create mode 100644 org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/uiadapter/interfaces/ITextComponentAdapter.java > create mode 100644 org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/swing/uiadapter/JTextComponentAdapter.java > create mode 100644 org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/uiadapter/StyledTextAdapter.java > create mode 100644 org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/uiadapter/TextComponentAdapter.java > >diff --git a/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/caps/AbstractTextComponent.java b/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/caps/AbstractTextComponent.java >new file mode 100644 >index 0000000..3a67632 >--- /dev/null >+++ b/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/caps/AbstractTextComponent.java >@@ -0,0 +1,205 @@ >+/******************************************************************************* >+ * Copyright (c) 2012 BREDEX GmbH. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * BREDEX GmbH - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jubula.rc.common.caps; >+ >+import org.apache.commons.lang.StringUtils; >+import org.eclipse.jubula.rc.common.exception.StepExecutionException; >+import org.eclipse.jubula.rc.common.implclasses.MatchUtil; >+import org.eclipse.jubula.rc.common.implclasses.Verifier; >+import org.eclipse.jubula.rc.common.uiadapter.interfaces.ITextComponentAdapter; >+import org.eclipse.jubula.tools.objects.event.EventFactory; >+import org.eclipse.jubula.tools.objects.event.TestErrorEvent; >+import org.eclipse.jubula.tools.utils.TimeUtil; >+/** >+ * Implementation of the CAPs from all Text like components. >+ * @author BREDEX GmbH >+ * >+ */ >+public class AbstractTextComponent extends AbstractTextInputSupport { >+ >+ /** >+ * Gets the specific adapter >+ * @return the specific adapter >+ */ >+ private ITextComponentAdapter getTextCompAdapter() { >+ return (ITextComponentAdapter) getComponent(); >+ } >+ >+ /** >+ * Sets the caret at the position <code>index</code>. >+ * @param index The caret position >+ */ >+ private void setCaretPosition(final int index) { >+ if (index < 0) { >+ throw new StepExecutionException("Invalid position: " + index, //$NON-NLS-1$ >+ EventFactory.createActionError(TestErrorEvent.INPUT_FAILED)); >+ } >+ int index2 = 0; >+ String text = getTextCompAdapter().getText(); >+ if (text != null) { >+ index2 = index > text.length() ? text.length() : index; >+ } >+ getTextCompAdapter().setSelection(index2); >+ } >+ >+ /** >+ * @param text The text to insert at the current caret position >+ */ >+ protected void insertText(final String text) { >+ // Scroll it to visible first to ensure that the typing >+ // performs correctly. >+ getRobot().scrollToVisible(getComponent().getRealComponent(), null); >+ getRobot().type(getComponent().getRealComponent(), text); >+ } >+ >+ /** >+ * Types <code>text</code> into the component. This replaces the shown >+ * content. >+ * >+ * @param text the text to type in >+ */ >+ public void gdReplaceText(String text) { >+ gdSelect(); >+ if (StringUtils.EMPTY.equals(text)) { >+ getRobot().keyStroke("DELETE"); //$NON-NLS-1$ >+ } >+ insertText(text); >+ } >+ >+ /** >+ * Types <code>text</code> into the component. >+ * >+ * @param text the text to type in >+ */ >+ public void gdInputText(String text) { >+ if (!getTextCompAdapter().hasFocus()) { >+ TimeUtil.delay(100); >+ gdClick(1, 1); >+ } >+ insertText(text); >+ } >+ >+ /** >+ * Inserts <code>text</code> at the position <code>index</code>. >+ * >+ * @param text The text to insert >+ * @param index The position for insertion >+ */ >+ public void gdInsertText(String text, int index) { >+ gdClick(1, 1); >+ setCaretPosition(index); >+ insertText(text); >+ } >+ >+ /** >+ * Inserts <code>text</code> before or after the first appearance of >+ * <code>pattern</code>. >+ * @param text The text to insert >+ * @param pattern The pattern to find the position for insertion >+ * @param operator Operator to select Matching Algorithm >+ * @param after If <code>true</code>, the text will be inserted after the >+ * pattern, otherwise before the pattern. >+ * @throws StepExecutionException If the pattern is invalid or cannot be found >+ */ >+ public void gdInsertText(String text, String pattern, String operator, >+ boolean after) >+ throws StepExecutionException { >+ >+ if (text == null) { >+ throw new StepExecutionException( >+ "The text to be inserted must not be null", EventFactory //$NON-NLS-1$ >+ .createActionError()); >+ } >+ final MatchUtil.FindResult matchedText = MatchUtil.getInstance(). >+ find(getTextCompAdapter().getText(), pattern, operator); >+ >+ if ((matchedText == null) || (matchedText.getStr() == null)) { >+ throw new StepExecutionException("The pattern '" + pattern //$NON-NLS-1$ >+ + "' could not be found", //$NON-NLS-1$ >+ EventFactory.createActionError(TestErrorEvent.NOT_FOUND)); >+ } >+ >+ int index = matchedText.getPos(); >+ >+ int insertPos = after ? index + matchedText.getStr().length() : index; >+ gdInsertText(text, insertPos); >+ } >+ >+ >+ >+ /** >+ * select the whole text of the textfield by calling "selectAll()". >+ */ >+ public void gdSelect() { >+ gdClick(1, 1); >+ // Wait a while. Without this, we got no selectAll sometimes! >+ TimeUtil.delay(100); >+ getTextCompAdapter().selectAll(); >+ } >+ >+ /** >+ * Verifies the editable property. >+ * @param editable The editable property to verify. >+ */ >+ public void gdVerifyEditable(boolean editable) { >+ Verifier.equals(editable, getTextCompAdapter().isEditable()); >+ } >+ >+ /** >+ * Selects the first (not)appearance of <code>pattern</code> in the text >+ * component's content. >+ * >+ * @param pattern The pattern to select >+ * @param operator operator >+ * @throws StepExecutionException >+ * If the pattern is invalid or cannot be found >+ */ >+ public void gdSelect(final String pattern, String operator) >+ throws StepExecutionException { >+ gdClick(1, 1); >+ final MatchUtil.FindResult matchedText = MatchUtil.getInstance(). >+ find(getTextCompAdapter().getText(), pattern, operator); >+ if ((matchedText == null) || (matchedText.getStr().length() == 0)) { >+ throw new StepExecutionException("Invalid pattern for insertion", //$NON-NLS-1$ >+ EventFactory.createActionError()); >+ } >+ final int index = matchedText.getPos(); >+ if (operator.startsWith("not")) { //$NON-NLS-1$ >+ if (pattern.equals(getTextCompAdapter().getText())) { >+ String msg = "The pattern '" + pattern //$NON-NLS-1$ >+ + "' is equal to current text"; //$NON-NLS-1$ >+ throw new StepExecutionException(msg, EventFactory >+ .createActionError(TestErrorEvent >+ .EXECUTION_ERROR, new String[] {msg})); >+ } else if (index > 0) { >+ // select part before pattern >+ getTextCompAdapter().setSelection(0, index); >+ } else { >+ // select part after pattern >+ getTextCompAdapter().setSelection( >+ matchedText.getStr().length(), >+ getTextCompAdapter().getText().length()); >+ } >+ } else { >+ getTextCompAdapter().setSelection(index, >+ index + matchedText.getStr().length()); >+ } >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public String[] getTextArrayFromComponent() { >+ return null; >+ } >+ >+ >+} >diff --git a/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/caps/AbstractWidgetCAPs.java b/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/caps/AbstractWidgetCAPs.java >index 888eb8b..4f0fb1b 100644 >--- a/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/caps/AbstractWidgetCAPs.java >+++ b/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/caps/AbstractWidgetCAPs.java >@@ -99,6 +99,14 @@ public abstract class AbstractWidgetCAPs extends AbstractUICAPs { > .setClickCount(count) > .setMouseButton(button)); > } >+ >+ /** >+ * Clicks the center of the component with the MouseButton 1 >+ * @param count Number of mouse clicks >+ */ >+ public void gdclick(int count) { >+ gdClick(count, 1); >+ } > /** > * clicks into a component. > * >diff --git a/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/uiadapter/factory/GUIAdapterFactoryRegistry.java b/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/uiadapter/factory/GUIAdapterFactoryRegistry.java >index c75e1bd..d89cbd6 100644 >--- a/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/uiadapter/factory/GUIAdapterFactoryRegistry.java >+++ b/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/uiadapter/factory/GUIAdapterFactoryRegistry.java >@@ -88,11 +88,13 @@ public class GUIAdapterFactoryRegistry { > Class adapteeclass = objectToAdapt.getClass(); > IUIAdapterFactory factory = (IUIAdapterFactory) m_registrationMap. > get(adapteeclass); >- while (factory == null && adapteeclass != Object.class) { >+ Class superclass = adapteeclass; >+ while (factory == null && superclass != Object.class) { > factory = (IUIAdapterFactory) m_registrationMap. >- get(adapteeclass.getSuperclass()); >+ get(superclass); >+ superclass = superclass.getSuperclass(); > } >- >+ // FIXME Here is missing the right Exception!!! > return factory.getAdapter(objectToAdapt); > > } >diff --git a/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/uiadapter/interfaces/ITextComponentAdapter.java b/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/uiadapter/interfaces/ITextComponentAdapter.java >new file mode 100644 >index 0000000..4e989c6 >--- /dev/null >+++ b/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/uiadapter/interfaces/ITextComponentAdapter.java >@@ -0,0 +1,52 @@ >+/******************************************************************************* >+ * Copyright (c) 2012 BREDEX GmbH. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * BREDEX GmbH - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jubula.rc.common.uiadapter.interfaces; >+/** >+ * Interface for all needed methods which are needed from TextComponents >+ * @author BREDEX GmbH >+ * >+ */ >+public interface ITextComponentAdapter extends ITextVerifiable { >+ >+ /** >+ * Sets the caret to a specific position. >+ * >+ * @param start The index at which the selection begins. >+ */ >+ void setSelection(int start); >+ /** >+ * Selects text in the component. >+ * >+ * @param start The index at which the selection begins. >+ * @param end The index at which the selection ends. >+ */ >+ void setSelection(int start, int end); >+ >+ >+ /** >+ * >+ * @return the selectes text >+ */ >+ String getSelectionText(); >+ >+ /** >+ * Selects all text in the component. >+ */ >+ void selectAll(); >+ >+ /** >+ * >+ * @return the value if the Text Component is editable >+ */ >+ boolean isEditable(); >+ >+ >+} >diff --git a/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/swing/uiadapter/JTextComponentAdapter.java b/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/swing/uiadapter/JTextComponentAdapter.java >new file mode 100644 >index 0000000..75ed7a5 >--- /dev/null >+++ b/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/swing/uiadapter/JTextComponentAdapter.java >@@ -0,0 +1,119 @@ >+/******************************************************************************* >+ * Copyright (c) 2012 BREDEX GmbH. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * BREDEX GmbH - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jubula.rc.swing.swing.uiadapter; >+ >+import javax.swing.text.JTextComponent; >+ >+import org.eclipse.jubula.rc.common.driver.IRunnable; >+import org.eclipse.jubula.rc.common.uiadapter.interfaces.ITextComponentAdapter; >+/** >+ * Implementation of the Interface <code>ITextComponentAdapter</code> as a >+ * adapter for the <code>JTextComponent</code> component. >+ * @author BREDEX GmbH >+ * >+ */ >+public class JTextComponentAdapter extends WidgetAdapter >+ implements ITextComponentAdapter { >+ >+ /** */ >+ private JTextComponent m_textComponent; >+ >+ /** >+ * Creates an object with the adapted JTextComponent. >+ * @param objectToAdapt >+ */ >+ public JTextComponentAdapter(Object objectToAdapt) { >+ super(objectToAdapt); >+ m_textComponent = (JTextComponent) objectToAdapt; >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public String getText() { >+ return m_textComponent.getText(); >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public void setSelection(final int position) { >+ getEventThreadQueuer().invokeAndWait("setSelection", //$NON-NLS-1$ >+ new IRunnable() { >+ public Object run() { >+ m_textComponent.setCaretPosition(position); >+ return null; >+ } >+ }); >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public void setSelection(final int start, final int end) { >+ getEventThreadQueuer().invokeAndWait("setSelection", //$NON-NLS-1$ >+ new IRunnable() { >+ public Object run() { >+ m_textComponent.setSelectionStart(start); >+ m_textComponent.setSelectionEnd(end); >+ return null; >+ } >+ }); >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public String getSelectionText() { >+ String actual = (String)getEventThreadQueuer().invokeAndWait( >+ "getSelectionText", new IRunnable() { //$NON-NLS-1$ >+ public Object run() { >+ return m_textComponent.getSelectedText(); >+ } >+ }); >+ return actual; >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public void selectAll() { >+ getRobot().keyStroke(getRobot().getSystemModifierSpec() + " A"); //$NON-NLS-1$ >+ >+ if (!getText().equals(getSelectionText())) { >+ getEventThreadQueuer().invokeAndWait( >+ "selectAll", new IRunnable() { //$NON-NLS-1$ >+ public Object run() { >+ m_textComponent.selectAll(); >+ return null; >+ } >+ }); >+ } >+ >+ } >+ >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public boolean isEditable() { >+ return ((Boolean) getEventThreadQueuer(). >+ invokeAndWait("isEditable", new IRunnable() { //$NON-NLS-1$ >+ public Object run() { >+ return m_textComponent.isEditable() >+ && m_textComponent.isEnabled() >+ ? Boolean.TRUE : Boolean.FALSE; // see findBugs >+ } >+ })).booleanValue(); >+ } >+ >+ >+} >diff --git a/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/swing/uiadapter/JTreeAdapter.java b/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/swing/uiadapter/JTreeAdapter.java >index acc0012..cd0f716 100644 >--- a/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/swing/uiadapter/JTreeAdapter.java >+++ b/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/swing/uiadapter/JTreeAdapter.java >@@ -26,7 +26,7 @@ public class JTreeAdapter extends WidgetAdapter implements ITreeAdapter { > > > /** >- * Creates an object with the adapted JMenu. >+ * Creates an object with the adapted JTree. > * @param objectToAdapt > */ > public JTreeAdapter(Object objectToAdapt) { >diff --git a/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/swing/uiadapter/factory/SwingAdapterFactory.java b/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/swing/uiadapter/factory/SwingAdapterFactory.java >index 8584168..8a3c387 100644 >--- a/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/swing/uiadapter/factory/SwingAdapterFactory.java >+++ b/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/swing/uiadapter/factory/SwingAdapterFactory.java >@@ -20,6 +20,7 @@ import javax.swing.JPopupMenu; > import javax.swing.JRadioButton; > import javax.swing.JTable; > import javax.swing.JTree; >+import javax.swing.text.JTextComponent; > > import org.eclipse.jubula.rc.common.uiadapter.factory.IUIAdapterFactory; > import org.eclipse.jubula.rc.common.uiadapter.interfaces.IComponentAdapter; >@@ -29,6 +30,7 @@ import org.eclipse.jubula.rc.swing.swing.uiadapter.JMenuBarAdapter; > import org.eclipse.jubula.rc.swing.swing.uiadapter.JMenuItemAdapter; > import org.eclipse.jubula.rc.swing.swing.uiadapter.JPopupMenuAdapter; > import org.eclipse.jubula.rc.swing.swing.uiadapter.JTableAdapter; >+import org.eclipse.jubula.rc.swing.swing.uiadapter.JTextComponentAdapter; > import org.eclipse.jubula.rc.swing.swing.uiadapter.JTreeAdapter; > /** > * This is the adapter factory for all swing components. It is >@@ -48,7 +50,7 @@ public class SwingAdapterFactory implements IUIAdapterFactory { > JButton.class, JCheckBox.class, JRadioButton.class, > JMenuBar.class, JMenuItem.class, JTree.class , > JCheckBox.class, JRadioButton.class, JTable.class, JPopupMenu.class, >- JList.class}; >+ JList.class, JTextComponent.class}; > > /** > * {@inheritDoc} >@@ -90,6 +92,9 @@ public class SwingAdapterFactory implements IUIAdapterFactory { > } else if (objectToAdapt instanceof JPopupMenu) { > returnvalue = new JPopupMenuAdapter(objectToAdapt); > >+ } else if (objectToAdapt instanceof JTextComponent) { >+ returnvalue = new JTextComponentAdapter(objectToAdapt); >+ > } > > return returnvalue; >diff --git a/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/uiadapter/StyledTextAdapter.java b/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/uiadapter/StyledTextAdapter.java >new file mode 100644 >index 0000000..45651e7 >--- /dev/null >+++ b/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/uiadapter/StyledTextAdapter.java >@@ -0,0 +1,151 @@ >+/******************************************************************************* >+ * Copyright (c) 2012 BREDEX GmbH. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * BREDEX GmbH - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jubula.rc.swt.uiadapter; >+ >+import org.eclipse.jubula.rc.common.driver.IRunnable; >+import org.eclipse.jubula.rc.common.exception.StepExecutionException; >+import org.eclipse.jubula.rc.common.logger.AutServerLogger; >+import org.eclipse.jubula.rc.common.uiadapter.interfaces.ITextComponentAdapter; >+import org.eclipse.jubula.tools.utils.EnvironmentUtils; >+import org.eclipse.swt.custom.StyledText; >+ >+/** >+ * Implementation of the Interface <code>ITextComponentAdapter</code> as a >+ * adapter for the <code>StyledText</code> component. >+ * @author BREDEX GmbH >+ * >+ */ >+public class StyledTextAdapter extends WidgetAdapter >+ implements ITextComponentAdapter { >+ >+ /** the logger */ >+ private static AutServerLogger log = new AutServerLogger( >+ StyledTextAdapter.class); >+ /** */ >+ private StyledText m_styledText; >+ /** >+ * >+ * @param objectToAdapt >+ */ >+ public StyledTextAdapter(Object objectToAdapt) { >+ super(objectToAdapt); >+ m_styledText = (StyledText) objectToAdapt; >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public String getText() { >+ String actual = (String)getEventThreadQueuer().invokeAndWait( >+ "getText", new IRunnable() { //$NON-NLS-1$ >+ public Object run() { >+ return m_styledText.getText(); >+ } >+ }); >+ return actual; >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public void setSelection(final int start) { >+ getEventThreadQueuer().invokeAndWait("setSelection", //$NON-NLS-1$ >+ new IRunnable() { >+ public Object run() { >+ m_styledText.setSelection(start); >+ return null; >+ } >+ }); >+ >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public void setSelection(final int start, final int end) { >+ getEventThreadQueuer().invokeAndWait("setSelection", //$NON-NLS-1$ >+ new IRunnable() { >+ public Object run() { >+ m_styledText.setSelection(start, end); >+ return null; >+ } >+ }); >+ >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public String getSelectionText() { >+ String actual = (String)getEventThreadQueuer().invokeAndWait( >+ "getText", new IRunnable() { //$NON-NLS-1$ >+ public Object run() { >+ return m_styledText.getSelectionText(); >+ } >+ }); >+ return actual; >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public void selectAll() { >+ final String totalText = getText(); >+ >+ // fix for https://bxapps.bredex.de/bugzilla/show_bug.cgi?id=201 >+ // The keystroke "command + a" sometimes causes an "a" to be entered >+ // into the text field instead of selecting all text (or having no >+ // effect). >+ if (!EnvironmentUtils.isMacOS()) { >+ try { >+ getRobot().keyStroke(getRobot().getSystemModifierSpec() + " A"); //$NON-NLS-1$ >+ } catch (StepExecutionException see) { >+ /*This might happen under certain circumstances e.g. on MacOS X see >+ bug 342691 */ >+ log.warn(see); >+ } >+ } >+ >+ if (!totalText.equals(getSelectionText())) { >+ // the selection failed for some reason >+ getEventThreadQueuer().invokeAndWait("text.selectAll", //$NON-NLS-1$ >+ new IRunnable() { >+ public Object run() { >+ m_styledText.selectAll(); >+ return null; >+ } >+ }); >+ } >+ >+ String selectionText = getSelectionText(); >+ if (!totalText.equals(selectionText)) { >+ log.warn("SelectAll failed!\n" //$NON-NLS-1$ >+ + "Total text: '" + totalText + "'\n" //$NON-NLS-1$//$NON-NLS-2$ >+ + "Selected text: '" + selectionText + "'"); //$NON-NLS-1$ //$NON-NLS-2$ >+ } >+ >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public boolean isEditable() { >+ return ((Boolean)getEventThreadQueuer().invokeAndWait( >+ "isEditable", //$NON-NLS-1$ >+ new IRunnable() { >+ public Object run() { >+ return m_styledText.getEditable() >+ && m_styledText.getEnabled() >+ ? Boolean.TRUE : Boolean.FALSE; // see findBugs >+ } >+ })).booleanValue(); >+ } >+} >diff --git a/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/uiadapter/TextComponentAdapter.java b/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/uiadapter/TextComponentAdapter.java >new file mode 100644 >index 0000000..1d1a55e >--- /dev/null >+++ b/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/uiadapter/TextComponentAdapter.java >@@ -0,0 +1,153 @@ >+/******************************************************************************* >+ * Copyright (c) 2012 BREDEX GmbH. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * BREDEX GmbH - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jubula.rc.swt.uiadapter; >+ >+import org.eclipse.jubula.rc.common.driver.IRunnable; >+import org.eclipse.jubula.rc.common.exception.StepExecutionException; >+import org.eclipse.jubula.rc.common.logger.AutServerLogger; >+import org.eclipse.jubula.rc.common.uiadapter.interfaces.ITextComponentAdapter; >+import org.eclipse.jubula.tools.utils.EnvironmentUtils; >+import org.eclipse.swt.widgets.Text; >+ >+/** >+ * Implementation of the Interface <code>ITextComponentAdapter</code> as a >+ * adapter for the <code>Text</code> component. >+ * @author BREDEX GmbH >+ * >+ */ >+public class TextComponentAdapter extends WidgetAdapter implements >+ ITextComponentAdapter { >+ >+ /** the logger */ >+ private static AutServerLogger log = new AutServerLogger( >+ TextComponentAdapter.class); >+ >+ /** */ >+ private Text m_textComponent; >+ /** >+ * >+ * @param objectToAdapt >+ */ >+ public TextComponentAdapter(Object objectToAdapt) { >+ super(objectToAdapt); >+ m_textComponent = (Text) objectToAdapt; >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public String getText() { >+ String actual = (String)getEventThreadQueuer().invokeAndWait( >+ "getText", new IRunnable() { //$NON-NLS-1$ >+ public Object run() { >+ return m_textComponent.getText(); >+ } >+ }); >+ return actual; >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public void setSelection(final int start) { >+ getEventThreadQueuer().invokeAndWait("setSelection", //$NON-NLS-1$ >+ new IRunnable() { >+ public Object run() { >+ m_textComponent.setSelection(start); >+ return null; >+ } >+ }); >+ >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public void setSelection(final int start, final int end) { >+ getEventThreadQueuer().invokeAndWait("setSelection", //$NON-NLS-1$ >+ new IRunnable() { >+ public Object run() { >+ m_textComponent.setSelection(start, end); >+ return null; >+ } >+ }); >+ >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public String getSelectionText() { >+ String actual = (String)getEventThreadQueuer().invokeAndWait( >+ "getText", new IRunnable() { //$NON-NLS-1$ >+ public Object run() { >+ return m_textComponent.getSelectionText(); >+ } >+ }); >+ return actual; >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public void selectAll() { >+ final String totalText = getText(); >+ >+ // fix for https://bxapps.bredex.de/bugzilla/show_bug.cgi?id=201 >+ // The keystroke "command + a" sometimes causes an "a" to be entered >+ // into the text field instead of selecting all text (or having no >+ // effect). >+ if (!EnvironmentUtils.isMacOS()) { >+ try { >+ getRobot().keyStroke(getRobot().getSystemModifierSpec() + " A"); //$NON-NLS-1$ >+ } catch (StepExecutionException see) { >+ /*This might happen under certain circumstances e.g. on MacOS X see >+ bug 342691 */ >+ log.warn(see); >+ } >+ } >+ >+ if (!totalText.equals(getSelectionText())) { >+ // the selection failed for some reason >+ getEventThreadQueuer().invokeAndWait("text.selectAll", //$NON-NLS-1$ >+ new IRunnable() { >+ public Object run() { >+ m_textComponent.selectAll(); >+ return null; >+ } >+ }); >+ } >+ >+ String selectionText = getSelectionText(); >+ if (!totalText.equals(selectionText)) { >+ log.warn("SelectAll failed!\n" //$NON-NLS-1$ >+ + "Total text: '" + totalText + "'\n" //$NON-NLS-1$//$NON-NLS-2$ >+ + "Selected text: '" + selectionText + "'"); //$NON-NLS-1$ //$NON-NLS-2$ >+ } >+ >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public boolean isEditable() { >+ return ((Boolean)getEventThreadQueuer().invokeAndWait( >+ "isEditable", //$NON-NLS-1$ >+ new IRunnable() { >+ public Object run() { >+ return m_textComponent.getEditable() >+ && m_textComponent.getEnabled() >+ ? Boolean.TRUE : Boolean.FALSE; // see findBugs >+ } >+ })).booleanValue(); >+ } >+ >+} >diff --git a/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/uiadapter/factory/SWTAdapterFactory.java b/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/uiadapter/factory/SWTAdapterFactory.java >index a1a4232..4079a78 100644 >--- a/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/uiadapter/factory/SWTAdapterFactory.java >+++ b/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/uiadapter/factory/SWTAdapterFactory.java >@@ -16,13 +16,17 @@ import org.eclipse.jubula.rc.swt.uiadapter.ButtonAdapter; > import org.eclipse.jubula.rc.swt.uiadapter.ListAdapter; > import org.eclipse.jubula.rc.swt.uiadapter.MenuAdapter; > import org.eclipse.jubula.rc.swt.uiadapter.MenuItemAdapter; >+import org.eclipse.jubula.rc.swt.uiadapter.StyledTextAdapter; > import org.eclipse.jubula.rc.swt.uiadapter.TableAdapter; >+import org.eclipse.jubula.rc.swt.uiadapter.TextComponentAdapter; > import org.eclipse.jubula.rc.swt.uiadapter.TreeAdapter; >+import org.eclipse.swt.custom.StyledText; > import org.eclipse.swt.widgets.Button; > import org.eclipse.swt.widgets.List; > import org.eclipse.swt.widgets.Menu; > import org.eclipse.swt.widgets.MenuItem; > import org.eclipse.swt.widgets.Table; >+import org.eclipse.swt.widgets.Text; > import org.eclipse.swt.widgets.Tree; > > /** >@@ -35,7 +39,7 @@ public class SWTAdapterFactory implements IUIAdapterFactory { > /** */ > private static final Class[] SUPPORTEDCLASSES = > new Class[]{Button.class, Menu.class, MenuItem.class, Tree.class, >- Table.class, List.class}; >+ Table.class, List.class, Text.class, StyledText.class}; > > > /** >@@ -62,6 +66,10 @@ public class SWTAdapterFactory implements IUIAdapterFactory { > returnvalue = new TableAdapter(objectToAdapt); > } else if (objectToAdapt instanceof List) { > returnvalue = new ListAdapter(objectToAdapt); >+ } else if (objectToAdapt instanceof Text) { >+ returnvalue = new TextComponentAdapter(objectToAdapt); >+ } else if (objectToAdapt instanceof StyledText) { >+ returnvalue = new StyledTextAdapter(objectToAdapt); > } > > >diff --git a/org.eclipse.jubula.toolkit.provider.swing/resources/xml/ComponentConfiguration.xml b/org.eclipse.jubula.toolkit.provider.swing/resources/xml/ComponentConfiguration.xml >index 0d3963c..30abd14 100644 >--- a/org.eclipse.jubula.toolkit.provider.swing/resources/xml/ComponentConfiguration.xml >+++ b/org.eclipse.jubula.toolkit.provider.swing/resources/xml/ComponentConfiguration.xml >@@ -72,7 +72,7 @@ > > <toolkitComponent type="javax.swing.text.JTextComponent" visible="false"> > <realizes>guidancer.concrete.TextComponent</realizes> >- <testerClass>org.eclipse.jubula.rc.swing.swing.implclasses.JTextComponentImplClass</testerClass> >+ <testerClass>org.eclipse.jubula.rc.common.caps.AbstractTextComponent</testerClass> > <componentClass name="javax.swing.text.JTextComponent" /> > </toolkitComponent> > >diff --git a/org.eclipse.jubula.toolkit.provider.swt/resources/xml/ComponentConfiguration.xml b/org.eclipse.jubula.toolkit.provider.swt/resources/xml/ComponentConfiguration.xml >index 6544234..9978b8c 100644 >--- a/org.eclipse.jubula.toolkit.provider.swt/resources/xml/ComponentConfiguration.xml >+++ b/org.eclipse.jubula.toolkit.provider.swt/resources/xml/ComponentConfiguration.xml >@@ -172,13 +172,13 @@ > > <toolkitComponent type="org.eclipse.swt.widgets.Text" visible="false"> > <realizes>guidancer.abstract.SwtText</realizes> >- <testerClass>org.eclipse.jubula.rc.swt.implclasses.TextImplClass</testerClass> >+ <testerClass>org.eclipse.jubula.rc.common.caps.AbstractTextComponent</testerClass> > <componentClass name="org.eclipse.swt.widgets.Text" /> > </toolkitComponent> > > <toolkitComponent type="org.eclipse.swt.custom.StyledText" visible="false"> > <realizes>guidancer.abstract.SwtText</realizes> >- <testerClass>org.eclipse.jubula.rc.swt.implclasses.StyledTextImplClass</testerClass> >+ <testerClass>org.eclipse.jubula.rc.common.caps.AbstractTextComponent</testerClass> > <componentClass name="org.eclipse.swt.custom.StyledText" /> > </toolkitComponent> > >-- >1.7.11 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 394179
:
223499
|
223848
|
223948
|
223950
|
224096
|
224662
|
225163