Does Eclipse RCP include a built in cut/copy/paste handler? - java

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()

Related

Winium - how to access tool bar item if that bar doesn't have child

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)

GWT Bootstrap Responsive Design of existing webapp with screens

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");
...

How do I open a new workbench window (with its own WorkbenchWindowAdvisor) from an existing workbench window?

I have a RCP applicaton from which I need to show a GEF Editor in a modal "dialog". But since the editor framework seems to be tightly coupled to the use of a workbench window etc I need to find a why to open a new workbench window (with its own WorkbenchWindowAdvisor etc) so that I can open my GEF editor within this workbench window. Once I get this workbenchWindow opened I will set the style of the WorkbenchWindow's shell to be application modal.
I have done this in a customer project using the following components:
A static class with a method openNewWindow(String type, ...). This is the method you call to open a new window. The type argument specifies the wanted type of window.
The class looks up the specified type via a new extension point to get an ILocalWorkbenchWindowAdvisor and the initial perspective ID.
It then saves the information in global variables and calls IWorkbench.openWorkbenchWindow(perspectiveID, ...)
In ApplicationWorkbenchAdvisor.createWorkbenchWindowAdvisor(...) a new advisor is create based on the saved ILocalWorkbenchWindowAdvisor - the returned advisor basically delegates all the postWindowCreate(...), etc to the same methods in ILocalWorkbenchWindowAdvisor...
If no ILocalWorkbenchWindowAdvisor is saved - which is the case for the very first window to be opened - the type "mainWindow" is looked up and used...
It works pretty well and let all parts of the project add new windows as needed.
Use the command "org.eclipse.ui.window.newWindow" to open a new window. In your WorkbenchWindowAdvisor.preWindowOpen(), set the shell style on the IWorkbenchWindowConfigurer to be application modal. You can also hide the coolbar, menu and status bars, so it looks more like a dialog than a window.

toolbar icons won't update automatically

I'm developing an Eclipse product. I have defined two different perspective, edit and debug. In the toolbar of the debug perspective i placed a set of buttons to guide the debug process flow(e.g. step over, step into, etc..). I used the eclipse command to implement the logic. Below the fragment of pluxin.xml where i declare the toolbar command.
<toolbar
id=".."
label="Debug navigation command">
....
<command
commandId="org.eclipse.debug.ui.commands.Terminate"
disabledIcon="icons/16x16/stop_disabled.ico"
icon="icons/16x16/stop.ico"
label="Terminate"
style="push"
tooltip="Terminate">
<visibleWhen
checkEnabled="false">
<with
variable="activeWorkbenchWindow.activePerspective">
<equals
value="org.xvr.xvrengine.perspective.debug">
</equals>
</with>
</visibleWhen>
</command>
</toolbar>
The problem is that while all the other icons associated to the command org.eclipse.debug.ui.commands.Terminate are updated by eclipse(active only when the process is selected in the debug view), the command i define is not updated. The editor updates the command icon if i change perspective and then switch back to the debug perspective.
How can i update the command icon? is possible to use the default eclipse icon? if i leave the "icon" entry empty the toolbar is filled with the command label.
thanks
There are 2 places where you can control the enabled state of your command.
in org.eclipse.ui.handlers, you can
associate your handler with your
command and provide an enabledWhen
core expression. See
http://wiki.eclipse.org/Command_Core_Expressions
and
http://wiki.eclipse.org/Platform_Expression_Framework
While your handler is active, its
enabled state reflects in the
command. Most handlers subclass
org.eclipse.core.commands.AbstractHandler.
As your handler updates its state
using
org.eclipse.core.commands.AbstractHandler.setBaseEnabled(boolean)
that enabled state will be reflected
in the UI
.
Sorry, but it is not clear for me what you want to achieve. If you would like to create a debugger, I suggest reusing the existing framework for that, see http://eclipse.org/articles/Article-Debugger/how-to.html and http://eclipse.org/articles/Article-Launch-Framework/launch.html
In this case you get automatically the debug frameworks icons, that are updated correspondingly.
Otherwise you might consult http://blog.eclipse-tips.com/2009/02/commands-part-5-authentication-in-rcp.html for ideas of dynamic command handling.
Update: Alternative answer:
You could use fireEvent(new DebugEvent(this, DebugEvent.RESUME, detail)); as described in the end of the following Eclipse Corner article: http://eclipse.org/articles/Article-Debugger/how-to.html
This is described in the part Debug Events. I believe, that is close to what you need.

Resources for data binding with WindowBuilder with SWT/JFace

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.

Categories

Resources