Splash ekranı gösterecek şekilde ayarlanmış bir Eclipse RCP uygulamamız varsa, önce plugin.xml dosyasına aşağıdaki extension eklemesini yapmakla işe başlayabiliriz. Eclipse uygulamamızda Product ID, "x.y.z.product" olarak tanımlanmıştır.
<extension point="org.eclipse.ui.splashHandlers">
<splashHandler
class="x.y.z.SplashHandler"
id="x.y.z.splashHandler">
</splashHandler>
<splashHandlerProductBinding
productId="x.y.z.product"
splashId="x.y.z.splashHandler">
</splashHandlerProductBinding>
</extension>
Şimdi bu extension tanımı ile eklenmek istenen fonksiyonalite aşağıdaki sınıf içinde gerçekleştirilir.package x.y.z;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.splash.AbstractSplashHandler;
public class SplashHandler extends AbstractSplashHandler {
private boolean authenticated = false;
@Override
public void init(final Shell splash) {
super.init(splash);
splash.setLayout(new FillLayout());
splash.setBackgroundMode(SWT.INHERIT_DEFAULT);
Composite composite = new Composite(splash, SWT.BORDER);
composite.setLayout(new GridLayout(2, false));
Label lblUserName = new Label(composite, SWT.NONE);
lblUserName.setText("&User Name :");
final Text txtUserName = new Text(composite, SWT.BORDER);
Label lblPassword = new Label(composite, SWT.NONE);
lblPassword.setText("&Password :");
final Text txtPassword = new Text(composite, SWT.BORDER);
Button btnOK = new Button(composite, SWT.PUSH);
btnOK.setText("OK");
btnOK.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
String userName = txtUserName.getText();
String password = txtPassword.getText();
if (userName.length() > 0 && password.length() > 0) {
if (userName.equals("user1") && password.equals("secret")) {
authenticated = true;
}
} else {
MessageDialog.openError(splash, "Authentication Failed", "Username and password must be specified.");
}
}
});
Button btnCancel = new Button(composite, SWT.PUSH);
btnCancel.setText("Cancel");
btnCancel.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
splash.getDisplay().close();
System.exit(0);
}
});
splash.layout(true);
while (authenticated == false) {
if (splash.getDisplay().readAndDispatch() == false) {
splash.getDisplay().sleep();
}
}
}
}
Burada işleyişin bir bütün halinde anlaşılması amacıyla oldukça sadeleştirilmiş bir kod örneği sunulmuştur. Daha kullanışlı bir login uygulaması için aşağıdaki bağlantıya göz atılabilir:http://tomsondev.bestsolution.at/2007/06/12/splash-screen-and-threads/

Hiç yorum yok:
Yorum Gönder