Search in sources :

Example 1 with StyledDefinitionLabelProvider

use of eu.esdihumboldt.hale.ui.common.definition.viewer.StyledDefinitionLabelProvider in project hale by halestudio.

the class ViewerEntityTray method createContents.

@Override
protected Control createContents(Composite parent) {
    Composite page = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().applyTo(page);
    // text / description
    Label label = new Label(page, SWT.WRAP);
    label.setText("An entity that is referenced in a mapping cell cannot be resolved. This may be due to a changed schema, with for instance changed namespaces or property names. To update the cell please select a replacement entity to the left, a candidate may already be selected. Press Skip to leave the cell entity unchanged or Cancel to skip all remaining entities.\n\nBelow is a (inaccurate) reconstruction of the original entity for reference:");
    GridDataFactory.swtDefaults().hint(300, SWT.DEFAULT).applyTo(label);
    // viewer for dummy entity
    TreeViewer viewer = new TreeViewer(page, SWT.BORDER);
    viewer.setContentProvider(new EntityContentProvider());
    viewer.setLabelProvider(new StyledDefinitionLabelProvider(viewer));
    viewer.setInput(Collections.singleton(entity));
    viewer.getControl().setEnabled(false);
    viewer.expandAll();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getControl());
    return page;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) StyledDefinitionLabelProvider(eu.esdihumboldt.hale.ui.common.definition.viewer.StyledDefinitionLabelProvider) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Label(org.eclipse.swt.widgets.Label)

Example 2 with StyledDefinitionLabelProvider

use of eu.esdihumboldt.hale.ui.common.definition.viewer.StyledDefinitionLabelProvider in project hale by halestudio.

the class SourceListParameterPage method createContent.

/**
 * @see HaleWizardPage#createContent(Composite)
 */
@Override
protected void createContent(Composite page) {
    GridLayout layout = GridLayoutFactory.swtDefaults().create();
    // Add margin to leave space for control decorations
    layout.marginLeft = 5;
    layout.marginRight = 5;
    page.setLayout(layout);
    // input field
    textField = createAndLayoutTextField(page);
    // let subclasses for example add validation
    configure(textField);
    addContentProposalProvider(projectVariablesProposalsProvider);
    setText(textField, initialValue);
    // variables
    Label label = new Label(page, SWT.NONE);
    label.setText("Available variables (double click to insert)");
    label.setLayoutData(GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.CENTER).indent(4, 12).create());
    // variables table
    Composite tableComposite = new Composite(page, SWT.NONE);
    tableComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).hint(SWT.DEFAULT, 100).create());
    TableColumnLayout columnLayout = new TableColumnLayout();
    tableComposite.setLayout(columnLayout);
    varTable = new TableViewer(tableComposite, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
    varTable.getTable().setHeaderVisible(true);
    TableViewerColumn entityColumn = new TableViewerColumn(varTable, SWT.NONE);
    columnLayout.setColumnData(entityColumn.getColumn(), new ColumnWeightData(2, true));
    entityColumn.getColumn().setText("Entity");
    varTable.setContentProvider(ArrayContentProvider.getInstance());
    varTable.setLabelProvider(new StyledDefinitionLabelProvider(varTable) {

        @Override
        protected Object extractElement(Object element) {
            if (element instanceof Entry) {
                return ((Entry<?, ?>) element).getKey();
            }
            return super.extractElement(element);
        }
    });
    varTable.getTable().addMouseListener(new MouseAdapter() {

        /**
         * @see MouseAdapter#mouseDoubleClick(MouseEvent)
         */
        @Override
        public void mouseDoubleClick(MouseEvent e) {
            ISelection sel = varTable.getSelection();
            if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
                Object selected = ((IStructuredSelection) sel).getFirstElement();
                if (selected instanceof Entry) {
                    selected = ((Entry<?, ?>) selected).getValue();
                }
                insertTextAtCurrentPos(textField, selected.toString());
            }
        }
    });
    // variable name column
    TableViewerColumn varColumn = new TableViewerColumn(varTable, SWT.NONE);
    columnLayout.setColumnData(varColumn.getColumn(), new ColumnWeightData(1, true));
    varColumn.getColumn().setText("Variable");
    varColumn.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            Object element = cell.getElement();
            if (element instanceof Entry) {
                element = ((Entry<?, ?>) element).getValue();
            }
            cell.setText(element.toString());
        }
    });
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ViewerCell(org.eclipse.jface.viewers.ViewerCell) GridLayout(org.eclipse.swt.layout.GridLayout) Entry(java.util.Map.Entry) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) StyledDefinitionLabelProvider(eu.esdihumboldt.hale.ui.common.definition.viewer.StyledDefinitionLabelProvider) ISelection(org.eclipse.jface.viewers.ISelection) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider)

Example 3 with StyledDefinitionLabelProvider

use of eu.esdihumboldt.hale.ui.common.definition.viewer.StyledDefinitionLabelProvider 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 StyledDefinitionLabelProvider

use of eu.esdihumboldt.hale.ui.common.definition.viewer.StyledDefinitionLabelProvider in project hale by halestudio.

the class JoinParameterPage method createContent.

/**
 * @see eu.esdihumboldt.hale.ui.HaleWizardPage#createContent(org.eclipse.swt.widgets.Composite)
 */
@Override
protected void createContent(Composite page) {
    page.setLayout(new GridLayout(2, false));
    Label intro = new Label(page, SWT.NONE);
    intro.setText("Select the join order. Focus will happen on the topmost type.");
    intro.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false, 2, 1));
    table = new TableViewer(page, SWT.V_SCROLL | SWT.BORDER | SWT.SINGLE);
    table.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2));
    table.setLabelProvider(new StyledDefinitionLabelProvider(table));
    table.setContentProvider(ArrayContentProvider.getInstance());
    table.setInput(types);
    final Button up = new Button(page, SWT.PUSH);
    final Button down = new Button(page, SWT.PUSH);
    upIcon = CoreFunctionsUIPlugin.getImageDescriptor("icons/nav_up.gif").createImage();
    up.setImage(upIcon);
    up.setLayoutData(new GridData(SWT.CENTER, SWT.BEGINNING, false, false));
    up.setEnabled(false);
    up.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int index = getCurrentSelection();
            if (index > 0) {
                swapTypes(index - 1, index);
                if (index - 1 == 0)
                    up.setEnabled(false);
                down.setEnabled(true);
            }
        }
    });
    downIcon = CoreFunctionsUIPlugin.getImageDescriptor("icons/nav_down.gif").createImage();
    down.setImage(downIcon);
    down.setLayoutData(new GridData(SWT.CENTER, SWT.BEGINNING, false, false));
    down.setEnabled(false);
    down.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int index = getCurrentSelection();
            if (index + 1 < types.size()) {
                swapTypes(index, index + 1);
                if (index + 2 == types.size())
                    down.setEnabled(false);
                up.setEnabled(true);
            }
        }
    });
    table.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            int index = getCurrentSelection();
            if (index < 0) {
                down.setEnabled(false);
                up.setEnabled(false);
            } else {
                down.setEnabled(index + 1 < types.size());
                up.setEnabled(index > 0);
            }
        }
    });
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) StyledDefinitionLabelProvider(eu.esdihumboldt.hale.ui.common.definition.viewer.StyledDefinitionLabelProvider) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 5 with StyledDefinitionLabelProvider

use of eu.esdihumboldt.hale.ui.common.definition.viewer.StyledDefinitionLabelProvider in project hale by halestudio.

the class SpatialJoinParameterPage method createContent.

/**
 * @see eu.esdihumboldt.hale.ui.HaleWizardPage#createContent(org.eclipse.swt.widgets.Composite)
 */
@Override
protected void createContent(Composite page) {
    page.setLayout(new GridLayout(2, false));
    Label intro = new Label(page, SWT.NONE);
    intro.setText("Select the join order. Focus will happen on the topmost type.");
    intro.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false, 2, 1));
    table = new TableViewer(page, SWT.V_SCROLL | SWT.BORDER | SWT.SINGLE);
    table.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2));
    table.setLabelProvider(new StyledDefinitionLabelProvider(table));
    table.setContentProvider(ArrayContentProvider.getInstance());
    table.setInput(types);
    final Button up = new Button(page, SWT.PUSH);
    final Button down = new Button(page, SWT.PUSH);
    upIcon = GeometricFunctionsUIPlugin.getImageDescriptor("icons/nav_up.gif").createImage();
    up.setImage(upIcon);
    up.setLayoutData(new GridData(SWT.CENTER, SWT.BEGINNING, false, false));
    up.setEnabled(false);
    up.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int index = getCurrentSelection();
            if (index > 0) {
                swapTypes(index - 1, index);
                if (index - 1 == 0)
                    up.setEnabled(false);
                down.setEnabled(true);
            }
        }
    });
    downIcon = GeometricFunctionsUIPlugin.getImageDescriptor("icons/nav_down.gif").createImage();
    down.setImage(downIcon);
    down.setLayoutData(new GridData(SWT.CENTER, SWT.BEGINNING, false, false));
    down.setEnabled(false);
    down.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int index = getCurrentSelection();
            if (index + 1 < types.size()) {
                swapTypes(index, index + 1);
                if (index + 2 == types.size())
                    down.setEnabled(false);
                up.setEnabled(true);
            }
        }
    });
    table.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            int index = getCurrentSelection();
            if (index < 0) {
                down.setEnabled(false);
                up.setEnabled(false);
            } else {
                down.setEnabled(index + 1 < types.size());
                up.setEnabled(index > 0);
            }
        }
    });
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) StyledDefinitionLabelProvider(eu.esdihumboldt.hale.ui.common.definition.viewer.StyledDefinitionLabelProvider) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

StyledDefinitionLabelProvider (eu.esdihumboldt.hale.ui.common.definition.viewer.StyledDefinitionLabelProvider)7 Label (org.eclipse.swt.widgets.Label)5 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)3 TableViewer (org.eclipse.jface.viewers.TableViewer)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 EntityDefinitionService (eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService)2 EntityTypeIndexContentProvider (eu.esdihumboldt.hale.ui.service.entity.util.EntityTypeIndexContentProvider)2 EntityTypeIndexHierarchy (eu.esdihumboldt.hale.ui.service.entity.util.EntityTypeIndexHierarchy)2 SchemaService (eu.esdihumboldt.hale.ui.service.schema.SchemaService)2 TreePathProviderAdapter (eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathProviderAdapter)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridData (org.eclipse.swt.layout.GridData)2 Button (org.eclipse.swt.widgets.Button)2 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)1