Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.apache.hop.i18n.BaseMessages;
import org.apache.hop.pipeline.PipelineMeta;
import org.apache.hop.pipeline.transform.TransformMeta;
import org.apache.hop.ui.core.FormDataBuilder;
import org.apache.hop.ui.core.PropsUi;
import org.apache.hop.ui.core.dialog.BaseDialog;
import org.apache.hop.ui.core.dialog.ErrorDialog;
Expand All @@ -55,8 +56,6 @@
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
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.Composite;
Expand Down Expand Up @@ -156,19 +155,12 @@ public void widgetSelected(SelectionEvent arg0) {
Label wlUnspecified = new Label(wSelectComp, SWT.RIGHT);
wlUnspecified.setText(BaseMessages.getString(PKG, "SelectValuesDialog.Unspecified.Label"));
PropsUi.setLook(wlUnspecified);
FormData fdlUnspecified = new FormData();
fdlUnspecified.left = new FormAttachment(0, 0);
fdlUnspecified.right = new FormAttachment(middle, 0);
fdlUnspecified.bottom = new FormAttachment(100, 0);
wlUnspecified.setLayoutData(fdlUnspecified);
wlUnspecified.setLayoutData(FormDataBuilder.builder().left().bottom(100, 0).build());

wUnspecified = new Button(wSelectComp, SWT.CHECK);
PropsUi.setLook(wUnspecified);
FormData fdUnspecified = new FormData();
fdUnspecified.left = new FormAttachment(middle, margin);
fdUnspecified.right = new FormAttachment(100, 0);
fdUnspecified.bottom = new FormAttachment(wlUnspecified, 0, SWT.CENTER);
wUnspecified.setLayoutData(fdUnspecified);
wUnspecified.setLayoutData(
FormDataBuilder.builder().left(wlUnspecified, margin).bottom(100, 5).build());
wUnspecified.addSelectionListener(lsSel);
// Update combo boxes when "Include unspecified fields" checkbox is toggled
wUnspecified.addSelectionListener(
Expand All @@ -187,19 +179,16 @@ public void widgetSelected(SelectionEvent e) {
}
}
});
// Label: select & Alter. Button: Get fields to select
Label wlFields = new Label(wSelectComp, SWT.NONE);
wlFields.setText(BaseMessages.getString(PKG, "SelectValuesDialog.Fields.Label"));
PropsUi.setLook(wlFields);
wlFields.setLayoutData(FormDataBuilder.builder().top().left().build());

Button wGetSelect = new Button(wSelectComp, SWT.PUSH);
wGetSelect.setText(BaseMessages.getString(PKG, "SelectValuesDialog.GetSelect.Button"));
wGetSelect.addListener(SWT.Selection, e -> get());
setButtonPositions(new Button[] {wGetSelect}, margin, null);

Label wlFields = new Label(wSelectComp, SWT.NONE);
wlFields.setText(BaseMessages.getString(PKG, "SelectValuesDialog.Fields.Label"));
PropsUi.setLook(wlFields);
FormData fdlFields = new FormData();
fdlFields.left = new FormAttachment(0, 0);
fdlFields.top = new FormAttachment(0, 0);
wlFields.setLayoutData(fdlFields);
wGetSelect.setLayoutData(FormDataBuilder.builder().top().right().build());

final int fieldsCols = 4;
final int fieldsRows = input.getSelectOption().getSelectFields().size();
Expand Down Expand Up @@ -242,24 +231,15 @@ public void widgetSelected(SelectionEvent e) {
lsMod,
props);

FormData fdFields = new FormData();
fdFields.left = new FormAttachment(0, 0);
fdFields.top = new FormAttachment(wlFields, margin);
fdFields.right = new FormAttachment(100, 0);
fdFields.bottom = new FormAttachment(wlUnspecified, -margin);
wFields.setLayoutData(fdFields);

fdlUnspecified.bottom = new FormAttachment(wGetSelect, -margin);
wlUnspecified.setLayoutData(fdlUnspecified);
fdUnspecified.bottom = new FormAttachment(wGetSelect, -margin);
wUnspecified.setLayoutData(fdUnspecified);

FormData fdSelectComp = new FormData();
fdSelectComp.left = new FormAttachment(0, 0);
fdSelectComp.top = new FormAttachment(0, 0);
fdSelectComp.right = new FormAttachment(100, 0);
fdSelectComp.bottom = new FormAttachment(100, 0);
wSelectComp.setLayoutData(fdSelectComp);
wFields.setLayoutData(
FormDataBuilder.builder()
.top(wlFields, margin)
.left()
.right()
.bottom(wlUnspecified, -2 * margin)
.build());
wSelectComp.setLayoutData(
FormDataBuilder.builder().top().left().right().bottom(100, 0).build());

wSelectComp.layout();
wSelectTab.setControl(wSelectComp);
Expand All @@ -283,18 +263,15 @@ public void widgetSelected(SelectionEvent e) {
PropsUi.setLook(wRemoveComp);
wRemoveComp.setLayout(contentLayout);

Button wGetRemove = new Button(wRemoveComp, SWT.PUSH);
wGetRemove.setText(BaseMessages.getString(PKG, "SelectValuesDialog.GetRemove.Button"));
wGetRemove.addListener(SWT.Selection, e -> get());
setButtonPositions(new Button[] {wGetRemove}, margin, null);

Label wlRemove = new Label(wRemoveComp, SWT.NONE);
wlRemove.setText(BaseMessages.getString(PKG, "SelectValuesDialog.Remove.Label"));
PropsUi.setLook(wlRemove);
FormData fdlRemove = new FormData();
fdlRemove.left = new FormAttachment(0, 0);
fdlRemove.top = new FormAttachment(0, 0);
wlRemove.setLayoutData(fdlRemove);
wlRemove.setLayoutData(FormDataBuilder.builder().top().left().build());

Button wGetRemove = new Button(wRemoveComp, SWT.PUSH);
wGetRemove.setText(BaseMessages.getString(PKG, "SelectValuesDialog.GetRemove.Button"));
wGetRemove.addListener(SWT.Selection, e -> get());
wGetRemove.setLayoutData(FormDataBuilder.builder().top().right().build());

final int RemoveCols = 1;
final int RemoveRows = input.getSelectOption().getDeleteName().size();
Expand All @@ -319,20 +296,9 @@ public void widgetSelected(SelectionEvent e) {
RemoveRows,
lsMod,
props);

FormData fdRemove = new FormData();
fdRemove.left = new FormAttachment(0, 0);
fdRemove.top = new FormAttachment(wlRemove, margin);
fdRemove.right = new FormAttachment(100, 0);
fdRemove.bottom = new FormAttachment(wGetRemove, -margin);
wRemove.setLayoutData(fdRemove);

FormData fdRemoveComp = new FormData();
fdRemoveComp.left = new FormAttachment(0, 0);
fdRemoveComp.top = new FormAttachment(0, 0);
fdRemoveComp.right = new FormAttachment(100, 0);
fdRemoveComp.bottom = new FormAttachment(100, 0);
wRemoveComp.setLayoutData(fdRemoveComp);
wRemove.setLayoutData(
FormDataBuilder.builder().top(wlRemove, margin).left().right().bottom(100, 0).build());
wRemoveComp.setLayoutData(FormDataBuilder.builder().top().left().bottom(100, 0).build());

wRemoveComp.layout();
wRemoveTab.setControl(wRemoveComp);
Expand All @@ -357,18 +323,15 @@ public void widgetSelected(SelectionEvent e) {
metaLayout.marginHeight = margin;
wMetaComp.setLayout(metaLayout);

Button wGetMeta = new Button(wMetaComp, SWT.PUSH);
wGetMeta.setText(BaseMessages.getString(PKG, "SelectValuesDialog.GetMeta.Button"));
wGetMeta.addListener(SWT.Selection, e -> get());
setButtonPositions(new Button[] {wGetMeta}, margin, null);

Label wlMeta = new Label(wMetaComp, SWT.NONE);
wlMeta.setText(BaseMessages.getString(PKG, "SelectValuesDialog.Meta.Label"));
PropsUi.setLook(wlMeta);
FormData fdlMeta = new FormData();
fdlMeta.left = new FormAttachment(0, 0);
fdlMeta.top = new FormAttachment(0, 0);
wlMeta.setLayoutData(fdlMeta);
wlMeta.setLayoutData(FormDataBuilder.builder().top().left().build());

Button wGetMeta = new Button(wMetaComp, SWT.PUSH);
wGetMeta.setText(BaseMessages.getString(PKG, "SelectValuesDialog.GetMeta.Button"));
wGetMeta.addListener(SWT.Selection, e -> get());
wGetMeta.setLayoutData(FormDataBuilder.builder().top().right().build());

final int MetaRows = input.getSelectOption().getMeta().size();

Expand Down Expand Up @@ -450,7 +413,8 @@ public void widgetSelected(SelectionEvent e) {
colmeta[5].setToolTip(
BaseMessages.getString(PKG, "SelectValuesDialog.ColumnInfo.Storage.Tooltip"));
fieldColumns.add(colmeta[0]);
metaFieldColumns.add(colmeta[0]); // Metadata tab should show fields remaining after Remove
// Metadata tab should show fields remaining after Remove
metaFieldColumns.add(colmeta[0]);
wMeta =
new TableView(
variables,
Expand All @@ -461,33 +425,24 @@ public void widgetSelected(SelectionEvent e) {
lsMod,
props);

FormData fdMeta = new FormData();
fdMeta.left = new FormAttachment(0, 0);
fdMeta.top = new FormAttachment(wlMeta, margin);
fdMeta.right = new FormAttachment(100, 0);
fdMeta.bottom = new FormAttachment(wGetMeta, -margin);
wMeta.setLayoutData(fdMeta);

FormData fdMetaComp = new FormData();
fdMetaComp.left = new FormAttachment(0, 0);
fdMetaComp.top = new FormAttachment(0, 0);
fdMetaComp.right = new FormAttachment(100, 0);
fdMetaComp.bottom = new FormAttachment(100, 0);
wMetaComp.setLayoutData(fdMetaComp);
wMeta.setLayoutData(
FormDataBuilder.builder().top(wlMeta, margin).left().right().bottom(100, 0).build());
wMetaComp.setLayoutData(
FormDataBuilder.builder().top().left().right(100, 0).bottom(100, 0).build());

wMetaComp.layout();
wMetaTab.setControl(wMetaComp);

// ///////////////////////////////////////////////////////////
// / END OF META TAB
// ///////////////////////////////////////////////////////////

FormData fdTabFolder = new FormData();
fdTabFolder.left = new FormAttachment(0, 0);
fdTabFolder.top = new FormAttachment(wSpacer, margin);
fdTabFolder.right = new FormAttachment(100, 0);
fdTabFolder.bottom = new FormAttachment(wOk, -margin);
wTabFolder.setLayoutData(fdTabFolder);
wTabFolder.setLayoutData(
FormDataBuilder.builder()
.top(wTransformName, margin)
.left()
.right(100, 0)
.bottom(wOk, -2 * margin)
.build());

// Add a listener to update combo boxes when switching tabs
// This ensures Remove and Metadata tabs see any field renamings from Select & Alter tab
Expand Down Expand Up @@ -592,15 +547,15 @@ private void setComboValues() {

/** Copy information from the meta-data input to the dialog fields. */
public void getData() {
wTabFolder.setSelection(0); // Default
wTabFolder.setSelection(0);

/*
* Select fields
*/
if (input.getSelectOption().getSelectFields() != null
&& !input.getSelectOption().getSelectFields().isEmpty()) {
for (int i = 0; i < input.getSelectOption().getSelectFields().size(); i++) {
SelectField selectField = input.getSelectOption().getSelectFields().get(i);
List<SelectField> fields = input.getSelectOption().getSelectFields();
if (!Utils.isEmpty(fields)) {
for (int i = 0; i < fields.size(); i++) {
SelectField selectField = fields.get(i);
TableItem item = wFields.table.getItem(i);
if (selectField.getName() != null) {
item.setText(1, selectField.getName());
Expand All @@ -614,33 +569,32 @@ public void getData() {
}
wFields.setRowNums();
wFields.optWidth(true);
wTabFolder.setSelection(0);
}
wUnspecified.setSelection(input.getSelectOption().isSelectingAndSortingUnspecifiedFields());

/*
* Remove certain fields...
*/
if (input.getSelectOption().getDeleteName() != null
&& !input.getSelectOption().getDeleteName().isEmpty()) {
for (int i = 0; i < input.getSelectOption().getDeleteName().size(); i++) {
DeleteField deleteName = input.getSelectOption().getDeleteName().get(i);
List<DeleteField> deleteFields = input.getSelectOption().getDeleteName();
if (!Utils.isEmpty(deleteFields)) {
for (int i = 0; i < deleteFields.size(); i++) {
DeleteField deleteName = deleteFields.get(i);
TableItem item = wRemove.table.getItem(i);
if (deleteName != null) {
item.setText(1, deleteName.getName());
}
}
wRemove.setRowNums();
wRemove.optWidth(true);
wTabFolder.setSelection(1);
}

/*
* Change the meta-data of certain fields
*/
if (!Utils.isEmpty(input.getSelectOption().getMeta())) {
for (int i = 0; i < input.getSelectOption().getMeta().size(); i++) {
SelectMetadataChange change = input.getSelectOption().getMeta().get(i);
List<SelectMetadataChange> meta = input.getSelectOption().getMeta();
if (!Utils.isEmpty(meta)) {
for (int i = 0; i < meta.size(); i++) {
SelectMetadataChange change = meta.get(i);

TableItem item = wMeta.table.getItem(i);
int index = 1;
Expand Down Expand Up @@ -685,7 +639,6 @@ public void getData() {
}
wMeta.setRowNums();
wMeta.optWidth(true);
wTabFolder.setSelection(2);
}
}

Expand Down
18 changes: 18 additions & 0 deletions ui/src/main/java/org/apache/hop/ui/core/FormDataBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.hop.ui.core;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.widgets.Control;
Expand Down Expand Up @@ -128,6 +129,23 @@ public FormDataBuilder bottom(Control control, int margin) {
return bottom(new FormAttachment(control, margin));
}

/**
* Sets the bottom attachment of this {@code FormDataBuilder} relative to the specified control.
*
* <p>The bottom edge will be attached to the given {@link Control} with the specified margin and
* alignment.
*
* @param control the reference control to which the bottom edge will be attached; must not be
* {@code null}
* @param margin the offset in pixels from the specified control
* @param alignment the alignment relative to the control (for example, {@link SWT#TOP}, {@link
* SWT#BOTTOM}, or {@link SWT#CENTER})
* @return this {@code FormDataBuilder} instance for method chaining
*/
public FormDataBuilder bottom(Control control, int margin, int alignment) {
return bottom(new FormAttachment(control, margin, alignment));
}

public FormDataBuilder right(Control control, int margin) {
return right(new FormAttachment(control, margin));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1141,19 +1141,22 @@ public static final void getFieldsFromPrevious(
}

int choice = 0;
boolean isOpenDialog = false;

if (!keys.isEmpty()) {
// Ask what we should do with the existing data in the transform.
//
DialogBoxWithButtons getFieldsChoiceDialog =
getFieldsChoiceDialogProvider.provide(tableView.getShell(), keys.size(), row.size());

int idx = getFieldsChoiceDialog.open();
choice = idx & 0xFF;
// Mark that the dialog was actually opened.
isOpenDialog = true;
}

if (choice == 3 || choice == 255) {
return; // Cancel clicked
// Cancel clicked, Close x
if ((choice == 0 && isOpenDialog) || choice == 3 || choice == 255) {
return;
}

if (choice == 2) {
Expand All @@ -1163,13 +1166,8 @@ public static final void getFieldsFromPrevious(
for (int i = 0; i < row.size(); i++) {
IValueMeta v = row.getValueMeta(i);

boolean add = true;

if (choice == 0
&& keys.indexOf(v.getName()) >= 0) { // hang on, see if it's not yet in the table view
add = false;
}

// hang on, see if it's not yet in the table view
boolean add = choice != 0 || !keys.contains(v.getName());
if (add) {
TableItem tableItem = new TableItem(table, SWT.NONE);

Expand Down
Loading