Search in sources :

Example 1 with HaleWizardDialog

use of eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog in project hale by halestudio.

the class WFSDescribeFeatureSource method determineSource.

@Override
protected void determineSource(URIFieldEditor sourceURL) {
    WFSDescribeFeatureConfig config = new WFSDescribeFeatureConfig();
    WFSDescribeFeatureWizard wizard = new WFSDescribeFeatureWizard(config);
    HaleWizardDialog dialog = new HaleWizardDialog(Display.getCurrent().getActiveShell(), wizard);
    if (dialog.open() == WizardDialog.OK) {
        WFSDescribeFeatureConfig result = wizard.getConfiguration();
        // create URL
        URIBuilder builder = new URIBuilder(result.getDescribeFeatureUri());
        // add fixed parameters
        builder.addParameter("SERVICE", "WFS");
        builder.addParameter("VERSION", result.getVersion().toString());
        builder.addParameter("REQUEST", "DescribeFeatureType");
        // specify type names
        if (!result.getTypeNames().isEmpty()) {
            KVPUtil.addTypeNameParameter(builder, result.getTypeNames(), result.getVersion());
        }
        try {
            sourceURL.setStringValue(builder.build().toASCIIString());
            getPage().setErrorMessage(null);
        } catch (URISyntaxException e) {
            getPage().setErrorMessage(e.getLocalizedMessage());
        }
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 2 with HaleWizardDialog

use of eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog in project hale by halestudio.

the class ClassificationMappingParameterPage method createManualTabControl.

private Control createManualTabControl(Composite tabParent) {
    // TODO load occurring value sources
    Composite tabContent = new Composite(tabParent, SWT.NONE);
    tabContent.setLayout(new GridLayout(1, true));
    ToolBar toolBar = new ToolBar(tabContent, SWT.NONE);
    toolBar.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    Composite tableContainer = new Composite(tabContent, SWT.NONE);
    tableContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    TableColumnLayout layout = new TableColumnLayout();
    tableContainer.setLayout(layout);
    tableViewer = new TableViewer(tableContainer, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
    tableViewer.getTable().setLinesVisible(true);
    tableViewer.getTable().setHeaderVisible(true);
    tableViewer.setContentProvider(ArrayContentProvider.getInstance());
    TableViewerColumn sourceColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    sourceColumn.getColumn().setText("Source value");
    layout.setColumnData(sourceColumn.getColumn(), new ColumnWeightData(1));
    sourceColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            @SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) element;
            return entry.getKey().getStringRepresentation();
        }
    });
    TableViewerColumn targetColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    targetColumn.getColumn().setText("Target value");
    layout.setColumnData(targetColumn.getColumn(), new ColumnWeightData(1));
    targetColumn.setLabelProvider(new StyledCellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            @SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) cell.getElement();
            if (entry.getValue() == null) {
                StyledString styledString = new StyledString("(unmapped)", StyledString.DECORATIONS_STYLER);
                cell.setText(styledString.getString());
                cell.setStyleRanges(styledString.getStyleRanges());
            } else {
                cell.setText(entry.getValue().getStringRepresentation());
                cell.setStyleRanges(null);
            }
            super.update(cell);
        }
    });
    tableViewer.setInput(lookupTable.entrySet());
    tableViewer.getTable().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            ViewerCell cell = tableViewer.getCell(new Point(e.x, e.y));
            if (cell != null) {
                @SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) cell.getElement();
                Value oldValue;
                Value newValue;
                if (cell.getColumnIndex() == 0) {
                    oldValue = entry.getKey();
                    newValue = selectValue(sourceProperty, sourceEntity, "Edit source value", "Enter a new source value", oldValue.getStringRepresentation());
                } else {
                    oldValue = entry.getValue();
                    String initialValue = oldValue == null ? null : oldValue.getStringRepresentation();
                    newValue = selectValue(targetProperty, targetEntity, "Edit target value", "Enter a target value", initialValue);
                }
                if (newValue == null)
                    return;
                if (cell.getColumnIndex() == 0) {
                    if (!newValue.equals(oldValue) && lookupTable.containsKey(newValue)) {
                        showDuplicateSourceWarning(newValue.getStringRepresentation());
                    } else {
                        lookupTable.put(newValue, entry.getValue());
                        lookupTable.remove(oldValue);
                        tableViewer.refresh();
                    }
                } else {
                    entry.setValue(newValue);
                    tableViewer.update(entry, null);
                }
            }
        }
    });
    final ToolItem valueAdd = new ToolItem(toolBar, SWT.PUSH);
    final ToolItem fillValues = new ToolItem(toolBar, SWT.PUSH);
    new ToolItem(toolBar, SWT.SEPARATOR);
    final ToolItem loadButton = new ToolItem(toolBar, SWT.PUSH);
    saveButton = new ToolItem(toolBar, SWT.PUSH);
    new ToolItem(toolBar, SWT.SEPARATOR);
    final ToolItem valueRemove = new ToolItem(toolBar, SWT.PUSH);
    removeAllButton = new ToolItem(toolBar, SWT.PUSH);
    valueAdd.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_ADD));
    valueAdd.setToolTipText("Add source value");
    valueAdd.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Value newSource = selectValue(sourceProperty, sourceEntity, "Add source value", "Enter a new source value", null);
            if (newSource != null) {
                if (lookupTable.containsKey(newSource))
                    showDuplicateSourceWarning(newSource.getStringRepresentation());
                else {
                    lookupTable.put(newSource, null);
                    removeAllButton.setEnabled(true);
                    saveButton.setEnabled(true);
                    tableViewer.refresh();
                }
            }
        }
    });
    loadButton.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_OPEN));
    loadButton.setToolTipText("Load classification from file");
    loadButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            LookupTableLoadWizard wizard = new LookupTableLoadWizard();
            LookupLoadAdvisor advisor = new LookupLoadAdvisor();
            wizard.setAdvisor(advisor, null);
            Shell shell = Display.getCurrent().getActiveShell();
            HaleWizardDialog dialog = new HaleWizardDialog(shell, wizard);
            dialog.open();
            if (advisor.getLookupTable() != null) {
                lookupTable.putAll(advisor.getLookupTable().getTable().asMap());
                tableViewer.refresh();
                removeAllButton.setEnabled(!lookupTable.isEmpty());
                saveButton.setEnabled(!lookupTable.isEmpty());
            }
        }
    });
    fillValues.setImage(fillValuesIcon);
    fillValues.setToolTipText("Attempt to fill source values with enumerations and occurring values.");
    fillValues.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // first try enumeration
            Enumeration<?> enumeration = sourceProperty.getPropertyType().getConstraint(Enumeration.class);
            if (enumeration.getValues() != null) {
                addSourceValuesIfNew(enumeration.getValues());
            }
            // then try occurring values
            if (!ovs.updateOccurringValues(sourceEntity)) {
                // values already there or not possible
                addOccurringSourceValues(ovs.getOccurringValues(sourceEntity));
            } else {
            // job is running, listener will be notified
            }
            removeAllButton.setEnabled(!lookupTable.isEmpty());
            saveButton.setEnabled(!lookupTable.isEmpty());
        }
    });
    saveButton.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_SAVE));
    saveButton.setToolTipText("Save classification to file");
    saveButton.setEnabled(false);
    saveButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            LookupTableExportWizard wizard = new LookupTableExportWizard();
            LookupExportAdvisor advisor = new LookupExportAdvisor(new LookupTableInfoImpl(new LookupTableImpl(lookupTable), "current", "not set"));
            wizard.setAdvisor(advisor, null);
            Shell shell = Display.getCurrent().getActiveShell();
            HaleWizardDialog dialog = new HaleWizardDialog(shell, wizard);
            dialog.open();
        }
    });
    valueRemove.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_REMOVE));
    valueRemove.setToolTipText("Remove classification entry");
    valueRemove.setEnabled(false);
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            valueRemove.setEnabled(!event.getSelection().isEmpty());
            saveButton.setEnabled(!event.getSelection().isEmpty());
        }
    });
    valueRemove.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (tableViewer.getSelection().isEmpty())
                return;
            Object element = ((IStructuredSelection) tableViewer.getSelection()).getFirstElement();
            @SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) element;
            lookupTable.remove(entry.getKey());
            tableViewer.refresh();
            removeAllButton.setEnabled(!lookupTable.isEmpty());
            saveButton.setEnabled(!lookupTable.isEmpty());
        }
    });
    removeAllButton.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_TRASH));
    removeAllButton.setEnabled(false);
    removeAllButton.setToolTipText("Remove complete classification");
    removeAllButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            lookupTable.clear();
            tableViewer.refresh();
            removeAllButton.setEnabled(false);
            saveButton.setEnabled(false);
        }
    });
    Label desc = new Label(tabContent, SWT.NONE);
    desc.setText("Double click on a table cell to change its value.");
    return tabContent;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) LookupLoadAdvisor(eu.esdihumboldt.hale.common.lookup.internal.LookupLoadAdvisor) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) StyledString(org.eclipse.jface.viewers.StyledString) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) Entry(java.util.Map.Entry) Shell(org.eclipse.swt.widgets.Shell) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) LookupTableLoadWizard(eu.esdihumboldt.hale.ui.lookup.LookupTableLoadWizard) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) ToolItem(org.eclipse.swt.widgets.ToolItem) LookupTableExportWizard(eu.esdihumboldt.hale.io.csv.ui.LookupTableExportWizard) StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) MouseEvent(org.eclipse.swt.events.MouseEvent) Enumeration(eu.esdihumboldt.hale.common.schema.model.constraint.type.Enumeration) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) MouseAdapter(org.eclipse.swt.events.MouseAdapter) LookupTableInfoImpl(eu.esdihumboldt.hale.common.lookup.impl.LookupTableInfoImpl) StyledString(org.eclipse.jface.viewers.StyledString) Point(org.eclipse.swt.graphics.Point) ViewerCell(org.eclipse.jface.viewers.ViewerCell) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) Value(eu.esdihumboldt.hale.common.core.io.Value) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) TableViewer(org.eclipse.jface.viewers.TableViewer) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog) LookupExportAdvisor(eu.esdihumboldt.hale.common.lookup.internal.LookupExportAdvisor) LookupTableImpl(eu.esdihumboldt.hale.common.lookup.impl.LookupTableImpl)

Example 3 with HaleWizardDialog

use of eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog in project hale by halestudio.

the class EditWizardAction method run.

@Override
public void run() {
    CustomPropertyFunctionWizard wizard = new CustomPropertyFunctionWizard(customFunction);
    wizard.init();
    Shell shell = Display.getCurrent().getActiveShell();
    HaleWizardDialog dialog = new HaleWizardDialog(shell, wizard);
    if (dialog.open() == HaleWizardDialog.OK) {
        alignmentService.addCustomPropertyFunction(wizard.getResultFunction());
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)

Example 4 with HaleWizardDialog

use of eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog in project hale by halestudio.

the class AbstractWizardAction method run.

/**
 * @see Action#run()
 */
@Override
public void run() {
    FunctionWizard wizard = createWizard();
    if (wizard != null) {
        // initialize the wizard
        wizard.init();
        HaleWizardDialog dialog = new HaleWizardDialog(Display.getCurrent().getActiveShell(), wizard);
        if (dialog.open() == WizardDialog.OK) {
            MutableCell cell = wizard.getResult();
            handleResult(cell);
        }
    }
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) FunctionWizard(eu.esdihumboldt.hale.ui.function.FunctionWizard) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)

Example 5 with HaleWizardDialog

use of eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog in project hale by halestudio.

the class EditRelationHandler method execute.

/**
 * @see IHandler#execute(ExecutionEvent)
 */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
        Object selected = ((IStructuredSelection) selection).getFirstElement();
        if (selected instanceof Cell) {
            final Cell originalCell = (Cell) selected;
            FunctionWizard wizard = null;
            List<FunctionWizardDescriptor<?>> factories = FunctionWizardExtension.getInstance().getFactories(new FactoryFilter<FunctionWizardFactory, FunctionWizardDescriptor<?>>() {

                @Override
                public boolean acceptFactory(FunctionWizardDescriptor<?> factory) {
                    return factory.getFunctionId().equals(originalCell.getTransformationIdentifier());
                }

                @Override
                public boolean acceptCollection(ExtensionObjectFactoryCollection<FunctionWizardFactory, FunctionWizardDescriptor<?>> collection) {
                    return true;
                }
            });
            if (!factories.isEmpty()) {
                // create registered wizard
                FunctionWizardDescriptor<?> fwd = factories.get(0);
                wizard = fwd.createEditWizard(originalCell);
            }
            if (wizard == null) {
                FunctionDefinition<?> function = FunctionUtil.getFunction(originalCell.getTransformationIdentifier(), HaleUI.getServiceProvider());
                if (function == null) {
                    log.userError(MessageFormat.format("Function with identifier ''{0}'' is unknown.", originalCell.getTransformationIdentifier()));
                    return null;
                }
                // create generic wizard
                if (function instanceof TypeFunction) {
                    wizard = new GenericTypeFunctionWizard(originalCell);
                } else {
                    wizard = new GenericPropertyFunctionWizard(originalCell);
                }
            }
            // initialize wizard
            wizard.init();
            HaleWizardDialog dialog = new HaleWizardDialog(HandlerUtil.getActiveShell(event), wizard);
            if (dialog.open() == WizardDialog.OK) {
                MutableCell cell = wizard.getResult();
                AlignmentService alignmentService = PlatformUI.getWorkbench().getService(AlignmentService.class);
                // remove the original cell
                // and add the new cell
                alignmentService.replaceCell(originalCell, cell);
            }
        }
    }
    return null;
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) FunctionWizardDescriptor(eu.esdihumboldt.hale.ui.function.extension.FunctionWizardDescriptor) FunctionWizardFactory(eu.esdihumboldt.hale.ui.function.extension.FunctionWizardFactory) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GenericTypeFunctionWizard(eu.esdihumboldt.hale.ui.function.generic.GenericTypeFunctionWizard) GenericPropertyFunctionWizard(eu.esdihumboldt.hale.ui.function.generic.GenericPropertyFunctionWizard) FunctionWizard(eu.esdihumboldt.hale.ui.function.FunctionWizard) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ISelection(org.eclipse.jface.viewers.ISelection) GenericTypeFunctionWizard(eu.esdihumboldt.hale.ui.function.generic.GenericTypeFunctionWizard) Cell(eu.esdihumboldt.hale.common.align.model.Cell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) GenericPropertyFunctionWizard(eu.esdihumboldt.hale.ui.function.generic.GenericPropertyFunctionWizard) TypeFunction(eu.esdihumboldt.hale.common.align.extension.function.TypeFunction) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)

Aggregations

HaleWizardDialog (eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)18 Shell (org.eclipse.swt.widgets.Shell)6 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)3 ISelection (org.eclipse.jface.viewers.ISelection)3 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 Composite (org.eclipse.swt.widgets.Composite)3 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)2 HaleWizardPage (eu.esdihumboldt.hale.ui.HaleWizardPage)2 FunctionWizard (eu.esdihumboldt.hale.ui.function.FunctionWizard)2 AlignmentService (eu.esdihumboldt.hale.ui.service.align.AlignmentService)2 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)2 IPageChangingListener (org.eclipse.jface.dialogs.IPageChangingListener)2 PageChangingEvent (org.eclipse.jface.dialogs.PageChangingEvent)2 TypeFunction (eu.esdihumboldt.hale.common.align.extension.function.TypeFunction)1 Cell (eu.esdihumboldt.hale.common.align.model.Cell)1 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)1