From b39b1c26c0a8445daa62ba5fb77664c98f820ced Mon Sep 17 00:00:00 2001 From: Nicolas Adment <39568358+nadment@users.noreply.github.com> Date: Fri, 6 Dec 2024 11:00:59 +0100 Subject: [PATCH 1/2] Bump Eclipse Platform from 3.127.0 to 3.128.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b91157a415..cf4fd0ff22 100644 --- a/pom.xml +++ b/pom.xml @@ -145,7 +145,7 @@ ${target.jdk.version} 5.12.0 3.4 - 3.127.0 + 3.128.0 UTF-8 UTF-8 initialize From ee38ced9d07c088fcbe04d3b5715f1be5231350f Mon Sep 17 00:00:00 2001 From: Nicolas Adment <39568358+nadment@users.noreply.github.com> Date: Sat, 14 Dec 2024 18:14:59 +0100 Subject: [PATCH 2/2] Implement Undo/Redo for StyledText #4708 Fix Variable insertion #4591 If StyledText widget, position the variables list under the caret Fix StyledText "disabled" look with dark mode Add key CTRL+A for select all in TextComposite Use TextComposite in ActionEvalDialog Reduce code duplication --- .../actions/eval/ActionEvalDialog.java | 27 +- .../workflow/actions/sql/ActionSqlDialog.java | 2 +- .../sql/messages/messages_en_US.properties | 2 +- .../waitforsql/ActionWaitForSqlDialog.java | 2 +- .../UserDefinedJavaClassDialog.java | 2 +- .../javascript/ScriptValuesDialog.java | 3 +- .../transforms/ldapinput/LdapInputDialog.java | 5 +- .../transforms/sql/ExecSqlDialog.java | 2 +- .../tableinput/TableInputDialog.java | 2 +- .../writetolog/WriteToLogDialog.java | 2 +- .../core/widget/ControlSpaceKeyAdapter.java | 144 +++---- .../core/widget/JavaScriptStyledTextComp.java | 312 +------------- .../ui/core/widget/JavaStyledTextComp.java | 312 +------------- .../hop/ui/core/widget/SQLStyledTextComp.java | 313 +------------- .../ui/core/widget/ScriptStyledTextComp.java | 314 +------------- .../hop/ui/core/widget/StyledTextComp.java | 216 +++------- .../hop/ui/core/widget/StyledTextVar.java | 398 ++++++++++++++++++ .../hop/ui/core/widget/TextComposite.java | 287 ++++++++++++- .../widget/messages/messages_en_US.properties | 2 + 19 files changed, 878 insertions(+), 1469 deletions(-) create mode 100644 ui/src/main/java/org/apache/hop/ui/core/widget/StyledTextVar.java diff --git a/plugins/actions/eval/src/main/java/org/apache/hop/workflow/actions/eval/ActionEvalDialog.java b/plugins/actions/eval/src/main/java/org/apache/hop/workflow/actions/eval/ActionEvalDialog.java index 48a5ca1232..61bd3c3621 100644 --- a/plugins/actions/eval/src/main/java/org/apache/hop/workflow/actions/eval/ActionEvalDialog.java +++ b/plugins/actions/eval/src/main/java/org/apache/hop/workflow/actions/eval/ActionEvalDialog.java @@ -24,8 +24,11 @@ import org.apache.hop.ui.core.PropsUi; import org.apache.hop.ui.core.dialog.BaseDialog; import org.apache.hop.ui.core.dialog.MessageBox; +import org.apache.hop.ui.core.widget.JavaScriptStyledTextComp; import org.apache.hop.ui.core.widget.StyledTextComp; +import org.apache.hop.ui.core.widget.TextComposite; import org.apache.hop.ui.pipeline.transform.BaseTransformDialog; +import org.apache.hop.ui.util.EnvironmentUtils; import org.apache.hop.ui.workflow.action.ActionDialog; import org.apache.hop.ui.workflow.dialog.WorkflowDialog; import org.apache.hop.workflow.WorkflowMeta; @@ -52,7 +55,7 @@ public class ActionEvalDialog extends ActionDialog { private Text wName; - private StyledTextComp wScript; + private TextComposite wScript; private Label wlPosition; @@ -133,16 +136,30 @@ public IAction open() { fdlScript.left = new FormAttachment(0, 0); fdlScript.top = new FormAttachment(wName, margin); wlScript.setLayoutData(fdlScript); - wScript = - new StyledTextComp( - action, shell, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); + + if (EnvironmentUtils.getInstance().isWeb()) { + wScript = + new StyledTextComp( + action, + shell, + SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, + false); + } else { + wScript = + new JavaScriptStyledTextComp( + action, + shell, + SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, + false); + wScript.addLineStyleListener(); + } wScript.setText(BaseMessages.getString(PKG, "ActionEval.Script.Default")); PropsUi.setLook(wScript, Props.WIDGET_STYLE_FIXED); wScript.addModifyListener(lsMod); FormData fdScript = new FormData(); fdScript.left = new FormAttachment(0, 0); fdScript.top = new FormAttachment(wlScript, margin); - fdScript.right = new FormAttachment(100, -10); + fdScript.right = new FormAttachment(100, 0); fdScript.bottom = new FormAttachment(wlPosition, -margin); wScript.setLayoutData(fdScript); wScript.addModifyListener(arg0 -> setPosition()); diff --git a/plugins/actions/sql/src/main/java/org/apache/hop/workflow/actions/sql/ActionSqlDialog.java b/plugins/actions/sql/src/main/java/org/apache/hop/workflow/actions/sql/ActionSqlDialog.java index e708aad499..66621a1e06 100644 --- a/plugins/actions/sql/src/main/java/org/apache/hop/workflow/actions/sql/ActionSqlDialog.java +++ b/plugins/actions/sql/src/main/java/org/apache/hop/workflow/actions/sql/ActionSqlDialog.java @@ -289,7 +289,7 @@ public IAction open() { FormData fdSql = new FormData(); fdSql.left = new FormAttachment(0, 0); fdSql.top = new FormAttachment(wlSql, margin); - fdSql.right = new FormAttachment(100, -20); + fdSql.right = new FormAttachment(100, -margin); fdSql.bottom = new FormAttachment(wlPosition, -margin); wSql.setLayoutData(fdSql); wSql.addListener(SWT.Modify, e -> setPosition()); diff --git a/plugins/actions/sql/src/main/resources/org/apache/hop/workflow/actions/sql/messages/messages_en_US.properties b/plugins/actions/sql/src/main/resources/org/apache/hop/workflow/actions/sql/messages/messages_en_US.properties index d8d5befa54..f47cdcf0b3 100644 --- a/plugins/actions/sql/src/main/resources/org/apache/hop/workflow/actions/sql/messages/messages_en_US.properties +++ b/plugins/actions/sql/src/main/resources/org/apache/hop/workflow/actions/sql/messages/messages_en_US.properties @@ -35,7 +35,7 @@ ActionSQL.NoDatabaseConnection=No database connection is defined. ActionSQL.NoSQLFileSpecified=Please specify SQL filename\! ActionSQL.Position.Label=Line {0} Column {1} ActionSQL.Script.Label=SQL Script\: -ActionSQL.SendOneStatement.Label=Send SQL as single statement? +ActionSQL.SendOneStatement.Label=Send SQL as single statement ActionSQL.SendOneStatement.Tooltip=Consider SQL as one running statement\nOtherwise ';' will be taken as statement end. ActionSQL.SQLFileExists=SQL file [{0}] exists ActionSQL.SQLFileNotExist=We can not find file [{0}]\! diff --git a/plugins/actions/waitforsql/src/main/java/org/apache/hop/workflow/actions/waitforsql/ActionWaitForSqlDialog.java b/plugins/actions/waitforsql/src/main/java/org/apache/hop/workflow/actions/waitforsql/ActionWaitForSqlDialog.java index 0894d40704..233b27a63a 100644 --- a/plugins/actions/waitforsql/src/main/java/org/apache/hop/workflow/actions/waitforsql/ActionWaitForSqlDialog.java +++ b/plugins/actions/waitforsql/src/main/java/org/apache/hop/workflow/actions/waitforsql/ActionWaitForSqlDialog.java @@ -539,7 +539,7 @@ public void widgetSelected(SelectionEvent e) { FormData fdSql = new FormData(); fdSql.left = new FormAttachment(0, 0); fdSql.top = new FormAttachment(wbSqlTable, margin); - fdSql.right = new FormAttachment(100, -10); + fdSql.right = new FormAttachment(100, 0); fdSql.bottom = new FormAttachment(wlPosition, -margin); wSql.setLayoutData(fdSql); diff --git a/plugins/transforms/janino/src/main/java/org/apache/hop/pipeline/transforms/userdefinedjavaclass/UserDefinedJavaClassDialog.java b/plugins/transforms/janino/src/main/java/org/apache/hop/pipeline/transforms/userdefinedjavaclass/UserDefinedJavaClassDialog.java index 7f2d438c61..716b9e8132 100644 --- a/plugins/transforms/janino/src/main/java/org/apache/hop/pipeline/transforms/userdefinedjavaclass/UserDefinedJavaClassDialog.java +++ b/plugins/transforms/janino/src/main/java/org/apache/hop/pipeline/transforms/userdefinedjavaclass/UserDefinedJavaClassDialog.java @@ -1626,7 +1626,7 @@ private void treeDblClick(Event event) { if (item.getParentItem().equals(wTreeClassesItem)) { setActiveCtab(item.getText()); } else if (!item.getData().equals("Snippit")) { - int iStart = wScript.getCaretOffset(); + int iStart = wScript.getCaretPosition(); int selCount = wScript.getSelectionCount(); // this selection // will be replaced // by wScript.insert diff --git a/plugins/transforms/javascript/src/main/java/org/apache/hop/pipeline/transforms/javascript/ScriptValuesDialog.java b/plugins/transforms/javascript/src/main/java/org/apache/hop/pipeline/transforms/javascript/ScriptValuesDialog.java index 3cde0bc493..6afa34cdf3 100644 --- a/plugins/transforms/javascript/src/main/java/org/apache/hop/pipeline/transforms/javascript/ScriptValuesDialog.java +++ b/plugins/transforms/javascript/src/main/java/org/apache/hop/pipeline/transforms/javascript/ScriptValuesDialog.java @@ -1596,8 +1596,7 @@ private void treeDblClick(Event event) { if (item.getParentItem().equals(wTreeScriptsItem)) { setActiveCtab(item.getText()); } else if (!item.getData().equals(CONST_FUNCTION)) { - // int iStart = wScript.getTextWidget().getCaretOffset(); - int iStart = wScript.getCaretOffset(); + int iStart = wScript.getCaretPosition(); int selCount = wScript.getSelectionCount(); // this selection will be replaced by wScript.insert iStart = diff --git a/plugins/transforms/ldap/src/main/java/org/apache/hop/pipeline/transforms/ldapinput/LdapInputDialog.java b/plugins/transforms/ldap/src/main/java/org/apache/hop/pipeline/transforms/ldapinput/LdapInputDialog.java index 25752259fa..57e021f24c 100644 --- a/plugins/transforms/ldap/src/main/java/org/apache/hop/pipeline/transforms/ldapinput/LdapInputDialog.java +++ b/plugins/transforms/ldap/src/main/java/org/apache/hop/pipeline/transforms/ldapinput/LdapInputDialog.java @@ -40,7 +40,6 @@ import org.apache.hop.ui.core.gui.GuiResource; import org.apache.hop.ui.core.widget.ColumnInfo; import org.apache.hop.ui.core.widget.ComboVar; -import org.apache.hop.ui.core.widget.ControlSpaceKeyAdapter; import org.apache.hop.ui.core.widget.PasswordTextVar; import org.apache.hop.ui.core.widget.StyledTextComp; import org.apache.hop.ui.core.widget.TableView; @@ -744,7 +743,8 @@ public void focusGained(org.eclipse.swt.events.FocusEvent e) { new StyledTextComp( variables, wSearchGroup, - SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); + SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, + true); wFilterString.setToolTipText( BaseMessages.getString(PKG, "LdapInputDialog.FilterString.Tooltip")); PropsUi.setLook(wFilterString); @@ -755,7 +755,6 @@ public void focusGained(org.eclipse.swt.events.FocusEvent e) { fdFilterString.right = new FormAttachment(100, -2 * margin); fdFilterString.bottom = new FormAttachment(100, -margin); wFilterString.setLayoutData(fdFilterString); - wFilterString.addKeyListener(new ControlSpaceKeyAdapter(variables, wFilterString)); FormData fdSearchGroup = new FormData(); fdSearchGroup.left = new FormAttachment(0, margin); diff --git a/plugins/transforms/sql/src/main/java/org/apache/hop/pipeline/transforms/sql/ExecSqlDialog.java b/plugins/transforms/sql/src/main/java/org/apache/hop/pipeline/transforms/sql/ExecSqlDialog.java index 6cd5675927..9b283954ae 100644 --- a/plugins/transforms/sql/src/main/java/org/apache/hop/pipeline/transforms/sql/ExecSqlDialog.java +++ b/plugins/transforms/sql/src/main/java/org/apache/hop/pipeline/transforms/sql/ExecSqlDialog.java @@ -267,7 +267,7 @@ public void mouseUp(MouseEvent e) { FormData fdlReadField = new FormData(); fdlReadField.left = new FormAttachment(middle, margin); fdlReadField.right = new FormAttachment(middle * 2, -margin); - fdlReadField.bottom = new FormAttachment(wOk, -3 * margin); + fdlReadField.bottom = new FormAttachment(wOk, -margin); wlReadField.setLayoutData(fdlReadField); wReadField = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); PropsUi.setLook(wReadField); diff --git a/plugins/transforms/tableinput/src/main/java/org/apache/hop/pipeline/transforms/tableinput/TableInputDialog.java b/plugins/transforms/tableinput/src/main/java/org/apache/hop/pipeline/transforms/tableinput/TableInputDialog.java index d2d1276b88..d4d7852b49 100644 --- a/plugins/transforms/tableinput/src/main/java/org/apache/hop/pipeline/transforms/tableinput/TableInputDialog.java +++ b/plugins/transforms/tableinput/src/main/java/org/apache/hop/pipeline/transforms/tableinput/TableInputDialog.java @@ -284,7 +284,7 @@ public void widgetSelected(SelectionEvent arg0) { FormData fdSql = new FormData(); fdSql.left = new FormAttachment(0, 0); fdSql.top = new FormAttachment(wbTable, margin); - fdSql.right = new FormAttachment(100, -2 * margin); + fdSql.right = new FormAttachment(100, -margin); fdSql.bottom = new FormAttachment(wlPosition, -margin); wSql.setLayoutData(fdSql); wSql.addModifyListener( diff --git a/plugins/transforms/writetolog/src/main/java/org/apache/hop/pipeline/transforms/writetolog/WriteToLogDialog.java b/plugins/transforms/writetolog/src/main/java/org/apache/hop/pipeline/transforms/writetolog/WriteToLogDialog.java index 5277fb7a1f..7707593957 100644 --- a/plugins/transforms/writetolog/src/main/java/org/apache/hop/pipeline/transforms/writetolog/WriteToLogDialog.java +++ b/plugins/transforms/writetolog/src/main/java/org/apache/hop/pipeline/transforms/writetolog/WriteToLogDialog.java @@ -210,7 +210,7 @@ public String open() { FormData fdLogMessage = new FormData(); fdLogMessage.left = new FormAttachment(middle, 0); fdLogMessage.top = new FormAttachment(wLimitRowsNumber, margin); - fdLogMessage.right = new FormAttachment(100, -2 * margin); + fdLogMessage.right = new FormAttachment(100, -margin); fdLogMessage.height = (int) (125 * props.getZoomFactor()); wLogMessage.setLayoutData(fdLogMessage); wLogMessage.addListener(SWT.Modify, lsModify); diff --git a/ui/src/main/java/org/apache/hop/ui/core/widget/ControlSpaceKeyAdapter.java b/ui/src/main/java/org/apache/hop/ui/core/widget/ControlSpaceKeyAdapter.java index 816b73ce61..e91e57f74e 100644 --- a/ui/src/main/java/org/apache/hop/ui/core/widget/ControlSpaceKeyAdapter.java +++ b/ui/src/main/java/org/apache/hop/ui/core/widget/ControlSpaceKeyAdapter.java @@ -36,12 +36,9 @@ import org.apache.hop.ui.core.gui.GuiResource; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.FocusAdapter; -import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.events.KeyAdapter; import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FormLayout; @@ -55,8 +52,6 @@ public class ControlSpaceKeyAdapter extends KeyAdapter { private static final Class PKG = ControlSpaceKeyAdapter.class; - private static final PropsUi props = PropsUi.getInstance(); - private final IGetCaretPosition getCaretPositionInterface; private final IInsertText insertTextInterface; @@ -95,31 +90,31 @@ public ControlSpaceKeyAdapter( * in chinese window, Ctrl-SPACE is reversed by system for input chinese character. use * Ctrl-ALT-SPACE instead. * - * @param e the keyevent + * @param event the keyevent * @return true when ctrl-SPACE is pressed */ - private boolean isHotKey(KeyEvent e) { + private boolean isHotKey(KeyEvent event) { if (System.getProperty("user.language").equals("zh")) { - return e.character == ' ' - && ((e.stateMask & SWT.CONTROL) != 0) - && ((e.stateMask & SWT.ALT) != 0); + return event.character == ' ' + && ((event.stateMask & SWT.CONTROL) != 0) + && ((event.stateMask & SWT.ALT) != 0); } else if (OsHelper.isMac()) { // character is empty when pressing special key in macOs - return e.keyCode == 32 - && ((e.stateMask & SWT.CONTROL) != 0) - && ((e.stateMask & SWT.ALT) == 0); + return event.keyCode == 32 + && ((event.stateMask & SWT.CONTROL) != 0) + && ((event.stateMask & SWT.ALT) == 0); } else { - return e.character == ' ' - && ((e.stateMask & SWT.CONTROL) != 0) - && ((e.stateMask & SWT.ALT) == 0); + return event.character == ' ' + && ((event.stateMask & SWT.CONTROL) != 0) + && ((event.stateMask & SWT.ALT) == 0); } } @Override - public void keyPressed(KeyEvent e) { + public void keyPressed(KeyEvent event) { // CTRL- --> Insert a variable - if (isHotKey(e)) { - e.doit = false; + if (isHotKey(event)) { + event.doit = false; // textField.setData(TRUE) indicates we have transitioned from the textbox to list mode... // This will be set to false when the list selection has been processed @@ -136,11 +131,21 @@ public void keyPressed(KeyEvent e) { // Drop down a list of variables... // Rectangle bounds = control.getBounds(); - Point location = GuiResource.calculateControlPosition(control); + Point location; + if (control instanceof StyledText styledText) { + // Position the list under the caret + location = styledText.getLocationAtOffset(styledText.getCaretOffset()); + location.y += styledText.getLineHeight(); + location = styledText.toDisplay(location); + } else { + // Position the list under the control + location = GuiResource.calculateControlPosition(control); + location.y += bounds.height; + } final Shell shell = new Shell(control.getShell(), SWT.NONE); shell.setSize(bounds.width > 300 ? bounds.width : 300, 200); - shell.setLocation(location.x, location.y + bounds.height); + shell.setLocation(location.x, location.y); shell.setLayout(new FormLayout()); final List list = new List(shell, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL); PropsUi.setLook(list); @@ -149,59 +154,50 @@ public void keyPressed(KeyEvent e) { final ToolTip toolTip = new ToolTip(list.getShell(), SWT.BALLOON); toolTip.setAutoHide(true); - list.addSelectionListener( - new SelectionAdapter() { - // Enter or double-click: picks the variable - // - @Override - public synchronized void widgetDefaultSelected(SelectionEvent e) { - applyChanges(shell, list, control, position, insertTextInterface); + // Double-click: picks the variable + list.addListener( + SWT.DefaultSelection, + e -> applyChanges(shell, list, control, position, insertTextInterface)); + + // Select a variable name: display the value in a tool tip + list.addListener( + SWT.Selection, + e -> { + if (list.getSelectionCount() <= 0) { + return; } - - // Select a variable name: display the value in a tool tip - // - @Override - public void widgetSelected(SelectionEvent event) { - if (list.getSelectionCount() <= 0) { - return; - } - String name = list.getSelection()[0]; - String value = variables.getVariable(name); - Rectangle shellBounds = shell.getBounds(); - String message = - BaseMessages.getString(PKG, "TextVar.VariableValue.Message", name, value); - if (name.startsWith(Const.INTERNAL_VARIABLE_PREFIX)) { - message += BaseMessages.getString(PKG, "TextVar.InternalVariable.Message"); - } - toolTip.setText(message); - toolTip.setVisible(false); - toolTip.setLocation( - shell.getLocation().x, shell.getLocation().y + shellBounds.height); - toolTip.setVisible(true); + String name = list.getSelection()[0]; + String value = variables.getVariable(name); + Rectangle shellBounds = shell.getBounds(); + String message = + BaseMessages.getString(PKG, "TextVar.VariableValue.Message", name, value); + if (name.startsWith(Const.INTERNAL_VARIABLE_PREFIX)) { + message += BaseMessages.getString(PKG, "TextVar.InternalVariable.Message"); } + toolTip.setText(message); + toolTip.setVisible(false); + toolTip.setLocation(shell.getLocation().x, shell.getLocation().y + shellBounds.height); + toolTip.setVisible(true); }); - list.addKeyListener( - new KeyAdapter() { - - @Override - public synchronized void keyPressed(KeyEvent e) { - if (e.keyCode == SWT.CR - && ((e.keyCode & SWT.CONTROL) == 0) - && ((e.keyCode & SWT.SHIFT) == 0)) { - applyChanges(shell, list, control, position, insertTextInterface); - } + // Enter key pressed: picks the variable + list.addListener( + SWT.KeyDown, + e -> { + if (e.keyCode == SWT.CR + && ((e.stateMask & SWT.CONTROL) == 0) + && ((e.stateMask & SWT.SHIFT) == 0)) { + applyChanges(shell, list, control, position, insertTextInterface); } }); - list.addFocusListener( - new FocusAdapter() { - @Override - public void focusLost(FocusEvent event) { - shell.dispose(); - if (!control.isDisposed()) { - control.setData(Boolean.FALSE); - } + // Focus lost: close the list + list.addListener( + SWT.FocusOut, + e -> { + shell.dispose(); + if (!control.isDisposed()) { + control.setData(Boolean.FALSE); } }); @@ -226,13 +222,13 @@ private static void applyChanges( if (list.getSelectionCount() <= 0) { return; } - if (control instanceof Text textControl) { - textControl.insert(extra); + if (control instanceof Text text) { + text.insert(extra); } else if (control instanceof CCombo combo) { - combo.setText( - extra); // We can't know the location of the cursor yet. All we can do is overwrite. - } else if (control instanceof StyledTextComp styledTextCompControl) { - styledTextCompControl.insert(extra); + // We can't know the location of the cursor yet. All we can do is overwrite. + combo.setText(extra); + } else if (control instanceof StyledText styledText) { + styledText.insert(extra); } } if (!shell.isDisposed()) { diff --git a/ui/src/main/java/org/apache/hop/ui/core/widget/JavaScriptStyledTextComp.java b/ui/src/main/java/org/apache/hop/ui/core/widget/JavaScriptStyledTextComp.java index c919b78060..61d50dd3d6 100644 --- a/ui/src/main/java/org/apache/hop/ui/core/widget/JavaScriptStyledTextComp.java +++ b/ui/src/main/java/org/apache/hop/ui/core/widget/JavaScriptStyledTextComp.java @@ -18,135 +18,29 @@ package org.apache.hop.ui.core.widget; import java.util.List; -import org.apache.commons.lang.StringUtils; import org.apache.hop.core.variables.IVariables; -import org.apache.hop.i18n.BaseMessages; -import org.apache.hop.ui.core.ConstUi; -import org.apache.hop.ui.core.FormDataBuilder; -import org.apache.hop.ui.core.PropsUi; -import org.apache.hop.ui.core.gui.GuiResource; import org.apache.hop.ui.core.widget.highlight.JavaScriptHighlight; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.LineStyleListener; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.dnd.Clipboard; -import org.eclipse.swt.dnd.TextTransfer; -import org.eclipse.swt.events.FocusAdapter; -import org.eclipse.swt.events.KeyAdapter; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.MouseAdapter; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; -public class JavaScriptStyledTextComp extends TextComposite { - private static final Class PKG = JavaScriptStyledTextComp.class; +public class JavaScriptStyledTextComp extends StyledTextVar { - // Modification for Undo/Redo on Styled Text - private final StyledText textWidget; - private final Menu styledTextPopupmenu; - private final Composite xParent; - private Image image; - - public JavaScriptStyledTextComp(IVariables variables, Composite parent, int args) { - this(variables, parent, args, true, false); + public JavaScriptStyledTextComp(IVariables variables, Composite parent, int style) { + this(variables, parent, style, true, false); } public JavaScriptStyledTextComp( - IVariables variables, Composite parent, int args, boolean varsSensitive) { - this(variables, parent, args, varsSensitive, false); + IVariables variables, Composite parent, int style, boolean varsSensitive) { + this(variables, parent, style, varsSensitive, false); } public JavaScriptStyledTextComp( IVariables variables, Composite parent, - int args, + int style, boolean varsSensitive, boolean variableIconOnTop) { - super(parent, SWT.NONE); - textWidget = new StyledText(this, args); - styledTextPopupmenu = new Menu(parent.getShell(), SWT.POP_UP); - xParent = parent; - this.setLayout(new FormLayout()); - - buildingStyledTextMenu(); - - // Default layout without variables - textWidget.setLayoutData( - new FormDataBuilder().top().left().right(100, 0).bottom(100, 0).result()); - - // Special layout for variables decorator - if (varsSensitive) { - textWidget.addKeyListener(new ControlSpaceKeyAdapter(variables, textWidget)); - image = GuiResource.getInstance().getImageVariableMini(); - if (variableIconOnTop) { - final Label wIcon = new Label(this, SWT.RIGHT); - PropsUi.setLook(wIcon); - wIcon.setToolTipText(BaseMessages.getString(PKG, "StyledTextComp.tooltip.InsertVariable")); - wIcon.setImage(image); - wIcon.setLayoutData(new FormDataBuilder().top().right(100, 0).result()); - textWidget.setLayoutData( - new FormDataBuilder() - .top(new FormAttachment(wIcon, 0, 0)) - .left() - .right(100, 0) - .bottom(100, 0) - .result()); - } else { - Label controlDecoration = new Label(this, SWT.NONE); - controlDecoration.setImage(image); - controlDecoration.setToolTipText( - BaseMessages.getString(PKG, "StyledTextComp.tooltip.InsertVariable")); - PropsUi.setLook(controlDecoration); - controlDecoration.setLayoutData(new FormDataBuilder().top().right(100, 0).result()); - textWidget.setLayoutData( - new FormDataBuilder() - .top() - .left() - .right(new FormAttachment(controlDecoration, 0, 0)) - .bottom(100, 0) - .result()); - } - } - } - - public String getSelectionText() { - return textWidget.getSelectionText(); - } - - @Override - public int getCaretOffset() { - return textWidget.getCaretOffset(); - } - - public String getText() { - return textWidget.getText(); - } - - public void setText(String text) { - textWidget.setText(text); - } - - public void insert(String strInsert) { - textWidget.insert(strInsert); - } - - @Override - public void addListener(int eventType, Listener listener) { - textWidget.addListener(eventType, listener); - } - - public void addModifyListener(ModifyListener lsMod) { - textWidget.addModifyListener(lsMod); + super(variables, parent, style, varsSensitive, variableIconOnTop); } @Override @@ -158,196 +52,4 @@ public void addLineStyleListener() { public void addLineStyleListener(List keywords) { addLineStyleListener(new JavaScriptHighlight()); } - - public void addLineStyleListener(LineStyleListener lineStyler) { - textWidget.addLineStyleListener(lineStyler); - } - - public void addKeyListener(KeyAdapter keyAdapter) { - textWidget.addKeyListener(keyAdapter); - } - - public void addFocusListener(FocusAdapter focusAdapter) { - textWidget.addFocusListener(focusAdapter); - } - - public void addMouseListener(MouseAdapter mouseAdapter) { - textWidget.addMouseListener(mouseAdapter); - } - - public int getSelectionCount() { - return textWidget.getSelectionCount(); - } - - public void setSelection(int arg0) { - textWidget.setSelection(arg0); - } - - public void setSelection(int arg0, int arg1) { - textWidget.setSelection(arg0, arg1); - } - - @Override - public void setBackground(Color color) { - super.setBackground(color); - textWidget.setBackground(color); - } - - @Override - public void setForeground(Color color) { - super.setForeground(color); - textWidget.setForeground(color); - } - - @Override - public void setFont(Font fnt) { - textWidget.setFont(fnt); - } - - private void buildingStyledTextMenu() { - - final MenuItem cutItem = new MenuItem(styledTextPopupmenu, SWT.PUSH); - cutItem.setText( - OsHelper.customizeMenuitemText(BaseMessages.getString(PKG, "WidgetDialog.Styled.Cut"))); - cutItem.setImage( - GuiResource.getInstance() - .getImage("ui/images/cut.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); - cutItem.addListener(SWT.Selection, e -> textWidget.cut()); - - final MenuItem copyItem = new MenuItem(styledTextPopupmenu, SWT.PUSH); - copyItem.setText( - OsHelper.customizeMenuitemText(BaseMessages.getString(PKG, "WidgetDialog.Styled.Copy"))); - copyItem.setImage( - GuiResource.getInstance() - .getImage("ui/images/copy.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); - copyItem.addListener(SWT.Selection, e -> textWidget.copy()); - - final MenuItem pasteItem = new MenuItem(styledTextPopupmenu, SWT.PUSH); - pasteItem.setText( - OsHelper.customizeMenuitemText(BaseMessages.getString(PKG, "WidgetDialog.Styled.Paste"))); - pasteItem.setImage( - GuiResource.getInstance() - .getImage("ui/images/paste.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); - pasteItem.addListener(SWT.Selection, e -> textWidget.paste()); - - new MenuItem(styledTextPopupmenu, SWT.SEPARATOR); - - MenuItem selectAllItem = new MenuItem(styledTextPopupmenu, SWT.PUSH); - selectAllItem.setText( - OsHelper.customizeMenuitemText( - BaseMessages.getString(PKG, "WidgetDialog.Styled.SelectAll"))); - selectAllItem.setImage( - GuiResource.getInstance() - .getImage( - "ui/images/select-all.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); - selectAllItem.addListener(SWT.Selection, e -> textWidget.selectAll()); - - textWidget.addMenuDetectListener( - e -> { - pasteItem.setEnabled(checkPaste()); - if (textWidget.getSelectionCount() > 0) { - cutItem.setEnabled(true); - copyItem.setEnabled(true); - } else { - cutItem.setEnabled(false); - copyItem.setEnabled(false); - } - }); - textWidget.setMenu(styledTextPopupmenu); - } - - // Check if something is stored inside the Clipboard - private boolean checkPaste() { - try { - Clipboard clipboard = new Clipboard(xParent.getDisplay()); - TextTransfer transfer = TextTransfer.getInstance(); - String text = (String) clipboard.getContents(transfer); - if (text != null && text.length() > 0) { - return true; - } else { - return false; - } - } catch (Exception e) { - return false; - } - } - - public Image getImage() { - return image; - } - - public StyledText getTextWidget() { - return textWidget; - } - - public boolean isEditable() { - return textWidget.getEditable(); - } - - public void setEditable(boolean canEdit) { - textWidget.setEditable(canEdit); - } - - @Override - public void setEnabled(boolean enabled) { - textWidget.setEnabled(enabled); - if (Display.getDefault() != null) { - Color foreground = - Display.getDefault().getSystemColor(enabled ? SWT.COLOR_BLACK : SWT.COLOR_DARK_GRAY); - Color background = - Display.getDefault() - .getSystemColor(enabled ? SWT.COLOR_WHITE : SWT.COLOR_WIDGET_BACKGROUND); - GuiResource guiResource = GuiResource.getInstance(); - textWidget.setForeground( - guiResource.getColor(foreground.getRed(), foreground.getGreen(), foreground.getBlue())); - textWidget.setBackground( - guiResource.getColor(background.getRed(), background.getGreen(), background.getBlue())); - } - } - - /** - * @return The caret line number, starting from 1. - */ - public int getLineNumber() { - String text = textWidget.getText(); - if (StringUtils.isEmpty(text)) { - return 1; - } - - int rowNumber = 1; - int textPosition = textWidget.getCaretOffset(); - while (textPosition > 0) { - if (text.charAt(textPosition - 1) == '\n') { - rowNumber++; - } - textPosition--; - } - - return rowNumber; - } - - /** - * @return The caret column number, starting from 1. - */ - public int getColumnNumber() { - String text = textWidget.getText(); - if (StringUtils.isEmpty(text)) { - return 1; - } - - int columnNumber = 1; - int textPosition = textWidget.getCaretOffset(); - while (textPosition > 0 - && text.charAt(textPosition - 1) != '\n' - && text.charAt(textPosition - 1) != '\r') { - textPosition--; - columnNumber++; - } - - return columnNumber; - } - - public int getCaretPosition() { - return textWidget.getCaretOffset(); - } } diff --git a/ui/src/main/java/org/apache/hop/ui/core/widget/JavaStyledTextComp.java b/ui/src/main/java/org/apache/hop/ui/core/widget/JavaStyledTextComp.java index 23cd49da22..7f5d7c32a9 100644 --- a/ui/src/main/java/org/apache/hop/ui/core/widget/JavaStyledTextComp.java +++ b/ui/src/main/java/org/apache/hop/ui/core/widget/JavaStyledTextComp.java @@ -18,135 +18,29 @@ package org.apache.hop.ui.core.widget; import java.util.List; -import org.apache.commons.lang.StringUtils; import org.apache.hop.core.variables.IVariables; -import org.apache.hop.i18n.BaseMessages; -import org.apache.hop.ui.core.ConstUi; -import org.apache.hop.ui.core.FormDataBuilder; -import org.apache.hop.ui.core.PropsUi; -import org.apache.hop.ui.core.gui.GuiResource; import org.apache.hop.ui.core.widget.highlight.JavaHighlight; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.LineStyleListener; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.dnd.Clipboard; -import org.eclipse.swt.dnd.TextTransfer; -import org.eclipse.swt.events.FocusAdapter; -import org.eclipse.swt.events.KeyAdapter; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.MouseAdapter; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; -public class JavaStyledTextComp extends TextComposite { - private static final Class PKG = JavaStyledTextComp.class; +public class JavaStyledTextComp extends StyledTextVar { - // Modification for Undo/Redo on Styled Text - private final StyledText textWidget; - private final Menu styledTextPopupmenu; - private final Composite xParent; - private Image image; - - public JavaStyledTextComp(IVariables variables, Composite parent, int args) { - this(variables, parent, args, true, false); + public JavaStyledTextComp(IVariables variables, Composite parent, int style) { + this(variables, parent, style, true, false); } public JavaStyledTextComp( - IVariables variables, Composite parent, int args, boolean varsSensitive) { - this(variables, parent, args, varsSensitive, false); + IVariables variables, Composite parent, int style, boolean varsSensitive) { + this(variables, parent, style, varsSensitive, false); } public JavaStyledTextComp( IVariables variables, Composite parent, - int args, + int style, boolean varsSensitive, boolean variableIconOnTop) { - super(parent, SWT.NONE); - textWidget = new StyledText(this, args); - styledTextPopupmenu = new Menu(parent.getShell(), SWT.POP_UP); - xParent = parent; - this.setLayout(new FormLayout()); - - buildingStyledTextMenu(); - - // Default layout without variables - textWidget.setLayoutData( - new FormDataBuilder().top().left().right(100, 0).bottom(100, 0).result()); - - // Special layout for variables decorator - if (varsSensitive) { - textWidget.addKeyListener(new ControlSpaceKeyAdapter(variables, textWidget)); - image = GuiResource.getInstance().getImageVariableMini(); - if (variableIconOnTop) { - final Label wIcon = new Label(this, SWT.RIGHT); - PropsUi.setLook(wIcon); - wIcon.setToolTipText(BaseMessages.getString(PKG, "StyledTextComp.tooltip.InsertVariable")); - wIcon.setImage(image); - wIcon.setLayoutData(new FormDataBuilder().top().right(100, 0).result()); - textWidget.setLayoutData( - new FormDataBuilder() - .top(new FormAttachment(wIcon, 0, 0)) - .left() - .right(100, 0) - .bottom(100, 0) - .result()); - } else { - Label controlDecoration = new Label(this, SWT.NONE); - controlDecoration.setImage(image); - controlDecoration.setToolTipText( - BaseMessages.getString(PKG, "StyledTextComp.tooltip.InsertVariable")); - PropsUi.setLook(controlDecoration); - controlDecoration.setLayoutData(new FormDataBuilder().top().right(100, 0).result()); - textWidget.setLayoutData( - new FormDataBuilder() - .top() - .left() - .right(new FormAttachment(controlDecoration, 0, 0)) - .bottom(100, 0) - .result()); - } - } - } - - public String getSelectionText() { - return textWidget.getSelectionText(); - } - - @Override - public int getCaretOffset() { - return textWidget.getCaretOffset(); - } - - public String getText() { - return textWidget.getText(); - } - - public void setText(String text) { - textWidget.setText(text); - } - - public void insert(String strInsert) { - textWidget.insert(strInsert); - } - - @Override - public void addListener(int eventType, Listener listener) { - textWidget.addListener(eventType, listener); - } - - public void addModifyListener(ModifyListener lsMod) { - textWidget.addModifyListener(lsMod); + super(variables, parent, style, varsSensitive, variableIconOnTop); } @Override @@ -158,196 +52,4 @@ public void addLineStyleListener() { public void addLineStyleListener(List keywords) { // No listener required } - - public void addLineStyleListener(LineStyleListener lineStyler) { - textWidget.addLineStyleListener(lineStyler); - } - - public void addKeyListener(KeyAdapter keyAdapter) { - textWidget.addKeyListener(keyAdapter); - } - - public void addFocusListener(FocusAdapter focusAdapter) { - textWidget.addFocusListener(focusAdapter); - } - - public void addMouseListener(MouseAdapter mouseAdapter) { - textWidget.addMouseListener(mouseAdapter); - } - - public int getSelectionCount() { - return textWidget.getSelectionCount(); - } - - public void setSelection(int arg0) { - textWidget.setSelection(arg0); - } - - public void setSelection(int arg0, int arg1) { - textWidget.setSelection(arg0, arg1); - } - - @Override - public void setBackground(Color color) { - super.setBackground(color); - textWidget.setBackground(color); - } - - @Override - public void setForeground(Color color) { - super.setForeground(color); - textWidget.setForeground(color); - } - - @Override - public void setFont(Font fnt) { - textWidget.setFont(fnt); - } - - private void buildingStyledTextMenu() { - - final MenuItem cutItem = new MenuItem(styledTextPopupmenu, SWT.PUSH); - cutItem.setText( - OsHelper.customizeMenuitemText(BaseMessages.getString(PKG, "WidgetDialog.Styled.Cut"))); - cutItem.setImage( - GuiResource.getInstance() - .getImage("ui/images/cut.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); - cutItem.addListener(SWT.Selection, e -> textWidget.cut()); - - final MenuItem copyItem = new MenuItem(styledTextPopupmenu, SWT.PUSH); - copyItem.setText( - OsHelper.customizeMenuitemText(BaseMessages.getString(PKG, "WidgetDialog.Styled.Copy"))); - copyItem.setImage( - GuiResource.getInstance() - .getImage("ui/images/copy.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); - copyItem.addListener(SWT.Selection, e -> textWidget.copy()); - - final MenuItem pasteItem = new MenuItem(styledTextPopupmenu, SWT.PUSH); - pasteItem.setText( - OsHelper.customizeMenuitemText(BaseMessages.getString(PKG, "WidgetDialog.Styled.Paste"))); - pasteItem.setImage( - GuiResource.getInstance() - .getImage("ui/images/paste.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); - pasteItem.addListener(SWT.Selection, e -> textWidget.paste()); - - new MenuItem(styledTextPopupmenu, SWT.SEPARATOR); - - MenuItem selectAllItem = new MenuItem(styledTextPopupmenu, SWT.PUSH); - selectAllItem.setText( - OsHelper.customizeMenuitemText( - BaseMessages.getString(PKG, "WidgetDialog.Styled.SelectAll"))); - selectAllItem.setImage( - GuiResource.getInstance() - .getImage( - "ui/images/select-all.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); - selectAllItem.addListener(SWT.Selection, e -> textWidget.selectAll()); - - textWidget.addMenuDetectListener( - e -> { - pasteItem.setEnabled(checkPaste()); - if (textWidget.getSelectionCount() > 0) { - cutItem.setEnabled(true); - copyItem.setEnabled(true); - } else { - cutItem.setEnabled(false); - copyItem.setEnabled(false); - } - }); - textWidget.setMenu(styledTextPopupmenu); - } - - // Check if something is stored inside the Clipboard - private boolean checkPaste() { - try { - Clipboard clipboard = new Clipboard(xParent.getDisplay()); - TextTransfer transfer = TextTransfer.getInstance(); - String text = (String) clipboard.getContents(transfer); - if (text != null && text.length() > 0) { - return true; - } else { - return false; - } - } catch (Exception e) { - return false; - } - } - - public Image getImage() { - return image; - } - - public StyledText getTextWidget() { - return textWidget; - } - - public boolean isEditable() { - return textWidget.getEditable(); - } - - public void setEditable(boolean canEdit) { - textWidget.setEditable(canEdit); - } - - @Override - public void setEnabled(boolean enabled) { - textWidget.setEnabled(enabled); - if (Display.getDefault() != null) { - Color foreground = - Display.getDefault().getSystemColor(enabled ? SWT.COLOR_BLACK : SWT.COLOR_DARK_GRAY); - Color background = - Display.getDefault() - .getSystemColor(enabled ? SWT.COLOR_WHITE : SWT.COLOR_WIDGET_BACKGROUND); - GuiResource guiResource = GuiResource.getInstance(); - textWidget.setForeground( - guiResource.getColor(foreground.getRed(), foreground.getGreen(), foreground.getBlue())); - textWidget.setBackground( - guiResource.getColor(background.getRed(), background.getGreen(), background.getBlue())); - } - } - - /** - * @return The caret line number, starting from 1. - */ - public int getLineNumber() { - String text = textWidget.getText(); - if (StringUtils.isEmpty(text)) { - return 1; - } - - int rowNumber = 1; - int textPosition = textWidget.getCaretOffset(); - while (textPosition > 0) { - if (text.charAt(textPosition - 1) == '\n') { - rowNumber++; - } - textPosition--; - } - - return rowNumber; - } - - /** - * @return The caret column number, starting from 1. - */ - public int getColumnNumber() { - String text = textWidget.getText(); - if (StringUtils.isEmpty(text)) { - return 1; - } - - int columnNumber = 1; - int textPosition = textWidget.getCaretOffset(); - while (textPosition > 0 - && text.charAt(textPosition - 1) != '\n' - && text.charAt(textPosition - 1) != '\r') { - textPosition--; - columnNumber++; - } - - return columnNumber; - } - - public int getCaretPosition() { - return textWidget.getCaretOffset(); - } } diff --git a/ui/src/main/java/org/apache/hop/ui/core/widget/SQLStyledTextComp.java b/ui/src/main/java/org/apache/hop/ui/core/widget/SQLStyledTextComp.java index 6e076b2962..46a61f4b86 100644 --- a/ui/src/main/java/org/apache/hop/ui/core/widget/SQLStyledTextComp.java +++ b/ui/src/main/java/org/apache/hop/ui/core/widget/SQLStyledTextComp.java @@ -18,135 +18,28 @@ package org.apache.hop.ui.core.widget; import java.util.List; -import org.apache.commons.lang.StringUtils; import org.apache.hop.core.variables.IVariables; -import org.apache.hop.i18n.BaseMessages; -import org.apache.hop.ui.core.ConstUi; -import org.apache.hop.ui.core.FormDataBuilder; -import org.apache.hop.ui.core.PropsUi; -import org.apache.hop.ui.core.gui.GuiResource; import org.apache.hop.ui.core.widget.highlight.SQLValuesHighlight; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.LineStyleListener; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.dnd.Clipboard; -import org.eclipse.swt.dnd.TextTransfer; -import org.eclipse.swt.events.FocusAdapter; -import org.eclipse.swt.events.KeyAdapter; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.MouseAdapter; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; -public class SQLStyledTextComp extends TextComposite { - private static final Class PKG = SQLStyledTextComp.class; - - // Modification for Undo/Redo on Styled Text - private final StyledText textWidget; - private final Menu styledTextPopupmenu; - private final Composite xParent; - private Image image; - - public SQLStyledTextComp(IVariables variables, Composite parent, int args) { - this(variables, parent, args, true, false); +public class SQLStyledTextComp extends StyledTextVar { + public SQLStyledTextComp(IVariables variables, Composite parent, int style) { + this(variables, parent, style, true, false); } public SQLStyledTextComp( - IVariables variables, Composite parent, int args, boolean varsSensitive) { - this(variables, parent, args, varsSensitive, false); + IVariables variables, Composite parent, int style, boolean varsSensitive) { + this(variables, parent, style, varsSensitive, false); } public SQLStyledTextComp( IVariables variables, Composite parent, - int args, + int style, boolean varsSensitive, boolean variableIconOnTop) { - super(parent, SWT.NONE); - textWidget = new StyledText(this, args); - styledTextPopupmenu = new Menu(parent.getShell(), SWT.POP_UP); - xParent = parent; - this.setLayout(new FormLayout()); - - buildingStyledTextMenu(); - - // Default layout without variables - textWidget.setLayoutData( - new FormDataBuilder().top().left().right(100, 0).bottom(100, 0).result()); - - // Special layout for variables decorator - if (varsSensitive) { - textWidget.addKeyListener(new ControlSpaceKeyAdapter(variables, textWidget)); - image = GuiResource.getInstance().getImageVariableMini(); - if (variableIconOnTop) { - final Label wIcon = new Label(this, SWT.RIGHT); - PropsUi.setLook(wIcon); - wIcon.setToolTipText(BaseMessages.getString(PKG, "StyledTextComp.tooltip.InsertVariable")); - wIcon.setImage(image); - wIcon.setLayoutData(new FormDataBuilder().top().right(100, 0).result()); - textWidget.setLayoutData( - new FormDataBuilder() - .top(new FormAttachment(wIcon, 0, 0)) - .left() - .right(100, 0) - .bottom(100, 0) - .result()); - } else { - Label controlDecoration = new Label(this, SWT.NONE); - controlDecoration.setImage(image); - controlDecoration.setToolTipText( - BaseMessages.getString(PKG, "StyledTextComp.tooltip.InsertVariable")); - PropsUi.setLook(controlDecoration); - controlDecoration.setLayoutData(new FormDataBuilder().top().right(100, 0).result()); - textWidget.setLayoutData( - new FormDataBuilder() - .top() - .left() - .right(new FormAttachment(controlDecoration, 0, 0)) - .bottom(100, 0) - .result()); - } - } - } - - public String getSelectionText() { - return textWidget.getSelectionText(); - } - - @Override - public int getCaretOffset() { - return textWidget.getCaretOffset(); - } - - public String getText() { - return textWidget.getText(); - } - - public void setText(String text) { - textWidget.setText(text); - } - - public void insert(String strInsert) { - textWidget.insert(strInsert); - } - - @Override - public void addListener(int eventType, Listener listener) { - textWidget.addListener(eventType, listener); - } - - public void addModifyListener(ModifyListener lsMod) { - textWidget.addModifyListener(lsMod); + super(variables, parent, style, varsSensitive, variableIconOnTop); } @Override @@ -158,196 +51,4 @@ public void addLineStyleListener() { public void addLineStyleListener(List keywords) { addLineStyleListener(new SQLValuesHighlight(keywords)); } - - public void addKeyListener(KeyAdapter keyAdapter) { - textWidget.addKeyListener(keyAdapter); - } - - public void addFocusListener(FocusAdapter focusAdapter) { - textWidget.addFocusListener(focusAdapter); - } - - public void addMouseListener(MouseAdapter mouseAdapter) { - textWidget.addMouseListener(mouseAdapter); - } - - public int getSelectionCount() { - return textWidget.getSelectionCount(); - } - - public void setSelection(int arg0) { - textWidget.setSelection(arg0); - } - - public void setSelection(int arg0, int arg1) { - textWidget.setSelection(arg0, arg1); - } - - @Override - public void setBackground(Color color) { - super.setBackground(color); - textWidget.setBackground(color); - } - - @Override - public void setForeground(Color color) { - super.setForeground(color); - textWidget.setForeground(color); - } - - @Override - public void setFont(Font fnt) { - textWidget.setFont(fnt); - } - - private void buildingStyledTextMenu() { - - final MenuItem cutItem = new MenuItem(styledTextPopupmenu, SWT.PUSH); - cutItem.setText( - OsHelper.customizeMenuitemText(BaseMessages.getString(PKG, "WidgetDialog.Styled.Cut"))); - cutItem.setImage( - GuiResource.getInstance() - .getImage("ui/images/cut.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); - cutItem.addListener(SWT.Selection, e -> textWidget.cut()); - - final MenuItem copyItem = new MenuItem(styledTextPopupmenu, SWT.PUSH); - copyItem.setText( - OsHelper.customizeMenuitemText(BaseMessages.getString(PKG, "WidgetDialog.Styled.Copy"))); - copyItem.setImage( - GuiResource.getInstance() - .getImage("ui/images/copy.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); - copyItem.addListener(SWT.Selection, e -> textWidget.copy()); - - final MenuItem pasteItem = new MenuItem(styledTextPopupmenu, SWT.PUSH); - pasteItem.setText( - OsHelper.customizeMenuitemText(BaseMessages.getString(PKG, "WidgetDialog.Styled.Paste"))); - pasteItem.setImage( - GuiResource.getInstance() - .getImage("ui/images/paste.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); - pasteItem.addListener(SWT.Selection, e -> textWidget.paste()); - - new MenuItem(styledTextPopupmenu, SWT.SEPARATOR); - - MenuItem selectAllItem = new MenuItem(styledTextPopupmenu, SWT.PUSH); - selectAllItem.setText( - OsHelper.customizeMenuitemText( - BaseMessages.getString(PKG, "WidgetDialog.Styled.SelectAll"))); - selectAllItem.setImage( - GuiResource.getInstance() - .getImage( - "ui/images/select-all.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); - selectAllItem.addListener(SWT.Selection, e -> textWidget.selectAll()); - - textWidget.addMenuDetectListener( - e -> { - pasteItem.setEnabled(checkPaste()); - if (textWidget.getSelectionCount() > 0) { - cutItem.setEnabled(true); - copyItem.setEnabled(true); - } else { - cutItem.setEnabled(false); - copyItem.setEnabled(false); - } - }); - textWidget.setMenu(styledTextPopupmenu); - } - - // Check if something is stored inside the Clipboard - private boolean checkPaste() { - try { - Clipboard clipboard = new Clipboard(xParent.getDisplay()); - TextTransfer transfer = TextTransfer.getInstance(); - String text = (String) clipboard.getContents(transfer); - if (text != null && text.length() > 0) { - return true; - } else { - return false; - } - } catch (Exception e) { - return false; - } - } - - public Image getImage() { - return image; - } - - public StyledText getTextWidget() { - return textWidget; - } - - public boolean isEditable() { - return textWidget.getEditable(); - } - - public void setEditable(boolean canEdit) { - textWidget.setEditable(canEdit); - } - - @Override - public void setEnabled(boolean enabled) { - textWidget.setEnabled(enabled); - if (Display.getDefault() != null) { - Color foreground = - Display.getDefault().getSystemColor(enabled ? SWT.COLOR_BLACK : SWT.COLOR_DARK_GRAY); - Color background = - Display.getDefault() - .getSystemColor(enabled ? SWT.COLOR_WHITE : SWT.COLOR_WIDGET_BACKGROUND); - GuiResource guiResource = GuiResource.getInstance(); - textWidget.setForeground( - guiResource.getColor(foreground.getRed(), foreground.getGreen(), foreground.getBlue())); - textWidget.setBackground( - guiResource.getColor(background.getRed(), background.getGreen(), background.getBlue())); - } - } - - /** - * @return The caret line number, starting from 1. - */ - public int getLineNumber() { - String text = textWidget.getText(); - if (StringUtils.isEmpty(text)) { - return 1; - } - - int rowNumber = 1; - int textPosition = textWidget.getCaretOffset(); - while (textPosition > 0) { - if (text.charAt(textPosition - 1) == '\n') { - rowNumber++; - } - textPosition--; - } - - return rowNumber; - } - - /** - * @return The caret column number, starting from 1. - */ - public int getColumnNumber() { - String text = textWidget.getText(); - if (StringUtils.isEmpty(text)) { - return 1; - } - - int columnNumber = 1; - int textPosition = textWidget.getCaretOffset(); - while (textPosition > 0 - && text.charAt(textPosition - 1) != '\n' - && text.charAt(textPosition - 1) != '\r') { - textPosition--; - columnNumber++; - } - - return columnNumber; - } - - public int getCaretPosition() { - return textWidget.getCaretOffset(); - } - - public void addLineStyleListener(LineStyleListener lineStyler) { - textWidget.addLineStyleListener(lineStyler); - } } diff --git a/ui/src/main/java/org/apache/hop/ui/core/widget/ScriptStyledTextComp.java b/ui/src/main/java/org/apache/hop/ui/core/widget/ScriptStyledTextComp.java index 55117cecf8..c02361904e 100644 --- a/ui/src/main/java/org/apache/hop/ui/core/widget/ScriptStyledTextComp.java +++ b/ui/src/main/java/org/apache/hop/ui/core/widget/ScriptStyledTextComp.java @@ -18,138 +18,32 @@ package org.apache.hop.ui.core.widget; import java.util.List; -import org.apache.commons.lang.StringUtils; import org.apache.hop.core.variables.IVariables; -import org.apache.hop.i18n.BaseMessages; -import org.apache.hop.ui.core.ConstUi; -import org.apache.hop.ui.core.FormDataBuilder; -import org.apache.hop.ui.core.PropsUi; -import org.apache.hop.ui.core.gui.GuiResource; import org.apache.hop.ui.core.widget.highlight.GenericCodeHighlight; import org.apache.hop.ui.core.widget.highlight.ScriptEngine; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.LineStyleListener; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.dnd.Clipboard; -import org.eclipse.swt.dnd.TextTransfer; -import org.eclipse.swt.events.FocusAdapter; -import org.eclipse.swt.events.KeyAdapter; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.MouseAdapter; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; -public class ScriptStyledTextComp extends TextComposite { - private static final Class PKG = ScriptStyledTextComp.class; - - // Modification for Undo/Redo on Styled Text - private final StyledText textWidget; - private final Menu styledTextPopupmenu; - private final Composite xParent; - private Image image; +public class ScriptStyledTextComp extends StyledTextVar { private ScriptEngine scriptEngine; - public ScriptStyledTextComp(IVariables variables, Composite parent, int args) { - this(variables, parent, args, true, false); + public ScriptStyledTextComp(IVariables variables, Composite parent, int style) { + this(variables, parent, style, true, false); } public ScriptStyledTextComp( - IVariables variables, Composite parent, int args, boolean varsSensitive) { - this(variables, parent, args, varsSensitive, false); + IVariables variables, Composite parent, int style, boolean varsSensitive) { + this(variables, parent, style, varsSensitive, false); } public ScriptStyledTextComp( IVariables variables, Composite parent, - int args, + int style, boolean varsSensitive, boolean variableIconOnTop) { - super(parent, SWT.NONE); - textWidget = new StyledText(this, args); - styledTextPopupmenu = new Menu(parent.getShell(), SWT.POP_UP); - xParent = parent; - this.setLayout(new FormLayout()); - - buildingStyledTextMenu(); - - // Default layout without variables - textWidget.setLayoutData( - new FormDataBuilder().top().left().right(100, 0).bottom(100, 0).result()); - - // Special layout for variables decorator - if (varsSensitive) { - textWidget.addKeyListener(new ControlSpaceKeyAdapter(variables, textWidget)); - image = GuiResource.getInstance().getImageVariableMini(); - if (variableIconOnTop) { - final Label wIcon = new Label(this, SWT.RIGHT); - PropsUi.setLook(wIcon); - wIcon.setToolTipText(BaseMessages.getString(PKG, "StyledTextComp.tooltip.InsertVariable")); - wIcon.setImage(image); - wIcon.setLayoutData(new FormDataBuilder().top().right(100, 0).result()); - textWidget.setLayoutData( - new FormDataBuilder() - .top(new FormAttachment(wIcon, 0, 0)) - .left() - .right(100, 0) - .bottom(100, 0) - .result()); - } else { - Label controlDecoration = new Label(this, SWT.NONE); - controlDecoration.setImage(image); - controlDecoration.setToolTipText( - BaseMessages.getString(PKG, "StyledTextComp.tooltip.InsertVariable")); - PropsUi.setLook(controlDecoration); - controlDecoration.setLayoutData(new FormDataBuilder().top().right(100, 0).result()); - textWidget.setLayoutData( - new FormDataBuilder() - .top() - .left() - .right(new FormAttachment(controlDecoration, 0, 0)) - .bottom(100, 0) - .result()); - } - } - } - - public String getSelectionText() { - return textWidget.getSelectionText(); - } - - @Override - public int getCaretOffset() { - return textWidget.getCaretOffset(); - } - - public String getText() { - return textWidget.getText(); - } - - public void setText(String text) { - textWidget.setText(text); - } - - public void insert(String strInsert) { - textWidget.insert(strInsert); - } - - @Override - public void addListener(int eventType, Listener listener) { - textWidget.addListener(eventType, listener); - } - - public void addModifyListener(ModifyListener lsMod) { - textWidget.addModifyListener(lsMod); + super(variables, parent, style, varsSensitive, variableIconOnTop); } @Override @@ -168,198 +62,6 @@ public void addLineStyleListener(String scriptEngine) { if (this.scriptEngine == null) { this.scriptEngine = ScriptEngine.GROOVY; } - textWidget.addLineStyleListener(new GenericCodeHighlight(this.scriptEngine)); - } - - public void addLineStyleListener(LineStyleListener lineStyler) { - textWidget.addLineStyleListener(lineStyler); - } - - public void addKeyListener(KeyAdapter keyAdapter) { - textWidget.addKeyListener(keyAdapter); - } - - public void addFocusListener(FocusAdapter focusAdapter) { - textWidget.addFocusListener(focusAdapter); - } - - public void addMouseListener(MouseAdapter mouseAdapter) { - textWidget.addMouseListener(mouseAdapter); - } - - public int getSelectionCount() { - return textWidget.getSelectionCount(); - } - - public void setSelection(int arg0) { - textWidget.setSelection(arg0); - } - - public void setSelection(int arg0, int arg1) { - textWidget.setSelection(arg0, arg1); - } - - @Override - public void setBackground(Color color) { - super.setBackground(color); - textWidget.setBackground(color); - } - - @Override - public void setForeground(Color color) { - super.setForeground(color); - textWidget.setForeground(color); - } - - @Override - public void setFont(Font fnt) { - textWidget.setFont(fnt); - } - - private void buildingStyledTextMenu() { - - final MenuItem cutItem = new MenuItem(styledTextPopupmenu, SWT.PUSH); - cutItem.setText( - OsHelper.customizeMenuitemText(BaseMessages.getString(PKG, "WidgetDialog.Styled.Cut"))); - cutItem.setImage( - GuiResource.getInstance() - .getImage("ui/images/cut.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); - cutItem.addListener(SWT.Selection, e -> textWidget.cut()); - - final MenuItem copyItem = new MenuItem(styledTextPopupmenu, SWT.PUSH); - copyItem.setText( - OsHelper.customizeMenuitemText(BaseMessages.getString(PKG, "WidgetDialog.Styled.Copy"))); - copyItem.setImage( - GuiResource.getInstance() - .getImage("ui/images/copy.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); - copyItem.addListener(SWT.Selection, e -> textWidget.copy()); - - final MenuItem pasteItem = new MenuItem(styledTextPopupmenu, SWT.PUSH); - pasteItem.setText( - OsHelper.customizeMenuitemText(BaseMessages.getString(PKG, "WidgetDialog.Styled.Paste"))); - pasteItem.setImage( - GuiResource.getInstance() - .getImage("ui/images/paste.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); - pasteItem.addListener(SWT.Selection, e -> textWidget.paste()); - - new MenuItem(styledTextPopupmenu, SWT.SEPARATOR); - - MenuItem selectAllItem = new MenuItem(styledTextPopupmenu, SWT.PUSH); - selectAllItem.setText( - OsHelper.customizeMenuitemText( - BaseMessages.getString(PKG, "WidgetDialog.Styled.SelectAll"))); - selectAllItem.setImage( - GuiResource.getInstance() - .getImage( - "ui/images/select-all.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); - selectAllItem.addListener(SWT.Selection, e -> textWidget.selectAll()); - - textWidget.addMenuDetectListener( - e -> { - pasteItem.setEnabled(checkPaste()); - if (textWidget.getSelectionCount() > 0) { - cutItem.setEnabled(true); - copyItem.setEnabled(true); - } else { - cutItem.setEnabled(false); - copyItem.setEnabled(false); - } - }); - textWidget.setMenu(styledTextPopupmenu); - } - - // Check if something is stored inside the Clipboard - private boolean checkPaste() { - try { - Clipboard clipboard = new Clipboard(xParent.getDisplay()); - TextTransfer transfer = TextTransfer.getInstance(); - String text = (String) clipboard.getContents(transfer); - if (text != null && text.length() > 0) { - return true; - } else { - return false; - } - } catch (Exception e) { - return false; - } - } - - public Image getImage() { - return image; - } - - public StyledText getTextWidget() { - return textWidget; - } - - public boolean isEditable() { - return textWidget.getEditable(); - } - - public void setEditable(boolean canEdit) { - textWidget.setEditable(canEdit); - } - - @Override - public void setEnabled(boolean enabled) { - textWidget.setEnabled(enabled); - if (Display.getDefault() != null) { - Color foreground = - Display.getDefault().getSystemColor(enabled ? SWT.COLOR_BLACK : SWT.COLOR_DARK_GRAY); - Color background = - Display.getDefault() - .getSystemColor(enabled ? SWT.COLOR_WHITE : SWT.COLOR_WIDGET_BACKGROUND); - GuiResource guiResource = GuiResource.getInstance(); - textWidget.setForeground( - guiResource.getColor(foreground.getRed(), foreground.getGreen(), foreground.getBlue())); - textWidget.setBackground( - guiResource.getColor(background.getRed(), background.getGreen(), background.getBlue())); - } - } - - /** - * @return The caret line number, starting from 1. - */ - public int getLineNumber() { - String text = textWidget.getText(); - if (StringUtils.isEmpty(text)) { - return 1; - } - - int rowNumber = 1; - int textPosition = textWidget.getCaretOffset(); - while (textPosition > 0) { - if (text.charAt(textPosition - 1) == '\n') { - rowNumber++; - } - textPosition--; - } - - return rowNumber; - } - - /** - * @return The caret column number, starting from 1. - */ - public int getColumnNumber() { - String text = textWidget.getText(); - if (StringUtils.isEmpty(text)) { - return 1; - } - - int columnNumber = 1; - int textPosition = textWidget.getCaretOffset(); - while (textPosition > 0 - && text.charAt(textPosition - 1) != '\n' - && text.charAt(textPosition - 1) != '\r') { - textPosition--; - columnNumber++; - } - - return columnNumber; - } - - public int getCaretPosition() { - return textWidget.getCaretOffset(); + addLineStyleListener(new GenericCodeHighlight(this.scriptEngine)); } } diff --git a/ui/src/main/java/org/apache/hop/ui/core/widget/StyledTextComp.java b/ui/src/main/java/org/apache/hop/ui/core/widget/StyledTextComp.java index f9bafd6afa..08f76e404c 100644 --- a/ui/src/main/java/org/apache/hop/ui/core/widget/StyledTextComp.java +++ b/ui/src/main/java/org/apache/hop/ui/core/widget/StyledTextComp.java @@ -18,48 +18,39 @@ package org.apache.hop.ui.core.widget; import java.util.List; -import org.apache.commons.lang.StringUtils; import org.apache.hop.core.variables.IVariables; import org.apache.hop.i18n.BaseMessages; -import org.apache.hop.ui.core.ConstUi; import org.apache.hop.ui.core.FormDataBuilder; import org.apache.hop.ui.core.PropsUi; import org.apache.hop.ui.core.gui.GuiResource; import org.eclipse.swt.SWT; -import org.eclipse.swt.dnd.Clipboard; -import org.eclipse.swt.dnd.TextTransfer; import org.eclipse.swt.events.FocusAdapter; import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.MenuDetectListener; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Text; public class StyledTextComp extends TextComposite { private static final Class PKG = StyledTextComp.class; - // Modification for Undo/Redo on Styled Text private final Text textWidget; - private final Menu styledTextPopupmenu; - private final Composite xParent; - private Image image; + private final Menu popupMenu; - public StyledTextComp(IVariables variables, Composite parent, int args) { - this(variables, parent, args, true, false); + public StyledTextComp(IVariables variables, Composite parent, int style) { + this(variables, parent, style, true, false); } - public StyledTextComp(IVariables variables, Composite parent, int args, boolean varsSensitive) { - this(variables, parent, args, varsSensitive, false); + public StyledTextComp(IVariables variables, Composite parent, int style, boolean varsSensitive) { + this(variables, parent, style, varsSensitive, false); } public StyledTextComp( @@ -71,11 +62,11 @@ public StyledTextComp( super(parent, SWT.NONE); textWidget = new Text(this, args); - styledTextPopupmenu = new Menu(parent.getShell(), SWT.POP_UP); - xParent = parent; + popupMenu = new Menu(parent.getShell(), SWT.POP_UP); + this.setLayout(new FormLayout()); - buildingStyledTextMenu(); + buildingStyledTextMenu(popupMenu); // Default layout without variables textWidget.setLayoutData( @@ -84,12 +75,12 @@ public StyledTextComp( // Special layout for variables decorator if (varsSensitive) { textWidget.addKeyListener(new ControlSpaceKeyAdapter(variables, textWidget)); - image = GuiResource.getInstance().getImageVariableMini(); + if (variableIconOnTop) { final Label wIcon = new Label(this, SWT.RIGHT); PropsUi.setLook(wIcon); wIcon.setToolTipText(BaseMessages.getString(PKG, "StyledTextComp.tooltip.InsertVariable")); - wIcon.setImage(image); + wIcon.setImage(GuiResource.getInstance().getImageVariableMini()); wIcon.setLayoutData(new FormDataBuilder().top().right(100, 0).result()); textWidget.setLayoutData( new FormDataBuilder() @@ -100,7 +91,7 @@ public StyledTextComp( .result()); } else { Label controlDecoration = new Label(this, SWT.NONE); - controlDecoration.setImage(image); + controlDecoration.setImage(GuiResource.getInstance().getImageVariableMini()); controlDecoration.setToolTipText( BaseMessages.getString(PKG, "StyledTextComp.tooltip.InsertVariable")); PropsUi.setLook(controlDecoration); @@ -116,23 +107,37 @@ public StyledTextComp( } } + @Override public String getSelectionText() { return textWidget.getSelectionText(); } @Override - public int getCaretOffset() { + public int getCaretPosition() { return textWidget.getCaretPosition(); } + @Override + public void setCaretPosition(int offset) { + // Does not exist in Text widget + } + + @Override + public int getCharCount() { + return textWidget.getCharCount(); + } + + @Override public String getText() { return textWidget.getText(); } + @Override public void setText(String text) { textWidget.setText(text); } + @Override public void insert(String strInsert) { textWidget.insert(strInsert); } @@ -142,6 +147,7 @@ public void addListener(int eventType, Listener listener) { textWidget.addListener(eventType, listener); } + @Override public void addModifyListener(ModifyListener lsMod) { textWidget.addModifyListener(lsMod); } @@ -168,16 +174,29 @@ public void addMouseListener(MouseAdapter mouseAdapter) { textWidget.addMouseListener(mouseAdapter); } + @Override + public void addMenuDetectListener(MenuDetectListener listener) { + textWidget.addMenuDetectListener(listener); + } + + @Override public int getSelectionCount() { return textWidget.getSelectionCount(); } - public void setSelection(int arg0) { - textWidget.setSelection(arg0); + @Override + public void setSelection(int start) { + textWidget.setSelection(start); + } + + @Override + public void setSelection(int start, int end) { + textWidget.setSelection(start, end); } - public void setSelection(int arg0, int arg1) { - textWidget.setSelection(arg0, arg1); + @Override + public boolean setFocus() { + return textWidget.setFocus(); } @Override @@ -197,150 +216,47 @@ public void setFont(Font fnt) { textWidget.setFont(fnt); } - private void buildingStyledTextMenu() { - - final MenuItem cutItem = new MenuItem(styledTextPopupmenu, SWT.PUSH); - cutItem.setText( - OsHelper.customizeMenuitemText(BaseMessages.getString(PKG, "WidgetDialog.Styled.Cut"))); - cutItem.setImage( - GuiResource.getInstance() - .getImage("ui/images/cut.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); - cutItem.addListener(SWT.Selection, e -> textWidget.cut()); - - final MenuItem copyItem = new MenuItem(styledTextPopupmenu, SWT.PUSH); - copyItem.setText( - OsHelper.customizeMenuitemText(BaseMessages.getString(PKG, "WidgetDialog.Styled.Copy"))); - copyItem.setImage( - GuiResource.getInstance() - .getImage("ui/images/copy.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); - copyItem.addListener(SWT.Selection, e -> textWidget.copy()); - - final MenuItem pasteItem = new MenuItem(styledTextPopupmenu, SWT.PUSH); - pasteItem.setText( - OsHelper.customizeMenuitemText(BaseMessages.getString(PKG, "WidgetDialog.Styled.Paste"))); - pasteItem.setImage( - GuiResource.getInstance() - .getImage("ui/images/paste.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); - pasteItem.addListener(SWT.Selection, e -> textWidget.paste()); - - new MenuItem(styledTextPopupmenu, SWT.SEPARATOR); - - MenuItem selectAllItem = new MenuItem(styledTextPopupmenu, SWT.PUSH); - selectAllItem.setText( - OsHelper.customizeMenuitemText( - BaseMessages.getString(PKG, "WidgetDialog.Styled.SelectAll"))); - selectAllItem.setImage( - GuiResource.getInstance() - .getImage( - "ui/images/select-all.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); - selectAllItem.addListener(SWT.Selection, e -> textWidget.selectAll()); - - textWidget.addMenuDetectListener( - e -> { - pasteItem.setEnabled(checkPaste()); - if (textWidget.getSelectionCount() > 0) { - cutItem.setEnabled(true); - copyItem.setEnabled(true); - } else { - cutItem.setEnabled(false); - copyItem.setEnabled(false); - } - }); - textWidget.setMenu(styledTextPopupmenu); - } - - // Check if something is stored inside the Clipboard - private boolean checkPaste() { - try { - Clipboard clipboard = new Clipboard(xParent.getDisplay()); - TextTransfer transfer = TextTransfer.getInstance(); - String text = (String) clipboard.getContents(transfer); - if (text != null && text.length() > 0) { - return true; - } else { - return false; - } - } catch (Exception e) { - return false; - } - } - - public Image getImage() { - return image; - } - public Text getTextWidget() { return textWidget; } + @Override public boolean isEditable() { return textWidget.getEditable(); } - public void setEditable(boolean canEdit) { - textWidget.setEditable(canEdit); + @Override + public void setEditable(boolean editable) { + textWidget.setEditable(editable); } @Override public void setEnabled(boolean enabled) { textWidget.setEnabled(enabled); - if (Display.getDefault() != null) { - Color foreground = - Display.getDefault().getSystemColor(enabled ? SWT.COLOR_BLACK : SWT.COLOR_DARK_GRAY); - Color background = - Display.getDefault() - .getSystemColor(enabled ? SWT.COLOR_WHITE : SWT.COLOR_WIDGET_BACKGROUND); - GuiResource guiResource = GuiResource.getInstance(); - textWidget.setForeground( - guiResource.getColor(foreground.getRed(), foreground.getGreen(), foreground.getBlue())); - textWidget.setBackground( - guiResource.getColor(background.getRed(), background.getGreen(), background.getBlue())); - } } - /** - * @return The caret line number, starting from 1. - */ - public int getLineNumber() { - String text = textWidget.getText(); - if (StringUtils.isEmpty(text)) { - return 1; - } - - int rowNumber = 1; - int textPosition = textWidget.getCaretPosition(); - while (textPosition > 0) { - if (text.charAt(textPosition - 1) == '\n') { - rowNumber++; - } - textPosition--; - } - - return rowNumber; + @Override + public void cut() { + textWidget.cut(); } - /** - * @return The caret column number, starting from 1. - */ - public int getColumnNumber() { - String text = textWidget.getText(); - if (StringUtils.isEmpty(text)) { - return 1; - } + @Override + public void copy() { + textWidget.copy(); + } - int columnNumber = 1; - int textPosition = textWidget.getCaretPosition(); - while (textPosition > 0 - && text.charAt(textPosition - 1) != '\n' - && text.charAt(textPosition - 1) != '\r') { - textPosition--; - columnNumber++; - } + @Override + public void paste() { + textWidget.paste(); + } - return columnNumber; + @Override + public void selectAll() { + textWidget.selectAll(); } - public int getCaretPosition() { - return textWidget.getCaretPosition(); + @Override + public void setMenu(Menu menu) { + textWidget.setMenu(menu); } } diff --git a/ui/src/main/java/org/apache/hop/ui/core/widget/StyledTextVar.java b/ui/src/main/java/org/apache/hop/ui/core/widget/StyledTextVar.java new file mode 100644 index 0000000000..fb956426c9 --- /dev/null +++ b/ui/src/main/java/org/apache/hop/ui/core/widget/StyledTextVar.java @@ -0,0 +1,398 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hop.ui.core.widget; + +import java.util.LinkedList; +import java.util.List; +import org.apache.hop.core.variables.IVariables; +import org.apache.hop.i18n.BaseMessages; +import org.apache.hop.ui.core.FormDataBuilder; +import org.apache.hop.ui.core.PropsUi; +import org.apache.hop.ui.core.gui.GuiResource; +import org.apache.hop.ui.core.widget.highlight.JavaHighlight; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ExtendedModifyEvent; +import org.eclipse.swt.custom.ExtendedModifyListener; +import org.eclipse.swt.custom.LineStyleListener; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.FocusAdapter; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.MenuDetectListener; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Menu; + +public class StyledTextVar extends TextComposite { + private static final Class PKG = StyledTextVar.class; + + // Modification for Undo/Redo on Styled Text + private static final int MAX_STACK_SIZE = 25; + + private final StyledText wText; + private final Menu wPopupMenu; + private List undoStack; + private List redoStack; + + private boolean fullSelection = false; + + public StyledTextVar(IVariables variables, Composite parent, int style) { + this(variables, parent, style, true, false); + } + + public StyledTextVar(IVariables variables, Composite parent, int style, boolean varsSensitive) { + this(variables, parent, style, varsSensitive, false); + } + + public StyledTextVar( + IVariables variables, + Composite parent, + int style, + boolean varsSensitive, + boolean variableIconOnTop) { + + super(parent, SWT.NONE); + + undoStack = new LinkedList(); + redoStack = new LinkedList(); + + wText = new StyledText(this, style); + wPopupMenu = new Menu(parent.getShell(), SWT.POP_UP); + this.setLayout(new FormLayout()); + + buildingStyledTextMenu(wPopupMenu); + + addUndoRedoSupport(); + + // Default layout without variables + wText.setLayoutData(new FormDataBuilder().top().left().right(100, 0).bottom(100, 0).result()); + + // Special layout for variables decorator + if (varsSensitive) { + wText.addKeyListener(new ControlSpaceKeyAdapter(variables, wText)); + if (variableIconOnTop) { + final Label wIcon = new Label(this, SWT.RIGHT); + PropsUi.setLook(wIcon); + wIcon.setToolTipText(BaseMessages.getString(PKG, "StyledTextComp.tooltip.InsertVariable")); + wIcon.setImage(GuiResource.getInstance().getImageVariableMini()); + wIcon.setLayoutData(new FormDataBuilder().top().right(100, 0).result()); + wText.setLayoutData( + new FormDataBuilder() + .top(new FormAttachment(wIcon, 0, 0)) + .left() + .right(100, 0) + .bottom(100, 0) + .result()); + } else { + Label controlDecoration = new Label(this, SWT.NONE); + controlDecoration.setImage(GuiResource.getInstance().getImageVariableMini()); + controlDecoration.setToolTipText( + BaseMessages.getString(PKG, "StyledTextComp.tooltip.InsertVariable")); + PropsUi.setLook(controlDecoration); + controlDecoration.setLayoutData(new FormDataBuilder().top().right(100, 0).result()); + wText.setLayoutData( + new FormDataBuilder() + .top() + .left() + .right(new FormAttachment(controlDecoration, 0, 0)) + .bottom(100, 0) + .result()); + } + } + } + + @Override + public String getSelectionText() { + return wText.getSelectionText(); + } + + @Override + public int getCaretPosition() { + return wText.getCaretOffset(); + } + + @Override + public void setCaretPosition(int offset) { + wText.setCaretOffset(offset); + } + + @Override + public int getCharCount() { + return wText.getCharCount(); + } + + @Override + public String getText() { + return wText.getText(); + } + + @Override + public void setText(String text) { + wText.setText(text); + } + + @Override + public void insert(String strInsert) { + wText.insert(strInsert); + } + + @Override + public void addListener(int eventType, Listener listener) { + wText.addListener(eventType, listener); + } + + public void addModifyListener(ModifyListener lsMod) { + wText.addModifyListener(lsMod); + } + + @Override + public void addLineStyleListener() { + addLineStyleListener(new JavaHighlight()); + } + + @Override + public void addLineStyleListener(List keywords) { + // No listener required + } + + public void addLineStyleListener(LineStyleListener lineStyler) { + wText.addLineStyleListener(lineStyler); + } + + public void addKeyListener(KeyAdapter keyAdapter) { + wText.addKeyListener(keyAdapter); + } + + public void addFocusListener(FocusAdapter focusAdapter) { + wText.addFocusListener(focusAdapter); + } + + public void addMouseListener(MouseAdapter mouseAdapter) { + wText.addMouseListener(mouseAdapter); + } + + @Override + public void addMenuDetectListener(MenuDetectListener listener) { + wText.addMenuDetectListener(listener); + } + + @Override + public int getSelectionCount() { + return wText.getSelectionCount(); + } + + @Override + public void setSelection(int start) { + wText.setSelection(start); + } + + @Override + public void setSelection(int start, int end) { + wText.setSelection(start, end); + } + + @Override + public void setBackground(Color color) { + super.setBackground(color); + wText.setBackground(color); + } + + @Override + public void setForeground(Color color) { + super.setForeground(color); + wText.setForeground(color); + } + + @Override + public void setFont(Font fnt) { + wText.setFont(fnt); + } + + public StyledText getTextWidget() { + return wText; + } + + @Override + public boolean isEditable() { + return wText.getEditable(); + } + + @Override + public void setEditable(boolean editable) { + wText.setEditable(editable); + } + + @Override + public void setEnabled(boolean enabled) { + wText.setEnabled(enabled); + // StyledText component does not get the "disabled" look, so it needs to be applied explicitly + if (Display.getDefault() != null) { + wText.setBackground( + enabled + ? GuiResource.getInstance().getColorWhite() + : GuiResource.getInstance().getColorBackground()); + } + } + + @Override + public void cut() { + wText.cut(); + } + + @Override + public void copy() { + wText.copy(); + } + + @Override + public void paste() { + wText.paste(); + } + + @Override + public void selectAll() { + wText.selectAll(); + } + + @Override + public void setMenu(Menu menu) { + wText.setMenu(menu); + } + + protected boolean isSupportUnoRedo() { + return true; + } + + // Add support functions for Undo/Redo on text widget + protected void addUndoRedoSupport() { + + wText.addListener( + SWT.Selection, + event -> { + if (getSelectionCount() == wText.getCharCount()) { + fullSelection = true; + } + }); + + wText.addExtendedModifyListener( + new ExtendedModifyListener() { + public void modifyText(ExtendedModifyEvent event) { + int eventLength = event.length; + int eventStartPostition = event.start; + + String newText = getText(); + String repText = event.replacedText; + String oldText = ""; + int eventType = -1; + + if ((event.length != newText.length()) || (fullSelection)) { + if (repText != null && repText.length() > 0) { + oldText = + newText.substring(0, event.start) + + repText + + newText.substring(event.start + event.length); + eventType = UndoRedoStack.DELETE; + eventLength = repText.length(); + } else { + oldText = + newText.substring(0, event.start) + + newText.substring(event.start + event.length); + eventType = UndoRedoStack.INSERT; + } + + if ((oldText != null && oldText.length() > 0) + || (eventStartPostition == event.length)) { + UndoRedoStack urs = + new UndoRedoStack( + eventStartPostition, newText, oldText, eventLength, eventType); + + // Stack is full + if (undoStack.size() == MAX_STACK_SIZE) { + undoStack.remove(undoStack.size() - 1); + } + undoStack.add(0, urs); + } + } + fullSelection = false; + } + }); + } + + protected void undo() { + if (undoStack.size() > 0) { + UndoRedoStack undo = undoStack.remove(0); + if (redoStack.size() == MAX_STACK_SIZE) { + redoStack.remove(redoStack.size() - 1); + } + UndoRedoStack redo = + new UndoRedoStack( + undo.getCursorPosition(), + undo.getReplacedText(), + getText(), + undo.getEventLength(), + undo.getType()); + fullSelection = false; + setText(undo.getReplacedText()); + if (undo.getType() == UndoRedoStack.INSERT) { + setCaretPosition(undo.getCursorPosition()); + } else if (undo.getType() == UndoRedoStack.DELETE) { + setCaretPosition(undo.getCursorPosition() + undo.getEventLength()); + setSelection(undo.getCursorPosition(), undo.getCursorPosition() + undo.getEventLength()); + if (getSelectionCount() == getCharCount()) { + fullSelection = true; + } + } + redoStack.add(0, redo); + } + } + + protected void redo() { + if (redoStack.size() > 0) { + UndoRedoStack redo = redoStack.remove(0); + if (undoStack.size() == MAX_STACK_SIZE) { + undoStack.remove(undoStack.size() - 1); + } + UndoRedoStack undo = + new UndoRedoStack( + redo.getCursorPosition(), + redo.getReplacedText(), + getText(), + redo.getEventLength(), + redo.getType()); + fullSelection = false; + setText(redo.getReplacedText()); + if (redo.getType() == UndoRedoStack.INSERT) { + setCaretPosition(redo.getCursorPosition()); + } else if (redo.getType() == UndoRedoStack.DELETE) { + setCaretPosition(redo.getCursorPosition() + redo.getEventLength()); + setSelection(redo.getCursorPosition(), redo.getCursorPosition() + redo.getEventLength()); + if (getSelectionCount() == getCharCount()) { + fullSelection = true; + } + } + undoStack.add(0, undo); + } + } +} diff --git a/ui/src/main/java/org/apache/hop/ui/core/widget/TextComposite.java b/ui/src/main/java/org/apache/hop/ui/core/widget/TextComposite.java index a7b7204957..eff5ea95da 100644 --- a/ui/src/main/java/org/apache/hop/ui/core/widget/TextComposite.java +++ b/ui/src/main/java/org/apache/hop/ui/core/widget/TextComposite.java @@ -18,10 +18,22 @@ package org.apache.hop.ui.core.widget; import java.util.List; +import org.apache.commons.lang.StringUtils; +import org.apache.hop.i18n.BaseMessages; +import org.apache.hop.ui.core.ConstUi; +import org.apache.hop.ui.core.gui.GuiResource; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.Clipboard; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.events.MenuDetectListener; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; public abstract class TextComposite extends Composite { + private static final Class PKG = StyledTextComp.class; + /** * Constructs a new instance of this class given its parent and a style value describing its * behavior and appearance. @@ -50,21 +62,284 @@ public void addLineStyleListener(String scriptEngine) { throw new UnsupportedOperationException("Cannot specify a script engine"); } - public abstract int getLineNumber(); + /** + * Adds the listener to the collection of listeners who will be notified when the + * platform-specific context menu trigger has occurred, by sending it one of the messages defined + * in the MenuDetectListener interface. + * + * @param listener the listener which should be notified + */ + public abstract void addMenuDetectListener(MenuDetectListener listener); + + /** Sets the receiver's pop up menu to the argument. */ + public abstract void setMenu(Menu menu); + + /** Cuts the selected text. */ + public abstract void cut(); + + /** Copies the selected text. */ + public abstract void copy(); + + /** Pastes text from clipboard. */ + public abstract void paste(); + + /** Selects all the text in the receiver. */ + public abstract void selectAll(); + + /** + * Returns the caret position relative to the start of the text. + * + *

Indexing is zero based. + * + * @return the caret position relative to the start of the text. + */ + public abstract int getCaretPosition(); + + /** + * Sets the caret position. + * + * @param position set caret offset, relative to the first character in the text. + */ + public abstract void setCaretPosition(int position); + + /** + * Gets the number of characters. + * + * @return number of characters in the widget + */ + public abstract int getCharCount(); + + /** + * @return The caret line number, starting from 1. + */ + public int getLineNumber() { + String text = getText(); + if (StringUtils.isEmpty(text)) { + return 1; + } + + int rowNumber = 1; + int textPosition = getCaretPosition(); + while (textPosition > 0) { + if (text.charAt(textPosition - 1) == '\n') { + rowNumber++; + } + textPosition--; + } + + return rowNumber; + } + + /** + * @return The caret column number, starting from 1. + */ + public int getColumnNumber() { + String text = getText(); + if (StringUtils.isEmpty(text)) { + return 1; + } - public abstract int getColumnNumber(); + int columnNumber = 1; + int textPosition = getCaretPosition(); + while (textPosition > 0 + && text.charAt(textPosition - 1) != '\n' + && text.charAt(textPosition - 1) != '\r') { + textPosition--; + columnNumber++; + } + + return columnNumber; + } + /** + * Returns the widget text. + * + *

The text for a text widget is the characters in the widget, or an empty string if this has + * never been set. + * + * @return the widget text + */ public abstract String getText(); + /** Sets the contents of the receiver to the given string. */ public abstract void setText(String text); - public abstract String getSelectionText(); + /** + * Returns the number of selected characters. + * + * @return the number of selected characters. + */ + public abstract int getSelectionCount(); - public abstract int getCaretOffset(); + /** Gets the selected text, or an empty string if there is no current selection. */ + public abstract String getSelectionText(); + /** + * Inserts a string. + * + *

The old selection is replaced with the new text. + * + * @param string the string + */ public abstract void insert(String strInsert); - public abstract void setSelection(int iStart, int length); + /** + * Sets the selection. + * + *

Indexing is zero based. The range of a selection is from 0..N where N is the number of + * characters in the widget. + * + * @param start new caret position + */ + public abstract void setSelection(int start); - public abstract int getSelectionCount(); + /** + * Sets the selection to the range specified by the given start and end indices. + * + *

Indexing is zero based. The range of a selection is from 0..N where N is the number of + * characters in the widget. + * + *

+ * + * @param start the start of the range + * @param end the end of the range + */ + public abstract void setSelection(int start, int end); + + /** + * Returns the editable state. + * + * @return whether or not the receiver is editable + */ + public abstract boolean isEditable(); + + /** + * Sets the editable state. + * + * @param editable the new editable state + */ + public abstract void setEditable(boolean editable); + + /** + * Check if something is stored inside the Clipboard. + * + * @return false if no text is available inside the Clipboard + */ + protected boolean checkPaste() { + try { + Clipboard clipboard = new Clipboard(getParent().getDisplay()); + String text = (String) clipboard.getContents(TextTransfer.getInstance()); + if (text != null && text.length() > 0) { + return true; + } else { + return false; + } + } catch (Exception e) { + return false; + } + } + + protected void undo() {} + + protected void redo() {} + + protected boolean isSupportUnoRedo() { + return false; + } + + protected void buildingStyledTextMenu(Menu popupMenu) { + + if (isSupportUnoRedo()) { + final MenuItem undoItem = new MenuItem(popupMenu, SWT.PUSH); + undoItem.setText( + OsHelper.customizeMenuitemText(BaseMessages.getString(PKG, "WidgetDialog.Styled.Undo"))); + undoItem.setImage( + GuiResource.getInstance() + .getImage("ui/images/undo.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); + undoItem.addListener(SWT.Selection, event -> undo()); + + final MenuItem redoItem = new MenuItem(popupMenu, SWT.PUSH); + redoItem.setText( + OsHelper.customizeMenuitemText(BaseMessages.getString(PKG, "WidgetDialog.Styled.Redo"))); + redoItem.setImage( + GuiResource.getInstance() + .getImage("ui/images/redo.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); + redoItem.addListener(SWT.Selection, event -> redo()); + + new MenuItem(popupMenu, SWT.SEPARATOR); + } + + final MenuItem cutItem = new MenuItem(popupMenu, SWT.PUSH); + cutItem.setText( + OsHelper.customizeMenuitemText(BaseMessages.getString(PKG, "WidgetDialog.Styled.Cut"))); + cutItem.setImage( + GuiResource.getInstance() + .getImage("ui/images/cut.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); + cutItem.addListener(SWT.Selection, event -> cut()); + + final MenuItem copyItem = new MenuItem(popupMenu, SWT.PUSH); + copyItem.setText( + OsHelper.customizeMenuitemText(BaseMessages.getString(PKG, "WidgetDialog.Styled.Copy"))); + copyItem.setImage( + GuiResource.getInstance() + .getImage("ui/images/copy.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); + copyItem.addListener(SWT.Selection, event -> copy()); + + final MenuItem pasteItem = new MenuItem(popupMenu, SWT.PUSH); + pasteItem.setText( + OsHelper.customizeMenuitemText(BaseMessages.getString(PKG, "WidgetDialog.Styled.Paste"))); + pasteItem.setImage( + GuiResource.getInstance() + .getImage("ui/images/paste.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); + pasteItem.addListener(SWT.Selection, event -> paste()); + + new MenuItem(popupMenu, SWT.SEPARATOR); + + final MenuItem selectAllItem = new MenuItem(popupMenu, SWT.PUSH); + selectAllItem.setText( + OsHelper.customizeMenuitemText( + BaseMessages.getString(PKG, "WidgetDialog.Styled.SelectAll"))); + selectAllItem.setImage( + GuiResource.getInstance() + .getImage( + "ui/images/select-all.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE)); + selectAllItem.addListener(SWT.Selection, event -> selectAll()); + + addListener( + SWT.KeyDown, + event -> { + if (isSupportUnoRedo() + && event.keyCode == 'z' + && (event.stateMask & SWT.MOD1) != 0 + && (event.stateMask & SWT.MOD2) != 0) { + redo(); + } else if (isSupportUnoRedo() + && event.keyCode == 'z' + && (event.stateMask & SWT.MOD1) != 0) { + undo(); + } else if (event.keyCode == 'a' && (event.stateMask & SWT.MOD1) != 0) { + selectAll(); + } else if (event.keyCode == 'f' && (event.stateMask & SWT.MOD1) != 0) { + // TODO: implement FIND + // find(); + } else if (event.keyCode == 'h' && (event.stateMask & SWT.MOD1) != 0) { + // TODO: implement FIND AND REPLACE + // findAndReplace(); + } + }); + + addMenuDetectListener( + event -> { + pasteItem.setEnabled(checkPaste()); + if (getSelectionCount() > 0) { + cutItem.setEnabled(true); + copyItem.setEnabled(true); + } else { + cutItem.setEnabled(false); + copyItem.setEnabled(false); + } + }); + + setMenu(popupMenu); + } } diff --git a/ui/src/main/resources/org/apache/hop/ui/core/widget/messages/messages_en_US.properties b/ui/src/main/resources/org/apache/hop/ui/core/widget/messages/messages_en_US.properties index ebd000af38..f85bda653d 100644 --- a/ui/src/main/resources/org/apache/hop/ui/core/widget/messages/messages_en_US.properties +++ b/ui/src/main/resources/org/apache/hop/ui/core/widget/messages/messages_en_US.properties @@ -93,4 +93,6 @@ TextVar.VariableValue.Message=The value of variable ''{0}'' is \: \n\n\t{1}\n\n WidgetDialog.Styled.Copy=Copy\tCtrl+C WidgetDialog.Styled.Cut=Cut\tCtrl+X WidgetDialog.Styled.Paste=Paste\tCtrl+V +WidgetDialog.Styled.Redo=Redo\tCtrl+Shift+Z WidgetDialog.Styled.SelectAll=Select &All\tCtrl+A +WidgetDialog.Styled.Undo=Undo\tCtrl+Z