Search in sources :

Example 1 with StackedPage

use of org.entirej.applicationframework.rwt.layout.EJRWTEntireJStackedPane.StackedPage in project rap by entirej.

the class EJRWTStackedItemRenderer method buildStackUI.

protected void buildStackUI(EJRWTEntireJStackedPane stackedPane) {
    // create stack UI for eash type
    // EJStackedItemRendererType.LABEL;
    {
        final Label label = new Label(stackedPane, SWT.NONE);
        label.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_LABEL);
        label.setData(EJ_RWT.CUSTOM_VARIANT + "_DEF", EJ_RWT.CSS_CV_ITEM_LABEL);
        String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
        if (customCSSKey != null && customCSSKey.trim().length() > 0) {
            label.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
        }
        stackedPane.add(EJRWTStackedItemRendererType.LABEL.name(), new EJRWTEntireJStackedPane.StackedPage() {

            @Override
            public String getKey() {
                return EJRWTStackedItemRendererType.LABEL.name();
            }

            @Override
            public Control getControl() {
                return label;
            }
        });
        label.setData(_item.getReferencedItemProperties().getName());
        label.setData("EJRWTItemRendererVisualContext", new EJRWTItemRendererVisualContext(label.getBackground(), label.getForeground(), label.getFont()));
    }
    {
        int style = SWT.NONE;
        final Button _button = new Button(stackedPane, style = style | SWT.CHECK);
        _button.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        Object old = null;
                        Object newVal = null;
                        EJRWTStackedItemRendererConfig.CheckBox config = (CheckBox) _baseValue.getConfig();
                        if (_button.getSelection()) {
                            old = config.getCheckBoxUnCheckedValue();
                            newVal = config.getCheckBoxCheckedValue();
                        } else {
                            old = config.getCheckBoxCheckedValue();
                            newVal = config.getCheckBoxUnCheckedValue();
                        }
                        _item.executeActionCommand();
                        _item.itemValueChaged(getRealValue());
                    }
                });
            }
        });
        _button.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_CHECKBOX);
        _button.setData(EJ_RWT.CUSTOM_VARIANT + "_DEF", EJ_RWT.CSS_CV_ITEM_CHECKBOX);
        String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
        if (customCSSKey != null && customCSSKey.trim().length() > 0) {
            _button.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
        }
        stackedPane.add(EJRWTStackedItemRendererType.CHECKBOX.name(), new StackedPage() {

            @Override
            public String getKey() {
                return EJRWTStackedItemRendererType.CHECKBOX.name();
            }

            @Override
            public Control getControl() {
                return _button;
            }
        });
        _button.setData(_item.getReferencedItemProperties().getName());
        _button.setData("EJRWTItemRendererVisualContext", new EJRWTItemRendererVisualContext(_button.getBackground(), _button.getForeground(), _button.getFont()));
    }
    {
        int style = SWT.NONE;
        final Button _button = new Button(stackedPane, style);
        _button.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        _item.executeActionCommand();
                    }
                });
            }
        });
        _button.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_BUTTON);
        _button.setData(EJ_RWT.CUSTOM_VARIANT + "_DEF", EJ_RWT.CSS_CV_ITEM_BUTTON);
        String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
        if (customCSSKey != null && customCSSKey.trim().length() > 0) {
            _button.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
        }
        stackedPane.add(EJRWTStackedItemRendererType.BUTTON.name(), new StackedPage() {

            @Override
            public String getKey() {
                return EJRWTStackedItemRendererType.BUTTON.name();
            }

            @Override
            public Control getControl() {
                return _button;
            }
        });
        _button.setData(_item.getReferencedItemProperties().getName());
        _button.setData("EJRWTItemRendererVisualContext", new EJRWTItemRendererVisualContext(_button.getBackground(), _button.getForeground(), _button.getFont()));
    }
    {
        int style = SWT.READ_ONLY;
        final Combo _comboField = new Combo(stackedPane, style);
        final ComboViewer _comboViewer = new ComboViewer(_comboField);
        _comboField.setData(_item.getReferencedItemProperties().getName());
        _comboField.addFocusListener(EJRWTStackedItemRenderer.this);
        _comboViewer.setLabelProvider(new ColumnLabelProvider() {

            @Override
            public String getText(Object element) {
                if (element instanceof ComboBoxValue) {
                    ComboBoxValue value = (ComboBoxValue) element;
                    return value.getItemValueAsString();
                }
                return "";
            }
        });
        _comboViewer.setContentProvider(new ArrayContentProvider());
        _comboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

            private ComboBoxValue getComboBoxValue() {
                if (controlState(_comboField)) {
                    IStructuredSelection selection = (IStructuredSelection) _comboViewer.getSelection();
                    return (ComboBoxValue) selection.getFirstElement();
                }
                return null;
            }

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                if (!_modifyListener.enable) {
                    return;
                }
                if (isValid()) {
                    Object old = _baseValue.getValue();
                    ComboBoxValue value = getComboBoxValue();
                    if (value != null) {
                        value.populateReturnItems(_item.getBlock().getBlockController(), _item.getScreenType());
                    }
                    _item.itemValueChaged(getRealValue());
                    setMandatoryBorder(_mandatory);
                } else {
                    _isValid = true;
                }
                _item.executeActionCommand();
            }
        });
        _comboField.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_COMBOBOX);
        _comboField.setData(EJ_RWT.CUSTOM_VARIANT + "_DEF", EJ_RWT.CSS_CV_ITEM_COMBOBOX);
        String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
        if (customCSSKey != null && customCSSKey.trim().length() > 0) {
            _comboField.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
        }
        stackedPane.add(EJRWTStackedItemRendererType.COMBO.name(), new StackedPage() {

            @Override
            public String getKey() {
                return EJRWTStackedItemRendererType.COMBO.name();
            }

            @Override
            public Control getControl() {
                return _comboField;
            }
        });
        _comboField.setData(_item.getReferencedItemProperties().getName());
        _comboField.setData("VIEW", _comboViewer);
        _comboField.setData("EJRWTItemRendererVisualContext", new EJRWTItemRendererVisualContext(_comboField.getBackground(), _comboField.getForeground(), _comboField.getFont()));
    }
    // EJStackedItemRendererType.SPACER;
    {
        final Label label = new Label(stackedPane, SWT.NONE);
        // label.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_LABEL);
        // label.setData(EJ_RWT.CUSTOM_VARIANT+"_DEF",
        // EJ_RWT.CSS_CV_ITEM_LABEL);
        // String customCSSKey =
        // _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
        // 
        // if (customCSSKey != null && customCSSKey.trim().length() > 0)
        // {
        // label.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
        // }
        stackedPane.add(EJRWTStackedItemRendererType.SPACER.name(), new StackedPage() {

            @Override
            public String getKey() {
                return EJRWTStackedItemRendererType.SPACER.name();
            }

            @Override
            public Control getControl() {
                return label;
            }
        });
        label.setData("EJRWTItemRendererVisualContext", new EJRWTItemRendererVisualContext(label.getBackground(), label.getForeground(), label.getFont()));
    }
    // EJStackedItemRendererType.TEXT;
    {
        final Text textField = new Text(stackedPane, SWT.BORDER);
        connectLOVAction(textField);
        textField.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_TEXT);
        textField.setData(EJ_RWT.CUSTOM_VARIANT + "_DEF", EJ_RWT.CSS_CV_ITEM_TEXT);
        String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
        textField.setData(_item.getReferencedItemProperties().getName());
        textField.addFocusListener(this);
        if (customCSSKey != null && customCSSKey.trim().length() > 0) {
            textField.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
        }
        textField.addModifyListener(_modifyListener);
        stackedPane.add(EJRWTStackedItemRendererType.TEXT.name(), new StackedPage() {

            @Override
            public String getKey() {
                return EJRWTStackedItemRendererType.TEXT.name();
            }

            @Override
            public Control getControl() {
                return textField;
            }
        });
        textField.setData("EJRWTItemRendererVisualContext", new EJRWTItemRendererVisualContext(textField.getBackground(), textField.getForeground(), textField.getFont()));
    }
    // EJStackedItemRendererType.TEXT;
    {
        final Text textField = new Text(stackedPane, SWT.BORDER | SWT.MULTI | SWT.WRAP);
        connectLOVAction(textField);
        textField.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_TEXTAREA);
        textField.setData(EJ_RWT.CUSTOM_VARIANT + "_DEF", EJ_RWT.CSS_CV_ITEM_TEXTAREA);
        String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
        textField.setData(_item.getReferencedItemProperties().getName());
        textField.addFocusListener(this);
        if (customCSSKey != null && customCSSKey.trim().length() > 0) {
            textField.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
        }
        textField.addModifyListener(_modifyListener);
        stackedPane.add(EJRWTStackedItemRendererType.TEXT_AREA.name(), new StackedPage() {

            @Override
            public String getKey() {
                return EJRWTStackedItemRendererType.TEXT_AREA.name();
            }

            @Override
            public Control getControl() {
                return textField;
            }
        });
        textField.setData("EJRWTItemRendererVisualContext", new EJRWTItemRendererVisualContext(textField.getBackground(), textField.getForeground(), textField.getFont()));
    }
    // EJStackedItemRendererType.NUMBER;
    {
        final Text textField = new Text(stackedPane, SWT.BORDER | SWT.RIGHT);
        textField.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_NUMBER);
        textField.setData(EJ_RWT.CUSTOM_VARIANT + "_DEF", EJ_RWT.CSS_CV_ITEM_NUMBER);
        String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
        textField.setData(_item.getReferencedItemProperties().getName());
        textField.addFocusListener(this);
        if (customCSSKey != null && customCSSKey.trim().length() > 0) {
            textField.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
        }
        textField.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent arg0) {
                if (textField.getText().trim().length() > 0) {
                    try {
                        _decimalFormatter.parse(textField.getText());
                        _errorDecoration.hide();
                    } catch (ParseException e) {
                        _rendererProps.getStringProperty(EJRWTTextItemRendererDefinitionProperties.PROPERTY_FORMAT);
                        _errorDecoration.setDescriptionText(String.format("Invalid Number format. Should be %s ", _rendererProps.getStringProperty(EJRWTTextItemRendererDefinitionProperties.PROPERTY_FORMAT)));
                        _errorDecoration.show();
                    }
                }
            }
        });
        connectLOVAction(textField);
        textField.addModifyListener(_modifyListener);
        textField.addFocusListener(new FocusListener() {

            @Override
            public void focusLost(FocusEvent arg0) {
                try {
                    _modifyListener.enable = false;
                    Object value = getValue();
                    if (value != null && _baseValue.getValue() != null) {
                        textField.setText(_decimalFormatter.format(_baseValue.getValue()));
                    } else {
                        textField.setText("");
                    }
                } finally {
                    _modifyListener.enable = true;
                }
            }

            @Override
            public void focusGained(FocusEvent arg0) {
            }
        });
        stackedPane.add(EJRWTStackedItemRendererType.NUMBER.name(), new StackedPage() {

            @Override
            public String getKey() {
                return EJRWTStackedItemRendererType.NUMBER.name();
            }

            @Override
            public Control getControl() {
                return textField;
            }
        });
        textField.setData("EJRWTItemRendererVisualContext", new EJRWTItemRendererVisualContext(textField.getBackground(), textField.getForeground(), textField.getFont()));
    }
    // EJStackedItemRendererType.DATE;
    {
        final Text textField = new Text(stackedPane, SWT.BORDER | SWT.RIGHT);
        textField.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_DATE);
        textField.setData(EJ_RWT.CUSTOM_VARIANT + "_DEF", EJ_RWT.CSS_CV_ITEM_DATE);
        textField.setData(_item.getReferencedItemProperties().getName());
        textField.addFocusListener(this);
        String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
        connectLOVAction(textField);
        if (customCSSKey != null && customCSSKey.trim().length() > 0) {
            textField.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
        }
        textField.addModifyListener(_modifyListener);
        textField.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent arg0) {
                if (textField.getText().trim().length() > 0) {
                    try {
                        _dateFormat.parse(textField.getText());
                        _errorDecoration.hide();
                    } catch (ParseException e) {
                        String format = _dateFormat.toFormatString();
                        if (format == null || format.length() == 0) {
                            format = "eg: " + _dateFormat.format(new Date());
                        }
                        _errorDecoration.setDescriptionText(String.format("Invalid Date format. Should be %s ", format));
                        _errorDecoration.show();
                    }
                }
            }
        });
        textField.addFocusListener(new FocusListener() {

            @Override
            public void focusLost(FocusEvent arg0) {
                try {
                    _modifyListener.enable = false;
                    Object value = getValue();
                    if (value != null && _baseValue.getValue() != null) {
                        textField.setText(_dateFormat.format(_baseValue.getValue()));
                    } else {
                        textField.setText("");
                    }
                } finally {
                    _modifyListener.enable = true;
                }
            }

            @Override
            public void focusGained(FocusEvent arg0) {
            }
        });
        stackedPane.add(EJRWTStackedItemRendererType.DATE.name(), new StackedPage() {

            @Override
            public String getKey() {
                return EJRWTStackedItemRendererType.DATE.name();
            }

            @Override
            public Control getControl() {
                return textField;
            }
        });
        textField.setData("EJRWTItemRendererVisualContext", new EJRWTItemRendererVisualContext(textField.getBackground(), textField.getForeground(), textField.getFont()));
    }
    {
    }
}
Also used : Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) MouseListener(org.eclipse.swt.events.MouseListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FocusListener(org.eclipse.swt.events.FocusListener) KeyListener(org.eclipse.swt.events.KeyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) FocusEvent(org.eclipse.swt.events.FocusEvent) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) StackedPage(org.entirej.applicationframework.rwt.layout.EJRWTEntireJStackedPane.StackedPage) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Text(org.eclipse.swt.widgets.Text) Date(java.util.Date) ComboViewer(org.eclipse.jface.viewers.ComboViewer) CheckBox(org.entirej.applicationframework.rwt.renderers.stack.EJRWTStackedItemRendererConfig.CheckBox) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) FocusEvent(org.eclipse.swt.events.FocusEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ParseException(java.text.ParseException) EJRWTItemRendererVisualContext(org.entirej.applicationframework.rwt.utils.EJRWTItemRendererVisualContext) FocusListener(org.eclipse.swt.events.FocusListener)

Aggregations

ParseException (java.text.ParseException)1 Date (java.util.Date)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 FocusEvent (org.eclipse.swt.events.FocusEvent)1 FocusListener (org.eclipse.swt.events.FocusListener)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 KeyListener (org.eclipse.swt.events.KeyListener)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 MouseListener (org.eclipse.swt.events.MouseListener)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Button (org.eclipse.swt.widgets.Button)1 Combo (org.eclipse.swt.widgets.Combo)1 Event (org.eclipse.swt.widgets.Event)1