Implement postWindowClose() in RCP application - java

Hi RCP developers,
I want to iplement postWindowClose() in my ECLIPSE RCP application.
Before coding this method, I just did a small test to see if when I close my application, the method is called, so I did that :
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
public class MainWindowControl extends WorkbenchWindowAdvisor{
public MainWindowControl(IWorkbenchWindowConfigurer configurer) {
super(configurer);
// TODO Auto-generated constructor stub
}
#Override
public void postWindowClose() {
// TODO Auto-generated method stub
super.postWindowClose();
System.out.println("close");
}
}
I am expecting to see : close in ECLIPSE console, but it's still blank after closing the application.
All the required plugins are added , and I have no error while launching or closing the application.
So, AM I missing something ?
The reasons why to implemets this method are :
Msg box : Are you sure you want to close the application
Kill all the running threads, my application upload files and even when I close the application running uploads continues. I want to abort them when closing the application.
Edit :
My life cycle class :
package upload.center.util;
import org.eclipse.e4.ui.workbench.lifecycle.PostContextCreate;
import org.eclipse.e4.ui.workbench.lifecycle.PreSave;
public class WindowLifeCycle {
#PostContextCreate
public void postContextCreate()
{
// TODO start up code here
System.out.println("open");
}
#PreSave
public void preSave()
{
// TODO add shutdown code here
System.out.println("close");
}
}
My plugin.xml :
<product ....
<property
name="windowLifeCycle"
value="bundleclass://UploadCenter.Source/upload.center.util.WindowLifeCycle">
</property>
...</product>
I hope that I am clear enough.
Ismail

For a pure Eclipse 4 (e4) application the workbench window advisor (and the other advisors) are not used. You use the #PreSave method of a life cycle class to run code during shutdown.
public class LifeCycle
{
#PostContextCreate
public void postContextCreate()
{
// TODO start up code here
}
#PreSave
public void preSave()
{
// TODO add shutdown code here
}
}
declare the life cycle class in the product definition in the plugin.xml:
<extension
id="product"
point="org.eclipse.core.runtime.products">
<product
name="%product.name"
application="org.eclipse.e4.ui.workbench.swt.E4Application">
<property
name="lifeCycleURI"
value="bundleclass://plugin-id/package.LifeCycle">
</property>
.... more properties ...
For more details see here

Related

unable to run feature file in IntelliJ - Undefined scenarios

I tried to run feature file by right click - run at IntelliJ editor but terminal displayed follows:
this is the configuration by default. is this correct?
please help as I am not sure what should be setup manually over here..
this is partial log copied from terminal:
Undefined scenarios:
C:/Users/tester/Dropbox/My PC (LAPTOP-1UVHO2K0)/Downloads/bdd-test-automation-workshop-master2/bdd-test-automation-workshop-master/src/test/resources/features/creating_todos/adding_new_todos.feature:9 # User should be assisted when adding todo items for the first time
C:/Users/tester/Dropbox/My PC (LAPTOP-1UVHO2K0)/Downloads/bdd-test-automation-workshop-master2/bdd-test-automation-workshop-master/src/test/resources/features/creating_todos/adding_new_todos.feature:13 # Adding a single todo item
C:/Users/tester/Dropbox/My PC (LAPTOP-1UVHO2K0)/Downloads/bdd-test-automation-workshop-master2/bdd-test-automation-workshop-master/src/test/resources/features/creating_todos/adding_new_todos.feature:20 # Adding todo items to an existing list
3 Scenarios (3 undefined)
10 Steps (10 undefined)
0m1.042s
You can implement missing steps with the snippets below:
#Given("{actor}")
public void (Actor actor) {
// Write code here that turns the phrase above into concrete actions
throw new cucumber.api.PendingException();
}
#Then("{actor}")
public void (Actor actor) {
// Write code here that turns the phrase above into concrete actions
throw new cucumber.api.PendingException();
}
#When("{actor}")
public void (Actor actor) {
}
#Then("{actor}")
public void (Actor actor, io.cucumber.datatable.DataTable dataTable) {
}
#Given("{actor}")
public void (Actor actor, io.cucumber.datatable.DataTable dataTable) {
}
Process finished with exit code 0
I added glue then it works now.
todos.stepdefinitions net.serenitybdd.cucumber.actors

Eclipse formatter automatically inserts two blank lines after package declaration

Am using Eclipse Neon 3 and was making my usual edits to the formatter when I noticed that everytime I create a new class, it creates two new (or blank) lines between the package declaration and the actual class itself!
package com.myapp;
public class MyClass {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
How to setup the Eclipse formatter to only include one blank line (initially), especially if there's no import declarations used yet, like this:
package com.myapp;
public class MyClass {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
Been trying to fix this myself and would appreciate if someone could point me in the right direction.
Review the code template that was set up in Eclipse by opening up Window > Preferences > Java > Code Style > Code Templates and configure the generated code for New Java Files under the Code header.
The default template given provided was
${filecomment}
${package_declaration}
${typecomment}
${type_declaration}
and the generated code as follows
package com.personal.test.com.personal.test;
public class AppTest {
}
If the template was modified to this, note the extra blank lines.
${filecomment}
${package_declaration}
${typecomment}
${type_declaration}
The following is generated
package com.personal.test.com.personal.test;
public class AppTestWithSpaces {
}

Liferay, how to get root logger?

I'm trying to develop portlet which sends email to administrators when a set of specified excpetions occured in a given time period. I'm trying to get root logger in liferay so i can add my appender to it and process all messages going trough the logging mechanism.
I looked into source code and seems that liferay uses java.util.logging.LogManager. I made a hook which is fired when server starts up. Here is my run() method:
public void run(String[] ids) throws ActionException {
System.out.println("initializing");
LogListener listener = new LogListener();
listener.setLevel(Level.ALL);
listener.setFilter(null);
Logger.getGlobal().addHandler(listener);
_log.debug("complete");
}
And LogListener class
package pl.com.mds.portlet.mailing.hook;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
public class LogListener extends Handler {
#Override
public void publish(LogRecord record) {
System.out.println("publishing******");
}
#Override
public void flush() {
// TODO Auto-generated method stub
System.out.println("have to flush! *****");
}
#Override
public void close() throws SecurityException {
// TODO Auto-generated method stub
System.out.println("close meee!");
}
}
But when some exception is thrown i cant see in console publishing****** only exception stacktrace. How can i get all logs in application and expceptions?
Thanks :)
Root logger can be obtained through standard procedure Logger.getLogger("logger name goes here"). Root logger has an empty string as its name. So you should edit your code as follows:
Logger.getLogger("").addHandler(listener);
Consider using LogFactoryUtil. Like following
private static final Log LOG = LogFactoryUtil.getLog(MyPortlet.class);

Eclipse and GWT desing mode

I am Working with GWT and eclipse. I am facing a problem . The design mode of eclipse is not working. I am using the eclipse 3.7 . Where is the problem?
One way to see design view is extending the view part. you can try this one.
public class test extends ViewPart {
public test() {
// TODO Auto-generated constructor stub
}
#Override
public void createPartControl(Composite parent) {
// TODO Auto-generated method stub
}
#Override
public void setFocus() {
}
}
You need to right click the file you want to open, then click open with --> GWT Designer.
Make sure your resource exclusion filters are not too strict.
If you are using Maven, the issue is explained here.

GWT: execution stops when adding a Composite widget to RootPanel

I have an abstract class extending Composite (AbstractWhiteBoard). Then I have a concrete class extending AbstractWhiteBoard. When I instantiate the concrete class and try to add it to the RootPanel, the program simply stops executing. There is no error or any output to direct me to a log file. I have no idea what is going wrong.
Here is my abstract class:
public abstract class AbstractWhiteBoard extends Composite {
/*
* FIELDS
*/
protected HorizontalPanel WhiteBoardWrapperPanel;
public AbstractWhiteBoard( ) {
WhiteBoardWrapperPanel = new HorizontalPanel();
WhiteBoardWrapperPanel.setStyleName("WhiteBoard-Wrapper");
initWidget(WhiteBoardWrapperPanel);
}
/*
* ABSTRACT PUBLIC METHODS
*/
abstract public void addNotecard( Notecard nc );
abstract public void addPostit( Postit postit );
/*
* ABSTRACT PROTECTED HELPER METHODS
*/
abstract protected void registerDragDropControllers();
}
And here is my concrete implementation class:
public class ConcreteWhiteBoard extends AbstractWhiteBoard {
/*
* CONTSTRUCTORS
*/
public ConcreteWhiteBoard() {
super();
}
/*
* PUBLIC METHOD OVERRIDES
*/
#Override
public void addNotecard(Notecard nc) {
// TODO Auto-generated method stub
}
#Override
public void addPostit(Postit postit) {
// TODO Auto-generated method stub
}
/*
* PRIVATE HELPER METHOD OVERRIDES
*/
#Override
protected void registerDragDropControllers() {
// TODO Auto-generated method stub
}
}
So, what is happening, is I have this code:
AbstractWhiteBoard wb = new ConcreteWhiteBoard();
RootPanel.get().add(wb);
Window.alert("wb added!");
But after I add wb to the RootPanel, execution stops. The alert statement never even gets called. There is no error and I don't see anything in the log.
Is there something wrong with having an abstract class that extends Composite? Or is it something entirely different that I am just not seeing? any help is greatly appreciated!
take a look at the uncaught exception handler in gwt. if a runtime exception occurs it is called. Think of it as a global try catch around your code.
But if your code is inside your entrypoint on module load make sure to set the uncaught exception handler and call the next function within a timer (so that the uncaught exception handler is active.
For a quick example take a look here:
http://code.google.com/p/mgwt/source/browse/src/main/java/com/googlecode/mgwt/examples/showcase/client/ShowCaseEntryPoint.java?repo=showcase
In web mode you can turn on emulated stack (and get meaningful stacktraces). YOu need to add this to your gwt.xml file (only for debug purposes because it is quite slow):
<set-property name="compiler.emulatedStack" value="true" />
<set-configuration-property name="compiler.emulatedStack.recordLineNumbers" value="true" />
<set-configuration-property name="compiler.emulatedStack.recordFileNames" value="true" />
So, this is one of those times that you feel like the most retarded developers of all time. What happened is that I was running several async calls all at the same time and I tried to refer to an object that was returned by one of those calls before it was actually created. Dunce cap on me, I got confused with async threads.
Major thanks to Daniel. Your input lead me straight to the problem!

Categories