Search in sources :

Example 1 with EJApplicationLevelParameter

use of org.entirej.framework.core.data.controllers.EJApplicationLevelParameter in project rap by entirej.

the class EJRWTBanner method createContainer.

@Override
public void createContainer(final EJRWTApplicationManager manager, Composite parent, final EJFrameworkExtensionProperties rendererprop) {
    canvas = new Label(parent, getComponentStyle(rendererprop.getStringProperty(PROPERTY_ALIGNMENT), SWT.NONE));
    canvas.setLayoutData(new GridData(GridData.FILL_BOTH));
    String imagePath = null;
    if (rendererprop != null) {
        String paramName = rendererprop.getStringProperty(IMAGE_PARAM);
        final String action = rendererprop.getStringProperty(ACTION);
        if (action != null && !action.isEmpty()) {
            final Cursor cursor = new Cursor(canvas.getDisplay(), SWT.CURSOR_HAND);
            canvas.addDisposeListener(new DisposeListener() {

                @Override
                public void widgetDisposed(DisposeEvent event) {
                    cursor.dispose();
                }
            });
            canvas.setCursor(cursor);
            canvas.addMouseListener(new MouseAdapter() {

                @Override
                public void mouseUp(MouseEvent e) {
                    EJApplicationActionProcessor applicationActionProcessor = manager.getApplicationActionProcessor();
                    if (applicationActionProcessor != null) {
                        try {
                            applicationActionProcessor.executeActionCommand(manager.getFrameworkManager(), action);
                        } catch (EJActionProcessorException e1) {
                            e1.printStackTrace();
                        }
                    }
                }
            });
        }
        if (paramName != null && paramName.length() > 0) {
            final EJApplicationLevelParameter applicationLevelParameter = manager.getApplicationLevelParameter(paramName);
            if (applicationLevelParameter != null) {
                Object value = applicationLevelParameter.getValue();
                imagePath = (String) value;
                if (imagePath != null) {
                    updateImage(manager, imagePath);
                } else {
                    imagePath = rendererprop.getStringProperty(IMAGE_PATH);
                    updateImage(manager, imagePath);
                }
                applicationLevelParameter.addParameterChangedListener(new ParameterChangedListener() {

                    @Override
                    public void parameterChanged(String parameterName, Object oldValue, Object newValue) {
                        if (newValue != null) {
                            updateImage(manager, (String) newValue);
                        } else {
                            updateImage(manager, rendererprop.getStringProperty(IMAGE_PATH));
                        }
                    }
                });
            } else {
                imagePath = rendererprop.getStringProperty(IMAGE_PATH);
                updateImage(manager, imagePath);
            }
        } else {
            imagePath = rendererprop.getStringProperty(IMAGE_PATH);
            updateImage(manager, imagePath);
        }
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) MouseEvent(org.eclipse.swt.events.MouseEvent) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) EJActionProcessorException(org.entirej.framework.core.EJActionProcessorException) Cursor(org.eclipse.swt.graphics.Cursor) DisposeEvent(org.eclipse.swt.events.DisposeEvent) EJApplicationLevelParameter(org.entirej.framework.core.data.controllers.EJApplicationLevelParameter) ParameterChangedListener(org.entirej.framework.core.data.controllers.EJApplicationLevelParameter.ParameterChangedListener) EJApplicationActionProcessor(org.entirej.framework.core.actionprocessor.interfaces.EJApplicationActionProcessor) GridData(org.eclipse.swt.layout.GridData)

Example 2 with EJApplicationLevelParameter

use of org.entirej.framework.core.data.controllers.EJApplicationLevelParameter in project rap by entirej.

the class EJRWTComboItemRenderer method connectLOVItems.

private void connectLOVItems() {
    String lovDefName = _rendererProps.getStringProperty(EJRWTComboBoxRendererDefinitionProperties.LOV_DEFINITION_NAME);
    if (lovDefName == null || lovDefName.trim().length() == 0) {
        return;
    }
    String defName = lovDefName;
    EJInternalForm form = _item.getForm();
    if (lovDefName.indexOf('.') != -1) {
        defName = lovDefName.substring(0, lovDefName.indexOf('.'));
    } else {
        EJMessage message = new EJMessage("No LovDefinition item has been chosen for the ComboBox renderer properties on item: " + _itemProperties.getName());
        form.getFrameworkManager().getApplicationManager().getApplicationMessenger().handleMessage(message);
        return;
    }
    if (_item.getBlock().getProperties().isReferenceBlock()) {
        defName = String.format("%s.%s", _item.getBlock().getProperties().getName(), defName);
    }
    EJLovDefinitionProperties lovDef = form.getProperties().getLovDefinitionProperties(defName);
    if (lovDef == null) {
        return;
    }
    Collection<EJItemProperties> allItemProperties = lovDef.getBlockProperties().getAllItemProperties();
    for (EJItemProperties ejItemProperties : allItemProperties) {
        String defaultValue = ejItemProperties.getDefaultQueryValue();
        if (defaultValue == null || defaultValue.trim().length() == 0) {
            continue;
        }
        String paramTypeCode = defaultValue.substring(0, defaultValue.indexOf(':'));
        String paramValue = defaultValue.substring(defaultValue.indexOf(':') + 1);
        final Logger logger = LoggerFactory.getLogger(EJRWTComboItemRenderer.class);
        if ("APP_PARAMETER".equals(paramTypeCode)) {
            EJApplicationLevelParameter param = form.getApplicationLevelParameter(paramValue);
            if (param != null) {
                param.addParameterChangedListener(new ParameterChangedListener() {

                    @Override
                    public void parameterChanged(String parameterName, Object oldValue, Object newValue) {
                        logger.debug("APP_PARAMETER:parameterChanged %s.%s", _item.getBlock().getProperties().getName(), _item.getName());
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                _loadComboBoxValues();
                                refreshCombo();
                            }
                        });
                    }
                });
            }
        } else if ("FORM_PARAMETER".equals(paramTypeCode)) {
            EJFormParameter param = form.getFormParameter(paramValue);
            if (param != null) {
                param.addParameterChangedListener(new ParameterChangedListener() {

                    @Override
                    public void parameterChanged(String parameterName, Object oldValue, Object newValue) {
                        logger.debug("FORM_PARAMETER.parameterChanged %s.%s", _item.getBlock().getProperties().getName(), _item.getName());
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                _loadComboBoxValues();
                                refreshCombo();
                            }
                        });
                    }
                });
            }
        } else if ("BLOCK_ITEM".equals(paramTypeCode)) {
            final String blockName = paramValue.substring(0, paramValue.indexOf('.'));
            String itemName = paramValue.substring(paramValue.indexOf('.') + 1);
            EJInternalEditableBlock block = form.getBlock(blockName);
            if (block != null) {
                final String itemBlock = _item.getBlock().getProperties().getName();
                _lovInitialiedOnValueSet = true;
                if (!itemBlock.equals(blockName) || _item.getScreenType() == EJScreenType.MAIN) {
                    block.getBlockController().addNewRecordFocusedListener(new EJNewRecordFocusedListener() {

                        @Override
                        public void focusedGained(EJDataRecord focusedRecord) {
                            logger.debug(String.format("BLOCK RECORD Changed %s", blockName));
                            Display.getDefault().asyncExec(new Runnable() {

                                @Override
                                public void run() {
                                    _loadComboBoxValues();
                                    refreshCombo();
                                }
                            });
                        }
                    });
                }
                block.addDataItemValueChangedListener(itemName, new EJDataItemValueChangedListener() {

                    @Override
                    public void dataItemValueChanged(String itemName, EJDataRecord changedRecord, EJScreenType screenType) {
                        if (blockName.equals(itemBlock)) {
                            if (screenType == _item.getScreenType()) {
                                logger.debug(String.format("BLOCK_ITEM.valueChanged %s.%s", blockName, itemName));
                                Display.getDefault().asyncExec(new Runnable() {

                                    @Override
                                    public void run() {
                                        _loadComboBoxValues();
                                        refreshCombo();
                                    }
                                });
                            }
                        } else {
                            if (screenType == EJScreenType.MAIN) {
                                logger.debug(String.format("BLOCK_ITEM.valueChanged %s.%s", blockName, itemName));
                                Display.getDefault().asyncExec(new Runnable() {

                                    @Override
                                    public void run() {
                                        _loadComboBoxValues();
                                        refreshCombo();
                                    }
                                });
                            }
                        }
                    }
                });
            }
        }
    }
    EJLovController lovController = form.getLovController(defName);
    if (lovController == null) {
        return;
    }
}
Also used : EJScreenType(org.entirej.framework.core.enumerations.EJScreenType) EJFormParameter(org.entirej.framework.core.data.controllers.EJFormParameter) Logger(org.slf4j.Logger) EJApplicationLevelParameter(org.entirej.framework.core.data.controllers.EJApplicationLevelParameter) EJLovController(org.entirej.framework.core.data.controllers.EJLovController) EJInternalForm(org.entirej.framework.core.internal.EJInternalForm) EJMessage(org.entirej.framework.core.EJMessage) EJLovDefinitionProperties(org.entirej.framework.core.properties.interfaces.EJLovDefinitionProperties) ParameterChangedListener(org.entirej.framework.core.data.controllers.EJApplicationLevelParameter.ParameterChangedListener) EJDataItemValueChangedListener(org.entirej.framework.core.renderers.eventhandlers.EJDataItemValueChangedListener) EJInternalEditableBlock(org.entirej.framework.core.internal.EJInternalEditableBlock) EJNewRecordFocusedListener(org.entirej.framework.core.renderers.eventhandlers.EJNewRecordFocusedListener) EJItemProperties(org.entirej.framework.core.properties.interfaces.EJItemProperties) EJDataRecord(org.entirej.framework.core.data.EJDataRecord)

Example 3 with EJApplicationLevelParameter

use of org.entirej.framework.core.data.controllers.EJApplicationLevelParameter in project rap by entirej.

the class EJRWTStatusbar method createContainer.

@Override
public void createContainer(final EJRWTApplicationManager manager, Composite parent, EJFrameworkExtensionProperties rendererprop) {
    int style = SWT.NONE;
    panel = new Composite(parent, style);
    panel.setData(EJ_RWT.CUSTOM_VARIANT, "applayout");
    actionProcessor = manager.getApplicationActionProcessor();
    final EJFrameworkExtensionPropertyList propertyList = rendererprop.getPropertyList(SECTIONS);
    if (propertyList == null) {
        return;
    }
    List<EJFrameworkExtensionPropertyListEntry> allListEntries = propertyList.getAllListEntries();
    GridLayout layout = new GridLayout(allListEntries.size(), false);
    panel.setLayout(layout);
    for (EJFrameworkExtensionPropertyListEntry entry : allListEntries) {
        Control control;
        final String action = entry.getProperty(ACTION);
        if (action != null && action.trim().length() > 0) {
            final Link linkField;
            String alignmentProperty = entry.getProperty(PROPERTY_ALIGNMENT);
            // use workaround to make sure link also provide alignment
            if (alignmentProperty != null && alignmentProperty.trim().length() > 0) {
                if (alignmentProperty.equals(PROPERTY_ALIGNMENT_LEFT)) {
                    control = linkField = new Link(panel, style);
                } else if (alignmentProperty.equals(PROPERTY_ALIGNMENT_RIGHT)) {
                    EJRWTEntireJGridPane sub = new EJRWTEntireJGridPane(panel, 3);
                    control = sub;
                    sub.cleanLayout();
                    new Label(sub, SWT.NONE).setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
                    new Label(sub, SWT.NONE).setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
                    linkField = new Link(sub, style);
                } else if (alignmentProperty.equals(PROPERTY_ALIGNMENT_CENTER)) {
                    EJRWTEntireJGridPane sub = new EJRWTEntireJGridPane(panel, 3);
                    control = sub;
                    sub.cleanLayout();
                    new Label(sub, SWT.NONE).setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
                    linkField = new Link(sub, style);
                    new Label(sub, SWT.NONE).setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
                } else {
                    control = linkField = new Link(panel, style);
                }
            } else {
                control = linkField = new Link(panel, style);
            }
            String paramName = entry.getProperty(PARAMETER);
            if (paramName != null && paramName.length() > 0) {
                final EJApplicationLevelParameter applicationLevelParameter = manager.getApplicationLevelParameter(paramName);
                if (applicationLevelParameter != null) {
                    Object value = applicationLevelParameter.getValue();
                    linkField.setText(String.format("<a>%s</a>", (value == null ? "" : value.toString())));
                    applicationLevelParameter.addParameterChangedListener(new ParameterChangedListener() {

                        @Override
                        public void parameterChanged(String parameterName, Object oldValue, Object newValue) {
                            linkField.setText(String.format("<a>%s</a>", (newValue == null ? "" : newValue.toString())));
                        }
                    });
                }
            }
            if (actionProcessor != null) {
                linkField.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        try {
                            actionProcessor.executeActionCommand(manager.getFrameworkManager(), action);
                        } catch (EJActionProcessorException e1) {
                            logger.error(e1.getMessage(), e);
                        }
                    }
                });
            }
            // set VA
            String visualAttribute = entry.getProperty(VISUAL_ATTRIBUTE_PROPERTY);
            if (visualAttribute != null && visualAttribute.length() > 0) {
                EJCoreVisualAttributeProperties va = EJCoreProperties.getInstance().getVisualAttributesContainer().getVisualAttributeProperties(visualAttribute);
                if (va != null) {
                    Color background = EJRWTVisualAttributeUtils.INSTANCE.getBackground(va);
                    if (background != null) {
                        linkField.setBackground(background);
                    }
                    Color foreground = EJRWTVisualAttributeUtils.INSTANCE.getForeground(va);
                    if (foreground != null) {
                        linkField.setForeground(foreground);
                    }
                    linkField.setFont(EJRWTVisualAttributeUtils.INSTANCE.getFont(va, linkField.getFont()));
                }
            }
            linkField.setData(EJ_RWT.CUSTOM_VARIANT, "applayout");
            control.setData(EJ_RWT.CUSTOM_VARIANT, "applayout");
        } else {
            final Label section = new Label(panel, getComponentStyle(entry.getProperty(PROPERTY_ALIGNMENT), SWT.NONE));
            control = section;
            section.setData(EJ_RWT.MARKUP_ENABLED, Boolean.TRUE);
            String paramName = entry.getProperty(PARAMETER);
            if (paramName != null && paramName.length() > 0) {
                final EJApplicationLevelParameter applicationLevelParameter = manager.getApplicationLevelParameter(paramName);
                if (applicationLevelParameter != null) {
                    Object value = applicationLevelParameter.getValue();
                    section.setText(value == null ? "" : value.toString());
                    applicationLevelParameter.addParameterChangedListener(new ParameterChangedListener() {

                        @Override
                        public void parameterChanged(String parameterName, Object oldValue, Object newValue) {
                            section.setText(newValue == null ? "" : newValue.toString());
                        }
                    });
                }
            }
            // set VA
            String visualAttribute = entry.getProperty(VISUAL_ATTRIBUTE_PROPERTY);
            if (visualAttribute != null && visualAttribute.length() > 0) {
                EJCoreVisualAttributeProperties va = EJCoreProperties.getInstance().getVisualAttributesContainer().getVisualAttributeProperties(visualAttribute);
                if (va != null) {
                    Color background = EJRWTVisualAttributeUtils.INSTANCE.getBackground(va);
                    if (background != null) {
                        section.setBackground(background);
                    }
                    Color foreground = EJRWTVisualAttributeUtils.INSTANCE.getForeground(va);
                    if (foreground != null) {
                        section.setForeground(foreground);
                    }
                    section.setFont(EJRWTVisualAttributeUtils.INSTANCE.getFont(va, section.getFont()));
                }
            }
        }
        GridData gridData = new GridData();
        gridData.verticalAlignment = SWT.CENTER;
        gridData.grabExcessVerticalSpace = true;
        gridData.horizontalAlignment = SWT.FILL;
        control.setLayoutData(gridData);
        boolean expand = Boolean.valueOf(entry.getProperty(EXPAND_X));
        if (expand) {
            gridData.grabExcessHorizontalSpace = true;
        }
        String width = entry.getProperty(WIDTH);
        if (width != null && width.length() > 0) {
            try {
                gridData.widthHint = (Integer.parseInt(width));
            } catch (Exception ex) {
            // ignore
            }
        }
    // 
    }
}
Also used : EJFrameworkExtensionPropertyList(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionPropertyList) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Color(org.eclipse.swt.graphics.Color) Label(org.eclipse.swt.widgets.Label) EJActionProcessorException(org.entirej.framework.core.EJActionProcessorException) EJApplicationLevelParameter(org.entirej.framework.core.data.controllers.EJApplicationLevelParameter) EJActionProcessorException(org.entirej.framework.core.EJActionProcessorException) EJApplicationException(org.entirej.framework.core.EJApplicationException) ParameterChangedListener(org.entirej.framework.core.data.controllers.EJApplicationLevelParameter.ParameterChangedListener) EJFrameworkExtensionPropertyListEntry(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionPropertyListEntry) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Link(org.eclipse.swt.widgets.Link) EJRWTEntireJGridPane(org.entirej.applicationframework.rwt.layout.EJRWTEntireJGridPane) EJCoreVisualAttributeProperties(org.entirej.framework.core.properties.EJCoreVisualAttributeProperties)

Aggregations

EJApplicationLevelParameter (org.entirej.framework.core.data.controllers.EJApplicationLevelParameter)3 ParameterChangedListener (org.entirej.framework.core.data.controllers.EJApplicationLevelParameter.ParameterChangedListener)3 GridData (org.eclipse.swt.layout.GridData)2 Label (org.eclipse.swt.widgets.Label)2 EJActionProcessorException (org.entirej.framework.core.EJActionProcessorException)2 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 MouseAdapter (org.eclipse.swt.events.MouseAdapter)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Color (org.eclipse.swt.graphics.Color)1 Cursor (org.eclipse.swt.graphics.Cursor)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Control (org.eclipse.swt.widgets.Control)1 Link (org.eclipse.swt.widgets.Link)1 EJRWTEntireJGridPane (org.entirej.applicationframework.rwt.layout.EJRWTEntireJGridPane)1 EJApplicationException (org.entirej.framework.core.EJApplicationException)1 EJMessage (org.entirej.framework.core.EJMessage)1