Search in sources :

Example 1 with ValueChangeListener

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

the class FileEditorFactory method newEditorOn.

public Control newEditorOn(Composite parent, final PropertyDescriptor<File> desc, final PropertySource source, final ValueChangeListener listener, SizeChangeListener sizeListener) {
    final FilePicker picker = new FilePicker(parent, SWT.SINGLE | SWT.BORDER, "Open", null);
    picker.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fillWidget(picker, desc, source);
    picker.addFocusOutListener(new Listener() {

        public void handleEvent(Event event) {
            File newValue = picker.getFile();
            File existingValue = valueFor(source, desc);
            if (areSemanticEquals(existingValue, newValue)) {
                return;
            }
            setValue(source, desc, newValue);
            // redraw
            fillWidget(picker, desc, source);
            listener.changed(source, desc, newValue);
        }
    });
    return picker;
}
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) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) File(java.io.File)

Example 2 with ValueChangeListener

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

the class StringEditorFactory method newEditorOn.

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

        public void handleEvent(Event event) {
            String newValue = text.getText().trim();
            String existingValue = valueFor(source, desc);
            if (StringUtil.areSemanticEquals(existingValue, newValue)) {
                return;
            }
            setValue(source, desc, newValue);
            // redraw
            fillWidget(text, desc, source);
            listener.changed(source, desc, newValue);
        }
    });
    return text;
}
Also used : ValueChangeListener(net.sourceforge.pmd.eclipse.ui.preferences.br.ValueChangeListener) Listener(org.eclipse.swt.widgets.Listener) SizeChangeListener(net.sourceforge.pmd.eclipse.ui.preferences.br.SizeChangeListener) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) Text(org.eclipse.swt.widgets.Text)

Example 3 with ValueChangeListener

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

the class TypeEditorFactory method newEditorOn.

public Control newEditorOn(Composite parent, final PropertyDescriptor<Class> desc, final PropertySource source, final ValueChangeListener listener, SizeChangeListener sizeListener) {
    final TypeText typeText = new TypeText(parent, SWT.SINGLE | SWT.BORDER, true, // TODO  i18l
    "Enter a type name");
    typeText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fillWidget(typeText, desc, source);
    Listener wereDoneListener = new Listener() {

        public void handleEvent(Event event) {
            Class<?> newValue = typeText.getType(true);
            if (newValue == null) {
                return;
            }
            Class<?> existingValue = (Class<?>) valueFor(source, desc);
            if (existingValue == newValue) {
                return;
            }
            source.setProperty(desc, newValue);
            listener.changed(source, desc, newValue);
            adjustRendering(source, desc, typeText);
        }
    };
    typeText.addListener(SWT.FocusOut, wereDoneListener);
    typeText.addListener(SWT.DefaultSelection, wereDoneListener);
    return typeText;
}
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) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event)

Example 4 with ValueChangeListener

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

the class AbstractMultiValueEditorFactory method convertToDelete.

private void convertToDelete(final Button button, final T toDeleteValue, final Composite parent, final List<Control> newControls, final PropertyDescriptor<List<T>> desc, final PropertySource source, final Text parentWidget, final Label number, final Control widget, final ValueChangeListener changeListener, final SizeChangeListener sizeListener) {
    button.setText("-");
    Util.removeListeners(button, SWT.Selection);
    button.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            delete(number, widget, button, newControls, toDeleteValue, desc, source);
            fillWidget(parentWidget, desc, source);
            sizeListener.addedRows(-1);
            changeListener.changed(source, desc, null);
            parent.getParent().layout();
        }
    });
}
Also used : ValueChangeListener(net.sourceforge.pmd.eclipse.ui.preferences.br.ValueChangeListener) Listener(org.eclipse.swt.widgets.Listener) SizeChangeListener(net.sourceforge.pmd.eclipse.ui.preferences.br.SizeChangeListener) Event(org.eclipse.swt.widgets.Event)

Example 5 with ValueChangeListener

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

the class AbstractMultiValueEditorFactory method newEditorOn.

public Control newEditorOn(final Composite parent, final PropertyDescriptor<List<T>> desc, final PropertySource source, final ValueChangeListener changeListener, final SizeChangeListener sizeListener) {
    final Composite panel = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(3, false);
    layout.verticalSpacing = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    panel.setLayout(layout);
    final Text textWidget = new Text(panel, SWT.SINGLE | SWT.BORDER);
    final Button butt = new Button(panel, SWT.PUSH);
    // TODO use triangle icon & rotate 90deg when clicked
    butt.setText("...");
    butt.addListener(SWT.Selection, new Listener() {

        boolean itemsVisible = false;

        List<Control> items = new ArrayList<Control>();

        public void handleEvent(Event event) {
            if (itemsVisible) {
                hideCollection(items);
                sizeListener.addedRows(items.size() / -WIDGETS_PER_ROW);
            } else {
                items = openCollection(panel, desc, source, textWidget, changeListener, sizeListener);
                sizeListener.addedRows(items.size() / WIDGETS_PER_ROW);
            }
            itemsVisible = !itemsVisible;
            // no raw editing when individual items are available
            textWidget.setEditable(!itemsVisible);
            parent.layout();
        }
    });
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    textWidget.setLayoutData(data);
    panel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fillWidget(textWidget, desc, source);
    configure(textWidget, desc, source, changeListener);
    return panel;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) 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) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) ArrayList(java.util.ArrayList) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) Text(org.eclipse.swt.widgets.Text)

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