Search in sources :

Example 1 with SourceValidator

use of eu.esdihumboldt.hale.ui.util.source.SourceValidator in project hale by halestudio.

the class SourceViewerPage method createContent.

@Override
protected void createContent(Composite page) {
    // init editor
    IVerticalRuler ruler = createVerticalRuler();
    IOverviewRuler overviewRuler = createOverviewRuler();
    SourceViewerPanel<C> panel = new SourceViewerPanel<C>(page, ruler, overviewRuler, new SourceValidator() {

        @Override
        public boolean validate(String content) {
            return SourceViewerPage.this.validate(content);
        }
    }, compiler);
    viewer = panel.getViewer();
    viewer.getTextWidget().setFont(JFaceResources.getTextFont());
    viewer.addPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent event) {
            if (ValidatingSourceViewer.PROPERTY_VALID.equals(event.getProperty())) {
                getShell().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        setPageComplete((Boolean) event.getNewValue());
                    }
                });
            } else if (ValidatingSourceViewer.PROPERTY_VALIDATION_ENABLED.equals(event.getProperty())) {
                if (!((Boolean) event.getNewValue())) {
                    // if validation is disabled, automatically set the page
                    // to be complete
                    setPageComplete(true);
                }
            }
        }
    });
    configure(viewer);
    SourceViewerKeyBindings.installDefault(viewer);
    viewer.getDocument().set(initialValue);
    addActions(panel.getToolbar(), viewer);
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) IOverviewRuler(org.eclipse.jface.text.source.IOverviewRuler) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) SourceValidator(eu.esdihumboldt.hale.ui.util.source.SourceValidator) SourceViewerPanel(eu.esdihumboldt.hale.ui.util.source.SourceViewerPanel) IVerticalRuler(org.eclipse.jface.text.source.IVerticalRuler)

Example 2 with SourceValidator

use of eu.esdihumboldt.hale.ui.util.source.SourceValidator in project hale by halestudio.

the class SourceViewerParameterPage method createAndLayoutTextField.

/**
 * @see SourceListParameterPage#createAndLayoutTextField(Composite)
 */
@Override
protected SourceViewer createAndLayoutTextField(Composite parent) {
    // init editor
    IVerticalRuler verticalRuler = createVerticalRuler();
    IOverviewRuler overviewRuler = createOverviewRuler();
    SourceViewerPanel<?> panel = new SourceViewerPanel<Void>(parent, verticalRuler, overviewRuler, new SourceValidator() {

        @Override
        public boolean validate(String content) {
            return SourceViewerParameterPage.this.validate(content);
        }
    }, null);
    viewer = panel.getViewer();
    panel.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    viewer.getTextWidget().setFont(JFaceResources.getTextFont());
    viewer.addPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent event) {
            if (ValidatingSourceViewer.PROPERTY_VALID.equals(event.getProperty())) {
                getShell().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        setPageComplete((Boolean) event.getNewValue());
                    }
                });
            }
            if (ValidatingSourceViewer.PROPERTY_VALIDATION_ENABLED.equals(event.getProperty())) {
                if (!((Boolean) event.getNewValue())) {
                    // if validation is disabled, automatically set the page
                    // to be complete
                    setPageComplete(true);
                }
            }
        }
    });
    SourceViewerKeyBindings.installDefault(viewer);
    addActions(panel.getToolbar(), viewer);
    return viewer;
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) IOverviewRuler(org.eclipse.jface.text.source.IOverviewRuler) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) SourceValidator(eu.esdihumboldt.hale.ui.util.source.SourceValidator) SourceViewerPanel(eu.esdihumboldt.hale.ui.util.source.SourceViewerPanel) IVerticalRuler(org.eclipse.jface.text.source.IVerticalRuler) GridData(org.eclipse.swt.layout.GridData)

Aggregations

SourceValidator (eu.esdihumboldt.hale.ui.util.source.SourceValidator)2 SourceViewerPanel (eu.esdihumboldt.hale.ui.util.source.SourceViewerPanel)2 IOverviewRuler (org.eclipse.jface.text.source.IOverviewRuler)2 IVerticalRuler (org.eclipse.jface.text.source.IVerticalRuler)2 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)2 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)2 GridData (org.eclipse.swt.layout.GridData)1