Search in sources :

Example 1 with ProjectValidator

use of eu.esdihumboldt.hale.io.validation.ProjectValidator in project hale by halestudio.

the class FileValidateTarget method createControls.

@Override
public void createControls(Composite parent) {
    super.createControls(parent);
    // page has a 3-column grid layout
    Group validatorGroup = new Group(parent, SWT.NONE);
    validatorGroup.setText("Validation");
    validatorGroup.setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.BEGINNING).grab(true, false).span(3, 1).indent(8, 10).create());
    validatorGroup.setLayout(GridLayoutFactory.swtDefaults().numColumns(3).margins(10, 8).create());
    // Add project validator by default
    IOProviderDescriptor pvDescriptor = HaleIO.findIOProviderFactory(IOProvider.class, getWizard().getContentType(), ProjectValidator.PROVIDER_ID);
    if (pvDescriptor != null) {
        ProjectValidator projectValidator = new ProjectValidator();
        List<? extends Locatable> schemas = getWizard().getProvider().getValidationSchemas();
        projectValidator.setSchemas(schemas.toArray(new Locatable[schemas.size()]));
        ValidatorEntry entry = new ValidatorEntry(projectValidator, pvDescriptor);
        validators.add(entry);
        getWizard().addValidator(projectValidator);
    }
    // viewer with validator list
    Composite tableContainer = new Composite(validatorGroup, SWT.NONE);
    tableContainer.setLayoutData(GridDataFactory.swtDefaults().span(3, 1).minSize(100, 100).align(SWT.FILL, SWT.FILL).grab(true, true).create());
    TableColumnLayout layout = new TableColumnLayout();
    tableContainer.setLayout(layout);
    validatorsTableViewer = new TableViewer(tableContainer, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
    validatorsTableViewer.getTable().setLinesVisible(true);
    validatorsTableViewer.getTable().setHeaderVisible(true);
    validatorsTableViewer.setContentProvider(ArrayContentProvider.getInstance());
    validatorsTableViewer.setInput(validators);
    TableViewerColumn typeColumn = new TableViewerColumn(validatorsTableViewer, SWT.NONE);
    layout.setColumnData(typeColumn.getColumn(), new ColumnWeightData(4));
    typeColumn.getColumn().setText("Validator");
    typeColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ValidatorEntry validator = (ValidatorEntry) element;
            return validator.getDescriptor().getDisplayName();
        }

        /**
         * @see org.eclipse.jface.viewers.ColumnLabelProvider#getImage(java.lang.Object)
         */
        @Override
        public Image getImage(Object element) {
            ValidatorEntry validator = (ValidatorEntry) element;
            if (validator.getStatusMessage() != null && !validator.getStatusMessage().isEmpty()) {
                return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_DEC_FIELD_ERROR);
            }
            return null;
        }
    });
    TableViewerColumn errorColumn = new TableViewerColumn(validatorsTableViewer, SWT.NONE);
    layout.setColumnData(errorColumn.getColumn(), new ColumnWeightData(3));
    errorColumn.getColumn().setText("Status");
    errorColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ValidatorEntry validator = (ValidatorEntry) element;
            String message = validator.getStatusMessage();
            if (message == null || message.trim().isEmpty()) {
                message = "OK";
            }
            return message;
        }
    });
    validatorsTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            updateWizard(getSelectedValidator(event.getSelection()));
        }
    });
    // Selection dialog for adding validators to the list
    final ValidatorSelectionDialog validatorSelectionDialog = new ValidatorSelectionDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell());
    addValidatorButton = new Button(validatorGroup, SWT.PUSH);
    addValidatorButton.setText("Add validator...");
    addValidatorButton.setEnabled(false);
    addValidatorButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            validatorSelectionDialog.create();
            validatorSelectionDialog.setContentType(getWizard().getContentType());
            if (validatorSelectionDialog.open() == Dialog.OK) {
                IOProviderDescriptor selection = validatorSelectionDialog.getSelection();
                addValidator(selection);
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    // Remove button
    removeValidatorButton = new Button(validatorGroup, SWT.PUSH);
    removeValidatorButton.setText("Remove validator...");
    removeValidatorButton.setEnabled(false);
    removeValidatorButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ValidatorEntry selection = getSelectedValidator();
            getWizard().removeValidator(selection.getValidator());
            validators.remove(selection);
            updateWizard(getSelectedValidator());
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    // Configure button
    configureValidatorButton = new Button(validatorGroup, SWT.PUSH);
    configureValidatorButton.setText("Configure validator...");
    configureValidatorButton.setEnabled(false);
    getWizard().addIOWizardListener(this);
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Group(org.eclipse.swt.widgets.Group) IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ProjectValidator(eu.esdihumboldt.hale.io.validation.ProjectValidator) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Image(org.eclipse.swt.graphics.Image) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Locatable(eu.esdihumboldt.hale.common.core.io.supplier.Locatable) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)1 Locatable (eu.esdihumboldt.hale.common.core.io.supplier.Locatable)1 ProjectValidator (eu.esdihumboldt.hale.io.validation.ProjectValidator)1 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 Image (org.eclipse.swt.graphics.Image)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Group (org.eclipse.swt.widgets.Group)1