Search in sources :

Example 21 with EJCoreVisualAttributeProperties

use of org.entirej.framework.core.properties.EJCoreVisualAttributeProperties in project rap by entirej.

the class EJRWTListItemRenderer method createColumnLabelProvider.

@Override
public ColumnLabelProvider createColumnLabelProvider(final EJScreenItemProperties item, EJScreenItemController controller) {
    if (!_lovInitialied) {
        loadListBoxValues();
    }
    ColumnLabelProvider provider = new ColumnLabelProvider() {

        @Override
        public Color getBackground(Object element) {
            EJCoreVisualAttributeProperties properties = getAttributes(item, element);
            if (properties != null) {
                Color background = EJRWTVisualAttributeUtils.INSTANCE.getBackground(properties);
                if (background != null) {
                    return background;
                }
            }
            return super.getBackground(element);
        }

        @Override
        public Color getForeground(Object element) {
            EJCoreVisualAttributeProperties properties = getAttributes(item, element);
            if (properties != null) {
                Color foreground = EJRWTVisualAttributeUtils.INSTANCE.getForeground(properties);
                if (foreground != null) {
                    return foreground;
                }
            }
            return super.getForeground(element);
        }

        private EJCoreVisualAttributeProperties getAttributes(final EJScreenItemProperties item, Object element) {
            EJCoreVisualAttributeProperties properties = null;
            if (element instanceof EJDataRecord) {
                EJDataRecord record = (EJDataRecord) element;
                properties = record.getItem(item.getReferencedItemName()).getVisualAttribute();
            }
            if (properties == null) {
                properties = _visualAttributeProperties;
            }
            return properties;
        }

        @Override
        public Font getFont(Object element) {
            EJCoreVisualAttributeProperties properties = getAttributes(item, element);
            if (properties != null) {
                return EJRWTVisualAttributeUtils.INSTANCE.getFont(properties, super.getFont(element));
            }
            return super.getFont(element);
        }

        @Override
        public String getText(Object element) {
            if (element instanceof EJDataRecord) {
                EJDataRecord record = (EJDataRecord) element;
                Object value = record.getValue(item.getReferencedItemName());
                if (value != null && _listValues != null && !_listValues.isEmpty()) {
                    ListBoxValue boxValue = null;
                    for (ListBoxValue val : _listValues.values()) {
                        if (val.getItemValue() == null && value == null) {
                            boxValue = val;
                            break;
                        }
                        if (val.getItemValue() == null) {
                            continue;
                        }
                        if (val.getItemValue().equals(value)) {
                            boxValue = val;
                            break;
                        }
                    }
                    if (boxValue != null) {
                        return boxValue.toString();
                    }
                }
            }
            return "";
        }
    };
    return provider;
}
Also used : ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) EJScreenItemProperties(org.entirej.framework.core.properties.interfaces.EJScreenItemProperties) Color(org.eclipse.swt.graphics.Color) EJDataRecord(org.entirej.framework.core.data.EJDataRecord) EJCoreVisualAttributeProperties(org.entirej.framework.core.properties.EJCoreVisualAttributeProperties)

Example 22 with EJCoreVisualAttributeProperties

use of org.entirej.framework.core.properties.EJCoreVisualAttributeProperties in project rap by entirej.

the class EJRWTRadioGroupItemRenderer method createColumnLabelProvider.

@Override
public ColumnLabelProvider createColumnLabelProvider(final EJScreenItemProperties item, EJScreenItemController controller) {
    final Map<Object, String> items = new HashMap<Object, String>();
    EJFrameworkExtensionPropertyList radioButtons = _rendererProps.getPropertyList(EJRWTRadioButtonItemRendererDefinitionProperties.PROPERTY_RADIO_BUTTONS);
    for (EJFrameworkExtensionPropertyListEntry listEntry : radioButtons.getAllListEntries()) {
        Object value = getValueAsObject(_item.getReferencedItemProperties().getDataTypeClass(), listEntry.getProperty(EJRWTRadioButtonItemRendererDefinitionProperties.PROPERTY_VALUE));
        String lable = _item.getForm().translateText(listEntry.getProperty(EJRWTRadioButtonItemRendererDefinitionProperties.PROPERTY_LABEL));
        items.put(value, lable);
    }
    ColumnLabelProvider provider = new ColumnLabelProvider() {

        @Override
        public Color getBackground(Object element) {
            EJCoreVisualAttributeProperties properties = getAttributes(item, element);
            if (properties != null) {
                Color background = EJRWTVisualAttributeUtils.INSTANCE.getBackground(properties);
                if (background != null) {
                    return background;
                }
            }
            return super.getBackground(element);
        }

        @Override
        public Color getForeground(Object element) {
            EJCoreVisualAttributeProperties properties = getAttributes(item, element);
            if (properties != null) {
                Color foreground = EJRWTVisualAttributeUtils.INSTANCE.getForeground(properties);
                if (foreground != null) {
                    return foreground;
                }
            }
            return super.getForeground(element);
        }

        private EJCoreVisualAttributeProperties getAttributes(final EJScreenItemProperties item, Object element) {
            EJCoreVisualAttributeProperties properties = null;
            if (element instanceof EJDataRecord) {
                EJDataRecord record = (EJDataRecord) element;
                properties = record.getItem(item.getReferencedItemName()).getVisualAttribute();
            }
            if (properties == null) {
                properties = _visualAttributeProperties;
            }
            return properties;
        }

        @Override
        public Font getFont(Object element) {
            EJCoreVisualAttributeProperties properties = getAttributes(item, element);
            if (properties != null) {
                return EJRWTVisualAttributeUtils.INSTANCE.getFont(properties, super.getFont(element));
            }
            return super.getFont(element);
        }

        @Override
        public String getText(Object element) {
            if (element instanceof EJDataRecord) {
                EJDataRecord record = (EJDataRecord) element;
                Object value = record.getValue(item.getReferencedItemName());
                if (value != null) {
                    return items.get(value);
                }
            }
            return "";
        }
    };
    return provider;
}
Also used : ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) EJFrameworkExtensionPropertyListEntry(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionPropertyListEntry) EJFrameworkExtensionPropertyList(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionPropertyList) HashMap(java.util.HashMap) EJScreenItemProperties(org.entirej.framework.core.properties.interfaces.EJScreenItemProperties) Color(org.eclipse.swt.graphics.Color) EJDataRecord(org.entirej.framework.core.data.EJDataRecord) EJCoreVisualAttributeProperties(org.entirej.framework.core.properties.EJCoreVisualAttributeProperties)

Example 23 with EJCoreVisualAttributeProperties

use of org.entirej.framework.core.properties.EJCoreVisualAttributeProperties in project rap by entirej.

the class EJRWTTreeTableRecordBlockRenderer method createScreenItem.

public ColumnLabelProvider createScreenItem(EJRWTTreeTableViewerColumnFactory factory, EJCoreMainScreenItemProperties itemProps) {
    if (itemProps.isSpacerItem()) {
        return null;
    }
    EJScreenItemController item = _block.getScreenItem(EJScreenType.MAIN, itemProps.getReferencedItemName());
    EJManagedItemRendererWrapper renderer = item.getManagedItemRenderer();
    if (renderer != null) {
        EJFrameworkExtensionProperties blockProperties = itemProps.getBlockRendererRequiredProperties();
        EJRWTAppItemRenderer itemRenderer = (EJRWTAppItemRenderer) renderer.getUnmanagedRenderer();
        ColumnLabelProvider labelProvider = itemRenderer.createColumnLabelProvider(itemProps, item);
        if (labelProvider != null) {
            String labelOrientation = blockProperties.getStringProperty(EJRWTTreeTableBlockDefinitionProperties.COLUMN_ALIGNMENT);
            int displayedWidth = blockProperties.getIntProperty(EJRWTTreeTableBlockDefinitionProperties.DISPLAY_WIDTH_PROPERTY, 0);
            // width
            if (displayedWidth == 0) {
                if (itemProps.getLabel() != null) {
                    // add
                    displayedWidth = itemProps.getLabel().length() + 2;
                // offset
                } else {
                    displayedWidth = 5;
                }
            }
            String visualAttribute = blockProperties.getStringProperty(EJRWTTreeTableBlockDefinitionProperties.VISUAL_ATTRIBUTE_PROPERTY);
            if (visualAttribute != null) {
                EJCoreVisualAttributeProperties va = EJCoreProperties.getInstance().getVisualAttributesContainer().getVisualAttributeProperties(visualAttribute);
                if (va != null) {
                    itemRenderer.setInitialVisualAttribute(va);
                }
            }
            if (item.getProperties().getVisualAttributeProperties() != null) {
                renderer.setVisualAttribute(item.getProperties().getVisualAttributeProperties());
            }
            TreeViewerColumn viewerColumn = factory.createColumn(itemProps.getLabel(), displayedWidth, labelProvider, getComponentStyle(labelOrientation));
            TreeColumn column = viewerColumn.getColumn();
            EJ_RWT.setTestId(column, blockProperties.getName() + "." + itemProps.getReferencedItemName());
            column.setData("KEY", itemProps.getReferencedItemName());
            column.setData("VIEWER", viewerColumn);
            column.setData("ITEM", item);
            column.setToolTipText(itemProps.getHint());
            ColumnInfo info = new ColumnInfo();
            column.setData("INFO", info);
            column.setMoveable(blockProperties.getBooleanProperty(EJRWTTreeTableBlockDefinitionProperties.ALLOW_COLUMN_REORDER, true));
            column.setResizable(info.resizable = blockProperties.getBooleanProperty(EJRWTTreeTableBlockDefinitionProperties.ALLOW_COLUMN_RESIZE, true));
            if (blockProperties.getBooleanProperty(EJRWTTreeTableBlockDefinitionProperties.ALLOW_ROW_SORTING, true)) {
                EJRWTAbstractTableSorter columnSorter = itemRenderer.getColumnSorter(itemProps, item);
                if (columnSorter != null) {
                    new EJRWTTreeTableSortSelectionListener(_tableViewer, column, columnSorter, SWT.UP, false);
                }
            }
            // ensure that the width property of the table column is in
            // Characters
            Font font = labelProvider.getFont(new Object());
            if (font == null) {
                font = _tableViewer.getTree().getFont();
            }
            if (font != null) {
                float avgCharWidth = EJRWTImageRetriever.getGraphicsProvider().getAvgCharWidth(font);
                if (avgCharWidth > 0) {
                    // add
                    column.setWidth(info.width = ((int) ((column.getWidth() + 1) * avgCharWidth)));
                // +1
                // padding
                }
            }
            return labelProvider;
        }
    }
    return null;
}
Also used : EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) EJRWTAppItemRenderer(org.entirej.applicationframework.rwt.renderer.interfaces.EJRWTAppItemRenderer) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) EJRWTTreeTableSortSelectionListener(org.entirej.applicationframework.rwt.table.EJRWTTreeTableSortSelectionListener) EJScreenItemController(org.entirej.framework.core.interfaces.EJScreenItemController) EJManagedItemRendererWrapper(org.entirej.framework.core.renderers.EJManagedItemRendererWrapper) TreeColumn(org.eclipse.swt.widgets.TreeColumn) EJCoreVisualAttributeProperties(org.entirej.framework.core.properties.EJCoreVisualAttributeProperties) EJRWTAbstractTableSorter(org.entirej.applicationframework.rwt.table.EJRWTAbstractTableSorter)

Example 24 with EJCoreVisualAttributeProperties

use of org.entirej.framework.core.properties.EJCoreVisualAttributeProperties in project rap by entirej.

the class EJRWTTextItemRenderer method createColumnLabelProvider.

@Override
public ColumnLabelProvider createColumnLabelProvider(final EJScreenItemProperties item, EJScreenItemController controller) {
    ColumnLabelProvider provider = new TextHtmlEscapeSupport() {

        @Override
        public Color getBackground(Object element) {
            EJCoreVisualAttributeProperties properties = getAttributes(item, element);
            if (properties != null) {
                Color background = EJRWTVisualAttributeUtils.INSTANCE.getBackground(properties);
                if (background != null) {
                    return background;
                }
            }
            return super.getBackground(element);
        }

        @Override
        public Color getForeground(Object element) {
            EJCoreVisualAttributeProperties properties = getAttributes(item, element);
            if (properties != null) {
                Color foreground = EJRWTVisualAttributeUtils.INSTANCE.getForeground(properties);
                if (foreground != null) {
                    return foreground;
                }
            }
            return super.getForeground(element);
        }

        private EJCoreVisualAttributeProperties getAttributes(final EJScreenItemProperties item, Object element) {
            EJCoreVisualAttributeProperties properties = null;
            if (element instanceof EJDataRecord) {
                EJDataRecord record = (EJDataRecord) element;
                properties = record.getItem(item.getReferencedItemName()).getVisualAttribute();
            }
            if (properties == null) {
                properties = _visualAttributeProperties;
            }
            return properties;
        }

        @Override
        public Font getFont(Object element) {
            EJCoreVisualAttributeProperties properties = getAttributes(item, element);
            if (properties != null) {
                return EJRWTVisualAttributeUtils.INSTANCE.getFont(properties, super.getFont(element));
            }
            return super.getFont(element);
        }

        @Override
        public String getText(Object element) {
            if (element instanceof EJDataRecord) {
                EJDataRecord record = (EJDataRecord) element;
                Object value = record.getValue(item.getReferencedItemName());
                if (value instanceof String) {
                    return check(value.toString());
                }
            }
            return "";
        }

        String check(String text) {
            if (escapeHtml && text != null && !text.isEmpty()) {
                return escapeHtml(text);
            }
            return text;
        }

        String escapeHtml(String string) {
            StringBuilder escapedTxt = new StringBuilder();
            for (int i = 0; i < string.length(); i++) {
                char tmp = string.charAt(i);
                switch(tmp) {
                    case '<':
                        escapedTxt.append("&lt;");
                        break;
                    case '>':
                        escapedTxt.append("&gt;");
                        break;
                    case '&':
                        escapedTxt.append("&amp;");
                        break;
                    case '"':
                        escapedTxt.append("&quot;");
                        break;
                    case '\'':
                        escapedTxt.append("&#x27;");
                        break;
                    case '/':
                        escapedTxt.append("&#x2F;");
                        break;
                    default:
                        escapedTxt.append(tmp);
                }
            }
            return escapedTxt.toString();
        }
    };
    return provider;
}
Also used : ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) EJScreenItemProperties(org.entirej.framework.core.properties.interfaces.EJScreenItemProperties) Color(org.eclipse.swt.graphics.Color) EJDataRecord(org.entirej.framework.core.data.EJDataRecord) EJCoreVisualAttributeProperties(org.entirej.framework.core.properties.EJCoreVisualAttributeProperties)

Aggregations

EJCoreVisualAttributeProperties (org.entirej.framework.core.properties.EJCoreVisualAttributeProperties)24 EJScreenItemProperties (org.entirej.framework.core.properties.interfaces.EJScreenItemProperties)16 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)15 EJDataRecord (org.entirej.framework.core.data.EJDataRecord)15 Color (org.eclipse.swt.graphics.Color)12 EJScreenItemController (org.entirej.framework.core.interfaces.EJScreenItemController)12 EJFrameworkExtensionProperties (org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties)11 EJRWTAppItemRenderer (org.entirej.applicationframework.rwt.renderer.interfaces.EJRWTAppItemRenderer)8 EJCoreMainScreenItemProperties (org.entirej.framework.core.properties.EJCoreMainScreenItemProperties)8 JsonObject (org.eclipse.rap.json.JsonObject)7 EJManagedItemRendererWrapper (org.entirej.framework.core.renderers.EJManagedItemRendererWrapper)7 EJFrameworkExtensionPropertyList (org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionPropertyList)6 EJFrameworkExtensionPropertyListEntry (org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionPropertyListEntry)6 GridData (org.eclipse.swt.layout.GridData)5 EJRWTEntireJGridPane (org.entirej.applicationframework.rwt.layout.EJRWTEntireJGridPane)5 ArrayList (java.util.ArrayList)4 Action (org.eclipse.jface.action.Action)4 IAction (org.eclipse.jface.action.IAction)4 ToolBarManager (org.eclipse.jface.action.ToolBarManager)4 DisposeEvent (org.eclipse.swt.events.DisposeEvent)4