Home » Eclipse Projects » Eclipse 4 » LoginDialog in LifeCycleManager
| |
Re: LoginDialog in LifeCycleManager [message #1097487 is a reply to message #1097339] |
Thu, 29 August 2013 20:03 |
Arjan Huijzer Messages: 9 Registered: October 2011 |
Junior Member |
|
|
Hello Eric,
Thanks for your help!
I tried injecting the MApplication into the LifeCycleManager class:
public class LifeCycleManager {
@Inject
MApplication application;
@PostContextCreate
public void postContextCreate(IEclipseContext context) {
final Shell shell = new Shell(SWT.TOOL | SWT.NO_TRIM);
LoginDialog dialog = new LoginDialog(shell);
if (dialog.open() != Window.OK) {
// close the application
System.exit(-1);
}
}
}
However, this results in an error:
org.eclipse.e4.core.di.InjectionException: Unable to process "LifeCycleManager.application": no actual value was found for the argument "MApplication".
Next, I tried injecting it in my LoginDialog class, but all I get is a null value.
public class LoginDialog extends TitleAreaDialog {
// Widgets
private Text textUsername;
private Text textPassword;
@Inject
MApplication application;
public LoginDialog(Shell parent) {
super(parent);
}
@Override
protected Control createContents(Composite parent) {
Control contents = super.createContents(parent);
setTitle("Credentials");
setMessage("Please provide the credentials.");
return contents;
}
@Override
protected Control createDialogArea(Composite parent) {
Composite area = (Composite) super.createDialogArea(parent);
System.out.println(application);
Composite container = new Composite(area, SWT.NULL);
container.setLayout(new GridLayout(2, false));
container.setLayoutData(new GridData(GridData.FILL_BOTH));
new Label(container, SWT.NULL).setText("Username");
textUsername = new Text(container, SWT.BORDER);
textUsername.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
new Label(container, SWT.NULL).setText("Password");
textPassword = new Text(container, SWT.PASSWORD | SWT.BORDER);
textPassword.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
return area;
}
@Override
protected Point getInitialSize() {
return new Point(500, 300);
}
}
Any idea what I am missing?
Thanks,
Arjan
[Updated on: Thu, 29 August 2013 20:04] Report message to a moderator
|
|
|
Re: LoginDialog in LifeCycleManager [message #1097523 is a reply to message #1097487] |
Thu, 29 August 2013 21:10 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Nothing - the model has not been loaded at this point you need to use
another point in time e.g. @ProcessAddons
Tom
On 29.08.13 22:03, Arjan Huijzer wrote:
> Hello Eric,
>
> Thanks for your help!
>
> I tried injecting the MApplication into the LifeCycleManager class:
>
> public class LifeCycleManager {
>
> @Inject
> MApplication application;
>
> @PostContextCreate
> public void postContextCreate(IEclipseContext context) {
>
> final Shell shell = new Shell(SWT.TOOL | SWT.NO_TRIM);
> LoginDialog dialog = new LoginDialog(shell);
>
> if (dialog.open() != Window.OK) {
> // close the application
> System.exit(-1);
> }
>
> }
>
> }
>
>
> However, this results in an error:
>
> org.eclipse.e4.core.di.InjectionException: Unable to process
> "LifeCycleManager.application": no actual value was found for the
> argument "MApplication".
>
> Next, I tried injecting it in my LoginDialog class, but all I get is a
> null value.
>
> public class LoginDialog extends TitleAreaDialog {
>
> // Widgets
> private Text textUsername;
> private Text textPassword;
>
> @Inject
> MApplication application;
>
> public CredentialsDialog(Shell parent) {
> super(parent);
> }
>
> @Override
> protected Control createContents(Composite parent) {
> Control contents = super.createContents(parent);
> setTitle("Credentials");
> setMessage("Please provide the credentials.");
> return contents;
> }
>
> @Override
> protected Control createDialogArea(Composite parent) {
>
> Composite area = (Composite) super.createDialogArea(parent);
>
> System.out.println(application);
>
> Composite container = new Composite(area, SWT.NULL);
> container.setLayout(new GridLayout(2, false));
> container.setLayoutData(new GridData(GridData.FILL_BOTH));
>
> new Label(container, SWT.NULL).setText("Username");
> textUsername = new Text(container, SWT.BORDER);
> textUsername.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
>
> new Label(container, SWT.NULL).setText("Password");
> textPassword = new Text(container, SWT.PASSWORD | SWT.BORDER);
> textPassword.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
>
> return area;
> }
>
> @Override
> protected Point getInitialSize() {
> return new Point(500, 300);
> }
>
>
> }
>
> Any idea what I am missing?
>
> Thanks,
> Arjan
|
|
|
Re: LoginDialog in LifeCycleManager [message #1097737 is a reply to message #1097523] |
Fri, 30 August 2013 05:22 |
Arjan Huijzer Messages: 9 Registered: October 2011 |
Junior Member |
|
|
Hello Tom,
Thanks for your help. I am one step closer, but I still have not got it working......
I now use @ProcessAdditions in my LIfeCycleManager. Furthermore, I used ContextInjectionFactory to inject the context into the login dialog.
public class LifeCycleManager {
@ProcessAdditions
public void processAdditions(IEclipseContext context) {
final Shell shell = new Shell(SWT.TOOL | SWT.NO_TRIM);
LoginDialog dialog = new LoginDialog(shell);
ContextInjectionFactory.inject(dialog, context);
if (dialog.open() != Window.OK) {
// close the application
System.exit(-1);
}
}
}
In the LoginDialog the state is persisted in the following method:
@Override
protected void okPressed() {
application.getPersistedState().put(CREDENTIALS_USERNAME, textUsername.getText());
super.okPressed();
}
When I run the application, the state seems to be persisted after I close it. My workbench.xmi file has the following entry:
<persistedState key="credentials.username" value="Arjan"/>
However, when I start the application again, the code to read the persisted state in the login dialog does not seem to work:
String persistedUsername = application.getPersistedState().get(CREDENTIALS_USERNAME);
persistedUsername is NULL
Note: I did remove the clearPersistedState property from the plugin.xml.
Thanks,
Arjan
|
|
|
Re: LoginDialog in LifeCycleManager [message #1098167 is a reply to message #1097737] |
Fri, 30 August 2013 18:18 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Most likely you launch with -clearPersistedState
Tom
On 30.08.13 07:22, Arjan Huijzer wrote:
> Hello Tom,
>
> Thanks for your help. I am one step closer, but I still have not got it
> working......
>
> I now use @ProcessAdditions in my LIfeCycleManager. Furthermore, I used
> ContextInjectionFactory to inject the context into the login dialog.
>
> public class LifeCycleManager {
>
> @ProcessAdditions
> public void processAdditions(IEclipseContext context) {
>
> final Shell shell = new Shell(SWT.TOOL | SWT.NO_TRIM);
> LoginDialog dialog = new LoginDialog(shell);
> ContextInjectionFactory.inject(dialog, context);
>
> if (dialog.open() != Window.OK) {
> // close the application
> System.exit(-1);
> }
>
> }
>
> }
>
> In the LoginDialog the state is persisted in the following method:
>
> @Override
> protected void okPressed() {
> application.getPersistedState().put(CREDENTIALS_USERNAME,
> textUsername.getText());
> super.okPressed();
> }
>
>
> When I run the application, the state seems to be persisted after I
> close it. My workbench.xmi file has the following entry:
>
> <persistedState key="credentials.username" value="Arjan"/>
>
> However, when I start the application again, the code to read the
> persisted state in the login dialog does not seem to work:
>
> String persistedUsername =
> application.getPersistedState().get(CREDENTIALS_USERNAME);
>
> persistedUsername is NULL :(
>
> Note: I did remove the clearPersistedState property from the plugin.xml.
>
>
> Thanks,
> Arjan
>
>
|
|
| |
Re: LoginDialog in LifeCycleManager [message #1706133 is a reply to message #1098239] |
Mon, 24 August 2015 05:12 |
|
But friend I am try to check login validation and false time focus login screen and correct to open application, how and where i'm apply code and i am post my code also....
Login Dialog
import javax.inject.Inject;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class LoginDialog extends TitleAreaDialog {
// Widgets
public static Text textUsername;
public static Text textPassword;
@Inject
MApplication application;
// @Inject
// EMenuService menuService;
/**
* @wbp.parser.constructor
*/
public LoginDialog() {
super(null);
}
@Inject
public LoginDialog(Shell parentShell) {
super(parentShell);
}
@Override
protected Control createContents(Composite parent) {
Control contents = super.createContents(parent);
setTitle("Login");
setMessage("Please provide credentials");
return contents;
}
@Override
protected Control createDialogArea(Composite parent) {
Composite area = (Composite) super.createDialogArea(parent);
Composite container = new Composite(area, SWT.NULL);
container.setLayout(new GridLayout(2, false));
container.setLayoutData(new GridData(GridData.FILL_BOTH));
new Label(container, SWT.NULL).setText("Username");
textUsername = new Text(container, SWT.BORDER);
textUsername.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
new Label(container, SWT.NULL).setText("Password");
textPassword = new Text(container, SWT.PASSWORD | SWT.BORDER);
textPassword.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
checkLoginValidation(textUsername.getText(),textPassword.getText());
return area;
}
private void checkLoginValidation(String text, String text2) {
}
@Override
protected Point getInitialSize() {
return new Point(500, 300);
}
}
Lifecycle manager class
package secdemo;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.di.UIEventTopic;
import org.eclipse.e4.ui.workbench.UIEvents;
import org.eclipse.e4.ui.workbench.lifecycle.PostContextCreate;
import org.eclipse.e4.ui.workbench.lifecycle.PreSave;
import org.eclipse.e4.ui.workbench.lifecycle.ProcessAdditions;
import org.eclipse.e4.ui.workbench.lifecycle.ProcessRemovals;
import org.eclipse.equinox.app.IApplicationContext;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.Shell;
import javax.inject.Inject;
import org.eclipse.e4.core.di.annotations.Optional;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;
import login.LoginDialog;
@SuppressWarnings("restriction")
public class Manager {
@PostContextCreate
void postContextCreate(IEclipseContext workbenchContext) {
}
@PreSave
void preSave(IEclipseContext workbenchContext) {
}
@ProcessAdditions
void processAdditions(final IEclipseContext workbenchContext, IEventBroker eventBroker) {
LoginDialog dialog = ContextInjectionFactory.make(LoginDialog.class, workbenchContext);
if(dialog.open() != Window.OK){
// close application
System.exit(-1);
}
eventBroker.subscribe(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE, new EventHandler() {
// @Override
public void handleEvent(Event event) {
// if(LoginDialog.textUsername.getText().equals("123") && LoginDialog.textPassword.getText().equals("123") ){
appStartupComplete(workbenchContext);
// }
}
});
// continue to the initial window
}
@ProcessRemovals
void processRemovals(IEclipseContext workbenchContext) {
}
@Optional
public void applicationStartupComplete(@UIEventTopic(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE) Event event)
{
}
private void appStartupComplete(IEclipseContext workbenchContext) {
}
@PostContextCreate
void postContextCreate(IApplicationContext appContext, Display display) {
final Shell shell = new Shell(SWT.LEFT);
LoginDialog dialog = new LoginDialog(shell);
// close the static splash screen
appContext.applicationRunning();
// position the shell
setLocation(display, shell);
if (dialog.open() != Window.OK) {
// close the application
System.exit(-1);
}
}
private void setLocation(Display display, Shell shell) {
Monitor monitor = display.getPrimaryMonitor();
Rectangle monitorRect = monitor.getBounds();
Rectangle shellRect = shell.getBounds();
int x = monitorRect.x + (monitorRect.width - shellRect.width) / 2;
int y = monitorRect.y + (monitorRect.height - shellRect.height) / 2;
shell.setLocation(x, y);
}
}
apply plugin.xml file in lifecycleURI....
Pleas help me friend .....
Lalit
|
|
|
Goto Forum:
Current Time: Thu Apr 25 22:13:48 GMT 2024
Powered by FUDForum. Page generated in 0.03597 seconds
|