Search in sources :

Example 1 with EnterSearchDialog

use of org.pentaho.di.ui.core.dialog.EnterSearchDialog in project pentaho-kettle by pentaho.

the class Spoon method searchMetaData.

/**
 * Search the transformation meta-data.
 */
public void searchMetaData() {
    TransMeta[] transMetas = getLoadedTransformations();
    JobMeta[] jobMetas = getLoadedJobs();
    if ((transMetas == null || transMetas.length == 0) && (jobMetas == null || jobMetas.length == 0)) {
        return;
    }
    EnterSearchDialog esd = new EnterSearchDialog(shell);
    if (!esd.open()) {
        return;
    }
    List<Object[]> rows = new ArrayList<>();
    for (TransMeta transMeta : transMetas) {
        String filter = esd.getFilterString();
        if (filter != null) {
            filter = filter.toUpperCase();
        }
        List<StringSearchResult> stringList = transMeta.getStringList(esd.isSearchingSteps(), esd.isSearchingDatabases(), esd.isSearchingNotes());
        for (StringSearchResult result : stringList) {
            boolean add = Utils.isEmpty(filter);
            if (filter != null && result.getString().toUpperCase().contains(filter)) {
                add = true;
            }
            if (filter != null && result.getFieldName().toUpperCase().contains(filter)) {
                add = true;
            }
            if (filter != null && result.getParentObject().toString().toUpperCase().contains(filter)) {
                add = true;
            }
            if (filter != null && result.getGrandParentObject().toString().toUpperCase().contains(filter)) {
                add = true;
            }
            if (add) {
                rows.add(result.toRow());
            }
        }
    }
    for (JobMeta jobMeta : jobMetas) {
        String filter = esd.getFilterString();
        if (filter != null) {
            filter = filter.toUpperCase();
        }
        List<StringSearchResult> stringList = jobMeta.getStringList(esd.isSearchingSteps(), esd.isSearchingDatabases(), esd.isSearchingNotes());
        for (StringSearchResult result : stringList) {
            boolean add = Utils.isEmpty(filter);
            if (filter != null && result.getString().toUpperCase().contains(filter)) {
                add = true;
            }
            if (filter != null && result.getFieldName().toUpperCase().contains(filter)) {
                add = true;
            }
            if (filter != null && result.getParentObject().toString().toUpperCase().contains(filter)) {
                add = true;
            }
            if (filter != null && result.getGrandParentObject().toString().toUpperCase().contains(filter)) {
                add = true;
            }
            if (add) {
                rows.add(result.toRow());
            }
        }
    }
    if (rows.size() != 0) {
        PreviewRowsDialog prd = new PreviewRowsDialog(shell, Variables.getADefaultVariableSpace(), SWT.NONE, BaseMessages.getString(PKG, "Spoon.StringSearchResult.Subtitle"), StringSearchResult.getResultRowMeta(), rows);
        String title = BaseMessages.getString(PKG, "Spoon.StringSearchResult.Title");
        String message = BaseMessages.getString(PKG, "Spoon.StringSearchResult.Message");
        prd.setTitleMessage(title, message);
        prd.open();
    } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
        mb.setMessage(BaseMessages.getString(PKG, "Spoon.Dialog.NothingFound.Message"));
        // Sorry!
        mb.setText(BaseMessages.getString(PKG, "Spoon.Dialog.NothingFound.Title"));
        mb.open();
    }
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) TransMeta(org.pentaho.di.trans.TransMeta) ArrayList(java.util.ArrayList) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) PreviewRowsDialog(org.pentaho.di.ui.core.dialog.PreviewRowsDialog) MessageBox(org.eclipse.swt.widgets.MessageBox) StringSearchResult(org.pentaho.di.core.reflection.StringSearchResult) EnterSearchDialog(org.pentaho.di.ui.core.dialog.EnterSearchDialog)

Aggregations

ArrayList (java.util.ArrayList)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1 StringSearchResult (org.pentaho.di.core.reflection.StringSearchResult)1 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)1 JobMeta (org.pentaho.di.job.JobMeta)1 TransMeta (org.pentaho.di.trans.TransMeta)1 EnterSearchDialog (org.pentaho.di.ui.core.dialog.EnterSearchDialog)1 PreviewRowsDialog (org.pentaho.di.ui.core.dialog.PreviewRowsDialog)1