Search in sources :

Example 6 with SizeChangeListener

use of net.sourceforge.pmd.eclipse.ui.preferences.br.SizeChangeListener 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 SizeChangeListener

use of net.sourceforge.pmd.eclipse.ui.preferences.br.SizeChangeListener 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)

Aggregations

SizeChangeListener (net.sourceforge.pmd.eclipse.ui.preferences.br.SizeChangeListener)7 ValueChangeListener (net.sourceforge.pmd.eclipse.ui.preferences.br.ValueChangeListener)7 Event (org.eclipse.swt.widgets.Event)7 Listener (org.eclipse.swt.widgets.Listener)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