Search in sources :

Example 91 with Variables

use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.

the class TextFileInputDialogTest method testMinimalWidth_PDI_14253.

@Test
public void testMinimalWidth_PDI_14253() throws Exception {
    final String virtualFile = "ram://pdi-14253.txt";
    KettleVFS.getFileObject(virtualFile).createFile();
    final String content = "r1c1,  r1c2\nr2c1  ,  r2c2  ";
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bos.write(content.getBytes());
    OutputStream os = KettleVFS.getFileObject(virtualFile).getContent().getOutputStream();
    IOUtils.copy(new ByteArrayInputStream(bos.toByteArray()), os);
    os.close();
    TextFileInputMeta meta = new TextFileInputMeta();
    meta.content.lineWrapped = false;
    meta.inputFields = new BaseFileField[] { new BaseFileField("col1", -1, -1), new BaseFileField("col2", -1, -1) };
    meta.content.fileCompression = "None";
    meta.content.fileType = "CSV";
    meta.content.header = false;
    meta.content.nrHeaderLines = -1;
    meta.content.footer = false;
    meta.content.nrFooterLines = -1;
    TextFileInputData data = new TextFileInputData();
    data.files = new FileInputList();
    data.files.addFile(KettleVFS.getFileObject(virtualFile));
    data.outputRowMeta = new RowMeta();
    data.outputRowMeta.addValueMeta(new ValueMetaString("col1"));
    data.outputRowMeta.addValueMeta(new ValueMetaString("col2"));
    data.dataErrorLineHandler = mock(FileErrorHandler.class);
    data.fileFormatType = TextFileInputMeta.FILE_FORMAT_UNIX;
    data.separator = ",";
    data.filterProcessor = new TextFileFilterProcessor(new TextFileFilter[0], new Variables() {
    });
    data.filePlayList = new FilePlayListAll();
    TextFileInputDialog dialog = new TextFileInputDialog(mock(Shell.class), meta, mock(TransMeta.class), "TFIMinimalWidthTest");
    TableView tv = mock(TableView.class);
    when(tv.nrNonEmpty()).thenReturn(0);
    // click the Minimal width button
    dialog.setMinimalWidth(tv);
    RowSet output = new BlockingRowSet(5);
    TextFileInput input = StepMockUtil.getStep(TextFileInput.class, TextFileInputMeta.class, "test");
    input.setOutputRowSets(Collections.singletonList(output));
    while (input.processRow(meta, data)) {
    // wait until the step completes executing
    }
    Object[] row1 = output.getRowImmediate();
    assertRow(row1, "r1c1", "r1c2");
    Object[] row2 = output.getRowImmediate();
    assertRow(row2, "r2c1", "r2c2");
    KettleVFS.getFileObject(virtualFile).delete();
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) TextFileFilterProcessor(org.pentaho.di.trans.steps.fileinput.text.TextFileFilterProcessor) RowMeta(org.pentaho.di.core.row.RowMeta) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) TextFileFilter(org.pentaho.di.trans.steps.fileinput.text.TextFileFilter) FilePlayListAll(org.pentaho.di.core.playlist.FilePlayListAll) BaseFileField(org.pentaho.di.trans.steps.file.BaseFileField) TransMeta(org.pentaho.di.trans.TransMeta) RowSet(org.pentaho.di.core.RowSet) BlockingRowSet(org.pentaho.di.core.BlockingRowSet) BlockingRowSet(org.pentaho.di.core.BlockingRowSet) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Variables(org.pentaho.di.core.variables.Variables) Shell(org.eclipse.swt.widgets.Shell) TextFileInputMeta(org.pentaho.di.trans.steps.fileinput.text.TextFileInputMeta) ByteArrayInputStream(java.io.ByteArrayInputStream) TextFileInput(org.pentaho.di.trans.steps.fileinput.text.TextFileInput) FileErrorHandler(org.pentaho.di.trans.step.errorhandling.FileErrorHandler) TextFileInputData(org.pentaho.di.trans.steps.fileinput.text.TextFileInputData) FileInputList(org.pentaho.di.core.fileinput.FileInputList) TableView(org.pentaho.di.ui.core.widget.TableView) Test(org.junit.Test)

Example 92 with Variables

use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.

the class DimensionTableDialog method addAttributesTab.

private void addAttributesTab() {
    wTablesTab = new CTabItem(wTabFolder, SWT.NONE);
    wTablesTab.setText(BaseMessages.getString(PKG, "DimensionTableDialog.AttributesTab.Label"));
    FormLayout paramLayout = new FormLayout();
    paramLayout.marginWidth = Const.MARGIN;
    paramLayout.marginHeight = Const.MARGIN;
    Composite wTablesComp = new Composite(wTabFolder, SWT.NONE);
    props.setLook(wTablesComp);
    wTablesComp.setLayout(paramLayout);
    Button wAddDefaultFields = new Button(wTablesComp, SWT.PUSH);
    wAddDefaultFields.setText(BaseMessages.getString(PKG, "DimensionTableDialog.AddDefaultFieldsButton.Label"));
    BaseStepDialog.positionBottomButtons(wTablesComp, new Button[] { wAddDefaultFields }, margin, null);
    wAddDefaultFields.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            addDefaultAttributes();
        }
    });
    Label wlAtrributes = new Label(wTablesComp, SWT.RIGHT);
    wlAtrributes.setText(BaseMessages.getString(PKG, "DimensionTableDialog.Attributes.Label"));
    props.setLook(wlAtrributes);
    FormData fdlAttributes = new FormData();
    fdlAttributes.left = new FormAttachment(0, 0);
    fdlAttributes.top = new FormAttachment(0, 0);
    wlAtrributes.setLayoutData(fdlAttributes);
    final int FieldsRows = logicalTable.getLogicalColumns().size();
    List<DatabaseMeta> sharedDatabases = SharedDatabaseUtil.loadSharedDatabases();
    String[] databaseNames = SharedDatabaseUtil.getSortedDatabaseNames(sharedDatabases);
    // data types
    // 
    String[] dataTypes = new String[DataType.values().length];
    for (int i = 0; i < dataTypes.length; i++) {
        dataTypes[i] = DataType.values()[i].name();
    }
    // field types
    // 
    String[] attributeTypes = new String[AttributeType.values().length];
    for (int i = 0; i < AttributeType.values().length; i++) {
        attributeTypes[i] = AttributeType.values()[i].name();
    }
    // name, description, field type, physical column name, data type, length, precision, source db, source table, source column, conversion remarks
    // 
    ColumnInfo[] colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "DimensionTableDialog.ColumnInfo.Name.Label"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "DimensionTableDialog.ColumnInfo.Description.Label"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "DimensionTableDialog.ColumnInfo.FieldType.Label"), ColumnInfo.COLUMN_TYPE_CCOMBO, attributeTypes), new ColumnInfo(BaseMessages.getString(PKG, "DimensionTableDialog.ColumnInfo.PhysicalName.Label"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "DimensionTableDialog.ColumnInfo.DataType.Label"), ColumnInfo.COLUMN_TYPE_CCOMBO, dataTypes), new ColumnInfo(BaseMessages.getString(PKG, "DimensionTableDialog.ColumnInfo.DataLength.Label"), ColumnInfo.COLUMN_TYPE_TEXT, true), new ColumnInfo(BaseMessages.getString(PKG, "DimensionTableDialog.ColumnInfo.DataPrecision.Label"), ColumnInfo.COLUMN_TYPE_TEXT, true), new ColumnInfo(BaseMessages.getString(PKG, "DimensionTableDialog.ColumnInfo.SourceDatabase.Label"), ColumnInfo.COLUMN_TYPE_CCOMBO, databaseNames), new ColumnInfo(BaseMessages.getString(PKG, "DimensionTableDialog.ColumnInfo.SourceTable.Label"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "DimensionTableDialog.ColumnInfo.SourceColumn.Label"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "DimensionTableDialog.ColumnInfo.ConversionLogicRemarks.Label"), ColumnInfo.COLUMN_TYPE_TEXT, false) };
    wAttributes = new TableView(new Variables(), wTablesComp, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, colinf, FieldsRows, null, props);
    FormData fdTables = new FormData();
    fdTables.left = new FormAttachment(0, 0);
    fdTables.top = new FormAttachment(wlAtrributes, margin);
    fdTables.right = new FormAttachment(100, 0);
    fdTables.bottom = new FormAttachment(wAddDefaultFields, -margin * 2);
    wAttributes.setLayoutData(fdTables);
    FormData fdTablesComp = new FormData();
    fdTablesComp.left = new FormAttachment(0, 0);
    fdTablesComp.top = new FormAttachment(0, 0);
    fdTablesComp.right = new FormAttachment(100, 0);
    fdTablesComp.bottom = new FormAttachment(100, 0);
    wTablesComp.setLayoutData(fdTablesComp);
    wTablesComp.layout();
    wTablesTab.setControl(wTablesComp);
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) CTabItem(org.eclipse.swt.custom.CTabItem) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Variables(org.pentaho.di.core.variables.Variables) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment) TableView(org.pentaho.di.ui.core.widget.TableView)

Example 93 with Variables

use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.

the class StarModelDialog method addDimensionsTab.

private void addDimensionsTab() {
    wDimensionsTab = new CTabItem(wTabFolder, SWT.NONE);
    wDimensionsTab.setText(BaseMessages.getString(PKG, "StarModelDialog.DimensionsTab.Label"));
    FormLayout dimensionsLayout = new FormLayout();
    dimensionsLayout.marginWidth = Const.MARGIN;
    dimensionsLayout.marginHeight = Const.MARGIN;
    Composite wDimensionsComp = new Composite(wTabFolder, SWT.NONE);
    props.setLook(wDimensionsComp);
    wDimensionsComp.setLayout(dimensionsLayout);
    Label wlTables = new Label(wDimensionsComp, SWT.RIGHT);
    wlTables.setText(BaseMessages.getString(PKG, "StarModelDialog.Tables.Label"));
    props.setLook(wlTables);
    FormData fdlAttributes = new FormData();
    fdlAttributes.left = new FormAttachment(0, 0);
    fdlAttributes.top = new FormAttachment(0, 0);
    wlTables.setLayoutData(fdlAttributes);
    // A few buttons to edit the list
    // 
    Button newTableButton = new Button(wDimensionsComp, SWT.PUSH);
    newTableButton.setText(BaseMessages.getString(PKG, "StarModelDialog.Button.NewTable"));
    newTableButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (newTable(shell, logicalModel)) {
                refreshTablesList();
            }
        }
    });
    Button copyTableButton = new Button(wDimensionsComp, SWT.PUSH);
    copyTableButton.setText(BaseMessages.getString(PKG, "StarModelDialog.Button.CopyTable"));
    copyTableButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (wTablesList.getSelectionIndex() < 0)
                return;
            TableItem item = wTablesList.table.getSelection()[0];
            String tableName = item.getText(1);
            if (copyTable(shell, logicalModel, tableName)) {
                refreshTablesList();
            }
        }
    });
    Button editTableButton = new Button(wDimensionsComp, SWT.PUSH);
    editTableButton.setText(BaseMessages.getString(PKG, "StarModelDialog.Button.EditTable"));
    editTableButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (wTablesList.getSelectionIndex() < 0)
                return;
            TableItem item = wTablesList.table.getSelection()[0];
            String tableName = item.getText(1);
            if (editTable(tableName)) {
                refreshTablesList();
            }
        }
    });
    Button delTableButton = new Button(wDimensionsComp, SWT.PUSH);
    delTableButton.setText(BaseMessages.getString(PKG, "StarModelDialog.Button.DeleteTable"));
    delTableButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (wTablesList.getSelectionIndex() < 0)
                return;
            TableItem item = wTablesList.table.getSelection()[0];
            String tableName = item.getText(1);
            if (deleteTable(tableName)) {
                refreshTablesList();
            }
        }
    });
    BaseStepDialog.positionBottomButtons(wDimensionsComp, new Button[] { newTableButton, copyTableButton, editTableButton, delTableButton }, margin, null);
    final int FieldsRows = logicalModel.getLogicalTables().size();
    List<DatabaseMeta> sharedDatabases = new ArrayList<DatabaseMeta>();
    try {
        SharedObjects sharedObjects = new SharedObjects();
        for (SharedObjectInterface sharedObject : sharedObjects.getObjectsMap().values()) {
            if (sharedObject instanceof DatabaseMeta) {
                sharedDatabases.add((DatabaseMeta) sharedObject);
            }
        }
    } catch (Exception e) {
        LogChannel.GENERAL.logError("Unable to load shared objects", e);
    }
    // The dimensions and fact of the model
    // 
    ColumnInfo[] colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "StarModelDialog.ColumnInfo.Name.Label"), ColumnInfo.COLUMN_TYPE_TEXT, false, true), new ColumnInfo(BaseMessages.getString(PKG, "StarModelDialog.ColumnInfo.Description.Label"), ColumnInfo.COLUMN_TYPE_TEXT, false, true), new ColumnInfo(BaseMessages.getString(PKG, "StarModelDialog.ColumnInfo.TableType.Label"), ColumnInfo.COLUMN_TYPE_TEXT, false, true) };
    wTablesList = new TableView(new Variables(), wDimensionsComp, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, colinf, FieldsRows, null, props);
    FormData fdTablesList = new FormData();
    fdTablesList.left = new FormAttachment(0, 0);
    fdTablesList.top = new FormAttachment(wlTables, margin);
    fdTablesList.right = new FormAttachment(100, 0);
    fdTablesList.bottom = new FormAttachment(newTableButton, -margin);
    wTablesList.setLayoutData(fdTablesList);
    wTablesList.setReadonly(true);
    wTablesList.table.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            if (wTablesList.getSelectionIndex() < 0)
                return;
            TableItem item = wTablesList.table.getSelection()[0];
            String tableName = item.getText(1);
            if (editTable(tableName)) {
                refreshTablesList();
            // refreshRelationshipsList();
            }
        }
    });
    FormData fdTablesComp = new FormData();
    fdTablesComp.left = new FormAttachment(0, 0);
    fdTablesComp.top = new FormAttachment(0, 0);
    fdTablesComp.right = new FormAttachment(100, 0);
    fdTablesComp.bottom = new FormAttachment(100, 0);
    wDimensionsComp.setLayoutData(fdTablesComp);
    wDimensionsComp.layout();
    wDimensionsTab.setControl(wDimensionsComp);
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) SharedObjects(org.pentaho.di.shared.SharedObjects) CTabItem(org.eclipse.swt.custom.CTabItem) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Variables(org.pentaho.di.core.variables.Variables) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SharedObjectInterface(org.pentaho.di.shared.SharedObjectInterface) FormAttachment(org.eclipse.swt.layout.FormAttachment) TableView(org.pentaho.di.ui.core.widget.TableView)

Example 94 with Variables

use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.

the class StarModelDialog method addFactTab.

private void addFactTab() {
    wFactTab = new CTabItem(wTabFolder, SWT.NONE);
    wFactTab.setText(BaseMessages.getString(PKG, "StarModelDialog.FactTab.Label"));
    FormLayout factLayout = new FormLayout();
    factLayout.marginWidth = Const.MARGIN;
    factLayout.marginHeight = Const.MARGIN;
    Composite wFactComp = new Composite(wTabFolder, SWT.NONE);
    props.setLook(wFactComp);
    wFactComp.setLayout(factLayout);
    Button wAddDimensionKeys = new Button(wFactComp, SWT.PUSH);
    wAddDimensionKeys.setText(BaseMessages.getString(PKG, "StarModelDialog.AddDimensionKeys.Label"));
    BaseStepDialog.positionBottomButtons(wFactComp, new Button[] { wAddDimensionKeys }, margin, null);
    wAddDimensionKeys.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            addDimensionKeys();
        }
    });
    // Table  name:
    // 
    Label wlFactTableName = new Label(wFactComp, SWT.RIGHT);
    wlFactTableName.setText(BaseMessages.getString(PKG, "StarModelDialog.FactTableName.Label"));
    props.setLook(wlFactTableName);
    FormData fdlFactTableName = new FormData();
    fdlFactTableName.left = new FormAttachment(0, 0);
    fdlFactTableName.right = new FormAttachment(middle, -margin);
    fdlFactTableName.top = new FormAttachment(0, margin);
    wlFactTableName.setLayoutData(fdlFactTableName);
    wFactTableName = new Text(wFactComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wFactTableName);
    FormData fdFactTableName = new FormData();
    fdFactTableName.left = new FormAttachment(middle, 0);
    fdFactTableName.top = new FormAttachment(0, margin);
    fdFactTableName.right = new FormAttachment(100, 0);
    wFactTableName.setLayoutData(fdFactTableName);
    Control lastControl = wFactTableName;
    // Table description
    // 
    Label wlFactTableDescription = new Label(wFactComp, SWT.RIGHT);
    wlFactTableDescription.setText(BaseMessages.getString(PKG, "StarModelDialog.FactTableDescription.Label"));
    props.setLook(wlFactTableDescription);
    FormData fdlFactTableDescription = new FormData();
    fdlFactTableDescription.left = new FormAttachment(0, 0);
    fdlFactTableDescription.right = new FormAttachment(middle, -margin);
    fdlFactTableDescription.top = new FormAttachment(lastControl, margin);
    wlFactTableDescription.setLayoutData(fdlFactTableDescription);
    wFactTableDescription = new Text(wFactComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wFactTableDescription);
    FormData fdFactTableDescription = new FormData();
    fdFactTableDescription.left = new FormAttachment(middle, 0);
    fdFactTableDescription.top = new FormAttachment(lastControl, margin);
    fdFactTableDescription.right = new FormAttachment(100, 0);
    wFactTableDescription.setLayoutData(fdFactTableDescription);
    lastControl = wFactTableDescription;
    // Table description
    // 
    Label wlPhysicalFactName = new Label(wFactComp, SWT.RIGHT);
    wlPhysicalFactName.setText(BaseMessages.getString(PKG, "StarModelDialog.PhysicalFactName.Label"));
    props.setLook(wlPhysicalFactName);
    FormData fdlPhysicalName = new FormData();
    fdlPhysicalName.left = new FormAttachment(0, 0);
    fdlPhysicalName.right = new FormAttachment(middle, -margin);
    fdlPhysicalName.top = new FormAttachment(lastControl, margin);
    wlPhysicalFactName.setLayoutData(fdlPhysicalName);
    wPhysicalFactName = new Text(wFactComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wPhysicalFactName);
    FormData fdPhysicalFactName = new FormData();
    fdPhysicalFactName.left = new FormAttachment(middle, 0);
    fdPhysicalFactName.top = new FormAttachment(lastControl, margin);
    fdPhysicalFactName.right = new FormAttachment(100, 0);
    wPhysicalFactName.setLayoutData(fdPhysicalFactName);
    lastControl = wPhysicalFactName;
    Label wlAtrributes = new Label(wFactComp, SWT.RIGHT);
    wlAtrributes.setText(BaseMessages.getString(PKG, "DimensionTableDialog.Attributes.Label"));
    props.setLook(wlAtrributes);
    FormData fdlAttributes = new FormData();
    fdlAttributes.left = new FormAttachment(0, 0);
    fdlAttributes.top = new FormAttachment(lastControl, margin);
    wlAtrributes.setLayoutData(fdlAttributes);
    final int FieldsRows = factTable.getLogicalColumns().size();
    List<DatabaseMeta> sharedDatabases = SharedDatabaseUtil.loadSharedDatabases();
    String[] databaseNames = SharedDatabaseUtil.getSortedDatabaseNames(sharedDatabases);
    // data types
    // 
    String[] dataTypes = new String[DataType.values().length];
    for (int i = 0; i < dataTypes.length; i++) {
        dataTypes[i] = DataType.values()[i].name();
    }
    // field types
    // 
    String[] attributeTypes = new String[AttributeType.values().length];
    for (int i = 0; i < AttributeType.values().length; i++) {
        attributeTypes[i] = AttributeType.values()[i].name();
    }
    String[] dimensionNames = getDimensionTableNames();
    // name, description, field type, physical column name, data type, length, precision, source db, source table, source column, conversion remarks
    // 
    factColumns = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "StarModelDialog.ColumnInfo.Name.Label"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "StarModelDialog.ColumnInfo.Description.Label"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "StarModelDialog.ColumnInfo.FieldType.Label"), ColumnInfo.COLUMN_TYPE_CCOMBO, attributeTypes), new ColumnInfo(BaseMessages.getString(PKG, "StarModelDialog.ColumnInfo.PhysicalName.Label"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "StarModelDialog.ColumnInfo.DataType.Label"), ColumnInfo.COLUMN_TYPE_CCOMBO, dataTypes), new ColumnInfo(BaseMessages.getString(PKG, "StarModelDialog.ColumnInfo.Dimension.Label"), ColumnInfo.COLUMN_TYPE_CCOMBO, dimensionNames), new ColumnInfo(BaseMessages.getString(PKG, "StarModelDialog.ColumnInfo.DataLength.Label"), ColumnInfo.COLUMN_TYPE_TEXT, true), new ColumnInfo(BaseMessages.getString(PKG, "StarModelDialog.ColumnInfo.DataPrecision.Label"), ColumnInfo.COLUMN_TYPE_TEXT, true), new ColumnInfo(BaseMessages.getString(PKG, "StarModelDialog.ColumnInfo.SourceDatabase.Label"), ColumnInfo.COLUMN_TYPE_CCOMBO, databaseNames), new ColumnInfo(BaseMessages.getString(PKG, "StarModelDialog.ColumnInfo.SourceTable.Label"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "StarModelDialog.ColumnInfo.SourceColumn.Label"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "StarModelDialog.ColumnInfo.ConversionLogicRemarks.Label"), ColumnInfo.COLUMN_TYPE_TEXT, false) };
    wFactAttributes = new TableView(new Variables(), wFactComp, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, factColumns, FieldsRows, null, props);
    FormData fdFactAttributes = new FormData();
    fdFactAttributes.left = new FormAttachment(0, 0);
    fdFactAttributes.top = new FormAttachment(wlAtrributes, margin);
    fdFactAttributes.right = new FormAttachment(100, 0);
    fdFactAttributes.bottom = new FormAttachment(wAddDimensionKeys, -margin * 2);
    wFactAttributes.setLayoutData(fdFactAttributes);
    FormData fdFactComp = new FormData();
    fdFactComp.left = new FormAttachment(0, 0);
    fdFactComp.top = new FormAttachment(0, 0);
    fdFactComp.right = new FormAttachment(100, 0);
    fdFactComp.bottom = new FormAttachment(100, 0);
    wFactComp.setLayoutData(fdFactComp);
    wFactComp.layout();
    wFactTab.setControl(wFactComp);
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) Text(org.eclipse.swt.widgets.Text) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) CTabItem(org.eclipse.swt.custom.CTabItem) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Variables(org.pentaho.di.core.variables.Variables) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment) TableView(org.pentaho.di.ui.core.widget.TableView)

Example 95 with Variables

use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.

the class StarModelerPerspective method addModelsGroupToDomainTab.

private Control addModelsGroupToDomainTab(final StarDomain starDomain, final XulTabAndPanel tabAndPanel, Composite parentComposite) {
    PropsUI props = PropsUI.getInstance();
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Add a group for the logical stars
    // 
    final Group logicalGroup = new Group(parentComposite, SWT.SHADOW_NONE);
    props.setLook(logicalGroup);
    logicalGroup.setText(BaseMessages.getString(PKG, "StarModelerPerspective.LogicalGroup.Label"));
    FormLayout groupLayout = new FormLayout();
    groupLayout.marginLeft = 10;
    groupLayout.marginRight = 10;
    groupLayout.marginTop = 10;
    groupLayout.marginBottom = 10;
    groupLayout.spacing = margin;
    logicalGroup.setLayout(groupLayout);
    FormData fdLogicalGroup = new FormData();
    fdLogicalGroup.top = new FormAttachment(0, 0);
    fdLogicalGroup.left = new FormAttachment(0, 0);
    fdLogicalGroup.right = new FormAttachment(100, 0);
    logicalGroup.setLayoutData(fdLogicalGroup);
    // Add a line to edit the name of the logical domain
    // 
    Label nameLabel = new Label(logicalGroup, SWT.RIGHT);
    props.setLook(nameLabel);
    nameLabel.setText(BaseMessages.getString(PKG, "StarModelerPerspective.DomainName.Label"));
    FormData fdNameLabel = new FormData();
    fdNameLabel.left = new FormAttachment(0, 0);
    fdNameLabel.right = new FormAttachment(middle, 0);
    fdNameLabel.top = new FormAttachment(0, 0);
    nameLabel.setLayoutData(fdNameLabel);
    final Text nameText = new Text(logicalGroup, SWT.BORDER | SWT.SINGLE);
    props.setLook(nameText);
    nameText.setText(Const.NVL(starDomain.getDomain().getName(defaultLocale), ""));
    FormData fdNameText = new FormData();
    fdNameText.left = new FormAttachment(middle, margin);
    fdNameText.right = new FormAttachment(100, 0);
    fdNameText.top = new FormAttachment(0, 0);
    nameText.setLayoutData(fdNameText);
    nameText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            starDomain.getDomain().setName(new LocalizedString(defaultLocale, nameText.getText()));
            setNameForTab(tabAndPanel.tab, starDomain.getDomain().getName(defaultLocale));
        }
    });
    Control lastControl = nameText;
    // Add a line to edit the name of the logical domain
    // 
    Label descriptionLabel = new Label(logicalGroup, SWT.RIGHT);
    props.setLook(descriptionLabel);
    descriptionLabel.setText(BaseMessages.getString(PKG, "StarModelerPerspective.DomainDescription.Label"));
    FormData fdDescriptionLabel = new FormData();
    fdDescriptionLabel.left = new FormAttachment(0, 0);
    fdDescriptionLabel.right = new FormAttachment(middle, 0);
    fdDescriptionLabel.top = new FormAttachment(lastControl, margin);
    descriptionLabel.setLayoutData(fdDescriptionLabel);
    final Text descriptionText = new Text(logicalGroup, SWT.BORDER | SWT.SINGLE);
    props.setLook(descriptionText);
    descriptionText.setText(Const.NVL(starDomain.getDomain().getDescription(defaultLocale), ""));
    FormData fdDescriptionText = new FormData();
    fdDescriptionText.left = new FormAttachment(middle, 5);
    fdDescriptionText.right = new FormAttachment(100, 0);
    fdDescriptionText.top = new FormAttachment(lastControl, margin);
    descriptionText.setLayoutData(fdDescriptionText);
    descriptionText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            starDomain.getDomain().setDescription(new LocalizedString(defaultLocale, descriptionText.getText()));
        }
    });
    lastControl = descriptionText;
    // Then we'll add a table view of all the models and their descriptions
    // 
    Label modelsLabel = new Label(logicalGroup, SWT.RIGHT);
    props.setLook(modelsLabel);
    modelsLabel.setText(BaseMessages.getString(PKG, "StarModelerPerspective.DomainModels.Label"));
    FormData fdModelsLabel = new FormData();
    fdModelsLabel.left = new FormAttachment(0, 0);
    fdModelsLabel.right = new FormAttachment(middle, 0);
    fdModelsLabel.top = new FormAttachment(lastControl, margin);
    modelsLabel.setLayoutData(fdModelsLabel);
    ColumnInfo[] colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "StarModelerPerspective.ModelName.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false, true), new ColumnInfo(BaseMessages.getString(PKG, "StarModelerPerspective.ModelDescription.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false, true) };
    final TableView modelsList = new TableView(new Variables(), logicalGroup, SWT.BORDER, colinf, 1, null, props);
    modelsList.setReadonly(true);
    modelsList.table.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            if (modelsList.getSelectionIndex() < 0)
                return;
            TableItem item = modelsList.table.getSelection()[0];
            String name = item.getText(1);
            if (editModel(logicalGroup.getShell(), starDomain, defaultLocale, name)) {
                refreshModelsList(starDomain, modelsList);
            }
        }
    });
    refreshModelsList(starDomain, modelsList);
    FormData fdModelsList = new FormData();
    fdModelsList.top = new FormAttachment(lastControl, margin);
    fdModelsList.bottom = new FormAttachment(lastControl, 250);
    fdModelsList.left = new FormAttachment(middle, margin);
    fdModelsList.right = new FormAttachment(100, 0);
    modelsList.setLayoutData(fdModelsList);
    lastControl = modelsList;
    // A few buttons to edit the list
    // 
    Button newModelButton = new Button(logicalGroup, SWT.PUSH);
    newModelButton.setText(BaseMessages.getString(PKG, "StarModelerPerspective.Button.NewModel"));
    FormData fdNewModelButton = new FormData();
    fdNewModelButton.top = new FormAttachment(lastControl, margin);
    fdNewModelButton.left = new FormAttachment(middle, margin);
    newModelButton.setLayoutData(fdNewModelButton);
    newModelButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (newModel(logicalGroup.getShell(), starDomain)) {
                refreshModelsList(starDomain, modelsList);
            }
        }
    });
    Button editModelButton = new Button(logicalGroup, SWT.PUSH);
    editModelButton.setText(BaseMessages.getString(PKG, "StarModelerPerspective.Button.EditModel"));
    FormData fdEditModelButton = new FormData();
    fdEditModelButton.top = new FormAttachment(lastControl, margin);
    fdEditModelButton.left = new FormAttachment(newModelButton, margin);
    editModelButton.setLayoutData(fdEditModelButton);
    editModelButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (modelsList.getSelectionIndex() < 0)
                return;
            TableItem item = modelsList.table.getSelection()[0];
            String name = item.getText(1);
            if (editModel(logicalGroup.getShell(), starDomain, defaultLocale, name)) {
                refreshModelsList(starDomain, modelsList);
            }
        }
    });
    Button delModelButton = new Button(logicalGroup, SWT.PUSH);
    delModelButton.setText(BaseMessages.getString(PKG, "StarModelerPerspective.Button.DeleteModel"));
    FormData fdDelModelButton = new FormData();
    fdDelModelButton.top = new FormAttachment(lastControl, margin);
    fdDelModelButton.left = new FormAttachment(editModelButton, margin);
    delModelButton.setLayoutData(fdDelModelButton);
    delModelButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (modelsList.getSelectionIndex() < 0)
                return;
            TableItem item = modelsList.table.getSelection()[0];
            String name = item.getText(1);
            if (deleteModel(logicalGroup.getShell(), starDomain, defaultLocale, name)) {
                refreshModelsList(starDomain, modelsList);
            }
        }
    });
    return logicalGroup;
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Group(org.eclipse.swt.widgets.Group) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) Text(org.eclipse.swt.widgets.Text) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) PropsUI(org.pentaho.di.ui.core.PropsUI) Variables(org.pentaho.di.core.variables.Variables) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment) TableView(org.pentaho.di.ui.core.widget.TableView)

Aggregations

Variables (org.pentaho.di.core.variables.Variables)119 Test (org.junit.Test)67 TransMeta (org.pentaho.di.trans.TransMeta)31 ArrayList (java.util.ArrayList)25 CheckResultInterface (org.pentaho.di.core.CheckResultInterface)20 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)20 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)20 StepMeta (org.pentaho.di.trans.step.StepMeta)18 RowMeta (org.pentaho.di.core.row.RowMeta)17 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)16 VariableSpace (org.pentaho.di.core.variables.VariableSpace)14 Repository (org.pentaho.di.repository.Repository)12 TableView (org.pentaho.di.ui.core.widget.TableView)10 FormAttachment (org.eclipse.swt.layout.FormAttachment)9 FormData (org.eclipse.swt.layout.FormData)9 ColumnInfo (org.pentaho.di.ui.core.widget.ColumnInfo)9 Label (org.eclipse.swt.widgets.Label)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)7