Search in sources :

Example 1 with GWTJahiaNodePropertyValue

use of org.jahia.ajax.gwt.client.data.definition.GWTJahiaNodePropertyValue in project jahia by Jahia.

the class TranslationHelper method translate.

/**
 * Calls {@link TranslationService} to translate values of a property.
 * Property definition is used to determine if the values are html or plain texts.
 *
 * @param property a property
 * @param definition the corresponding property definition
 * @param srcLanguage the source language code
 * @param destLanguage the destination language code
 * @param site the site
 * @param uiLocale
 * @return the property with its values translated
 * @throws TranslationException
 */
public GWTJahiaNodeProperty translate(GWTJahiaNodeProperty property, GWTJahiaItemDefinition definition, String srcLanguage, String destLanguage, JCRSiteNode site, Locale uiLocale) throws TranslationException {
    List<String> stringValues = new ArrayList<String>();
    for (GWTJahiaNodePropertyValue value : property.getValues()) {
        stringValues.add(value.getString());
    }
    stringValues = translationService.translate(stringValues, srcLanguage, destLanguage, definition.getSelector() == GWTJahiaNodeSelectorType.RICHTEXT, site, uiLocale);
    List<GWTJahiaNodePropertyValue> translatedValues = new ArrayList<GWTJahiaNodePropertyValue>();
    for (String stringValue : stringValues) {
        translatedValues.add(new GWTJahiaNodePropertyValue(stringValue));
    }
    GWTJahiaNodeProperty translatedProperty = property.cloneObject();
    translatedProperty.setValues(translatedValues);
    return translatedProperty;
}
Also used : GWTJahiaNodePropertyValue(org.jahia.ajax.gwt.client.data.definition.GWTJahiaNodePropertyValue) GWTJahiaNodeProperty(org.jahia.ajax.gwt.client.data.definition.GWTJahiaNodeProperty) ArrayList(java.util.ArrayList)

Example 2 with GWTJahiaNodePropertyValue

use of org.jahia.ajax.gwt.client.data.definition.GWTJahiaNodePropertyValue in project jahia by Jahia.

the class TranslationHelper method translate.

/**
 * Calls {@link TranslationService} to translate values of a list of properties.
 * The number of calls is minimized : maximum two, one for html values, one for plain texts.
 * Properties definitions are used to determine if the values are html or plain texts.
 *
 * @param properties a list of properties
 * @param definitions the corresponding list of property definitions
 * @param srcLanguage the source language code
 * @param destLanguage the destination language code
 * @param site the site
 * @param uiLocale
 * @return the properties with their values translated
 * @throws TranslationException
 */
public List<GWTJahiaNodeProperty> translate(List<GWTJahiaNodeProperty> properties, List<GWTJahiaItemDefinition> definitions, String srcLanguage, String destLanguage, JCRSiteNode site, Locale uiLocale) throws TranslationException {
    List<String> plainTextValues = new ArrayList<String>();
    List<String> htmlValues = new ArrayList<String>();
    for (int i = 0; i < properties.size(); i++) {
        GWTJahiaNodeProperty property = properties.get(i);
        List<String> stringValues = definitions.get(i).getSelector() == GWTJahiaNodeSelectorType.RICHTEXT ? htmlValues : plainTextValues;
        for (GWTJahiaNodePropertyValue value : property.getValues()) {
            stringValues.add(value.getString());
        }
    }
    if (!plainTextValues.isEmpty()) {
        plainTextValues = translationService.translate(plainTextValues, srcLanguage, destLanguage, false, site, uiLocale);
    }
    if (!htmlValues.isEmpty()) {
        htmlValues = translationService.translate(htmlValues, srcLanguage, destLanguage, true, site, uiLocale);
    }
    List<GWTJahiaNodeProperty> translatedProperties = new ArrayList<GWTJahiaNodeProperty>();
    for (int i = 0; i < properties.size(); i++) {
        GWTJahiaNodeProperty property = properties.get(i);
        GWTJahiaNodeProperty translatedProperty = property.cloneObject();
        List<GWTJahiaNodePropertyValue> translatedValues = new ArrayList<GWTJahiaNodePropertyValue>();
        List<String> stringValues = definitions.get(i).getSelector() == GWTJahiaNodeSelectorType.RICHTEXT ? htmlValues : plainTextValues;
        for (GWTJahiaNodePropertyValue value : property.getValues()) {
            translatedValues.add(new GWTJahiaNodePropertyValue(stringValues.remove(0)));
        }
        translatedProperty.setValues(translatedValues);
        translatedProperties.add(translatedProperty);
    }
    return translatedProperties;
}
Also used : GWTJahiaNodePropertyValue(org.jahia.ajax.gwt.client.data.definition.GWTJahiaNodePropertyValue) GWTJahiaNodeProperty(org.jahia.ajax.gwt.client.data.definition.GWTJahiaNodeProperty) ArrayList(java.util.ArrayList)

Example 3 with GWTJahiaNodePropertyValue

use of org.jahia.ajax.gwt.client.data.definition.GWTJahiaNodePropertyValue in project jahia by Jahia.

the class WorkflowHelper method getPropertiesMap.

private Map<String, GWTJahiaNodeProperty> getPropertiesMap(Map<String, Object> variables) {
    Map<String, GWTJahiaNodeProperty> properties = new HashMap<String, GWTJahiaNodeProperty>(variables.size());
    for (Map.Entry<String, Object> entry : variables.entrySet()) {
        GWTJahiaNodeProperty property = new GWTJahiaNodeProperty();
        property.setName(entry.getKey());
        Object variable = entry.getValue();
        if (variable instanceof List) {
            List list = (List) variable;
            List<GWTJahiaNodePropertyValue> values = new ArrayList<GWTJahiaNodePropertyValue>();
            for (Object o : list) {
                if (o instanceof WorkflowVariable) {
                    values.add(new GWTJahiaNodePropertyValue(((WorkflowVariable) o).getValue(), ((WorkflowVariable) o).getType()));
                }
            }
            if (!values.isEmpty()) {
                property.setValues(values);
                properties.put(entry.getKey(), property);
            }
        } else if (variable instanceof WorkflowVariable) {
            WorkflowVariable workflowVariable = (WorkflowVariable) variable;
            String value = workflowVariable.getValue();
            if (workflowVariable.getType() == GWTJahiaNodePropertyType.DATE) {
                Calendar cal = ISO8601.parse(value);
                value = ContentDefinitionHelper.dateTimeFormat.format(cal.getTime());
            }
            property.setValue(new GWTJahiaNodePropertyValue(value, workflowVariable.getType()));
            properties.put(entry.getKey(), property);
        }
    }
    return properties;
}
Also used : GWTJahiaNodePropertyValue(org.jahia.ajax.gwt.client.data.definition.GWTJahiaNodePropertyValue) GWTJahiaNodeProperty(org.jahia.ajax.gwt.client.data.definition.GWTJahiaNodeProperty)

Example 4 with GWTJahiaNodePropertyValue

use of org.jahia.ajax.gwt.client.data.definition.GWTJahiaNodePropertyValue in project jahia by Jahia.

the class PropertiesHelper method getProperties.

public Map<String, GWTJahiaNodeProperty> getProperties(String path, JCRSessionWrapper currentUserSession, Locale uiLocale) throws GWTJahiaServiceException {
    JCRNodeWrapper objectNode;
    try {
        objectNode = currentUserSession.getNode(path);
    } catch (RepositoryException e) {
        logger.error(e.toString(), e);
        throw new GWTJahiaServiceException(new StringBuilder(path).append(Messages.getInternal("label.gwt.error.could.not.be.accessed", uiLocale)).append(e.toString()).toString());
    }
    Map<String, GWTJahiaNodeProperty> props = new HashMap<String, GWTJahiaNodeProperty>();
    String propName = "null";
    try {
        PropertyIterator it = objectNode.getProperties();
        while (it.hasNext()) {
            Property prop = it.nextProperty();
            PropertyDefinition def = prop.getDefinition();
            Property translationProp = null;
            // definition can be null if the file is versionned
            if (def != null && !ignoredProperties.contains(def.getName()) && ((ExtendedPropertyDefinition) def).getSelectorOptions().get("password") == null) {
                propName = def.getName();
                // check that we're not dealing with a not-set property from the translation nodes,
                // in which case it needs to be omitted
                final Locale locale = currentUserSession.getLocale();
                if (Constants.nonI18nPropertiesCopiedToTranslationNodes.contains(propName) && objectNode.hasI18N(locale, false)) {
                    // get the translation node for the current locale
                    final Node i18N = objectNode.getI18N(locale, false);
                    if (!i18N.hasProperty(propName)) {
                        // if the translation node doesn't have the property and it's part of the set of copied properties, then we shouldn't return it
                        continue;
                    } else {
                        translationProp = i18N.getProperty(propName);
                    }
                }
                // create the corresponding GWT bean
                GWTJahiaNodeProperty nodeProp = new GWTJahiaNodeProperty();
                nodeProp.setName(propName);
                nodeProp.setMultiple(def.isMultiple());
                Value[] values;
                if (!def.isMultiple()) {
                    Value oneValue = translationProp == null ? prop.getValue() : translationProp.getValue();
                    values = new Value[] { oneValue };
                } else {
                    values = translationProp == null ? prop.getValues() : translationProp.getValues();
                }
                List<GWTJahiaNodePropertyValue> gwtValues = new ArrayList<GWTJahiaNodePropertyValue>(values.length);
                for (Value val : values) {
                    GWTJahiaNodePropertyValue convertedValue = contentDefinition.convertValue(val, (ExtendedPropertyDefinition) def);
                    if (convertedValue != null) {
                        gwtValues.add(convertedValue);
                    }
                }
                nodeProp.setValues(gwtValues);
                props.put(nodeProp.getName(), nodeProp);
            } else {
                if (logger.isDebugEnabled()) {
                    logger.debug("The following property has been ignored " + prop.getName() + "," + prop.getPath());
                }
            }
        }
        NodeIterator ni = objectNode.getNodes();
        while (ni.hasNext()) {
            Node node = ni.nextNode();
            if (node.isNodeType(Constants.NT_RESOURCE)) {
                NodeDefinition def = node.getDefinition();
                propName = def.getName();
                // create the corresponding GWT bean
                GWTJahiaNodeProperty nodeProp = new GWTJahiaNodeProperty();
                nodeProp.setName(propName);
                List<GWTJahiaNodePropertyValue> gwtValues = new ArrayList<GWTJahiaNodePropertyValue>();
                gwtValues.add(new GWTJahiaNodePropertyValue(node.getProperty(Constants.JCR_MIMETYPE).getString(), GWTJahiaNodePropertyType.ASYNC_UPLOAD));
                nodeProp.setValues(gwtValues);
                props.put(nodeProp.getName(), nodeProp);
            } else if (node.isNodeType(Constants.JAHIANT_PAGE_LINK)) {
                // case of link
                NodeDefinition def = node.getDefinition();
                propName = def.getName();
                // create the corresponding GWT bean
                GWTJahiaNodeProperty nodeProp = new GWTJahiaNodeProperty();
                nodeProp.setName(propName);
                List<GWTJahiaNodePropertyValue> gwtValues = new ArrayList<GWTJahiaNodePropertyValue>();
                GWTJahiaNode linkNode = navigation.getGWTJahiaNode((JCRNodeWrapper) node);
                if (node.isNodeType(Constants.JAHIANT_NODE_LINK)) {
                    linkNode.set("linkType", "internal");
                } else if (node.isNodeType(Constants.JAHIANT_EXTERNAL_PAGE_LINK)) {
                    linkNode.set("linkType", "external");
                }
                // url
                if (node.hasProperty(Constants.URL)) {
                    String linkUrl = node.getProperty(Constants.URL).getValue().getString();
                    linkNode.set(Constants.URL, linkUrl);
                }
                // title
                if (node.hasProperty(Constants.JCR_TITLE)) {
                    String linkTitle = node.getProperty(Constants.JCR_TITLE).getValue().getString();
                    linkNode.set(Constants.JCR_TITLE, linkTitle);
                }
                // alt
                if (node.hasProperty(Constants.ALT)) {
                    String alt = node.getProperty(Constants.ALT).getValue().getString();
                    linkNode.set(Constants.ALT, alt);
                }
                if (node.hasProperty(Constants.NODE)) {
                    JCRValueWrapper weekReference = (JCRValueWrapper) node.getProperty(Constants.NODE).getValue();
                    Node pageNode = weekReference.getNode();
                    if (pageNode != null) {
                        linkNode.set(Constants.NODE, navigation.getGWTJahiaNode((JCRNodeWrapper) pageNode));
                        linkNode.set(Constants.ALT, pageNode.getName());
                        linkNode.set(Constants.URL, ((JCRNodeWrapper) pageNode).getUrl());
                        linkNode.set(Constants.JCR_TITLE, ((JCRNodeWrapper) pageNode).getUrl());
                    } else {
                        String resource = Messages.getInternal("label.error.invalidlink", uiLocale);
                        linkNode.set(Constants.JCR_TITLE, resource);
                        linkNode.set(Constants.ALT, resource);
                    }
                }
                GWTJahiaNodePropertyValue proper = new GWTJahiaNodePropertyValue(linkNode, GWTJahiaNodePropertyType.PAGE_LINK);
                gwtValues.add(proper);
                nodeProp.setValues(gwtValues);
                props.put(nodeProp.getName(), nodeProp);
            }
        }
    } catch (RepositoryException e) {
        logger.error("Cannot access property " + propName + " of node " + objectNode.getName(), e);
    }
    return props;
}
Also used : GWTJahiaNode(org.jahia.ajax.gwt.client.data.node.GWTJahiaNode) GWTJahiaNode(org.jahia.ajax.gwt.client.data.node.GWTJahiaNode) ExtendedNodeDefinition(org.jahia.services.content.nodetypes.ExtendedNodeDefinition) NodeDefinition(javax.jcr.nodetype.NodeDefinition) ExtendedPropertyDefinition(org.jahia.services.content.nodetypes.ExtendedPropertyDefinition) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition) GWTJahiaNodePropertyValue(org.jahia.ajax.gwt.client.data.definition.GWTJahiaNodePropertyValue) GWTJahiaServiceException(org.jahia.ajax.gwt.client.service.GWTJahiaServiceException) GWTJahiaNodeProperty(org.jahia.ajax.gwt.client.data.definition.GWTJahiaNodeProperty) GWTJahiaNodePropertyValue(org.jahia.ajax.gwt.client.data.definition.GWTJahiaNodePropertyValue) StringValue(org.apache.jackrabbit.value.StringValue) GWTJahiaNodeProperty(org.jahia.ajax.gwt.client.data.definition.GWTJahiaNodeProperty)

Example 5 with GWTJahiaNodePropertyValue

use of org.jahia.ajax.gwt.client.data.definition.GWTJahiaNodePropertyValue in project jahia by Jahia.

the class AbstractContentEngine method refillDependantListWidgetOn.

protected void refillDependantListWidgetOn(final String propertyId, final List<String> dependentProperties) {
    final String nodeTypeName = propertyId.substring(0, propertyId.indexOf('.'));
    final String propertyName = propertyId.substring(propertyId.indexOf('.') + 1);
    Map<String, List<GWTJahiaNodePropertyValue>> dependentValues = new HashMap<String, List<GWTJahiaNodePropertyValue>>();
    for (TabItem tab : tabs.getItems()) {
        EditEngineTabItem item = tab.getData("item");
        if (item instanceof PropertiesTabItem) {
            for (PropertiesEditor pe : ((PropertiesTabItem) item).getLangPropertiesEditorMap().values()) {
                if (pe != null) {
                    for (Field<?> field : pe.getFields()) {
                        if (field instanceof PropertiesEditor.PropertyAdapterField) {
                            String name = ((PropertiesEditor.PropertyAdapterField) field).getDefinition().getName();
                            if (dependentProperties.contains(name)) {
                                dependentValues.put(name, PropertiesEditor.getPropertyValues(field, pe.getGWTJahiaItemDefinition(name)));
                            }
                        }
                    }
                }
            }
        }
    }
    JahiaContentManagementService.App.getInstance().getFieldInitializerValues(nodeTypeName, propertyName, parentPath, dependentValues, new BaseAsyncCallback<GWTChoiceListInitializer>() {

        @Override
        public void onSuccess(GWTChoiceListInitializer result) {
            choiceListInitializersValues.put(propertyId, result);
            if (result.getDisplayValues() != null) {
                String nameForDualFields = "from-" + propertyName;
                for (TabItem tab : tabs.getItems()) {
                    EditEngineTabItem item = tab.getData("item");
                    if (item instanceof PropertiesTabItem) {
                        PropertiesEditor pe = ((PropertiesTabItem) item).getPropertiesEditor();
                        if (pe != null) {
                            for (Field<?> field : pe.getFields()) {
                                if (field instanceof PropertiesEditor.PropertyAdapterField) {
                                    field = ((PropertiesEditor.PropertyAdapterField) field).getField();
                                }
                                if (propertyName.equals(field.getName()) || (field instanceof DualListField<?> && nameForDualFields.equals(field.getName()))) {
                                    if (field instanceof DualListField<?>) {
                                        @SuppressWarnings("unchecked") DualListField<GWTJahiaValueDisplayBean> dualListField = (DualListField<GWTJahiaValueDisplayBean>) field;
                                        ListStore<GWTJahiaValueDisplayBean> store = dualListField.getToField().getStore();
                                        for (GWTJahiaValueDisplayBean toValue : store.getModels()) {
                                            if (!result.getDisplayValues().contains(toValue)) {
                                                store.remove(toValue);
                                            }
                                        }
                                        dualListField.getToField().getListView().refresh();
                                        store = dualListField.getFromField().getStore();
                                        store.removeAll();
                                        store.add(result.getDisplayValues());
                                        dualListField.getFromField().getListView().refresh();
                                    } else if (field instanceof ComboBox<?>) {
                                        @SuppressWarnings("unchecked") ComboBox<GWTJahiaValueDisplayBean> comboBox = (ComboBox<GWTJahiaValueDisplayBean>) field;
                                        if (comboBox.getValue() != null && !result.getDisplayValues().contains(comboBox.getValue())) {
                                            try {
                                                comboBox.clear();
                                            } catch (Exception ex) {
                                            /*
                                                             * it could happen that the combobox is empty and so exception is thrown
                                                             * and combobox isn't reinitialized
                                                             */
                                            }
                                        }
                                        ListStore<GWTJahiaValueDisplayBean> store = new ListStore<GWTJahiaValueDisplayBean>();
                                        store.add(result.getDisplayValues());
                                        comboBox.setStore(store);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        @Override
        public void onApplicationFailure(Throwable caught) {
            Log.error("Unable to load avalibale mixin", caught);
        }
    });
}
Also used : ListStore(com.extjs.gxt.ui.client.store.ListStore) GWTJahiaNodePropertyValue(org.jahia.ajax.gwt.client.data.definition.GWTJahiaNodePropertyValue) DualListField(com.extjs.gxt.ui.client.widget.form.DualListField) Field(com.extjs.gxt.ui.client.widget.form.Field) PropertiesEditor(org.jahia.ajax.gwt.client.widget.definition.PropertiesEditor) ComboBox(com.extjs.gxt.ui.client.widget.form.ComboBox) GWTChoiceListInitializer(org.jahia.ajax.gwt.client.data.GWTChoiceListInitializer) TabItem(com.extjs.gxt.ui.client.widget.TabItem) AsyncTabItem(org.jahia.ajax.gwt.client.widget.AsyncTabItem) DualListField(com.extjs.gxt.ui.client.widget.form.DualListField) GWTJahiaValueDisplayBean(org.jahia.ajax.gwt.client.data.GWTJahiaValueDisplayBean)

Aggregations

GWTJahiaNodePropertyValue (org.jahia.ajax.gwt.client.data.definition.GWTJahiaNodePropertyValue)20 GWTJahiaNodeProperty (org.jahia.ajax.gwt.client.data.definition.GWTJahiaNodeProperty)16 GWTJahiaNode (org.jahia.ajax.gwt.client.data.node.GWTJahiaNode)9 ArrayList (java.util.ArrayList)4 TabItem (com.extjs.gxt.ui.client.widget.TabItem)3 GWTJahiaNewPortletInstance (org.jahia.ajax.gwt.client.data.node.GWTJahiaNewPortletInstance)3 GWTJahiaPortletDefinition (org.jahia.ajax.gwt.client.data.node.GWTJahiaPortletDefinition)3 GWTJahiaServiceException (org.jahia.ajax.gwt.client.service.GWTJahiaServiceException)3 ExtendedPropertyDefinition (org.jahia.services.content.nodetypes.ExtendedPropertyDefinition)3 CheckBox (com.extjs.gxt.ui.client.widget.form.CheckBox)2 StringValue (org.apache.jackrabbit.value.StringValue)2 BaseAsyncCallback (org.jahia.ajax.gwt.client.core.BaseAsyncCallback)2 GWTJahiaLanguage (org.jahia.ajax.gwt.client.data.GWTJahiaLanguage)2 GWTJahiaNodeACE (org.jahia.ajax.gwt.client.data.acl.GWTJahiaNodeACE)2 GWTJahiaNodeACL (org.jahia.ajax.gwt.client.data.acl.GWTJahiaNodeACL)2 JahiaException (org.jahia.exceptions.JahiaException)2 ExtendedNodeDefinition (org.jahia.services.content.nodetypes.ExtendedNodeDefinition)2 RpcMap (com.extjs.gxt.ui.client.data.RpcMap)1 StatusProxy (com.extjs.gxt.ui.client.dnd.StatusProxy)1 ListStore (com.extjs.gxt.ui.client.store.ListStore)1