I am working with a RWT web-application and I need to select a piece of text and scroll to it. I use:
import org.eclipse.swt.widgets.Text;
...
Text multiLineText;
...
multiLineText.setFocus();
multiLineText.setSelection(point);
But in this case, if the selected piece of text is not in the text control (lower or higher), I need to scroll to it.
I try to add a line of code:
multiLineText.showSelection();
But my compiler says The method showSelection() is undefined for the type Text. Documentation says, this method is defined:
http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fswt%2Fwidgets%2FText.html
Related
I am writing java code to access a document open in Libre Office.
I now need to write some code which iterate over the entire document, hopefully in the same order it is shown in the editor.
I can use this code to iterate over all the normal text:
XComponent writerComponent=xComponentLoader.loadComponentFromURL(loadUrl, "_blank", 0, loadProps);
XTextDocument mxDoc=UnoRuntime.queryInterface(XTextDocument.class, writerComponent);
XText mxDocText=mxDoc.getText();
XEnumerationAccess xParaAccess = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, mxDocText);
XEnumeration xParaEnum = xParaAccess.createEnumeration();
Object element = xParaEnum.nextElement();
while (xParaEnum.hasMoreElements()) {
XEnumerationAccess inlineAccess = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, element);
XEnumeration inline = inlineAccess.createEnumeration();
// And I can then iterate over this inline element and get all the text and formatting.
}
But the problem is that this does not include any chart objects.
I can then use
XDrawPagesSupplier drawSupplier=UnoRuntime.queryInterface(XDrawPagesSupplier.class, writerComponent);
XDrawPages pages=drawSupplier.getDrawPages();
XDrawPage drawPage=UnoRuntime.queryInterface(XDrawPage.class,page);
for(int j=0;j!=drawPage.getCount();j++) {
Object sub=drawPage.getByIndex(j);
XShape subShape=UnoRuntime.queryInterface(XShape.class,sub);
// Now I got my subShape, but how do I know its position, relative to the text.
}
And this gives me all charts (And other figures I guess), but the problem is: How do I find out where these charts are positioned in relation to the text in the model. And how do I get a cursor which represent each chart?
Update:
I am now looking for an anchor for my XShape, but XShape don't have a getAnchor() method.
But If I use
XPropertySet prop=UnoRuntime.queryInterface(XPropertySet.class,shape);
I get the prop class.
And I call prop.getPropertyValue("AnchorType") which gives me an ancher type of TextContentAnchorType.AS_CHARACTER
but I just can't get the anchor itself. There are no anchor or textrange property.
btw: I tried looking into installing "MRI" for libre office, but the only version I could find hav libreoffice 3.3 as supported version, and it would not install on version 7.1
----- Update 2 -----
I managed to make it work. It turns out that my XShape also implements XTextContent (Thank you MRI), so all I had to do was:
XTextContent subContent=UnoRuntime.queryInterface(XTextContent.class,subShape);
XTextRange anchor=subContent.getAnchor();
XTextCursor cursor = anchor.getText().createTextCursorByRange(anchor.getStart());
cursor.goRight((short)50,true);
System.out.println("String=" + cursor.getString());
This gives me a cursor which point to the paragraph, which I can then move forward/backward to find out where the shape is. So this println call will print the 50 chars following the XShape.
How do I find out where these charts are positioned in relation to the text in the model. And how do I get a cursor which represent each chart?
Abridged comments
Anchors pin objects to a specific location. Does the shape have a method getAnchor() or property AnchorType? I would use an introspection tool such as MRI to determine this. Download MRI 1.3.4 from https://github.com/hanya/MRI/releases.
As far as a cursor, maybe it is similar to tables:
oText = oTable.getAnchor().getText()
oCurs = oText.createTextCursor()
Code solution given by OP
XTextContent subContent=UnoRuntime.queryInterface(XTextContent.class,subShape);
XTextRange anchor=subContent.getAnchor();
XTextCursor cursor = anchor.getText().createTextCursorByRange(anchor.getStart());
cursor.goRight((short)50,true);
System.out.println("String=" + cursor.getString());
I have the following code snippet and the screenshot attached.
String query = "new UiScrollable(new UiSelector().className(\"androidx.recyclerview.widget.RecyclerView\"))" +
".scrollIntoView(new UiSelector().text(\"Test Group\"))";
driver.findElementByAndroidUIAutomator (query).click ();
What I want is to find an element with the text "Test Group" using UISelector, but inside the RecyclerView only (not searching the whole app source). What I get is the element inside search field instead (not in the RecyclerView).
Please advice. I know that I can get all searched elements using findElements(By.id("name")). But I want to use UI selector in this case.
With UiSelector you can use chaining:
String query = "new UiScrollable(resourseIdMatches(\".*recycler_view\")).scrollIntoView(resourseIdMatches(\".*recycler_view\")).childSelector(text(\"Text Group\")))";
In addition new UiSelector... part can be omitted. Appium does support this syntax.
Basically I have changed the css for a text field in javafx by adding a style class like this:
textfield.getStyleClass().add("textfieldstyle");
But then I want to be able to revert it back to its original appearance. But since the original appearance in this case is the default skin for JavaFX, I can't find the original layout for the textfields. I found the textfieldskin properties here, but its a jungle, and I can't find anything about the color of the -fx-control-inner-background, -fx-text-box-border and -fx-focus-color, which is what I want to know.
I've triedtextfield.getStyleClass().remove("textfieldstyle"); and think that does remove the new css, but it doesn't apply the old one again.
Thanks to the comments by #UlukBiy and #varren I solved the issue. System.out.println(textfield.getStyleClass()); was of great use since it allowed me to check which style classes were applied on the text field as default. And as it is pointed out in the comments those where text-input and text-field.
So to restore the text field's css to its default value I just did:
textfield.getStyleClass().clear();
textfield.getStyleClass().addAll("text-field", "text-input");
To reset an element's default styling after setting it using .setStyle("css settings....."); you can simply use -
textfield.setStyle(null);
I'm not sure if this would work on it's own for an element that's had a class applied using .getStyleClass().add("textfieldstyle"); but if not you could do something like -
textfield.getStyleClass().clear();
textfield.setStyle(null);
A short way to effictively remove your style class even in case of duplicates, with a lambda :
textfield.getStyleClass().removeIf(style -> style.equals("textfieldstyle"));
The following test code works for me when adding and removing a class from a control such as Textfield:
import javafx.scene.control.TextInputControl;
public class test
{
protected void setEditable(final TextInputControl toControl, final boolean tlEditable)
{
toControl.setEditable(tlEditable);
if (tlEditable)
{
if (toControl.getStyleClass().contains("non-editable-class"))
{
toControl.getStyleClass().removeAll("non-editable-class");
}
}
else if (!toControl.getStyleClass().contains("non-editable-class"))
{
toControl.getStyleClass().add("non-editable-class");
}
}
}
I am building an extention which first gets the window associated with an HTTPRequest as explained here.
There is a div element in the document which has a src from an external website. I basically cancel the request and get the associated window.
Now say I want to fill that window's doc with a string "Hello World".
Using the following in JavaScript (JSNI) works (ie, it replaces the string where normally the data from external source would be):
window.document.write("Hello World");
But I really need to do that in Java rather than through JSNI.
I tried using the class Document to pass the object making the call from JSNI as:
#[package].[class]::populateBox(Lcom/google/gwt/dom/client/Document)(window.document);
The method is defined as:
public static void populateBox(Document doc){
doc.getBody().setInnerHTML("Hello World);
}
This code rather than replacing text at the div where the request was to be loaded replaces the top level body of the html document.
What is the problem here? Is Document the wrong class to use here?
There is no problem with your Code:
window.document donates th the Document.
doc.getBody() will be the complete body of the Document.
doc.getBody().setInnerHTML(""); will reomove the complete content and set the body to a new value.
I think you are looking for appendChild:
DOM.appentChild(doc.getBody(), new HTML('Hello World!').getElement());
I am trying to bind the visibility of a JLabel to whether the text of a JTextField is empty or not.
I want to do this because I want to hide the JLabel with a red asterisk, which denotes that filling in a text field is compulsory, so it should hide when it is filled in.
The following does however not work (with ${text.isEmpty}):
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(
org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE,
estimatedCostTextField,
org.jdesktop.beansbinding.ELProperty.create("${text.isEmpty}"),
estimatedCostAsterisk,
org.jdesktop.beansbinding.BeanProperty.create("visible"));
bindingGroup.addBinding(binding);
Can anybody help me with this?
I found the answer. You should use ${empty text}
So the code becomes:
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(
org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ,
estimatedCostTextField,
org.jdesktop.beansbinding.ELProperty.create("${empty text}"),
estimatedCostAsterisk,
org.jdesktop.beansbinding.BeanProperty.create("visible"));
bindingGroup.addBinding(binding);