Examples of BeanDictionary


Examples of org.apache.pivot.beans.BeanDictionary

            this.columnIndex = columnIndex;

            // Get the row data, represented as a Dictionary
            Object tableRow = tableView.getTableData().get(rowIndex);
            Dictionary<String, Object> rowData;
            BeanDictionary beanDictionary = null;
            if (tableRow instanceof Dictionary<?, ?>) {
                rowData = (Dictionary<String, Object>)tableRow;
            } else {
                beanDictionary = new BeanDictionary(tableRow);
                rowData = beanDictionary;
            }

            // Set up the editor component hierarchy
            scrollPane = new ScrollPane(ScrollPane.ScrollBarPolicy.NEVER,
                ScrollPane.ScrollBarPolicy.FILL);
            setContent(scrollPane);

            cardPane = new CardPane();
            scrollPane.setView(cardPane);

            cardPane.add(new ImageView(new ComponentImage(tableView,
                tableView.getRowBounds(rowIndex))));
            cardPane.setSelectedIndex(0);
            cardPane.getStyles().put("selectionChangeEffect", editEffect);
            cardPane.getStyles().put("selectionChangeDuration", editEffectDuration);

            tablePane = new TablePane();
            tablePane.getStyles().put("horizontalSpacing", 1);
            cardPane.add(tablePane);

            TablePane.Row tablePaneRow = new TablePane.Row(1, true);
            tablePane.getRows().add(tablePaneRow);

            // Match the table pane's columns to the table view's
            TableView.ColumnSequence tableViewColumns = tableView.getColumns();
            TablePane.ColumnSequence tablePaneColumns = tablePane.getColumns();

            for (int i = 0, n = tableViewColumns.getLength(); i < n; i++) {
                // Add a new column to the table pane to match the table view column
                TablePane.Column tablePaneColumn = new TablePane.Column();
                tablePaneColumns.add(tablePaneColumn);

                // Determine which component to use as the editor for this column
                String columnName = tableViewColumns.get(i).getName();
                Component editorComponent = null;
                if (columnName != null) {
                    editorComponent = cellEditors.get(columnName);
                }

                // Default to a TextInput editor
                if (editorComponent == null) {
                    TextInput editorTextInput = new TextInput();
                    editorTextInput.setTextKey(columnName);
                    editorComponent = editorTextInput;
                }

                // Disable the component for read-only properties. Components
                // that are already disabled must be custom cell editor
                // components and assumed to represent read-only properties.
                if (!editorComponent.isEnabled()
                    || (beanDictionary != null
                    && beanDictionary.isReadOnly(columnName))) {
                    editorComponent.getUserData().put(READ_ONLY_KEY, true);
                }

                // Add the editor component to the table pane
                tablePaneRow.add(editorComponent);
View Full Code Here

Examples of org.apache.pivot.beans.BeanDictionary

                Object tableRow = tableData.get(rowIndex);
                Dictionary<String, Object> rowData;
                if (tableRow instanceof Dictionary<?, ?>) {
                    rowData = (Dictionary<String, Object>)tableRow;
                } else {
                    rowData = new BeanDictionary(tableRow);
                }

                // Update the row data using data binding
                tablePane.store(rowData);
View Full Code Here

Examples of org.apache.pivot.beans.BeanDictionary

            if (columnName != null) {
                Dictionary<String, Object> rowData;
                if (value instanceof Dictionary<?, ?>) {
                    rowData = (Dictionary<String, Object>)value;
                } else {
                    rowData = new BeanDictionary(value);
                }

                cellData = rowData.get(columnName);
            }
View Full Code Here

Examples of org.apache.pivot.beans.BeanDictionary

                if (prefix != null
                    && prefix.length() > 0) {
                    throw new SerializationException("Property elements cannot have a namespace prefix.");
                }

                BeanDictionary beanDictionary = new BeanDictionary(element.value);

                if (beanDictionary.isReadOnly(localName)) {
                    elementType = Element.Type.READ_ONLY_PROPERTY;
                    value = beanDictionary.get(localName);
                    assert (value != null) : "Read-only properties cannot be null.";

                    if (attributes.getLength() > 0
                        && !(value instanceof Dictionary<?, ?>)) {
                        throw new SerializationException("Only read-only dictionaries can have attributes.");
View Full Code Here

Examples of org.apache.pivot.beans.BeanDictionary

                // Apply instance attributes
                Dictionary<String, Object> dictionary;
                if (element.value instanceof Dictionary<?, ?>) {
                    dictionary = (Dictionary<String, Object>)element.value;
                } else {
                    dictionary = new BeanDictionary(element.value);
                }

                for (Attribute attribute : instancePropertyAttributes) {
                    dictionary.put(attribute.localName, resolve(attribute.value));
                }

                // If the element's parent is a sequence or a listener list, add
                // the element value to it
                if (element.parent != null) {
                    if (element.parent.value instanceof Sequence<?>) {
                        Sequence<Object> sequence = (Sequence<Object>)element.parent.value;
                        sequence.add(element.value);
                    } else {
                        if (element.parent.value instanceof ListenerList<?>) {
                            ListenerList<Object> listenerList = (ListenerList<Object>)element.parent.value;
                            listenerList.add(element.value);
                        }
                    }
                }

                // Apply static attributes
                if (element.value instanceof Dictionary<?, ?>) {
                    if (staticPropertyAttributes.getLength() > 0) {
                        throw new SerializationException("Static setters are only supported"
                            + " for typed objects.");
                    }
                } else {
                    for (Attribute attribute : staticPropertyAttributes) {
                        // Determine the type of the attribute
                        String propertyClassName = attribute.namespaceURI + "."
                            + attribute.localName.substring(0, attribute.localName.lastIndexOf("."));

                        Class<?> propertyClass = null;
                        try {
                            propertyClass = Class.forName(propertyClassName);
                        } catch (ClassNotFoundException exception) {
                            throw new SerializationException(exception);
                        }

                        if (propertyClass.isInterface()) {
                            // The attribute represents an event listener
                            String listenerClassName = propertyClassName.substring(propertyClassName.lastIndexOf('.') + 1);
                            String getListenerListMethodName = "get" + Character.toUpperCase(listenerClassName.charAt(0))
                                + listenerClassName.substring(1) + "s";

                            // Get the listener list
                            Method getListenerListMethod;
                            try {
                                Class<?> type = element.value.getClass();
                                getListenerListMethod = type.getMethod(getListenerListMethodName);
                            } catch (NoSuchMethodException exception) {
                                throw new SerializationException(exception);
                            }

                            Object listenerList;
                            try {
                                listenerList = getListenerListMethod.invoke(element.value);
                            } catch (InvocationTargetException exception) {
                                throw new SerializationException(exception);
                            } catch (IllegalAccessException exception) {
                                throw new SerializationException(exception);
                            }

                            // Don't pollute the engine namespace with the listener functions
                            ScriptEngine scriptEngine = scriptEngineManager.getEngineByName(language);
                            scriptEngine.setBindings(new SimpleBindings(), ScriptContext.ENGINE_SCOPE);

                            // Create an invocation handler for this listener
                            AttributeInvocationHandler handler =
                                new AttributeInvocationHandler(scriptEngine,
                                    attribute.localName.substring(attribute.localName.lastIndexOf(".") + 1),
                                    attribute.value);

                            Object listener = Proxy.newProxyInstance(ThreadUtilities.getClassLoader(),
                                new Class<?>[]{propertyClass}, handler);

                            // Add the listener
                            Class<?> listenerListClass = listenerList.getClass();
                            Method addMethod;
                            try {
                                addMethod = listenerListClass.getMethod("add", Object.class);
                            } catch (NoSuchMethodException exception) {
                                throw new RuntimeException(exception);
                            }

                            try {
                                addMethod.invoke(listenerList, listener);
                            } catch (IllegalAccessException exception) {
                                throw new SerializationException(exception);
                            } catch (InvocationTargetException exception) {
                                throw new SerializationException(exception);
                            }
                        } else {
                            // The attribute reprsents a static setter
                            Object value = resolve(attribute.value);

                            Class<?> objectType = element.value.getClass();

                            String propertyName = attribute.localName.substring(attribute.localName.lastIndexOf(".") + 1);
                            propertyName = Character.toUpperCase(propertyName.charAt(0)) +
                            propertyName.substring(1);

                            Method setterMethod = null;
                            if (value != null) {
                                setterMethod = getStaticSetterMethod(propertyClass, propertyName,
                                    objectType, value.getClass());
                            }

                            if (setterMethod == null) {
                                Method getterMethod = getStaticGetterMethod(propertyClass, propertyName, objectType);

                                if (getterMethod != null) {
                                    Class<?> propertyType = getterMethod.getReturnType();
                                    setterMethod = getStaticSetterMethod(propertyClass, propertyName,
                                        objectType, propertyType);

                                    if (value instanceof String) {
                                        value = BeanDictionary.coerce((String)value, propertyType);
                                    }
                                }
                            }

                            if (setterMethod == null) {
                                throw new SerializationException(attribute.localName + " is not valid static property.");
                            }

                            // Invoke the setter
                            try {
                                setterMethod.invoke(null, element.value, value);
                            } catch (Exception exception) {
                                throw new SerializationException(exception);
                            }
                        }
                    }
                }

                // If the parent element is a writable property, set this as its
                // value; it will be applied later in the parent's closing tag
                if (element.parent != null
                    && element.parent.type == Element.Type.WRITABLE_PROPERTY) {
                    element.parent.value = element.value;
                }

                break;
            }

            case READ_ONLY_PROPERTY: {
                if (element.value instanceof Dictionary<?, ?>) {
                    // Process attributes looking for instance property setters
                    for (Attribute attribute : element.attributes) {
                        if (Character.isUpperCase(attribute.localName.charAt(0))) {
                            throw new SerializationException("Static setters are not supported"
                                + " for read-only properties.");
                        }

                        Dictionary<String, Object> dictionary =
                            (Dictionary<String, Object>)element.value;
                        dictionary.put(attribute.localName, resolve(attribute.value));
                    }
                }

                break;
            }

            case WRITABLE_PROPERTY: {
                BeanDictionary beanDictionary = new BeanDictionary(element.parent.value);
                beanDictionary.put(localName, element.value);
                break;
            }

            case SCRIPT: {
                // Process attributes looking for src and language
View Full Code Here

Examples of org.apache.pivot.beans.BeanDictionary

                Dictionary<String, Object> dictionary;
                if (value instanceof Dictionary<?, ?>) {
                    dictionary = (Dictionary<String, Object>)value;
                    value = dictionary.get(key);
                } else {
                    dictionary = new BeanDictionary(value);
                }

                if (dictionary.containsKey(key)) {
                    value = dictionary.get(key);
                } else {
View Full Code Here

Examples of org.apache.pivot.beans.BeanDictionary

        } else {
            Dictionary<String, Object> dictionary;
            if (parent instanceof Dictionary<?, ?>) {
                dictionary = (Dictionary<String, Object>)parent;
            } else {
                dictionary = new BeanDictionary(parent);
            }

            previousValue = dictionary.put(key, value);
        }
View Full Code Here

Examples of org.apache.pivot.beans.BeanDictionary

        } else {
            Dictionary<String, Object> dictionary;
            if (parent instanceof Dictionary<?, ?>) {
                dictionary = (Dictionary<String, Object>)parent;
            } else {
                dictionary = new BeanDictionary(parent);
            }

            previousValue = dictionary.remove(key);
        }
View Full Code Here

Examples of org.apache.pivot.beans.BeanDictionary

        } else {
            Dictionary<String, Object> dictionary;
            if (parent instanceof Dictionary<?, ?>) {
                dictionary = (Dictionary<String, Object>)parent;
            } else {
                dictionary = new BeanDictionary(parent);
            }

            containsKey = dictionary.containsKey(key);
        }
View Full Code Here

Examples of org.apache.pivot.beans.BeanDictionary

                item = itemClass.newInstance();

                if (item instanceof Dictionary<?, ?>) {
                    itemDictionary = (Dictionary<String, Object>)item;
                } else {
                    itemDictionary = new BeanDictionary(item);
                }
            } catch(IllegalAccessException exception) {
                throw new SerializationException(exception);
            } catch(InstantiationException exception) {
                throw new SerializationException(exception);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.