Skip to content

Commit

Permalink
Merge pull request apache#4446 from nadment/4444
Browse files Browse the repository at this point in the history
Fix layout for Detect language transform apache#4444
  • Loading branch information
hansva authored Oct 18, 2024
2 parents a6580f4 + bf0dda9 commit 0c2454f
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 73 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
|===

Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -69,46 +66,49 @@ 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
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);
fdlTransformName.top = new FormAttachment(0, margin);
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);
Expand All @@ -118,20 +118,20 @@ 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);
fdlCorpusFieldName.top = new FormAttachment(wTransformName, margin);
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() {
Expand Down Expand Up @@ -167,21 +167,15 @@ 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);
wOk.setText(getString(PKG, "System.Button.OK"));
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DetectLanguage, DetectLanguageData> {
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() {
Expand All @@ -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,
Expand All @@ -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<ICheckResult> remarks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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



0 comments on commit 0c2454f

Please sign in to comment.