Search in sources :

Example 1 with ColumnLineData

use of org.talend.designer.filemultischemas.ui.provider.column.ColumnLineData in project tdi-studio-se by Talend.

the class UIManager method validSchemaDetailsColumns.

public static String validSchemaDetailsColumns(final TreeViewer schemaDetailsViewer, final MultiMetadataColumn multiMetadataColumn, final EPropertyName property, final Object input) {
    String mess = null;
    if (input != null && input instanceof String) {
        final String value = (String) input;
        final String existedMessage = "The column name have existed.";
        if (isFirstForColumnModel(property)) {
            // for column model
            IStructuredSelection selection = (IStructuredSelection) schemaDetailsViewer.getSelection();
            if (selection != null) {
                final Object firstElement = selection.getFirstElement();
                if (firstElement != null && firstElement instanceof ColumnLineData) {
                    ColumnLineData lineData = (ColumnLineData) firstElement;
                    for (MultiMetadataColumn column : lineData.getKeyData().getMetadataColumnsInModel()) {
                        if (multiMetadataColumn != column && value.equals(column.getLabel())) {
                            mess = existedMessage;
                            break;
                        }
                    }
                }
            }
        } else {
            final String invalidInput = "Invalid input.";
            switch(property) {
                case // for property model.
                NAME:
                    IStructuredSelection selection = (IStructuredSelection) schemaDetailsViewer.getSelection();
                    if (selection != null) {
                        final Object firstElement = selection.getFirstElement();
                        if (firstElement != null && firstElement instanceof MultiMetadataColumn) {
                            MultiMetadataColumn column = (MultiMetadataColumn) firstElement;
                            for (TreeItem item : schemaDetailsViewer.getTree().getItems()) {
                                final Object data = item.getData();
                                if (data != column && data instanceof MultiMetadataColumn) {
                                    MultiMetadataColumn other = (MultiMetadataColumn) data;
                                    if (value.equals(other.getLabel())) {
                                        mess = existedMessage;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (mess == null && !value.matches(RepositoryConstants.CONTEXT_AND_VARIABLE_PATTERN)) {
                        mess = invalidInput;
                    }
                    break;
                case LENGTH:
                    if (!value.matches(ExternalMultiSchemasUIProperties.NUMBER_PATTERN)) {
                        mess = invalidInput;
                    }
                    break;
            }
        }
    }
    return mess;
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) ColumnLineData(org.talend.designer.filemultischemas.ui.provider.column.ColumnLineData) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) MultiMetadataColumn(org.talend.designer.filemultischemas.data.MultiMetadataColumn)

Aggregations

IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1 MultiMetadataColumn (org.talend.designer.filemultischemas.data.MultiMetadataColumn)1 ColumnLineData (org.talend.designer.filemultischemas.ui.provider.column.ColumnLineData)1