Skip to content

Commit

Permalink
HOP-1491: Fill the gap for single-sourcing (#540)
Browse files Browse the repository at this point in the history
* HOP-1491: RAP only allows painting on the Canvas widget

* RAP does not implement LineStyle and LineAttributes

* Do not use a Lambda expression here otherwise SecurityException happens on Hop Web
  • Loading branch information
HiromuHota committed Jan 6, 2021
1 parent 8f9fc64 commit 4ddbf62
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 54 deletions.
Expand Up @@ -51,6 +51,7 @@
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
Expand All @@ -70,7 +71,7 @@
* @since 29-07-2004
*/

public class ConditionEditor extends Composite {
public class ConditionEditor extends Canvas {
private static final Class<?> PKG = ConditionEditor.class; // Needed by Translator

private static final int X_PADDING = 18;
Expand All @@ -90,7 +91,7 @@ public class ConditionEditor extends Composite {
private static final int AREA_RIGHT_EXACT = 10;
private static final int AREA_ICON_ADD = 11;

protected Composite widget;
protected Canvas widget;
private Shell shell;
private Display display;
private Condition activeCondition;
Expand Down Expand Up @@ -736,10 +737,7 @@ public void widgetSelected( SelectionEvent e ) {
}
}

public void repaint( GC dgc, int width, int height ) {
Image im = new Image( display, width, height );
GC gc = new GC( im );

public void repaint( GC gc, int width, int height ) {
// Initialize some information
size_not = getNotSize( gc );
size_widget = getWidgetSize( gc );
Expand Down Expand Up @@ -804,11 +802,6 @@ public void repaint( GC dgc, int width, int height ) {
* Set the scroll bars: show/don't show and set the size
*/
setBars();

// Draw the result on the canvas, all in 1 go.
dgc.drawImage( im, 0, 0 );

im.dispose();
}

private Rectangle getNotSize( GC gc ) {
Expand Down
Expand Up @@ -3048,27 +3048,31 @@ private void inputOutputFields(TransformMeta transformMeta, boolean before) {
final ProgressMonitorDialog pmd = new ProgressMonitorDialog(hopShell());

// Run something in the background to cancel active database queries, forecably if needed!
Runnable run =
() -> {
IProgressMonitor monitor = pmd.getProgressMonitor();
while (pmd.getShell() == null
|| (!pmd.getShell().isDisposed() && !monitor.isCanceled())) {
try {
Thread.sleep(250);
} catch (InterruptedException e) {
// Ignore
}
// TODO: make this runnable a Lambda expression in a way that does not
// raise java.lang.SecurityException even on RAP/RWT.
Runnable run = new Runnable() {
@Override
public void run() {
IProgressMonitor monitor = pmd.getProgressMonitor();
while (pmd.getShell() == null
|| (!pmd.getShell().isDisposed() && !monitor.isCanceled())) {
try {
Thread.sleep(250);
} catch (InterruptedException e) {
// Ignore
}
}

if (monitor.isCanceled()) { // Disconnect and see what happens!
if (monitor.isCanceled()) { // Disconnect and see what happens!

try {
pipelineMeta.cancelQueries();
} catch (Exception e) {
// Ignore
}
try {
pipelineMeta.cancelQueries();
} catch (Exception e) {
// Ignore
}
};
}
}
};
// Dump the cancel looker in the background!
new Thread(run).start();

Expand Down
51 changes: 32 additions & 19 deletions ui/src/main/java/org/apache/hop/ui/hopgui/shared/SwtGc.java
Expand Up @@ -35,6 +35,7 @@
import org.apache.hop.pipeline.transform.TransformMeta;
import org.apache.hop.ui.core.PropsUi;
import org.apache.hop.ui.core.gui.GuiResource;
import org.apache.hop.ui.util.EnvironmentUtils;
import org.apache.hop.workflow.action.ActionMeta;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
Expand Down Expand Up @@ -361,25 +362,37 @@ public void setForeground( EColor color ) {
}

public void setLineStyle( ELineStyle lineStyle ) {
switch ( lineStyle ) {
case DASHDOT:
gc.setLineStyle( SWT.LINE_DASHDOT );
break;
case SOLID:
gc.setLineStyle( SWT.LINE_SOLID );
break;
case DOT:
gc.setLineStyle( SWT.LINE_DOT );
break;
case DASH:
gc.setLineStyle( SWT.LINE_DASH );
break;
case PARALLEL:
gc.setLineAttributes( new LineAttributes(
gc.getLineWidth(), SWT.CAP_FLAT, SWT.JOIN_MITER, SWT.LINE_CUSTOM, new float[] { 5, 3, }, 0, 10 ) );
break;
default:
break;
// RAP does not implement LineStyle and LineAttributes
if (!EnvironmentUtils.getInstance().isWeb()) {
switch (lineStyle) {
case DASHDOT:
gc.setLineStyle(SWT.LINE_DASHDOT);
break;
case SOLID:
gc.setLineStyle(SWT.LINE_SOLID);
break;
case DOT:
gc.setLineStyle(SWT.LINE_DOT);
break;
case DASH:
gc.setLineStyle(SWT.LINE_DASH);
break;
case PARALLEL:
gc.setLineAttributes(
new LineAttributes(
gc.getLineWidth(),
SWT.CAP_FLAT,
SWT.JOIN_MITER,
SWT.LINE_CUSTOM,
new float[] {
5, 3,
},
0,
10));
break;
default:
break;
}
}
}

Expand Down
17 changes: 10 additions & 7 deletions ui/src/main/java/org/apache/hop/ui/util/SwtSvgImageUtil.java
Expand Up @@ -79,13 +79,16 @@ public class SwtSvgImageUtil {
*/
public static SwtUniversalImage getMissingImage( Display display ) {
Image img = new Image( display, ConstUi.ICON_SIZE, ConstUi.ICON_SIZE );
GC gc = new GC( img );
gc.setForeground( new Color( display, 0, 0, 0 ) );
gc.drawRectangle( 4, 4, ConstUi.ICON_SIZE - 8, ConstUi.ICON_SIZE - 8 );
gc.setForeground( new Color( display, 255, 0, 0 ) );
gc.drawLine( 4, 4, ConstUi.ICON_SIZE - 4, ConstUi.ICON_SIZE - 4 );
gc.drawLine( ConstUi.ICON_SIZE - 4, 4, 4, ConstUi.ICON_SIZE - 4 );
gc.dispose();
// RAP only allows painting on the Canvas widget
if (!EnvironmentUtils.getInstance().isWeb()) {
GC gc = new GC(img);
gc.setForeground(new Color(display, 0, 0, 0));
gc.drawRectangle(4, 4, ConstUi.ICON_SIZE - 8, ConstUi.ICON_SIZE - 8);
gc.setForeground(new Color(display, 255, 0, 0));
gc.drawLine(4, 4, ConstUi.ICON_SIZE - 4, ConstUi.ICON_SIZE - 4);
gc.drawLine(ConstUi.ICON_SIZE - 4, 4, 4, ConstUi.ICON_SIZE - 4);
gc.dispose();
}
return new SwtUniversalImageBitmap( img, zoomFactor );
}

Expand Down

0 comments on commit 4ddbf62

Please sign in to comment.