Skip to content

Commit

Permalink
Merge pull request #589 from ashitsalesforce/master
Browse files Browse the repository at this point in the history
search by salesforce field in mapping dialog
  • Loading branch information
ashitsalesforce authored Jan 29, 2023
2 parents 59a6aa7 + 065c9ae commit 9ce8c69
Showing 1 changed file with 54 additions and 2 deletions.
56 changes: 54 additions & 2 deletions src/main/java/com/salesforce/dataloader/ui/MappingDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.*;
import org.eclipse.swt.events.*;
Expand Down Expand Up @@ -218,11 +220,19 @@ public void widgetSelected(SelectionEvent event) {
autoMatchFields();
}
});

Text sforceFieldsSearch = new Text(shell, SWT.SEARCH | SWT.ICON_CANCEL | SWT.ICON_SEARCH);
sforceFieldsSearch.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
sforceFieldsSearch.addListener(SWT.KeyUp, new Listener() {
public void handleEvent(Event e) {
sforceTblViewer.refresh();
}
});

///////////////////////////////////////////////
//InitializeSforceViewer
///////////////////////////////////////////////
initializeSforceViewer(shell);
initializeSforceViewer(shell, sforceFieldsSearch);

Label sep1 = new Label(shell, SWT.HORIZONTAL | SWT.SEPARATOR);
sep1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Expand Down Expand Up @@ -423,14 +433,15 @@ public void widgetSelected(SelectionEvent event) {

}

private void initializeSforceViewer(Shell shell) {
private void initializeSforceViewer(Shell shell, Text sforceFieldsSearch) {
GridData data;

//sforce field table viewer
sforceTblViewer = new TableViewer(shell, SWT.FULL_SELECTION);
sforceTblViewer.setContentProvider(new SforceContentProvider());
sforceTblViewer.setLabelProvider(new SforceLabelProvider());
sforceTblViewer.setSorter(new SforceViewerSorter());
sforceTblViewer.addFilter(new SforceFieldsFilter(sforceFieldsSearch));

//add drag support
int ops = DND.DROP_MOVE;
Expand Down Expand Up @@ -672,3 +683,44 @@ public LoadMapper getMapper() {
}

}

/**
* This class filters the Saleforce fields list
*/

class SforceFieldsFilter extends ViewerFilter {
private Text searchText;
public SforceFieldsFilter(Text search) {
super();
this.searchText = search;
}
/**
* Returns whether the specified element passes this filter
*
* @param arg0
* the viewer
* @param arg1
* the parent element
* @param arg2
* the element
* @return boolean
*/
@Override
public boolean select(Viewer arg0, Object arg1, Object arg2) {

Field selectedField = (Field)arg2;
String fieldName = selectedField.getName();
String fieldLabel = selectedField.getLabel();
String searchText = this.searchText.getText();
if (searchText != null && !searchText.isBlank()) {
searchText = searchText.toLowerCase();
if ((fieldName != null && fieldName.toLowerCase().contains(searchText))
|| (fieldLabel != null && fieldLabel.toLowerCase().contains(searchText))) {
return true;
} else {
return false;
}
}
return true;
}
}

0 comments on commit 9ce8c69

Please sign in to comment.