Search in sources :

Example 91 with IPropertyChangeListener

use of org.eclipse.jface.util.IPropertyChangeListener 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)

Example 92 with IPropertyChangeListener

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

the class ArchiveProjectImportSelectLocationPage method createContent.

@Override
protected void createContent(Composite page) {
    directoryField = new KeyStrokeValidatingDirectoryFieldEditor("Import location", "Select directory", page);
    directoryField.setEmptyStringAllowed(false);
    directoryField.setPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(FieldEditor.IS_VALID)) {
                updateState();
            } else if (event.getProperty().equals(FieldEditor.VALUE)) {
                updateState();
            }
        }
    });
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) KeyStrokeValidatingDirectoryFieldEditor(eu.esdihumboldt.hale.ui.util.io.KeyStrokeValidatingDirectoryFieldEditor)

Example 93 with IPropertyChangeListener

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

the class InspireDatasetFeedConfigurationPage method createContent.

@Override
protected void createContent(Composite page) {
    parent = page;
    GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(false).spacing(6, 12).applyTo(page);
    // TODO "intro" explanation
    FieldDecoration fieldDec = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION);
    Image infoImage = fieldDec.getImage();
    create = new BooleanFieldEditor("create", "Create feed", BooleanFieldEditor.SEPARATE_LABEL, page);
    create.setPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            updateStatus();
        }
    });
    title = new StringFieldEditor("title", "Feed title", page);
    subTitle = new StringFieldEditor("subtitle", "Feed sub title", page);
    // e
    rights = new StringFieldEditor("rights", "Rights", page);
    ControlDecoration rightsExplanation = new ControlDecoration(rights.getTextControl(page), SWT.LEFT | SWT.TOP);
    rightsExplanation.setImage(infoImage);
    rightsExplanation.setDescriptionText("Any information about rights or restrictions to the dataset.");
    authorName = new StringFieldEditor("name", "Author name", page);
    authorMail = new StringFieldEditor("mail", "Author mail", page);
    // e
    selfLink = new StringFieldEditor("self", "Feed URI", page);
    ControlDecoration selfLinkExplanation = new ControlDecoration(selfLink.getTextControl(page), SWT.LEFT | SWT.TOP);
    selfLinkExplanation.setImage(infoImage);
    selfLinkExplanation.setDescriptionText("The address under which the feed will be accessible.\n" + "Changes do not affect the location of the created file.");
    // e
    gmlLink = new StringFieldEditor("gml", "GML URI", page);
    ControlDecoration gmlLinkExplanation = new ControlDecoration(gmlLink.getTextControl(page), SWT.LEFT | SWT.TOP);
    gmlLinkExplanation.setImage(infoImage);
    gmlLinkExplanation.setDescriptionText("The address under which the gml data will be accessible.\n" + "Changes do not affect the location of the created file.");
    updateStatus();
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) StringFieldEditor(org.eclipse.jface.preference.StringFieldEditor) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) FieldDecoration(org.eclipse.jface.fieldassist.FieldDecoration) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) BooleanFieldEditor(org.eclipse.jface.preference.BooleanFieldEditor) Image(org.eclipse.swt.graphics.Image)

Example 94 with IPropertyChangeListener

use of org.eclipse.jface.util.IPropertyChangeListener 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)

Example 95 with IPropertyChangeListener

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

the class GroovyASTTray method createContents.

@Override
protected Control createContents(Composite parent) {
    Composite page = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(1).applyTo(page);
    final ASTViewer viewer = new ASTViewer(page, groovyViewer);
    GridDataFactory.fillDefaults().grab(true, true).hint(400, SWT.DEFAULT).applyTo(viewer.getControl());
    if (groovyViewer != null) {
        // current AST
        try {
            GroovyAST ast = groovyViewer.getCompiled().get();
            if (ast != null) {
                viewer.setInput(ast.getNodes());
                viewer.getTreeViewer().expandAll();
            } else {
                viewer.setInput(null);
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        // listen to AST changes
        final IPropertyChangeListener listener = new IPropertyChangeListener() {

            @Override
            public void propertyChange(final PropertyChangeEvent event) {
                if (CompilingSourceViewer.PROPERTY_COMPILED.equals(event.getProperty())) {
                    PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            if (event.getNewValue() instanceof GroovyAST) {
                                viewer.setInput(((GroovyAST) event.getNewValue()).getNodes());
                                viewer.getTreeViewer().expandAll();
                            } else {
                                viewer.setInput(null);
                            }
                        }
                    });
                }
            }
        };
        groovyViewer.addPropertyChangeListener(listener);
        // ensure listener is removed
        page.addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                groovyViewer.removePropertyChangeListener(listener);
            }
        });
    }
    return page;
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) ASTViewer(eu.esdihumboldt.hale.ui.util.groovy.ast.viewer.ASTViewer) GroovyAST(eu.esdihumboldt.hale.ui.util.groovy.ast.GroovyAST) DisposeListener(org.eclipse.swt.events.DisposeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Composite(org.eclipse.swt.widgets.Composite) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

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