Search in sources :

Example 1 with SelectRowDialog

use of org.apache.hop.ui.core.dialog.SelectRowDialog in project hop by apache.

the class HopGuiFileDelegate method fileOpenRecent.

/**
 * Show all the recent files in a new dialog...
 */
public void fileOpenRecent() {
    // Get the recent files for the active perspective...
    // 
    IHopPerspective perspective = hopGui.getActivePerspective();
    try {
        // Let's limit ourselves to 100 operations...
        // 
        List<AuditEvent> events = AuditManager.findEvents(HopNamespace.getNamespace(), "file", "open", 100, true);
        Set<String> filenames = new HashSet<>();
        List<RowMetaAndData> rows = new ArrayList<>();
        IRowMeta rowMeta = new RowMeta();
        rowMeta.addValueMeta(new ValueMetaString("filename"));
        rowMeta.addValueMeta(new ValueMetaString("operation"));
        rowMeta.addValueMeta(new ValueMetaString("date"));
        for (AuditEvent event : events) {
            String filename = event.getName();
            if (!filenames.contains(filename)) {
                filenames.add(filename);
                String operation = event.getOperation();
                String dateString = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(event.getDate());
                rows.add(new RowMetaAndData(rowMeta, new Object[] { filename, operation, dateString }));
            }
        }
        SelectRowDialog rowDialog = new SelectRowDialog(hopGui.getShell(), hopGui.getVariables(), SWT.NONE, rows);
        rowDialog.setTitle("Select the file to open");
        RowMetaAndData row = rowDialog.open();
        if (row != null) {
            String filename = row.getString("filename", null);
            hopGui.fileDelegate.fileOpen(filename);
        }
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), "Error", "Error getting list of recently opened files", e);
    }
}
Also used : ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) RowMeta(org.apache.hop.core.row.RowMeta) IRowMeta(org.apache.hop.core.row.IRowMeta) IRowMeta(org.apache.hop.core.row.IRowMeta) ArrayList(java.util.ArrayList) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) SelectRowDialog(org.apache.hop.ui.core.dialog.SelectRowDialog) HopException(org.apache.hop.core.exception.HopException) RowMetaAndData(org.apache.hop.core.RowMetaAndData) IHopPerspective(org.apache.hop.ui.hopgui.perspective.IHopPerspective) AuditEvent(org.apache.hop.history.AuditEvent) FileObject(org.apache.commons.vfs2.FileObject) SimpleDateFormat(java.text.SimpleDateFormat) HashSet(java.util.HashSet)

Example 2 with SelectRowDialog

use of org.apache.hop.ui.core.dialog.SelectRowDialog in project hop by apache.

the class TestingGuiPlugin method selectUnitTestFromAllTests.

/**
 * List all unit tests which are defined And allow the user to select one
 */
public RowMetaAndData selectUnitTestFromAllTests() {
    HopGui hopGui = HopGui.getInstance();
    IHopMetadataProvider metadataProvider = hopGui.getMetadataProvider();
    IRowMeta rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaString("Unit test"));
    rowMeta.addValueMeta(new ValueMetaString("Description"));
    rowMeta.addValueMeta(new ValueMetaString("Filename"));
    List<RowMetaAndData> rows = new ArrayList<>();
    try {
        IHopMetadataSerializer<PipelineUnitTest> testSerializer = metadataProvider.getSerializer(PipelineUnitTest.class);
        List<String> testNames = testSerializer.listObjectNames();
        for (String testName : testNames) {
            PipelineUnitTest unitTest = testSerializer.load(testName);
            Object[] row = RowDataUtil.allocateRowData(rowMeta.size());
            row[0] = testName;
            row[1] = unitTest.getDescription();
            row[2] = unitTest.getPipelineFilename();
            rows.add(new RowMetaAndData(rowMeta, row));
        }
        // Now show a selection dialog...
        // 
        SelectRowDialog dialog = new SelectRowDialog(hopGui.getShell(), new Variables(), SWT.DIALOG_TRIM | SWT.MAX | SWT.RESIZE, rows);
        RowMetaAndData selection = dialog.open();
        if (selection != null) {
            return selection;
        }
        return null;
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "TestingGuiPlugin.SelectUnitTestFromAllTests.Error.Header"), BaseMessages.getString(PKG, "TestingGuiPlugin.SelectUnitTestFromAllTests.Error.Message"), e);
        return null;
    }
}
Also used : ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) RowMeta(org.apache.hop.core.row.RowMeta) IRowMeta(org.apache.hop.core.row.IRowMeta) IRowMeta(org.apache.hop.core.row.IRowMeta) ArrayList(java.util.ArrayList) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) SelectRowDialog(org.apache.hop.ui.core.dialog.SelectRowDialog) HopException(org.apache.hop.core.exception.HopException) HopTransformException(org.apache.hop.core.exception.HopTransformException) HopValueException(org.apache.hop.core.exception.HopValueException) HopPluginException(org.apache.hop.core.exception.HopPluginException) IVariables(org.apache.hop.core.variables.IVariables) Variables(org.apache.hop.core.variables.Variables) RowMetaAndData(org.apache.hop.core.RowMetaAndData) IHopMetadataProvider(org.apache.hop.metadata.api.IHopMetadataProvider) HopGui(org.apache.hop.ui.hopgui.HopGui)

Aggregations

ArrayList (java.util.ArrayList)2 RowMetaAndData (org.apache.hop.core.RowMetaAndData)2 HopException (org.apache.hop.core.exception.HopException)2 IRowMeta (org.apache.hop.core.row.IRowMeta)2 RowMeta (org.apache.hop.core.row.RowMeta)2 ValueMetaString (org.apache.hop.core.row.value.ValueMetaString)2 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)2 SelectRowDialog (org.apache.hop.ui.core.dialog.SelectRowDialog)2 SimpleDateFormat (java.text.SimpleDateFormat)1 HashSet (java.util.HashSet)1 FileObject (org.apache.commons.vfs2.FileObject)1 HopPluginException (org.apache.hop.core.exception.HopPluginException)1 HopTransformException (org.apache.hop.core.exception.HopTransformException)1 HopValueException (org.apache.hop.core.exception.HopValueException)1 IVariables (org.apache.hop.core.variables.IVariables)1 Variables (org.apache.hop.core.variables.Variables)1 AuditEvent (org.apache.hop.history.AuditEvent)1 IHopMetadataProvider (org.apache.hop.metadata.api.IHopMetadataProvider)1 HopGui (org.apache.hop.ui.hopgui.HopGui)1 IHopPerspective (org.apache.hop.ui.hopgui.perspective.IHopPerspective)1