Search in sources :

Example 26 with EJScreenItemProperties

use of org.entirej.framework.core.properties.interfaces.EJScreenItemProperties 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

EJScreenItemProperties (org.entirej.framework.core.properties.interfaces.EJScreenItemProperties)26 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)16 EJDataRecord (org.entirej.framework.core.data.EJDataRecord)16 EJCoreVisualAttributeProperties (org.entirej.framework.core.properties.EJCoreVisualAttributeProperties)16 EJItemGroupProperties (org.entirej.framework.core.properties.interfaces.EJItemGroupProperties)14 EJFrameworkExtensionProperties (org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties)13 Color (org.eclipse.swt.graphics.Color)12 EJCoreMainScreenItemProperties (org.entirej.framework.core.properties.EJCoreMainScreenItemProperties)12 EJScreenItemController (org.entirej.framework.core.interfaces.EJScreenItemController)11 Group (org.eclipse.swt.widgets.Group)10 EJFrameworkExtensionPropertyListEntry (org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionPropertyListEntry)10 FocusEvent (org.eclipse.swt.events.FocusEvent)9 MouseAdapter (org.eclipse.swt.events.MouseAdapter)9 MouseEvent (org.eclipse.swt.events.MouseEvent)9 FillLayout (org.eclipse.swt.layout.FillLayout)9 GridData (org.eclipse.swt.layout.GridData)9 EJRWTEntireJGridPane (org.entirej.applicationframework.rwt.layout.EJRWTEntireJGridPane)9 EJFrameworkExtensionPropertyList (org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionPropertyList)9 ArrayList (java.util.ArrayList)8 Action (org.eclipse.jface.action.Action)8