From bf0dda9572f272caa08f1ad5bba9e1658c579e6e Mon Sep 17 00:00:00 2001
From: Nicolas Adment <39568358+nadment@users.noreply.github.com>
Date: Thu, 17 Oct 2024 21:44:26 +0200
Subject: [PATCH] Fix layout for Detect language transform #4444 Adapt dialog
constructor method Add support for MDI Add basic documentation
---
.../transforms/icons/detectlanguage.svg | 13 +++++
.../ROOT/pages/pipeline/transforms.adoc | 1 +
.../pipeline/transforms/detectlanguage.adoc | 49 +++++++++++++++++
.../language/DetectLanguageDialog.java | 52 ++++++++-----------
.../language/DetectLanguageMeta.java | 40 +++++---------
.../messages/messages_en_US.properties | 22 ++------
6 files changed, 104 insertions(+), 73 deletions(-)
create mode 100644 docs/hop-user-manual/modules/ROOT/assets/images/transforms/icons/detectlanguage.svg
create mode 100644 docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms/detectlanguage.adoc
diff --git a/docs/hop-user-manual/modules/ROOT/assets/images/transforms/icons/detectlanguage.svg b/docs/hop-user-manual/modules/ROOT/assets/images/transforms/icons/detectlanguage.svg
new file mode 100644
index 00000000000..d0c02c65f6e
--- /dev/null
+++ b/docs/hop-user-manual/modules/ROOT/assets/images/transforms/icons/detectlanguage.svg
@@ -0,0 +1,13 @@
+
diff --git a/docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms.adoc b/docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms.adoc
index 7f744f0958c..fb87a728484 100644
--- a/docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms.adoc
+++ b/docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms.adoc
@@ -74,6 +74,7 @@ The pages nested under this topic contain information on how to use the transfor
* xref:pipeline/transforms/delete.adoc[Delete]
* xref:pipeline/transforms/serialize-de-from-file.adoc[De-Serialize From File]
* xref:pipeline/transforms/detectemptystream.adoc[Detect Empty Stream]
+* xref:pipeline/transforms/detectlanguage.adoc[Detect Language]
* xref:pipeline/transforms/dimensionlookup.adoc[Dimension lookup/update]
* xref:pipeline/transforms/dummy.adoc[Dummy (do nothing)]
* xref:pipeline/transforms/dynamicsqlrow.adoc[Dynamic SQL row]
diff --git a/docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms/detectlanguage.adoc b/docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms/detectlanguage.adoc
new file mode 100644
index 00000000000..9c6b5d893bb
--- /dev/null
+++ b/docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms/detectlanguage.adoc
@@ -0,0 +1,49 @@
+////
+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.
+////
+:documentationPath: /pipeline/transforms/
+:language: en_US
+:description: The Detect Empty Stream transform outputs one single empty row of data if the input stream is empty (ie when input stream does not contain any row). The output row will have the same field layout as the input row, but all field values will be empty (null).
+
+= image:transforms/icons/detect.svg[Detect Language transform Icon, role="image-doc-icon"] Detect Language
+
+[%noheader,cols="3a,1a", role="table-no-borders" ]
+|===
+|
+== Description
+
+The Detect Language transform examine text to identify the language.
+
+|
+== Supported Engines
+[%noheader,cols="2,1a",frame=none, role="table-supported-engines"]
+!===
+!Hop Engine! image:check_mark.svg[Supported, 24]
+!Spark! image:question_mark.svg[Maybe Supported, 24]
+!Flink! image:question_mark.svg[Maybe Supported, 24]
+!Dataflow! image:question_mark.svg[Maybe Supported, 24]
+!===
+|===
+
+== Options
+
+[options="header"]
+|===
+|Option|Description
+|Transform name|Name of the transform.
+This name must be unique throughout the pipeline.
+|===
+
diff --git a/plugins/transforms/detectlanguage/src/main/java/org/apache/hop/pipeline/transforms/language/DetectLanguageDialog.java b/plugins/transforms/detectlanguage/src/main/java/org/apache/hop/pipeline/transforms/language/DetectLanguageDialog.java
index 0f2de0b9dd5..0f8248bb8c2 100644
--- a/plugins/transforms/detectlanguage/src/main/java/org/apache/hop/pipeline/transforms/language/DetectLanguageDialog.java
+++ b/plugins/transforms/detectlanguage/src/main/java/org/apache/hop/pipeline/transforms/language/DetectLanguageDialog.java
@@ -33,29 +33,26 @@
import static org.eclipse.swt.SWT.SINGLE;
import static org.eclipse.swt.SWT.Selection;
-import org.apache.hop.core.Const;
import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.row.IRowMeta;
import org.apache.hop.core.variables.IVariables;
import org.apache.hop.pipeline.PipelineMeta;
-import org.apache.hop.pipeline.transform.BaseTransformMeta;
import org.apache.hop.pipeline.transform.ITransformDialog;
import org.apache.hop.ui.core.PropsUi;
import org.apache.hop.ui.core.dialog.BaseDialog;
import org.apache.hop.ui.core.dialog.ErrorDialog;
import org.apache.hop.ui.pipeline.transform.BaseTransformDialog;
+import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
@@ -69,9 +66,12 @@ public class DetectLanguageDialog extends BaseTransformDialog implements ITransf
private final DetectLanguageMeta input;
public DetectLanguageDialog(
- Shell parent, IVariables variables, Object in, PipelineMeta pipelineMeta, String sname) {
- super(parent, variables, (BaseTransformMeta) in, pipelineMeta, sname);
- input = (DetectLanguageMeta) in;
+ Shell parent,
+ IVariables variables,
+ DetectLanguageMeta transformMeta,
+ PipelineMeta pipelineMeta) {
+ super(parent, variables, transformMeta, pipelineMeta);
+ input = transformMeta;
}
@Override
@@ -79,27 +79,27 @@ public String open() {
Shell parent = getParent();
shell = new Shell(parent, DIALOG_TRIM | RESIZE | MAX | MIN);
- props.setLook(shell);
+ PropsUi.setLook(shell);
setShellImage(shell, input);
- ModifyListener lsMod = e -> input.setChanged();
+ Listener lsMod = e -> input.setChanged();
changed = input.hasChanged();
FormLayout formLayout = new FormLayout();
- formLayout.marginWidth = Const.FORM_MARGIN;
- formLayout.marginHeight = Const.FORM_MARGIN;
+ formLayout.marginWidth = PropsUi.getFormMargin();
+ formLayout.marginHeight = PropsUi.getFormMargin();
shell.setLayout(formLayout);
shell.setText(getString(PKG, "DetectLanguageDialog.Shell.Title"));
- int middle = props.getMiddlePct();
- int margin = props.getMargin();
+ int middle = PropsUi.getInstance().getMiddlePct();
+ int margin = PropsUi.getMargin();
// TransformName line
wlTransformName = new Label(shell, RIGHT);
wlTransformName.setText(getString(PKG, "DetectLanguageDialog.TransformName.Label"));
- props.setLook(wlTransformName);
+ PropsUi.setLook(wlTransformName);
fdlTransformName = new FormData();
fdlTransformName.left = new FormAttachment(0, 0);
fdlTransformName.right = new FormAttachment(middle, -margin);
@@ -107,8 +107,8 @@ public String open() {
wlTransformName.setLayoutData(fdlTransformName);
wTransformName = new Text(shell, SINGLE | LEFT | BORDER);
wTransformName.setText(transformName);
- props.setLook(wTransformName);
- wTransformName.addModifyListener(lsMod);
+ PropsUi.setLook(wTransformName);
+ wTransformName.addListener(SWT.Modify, lsMod);
fdTransformName = new FormData();
fdTransformName.left = new FormAttachment(middle, 0);
fdTransformName.top = new FormAttachment(0, margin);
@@ -118,7 +118,7 @@ public String open() {
// CorpusFieldName field
Label wlCorpusFieldName = new Label(shell, RIGHT);
wlCorpusFieldName.setText(getString(PKG, "DetectLanguageDialog.CorpusFieldName.Label"));
- props.setLook(wlCorpusFieldName);
+ PropsUi.setLook(wlCorpusFieldName);
FormData fdlCorpusFieldName = new FormData();
fdlCorpusFieldName.left = new FormAttachment(0, 0);
fdlCorpusFieldName.right = new FormAttachment(middle, -margin);
@@ -126,12 +126,12 @@ public String open() {
wlCorpusFieldName.setLayoutData(fdlCorpusFieldName);
wCorpusFieldName = new CCombo(shell, BORDER | READ_ONLY);
- props.setLook(wCorpusFieldName);
- wCorpusFieldName.addModifyListener(lsMod);
+ PropsUi.setLook(wCorpusFieldName);
+ wCorpusFieldName.addListener(SWT.Modify, lsMod);
FormData fdCorpusFieldName = new FormData();
fdCorpusFieldName.left = new FormAttachment(middle, 0);
fdCorpusFieldName.top = new FormAttachment(wTransformName, margin);
- fdCorpusFieldName.right = new FormAttachment(100, -margin);
+ fdCorpusFieldName.right = new FormAttachment(100, 0);
wCorpusFieldName.setLayoutData(fdCorpusFieldName);
wCorpusFieldName.addFocusListener(
new FocusListener() {
@@ -167,13 +167,7 @@ public void focusGained(FocusEvent e) {
fdParallelism.top = new FormAttachment(wCorpusFieldName, margin * 2);
fdParallelism.right = new FormAttachment(100, 0);
wParallelism.setLayoutData(fdParallelism);
- wParallelism.addSelectionListener(
- new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- input.setChanged();
- }
- });
+ wParallelism.addListener(SWT.Selection, lsMod);
// THE BUTTONS
wOk = new Button(shell, PUSH);
@@ -181,7 +175,7 @@ public void widgetSelected(SelectionEvent e) {
wCancel = new Button(shell, PUSH);
wCancel.setText(getString(PKG, "System.Button.Cancel"));
- setButtonPositions(new Button[] {wOk, wCancel}, margin, wCorpusFieldName);
+ setButtonPositions(new Button[] {wOk, wCancel}, margin, null);
// Add listeners
wOk.addListener(Selection, e -> ok());
diff --git a/plugins/transforms/detectlanguage/src/main/java/org/apache/hop/pipeline/transforms/language/DetectLanguageMeta.java b/plugins/transforms/detectlanguage/src/main/java/org/apache/hop/pipeline/transforms/language/DetectLanguageMeta.java
index 0cf2347bc33..efb62eddbce 100644
--- a/plugins/transforms/detectlanguage/src/main/java/org/apache/hop/pipeline/transforms/language/DetectLanguageMeta.java
+++ b/plugins/transforms/detectlanguage/src/main/java/org/apache/hop/pipeline/transforms/language/DetectLanguageMeta.java
@@ -17,41 +17,47 @@
package org.apache.hop.pipeline.transforms.language;
-import static org.apache.commons.lang3.StringUtils.equalsIgnoreCase;
import static org.apache.hop.core.ICheckResult.TYPE_RESULT_ERROR;
import static org.apache.hop.core.ICheckResult.TYPE_RESULT_OK;
import static org.apache.hop.core.util.Utils.isEmpty;
-import static org.apache.hop.core.xml.XmlHandler.addTagValue;
-import static org.apache.hop.core.xml.XmlHandler.getTagValue;
import java.util.List;
import org.apache.hop.core.CheckResult;
import org.apache.hop.core.ICheckResult;
import org.apache.hop.core.annotations.Transform;
-import org.apache.hop.core.exception.HopXmlException;
import org.apache.hop.core.row.IRowMeta;
import org.apache.hop.core.row.IValueMeta;
import org.apache.hop.core.row.value.ValueMetaNumber;
import org.apache.hop.core.row.value.ValueMetaString;
import org.apache.hop.core.variables.IVariables;
import org.apache.hop.i18n.BaseMessages;
+import org.apache.hop.metadata.api.HopMetadataProperty;
import org.apache.hop.metadata.api.IHopMetadataProvider;
import org.apache.hop.pipeline.PipelineMeta;
import org.apache.hop.pipeline.transform.BaseTransformMeta;
import org.apache.hop.pipeline.transform.TransformMeta;
-import org.w3c.dom.Node;
@Transform(
id = "DetectLanguage",
image = "detectlanguage.svg",
- name = "i18n::BaseTransform.TypeLongDesc.DetectLanguage",
- description = "i18n::BaseTransform.TypeTooltipDesc.DetectLanguage",
+ name = "i18n::DetectLanguage.Name",
+ description = "i18n::DetectLanguage.Description",
categoryDescription = "i18n:org.apache.hop.pipeline.transform:BaseTransform.Category.Transform",
+ keywords = "i18n::DetectLanguage.Keyword",
documentationUrl = "/pipeline/transforms/detectlanguage.html")
public class DetectLanguageMeta extends BaseTransformMeta {
private static final Class> PKG = DetectLanguageMeta.class;
+ @HopMetadataProperty(
+ key = "corpusField",
+ injectionKey = "FIELD",
+ injectionKeyDescription = "DetectLanguage.Injection.CorpusField")
private String corpusField;
+
+ @HopMetadataProperty(
+ key = "parallelism",
+ injectionKey = "PARALLISM",
+ injectionKeyDescription = "DetectLanguage.Injection.Parallelism")
private boolean parallelism = false;
public DetectLanguageMeta() {
@@ -63,18 +69,6 @@ public void setDefault() {
parallelism = false;
}
- @Override
- public void loadXml(Node transformNode, IHopMetadataProvider metadataProvider)
- throws HopXmlException {
- try {
- corpusField = getTagValue(transformNode, "corpusField");
- parallelism = equalsIgnoreCase("Y", getTagValue(transformNode, "parallelism"));
- } catch (Exception e) {
- throw new HopXmlException(
- BaseMessages.getString(PKG, "DetectLanguageMeta.Exception.UnableToReadTransformMeta"), e);
- }
- }
-
@Override
public void getFields(
IRowMeta r,
@@ -101,14 +95,6 @@ private void valueMetaNumber(IRowMeta r, String name, String metaName) {
r.addValueMeta(sText);
}
- @Override
- public String getXml() {
- return " "
- + addTagValue("corpusField", corpusField)
- + " "
- + addTagValue("parallelism", parallelism);
- }
-
@Override
public void check(
List remarks,
diff --git a/plugins/transforms/detectlanguage/src/main/resources/org/apache/hop/pipeline/transforms/language/messages/messages_en_US.properties b/plugins/transforms/detectlanguage/src/main/resources/org/apache/hop/pipeline/transforms/language/messages/messages_en_US.properties
index b3101fc473a..af4078c8c20 100644
--- a/plugins/transforms/detectlanguage/src/main/resources/org/apache/hop/pipeline/transforms/language/messages/messages_en_US.properties
+++ b/plugins/transforms/detectlanguage/src/main/resources/org/apache/hop/pipeline/transforms/language/messages/messages_en_US.properties
@@ -16,38 +16,26 @@
#
DetectLanguage.ClassName=Detect Language
-BaseTransform.TypeLongDesc.DetectLanguage=Detect Language
-BaseTransform.TypeTooltipDesc.DetectLanguage=Examine text to identify the language.
+DetectLanguage.Name=Detect Language
+DetectLanguage.Description=Examine text to identify the language.
DetectLanguageDialog.Shell.Title=Detect Language
-
DetectLanguage.Error.CorpusFieldMissing=Corpus field is missing\!
-
DetectLanguage.Exception.CouldnotFindField=Couldn''t find field ''{0}'' in row\!
+DetectLanguage.Keyword=tongue
DetectLanguage.LineNumber=linenr {0}
DetectLanguage.ErrorInTransformRunning=Because of an error, this transform can''t continue\:
-
DetectLanguageDialog.TransformName.Label=Transform name
DetectLanguageDialog.CorpusFieldName.Label=Corpus text field
-
DetectLanguageDialog.FailedToGetFields.DialogTitle=Get fields failed
DetectLanguageDialog.FailedToGetFields.DialogMessage=Unable to get fields from previous transforms because of an error
-DetectLanguageMeta.Exception.UnableToReadTransformMeta=Unable to read transform information from XML
-
DetectLanguageMeta.CheckResult.CorpusFieldMissing=Corpus field is missing\!
DetectLanguageMeta.CheckResult.CorpusFieldOK=Corpus field was specified.
-
DetectLanguageMeta.CheckResult.NoInpuReceived=No input received from other transforms\!
-
+DetectLanguage.Injection.CorpusField=Corpus text field
+DetectLanguage.Injection.Parallelism=Parallelism
DetectLanguage.Log.UnexpectedError=Unexpected error in ''
-
-
DetectLanguage.Log.ErrorFindingField=Error finding field\:
DetectLanguageMeta.CheckResult.CouldNotReadFields=Couldn''t read fields from the previous transform.
DetectLanguageMeta.CheckResult.ReceivingInfoFromOtherTransforms=Transform is receiving info from other transforms.
-
DetectLanguageMeta.CheckResult.ErrorOccurred=An error occurred\:
-
DetectLanguageDialog.Parallelism.Label=Use Parallelism
-
-
-