tdeclipse 2009-12-14
packagecom.cnex.oss.managerupdate.tools;
importjava.beans.PropertyChangeListener;
importjava.beans.PropertyChangeSupport;
importjava.util.Timer;
importjava.util.TimerTask;
importorg.eclipse.jface.dialogs.IDialogConstants;
importorg.eclipse.jface.layout.GridDataFactory;
importorg.eclipse.jface.window.Window;
importorg.eclipse.swt.SWT;
importorg.eclipse.swt.graphics.Image;
importorg.eclipse.swt.widgets.Composite;
importorg.eclipse.swt.widgets.Control;
importorg.eclipse.swt.widgets.Display;
importorg.eclipse.swt.widgets.Label;
importorg.eclipse.swt.widgets.Shell;
/**
*定时执行对话框。
*/
publicclassTimerMessageDialogextendsMessageDialog2{
/**标签文本*/
protectedstaticLabellocalMessageLabel;
/**属性修改支持实现类*/
privatePropertyChangeSupportImplinstance=newPropertyChangeSupportImpl();
/**定时器*/
privateTimertimer;
/**
*构造函数。
*@paramparentShell
*@paramdialogTitle
*@paramdialogMessage
*/
publicTimerMessageDialog(ShellparentShell,StringdialogTitle,StringdialogMessage){
super(parentShell,dialogTitle,null,dialogMessage,INFORMATION,newString[]{"立即重启","隐藏"},0);
setShellStyle(SWT.BORDER|SWT.MIN);
}
protectedControlcreateMessageArea(Compositecomposite){
//createcomposite
//createimage
Imageimage=getImage();
if(image!=null){
imageLabel=newLabel(composite,SWT.NULL);
image.setBackground(imageLabel.getBackground());
imageLabel.setImage(image);
//addAccessibleListeners(imageLabel,image);
GridDataFactory.fillDefaults().align(SWT.CENTER,SWT.BEGINNING)
.applyTo(imageLabel);
}
//createmessage
if(message!=null){
messageLabel=newLabel(composite,getMessageLabelStyle());
TimerMessageDialog.localMessageLabel=messageLabel;
messageLabel.setText(message);
GridDataFactory
.fillDefaults()
.align(SWT.FILL,SWT.BEGINNING)
.grab(true,false)
.hint(
convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH),
SWT.DEFAULT).applyTo(messageLabel);
}
returncomposite;
}
/**
*打开定时关闭对话框,顾名思义,就是在指定的时间自动关闭。
*/
publicvoidopen(finalintsecond,finalStringmessage){
setBlockOnOpen(false);
open();
//finalMessageFormatformat=newMessageFormat("系统检查到重要插件的更新,系统将会在{0}秒后自动重启,请注意保存文件");
timer=newTimer("检查更新");
finalTimerTasktask=newTimerTask(){
intcount=second;
publicvoidrun(){
Displaydisplay=Display.getDefault();
if(display==null){
return;
}
display.asyncExec(newRunnable(){
publicvoidrun(){
try{
if(count==0){
cancel();
buttonPressed(Window.OK);
}else{
count-=1;
if(!localMessageLabel.isDisposed()&&localMessageLabel!=null){
localMessageLabel.setText(message+"系统将在:"+count+"秒后自动重启");
//localMessageLabel.setText(format.format(newObject[]{newInteger(count)}));
}
}
}catch(Exceptione){
e.printStackTrace();
}
}
});
}
};
timer.schedule(task,1000,1000);
}
protectedvoidbuttonPressed(intbuttonId){
if(buttonId==Window.OK){
timer.cancel();
firePropertyChange(IPropery.RESTART_OK_PRESSED,false,true);
}elseif(buttonId==Window.CANCEL){
close();
}
}
/**
*添加属性事件。
*/
publicvoidaddPropertyChangeListener(PropertyChangeListenerl){
instance.addPropertyChangeListener(l);
}
/**
*删除属性修改事件。
*/
publicvoidremovePropertyChangeListener(PropertyChangeListenerl){
instance.removePropertyChangeListener(l);
}
/**
*通知属性修改事件(通知前台代码修改)。
*/
publicvoidfirePropertyChange(Stringprop,Objectold,ObjectnewValue){
instance.firePropertyChange(prop,old,newValue);
}
/**
*属性修改支持实现类。
*/
publicclassPropertyChangeSupportImpl{
/**属性修改支持*/
PropertyChangeSupportlisteners=newPropertyChangeSupport(this);
/**
*添加属性修改事件。
*/
publicvoidaddPropertyChangeListener(PropertyChangeListenerl){
listeners.addPropertyChangeListener(l);
}
/**
*通知修改事件发生。
*/
publicvoidfirePropertyChange(Stringprop,Objectold,ObjectnewValue){
listeners.firePropertyChange(prop,old,newValue);
}
/**
*通知事件修改。
*/
protectedvoidfireStructureChange(Stringprop,Objectchild){
listeners.firePropertyChange(prop,null,child);
}
/**
*删除属性修改事件/。
publicvoidremovePropertyChangeListener(PropertyChangeListenerl){
listeners.removePropertyChangeListener(l);
}
}
}