1
1
/*******************************************************************************
2
- * Copyright (c) 2000, 2020 IBM Corporation and others.
2
+ * Copyright (c) 2000, 2025 IBM Corporation and others.
3
3
*
4
4
* This program and the accompanying materials
5
5
* are made available under the terms of the Eclipse Public License 2.0
15
15
16
16
17
17
import java .text .MessageFormat ;
18
+ import java .util .regex .Pattern ;
18
19
19
20
import org .eclipse .debug .internal .ui .DebugUIPlugin ;
20
21
import org .eclipse .debug .internal .ui .IDebugHelpContextIds ;
24
25
import org .eclipse .jface .preference .FieldEditorPreferencePage ;
25
26
import org .eclipse .jface .preference .IPreferenceStore ;
26
27
import org .eclipse .jface .preference .IntegerFieldEditor ;
28
+ import org .eclipse .jface .preference .StringFieldEditor ;
27
29
import org .eclipse .jface .util .PropertyChangeEvent ;
28
30
import org .eclipse .swt .SWT ;
29
31
import org .eclipse .swt .events .SelectionAdapter ;
@@ -87,6 +89,8 @@ protected void clearErrorMessage() {
87
89
private BooleanFieldEditor2 fInterpretControlCharactersEditor ;
88
90
private BooleanFieldEditor2 fInterpretCrAsControlCharacterEditor ;
89
91
92
+ private StringFieldEditor fElapsedFormat ;
93
+
90
94
/**
91
95
* Create the console page.
92
96
*/
@@ -159,6 +163,11 @@ public void widgetSelected(SelectionEvent e) {
159
163
addField (new BooleanFieldEditor (IDebugPreferenceConstants .CONSOLE_OPEN_ON_OUT , DebugPreferencesMessages .ConsolePreferencePage_Show__Console_View_when_there_is_program_output_3 , SWT .NONE , getFieldEditorParent ()));
160
164
addField (new BooleanFieldEditor (IDebugPreferenceConstants .CONSOLE_OPEN_ON_ERR , DebugPreferencesMessages .ConsolePreferencePage_Show__Console_View_when_there_is_program_error_3 , SWT .NONE , getFieldEditorParent ()));
161
165
166
+ fElapsedFormat = new StringFieldEditor (IDebugPreferenceConstants .CONSOLE_ELAPSED_FORMAT ,
167
+ DebugPreferencesMessages .ConsoleElapsedTimeLabel , getFieldEditorParent ());
168
+ fElapsedFormat .setErrorMessage (DebugPreferencesMessages .ConsoleElapsedTimeInvalidFormat );
169
+ addField (fElapsedFormat );
170
+
162
171
ColorFieldEditor sysout = new ColorFieldEditor (IDebugPreferenceConstants .CONSOLE_SYS_OUT_COLOR , DebugPreferencesMessages .ConsolePreferencePage_Standard_Out__2 , getFieldEditorParent ());
163
172
ColorFieldEditor syserr = new ColorFieldEditor (IDebugPreferenceConstants .CONSOLE_SYS_ERR_COLOR , DebugPreferencesMessages .ConsolePreferencePage_Standard_Error__3 , getFieldEditorParent ());
164
173
ColorFieldEditor sysin = new ColorFieldEditor (IDebugPreferenceConstants .CONSOLE_SYS_IN_COLOR , DebugPreferencesMessages .ConsolePreferencePage_Standard_In__4 , getFieldEditorParent ());
@@ -197,6 +206,15 @@ public boolean performOk() {
197
206
int low = store .getInt (IDebugPreferenceConstants .CONSOLE_LOW_WATER_MARK );
198
207
int high = low + 8000 ;
199
208
store .setValue (IDebugPreferenceConstants .CONSOLE_HIGH_WATER_MARK , high );
209
+
210
+ String elapsedTime = fElapsedFormat .getStringValue ();
211
+ if (validateElapsedTimeFormat (elapsedTime )) {
212
+ DebugUIPlugin .getDefault ().getPreferenceStore ().setValue (IDebugPreferenceConstants .CONSOLE_ELAPSED_FORMAT ,
213
+ elapsedTime );
214
+ } else {
215
+ fElapsedFormat .showErrorMessage ();
216
+ }
217
+
200
218
return ok ;
201
219
}
202
220
@@ -211,6 +229,8 @@ protected void initialize() {
211
229
updateBufferSizeEditor ();
212
230
updateInterpretCrAsControlCharacterEditor ();
213
231
updateWordWrapEditorFromConsolePreferences ();
232
+ updateElapsedTimePreferences (false );
233
+
214
234
}
215
235
216
236
/**
@@ -266,10 +286,12 @@ protected void performDefaults() {
266
286
updateWidthEditor ();
267
287
updateBufferSizeEditor ();
268
288
updateInterpretCrAsControlCharacterEditor ();
289
+ updateElapsedTimePreferences (true );
269
290
}
270
291
271
292
protected boolean canClearErrorMessage () {
272
- return fWidthEditor .isValid () && fBufferSizeEditor .isValid () && fTabSizeEditor .isValid ();
293
+ return fWidthEditor .isValid () && fBufferSizeEditor .isValid () && fTabSizeEditor .isValid ()
294
+ && fElapsedFormat .isValid ();
273
295
}
274
296
275
297
/**
@@ -301,4 +323,25 @@ public void propertyChange(PropertyChangeEvent event) {
301
323
super .propertyChange (event );
302
324
}
303
325
}
326
+
327
+ protected void updateElapsedTimePreferences (boolean setDefault ) {
328
+ if (setDefault ) {
329
+ fElapsedFormat .setStringValue (DebugPreferencesMessages .ConsoleDefaultElapsedTimeFormat ); // Default
330
+ } else {
331
+ IPreferenceStore pref = DebugUIPlugin .getDefault ().getPreferenceStore ();
332
+ pref .setValue (IDebugPreferenceConstants .CONSOLE_ELAPSED_FORMAT , fElapsedFormat .getStringValue ());
333
+ }
334
+ }
335
+
336
+ private boolean validateElapsedTimeFormat (String format ) {
337
+ if (format .isEmpty ()) {
338
+ return true ;
339
+ }
340
+ String matcherFormat = "^((%d|%0\\ d+d):%0\\ d+d(:%0\\ d+d)?(\\ .%0\\ d+d)?|(%0\\ d+dh )?(%0\\ d+dm )?(%0\\ d+ds)?)$" ; //$NON-NLS-1$
341
+ Pattern pattern = Pattern .compile (matcherFormat );
342
+ if (pattern .matcher (format ).matches ()) {
343
+ return true ;
344
+ }
345
+ return false ;
346
+ }
304
347
}
0 commit comments