Search in sources :

Example 41 with IPropertyChangeListener

use of org.eclipse.jface.util.IPropertyChangeListener in project hale by halestudio.

the class FileSource method createControls.

/**
 * @see ImportSource#createControls(Composite)
 */
@Override
public void createControls(Composite parent) {
    parent.setLayout(new GridLayout(4, false));
    ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
    projectLocation = ps.getLoadLocation() == null ? null : ps.getLoadLocation();
    boolean projectLocAvailable = projectLocation != null && "file".equals(projectLocation.getScheme());
    // source file
    sourceFile = new FileSourceFileFieldEditor("sourceFile", "Source file:", FileFieldEditor.VALIDATE_ON_KEY_STROKE, parent, projectLocation);
    sourceFile.setEmptyStringAllowed(false);
    sourceFile.setPage(getPage());
    // set content types for file field
    Collection<IOProviderDescriptor> factories = getConfiguration().getFactories();
    supportedTypes = new HashSet<IContentType>();
    for (IOProviderDescriptor factory : factories) {
        supportedTypes.addAll(factory.getSupportedTypes());
    }
    sourceFile.setContentTypes(supportedTypes);
    sourceFile.setPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(FieldEditor.IS_VALID)) {
                updateState(true);
            } else if (event.getProperty().equals(FieldEditor.VALUE)) {
                updateState(true);
            }
        }
    });
    // provider selection
    // label
    Label providerLabel = new Label(parent, SWT.NONE);
    providerLabel.setText("Import as");
    // create provider combo
    ComboViewer providers = createProviders(parent);
    providers.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 3, 1));
    final Button relativeCheck = new Button(parent, SWT.CHECK);
    String text = "Use relative paths if possible.";
    relativeCheck.setText("Use relative paths if possible.");
    relativeCheck.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            sourceFile.setUseRelativeIfPossible(relativeCheck.getSelection());
        }
    });
    if (!projectLocAvailable) {
        relativeCheck.setEnabled(false);
        text += " Only available once the project is saved to a file.";
    }
    relativeCheck.setText(text);
    relativeCheck.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 4, 1));
    // initial state update
    updateState(true);
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) IContentType(org.eclipse.core.runtime.content.IContentType) GridLayout(org.eclipse.swt.layout.GridLayout) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 42 with IPropertyChangeListener

use of org.eclipse.jface.util.IPropertyChangeListener in project hale by halestudio.

the class URLSource method createControls.

/**
 * @see ImportSource#createControls(Composite)
 */
@Override
public void createControls(Composite parent) {
    parent.setLayout(new GridLayout(3, false));
    detectImage = HALEUIPlugin.getImageDescriptor("icons/find_obj.gif").createImage();
    // source file
    sourceURL = new URLSourceURIFieldEditor("sourceURL", "Source URL:", parent) {

        @Override
        protected void onHistorySelected(URI location, IContentType contentType) {
            // select the content type associated with the recent URL
            types.setSelection(new StructuredSelection(contentType));
            updateState(false);
        }
    };
    sourceURL.setPage(getPage());
    // set content types for file field
    Collection<IOProviderDescriptor> factories = getConfiguration().getFactories();
    supportedTypes = new HashSet<IContentType>();
    for (IOProviderDescriptor factory : factories) {
        supportedTypes.addAll(factory.getSupportedTypes());
    }
    sourceURL.setContentTypes(supportedTypes);
    sourceURL.setPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(FieldEditor.IS_VALID)) {
                getPage().setMessage(null);
                updateState(false);
            } else if (event.getProperty().equals(FieldEditor.VALUE)) {
                getPage().setMessage(null);
                updateState(false);
            }
        }
    });
    // content type selection
    // label
    Label typesLabel = new Label(parent, SWT.NONE);
    typesLabel.setText("Content type");
    // types combo
    Composite group = new Composite(parent, SWT.NONE);
    group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
    group.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).create());
    types = new ComboViewer(group, SWT.DROP_DOWN | SWT.READ_ONLY);
    types.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    types.setContentProvider(ArrayContentProvider.getInstance());
    types.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof IContentType) {
                return ((IContentType) element).getName();
            }
            return super.getText(element);
        }
    });
    types.setInput(supportedTypes);
    // process selection changes
    types.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            updateState(true);
        }
    });
    // detect button
    detect = new Button(group, SWT.PUSH);
    detect.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    detect.setText("Detect");
    detect.setImage(detectImage);
    detect.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            runDetectContentType();
        }
    });
    // provider selection
    // label
    Label providerLabel = new Label(parent, SWT.NONE);
    providerLabel.setText("Import as");
    // create provider combo
    ComboViewer providers = createProviders(parent);
    providers.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1));
    // initial state update
    updateState(true);
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Label(org.eclipse.swt.widgets.Label) IContentType(org.eclipse.core.runtime.content.IContentType) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) URI(java.net.URI) GridLayout(org.eclipse.swt.layout.GridLayout) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 43 with IPropertyChangeListener

use of org.eclipse.jface.util.IPropertyChangeListener in project hale by halestudio.

the class URLTarget method createControls.

/**
 * @see eu.esdihumboldt.hale.ui.io.ExportTarget#createControls(org.eclipse.swt.widgets.Composite)
 */
@Override
public void createControls(Composite parent) {
    parent.setLayout(new GridLayout(3, false));
    // source file
    targetURL = new URLTargetURIFieldEditor("targetURL", "Target URL", parent) {

        @Override
        protected void onHistorySelected(URI location) {
            updateState();
        }
    };
    targetURL.setPage(getPage());
    targetURL.setPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(FieldEditor.IS_VALID)) {
                getPage().setMessage(null);
                updateState();
            } else if (event.getProperty().equals(FieldEditor.VALUE)) {
                getPage().setMessage(null);
                updateState();
            }
        }
    });
    // content type selection
    // label
    Label typesLabel = new Label(parent, SWT.NONE);
    typesLabel.setText("Content type");
    // types combo
    Composite group = new Composite(parent, SWT.NONE);
    group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
    group.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).create());
    types = new ComboViewer(group, SWT.DROP_DOWN | SWT.READ_ONLY);
    types.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    types.setContentProvider(ArrayContentProvider.getInstance());
    types.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof IContentType) {
                return ((IContentType) element).getName();
            }
            return super.getText(element);
        }
    });
    // process selection changes
    types.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            // update content type
            ISelection sel = event.getSelection();
            if (sel.isEmpty() || !(sel instanceof IStructuredSelection)) {
                setContentType(null);
            } else {
                setContentType((IContentType) ((IStructuredSelection) sel).getFirstElement());
            }
        }
    });
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) IContentType(org.eclipse.core.runtime.content.IContentType) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) URI(java.net.URI) GridLayout(org.eclipse.swt.layout.GridLayout) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) ISelection(org.eclipse.jface.viewers.ISelection) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 44 with IPropertyChangeListener

use of org.eclipse.jface.util.IPropertyChangeListener in project hale by halestudio.

the class AbstractWFSCapabilitiesPage method createContent.

@Override
protected void createContent(Composite parent) {
    Composite page = new Composite(parent, SWT.NONE);
    page.setLayout(new GridLayout(2, false));
    // capabilities field
    location = new WFSCapabilitiesFieldEditor("location", "GetCapabilities URL", page) {

        @Override
        protected WFSVersion getWFSVersion() {
            if (versionSelect != null) {
                ISelection sel = versionSelect.getSelection();
                if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
                    Object selected = ((IStructuredSelection) sel).getFirstElement();
                    if (NoObject.NONE.equals(selected)) {
                        return null;
                    }
                    return (WFSVersion) selected;
                }
            }
            return super.getWFSVersion();
        }
    };
    location.setPage(this);
    location.setPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(FieldEditor.IS_VALID)) {
                update();
            }
        }
    });
    String currentValue = getCapabilitiesURL(getWizard().getConfiguration());
    if (currentValue != null) {
        location.setValue(currentValue);
    }
    // version field
    Label vLabel = new Label(page, SWT.NONE);
    vLabel.setText("WFS version");
    versionSelect = new ComboViewer(page, SWT.READ_ONLY);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(versionSelect.getControl());
    versionSelect.setContentProvider(new EnumContentProvider() {

        @Override
        public Object[] getElements(Object inputElement) {
            Object[] values = super.getElements(inputElement);
            // add a NoObject
            values = Arrays.copyOf(values, values.length + 1, Object[].class);
            values[values.length - 1] = NoObject.NONE;
            return values;
        }
    });
    versionSelect.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof NoObject) {
                return "Based on URL / server default";
            }
            return super.getText(element);
        }
    });
    versionSelect.setInput(WFSVersion.class);
    versionSelect.setSelection(new StructuredSelection(NoObject.NONE));
    versionSelect.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            location.revalidate();
        }
    });
    setControl(page);
    update();
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) WFSVersion(eu.esdihumboldt.hale.io.wfs.WFSVersion) EnumContentProvider(eu.esdihumboldt.hale.ui.util.viewer.EnumContentProvider) GridLayout(org.eclipse.swt.layout.GridLayout) ComboViewer(org.eclipse.jface.viewers.ComboViewer) ISelection(org.eclipse.jface.viewers.ISelection) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 45 with IPropertyChangeListener

use of org.eclipse.jface.util.IPropertyChangeListener in project hale by halestudio.

the class AbstractWFSSource method createControls.

/**
 * @see ImportSource#createControls(Composite)
 */
@Override
public void createControls(Composite parent) {
    parent.setLayout(new GridLayout(4, false));
    // caption
    // placeholder
    new Label(parent, SWT.NONE);
    Label caption = new Label(parent, SWT.NONE);
    caption.setText(getCaption());
    caption.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false, 3, 1));
    // source file
    // target URL field
    sourceURL = new URLSourceURIFieldEditor("sourceURL", "URL:", parent) {

        // the following methods are overridden so the capabilities button
        // may appear on the same line
        @Override
        public int getNumberOfControls() {
            return super.getNumberOfControls() + 1;
        }

        @Override
        protected void doFillIntoGrid(Composite parent, int numColumns) {
            super.doFillIntoGrid(parent, numColumns - 1);
        }
    };
    sourceURL.setPage(getPage());
    // set custom URI filter
    sourceURL.setURIFilter(createHistoryURIFilter());
    // set content types for URI field
    Collection<IOProviderDescriptor> factories = getConfiguration().getFactories();
    HashSet<IContentType> supportedTypes = new HashSet<IContentType>();
    for (IOProviderDescriptor factory : factories) {
        supportedTypes.addAll(factory.getSupportedTypes());
    }
    sourceURL.setContentTypes(supportedTypes);
    sourceURL.setPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(FieldEditor.IS_VALID)) {
                getPage().setMessage(null);
                updateState(true);
            } else if (event.getProperty().equals(FieldEditor.VALUE)) {
                getPage().setMessage(null);
                updateState(true);
            }
        }
    });
    // button to determine from capabilities
    Button capButton = new Button(parent, SWT.PUSH);
    capButton.setText("...");
    capButton.setToolTipText("Determine based on WFS Capabilities");
    capButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            determineSource(sourceURL);
        }
    });
    // provider selection
    // label
    Label providerLabel = new Label(parent, SWT.NONE);
    providerLabel.setText("Import as");
    // create provider combo
    ComboViewer providers = createProviders(parent);
    providers.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 3, 1));
    // initial state update
    updateState(true);
}
Also used : URLSourceURIFieldEditor(eu.esdihumboldt.hale.ui.io.source.URLSourceURIFieldEditor) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Composite(org.eclipse.swt.widgets.Composite) IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) IContentType(org.eclipse.core.runtime.content.IContentType) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) HashSet(java.util.HashSet)

Aggregations

IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)126 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)120 Composite (org.eclipse.swt.widgets.Composite)55 GridData (org.eclipse.swt.layout.GridData)44 Label (org.eclipse.swt.widgets.Label)39 GridLayout (org.eclipse.swt.layout.GridLayout)37 SelectionEvent (org.eclipse.swt.events.SelectionEvent)31 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)25 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 Button (org.eclipse.swt.widgets.Button)22 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)21 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)20 ColorSelector (org.eclipse.jface.preference.ColorSelector)14 ComboViewer (org.eclipse.jface.viewers.ComboViewer)12 Text (org.eclipse.swt.widgets.Text)11 Iterator (java.util.Iterator)10 ISelection (org.eclipse.jface.viewers.ISelection)10 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)10 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)9 SashForm (org.eclipse.swt.custom.SashForm)9