我创建了一个带有交互式启动画面的 RCP 应用程序,用于登录我的系统。我在 Mac 上构建它,应用程序运行完美,但是当我为 Windows 创建新的产品配置并运行应用程序时,它启动时没有启动,控制台中也没有出现错误。
splash handler代码如下
/**
* The splash screen controller for the RCP application. This has been modified to also act as a login screen for the
* application. Failure to correctly authenticate results in the application termination.
*/
package com.myproject.plugins.core.splashHandlers;
import java.net.MalformedURLException;
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.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
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;
/**
* The splash handler overrides the default RCP splash handler.
* @since 3.3
*/
public class InteractiveSplashHandler extends AbstractSplashHandler {
/**
* Composite container for login form.
*/
private Composite loginComposite;
/**
* Text box input for login username.
*/
private Text usernameTextBox;
/**
* Text box input for login password.
*/
private Text passwordTextBox;
/**
* OK button for submission of the login form.
*/
private Button okButton;
/**
* Cancel button for cancelling the login attempt and exiting the application.
*/
private Button cancelButton;
/**
* Simple boolean flag to store login success/status.
*/
private boolean isAuthenticated;
/**
* SWT form label for username.
*/
private Label usernameLabel;
/**
* SWT form label for password.
*/
private Label passwordLabel;
/**
* Form/layout data for username label.
*/
private FormData usernameLabelFormData;
/**
* Form/layout data for password label.
*/
private FormData passwordLabelFormData;
/**
* Form/layout data for username text box.
*/
private FormData usernameTextBoxFormData;
/**
* Form/layout data for password text box.
*/
private FormData passwordTextBoxFormData;
/**
* Form/layout data for OK button.
*/
private FormData okButtonFormData;
/**
* Constructor for the splash handler.
*/
public InteractiveSplashHandler() {
passwordTextBox = null;
cancelButton = null;
isAuthenticated = false;
}
/**
* Initialiser for the splash screen.
* @see org.eclipse.ui.splash.AbstractSplashHandler#init(org.eclipse.swt.widgets.Shell)
*/
public void init(final Shell splash) {
/**
* Initialising the parent SplashHandler with the splash shell.
*/
super.init(splash);
/**
* Configure the shell UI layout.
*/
configureUISplash();
/**
* Create UI components.
*/
createUI();
/**
* Create UI listeners.
*/
createUIListeners();
/**
* Force the splash screen to layout.
*/
splash.layout(true);
/**
* Keep the splash screen visible and prevent the RCP application from loading until the close button is
* clicked.
*/
doEventLoop();
}
/**
* Create the event loop for the splash to prevent the application load from completion, and hold it at the splash
* until the login event is successful.
*/
private void doEventLoop() {
Shell splash = getSplash();
while (isAuthenticated == false) {
if (splash.getDisplay().readAndDispatch() == false) {
splash.getDisplay().sleep();
}
}
}
/**
* Create the UI listeners for all the form components.
*/
private void createUIListeners() {
/**
* Create the OK button listeners.
*/
createUIListenersButtonOK();
/**
* Create the cancel button listeners.
*/
createUIListenersButtonCancel();
}
/**
* Listeners setup for the cancel button.
*/
private void createUIListenersButtonCancel() {
cancelButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
handleButtonCancelWidgetSelected();
}
});
}
/**
* Handles the cancel action by shutting down the RCP application.
*/
private void handleButtonCancelWidgetSelected() {
/**
* Abort the loading of the RCP application.
*/
getSplash().getDisplay().close();
System.exit(0);
}
/**
* Listeners setup for the OK button.
*/
private void createUIListenersButtonOK() {
okButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
handleButtonOKWidgetSelected();
}
});
}
/**
* Handles the OK button being pressed and the login attempted.
*/
private void handleButtonOKWidgetSelected() {
String username = usernameTextBox.getText();
String password = passwordTextBox.getText();
AuthenticationClient client = new AuthenticationClient();
if (username.equals("") || password.equals("")) {
MessageDialog.openError(getSplash(),
"Authentication Failed", //$NON-NLS-1$
"A username and password must be specified to login."); //$NON-NLS-1$
} else {
try {
if (client.authenticate(username, password)) {
isAuthenticated = true;
} else {
MessageDialog.openError(getSplash(),
"Authentication Failed", //$NON-NLS-1$
"The details you entered could not be verified."); //$NON-NLS-1$
}
} catch (MalformedURLException e) {
MessageDialog.openError(getSplash(),
"Authentication Failed", //$NON-NLS-1$
"Service responded with an error."); //$NON-NLS-1$
}
}
}
/**
* Calls the individual UI component creation functions.
*/
private void createUI() {
/**
* Create the login panel.
*/
createUICompositeLogin();
/**
* Create the user name label.
*/
createUILabelUserName();
/**
* Create the user name text widget.
*/
createUITextUserName();
/**
* Create the password label.
*/
createUILabelPassword();
/**
* Create the password text widget.
*/
createUITextPassword();
/**
* Create the OK button.
*/
createUIButtonOK();
/**
* Create the cancel button.
*/
createUIButtonCancel();
}
/**
* Creates the SWT component for the cancel button.
*/
private void createUIButtonCancel() {
/**
* Create the button.
*/
cancelButton = new Button(loginComposite, SWT.PUSH);
okButtonFormData.right = new FormAttachment(cancelButton, -6);
FormData cancelButtonFormData = new FormData();
cancelButtonFormData.left = new FormAttachment(0, 392);
cancelButtonFormData.right = new FormAttachment(100, -10);
cancelButtonFormData.bottom = new FormAttachment(100, -10);
cancelButton.setLayoutData(cancelButtonFormData);
cancelButton.setText("Cancel");
}
/**
* Creates the SWT component for the OK button.
*/
private void createUIButtonOK() {
/**
* Create the button.
*/
okButton = new Button(loginComposite, SWT.PUSH);
passwordTextBoxFormData.bottom = new FormAttachment(okButton, -6);
okButtonFormData = new FormData();
okButtonFormData.left = new FormAttachment(0, 279);
okButtonFormData.bottom = new FormAttachment(100, -10);
okButton.setLayoutData(okButtonFormData);
okButton.setText("OK");
}
/**
* Creates the SWT component for the password text box.
*/
private void createUITextPassword() {
/**
* Create the text widget.
*/
int style = SWT.PASSWORD | SWT.BORDER;
passwordTextBox = new Text(loginComposite, style);
passwordLabelFormData.right = new FormAttachment(passwordTextBox, -6);
passwordTextBoxFormData = new FormData();
passwordTextBoxFormData.right = new FormAttachment(100, -10);
passwordTextBoxFormData.left = new FormAttachment(0, 279);
passwordTextBox.setLayoutData(passwordTextBoxFormData);
}
/**
* Creates the SWT component for the password label.
*/
private void createUILabelPassword() {
/**
* Create the label.
*/
passwordLabel = new Label(loginComposite, SWT.NONE);
passwordLabelFormData = new FormData();
passwordLabelFormData.top = new FormAttachment(usernameLabel, 11);
passwordLabel.setLayoutData(passwordLabelFormData);
passwordLabel.setText("&Password:");
}
/**
* Creates SWT component for the username text box.
*/
private void createUITextUserName() {
/**
* Create the text widget.
*/
usernameTextBox = new Text(loginComposite, SWT.BORDER);
usernameLabelFormData.top = new FormAttachment(usernameTextBox, 3, SWT.TOP);
usernameLabelFormData.right = new FormAttachment(usernameTextBox, -6);
usernameTextBoxFormData = new FormData();
usernameTextBoxFormData.top = new FormAttachment(0, 233);
usernameTextBoxFormData.right = new FormAttachment(100, -10);
usernameTextBoxFormData.left = new FormAttachment(0, 279);
usernameTextBox.setLayoutData(usernameTextBoxFormData);
}
/**
* Creates SWT component for the username label.
*/
private void createUILabelUserName() {
/**
* Create the label
*/
usernameLabel = new Label(loginComposite, SWT.NONE);
usernameLabelFormData = new FormData();
usernameLabel.setLayoutData(usernameLabelFormData);
usernameLabel.setText("&User Name:");
}
/**
* Creates SWT component for the login composite.
*/
private void createUICompositeLogin() {
/**
* Create the composite and set the layout.
*/
loginComposite = new Composite(getSplash(), SWT.BORDER);
loginComposite.setLayout(new FormLayout());
}
/**
* Configures the splash screen SWT/UI components.
*/
private void configureUISplash() {
/**
* Configure layout
*/
FillLayout layout = new FillLayout();
getSplash().setLayout(layout);
/**
* Force shell to inherit the splash background
*/
getSplash().setBackgroundMode(SWT.INHERIT_DEFAULT);
}
}
最佳答案
奇怪的是,位图(在 Photoshop/Mac 中创建)图像在 Eclipse 中被视为已损坏,但在所有图形应用程序(包括 Photoshop/Win)中都可以正常打开。我在 MS Paint 中打开文件并保存而没有更改。飞溅开始正常工作。
如果出现此错误,请检查您的位图!
关于windows - 为什么我的 RCP 应用程序启动画面没有显示在 Windows 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10814324/
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co
对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl
我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
为什么4.1%2返回0.0999999999999996?但是4.2%2==0.2。 最佳答案 参见此处:WhatEveryProgrammerShouldKnowAboutFloating-PointArithmetic实数是无限的。计算机使用的位数有限(今天是32位、64位)。因此计算机进行的浮点运算不能代表所有的实数。0.1是这些数字之一。请注意,这不是与Ruby相关的问题,而是与所有编程语言相关的问题,因为它来自计算机表示实数的方式。 关于ruby-为什么4.1%2使用Ruby返
我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr