Search in sources :

Example 6 with ValueChangeListener

use of net.sourceforge.pmd.eclipse.ui.preferences.br.ValueChangeListener in project pmd-eclipse-plugin by pmd.

the class AbstractMultiValueEditorFactory method addNewValueRow.

private void addNewValueRow(final Composite parent, final PropertyDescriptor<List<T>> desc, final PropertySource source, final Text parentWidget, final ValueChangeListener changeListener, final SizeChangeListener sizeListener, final List<Control> newControls, int i) {
    if (!canAddNewRowFor(desc, source)) {
        return;
    }
    final Label number = new Label(parent, SWT.NONE);
    number.setText(Integer.toString(i + 1));
    newControls.add(number);
    final Control widget = addWidget(parent, null, desc, source);
    widget.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    newControls.add(widget);
    final Button butt = new Button(parent, SWT.PUSH);
    // TODO use icon for consistent width
    butt.setText("+");
    newControls.add(butt);
    Listener addListener = new Listener() {

        public void handleEvent(Event event) {
            // add new value handler
            // add the new value to the property set
            // set the value in the widget to the cleaned up one, disable it
            // remove old listener from button, add new (delete) one, update text/icon
            // add new row widgets: label, value widget, button
            // add listener for new button
            T newValue = addValueIn(widget, desc, source);
            if (newValue == null) {
                return;
            }
            addNewValueRow(parent, desc, source, parentWidget, changeListener, sizeListener, newControls, -1);
            convertToDelete(butt, newValue, parent, newControls, desc, source, parentWidget, number, widget, changeListener, sizeListener);
            widget.setEnabled(false);
            setValue(widget, newValue);
            renumberLabelsIn(newControls);
            fillWidget(parentWidget, desc, source);
            adjustRendering(source, desc, parentWidget);
            sizeListener.addedRows(1);
            changeListener.changed(source, desc, newValue);
            parent.getParent().layout();
        }
    };
    butt.addListener(SWT.Selection, addListener);
    // allow for CR on entry widgets themselves, no need to click the '+' button
    widget.addListener(SWT.DefaultSelection, addListener);
    widget.setFocus();
}
Also used : Control(org.eclipse.swt.widgets.Control) ValueChangeListener(net.sourceforge.pmd.eclipse.ui.preferences.br.ValueChangeListener) Listener(org.eclipse.swt.widgets.Listener) SizeChangeListener(net.sourceforge.pmd.eclipse.ui.preferences.br.SizeChangeListener) SWT(org.eclipse.swt.SWT) Button(org.eclipse.swt.widgets.Button) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event)

Example 7 with ValueChangeListener

use of net.sourceforge.pmd.eclipse.ui.preferences.br.ValueChangeListener in project pmd-eclipse-plugin by pmd.

the class CharacterEditorFactory method newEditorOn.

public Control newEditorOn(Composite parent, final PropertyDescriptor<Character> desc, final PropertySource source, final ValueChangeListener listener, SizeChangeListener sizeListener) {
    final Text text = new Text(parent, SWT.SINGLE | SWT.BORDER);
    fillWidget(text, desc, source);
    text.addListener(SWT.FocusOut, new Listener() {

        public void handleEvent(Event event) {
            Character newValue = charValueIn(text);
            Character existingValue = valueFor(source, desc);
            if (existingValue.equals(newValue)) {
                return;
            }
            source.setProperty(desc, newValue);
            listener.changed(source, desc, newValue);
            adjustRendering(source, desc, text);
        }
    });
    return text;
}
Also used : Listener(org.eclipse.swt.widgets.Listener) SizeChangeListener(net.sourceforge.pmd.eclipse.ui.preferences.br.SizeChangeListener) ValueChangeListener(net.sourceforge.pmd.eclipse.ui.preferences.br.ValueChangeListener) Event(org.eclipse.swt.widgets.Event) Text(org.eclipse.swt.widgets.Text)

Example 8 with ValueChangeListener

use of net.sourceforge.pmd.eclipse.ui.preferences.br.ValueChangeListener in project pmd-eclipse-plugin by pmd.

the class MultiStringEditorFactory method configure.

protected void configure(final Text textWidget, final PropertyDescriptor<List<String>> desc, final PropertySource source, final ValueChangeListener listener) {
    Listener widgetListener = new Listener() {

        public void handleEvent(Event event) {
            List<String> newValues = textWidgetValues(textWidget);
            List<String> existingValues = valueFor(source, desc);
            if (existingValues != null && existingValues.equals(newValues)) {
                return;
            }
            source.setProperty(desc, newValues);
            // reload with latest scrubbed values
            fillWidget(textWidget, desc, source);
            listener.changed(source, desc, newValues);
        }
    };
    textWidget.addListener(SWT.FocusOut, widgetListener);
// textWidget.addListener(SWT.DefaultSelection, widgetListener);
}
Also used : ValueChangeListener(net.sourceforge.pmd.eclipse.ui.preferences.br.ValueChangeListener) Listener(org.eclipse.swt.widgets.Listener) Event(org.eclipse.swt.widgets.Event)

Aggregations

ValueChangeListener (net.sourceforge.pmd.eclipse.ui.preferences.br.ValueChangeListener)8 Event (org.eclipse.swt.widgets.Event)8 Listener (org.eclipse.swt.widgets.Listener)8 SizeChangeListener (net.sourceforge.pmd.eclipse.ui.preferences.br.SizeChangeListener)7 GridData (org.eclipse.swt.layout.GridData)5 Text (org.eclipse.swt.widgets.Text)3 Button (org.eclipse.swt.widgets.Button)2 Control (org.eclipse.swt.widgets.Control)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 SWT (org.eclipse.swt.SWT)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1