You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hop.apache.org by ha...@apache.org on 2021/01/19 18:35:01 UTC

[incubator-hop] branch master updated: HOP-2349: Replace the use of StyledText with Text at HopGuiLogBrowser

This is an automated email from the ASF dual-hosted git repository.

hansva pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hop.git


The following commit(s) were added to refs/heads/master by this push:
     new babfce0  HOP-2349: Replace the use of StyledText with Text at HopGuiLogBrowser
     new 62bf549  Merge pull request #566 from HiromuHota/HOP-2349
babfce0 is described below

commit babfce075c64fdf668897af57f733e7e39971b4d
Author: Hiromu Hota <hi...@gmail.com>
AuthorDate: Mon Jan 18 15:36:27 2021 -0800

    HOP-2349: Replace the use of StyledText with Text at HopGuiLogBrowser
---
 .../ui/hopgui/file/pipeline/HopGuiLogBrowser.java  | 50 +++-------------------
 .../delegates/HopGuiPipelineLogDelegate.java       |  6 +--
 .../delegates/HopGuiWorkflowLogDelegate.java       |  6 +--
 3 files changed, 11 insertions(+), 51 deletions(-)

diff --git a/ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiLogBrowser.java b/ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiLogBrowser.java
index a4ca4d2..d8607bd 100644
--- a/ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiLogBrowser.java
+++ b/ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiLogBrowser.java
@@ -37,8 +37,6 @@ import org.apache.hop.ui.core.widget.text.Format;
 import org.apache.hop.ui.core.widget.text.TextFormatter;
 import org.apache.hop.ui.hopgui.HopGui;
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyleRange;
-import org.eclipse.swt.custom.StyledText;
 import org.eclipse.swt.events.DisposeEvent;
 import org.eclipse.swt.events.DisposeListener;
 import org.eclipse.swt.events.MouseAdapter;
@@ -48,6 +46,7 @@ import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.widgets.Menu;
 import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.Text;
 
 import java.awt.*;
 import java.net.URI;
@@ -62,13 +61,13 @@ import java.util.concurrent.atomic.AtomicInteger;
 public class HopGuiLogBrowser {
   private static final Class<?> PKG = HopGui.class; // For Translator
 
-  private StyledText text;
+  private Text text;
   private ILogParentProvided logProvider;
   private List<String> childIds = new ArrayList<>();
   private Date lastLogRegistryChange;
   private AtomicBoolean paused;
 
-  public HopGuiLogBrowser( final StyledText text, final ILogParentProvided logProvider ) {
+  public HopGuiLogBrowser( final Text text, final ILogParentProvided logProvider ) {
     this.text = text;
     this.logProvider = logProvider;
     this.paused = new AtomicBoolean( false );
@@ -82,11 +81,6 @@ public class HopGuiLogBrowser {
     final AtomicBoolean busy = new AtomicBoolean( false );
     final HopLogLayout logLayout = new HopLogLayout( true );
 
-    final StyleRange normalLogLineStyle = new StyleRange();
-    normalLogLineStyle.foreground = GuiResource.getInstance().getColorBlue();
-    final StyleRange errorLogLineStyle = new StyleRange();
-    errorLogLineStyle.foreground = GuiResource.getInstance().getColorRed();
-
     // Refresh the log every second or so
     //
     final Timer logRefreshTimer = new Timer( "log sniffer Timer" );
@@ -146,25 +140,6 @@ public class HopGuiLogBrowser {
                     Format format = TextFormatter.getInstance().execute( line );
                     text.append( format.getText() );
                     text.append( Const.CR );
-
-                    for ( StyleRange styleRange : format.getStyleRanges() ) {
-                      styleRange.start += start;
-                      text.setStyleRange( styleRange );
-                    }
-
-                    if ( event.getLevel() == LogLevel.ERROR ) {
-                      StyleRange styleRange = new StyleRange();
-                      styleRange.foreground = GuiResource.getInstance().getColorRed();
-                      styleRange.start = start;
-                      styleRange.length = length;
-                      text.setStyleRange( styleRange );
-                    } else {
-                      StyleRange styleRange = new StyleRange();
-                      styleRange.foreground = GuiResource.getInstance().getColorBlue();
-                      styleRange.start = start;
-                      styleRange.length = Math.min( 20, length );
-                      text.setStyleRange( styleRange );
-                    }
                   }
                 }
               }
@@ -176,7 +151,7 @@ public class HopGuiLogBrowser {
               if ( maxSize > 0 && size > maxSize ) {
 
                 int dropIndex = ( text.getText().indexOf( Const.CR, size - maxSize ) ) + Const.CR.length();
-                text.replaceTextRange( 0, dropIndex, "" );
+                text.setText( text.getText().substring( dropIndex ) );
               }
 
               text.setSelection( text.getText().length() );
@@ -196,21 +171,6 @@ public class HopGuiLogBrowser {
       .schedule( timerTask, Const.toInt( EnvUtil.getSystemProperty( Const.HOP_LOG_TAB_REFRESH_DELAY ), 1000 ),
         Const.toInt( EnvUtil.getSystemProperty( Const.HOP_LOG_TAB_REFRESH_PERIOD ), 1000 ) );
 
-
-    text.addListener( SWT.MouseDown, e -> {
-      try {
-        int offset = text.getOffsetAtLocation( new Point( e.x, e.y ) );
-        StyleRange style = text.getStyleRangeAtOffset( offset );
-        if ( style != null && style.underline && style.underlineStyle == SWT.UNDERLINE_LINK ) {
-          if ( Desktop.isDesktopSupported() ) {
-            Desktop.getDesktop().browse( new URI( (String) style.data ) );
-          }
-        }
-      } catch ( Exception ex ) {
-        // no character under event.x, event.y
-      }
-    } );
-
     // Make sure the timer goes down when the widget is disposed
     //
     text.addDisposeListener( event -> logRefreshTimer.cancel() );
@@ -249,7 +209,7 @@ public class HopGuiLogBrowser {
   /**
    * @return the text
    */
-  public StyledText getText() {
+  public Text getText() {
     return text;
   }
 
diff --git a/ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/delegates/HopGuiPipelineLogDelegate.java b/ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/delegates/HopGuiPipelineLogDelegate.java
index b02fcd0..a0830ec 100644
--- a/ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/delegates/HopGuiPipelineLogDelegate.java
+++ b/ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/delegates/HopGuiPipelineLogDelegate.java
@@ -35,11 +35,11 @@ import org.apache.hop.ui.hopgui.file.pipeline.HopGuiLogBrowser;
 import org.apache.hop.ui.hopgui.file.pipeline.HopGuiPipelineGraph;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.CTabItem;
-import org.eclipse.swt.custom.StyledText;
 import org.eclipse.swt.layout.FormAttachment;
 import org.eclipse.swt.layout.FormData;
 import org.eclipse.swt.layout.FormLayout;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
 import org.eclipse.swt.widgets.ToolBar;
 import org.eclipse.swt.widgets.ToolItem;
 
@@ -61,7 +61,7 @@ public class HopGuiPipelineLogDelegate {
   private HopGui hopGui;
   private CTabItem pipelineLogTab;
 
-  private StyledText pipelineLogText;
+  private Text pipelineLogText;
 
   private ToolBar toolbar;
   private GuiToolbarWidgets toolBarWidgets;
@@ -109,7 +109,7 @@ public class HopGuiPipelineLogDelegate {
     fd.right = new FormAttachment( 100, 0 );
     toolbar.setLayoutData( fd );
 
-    pipelineLogText = new StyledText( pipelineLogComposite, SWT.READ_ONLY | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL );
+    pipelineLogText = new Text( pipelineLogComposite, SWT.READ_ONLY | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL );
     hopGui.getProps().setLook( pipelineLogText );
     FormData fdText = new FormData();
     fdText.left = new FormAttachment( 0, 0 );
diff --git a/ui/src/main/java/org/apache/hop/ui/hopgui/file/workflow/delegates/HopGuiWorkflowLogDelegate.java b/ui/src/main/java/org/apache/hop/ui/hopgui/file/workflow/delegates/HopGuiWorkflowLogDelegate.java
index 71586c6..352f51d 100644
--- a/ui/src/main/java/org/apache/hop/ui/hopgui/file/workflow/delegates/HopGuiWorkflowLogDelegate.java
+++ b/ui/src/main/java/org/apache/hop/ui/hopgui/file/workflow/delegates/HopGuiWorkflowLogDelegate.java
@@ -35,12 +35,12 @@ import org.apache.hop.ui.hopgui.file.workflow.HopGuiWorkflowGraph;
 import org.apache.hop.ui.hopgui.file.pipeline.HopGuiLogBrowser;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.CTabItem;
-import org.eclipse.swt.custom.StyledText;
 import org.eclipse.swt.layout.FormAttachment;
 import org.eclipse.swt.layout.FormData;
 import org.eclipse.swt.layout.FormLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Text;
 import org.eclipse.swt.widgets.ToolBar;
 import org.eclipse.swt.widgets.ToolItem;
 
@@ -62,7 +62,7 @@ public class HopGuiWorkflowLogDelegate {
 
   private CTabItem jobLogTab;
 
-  public StyledText jobLogText;
+  public Text jobLogText;
 
   /**
    * The number of lines in the log tab
@@ -114,7 +114,7 @@ public class HopGuiWorkflowLogDelegate {
     fd.right = new FormAttachment( 100, 0 );
     toolbar.setLayoutData( fd );
 
-    jobLogText = new StyledText( jobLogComposite, SWT.READ_ONLY | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL );
+    jobLogText = new Text( jobLogComposite, SWT.READ_ONLY | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL );
     hopGui.getProps().setLook( jobLogText );
     FormData fdText = new FormData();
     fdText.left = new FormAttachment( 0, 0 );