Search in sources :

Example 36 with XmlElement

use of eu.esdihumboldt.hale.io.xsd.model.XmlElement in project hale by halestudio.

the class RootElementPage method createContent.

/**
 * @see HaleWizardPage#createContent(Composite)
 */
@Override
protected void createContent(Composite page) {
    page.setLayout(new GridLayout(1, false));
    // add filter text
    filterText = new Text(page, SWT.SINGLE | SWT.BORDER);
    filterText.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    // $NON-NLS-1$
    filterText.setText("");
    // add filtered list
    list = new ListViewer(page, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    list.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof XmlElement) {
                QName name = ((XmlElement) element).getName();
                return name.getLocalPart() + " (" + name.getNamespaceURI() + ")";
            }
            if (element instanceof Definition) {
                return ((Definition<?>) element).getDisplayName();
            }
            return super.getText(element);
        }
    });
    list.setContentProvider(ArrayContentProvider.getInstance());
    GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
    layoutData.widthHint = SWT.DEFAULT;
    layoutData.heightHint = 8 * list.getList().getItemHeight();
    list.getControl().setLayoutData(layoutData);
    // page status update
    list.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            setPageComplete(!selection.isEmpty());
        }
    });
    list.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            if (canFlipToNextPage()) {
                getContainer().showPage(getNextPage());
                return;
            }
        }
    });
    // search filter & update
    list.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            String filter = filterText.getText();
            // handle empty filter
            if (filter == null || filter.isEmpty()) {
                return true;
            }
            if (element instanceof Definition) {
                Definition<?> def = (Definition<?>) element;
                filter = filter.toLowerCase();
                if (def.getDisplayName().toLowerCase().contains(filter)) {
                    return true;
                }
            }
            return false;
        }
    });
    list.setComparator(new ViewerComparator());
    filterText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            // refilter
            list.refresh();
        }
    });
    updateList();
}
Also used : ListViewer(org.eclipse.jface.viewers.ListViewer) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) ModifyListener(org.eclipse.swt.events.ModifyListener) QName(javax.xml.namespace.QName) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) Text(org.eclipse.swt.widgets.Text) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) ListViewer(org.eclipse.jface.viewers.ListViewer) Viewer(org.eclipse.jface.viewers.Viewer) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) ISelection(org.eclipse.jface.viewers.ISelection) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 37 with XmlElement

use of eu.esdihumboldt.hale.io.xsd.model.XmlElement in project hale by halestudio.

the class RootElementPage method loadPreSelection.

/**
 * @see eu.esdihumboldt.hale.ui.io.IOWizardPage#loadPreSelection(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)
 */
@Override
public void loadPreSelection(IOConfiguration conf) {
    String name = conf.getProviderConfiguration().get(StreamGmlWriter.PARAM_ROOT_ELEMENT_NAME).getStringRepresentation();
    String namespace = conf.getProviderConfiguration().get(StreamGmlWriter.PARAM_ROOT_ELEMENT_NAMESPACE).getStringRepresentation();
    String elementName = namespace + "/" + name;
    SchemaSpace schemas = getWizard().getProvider().getTargetSchema();
    XmlIndex index = StreamGmlWriter.getXMLIndex(schemas);
    for (XmlElement element : index.getElements().values()) {
        if (element.getIdentifier().equals(elementName)) {
            list.setSelection(new StructuredSelection(element), true);
        }
    }
}
Also used : SchemaSpace(eu.esdihumboldt.hale.common.schema.model.SchemaSpace) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XmlIndex(eu.esdihumboldt.hale.io.xsd.model.XmlIndex) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement)

Aggregations

XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)37 QName (javax.xml.namespace.QName)23 XmlIndex (eu.esdihumboldt.hale.io.xsd.model.XmlIndex)16 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)14 XmlElements (eu.esdihumboldt.hale.io.xsd.constraint.XmlElements)12 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)11 URI (java.net.URI)11 Test (org.junit.Test)9 HashSet (java.util.HashSet)7 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)6 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)4 SchemaSpace (eu.esdihumboldt.hale.common.schema.model.SchemaSpace)4 IOException (java.io.IOException)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)3 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)3 DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)3 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)3 File (java.io.File)3 ValueList (eu.esdihumboldt.hale.common.core.io.ValueList)2