Open Editor at Start in an EclipseRCP application - java

I'm currently programming on an eclipse RCP application in Java for an university project.
My problem is that I want an editor loaded at application start, but I don't know which method is the right one to start with. In the perspective I can only add views and set my editor space, but I can't set any editors.
I tried overwrite the WorkbenchWindowAdvisor.postWindowOpen() method, but this only got me an exception...

You say you got an exception.. what was it? How did you overwrite postWindowOpen(), can you post your code? I could help you more if I knew these things.
Anyway, the following code opens the editor at application startup:
#Override
public void postWindowOpen() {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
try {
page.openEditor(editorInput, editorId);
} catch (PartInitException e) {
// Handle the exception here
}
}
where "editorInput" is the input of your editor and "editorId" it's ID.
Also, I highly recommend reading Lars Vogel's tutorial on editors:
http://www.vogella.de/articles/EclipseEditors/article.html

Related

How to delete IMarkers after editor closed ( or why isnt the IMarker.TRANSIENT property working)?

I'm writing a custom editor in Eclipse and just integrated custom error recognition. Now I'm facing a strange issue: I can add Markers to my editor that get displayed all fine, I can also delete them while the editor is running.
What doesn't work: When I close my editor I want the markers to disappear/get deleted.
What I'm doing right now, is
creating the Markers with the transient property set like this: marker.setAttribute(IMarker.TRANSIENT, true); This doesn't seem to change anything though.
trying to delete all Annotations via the source viewers annotation-model. This doesn't work, cause when I try to hook into my editors dispose() method or add a DisposeListener to my sourceviewers textwidget, the sourceviewer already has been disposed of and getSourceViewer().getAnnotationModel(); returns null.
My deleteMarkers method:
private void deleteMarkers() {
IAnnotationModel anmod = getSourceViewer().getAnnotationModel();
Iterator<Annotation> it = anmod.getAnnotationIterator();
while (it.hasNext()) {
SimpleMarkerAnnotation a = (SimpleMarkerAnnotation) it.next();
anmod.removeAnnotation(a);
try {
a.getMarker().delete();
} catch (CoreException e) {
e.printStackTrace();
}
}
}
Any help is appreciated ^^
Hook into your editor close event, get a reference to the IResource for the editor (i believe you get can that on IEditorInput) and call IResource#deleteMarkers() on the relevant resource which will delete them when you close your editor. By design eclipse does not delete markers when editors are closed.
Here is some reference:
http://help.eclipse.org/kepler/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/core/resources/IResource.html#deleteMarkers(java.lang.String, boolean, int)

UISpec4J and external application

I am trying to launch an external application for testing using UISpec4J.
Here are the questions and their answers I referred so far:
How to automate a swing java web start application which runs clicking a link into a web application, which is automated with Selenium WebDriver?
Getting all windows using UISpec4J
UISpec4J Capturing modal dialog, before the trigger finish
my.exe referred below is a Java application wrapped in exe using some tool. Internally it uses the jars and is Java GUI application.
This executable launches a splash screen first, then a dialog to choose where you want to connect to and after that main window is shown. Unless I can automate where I can connect to I won't get main window.
Based on these questions I have come up with following code fragments:
this.setAdapter(new UISpecAdapter() {
#Override
public Window getMainWindow() {
return WindowInterceptor.run(new Trigger() {
#Override
public void run() throws Exception {
// running jnlp by netx launcher
Runtime.getRuntime().exec("C:\\my.exe");
Thread.sleep(10000);
}
});
}
});
In the approach above I simple get "No window was shown" error.
this.setAdapter(new UISpecAdapter() {
#Override
public Window getMainWindow() {
final Window[] result = new Window[1];
WindowInterceptor
.init(new Trigger() {
#Override
public void run() throws Exception {
Runtime.getRuntime().exec("C:\\my.exe");
//Thread.sleep(10000);
}
})
//.processTransientWindow()
.process(new WindowHandler() {
public Trigger process(Window window) throws Exception {
result[0] = window;
return Trigger.DO_NOTHING;
}
})
.run();
return result[0];
}
});
In the second approach above, I still get "No window shown" error AND control never reaches to overriden "process" method.
I referred to http://www.uispec4j.org/reports/apidocs/org/uispec4j/interception/WindowInterceptor.html and recommended approach is to use init to capture modal dialog is init\process sequence.
To capture non-modal it is recommended that we should use following:
Window window = WindowInterceptor.run(panel.getButton("open").triggerClick());
But I have NO idea where and how I am supposed to call it..
From the first question I referred, mentioned above, we should be able to do that because the answer to it mentions launching jnlp application which is external application.
I tried with jre 6 update 0 and I can at least run test. In java update 37, from the third question I referred above, I get abstract method not implemented error.
What am I doing wrong? Any idea?
I am using latest UISpec4J package - version 2.4.
Thanks in advance,
-Neel.
I'm very new to UISpec4J but I'm guessing it needs to run in the same JVM in order to intercept and interact with the GUI components. When you start the exe file with exec, it will create a new process and a new, separate JVM. That'll not work, if I understand UISpec4J correctly.
Regarding the non-modal example, the documentation says "You would retrieve the window from within the test...", so in a setup method or in a test should work.

Custom message when closing a part in Eclipse RCP 4

we have the following problem:
In our Eclipse RCP 4 application there are multiple parts and the parts are closable. When the user is closing a part there should be a custom pop-up (depending on some internal part state) which is asking the user if he really wants to close the part or not.
It seems to be not that easy to implement in Eclipse RCP 4 or we have just totally overseen something.
I'll just give you a short brieifing about the things we tried:
Use dirtable with a #persist method in the part. Though the problem is, we don't want this standard eclipse save dialog. So is there a way to override this?
public int promptToSaveOnClose(): This seemed to be promising but not for Eclipse 4 or is there a way to integrate it that way? Compare: http://e-rcp.blogspot.de/2007/09/prevent-that-rcp-editor-is-closed.html
Our last try was to integrate a custom part listener, simple example shown in the following:
partService.addPartListener(new IPartListener() {
public void partVisible(MPart part) {
}
public void partHidden(MPart part) {
partService.showPart(part, PartState.ACTIVATE);
}
public void partDeactivated(MPart part) {
}
public void partBroughtToTop(MPart part) {
}
public void partActivated(MPart part) {
}
});
The problem with this was we are running into a continuous loop. Something similar is posted over here in the last comment: Detect tab close in Eclipse editor
So I could write some more about this problem, but I think that's enough for the moment. If you need some more input just give me a hint.
Thanks for helping.
The save prompt is generated by the ISaveHandler registered in the context of the MWindow containing the MPart. You can write your own ISaveHandler and set it in the window context to replace the default.
You might also want to look at the IWindowCloseHandler also in the window context.
Thanks greg, this has helped and I was able to achieve changing the pop-up when the user closes a part. Here's a short description of what I've done:
Use the MDirtyable for marking the part as dirty whenever it's needed.
Create a custom save handler which implements ISaveHandler (when a part got closed the save method is called). Add the additional logic to this handler (e.g. a custom message dialog)
Register this handler at application start-up (I just chose a method which is called at the start-up):
#Inject
private MWindow window;
...
ISaveHandler saveHandler = new CustomSaveHandler(shell);
window.getContext().set(ISaveHandler.class, saveHandler);
Note that the registration via a model processor was sadly not that easy because the model processor is called too early. (Take a look at: http://www.eclipse.org/forums/index.php/t/369989/)
The IWindowCloseHandler is just needed when the complete window is closed, though this was not an requirement for us :).

Open and maximise a browser window in OATS Java (not javascript)

I am a tester and just installed oracle application test suite to use testing eBus apps
Anyway the only language it supports for coding test scripts (I don't want to use the recorder for a number of reasons). The problem I am having is that everything I search or google is javascript not java (even googling with -script I still ended up looking at javascript. This just gets rejected by the oats editor
The only other examples I have seen, appear to be defining a variable then setting the value of that variable as the window they want to maximize. Aside from the fact that my java skills are not up to doing that - I do not need to do this for a newly opened browser window do I? (The assumption is that this will be the only browser window open (ie test is executed with browser closed)
Is there any easy way to do this?
Below is the very simple initiate of the browser which is generated from a recording plus part of the first step which loads the url the test starts at: (I realize the first step is not complete below -I didn't paste it all, just enough to hopefully allow someone to show me what I need to edit to force the browser to load maximized, or maximize it immediately after loading?
public void initialize() throws Exception {
browser.launch();
}
/**
* Add code to be executed each iteration for this virtual user.
*/
public void run() throws Exception {
beginStep("[1] Login (/RF.jsp)", 0);
{
web
.window(2,
"/web:window[#index='0' or #title='about:blank']")
.navigate(
"http://somepageiwantolaunch");
web.window(4, "/web:window[#index='0' or #title='Login']")
.waitForPage(null);
I am not sure whether you already got the answer for this.. if not this code should help you
browser.launch();
DOMBrowser currentExecutionBrowser = web.window("/web:window[#index='0' or #index='1']");
currentExecutionBrowser.maximize();
Let me know if this helps!
There is a function in the Oracle Functional Tester API Reference which has a build in function called object.WindowState It says you can get or set using this function and it has values
0 - Normal, 1- minimized and 2-maximised.
Only issue is that these examples look more like VB than Javascript but presumably there is a similar function built into to the Oracle libraries for Java.
I did a quick search for Oracle Openscript API and came up with this link which asks for the same thing. They suggest using Help->Search from within the openscript application and then searching for "openscript API" which should provide a list of the functions available.
Hope that helps.
To Maximize browser in OATS, follow the below code
Open script ha in built methods which helps coding easy
browser.launch();
web.window(12, "/web:window[#index='0' or #title='about:blank']").navigate("http://www.google.com/");
web.window(12, "/web:window[#index='0' or #title='about:blank']").maximize();
for more OATS Tips/Tricks follow here
http://www.testinghive.com/category/oracle-application-testing-suite-tips
If it is the only browser window open, you can use the below code. It must be used with caution since the code maximizes any window that is open above the browser window.
try {
Robot a = new Robot();
a.keyPress(KeyEvent.VK_ALT);
a.keyPress(KeyEvent.VK_SPACE);
a.keyRelease(KeyEvent.VK_SPACE);
a.keyRelease(KeyEvent.VK_ALT);
a.keyPress(KeyEvent.VK_X);
a.keyRelease(KeyEvent.VK_X);
} catch (AWTException e) {
}

Why aren't my Resources being refreshed in my Eclipse plugin?

I have a custom Eclipse plugin I am working on. It has a CustomerExplorer View(Part) that effectively replaces the 'Project Explorer' and it has a number of MultiPageEditorParts, each has a XML editor and a Form editor, both modifying the same configuration file. The XML editor is a TextEditor. The form and the XML are linked and each updates the other whenever there is a pageChange().
My problem lies in the external modification of files opened in my Eclipse plugin. If I edit a file in an external editor and then load it (from CustomerExplorer View), upon switching to the XML tab I will recieve the message:
"Resource is out of sync with the file system: '/example/example.xml'.
Press 'F5' or select File > Refresh to refresh the file.
I am familiar with this error from using Eclipse and usually simply pushing F5, right clicking the file in question and choosing refresh or choosing File > Refresh from the menu bar usually solves it. However, in this case F5 does nothing, File > Refresh is greyed out and right clicking on the file (in my custom view), the context menu does not contain 'refresh'. I have tried opening the 'Project Explorer' view, where 'Refresh' is available in the context menu, but this does nothing.
From reading around I have been led to understand that these resources should be refreshed by eclipse but they are not. Any pointers as to why?
Hard to say exactly what is happening here, but you may need to explicitly add the action set for refreshing resources to your custom view.
Another way of solving your issue might be to track change to the file an update your view when there is one:
ResourcesPlugin.getWorkspace().addResourceChangeListener(new MyResourceTracker(), IResourceChangeEvent.POST_CHANGE);
With something like that:
public class MyResourceTrackerimplements IResourceChangeListener {
#Override
public void resourceChanged(final IResourceChangeEvent ev) {
if (ev.getDelta() != null) {
try {
ev.getDelta().accept(new IResourceDeltaVisitor() {
#Override
public boolean visit(final IResourceDelta delta)
throws CoreException {
// TODO do something
return true;
}
});
} catch (CoreException e) {
// TODO
}
}
}
}

Categories