Search in sources :

Example 1 with AttributeEditorFactory

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

the class ParameterEditorExtension method createEditor.

/**
 * Create an editor for a parameter.
 *
 * @param parent the parent composite
 * @param functionId the ID of the function the parameter is associated with
 * @param parameter the parameter
 * @param initialValue the initial value, may be <code>null</code>
 * @return the editor
 */
public AttributeEditor<?> createEditor(final Composite parent, final String functionId, final FunctionParameterDefinition parameter, final ParameterValue initialValue) {
    List<ParameterEditorFactory> factories = getFactories(new FactoryFilter<EditorFactory, ParameterEditorFactory>() {

        @Override
        public boolean acceptFactory(ParameterEditorFactory factory) {
            return factory.getParameterName().equals(parameter.getName()) && factory.getFunctionId().equals(functionId);
        }

        @Override
        public boolean acceptCollection(ExtensionObjectFactoryCollection<EditorFactory, ParameterEditorFactory> collection) {
            return true;
        }
    });
    if (!factories.isEmpty()) {
        ParameterEditorFactory fact = factories.get(0);
        try {
            AttributeEditor<?> editor = fact.createExtensionObject().createEditor(parent);
            if (initialValue != null)
                editor.setAsText(initialValue.as(String.class));
            return editor;
        } catch (Exception e) {
            // ignore, use default
            log.error("Could not create editor for parameter, using default editor instead.");
        }
    }
    // default editor
    AttributeEditorFactory aef = PlatformUI.getWorkbench().getService(AttributeEditorFactory.class);
    // set variable replacer
    AttributeEditor<?> editor = aef.createEditor(parent, parameter, initialValue);
    editor.setVariableReplacer(new TransformationVariableReplacer());
    return editor;
}
Also used : TransformationVariableReplacer(eu.esdihumboldt.hale.ui.transformation.TransformationVariableReplacer) EditorFactory(eu.esdihumboldt.hale.ui.common.EditorFactory) AttributeEditorFactory(eu.esdihumboldt.hale.ui.common.definition.AttributeEditorFactory) AttributeEditorFactory(eu.esdihumboldt.hale.ui.common.definition.AttributeEditorFactory)

Example 2 with AttributeEditorFactory

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

the class IdentifierParameterPage method createContent.

@Override
protected void createContent(Composite parent) {
    boolean relayout = this.parent != null;
    this.parent = parent;
    lastEntity = determineTargetEntity();
    if (lastEntity == null) {
        setPageComplete(false);
        // can't create controls
        return;
    }
    if (page != null) {
        // page was created before
        initialCountry = countryCode.getText();
        initialProvider = providerName.getText();
        initialProduct = productName.getText();
        initialVersion = version.getText();
        initialVersionNil = nilEditor.getAsText();
        page.dispose();
    }
    PropertyFunctionDefinition function = FunctionUtil.getPropertyFunction(ID, HaleUI.getServiceProvider());
    // create a composite to hold the widgets
    page = new Composite(parent, SWT.NULL);
    setControl(page);
    // create layout for this wizard page
    GridLayout gl = GridLayoutFactory.fillDefaults().create();
    page.setLayout(gl);
    AttributeEditorFactory aef = PlatformUI.getWorkbench().getService(AttributeEditorFactory.class);
    DefinitionLabelFactory dlf = PlatformUI.getWorkbench().getService(DefinitionLabelFactory.class);
    // identifier type
    TypeDefinition identifierType = null;
    Definition<?> def = lastEntity.getDefinition();
    if (def instanceof PropertyDefinition) {
        TypeDefinition typeDef = ((PropertyDefinition) def).getPropertyType();
        for (ChildDefinition<?> child : typeDef.getChildren()) {
            if (child.asProperty() != null && child.asProperty().getPropertyType().getName().getLocalPart().equals("IdentifierType")) {
                identifierType = child.asProperty().getPropertyType();
            }
        }
    }
    // Namespace group
    Group nsGroup = new Group(page, SWT.NONE);
    nsGroup.setText(Messages.IdentifierFunctionWizardPage_2);
    nsGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    nsGroup.setLayout(// 
    GridLayoutFactory.swtDefaults().numColumns(// 
    2).spacing(8, // 
    4).create());
    // localId
    if (identifierType != null) {
        // $NON-NLS-1$
        PropertyDefinition propDef = null;
        for (ChildDefinition<?> child : identifierType.getChildren()) {
            String localName = child.getName().getLocalPart();
            if (localName.equals("namespace")) {
                if (child.asProperty() != null) {
                    propDef = child.asProperty();
                }
            }
        }
        if (propDef != null) {
            Control nsLabel = dlf.createLabel(nsGroup, propDef, false);
            nsLabel.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
            Label nsDesc = new Label(nsGroup, SWT.NONE);
            nsDesc.setText(Messages.IdentifierFunctionWizardPage_4);
        }
    }
    // Country code
    Label ccLabel = new Label(nsGroup, SWT.NONE);
    ccLabel.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
    ccLabel.setText(Messages.IdentifierFunctionWizardPage_5);
    FunctionParameterDefinition param = function.getParameter(COUNTRY_PARAMETER_NAME);
    configureParameterLabel(ccLabel, param);
    this.countryCode = new Text(nsGroup, SWT.BORDER | SWT.SINGLE);
    // $NON-NLS-1$
    this.countryCode.setText(initialCountry);
    this.countryCode.setEnabled(true);
    this.countryCode.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    // Provider name
    Label providerLabel = new Label(nsGroup, SWT.NONE);
    providerLabel.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
    providerLabel.setText(Messages.IdentifierFunctionWizardPage_7);
    param = function.getParameter(DATA_PROVIDER_PARAMETER_NAME);
    configureParameterLabel(providerLabel, param);
    this.providerName = new Text(nsGroup, SWT.BORDER | SWT.SINGLE);
    // $NON-NLS-1$
    this.providerName.setText(initialProvider);
    this.providerName.setEnabled(true);
    this.providerName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    // Product name
    Label productLabel = new Label(nsGroup, SWT.NONE);
    productLabel.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
    productLabel.setText(Messages.IdentifierFunctionWizardPage_9);
    param = function.getParameter(PRODUCT_PARAMETER_NAME);
    configureParameterLabel(productLabel, param);
    this.productName = new Text(nsGroup, SWT.BORDER | SWT.SINGLE);
    // $NON-NLS-1$
    this.productName.setText(initialProduct);
    this.productName.setEnabled(true);
    this.productName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    // Local ID group
    Group idGroup = new Group(page, SWT.NONE);
    idGroup.setText(Messages.IdentifierFunctionWizardPage_11);
    idGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    idGroup.setLayout(new GridLayout(2, false));
    // localId
    Control idLabel = null;
    if (identifierType != null) {
        // $NON-NLS-1$
        PropertyDefinition propDef = null;
        for (ChildDefinition<?> child : identifierType.getChildren()) {
            String LocalName = child.getName().getLocalPart();
            if (LocalName.equals("localId")) {
                if (child.asProperty() != null) {
                    propDef = child.asProperty();
                }
            }
        }
        if (propDef != null) {
            idLabel = dlf.createLabel(idGroup, propDef, false);
        }
    }
    if (idLabel == null) {
        idLabel = new Label(idGroup, SWT.NONE);
        // $NON-NLS-1$
        ((Label) idLabel).setText("localId");
    }
    idLabel.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
    Control localId = dlf.createLabel(idGroup, getWizard().getUnfinishedCell().getSource().get(null).get(0).getDefinition().getDefinition(), true);
    localId.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    // Version group
    Group versGroup = new Group(page, SWT.NONE);
    versGroup.setText(Messages.IdentifierFunctionWizardPage_14);
    versGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    versGroup.setLayout(new GridLayout(2, false));
    // Version
    Control versionLabel = null;
    if (identifierType != null) {
        // $NON-NLS-1$
        PropertyDefinition propDef = null;
        for (ChildDefinition<?> child : identifierType.getChildren()) {
            String localName = child.getName().getLocalPart();
            if (localName.equals("versionId")) {
                if (child.asProperty() != null) {
                    propDef = child.asProperty();
                }
            }
        }
        if (propDef != null) {
            versionLabel = dlf.createLabel(versGroup, propDef, false);
        }
    }
    if (versionLabel == null) {
        versionLabel = new Label(versGroup, SWT.NONE);
        ((Label) versionLabel).setText(Messages.IdentifierFunctionWizardPage_16);
    }
    versionLabel.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
    this.version = new Text(versGroup, SWT.BORDER | SWT.SINGLE);
    // $NON-NLS-1$
    this.version.setText(initialVersion);
    this.version.setEnabled(true);
    this.version.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    // version nil reason
    if (identifierType != null) {
        // $NON-NLS-1$
        PropertyDefinition propDef = null;
        for (ChildDefinition<?> child : identifierType.getChildren()) {
            String localName = child.getName().getLocalPart();
            if (localName.equals("versionId")) {
                if (child.asProperty() != null) {
                    propDef = child.asProperty();
                }
            }
        }
        if (propDef != null) {
            for (ChildDefinition<?> child : propDef.getPropertyType().getChildren()) {
                String localName = child.getName().getLocalPart();
                if (localName.equals("nilReason")) {
                    if (child.asProperty() != null) {
                        propDef = child.asProperty();
                    }
                }
            }
        }
        if (propDef != null) {
            // label
            Control nilLabel = dlf.createLabel(versGroup, propDef, false);
            nilLabel.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
            // editor
            nilEditor = aef.createEditor(versGroup, propDef, null, false);
            nilEditor.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
            // default to unknown
            nilEditor.setAsText(initialVersionNil);
        // //$NON-NLS-1$
        }
    }
    if (relayout) {
        parent.layout();
        getContainer().getShell().pack();
    }
    setPageComplete(true);
}
Also used : Group(org.eclipse.swt.widgets.Group) DefinitionLabelFactory(eu.esdihumboldt.hale.ui.common.definition.DefinitionLabelFactory) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) FunctionParameterDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition) AttributeEditorFactory(eu.esdihumboldt.hale.ui.common.definition.AttributeEditorFactory) Text(org.eclipse.swt.widgets.Text) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) GridData(org.eclipse.swt.layout.GridData) PropertyFunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.PropertyFunctionDefinition)

Example 3 with AttributeEditorFactory

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

the class SpatialDataSetConfigurationPage method createContent.

/**
 * @see HaleWizardPage#createContent(Composite)
 */
@Override
protected void createContent(Composite page) {
    GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(false).spacing(6, 12).applyTo(page);
    // Get the property definitions of localId and namespace.
    String action = getWizard().getActionId();
    SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
    SchemaSpaceID ssid = SchemaSpaceID.TARGET;
    if (InstanceIO.ACTION_SAVE_SOURCE_DATA.equals(action)) {
        ssid = SchemaSpaceID.SOURCE;
    }
    SchemaSpace target = ss.getSchemas(ssid);
    XmlIndex index = StreamGmlWriter.getXMLIndex(target);
    XmlElement sdsElement = InspireUtil.findSpatialDataSet(index);
    TypeDefinition sdsType = null;
    if (sdsElement != null) {
        sdsType = sdsElement.getType();
    }
    // applicable.
    if (sdsType == null)
        return;
    // find localId and namespace definitions
    Path<Definition<?>> localIdPath = new DefinitionAccessor(sdsType).findChildren("identifier").findChildren("Identifier").findChildren("localId").eval(false);
    List<Definition<?>> localIdDefs = localIdPath.getElements();
    PropertyDefinition localIdDef = (PropertyDefinition) localIdDefs.get(localIdDefs.size() - 1);
    Path<Definition<?>> namespacePath = new DefinitionAccessor(sdsType).findChildren("identifier").findChildren("Identifier").findChildren("namespace").eval(false);
    List<Definition<?>> namespaceDefs = namespacePath.getElements();
    PropertyDefinition nsDef = (PropertyDefinition) namespaceDefs.get(namespaceDefs.size() - 1);
    IPropertyChangeListener changeListener = new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(AttributeEditor.IS_VALID) || event.getProperty().equals(FileFieldEditor.IS_VALID))
                updateState();
        }
    };
    // inspire identifier
    Label inspireId = new Label(page, SWT.NONE);
    inspireId.setText("Please specify the local ID and the namespace as part of the INSPIRE identifier of the Spatial Data Set:");
    GridDataFactory.fillDefaults().span(2, 1).applyTo(inspireId);
    AttributeEditorFactory aef = PlatformUI.getWorkbench().getService(AttributeEditorFactory.class);
    Composite localIdtitle = new Composite(page, SWT.NONE);
    localIdtitle.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).create());
    DefinitionLabelFactory dlf = PlatformUI.getWorkbench().getService(DefinitionLabelFactory.class);
    dlf.createLabel(localIdtitle, localIdDef, false);
    Label label = new Label(localIdtitle, SWT.NONE);
    label.setText(" = ");
    localIdEditor = aef.createEditor(page, localIdDef, null, false);
    localIdEditor.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    localIdEditor.setPropertyChangeListener(changeListener);
    Composite namespacetitle = new Composite(page, SWT.NONE);
    namespacetitle.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).create());
    dlf.createLabel(namespacetitle, nsDef, false);
    label = new Label(namespacetitle, SWT.NONE);
    label.setText(" = ");
    namespaceEditor = aef.createEditor(page, nsDef, null, false);
    namespaceEditor.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    namespaceEditor.setPropertyChangeListener(changeListener);
    // spacer
    Composite spacer = new Composite(page, SWT.NONE);
    GridDataFactory.fillDefaults().hint(0, 8).applyTo(spacer);
    // metadata file
    Label metadataLabel = new Label(page, SWT.NONE);
    metadataLabel.setText("You can include metadata in the Spatial Data Set from a XML file with a MD_Metadata element:");
    GridDataFactory.fillDefaults().span(2, 1).applyTo(metadataLabel);
    // source file
    Composite fileFieldComposite = new Composite(page, SWT.NONE);
    fileFieldComposite.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1));
    metadataFile = new OpenFileFieldEditor("metadataFile", "ISO Geographic MetaData XML", true, FileFieldEditor.VALIDATE_ON_KEY_STROKE, fileFieldComposite);
    metadataFile.setPage(this);
    metadataFile.setEmptyStringAllowed(true);
    metadataFile.setFileExtensions(new String[] { "*.xml" });
    metadataFile.setPropertyChangeListener(changeListener);
    // isValid starts with false even if emptyStringAllowed is true.
    // -> force validation hack
    metadataFile.setStringValue(" ");
    metadataFile.setStringValue("");
    updateState();
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) DefinitionLabelFactory(eu.esdihumboldt.hale.ui.common.definition.DefinitionLabelFactory) Composite(org.eclipse.swt.widgets.Composite) SchemaSpace(eu.esdihumboldt.hale.common.schema.model.SchemaSpace) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) Label(org.eclipse.swt.widgets.Label) XmlIndex(eu.esdihumboldt.hale.io.xsd.model.XmlIndex) AttributeEditorFactory(eu.esdihumboldt.hale.ui.common.definition.AttributeEditorFactory) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) SchemaSpaceID(eu.esdihumboldt.hale.common.schema.SchemaSpaceID) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) OpenFileFieldEditor(eu.esdihumboldt.hale.ui.util.io.OpenFileFieldEditor) SchemaService(eu.esdihumboldt.hale.ui.service.schema.SchemaService) DefinitionAccessor(eu.esdihumboldt.hale.common.schema.groovy.DefinitionAccessor) GridData(org.eclipse.swt.layout.GridData) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement)

Aggregations

AttributeEditorFactory (eu.esdihumboldt.hale.ui.common.definition.AttributeEditorFactory)3 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)2 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)2 DefinitionLabelFactory (eu.esdihumboldt.hale.ui.common.definition.DefinitionLabelFactory)2 GridData (org.eclipse.swt.layout.GridData)2 Composite (org.eclipse.swt.widgets.Composite)2 Label (org.eclipse.swt.widgets.Label)2 FunctionParameterDefinition (eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition)1 PropertyFunctionDefinition (eu.esdihumboldt.hale.common.align.extension.function.PropertyFunctionDefinition)1 SchemaSpaceID (eu.esdihumboldt.hale.common.schema.SchemaSpaceID)1 DefinitionAccessor (eu.esdihumboldt.hale.common.schema.groovy.DefinitionAccessor)1 Definition (eu.esdihumboldt.hale.common.schema.model.Definition)1 SchemaSpace (eu.esdihumboldt.hale.common.schema.model.SchemaSpace)1 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)1 XmlIndex (eu.esdihumboldt.hale.io.xsd.model.XmlIndex)1 EditorFactory (eu.esdihumboldt.hale.ui.common.EditorFactory)1 SchemaService (eu.esdihumboldt.hale.ui.service.schema.SchemaService)1 TransformationVariableReplacer (eu.esdihumboldt.hale.ui.transformation.TransformationVariableReplacer)1 OpenFileFieldEditor (eu.esdihumboldt.hale.ui.util.io.OpenFileFieldEditor)1 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)1