Search in sources :

Example 61 with ISelectionChangedListener

use of org.eclipse.jface.viewers.ISelectionChangedListener in project hale by halestudio.

the class GeographicalNamePage method createSpellingGroup.

private void createSpellingGroup(Composite parent, PropertyFunctionDefinition function) {
    // define Spelling Group composite
    Group configurationGroup = new Group(parent, SWT.NONE);
    configurationGroup.setText(SPELLING_GROUP_TEXT);
    configurationGroup.setLayout(GridLayoutFactory.fillDefaults().create());
    GridData configurationAreaGD = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    configurationAreaGD.grabExcessHorizontalSpace = true;
    configurationAreaGD.grabExcessVerticalSpace = true;
    configurationGroup.setLayoutData(configurationAreaGD);
    configurationGroup.setSize(configurationGroup.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    configurationGroup.setFont(parent.getFont());
    final Composite configurationComposite = new Composite(configurationGroup, SWT.NONE);
    GridData configurationLayoutData = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
    configurationLayoutData.grabExcessHorizontalSpace = true;
    configurationComposite.setLayoutData(configurationLayoutData);
    GridLayout spellingLayout = new GridLayout();
    spellingLayout.numColumns = 2;
    spellingLayout.makeColumnsEqualWidth = false;
    spellingLayout.marginWidth = 0;
    spellingLayout.marginHeight = 0;
    spellingLayout.horizontalSpacing = 8;
    configurationComposite.setLayout(spellingLayout);
    // or get the known information about the cell to be edited
    if (getSpellings() == null || getSpellings().size() == 0) {
        spellings = new ArrayList<SpellingType>();
        ListMultimap<String, ? extends Entity> source = getWizard().getUnfinishedCell().getSource();
        if (source != null) {
            for (Entity item : source.values()) {
                int i = 0;
                Definition<?> entity = item.getDefinition().getDefinition();
                if (entity instanceof PropertyDefinition) {
                    SpellingType sp = new SpellingType((PropertyDefinition) entity);
                    // set the same script value if you had a value before
                    if (scripts != null && i < scripts.size()) {
                        sp.setScript(scripts.get(i));
                    } else {
                        // else set the default value
                        sp.setScript(ISO_CODE_ENG);
                    }
                    // before
                    if (trans != null && i < trans.size()) {
                        sp.setTransliteration(trans.get(i));
                    } else {
                        // else set the default value
                        sp.setTransliteration("");
                    }
                    spellings.add(sp);
                }
                i++;
            }
        }
    } else {
        // after initialization of the spellings
        ArrayList<PropertyDefinition> temp = new ArrayList<PropertyDefinition>();
        ArrayList<SpellingType> templist = getSpellings();
        // we have to create a new spellings list because a live
        // modification of the combo box input would occur an error
        spellings = new ArrayList<SpellingType>();
        for (int i = 0; i < templist.size(); i++) {
            temp.add(templist.get(i).getProperty());
            if (scripts != null && trans != null && i < scripts.size() && scripts.get(i) != null && i < trans.size() && trans.get(i) != null) {
                templist.get(i).setScript(scripts.get(i));
                templist.get(i).setTransliteration(trans.get(i));
            }
        }
        for (Entity item : getWizard().getUnfinishedCell().getSource().values()) {
            Definition<?> entity = item.getDefinition().getDefinition();
            if (entity instanceof PropertyDefinition) {
                PropertyDefinition propDef = (PropertyDefinition) entity;
                for (SpellingType st : templist) {
                    // transliteration) to the new spellings list
                    if (propDef.equals(st.getProperty())) {
                        spellings.add(st);
                    }
                }
                // with default values
                if (!temp.contains(propDef)) {
                    SpellingType sp = new SpellingType(propDef);
                    sp.setScript(ISO_CODE_ENG);
                    sp.setTransliteration("");
                    spellings.add(sp);
                }
            }
        }
    }
    // Text
    final Label nameSpellingTextLabel = new Label(configurationComposite, SWT.NONE);
    nameSpellingTextLabel.setText(SPELLING_TEXT_LABEL_TEXT);
    this.nameSpellingText = new ComboViewer(configurationComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
    this.nameSpellingText.getControl().setLayoutData(configurationLayoutData);
    this.nameSpellingText.setContentProvider(ArrayContentProvider.getInstance());
    this.nameSpellingText.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof SpellingType) {
                return ((SpellingType) element).getProperty().getName().getLocalPart();
            }
            return super.getText(element);
        }
    });
    this.nameSpellingText.setInput(spellings);
    // default set selection to the first element on the list
    if (!spellings.isEmpty()) {
        this.activeSpelling = spellings.iterator().next();
        this.nameSpellingText.setSelection(new StructuredSelection(activeSpelling));
    }
    // set active spelling
    nameSpellingText.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            if (!event.getSelection().isEmpty() && event.getSelection() instanceof IStructuredSelection) {
                SpellingType selected = (SpellingType) ((IStructuredSelection) event.getSelection()).getFirstElement();
                String script = ISO_CODE_ENG;
                // $NON-NLS-1$
                String transliteration = "";
                activeSpelling = selected;
                if (activeSpelling.getScript() != null && // $NON-NLS-1$
                !activeSpelling.getScript().equals(""))
                    script = activeSpelling.getScript();
                if (activeSpelling.getTransliteration() != null && // $NON-NLS-1$
                !activeSpelling.getTransliteration().equals(""))
                    transliteration = activeSpelling.getTransliteration();
                nameSpellingScript.setText(script);
                nameSpellingTransliteration.setText(transliteration);
            }
        }
    });
    // Script
    final Label nameSpellingScriptLabel = new Label(configurationComposite, SWT.NONE);
    nameSpellingScriptLabel.setText(SCRIPT_LABEL_TEXT);
    configureParameterLabel(nameSpellingScriptLabel, PROPERTY_SCRIPT, function);
    this.nameSpellingScript = new Text(configurationComposite, SWT.BORDER | SWT.SINGLE);
    this.nameSpellingScript.setLayoutData(configurationLayoutData);
    this.nameSpellingScript.setEnabled(true);
    this.nameSpellingScript.setTabs(0);
    // $NON-NLS-1$
    String script = "eng";
    // read script from the active spelling
    if (activeSpelling != null && activeSpelling.getScript() != null)
        script = activeSpelling.getScript();
    // set default value for script
    this.nameSpellingScript.setText(script);
    this.nameSpellingScript.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            activeSpelling.setScript(nameSpellingScript.getText());
        }
    });
    // Transliteration
    final Label nameSpellingTransliterationLabel = new Label(configurationComposite, SWT.NONE);
    nameSpellingTransliterationLabel.setText(TRANSLITERATION_LABEL_TEXT);
    configureParameterLabel(nameSpellingTransliterationLabel, PROPERTY_TRANSLITERATION, function);
    this.nameSpellingTransliteration = new Text(configurationComposite, SWT.BORDER | SWT.SINGLE);
    this.nameSpellingTransliteration.setLayoutData(configurationLayoutData);
    this.nameSpellingTransliteration.setEnabled(true);
    this.nameSpellingTransliteration.setTabs(0);
    // read script from the active spelling
    // $NON-NLS-1$
    String transliteration = "";
    if (activeSpelling != null && activeSpelling.getTransliteration() != null)
        transliteration = activeSpelling.getTransliteration();
    // set default value for transliteration
    this.nameSpellingTransliteration.setText(transliteration);
    this.nameSpellingTransliteration.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            activeSpelling.setTransliteration(nameSpellingTransliteration.getText());
        }
    });
}
Also used : Group(org.eclipse.swt.widgets.Group) SpellingType(eu.esdihumboldt.cst.functions.inspire.SpellingType) Entity(eu.esdihumboldt.hale.common.align.model.Entity) ModifyListener(org.eclipse.swt.events.ModifyListener) ArrayList(java.util.ArrayList) Label(org.eclipse.swt.widgets.Label) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Text(org.eclipse.swt.widgets.Text) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 62 with ISelectionChangedListener

use of org.eclipse.jface.viewers.ISelectionChangedListener in project hale by halestudio.

the class SequentialIDParameterPage method createContent.

/**
 * @see HaleWizardPage#createContent(Composite)
 */
@Override
protected void createContent(Composite page) {
    page.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).spacing(10, 8).create());
    Label label;
    GridDataFactory labelLayout = GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER);
    GridDataFactory controlLayout = GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false);
    // select sequence type
    if (getParametersToHandle().containsKey(PARAM_SEQUENCE)) {
        label = new Label(page, SWT.NONE);
        label.setText("Sequence");
        labelLayout.applyTo(label);
        sequence = new ComboViewer(page);
        sequence.setContentProvider(EnumContentProvider.getInstance());
        sequence.setLabelProvider(new LabelProvider() {

            @Override
            public String getText(Object element) {
                if (element instanceof Sequence) {
                    switch((Sequence) element) {
                        case overall:
                            return "Over all sequential IDs";
                        case type:
                            return "Per target instance type";
                    }
                }
                return super.getText(element);
            }
        });
        sequence.setInput(Sequence.class);
        controlLayout.applyTo(sequence.getControl());
        Sequence initialValue = Sequence.valueOf(getOptionalInitialValue(PARAM_SEQUENCE, new ParameterValue(Sequence.type.name())).as(String.class));
        sequence.setSelection(new StructuredSelection(initialValue));
        sequence.addSelectionChangedListener(new ISelectionChangedListener() {

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                updateStatus();
            }
        });
    }
    // specify prefix
    if (getParametersToHandle().containsKey(PARAM_PREFIX)) {
        label = new Label(page, SWT.NONE);
        label.setText("Prefix");
        labelLayout.applyTo(label);
        prefix = new Text(page, SWT.SINGLE | SWT.BORDER);
        controlLayout.applyTo(prefix);
        prefix.setText(getOptionalInitialValue(PARAM_PREFIX, new ParameterValue("")).as(String.class));
        prefix.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                updateStatus();
            }
        });
        ContentProposalAdapter adapter = new ContentProposalAdapter(prefix, new TextContentAdapter(), contentProposalProvider, ProjectVariablesContentProposalProvider.CTRL_SPACE, new char[] { '{' });
        adapter.setAutoActivationDelay(0);
        final ControlDecoration infoDeco = new ControlDecoration(prefix, SWT.TOP | SWT.LEFT);
        infoDeco.setDescriptionText("Type Ctrl+Space for project variable content assistance");
        infoDeco.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
        infoDeco.setMarginWidth(2);
    }
    // specify suffix
    if (getParametersToHandle().containsKey(PARAM_SUFFIX)) {
        label = new Label(page, SWT.NONE);
        label.setText("Suffix");
        labelLayout.applyTo(label);
        suffix = new Text(page, SWT.SINGLE | SWT.BORDER);
        controlLayout.applyTo(suffix);
        suffix.setText(getOptionalInitialValue(PARAM_SUFFIX, new ParameterValue("")).as(String.class));
        suffix.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                updateStatus();
            }
        });
        ContentProposalAdapter adapter = new ContentProposalAdapter(suffix, new TextContentAdapter(), contentProposalProvider, ProjectVariablesContentProposalProvider.CTRL_SPACE, new char[] { '{' });
        adapter.setAutoActivationDelay(0);
        final ControlDecoration infoDeco = new ControlDecoration(suffix, SWT.TOP | SWT.LEFT);
        infoDeco.setDescriptionText("Type Ctrl+Space for project variable content assistance");
        infoDeco.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
        infoDeco.setShowOnlyOnFocus(true);
    }
    // show example
    if (sequence != null && prefix != null && suffix != null) {
        label = new Label(page, SWT.NONE);
        label.setText("Example");
        labelLayout.applyTo(label);
        example = new Label(page, SWT.NONE);
        example.setFont(JFaceResources.getTextFont());
        controlLayout.applyTo(example);
        // error decoration
        exampleDecoration = new ControlDecoration(example, SWT.LEFT | SWT.TOP, page);
        FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
        exampleDecoration.setImage(fieldDecoration.getImage());
        exampleDecoration.hide();
    }
    updateStatus();
}
Also used : ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) ModifyListener(org.eclipse.swt.events.ModifyListener) FieldDecoration(org.eclipse.jface.fieldassist.FieldDecoration) 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) Text(org.eclipse.swt.widgets.Text) TextContentAdapter(org.eclipse.jface.fieldassist.TextContentAdapter) ContentProposalAdapter(org.eclipse.jface.fieldassist.ContentProposalAdapter) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ComboViewer(org.eclipse.jface.viewers.ComboViewer) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 63 with ISelectionChangedListener

use of org.eclipse.jface.viewers.ISelectionChangedListener in project hale by halestudio.

the class PresetsSource method createControls.

/**
 * @see ImportSource#createControls(Composite)
 */
@Override
public void createControls(Composite parent) {
    GridLayoutFactory parentLayout = GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(false);
    parentLayout.applyTo(parent);
    GridDataFactory labelData = // 
    GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.CENTER);
    GridDataFactory controlData = // 
    GridDataFactory.swtDefaults().align(SWT.FILL, // 
    SWT.CENTER).grab(true, false);
    // preset label
    Label label = new Label(parent, SWT.NONE);
    label.setText("Select preset:");
    labelData.applyTo(label);
    // preset selector
    selector = new SchemaPresetSelector(parent);
    selector.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            if (description != null) {
                SchemaPreset schema = selector.getSelectedObject();
                if (schema != null && schema.getDescription() != null) {
                    description.setText(schema.getDescription());
                } else {
                    description.setText("");
                }
            }
            updateState(true);
        }
    });
    controlData.applyTo(selector.getControl());
    // skipper
    Composite empty = new Composite(parent, SWT.NONE);
    GridDataFactory.swtDefaults().hint(1, 1).applyTo(empty);
    // description label
    description = new Label(parent, SWT.WRAP);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(description);
    // preset label
    label = new Label(parent, SWT.NONE);
    label.setText("Import as");
    labelData.applyTo(label);
    // create provider combo
    ComboViewer providers = createProviders(parent);
    controlData.applyTo(providers.getControl());
    // prevent selector appearing very small
    parent.pack();
    // initial state update
    updateState(true);
}
Also used : GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) Composite(org.eclipse.swt.widgets.Composite) SchemaPresetSelector(eu.esdihumboldt.hale.ui.schema.presets.internal.SchemaPresetSelector) SchemaPreset(eu.esdihumboldt.hale.common.schema.presets.extension.SchemaPreset) ComboViewer(org.eclipse.jface.viewers.ComboViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent)

Example 64 with ISelectionChangedListener

use of org.eclipse.jface.viewers.ISelectionChangedListener in project hale by halestudio.

the class JDBCSource method createControls.

@Override
public void createControls(Composite page) {
    page.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).create());
    GridDataFactory labelData = GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER);
    GridDataFactory compData = GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false);
    // driver
    Label labelDriver = new Label(page, SWT.NONE);
    labelDriver.setText("Driver");
    labelData.applyTo(labelDriver);
    driver = JDBCComponents.createDriverSelector(page);
    compData.applyTo(driver.getControl());
    // driver selection listener
    driver.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            updateState(false);
        }
    });
    // host
    Label labelHost = new Label(page, SWT.NONE);
    labelHost.setText("Host(:Port)");
    labelData.applyTo(labelHost);
    host = new Text(page, SWT.BORDER | SWT.SINGLE);
    compData.applyTo(host);
    host.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            updateState(false);
        }
    });
    // database
    Label labelDatabase = new Label(page, SWT.NONE);
    labelDatabase.setText("Database");
    labelData.applyTo(labelDatabase);
    database = new Text(page, SWT.BORDER | SWT.SINGLE);
    compData.applyTo(database);
    database.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            updateState(false);
        }
    });
    // preset label
    Label providerLabel = new Label(page, SWT.NONE);
    providerLabel.setText("Import as");
    labelData.applyTo(providerLabel);
    // create provider combo
    ComboViewer providers = createProviders(page);
    compData.applyTo(providers.getControl());
    // content type is set through source registration
    // initial state update
    updateState(true);
}
Also used : GridDataFactory(org.eclipse.jface.layout.GridDataFactory) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) ComboViewer(org.eclipse.jface.viewers.ComboViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Text(org.eclipse.swt.widgets.Text)

Example 65 with ISelectionChangedListener

use of org.eclipse.jface.viewers.ISelectionChangedListener in project hale by halestudio.

the class JDBCTarget method createControls.

@Override
public void createControls(Composite page) {
    page.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).create());
    GridDataFactory labelData = GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER);
    GridDataFactory compData = GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false);
    // driver
    Label labelDriver = new Label(page, SWT.NONE);
    labelDriver.setText("Driver");
    labelData.applyTo(labelDriver);
    driver = JDBCComponents.createDriverSelector(page);
    compData.applyTo(driver.getControl());
    // driver selection listener
    driver.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            updateState();
        }
    });
    // host
    Label labelHost = new Label(page, SWT.NONE);
    labelHost.setText("Host(:Port)");
    labelData.applyTo(labelHost);
    host = new Text(page, SWT.BORDER | SWT.SINGLE);
    compData.applyTo(host);
    host.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            updateState();
        }
    });
    // database
    Label labelDatabase = new Label(page, SWT.NONE);
    labelDatabase.setText("Database");
    labelData.applyTo(labelDatabase);
    database = new Text(page, SWT.BORDER | SWT.SINGLE);
    compData.applyTo(database);
    database.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            updateState();
        }
    });
    // initial state update
    updateState();
}
Also used : GridDataFactory(org.eclipse.jface.layout.GridDataFactory) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Text(org.eclipse.swt.widgets.Text)

Aggregations

ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)774 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)755 GridData (org.eclipse.swt.layout.GridData)419 Composite (org.eclipse.swt.widgets.Composite)333 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)302 GridLayout (org.eclipse.swt.layout.GridLayout)247 SelectionEvent (org.eclipse.swt.events.SelectionEvent)187 Label (org.eclipse.swt.widgets.Label)157 TableViewer (org.eclipse.jface.viewers.TableViewer)151 AdapterFactoryLabelProvider (org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider)147 Button (org.eclipse.swt.widgets.Button)141 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)139 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)131 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)121 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)120 IPropertiesEditionEvent (org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)116 PropertiesEditionEvent (org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent)116 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)116 Table (org.eclipse.swt.widgets.Table)93 ISelection (org.eclipse.jface.viewers.ISelection)87