Search in sources :

Example 1 with SimpleGroovySourceViewerConfiguration

use of eu.esdihumboldt.hale.ui.util.groovy.SimpleGroovySourceViewerConfiguration in project hale by halestudio.

the class GroovyCreatePage method createConfiguration.

@Override
protected SourceViewerConfiguration createConfiguration() {
    InstanceBuilderCompletions targetCompletions = new InstanceBuilderCompletions(definitionImages) {

        @Override
        protected TypeDefinition getTargetType() {
            Type typeEntity = (Type) CellUtil.getFirstEntity(getWizard().getUnfinishedCell().getTarget());
            if (typeEntity != null) {
                return typeEntity.getDefinition().getDefinition();
            }
            return null;
        }
    };
    HelperFunctionsCompletions functionCompletions = new HelperFunctionsCompletions(HaleUI.getServiceProvider().getService(HelperFunctionsService.class));
    return new SimpleGroovySourceViewerConfiguration(colorManager, ImmutableList.of(BINDING_BUILDER, BINDING_INDEX, BINDING_TARGET, BINDING_TARGET_TYPE, BINDING_CELL, BINDING_LOG, BINDING_CELL_CONTEXT, BINDING_FUNCTION_CONTEXT, BINDING_TRANSFORMATION_CONTEXT, BINDING_HELPER_FUNCTIONS), ImmutableList.of(targetCompletions, functionCompletions));
}
Also used : Type(eu.esdihumboldt.hale.common.align.model.Type) HelperFunctionsService(eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionsService) InstanceBuilderCompletions(eu.esdihumboldt.hale.ui.functions.groovy.internal.InstanceBuilderCompletions) HelperFunctionsCompletions(eu.esdihumboldt.hale.ui.functions.groovy.internal.HelperFunctionsCompletions) SimpleGroovySourceViewerConfiguration(eu.esdihumboldt.hale.ui.util.groovy.SimpleGroovySourceViewerConfiguration)

Example 2 with SimpleGroovySourceViewerConfiguration

use of eu.esdihumboldt.hale.ui.util.groovy.SimpleGroovySourceViewerConfiguration in project hale by halestudio.

the class GroovyTransformationPage method createConfiguration.

@Override
protected SourceViewerConfiguration createConfiguration() {
    InstanceBuilderCompletions targetCompletions = new InstanceBuilderCompletions(definitionImages) {

        @Override
        protected TypeDefinition getTargetType() {
            Property targetProperty = (Property) CellUtil.getFirstEntity(getWizard().getUnfinishedCell().getTarget());
            if (targetProperty != null) {
                return targetProperty.getDefinition().getDefinition().getPropertyType();
            }
            return null;
        }
    };
    HelperFunctionsCompletions functionCompletions = new HelperFunctionsCompletions(HaleUI.getServiceProvider().getService(HelperFunctionsService.class));
    return new SimpleGroovySourceViewerConfiguration(colorManager, ImmutableList.of(BINDING_BUILDER, BINDING_TARGET, BINDING_SOURCE_TYPES, BINDING_TARGET_TYPE, BINDING_CELL, BINDING_LOG, BINDING_CELL_CONTEXT, BINDING_FUNCTION_CONTEXT, BINDING_TRANSFORMATION_CONTEXT, BINDING_HELPER_FUNCTIONS), ImmutableList.of(targetCompletions, functionCompletions));
}
Also used : HelperFunctionsService(eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionsService) InstanceBuilderCompletions(eu.esdihumboldt.hale.ui.functions.groovy.internal.InstanceBuilderCompletions) HelperFunctionsCompletions(eu.esdihumboldt.hale.ui.functions.groovy.internal.HelperFunctionsCompletions) SimpleGroovySourceViewerConfiguration(eu.esdihumboldt.hale.ui.util.groovy.SimpleGroovySourceViewerConfiguration) Property(eu.esdihumboldt.hale.common.align.model.Property)

Example 3 with SimpleGroovySourceViewerConfiguration

use of eu.esdihumboldt.hale.ui.util.groovy.SimpleGroovySourceViewerConfiguration in project hale by halestudio.

the class TypeStructureTray method createContents.

@Override
protected Control createContents(Composite parent) {
    Composite page = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(1).applyTo(page);
    // retrieve the types
    final Collection<? extends TypeDefinition> types = this.types.getTypes();
    // heading
    Label caption = new Label(page, SWT.NONE);
    switch(schemaSpace) {
        case SOURCE:
            caption.setText("Source structure");
            break;
        case TARGET:
            caption.setText("Target structure");
            break;
    }
    caption.setFont(JFaceResources.getHeaderFont());
    // create tree viewer
    PatternFilter patternFilter = new SchemaPatternFilter();
    patternFilter.setIncludeLeadingWildcard(true);
    final FilteredTree filteredTree = new TreePathFilteredTree(page, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true);
    TreeViewer tree = filteredTree.getViewer();
    tree.setUseHashlookup(true);
    StyledDefinitionLabelProvider labelProvider = new StyledDefinitionLabelProvider(tree);
    tree.setLabelProvider(labelProvider);
    IContentProvider contentProvider = createContentProvider(tree);
    tree.setContentProvider(contentProvider);
    GridDataFactory.fillDefaults().grab(true, true).hint(280, 400).applyTo(filteredTree);
    tree.setComparator(new DefinitionComparator());
    // set input
    if (types.size() == 1) {
        tree.setInput(types.iterator().next());
    } else {
        tree.setInput(types);
    }
    /*
		 * Groovy specific part
		 */
    // caption
    Label example = new Label(page, SWT.NONE);
    switch(schemaSpace) {
        case SOURCE:
            example.setText("Examples: Access variables");
            break;
        case TARGET:
            example.setText("Example: Build instance");
            break;
        default:
            example.setText("Example");
    }
    // source viewer
    final SourceViewer viewer = new SourceViewer(page, null, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY);
    final IColorManager colorManager = new GroovyColorManager();
    SourceViewerConfiguration configuration = new SimpleGroovySourceViewerConfiguration(colorManager, ImmutableList.of(BINDING_TARGET, BINDING_BUILDER, BINDING_INDEX, BINDING_SOURCE, BINDING_SOURCE_TYPES, BINDING_TARGET_TYPE, BINDING_CELL, BINDING_LOG, BINDING_CELL_CONTEXT, BINDING_FUNCTION_CONTEXT, BINDING_TRANSFORMATION_CONTEXT), null);
    viewer.configure(configuration);
    GridDataFactory.fillDefaults().grab(true, false).hint(200, 130).applyTo(viewer.getControl());
    // make sure the color manager is disposed
    viewer.getControl().addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            colorManager.dispose();
        }
    });
    // react to tree selection changes
    tree.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IDocument doc = new Document();
            GroovySourceViewerUtil.setupDocument(doc);
            String example = null;
            if (!event.getSelection().isEmpty()) {
                switch(schemaSpace) {
                    case SOURCE:
                        example = createSourceSample(event.getSelection(), types);
                        break;
                    case TARGET:
                        example = createTargetSample(event.getSelection(), types);
                        break;
                }
            }
            if (example == null || example.isEmpty()) {
                switch(schemaSpace) {
                    case SOURCE:
                        doc.set("// Please select schema elements to access");
                        break;
                    case TARGET:
                        doc.set("// Please select which schema elements\n// to include in the instance to build");
                        break;
                    default:
                        doc.set("// Please select one or more schema elements");
                }
            } else {
                doc.set(example);
            }
            viewer.setDocument(doc);
        }
    });
    tree.setSelection(StructuredSelection.EMPTY);
    return page;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) SchemaPatternFilter(eu.esdihumboldt.hale.ui.common.definition.viewer.SchemaPatternFilter) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) SourceViewer(org.eclipse.jface.text.source.SourceViewer) Composite(org.eclipse.swt.widgets.Composite) IContentProvider(org.eclipse.jface.viewers.IContentProvider) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree) GroovyColorManager(eu.esdihumboldt.hale.ui.util.groovy.GroovyColorManager) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DefinitionComparator(eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator) IColorManager(eu.esdihumboldt.hale.ui.util.IColorManager) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) SchemaPatternFilter(eu.esdihumboldt.hale.ui.common.definition.viewer.SchemaPatternFilter) SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) SimpleGroovySourceViewerConfiguration(eu.esdihumboldt.hale.ui.util.groovy.SimpleGroovySourceViewerConfiguration) StyledDefinitionLabelProvider(eu.esdihumboldt.hale.ui.common.definition.viewer.StyledDefinitionLabelProvider) SimpleGroovySourceViewerConfiguration(eu.esdihumboldt.hale.ui.util.groovy.SimpleGroovySourceViewerConfiguration) IDocument(org.eclipse.jface.text.IDocument)

Example 4 with SimpleGroovySourceViewerConfiguration

use of eu.esdihumboldt.hale.ui.util.groovy.SimpleGroovySourceViewerConfiguration in project hale by halestudio.

the class GroovyRetypePage method createConfiguration.

@Override
protected SourceViewerConfiguration createConfiguration() {
    InstanceBuilderCompletions targetCompletions = new InstanceBuilderCompletions(definitionImages) {

        @Override
        protected TypeDefinition getTargetType() {
            Type typeEntity = (Type) CellUtil.getFirstEntity(getWizard().getUnfinishedCell().getTarget());
            if (typeEntity != null) {
                return typeEntity.getDefinition().getDefinition();
            }
            return null;
        }
    };
    HelperFunctionsCompletions functionCompletions = new HelperFunctionsCompletions(HaleUI.getServiceProvider().getService(HelperFunctionsService.class));
    return new SimpleGroovySourceViewerConfiguration(colorManager, ImmutableList.of(BINDING_BUILDER, BINDING_SOURCE, BINDING_TARGET, BINDING_SOURCE_TYPES, BINDING_TARGET_TYPE, BINDING_CELL, BINDING_LOG, BINDING_CELL_CONTEXT, BINDING_FUNCTION_CONTEXT, BINDING_TRANSFORMATION_CONTEXT, BINDING_HELPER_FUNCTIONS), ImmutableList.of(targetCompletions, functionCompletions));
}
Also used : Type(eu.esdihumboldt.hale.common.align.model.Type) HelperFunctionsService(eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionsService) InstanceBuilderCompletions(eu.esdihumboldt.hale.ui.functions.groovy.internal.InstanceBuilderCompletions) HelperFunctionsCompletions(eu.esdihumboldt.hale.ui.functions.groovy.internal.HelperFunctionsCompletions) SimpleGroovySourceViewerConfiguration(eu.esdihumboldt.hale.ui.util.groovy.SimpleGroovySourceViewerConfiguration)

Aggregations

SimpleGroovySourceViewerConfiguration (eu.esdihumboldt.hale.ui.util.groovy.SimpleGroovySourceViewerConfiguration)4 HelperFunctionsService (eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionsService)3 HelperFunctionsCompletions (eu.esdihumboldt.hale.ui.functions.groovy.internal.HelperFunctionsCompletions)3 InstanceBuilderCompletions (eu.esdihumboldt.hale.ui.functions.groovy.internal.InstanceBuilderCompletions)3 Type (eu.esdihumboldt.hale.common.align.model.Type)2 Property (eu.esdihumboldt.hale.common.align.model.Property)1 DefinitionComparator (eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator)1 SchemaPatternFilter (eu.esdihumboldt.hale.ui.common.definition.viewer.SchemaPatternFilter)1 StyledDefinitionLabelProvider (eu.esdihumboldt.hale.ui.common.definition.viewer.StyledDefinitionLabelProvider)1 IColorManager (eu.esdihumboldt.hale.ui.util.IColorManager)1 GroovyColorManager (eu.esdihumboldt.hale.ui.util.groovy.GroovyColorManager)1 TreePathFilteredTree (eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree)1 Document (org.eclipse.jface.text.Document)1 IDocument (org.eclipse.jface.text.IDocument)1 SourceViewer (org.eclipse.jface.text.source.SourceViewer)1 SourceViewerConfiguration (org.eclipse.jface.text.source.SourceViewerConfiguration)1 IContentProvider (org.eclipse.jface.viewers.IContentProvider)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1