Search in sources :

Example 1 with ImportSource

use of eu.esdihumboldt.hale.ui.io.ImportSource in project hale by halestudio.

the class AbstractMultipleFilesSource 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());
    sourceFile = getSourceFile(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)) {
                sourceFile.getStringValues().forEach(k -> updateState(true));
            } else if (event.getProperty().equals(FieldEditor.VALUE)) {
                sourceFile.getStringValues().forEach(k -> updateState(true));
            }
        }
    });
    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.FILL, 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) IOUtils(eu.esdihumboldt.util.io.IOUtils) IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) ComboViewer(org.eclipse.jface.viewers.ComboViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IOProvider(eu.esdihumboldt.hale.common.core.io.IOProvider) ImportSource(eu.esdihumboldt.hale.ui.io.ImportSource) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) HaleIO(eu.esdihumboldt.hale.common.core.io.HaleIO) LocatableInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.LocatableInputSupplier) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Composite(org.eclipse.swt.widgets.Composite) URI(java.net.URI) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) GridData(org.eclipse.swt.layout.GridData) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Button(org.eclipse.swt.widgets.Button) PlatformUI(org.eclipse.ui.PlatformUI) Collection(java.util.Collection) IContentType(org.eclipse.core.runtime.content.IContentType) Set(java.util.Set) ImportProvider(eu.esdihumboldt.hale.common.core.io.ImportProvider) File(java.io.File) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) FilesIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FilesIOSupplier) List(java.util.List) SWT(org.eclipse.swt.SWT) ISelection(org.eclipse.jface.viewers.ISelection) DialogPage(org.eclipse.jface.dialogs.DialogPage) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FieldEditor(org.eclipse.jface.preference.FieldEditor) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Label(org.eclipse.swt.widgets.Label) InputStream(java.io.InputStream) GridLayout(org.eclipse.swt.layout.GridLayout) 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)

Aggregations

HaleIO (eu.esdihumboldt.hale.common.core.io.HaleIO)1 IOProvider (eu.esdihumboldt.hale.common.core.io.IOProvider)1 ImportProvider (eu.esdihumboldt.hale.common.core.io.ImportProvider)1 IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)1 FilesIOSupplier (eu.esdihumboldt.hale.common.core.io.supplier.FilesIOSupplier)1 LocatableInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.LocatableInputSupplier)1 ImportSource (eu.esdihumboldt.hale.ui.io.ImportSource)1 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)1 IOUtils (eu.esdihumboldt.util.io.IOUtils)1 File (java.io.File)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 IContentType (org.eclipse.core.runtime.content.IContentType)1 DialogPage (org.eclipse.jface.dialogs.DialogPage)1 FieldEditor (org.eclipse.jface.preference.FieldEditor)1