98
99
public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor implements
102
private final class ErrorHandler implements IDbErrorHandler {
103
private final IWorkbenchConfigurer configurer;
105
public ErrorHandler(IWorkbenchConfigurer configurer) {
106
this.configurer = configurer;
109
public void fatalError(final String title, final String msg,
110
IAdaptable adaptable) {
111
final Shell shell = getShell(adaptable);
112
syncExec(shell, new Runnable() {
114
if (!shell.isDisposed()) {
115
AcousticMessageDialog.openError(shell, title, msg);
116
shell.getDisplay().dispose();
123
public void connectionLostWarning(final String title,
124
final String message, final IAdaptable adaptable) {
125
final Shell shell = getShell(adaptable);
126
syncExec(shell, new Runnable() {
128
if (!shell.isDisposed()
129
&& !AcousticMessageDialog.openQuestion(shell,
132
configurer.emergencyClose();
137
public void promptForReconnect(final String title,
138
final String message, final IInputValidator validator,
139
final IAdaptable adaptable) {
140
final Shell shell = getShell(adaptable);
141
syncExec(shell, new Runnable() {
143
if (!shell.isDisposed()
144
&& new TimedMessageDialog(shell, validator,
145
title, null, message,
146
MessageDialog.WARNING, new String[] {
147
IDialogConstants.RETRY_LABEL,
148
IDialogConstants.ABORT_LABEL },
149
0, 0, 1000L).open() != 0) {
150
shell.getDisplay().dispose();
157
public boolean question(String title, String message,
158
IAdaptable adaptable) {
159
final Shell shell = getShell(adaptable);
160
final AcousticMessageDialog dialog = new AcousticMessageDialog(
161
shell, title, null, message, MessageDialog.QUESTION,
162
new String[] { IDialogConstants.YES_LABEL,
163
IDialogConstants.NO_LABEL }, 0);
164
syncExec(shell, new Runnable() {
169
return dialog.getReturnCode() == 0;
172
public void showError(final String title, final String message,
173
IAdaptable adaptable) {
174
final Shell shell = getShell(adaptable);
175
asyncExec(shell, new Runnable() {
177
if (!shell.isDisposed())
178
AcousticMessageDialog.openError(shell, title,
184
public void showWarning(final String title, final String message,
185
IAdaptable adaptable) {
186
final Shell shell = getShell(adaptable);
187
asyncExec(shell, new Runnable() {
189
if (!shell.isDisposed())
190
AcousticMessageDialog.openWarning(shell, title,
196
public void showInformation(final String title,
197
final String message, IAdaptable adaptable) {
198
showInformation(title, message, adaptable, null);
201
public void showInformation(final String title,
202
final String message, IAdaptable adaptable,
203
final IValidator validator) {
204
final Shell shell = getShell(adaptable);
205
asyncExec(shell, new Runnable() {
207
if (!shell.isDisposed())
208
AcousticMessageDialog.openInformation(shell, title,
214
public int showMessageDialog(String dialogTitle,
215
Image dialogTitleImage, String dialogMessage,
216
int dialogImageType, String[] dialogButtonLabels,
217
int defaultIndex, IAdaptable adaptable) {
218
final Shell shell = getShell(adaptable);
219
final AcousticMessageDialog dialog = new AcousticMessageDialog(
220
shell, dialogTitle, dialogTitleImage, dialogMessage,
221
dialogImageType, dialogButtonLabels, defaultIndex);
222
syncExec(shell, new Runnable() {
227
return dialog.getReturnCode();
230
public ImportConfiguration showConflictDialog(String title,
231
String message, Asset asset,
232
ImportConfiguration currentConfig, boolean multi,
233
IAdaptable adaptable) {
234
final Shell shell = getShell(adaptable);
235
final ConflictDialog dialog = new ConflictDialog(shell, title,
236
message, asset, currentConfig, multi);
237
syncExec(shell, new Runnable() {
242
return dialog.getCurrentConfig();
245
public void alarmOnPrompt(String sound) {
248
ui.playSound(sound, PreferenceConstants.ALARMONPROMPT);
251
public void signalEOJ(String sound) {
254
ui.playSound(sound, PreferenceConstants.ALARMONFINISH);
257
private void syncExec(Shell shell, Runnable runnable) {
258
if (shell != null && !shell.isDisposed())
259
shell.getDisplay().syncExec(runnable);
262
private void asyncExec(Shell shell, Runnable runnable) {
263
if (shell != null && !shell.isDisposed())
264
shell.getDisplay().asyncExec(runnable);
267
public Shell getShell(IAdaptable adaptable) {
268
Shell shell = adaptable == null ? null : (Shell) adaptable
269
.getAdapter(Shell.class);
271
final Display display = Display.getDefault();
272
if (!display.isDisposed()) {
273
display.syncExec(new Runnable() {
275
auxShell = new Shell(display);
285
public File showDngDialog(File dngLocation, IAdaptable adaptable) {
286
Shell shell = getShell(adaptable);
287
final DNGConverterDialog dialog = new DNGConverterDialog(shell,
289
syncExec(shell, new Runnable() {
294
return dialog.getResult();
297
public IRawConverter showRawDialog(IAdaptable adaptable) {
298
final Shell shell = getShell(adaptable);
299
boolean result = question(
300
Constants.APPLICATION_NAME,
301
Messages.getString("ApplicationWorkbenchAdvisor.no_raw_converter"), adaptable); //$NON-NLS-1$
303
final int ret[] = new int[1];
304
syncExec(shell, new Runnable() {
306
ret[0] = PreferencesUtil.createPreferenceDialogOn(
307
shell, ImportPreferencePage.ID,
308
new String[0], ImportPreferencePage.RAW)
312
if (ret[0] == Dialog.OK)
313
return BatchActivator.getDefault()
314
.getCurrentRawConverter(true);
101
320
private static final String CURRENT_CATALOG = "com.bdaum.zoom.currentCatalog"; //$NON-NLS-1$
102
321
private static final String CURRENT_VOLUME = "com.bdaum.zoom.currentVolume"; //$NON-NLS-1$
103
322
private static final String RECENTCATS = "com.bdaum.zoom.recentCats"; //$NON-NLS-1$
134
354
public void initialize(final IWorkbenchConfigurer configurer) {
135
Core.getCore().getDbFactory().setErrorHandler(new IDbErrorHandler() {
137
public void fatalError(final String title, final String msg,
138
IAdaptable adaptable) {
139
final Shell shell = getShell(adaptable);
140
syncExec(shell, new Runnable() {
142
if (!shell.isDisposed()) {
143
AcousticMessageDialog.openError(shell, title, msg);
150
public void connectionLostWarning(final String title,
151
final String message, final IAdaptable adaptable) {
152
final Shell shell = getShell(adaptable);
153
syncExec(shell, new Runnable() {
155
if (!shell.isDisposed()) {
156
if (AcousticMessageDialog.openQuestion(shell,
158
configurer.emergencyClose();
160
configurer.emergencyClose();
165
public void promptForReconnect(final String title,
166
final String message, final IInputValidator validator,
167
final IAdaptable adaptable) {
168
final Shell shell = getShell(adaptable);
169
syncExec(shell, new Runnable() {
171
if (!shell.isDisposed()
172
&& new TimedMessageDialog(shell, validator,
173
title, null, message,
174
MessageDialog.WARNING, new String[] {
175
IDialogConstants.RETRY_LABEL,
176
IDialogConstants.ABORT_LABEL },
177
0, 0, 1000L).open() != 0) {
178
shell.getDisplay().dispose();
185
public boolean question(String title, String message,
186
IAdaptable adaptable) {
187
final Shell shell = getShell(adaptable);
188
final AcousticMessageDialog dialog = new AcousticMessageDialog(
189
shell, title, null, message, MessageDialog.QUESTION,
190
new String[] { IDialogConstants.YES_LABEL,
191
IDialogConstants.NO_LABEL }, 0);
192
syncExec(shell, new Runnable() {
197
return dialog.getReturnCode() == 0;
200
public void showError(final String title, final String message,
201
IAdaptable adaptable) {
202
final Shell shell = getShell(adaptable);
203
asyncExec(shell, new Runnable() {
205
if (!shell.isDisposed())
206
AcousticMessageDialog.openError(shell, title,
212
public void showWarning(final String title, final String message,
213
IAdaptable adaptable) {
214
final Shell shell = getShell(adaptable);
215
asyncExec(shell, new Runnable() {
217
if (!shell.isDisposed())
218
AcousticMessageDialog.openWarning(shell, title,
224
public void showInformation(final String title,
225
final String message, IAdaptable adaptable) {
226
showInformation(title, message, adaptable, null);
229
public void showInformation(final String title,
230
final String message, IAdaptable adaptable,
231
final IValidator validator) {
232
final Shell shell = getShell(adaptable);
233
asyncExec(shell, new Runnable() {
235
if (!shell.isDisposed())
236
AcousticMessageDialog.openInformation(shell, title,
242
public int showMessageDialog(String dialogTitle,
243
Image dialogTitleImage, String dialogMessage,
244
int dialogImageType, String[] dialogButtonLabels,
245
int defaultIndex, IAdaptable adaptable) {
246
final Shell shell = getShell(adaptable);
247
final AcousticMessageDialog dialog = new AcousticMessageDialog(
248
shell, dialogTitle, dialogTitleImage, dialogMessage,
249
dialogImageType, dialogButtonLabels, defaultIndex);
250
syncExec(shell, new Runnable() {
255
return dialog.getReturnCode();
258
public ImportConfiguration showConflictDialog(String title,
259
String message, Asset asset, ImportConfiguration currentConfig,
260
boolean multi, IAdaptable adaptable) {
261
final Shell shell = getShell(adaptable);
262
final ConflictDialog dialog = new ConflictDialog(shell, title,
263
message, asset, currentConfig, multi);
264
syncExec(shell, new Runnable() {
269
return dialog.getCurrentConfig();
272
public void alarmOnPrompt(String sound) {
275
ui.playSound(sound, PreferenceConstants.ALARMONPROMPT);
278
public void signalEOJ(String sound) {
281
ui.playSound(sound, PreferenceConstants.ALARMONFINISH);
284
private void syncExec(Shell shell, Runnable runnable) {
285
if (shell != null && !shell.isDisposed())
286
shell.getDisplay().syncExec(runnable);
289
private void asyncExec(Shell shell, Runnable runnable) {
290
if (shell != null && !shell.isDisposed())
291
shell.getDisplay().asyncExec(runnable);
294
public Shell getShell(IAdaptable adaptable) {
295
Shell shell = adaptable == null ? null : (Shell) adaptable
296
.getAdapter(Shell.class);
298
final Display display = Display.getDefault();
299
if (!display.isDisposed()) {
300
display.syncExec(new Runnable() {
302
auxShell = new Shell(display);
312
public File showDngDialog(File dngLocation, IAdaptable adaptable) {
313
Shell shell = getShell(adaptable);
314
final DNGConverterDialog dialog = new DNGConverterDialog(shell,
316
syncExec(shell, new Runnable() {
321
return dialog.getResult();
324
public IRawConverter showRawDialog(IAdaptable adaptable) {
325
final Shell shell = getShell(adaptable);
326
boolean result = question(
327
Constants.APPLICATION_NAME,
328
Messages.getString("ApplicationWorkbenchAdvisor.no_raw_converter"), adaptable); //$NON-NLS-1$
330
final int ret[] = new int[1];
331
syncExec(shell, new Runnable() {
333
ret[0] = PreferencesUtil.createPreferenceDialogOn(shell,
334
ImportPreferencePage.ID, new String[0], ImportPreferencePage.RAW).open();
337
if (ret[0] == Dialog.OK)
338
return BatchActivator.getDefault().getCurrentRawConverter(true);
355
Core.getCore().getDbFactory().setErrorHandler(new ErrorHandler(configurer));
344
356
configurer.setSaveAndRestore(true);
357
workbenchHelper = new WorkbenchHelper(this, true);
348
361
public void postStartup() {
349
362
super.postStartup();
363
// Runtime.getRuntime().addShutdownHook(new Thread() { // Caused to many problems during emergency shutdown of platform
365
// public void run() {
366
// if (!getWorkbenchConfigurer().emergencyClosing()) {
367
// BatchActivator.setFastExit(true);
368
// getWorkbenchConfigurer().emergencyClose();
350
372
final IWorkbench workbench = getWorkbenchConfigurer().getWorkbench();
351
373
workbench.getPreferenceManager().remove(
352
374
"org.eclipse.help.ui.browsersPreferencePage"); //$NON-NLS-1$