I just started creating a SWT/JFace application using the (now free) WindowBuilder from Google (previously instantiations).
I find the Data binding part difficult although it -should- make it easier for me.
For instance, I cannot bind the enabling-property of a button to a (myself defined) boolean function.
Are there any resources (demos, text, tutorials, examples) about using the WindowBuilder GUI and/or the data binding principle?
The information found on the google page or the instantiations page did not help me enough.
For what it's worth:
bindingContext.bindValue(
new ComputedValue() {
public Object calculate() {
// calculate the enablement using the value of other, previously
// created observables.
}
},
WidgetProperties.enabled().observe(theButton)
);
The Eclipse newsgroups are a great place to ask these questions. Try the eclipse.platform.jface newsgroup.
Related
As the title says I'm wondering whether Eclipse RCP 4 provides any built in cut/copy/paste handlers which can be linked to the org.eclipse.ui.edit.cut, org.eclipse.ui.edit.copy and org.eclipse.ui.edit.paste commands?
I appreciate that that a custom handler may be needed for some SWT widgets or more complex use cases with cut/copy/paste operations, but I can't help but feel I'm trying to re-invent the wheel to copy some text from one component and paste in into another.
If there aren't any built in cut/copy/paste handlers, are there any well documented examples of how to do this? I understand how to use the clipboard.getContents and clipboard.setContents methods, but have found this starts to become non-trivial when trying to find out what text was selected when the copy command is invoked and which component has focus and whether its read only when the paste command is invoked.
I've looked at this StackOverflow question but it doesn't explain whether there any built in handlers or offer any guidance on writing my own handlers.
For a 3.x compatibilty mode Eclipse 4 application these commands are defined as:
<command
name="%command.cut.name"
description="%command.cut.description"
categoryId="org.eclipse.ui.category.edit"
id="org.eclipse.ui.edit.cut"
defaultHandler="org.eclipse.ui.internal.handlers.WidgetMethodHandler:cut" />
<command
name="%command.copy.name"
description="%command.copy.description"
categoryId="org.eclipse.ui.category.edit"
id="org.eclipse.ui.edit.copy"
defaultHandler="org.eclipse.ui.internal.handlers.WidgetMethodHandler:copy" />
<command
name="%command.paste.name"
description="%command.paste.description"
categoryId="org.eclipse.ui.category.edit"
id="org.eclipse.ui.edit.paste"
defaultHandler="org.eclipse.ui.internal.handlers.WidgetMethodHandler:paste" />
So they all use org.eclipse.ui.internal.handlers.WidgetMethodHandler as the default handler which is used when no other handler is active.
This handler uses reflection to look for the method name cut, copy or paste in the currently focussed SWT Widget and calls that method if it is found.
For a pure e4 application there is no default definition of cut/copy/paste commands and the WidgetMethodHandler is not available. SWT controls will continue to support cut/copy/paste but there is no other support.
You can put text in the clipboard using something like:
Clipboard clipboard = new Clipboard(Display.getCurrent());
clipboard.setContents(new Object [] {"Text for clipboard"},
new Transfer [] {TextTransfer.getInstance()});
clipboard.dispose()
and get text from the clipboard with:
Clipboard clipboard = new Clipboard(Display.getCurrent());
String text = (String)clipboard.getContents(TextTransfer.getInstance());
clipboard.dispose()
I am using Winium + Java for automation testing of Windows application, and trying to access tool bar menu.
When I tried to detect elements using UI Automation Verify, I couldn't see child elements under tool bar element like below screenshot.
enter image description here
But my tool bar definitely has sub menu items like screenshot and I need to access them.
enter image description here
I tried below java code, but it didn't work
WebElement el = driver.findElement(By.id('59398'));
el.click();
WebElement child = el.findElement(By.name('Start'));
child.click();
when I tried
driver.findElement(By.name"Start').click();
it clicked my windows start menu, not my application's menu.
Is there any way to access items under this tool bar?
You can try use another UI Inspector
eg. UI SPY or Inspector.exe
Probably your ID is not a AutomationID (process id?)
You should find a main window (parent of your app) (Example for calc) and get a parameter like AutomationId, ClassName or Name
I see this is MFC application, and this is an app side MFC library problem. If you hover mouse over toolbar button using Inspect.exe, the info is available but you can't reach this button from the hierarchy (the buttons have no parent somehow). Possible workaround involves combined Win32 API and UI Automation approach:
get button rectangle using Win32 API (but there is no text).
use ElementFromPoint method of UI Automation API and get actual texts to choose the right button.
P.S. My suggestion is applicable for Java + Winium in theory. But I can't estimate the complexity because I'm not a Java expert. So below is Python solution.
We have plans to implemented this mixed way in pywinauto. See issue #413. It contains Python code sample how to do that. We've had no chance to integrate it yet.
from ctypes.wintypes import tagPOINT
import pywinauto
app = pywinauto.Application().start(r'.\apps\MFC_samples\RebarTest.exe')
menu_bar = app.RebarTest.MenuBar.wrapper_object()
point = menu_bar.button(0).rectangle().mid_point()
point = menu_bar.client_to_screen(point)
elem = pywinauto.uia_defines.IUIA().iuia.ElementFromPoint(tagPOINT(point[0], point[1]))
element = pywinauto.uia_element_info.UIAElementInfo(elem)
print(element.name)
I have a working web application developed with GWT. Now that it has to resize on a tablet or smaller screens I thought of using GWT Bootstrap. But the existing application has only one project.html and project.css file under war folder. Currently no UI binders are used. There are four screens displaying different charts created by d3js.
My Question is it still possible to use gwt bootstrap for resizing? Or what about only Bootstrap and use the css file without any UI binders?
Which approach is better ? As im confused and have spent couple of hours searching and reading.
If you plan to interact in your GWT app with bootstrap components (i.e. NavBar, Caoursel, etc) then I would go with gwt-bootstrap because you don't have to use JSNI and you get some type safety.
If you don't need to interact those components or you use mostly pure HTML in your GWT app you can also use plain bootstrap and add the corresponding classes.
Edit code example:
UiBinder:
<b:NavPills>
<b:AnchorListItem active="true">Item 1</b:AnchorListItem>
<b:AnchorListItem>Item 2</b:AnchorListItem>
<b:AnchorListItem>Item 3</b:AnchorListItem>
<b:AnchorListItem enabled="false">Item 4</b:AnchorListItem>
<b:AnchorListItem pull="RIGHT">Pulled right</b:AnchorListItem>
</b:NavPills>
Code:
NavPills pills = new NavPills();
AnchorListItem item1 = new AnchorListItem("Item 1");
item1.setActive(true);
pills.add(item1);
pills.add(new AnchorListItem("Item 2");
pills.add(new AnchorListItem("Item 3");
...
So, I’m currently developing a plugin for the eclipse IDE. In a nutshell, the plugin is a collaborative real time code editor where the editor is eclipse (which is something like Google documents but with the code and on eclipse). Meaning that when I install the plugin, I would be able to connect -using my Gmail account- eclipse to the partner’s eclipse. And when I start coding on my machine, my partner would be seeing what I write and vice versa.
The problem I’m currently facing is accessing eclipse’s editor. For example, I have to monitor all the changes in the active document so that every time a change happens, the other partner’s IDE would be notified with this change.
I found and read about the IDcoumentProvider, IDocument and IEditorInput classes and they’re somehow connected but I can’t understand this connection or how to use it. So if someone can explain this connection I would really appreciate it. Also if there is another way to achieve my goal?
You can access the IEditorPart via the IWorkbenchPage.
IEditorPart editor = ((IWorkbenchPage) PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage()).getActiveEditor();
From there, you have access to various other classes, including the editor's IEditorInput, the File loaded by that editor, or the underlying GUI Control element. (Note that depending on the kind of editor (text files, diagram, etc.) you may have to cast to different classes.)
FileEditorInput input = (FileEditorInput) editor.getEditorInput();
StyledText editorControl = ((StyledText) editor.getAdapter(Control.class));
String path = input.getFile().getRawLocationURI().getRawPath();
Now, you can add a listener to the Control, e.g. a KeyAdapter for monitoring all key strokes occurring in the respective editor.
editorControl.addKeyListener(new KeyAdapter() {
#Override
public void keyPressed(KeyEvent e) {
System.out.println("Editing in file " + path);
}
});
Or, if monitoring all key strokes is too much, you can register an IPropertyListener to the editor. This listener will e.g. be notified whenever the editor gets 'dirty' or when it is saved. The meaning of propId can be found in IWorkbenchPartConstants.
editor.addPropertyListener(new IPropertyListener() {
#Override
public void propertyChanged(Object source, int propId) {
if (propId == IWorkbenchPartConstants.PROP_DIRTY) {
System.out.println("'Dirty' Property Changed");
}
}
});
I want to design new Git client with a clean GUI.
Is it possible to use the power of HTML, CSS and JavaScript in a java application?
I would like to use Java + JGit for models, Java for controllers and HTML + CSS + JavaScript for views.
I don't want a client-server model. I would like to integrate Java and HTML nicely. A DOM event would fire events directly to a Java controller. This way it would be possible to create rich offline application.
You can embed web browser component into your Java Swing/JavaFX Desktop application that displays GUI built with HTML5+CSS+JavaScript. You can see an article that describes how to do this at https://jxbrowser-support.teamdev.com/docs/tutorials/cross-desktop-apps.html
One of the Java Swing/JavaFX libraries that allows embedding Chromium into Java applications is JxBrowser. Using JxBrowser API you can load any web page and work with its DOM and JavaScript. You can even call Java methods from JavaScript code and vice versa. For example:
import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.JSFunctionCallback;
import com.teamdev.jxbrowser.chromium.JSObject;
import com.teamdev.jxbrowser.chromium.JSValue;
import com.teamdev.jxbrowser.chromium.events.FinishLoadingEvent;
import com.teamdev.jxbrowser.chromium.events.LoadAdapter;
public class JavaScriptJavaSample {
public static void main(String[] args) {
Browser browser = new Browser();
browser.addLoadListener(new LoadAdapter() {
#Override
public void onFinishLoadingFrame(FinishLoadingEvent event) {
if (event.isMainFrame()) {
Browser browser = event.getBrowser();
JSObject window = (JSObject)
browser.executeJavaScriptAndReturnValue("window");
window.setProperty("MyFunction", new JSFunctionCallback() {
#Override
public Object invoke(Object... args) {
for (Object arg : args) {
System.out.println("arg = " + arg);
}
return "Hello!";
}
});
JSValue returnValue = browser.executeJavaScriptAndReturnValue(
"MyFunction('Hello JxBrowser!', 1, 2, 3, true);");
System.out.println("return value = " + returnValue);
}
}
});
browser.loadURL("about:blank");
}
}
It's not really feasible. Rich clients in Java are done using Swing or SWT.
If you want to use HTML/CSS for your user interface, you need to use the server/client model. It can be as simple as creating a local server and launching a browser that connects to it, but it would still be that model.
If you absolutely need to have HTML/CSS as your UI framework and can't go to a server/client model, your best bet is probably looking at something like Google Native Client, but that uses C/C++ bindings on the backend. I haven't used Native Client so I can't personally give much more information on that front.
Edit to add:
One option is to embed a native browser into your Swing app using something like: http://djproject.sourceforge.net/ns/
There are some pure Java HTML renderers, however, they most likely won't be fully HTML5/CSS3 compliant, let alone possibly have Javascript bugs as well.
See here for some of those options: Pure Java HTML viewer/renderer for use in a Scrollable pane
Like #Reverand Gonzo says, you will need some form of server/client. But you could easily embed a Jetty server into a Java app and then use GWT for your client code.
You can bring in the power of HTML,CSS,JavaScript into your Swing app using JFXPanel to embed JavaFX WebView. Have a look at the SimpleSwingBrowser demo in this link:https://docs.oracle.com/javase/8/javafx/interoperability-tutorial/swing-fx-interoperability.htm
WebView allows to call JavaScript functions from Java and vice versa. It is also a nice way to enhance your legacy Java app with web technologies.
JavaFX 2.2 brought this functionality to providing a user interface component (GUI) that has web view and full browsing functionality.
For more details, see Adding HTML Content to JavaFX Applications.
Use Angular.js with HTML and rest of the things as same in Java, just use classes for business logic, no need to write code for awt/swing. Angular with spring boot are rapid development in Java for webapp with less code in Java without swing use to create best webapp .