1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
| public class LoadingDialog extends Dialog implements Observer, SelectionListener {
private static final Logger log = LogManager.getLogger(LoadingDialog.class.getName());
private Composite container;
private Label labelInfo;
private final HelloSWTJFace mainApplication;
private ProgressBar progressBar;
private ProjectsLoader projectsLoader;
public LoadingDialog(HelloSWTJFace mainApplication) {
super(mainApplication);
this.mainApplication = mainApplication;
}
@Override
protected void configureShell(Shell shell) {
super.configureShell(shell);
shell.setText(HelloSWTJFace.props.getProperty("messageDialogTitle.Loading"));
}
@Override
protected void createButtonsForButtonBar(Composite parent) {
final Button button = this.createButton(parent, IDialogConstants.CANCEL_ID,
HelloSWTJFace.props.getProperty("button.Cancel"), true);
button.addSelectionListener(this);
}
@Override
protected Control createDialogArea(Composite parent) {
this.container = (Composite) super.createDialogArea(parent);
final GridLayout gridLayout = new GridLayout(1, true);
gridLayout.marginRight = 7;
gridLayout.marginLeft = 10;
gridLayout.marginTop = 10;
gridLayout.marginBottom = 10;
this.getContainer().setLayout(gridLayout);
this.getContainer().setLayoutData(new GridData(325, 100));
this.progressBar = new ProgressBar(this.getContainer(), SWT.HORIZONTAL | SWT.SMOOTH);
final GridData gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.horizontalSpan = 1;
gridData.heightHint = 50;
this.getProgressBar().setLayoutData(gridData);
this.getProgressBar().setMinimum(0);
this.getProgressBar().setMaximum(100);
this.labelInfo = new Label(this.getContainer(), SWT.NONE);
gridData.horizontalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.horizontalSpan = 1;
gridData.heightHint = 50;
this.getLabelInfo().setLayoutData(gridData);
return this.container;
}
public Composite getContainer() {
return this.container;
}
@Override
protected Point getInitialSize() {
return super.getInitialSize();
}
public Label getLabelInfo() {
return this.labelInfo;
}
public HelloSWTJFace getMainApplication() {
return this.mainApplication;
}
public ProgressBar getProgressBar() {
return this.progressBar;
}
public ProjectsLoader getProjectsLoader() {
return this.projectsLoader;
}
public void setProjectsLoader(ProjectsLoader projectsLoader) {
this.projectsLoader = projectsLoader;
}
@Override
public void update(Observable arg0, Object arg1) {
// log.warn("updateObservable : " + arg0);
if (arg0 instanceof ProjectsLoader) {
this.setProjectsLoader((ProjectsLoader) arg0);
// log.warn("projectsLoader : " + this.getProjectsLoader());
try {
this.getProgressBar().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
LoadingDialog.this.progressBar.setSelection(LoadingDialog.this.progressBar.getSelection() + 1);
if (LoadingDialog.this.progressBar
.getSelection() < (LoadingDialog.this.progressBar.getMaximum())) {
LoadingDialog.this.labelInfo.setText(
String.valueOf(LoadingDialog.this.progressBar.getSelection() + 1) + " / 100");
}
else if (LoadingDialog.this.progressBar
.getSelection() == (LoadingDialog.this.progressBar.getMaximum())) {
try {
Thread.sleep(2000);
}
catch (final Exception e) {
log.warn(e.fillInStackTrace());
}
LoadingDialog.this.close();
}
}
});
}
catch (final Exception e) {
log.warn("Interrupted : " + e.fillInStackTrace());
}
}
}
@Override
public void widgetDefaultSelected(SelectionEvent arg0) {
}
@Override
public void widgetSelected(SelectionEvent arg0) {
log.warn("widgetSelected : " + arg0.getSource());
try {
this.getProjectsLoader().stop();
}
catch (final NullPointerException e) {
log.warn(e.fillInStackTrace());
}
}
} |
Partager