29
29
import java .text .DateFormat ;
30
30
import java .text .MessageFormat ;
31
31
import java .text .ParseException ;
32
+ import java .time .Duration ;
33
+ import java .time .Instant ;
32
34
import java .time .LocalDateTime ;
33
35
import java .time .ZoneId ;
34
36
import java .time .temporal .ChronoUnit ;
@@ -333,6 +335,14 @@ protected String computeName() {
333
335
}
334
336
335
337
DateFormat dateTimeFormat = DateFormat .getDateTimeInstance (DateFormat .MEDIUM , DateFormat .MEDIUM );
338
+ Duration elapsedTime = Duration .between (launchTime != null ? launchTime .toInstant () : Instant .now (),
339
+ terminateTime != null ? terminateTime .toInstant () : Instant .now ());
340
+ String elapsedString = String .format ("%d:%02d:%02d.%03d" , elapsedTime .toHours (), //$NON-NLS-1$
341
+ elapsedTime .toMinutesPart (), elapsedTime .toSecondsPart (), elapsedTime .toMillisPart ());
342
+ if (terminateTime == null ) {
343
+ DebugUIPlugin .getStandardDisplay ().asyncExec (
344
+ () -> DebugUIPlugin .getStandardDisplay ().timerExec (1000 , () -> resetName (false )));
345
+ }
336
346
if (launchTime != null && terminateTime != null ) {
337
347
String launchTimeStr = dateTimeFormat .format (launchTime );
338
348
// Check if process started and terminated at same day. If so only print the
@@ -351,10 +361,10 @@ protected String computeName() {
351
361
}
352
362
353
363
buffer .append (MessageFormat .format (ConsoleMessages .ProcessConsole_commandLabel_withStartEnd ,
354
- procLabel , launchTimeStr , terminateTimeStr ));
364
+ procLabel , launchTimeStr , terminateTimeStr , elapsedString ));
355
365
} else if (launchTime != null ) {
356
366
buffer .append (MessageFormat .format (ConsoleMessages .ProcessConsole_commandLabel_withStart ,
357
- procLabel , dateTimeFormat .format (launchTime )));
367
+ procLabel , dateTimeFormat .format (launchTime ), elapsedString ));
358
368
} else if (terminateTime != null ) {
359
369
buffer .append (MessageFormat .format (ConsoleMessages .ProcessConsole_commandLabel_withEnd ,
360
370
procLabel , dateTimeFormat .format (terminateTime )));
@@ -559,7 +569,7 @@ protected void init() {
559
569
setName (computeName ());
560
570
if (fProcess .isTerminated ()) {
561
571
closeStreams ();
562
- resetName ();
572
+ resetName (true );
563
573
DebugPlugin .getDefault ().removeDebugEventListener (this );
564
574
}
565
575
IPreferenceStore store = DebugUIPlugin .getDefault ().getPreferenceStore ();
@@ -600,24 +610,26 @@ public void handleDebugEvents(DebugEvent[] events) {
600
610
DebugPlugin .getDefault ().removeDebugEventListener (this );
601
611
}
602
612
603
- resetName ();
613
+ resetName (true );
604
614
}
605
615
}
606
616
}
607
617
608
618
/**
609
619
* resets the name of this console to the original computed name
610
620
*/
611
- private synchronized void resetName () {
621
+ private synchronized void resetName (boolean changed ) {
612
622
final String newName = computeName ();
613
623
String name = getName ();
614
624
if (!name .equals (newName )) {
615
625
UIJob job = new UIJob ("Update console title" ) { //$NON-NLS-1$
616
626
@ Override
617
627
public IStatus runInUIThread (IProgressMonitor monitor ) {
618
- ProcessConsole .this .setName (newName );
619
- warnOfContentChange ();
620
- return Status .OK_STATUS ;
628
+ ProcessConsole .this .setName (newName );
629
+ if (changed ) {
630
+ warnOfContentChange ();
631
+ }
632
+ return Status .OK_STATUS ;
621
633
}
622
634
};
623
635
job .setSystem (true );
0 commit comments