Search in sources :

Example 21 with Portal

use of com.servoy.j2db.persistence.Portal in project servoy-client by Servoy.

the class TemplateGenerator method createCellBasedView.

private static void createCellBasedView(AbstractBase obj, Form form, StringBuffer html, TextualCSS css, boolean addHeaders, int startY, int endY, Color bgColor, IServiceProvider sp, int viewType, boolean enableAnchoring, int partStartY, int partEndY) throws RepositoryException {
    try {
        html.append('\n');
        boolean sortable = true;
        boolean shouldFillAllHorizSpace = false;
        boolean[] userCssClassAdded = new boolean[] { false };
        if (obj instanceof ISupportScrollbars) {
            int scrollbars = ((ISupportScrollbars) obj).getScrollbars();
            if ((scrollbars & ISupportScrollbars.HORIZONTAL_SCROLLBAR_NEVER) == ISupportScrollbars.HORIZONTAL_SCROLLBAR_NEVER) {
                boolean hasAtLeastOneAnchored = false;
                Iterator<IPersist> it2 = obj.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
                while (it2.hasNext()) {
                    IPersist element = it2.next();
                    if (element instanceof Field || element instanceof GraphicalComponent || element instanceof Bean) {
                        if (element instanceof GraphicalComponent && ((GraphicalComponent) element).getLabelFor() != null) {
                            continue;
                        }
                        Point l = ((IFormElement) element).getLocation();
                        if (l == null) {
                            // unkown where to add
                            continue;
                        }
                        if (l.y >= startY && l.y < endY) {
                            if (element instanceof ISupportAnchors) {
                                int anchors = ((ISupportAnchors) element).getAnchors();
                                if (((anchors & IAnchorConstants.EAST) != 0) && ((anchors & IAnchorConstants.WEST) != 0)) {
                                    hasAtLeastOneAnchored = true;
                                    break;
                                }
                            }
                        }
                    }
                }
                if (hasAtLeastOneAnchored)
                    shouldFillAllHorizSpace = true;
            }
        }
        // true for list view type and multi-line portals
        boolean listViewMode = viewType == IForm.LIST_VIEW || viewType == FormController.LOCKED_LIST_VIEW;
        if (obj instanceof Form) {
            html.append("<span servoy:id='info'></span>\n<table border=0 cellpadding=0 cellspacing=0 width='100%'>\n");
            html.append(getCssClassForElement(obj, ""));
        } else // is portal
        {
            Portal p = (Portal) obj;
            listViewMode = p.getMultiLine();
            sortable = p.getSortable();
            TextualStyle styleObj = css.addStyle('#' + ComponentFactory.getWebID(form, p));
            BorderAndPadding ins = applyBaseComponentProperties(p, form, styleObj, null, null, sp);
            applyLocationAndSize(p, styleObj, ins, partStartY, partEndY, form.getSize().width, true, p.getAnchors(), sp);
            html.append("<div style='overflow: auto' ");
            html.append(getWicketIDParameter(form, p));
            // html.append(getJavaScriptIDParameter(p));
            html.append(getCssClassForElement(obj, userCssClassAdded, "portal"));
            // $NON-NLS-1$
            html.append("><span servoy:id='info'></span>\n<table cellpadding='0' cellspacing='0' class='portal'>\n");
        }
        int yOffset = 0;
        if (listViewMode) {
            if (obj instanceof Portal) {
                Iterator<IPersist> it = obj.getAllObjects();
                boolean isYOffsetSet = false;
                while (it.hasNext()) {
                    IPersist element = it.next();
                    if (element instanceof Field || element instanceof GraphicalComponent || element instanceof Bean) {
                        Point l = ((IFormElement) element).getLocation();
                        // unknown where to add
                        if (l == null)
                            continue;
                        if (l.y >= startY && l.y < endY) {
                            if (!isYOffsetSet || yOffset > (l.y - startY)) {
                                yOffset = l.y - startY;
                                isYOffsetSet = true;
                            }
                        }
                    }
                }
            }
            css.addCSSBoundsHandler(new YOffsetCSSBoundsHandler(-startY - yOffset));
        } else {
            css.addCSSBoundsHandler(NoLocationCSSBoundsHandler.INSTANCE);
        }
        html.append("<tr><td height='99%'><table border=0 cellpadding=0 cellspacing=0 width='100%'>\n");
        if (addHeaders) {
            Map<String, GraphicalComponent> labelsFor = new HashMap<String, GraphicalComponent>();
            html.append("<thead ");
            // if (sortable) html.append("servoy:id='header'");
            html.append("servoy:id='header'");
            html.append("><tr class='headerbuttons'>\n");
            Iterator<IPersist> it1 = obj.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
            while (it1.hasNext()) {
                IPersist element = it1.next();
                if (element instanceof GraphicalComponent && ((GraphicalComponent) element).getLabelFor() != null && !((GraphicalComponent) element).getLabelFor().equals("")) {
                    labelsFor.put(((GraphicalComponent) element).getLabelFor(), (GraphicalComponent) element);
                }
            }
            boolean usesImageMedia = false;
            boolean hasAtLeastOneLabelFor = false;
            Iterator<IPersist> it2 = obj.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
            while (it2.hasNext()) {
                IPersist element = it2.next();
                if (element instanceof Field || element instanceof GraphicalComponent || element instanceof Bean) {
                    if (element instanceof GraphicalComponent && ((GraphicalComponent) element).getLabelFor() != null) {
                        continue;
                    }
                    Point l = ((IFormElement) element).getLocation();
                    if (l == null) {
                        // unkown where to add
                        continue;
                    }
                    if (l.y >= startY && l.y < endY) {
                        GraphicalComponent label = labelsFor.get(((IFormElement) element).getName());
                        if (label != null)
                            hasAtLeastOneLabelFor = true;
                    }
                }
            }
            int currentColumnCount = 0;
            int headerHeight = 0;
            it2 = obj.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
            while (it2.hasNext()) {
                IPersist element = it2.next();
                if (element instanceof Field || element instanceof GraphicalComponent || element instanceof Bean) {
                    if (element instanceof GraphicalComponent && ((GraphicalComponent) element).getLabelFor() != null) {
                        continue;
                    }
                    Point l = ((IFormElement) element).getLocation();
                    if (l == null) {
                        // unkown where to add
                        continue;
                    }
                    if (l.y >= startY && l.y < endY) {
                        currentColumnCount++;
                        html.append("<th ");
                        // if (sortable) html.append(getWicketIDParameter(element));
                        html.append(getWicketIDParameter(form, element));
                        int w = ((IFormElement) element).getSize().width;
                        // minus left padding from css for th
                        w = w - 2;
                        // html.append("height='");
                        // html.append( ((IFormElement)element).getSize().height );
                        // html.append("' ");
                        TextualStyle styleObj = new TextualStyle();
                        GraphicalComponent label = labelsFor.get(((IFormElement) element).getName());
                        if (label != null) {
                            if (currentColumnCount == 1)
                                headerHeight = label.getSize().height;
                            html.append(' ');
                            BorderAndPadding ins = applyBaseComponentProperties(label, form, styleObj, (Insets) DEFAULT_LABEL_PADDING.clone(), null, sp);
                            // some css attributes were not applied
                            Pair<IStyleSheet, IStyleRule> styleInfo = ComponentFactory.getStyleForBasicComponent(sp, label, form);
                            Border cssBorder = null;
                            if (styleInfo != null) {
                                IStyleRule s = styleInfo.getRight();
                                IStyleSheet ss = styleInfo.getLeft();
                                if (ss != null && s != null) {
                                    addAttributeToStyle(styleObj, CSS.Attribute.COLOR.toString(), s.getValue(CSS.Attribute.COLOR.toString()));
                                    addAttributeToStyle(styleObj, CSS.Attribute.BACKGROUND_COLOR.toString(), s.getValue(CSS.Attribute.BACKGROUND_COLOR.toString()));
                                    addAttributeToStyle(styleObj, CSS.Attribute.FONT.toString(), s.getValue(CSS.Attribute.FONT.toString()));
                                    addAttributeToStyle(styleObj, CSS.Attribute.FONT_FAMILY.toString(), s.getValue(CSS.Attribute.FONT_FAMILY.toString()));
                                    addAttributeToStyle(styleObj, CSS.Attribute.FONT_SIZE.toString(), s.getValue(CSS.Attribute.FONT_SIZE.toString()));
                                    addAttributeToStyle(styleObj, CSS.Attribute.FONT_STYLE.toString(), s.getValue(CSS.Attribute.FONT_STYLE.toString()));
                                    addAttributeToStyle(styleObj, CSS.Attribute.FONT_VARIANT.toString(), s.getValue(CSS.Attribute.FONT_VARIANT.toString()));
                                    addAttributeToStyle(styleObj, CSS.Attribute.FONT_WEIGHT.toString(), s.getValue(CSS.Attribute.FONT_WEIGHT.toString()));
                                    cssBorder = ss.getBorder(s);
                                }
                            }
                            if (ins.border != null)
                                w = w - ins.border.left - ins.border.right;
                            applyTextProperties(label, styleObj);
                            TextualStyle bgborderstyleObj = new TextualStyle();
                            if (!sortable) {
                                bgborderstyleObj.setProperty("text-align", styleObj.getProperty("text-align"));
                                bgborderstyleObj.setProperty("color", styleObj.getProperty("color"));
                            }
                            if (label.getImageMediaID() <= 0) {
                                bgborderstyleObj.setProperty("background-image", "none");
                                usesImageMedia = false;
                            } else {
                                usesImageMedia = true;
                                // always remove background image here
                                styleObj.remove(CSS.Attribute.BACKGROUND_IMAGE.toString());
                            }
                            String styleObjBgColor = styleObj.getProperty("background-color");
                            if (styleObjBgColor != null && !"".equals(styleObjBgColor)) {
                                bgborderstyleObj.setProperty("background-color", styleObjBgColor);
                            }
                            // unless specified, set the font-weight for <th> to normal, as disabled parent component will make the font bold by default and we don't want that
                            if (styleObj.getProperty(CSS.Attribute.FONT_WEIGHT.toString()) == null) {
                                bgborderstyleObj.setProperty(CSS.Attribute.FONT_WEIGHT.toString(), "normal", false);
                            }
                            if (cssBorder != null && label.getBorderType() == null)
                                ComponentFactoryHelper.createBorderCSSProperties(ComponentFactoryHelper.createBorderString(cssBorder), bgborderstyleObj);
                            else
                                ComponentFactoryHelper.createBorderCSSProperties(label.getBorderType(), bgborderstyleObj);
                            if (headerHeight > 0)
                                bgborderstyleObj.setProperty(CSS.Attribute.HEIGHT.toString(), headerHeight + "px");
                            html.append(bgborderstyleObj.toString());
                            Enumeration<Object> e = bgborderstyleObj.keys();
                            while (e.hasMoreElements()) {
                                String key = (String) e.nextElement();
                                styleObj.remove(key);
                            }
                            if (cssBorder != null || label.getBorderType() != null) {
                                for (Attribute att : ServoyStyleSheet.borderAttributes) {
                                    // make sure all border attributes are removed
                                    styleObj.remove(att.toString());
                                }
                                for (String extendedStyleAttribute : ServoyStyleSheet.borderAttributesExtensions) {
                                    // make sure all border attributes are removed
                                    styleObj.remove(extendedStyleAttribute);
                                }
                            }
                        } else {
                            // If there is no label-for, we put a default right-border to all columns except the last.
                            if (!hasAtLeastOneLabelFor) {
                                TextualStyle defaultBorder = new TextualStyle();
                                defaultBorder.setProperty("border-right", NO_LABELFOR_DEFAULT_BORDER_WIDTH + "px solid gray");
                                html.append(defaultBorder.toString());
                            }
                        }
                        if (sortable && !usesImageMedia) {
                            html.append(getCssClassForElement((AbstractBase) element, "sortable"));
                        } else {
                            html.append(getCssClassForElement((AbstractBase) element, "nosort"));
                        }
                        html.append("width='");
                        html.append(w);
                        html.append("' ");
                        html.append('>');
                        int headerW = w;
                        if (!hasAtLeastOneLabelFor)
                            headerW -= 1;
                        html.append("<table servoy:id='headerColumnTable' cellspacing='0' cellpadding='0' width='");
                        html.append(headerW).append("px'><tr>");
                        Object fontHeight = styleObj.get(CSS.Attribute.FONT_SIZE.toString());
                        int cellHeight = 13;
                        if (fontHeight != null) {
                            String sFontHeight = fontHeight.toString().toLowerCase();
                            if (sFontHeight.endsWith("px") || sFontHeight.endsWith("pt"))
                                sFontHeight = sFontHeight.substring(0, sFontHeight.length() - 2);
                            try {
                                cellHeight = Integer.parseInt(sFontHeight);
                                cellHeight += 2;
                            } catch (NumberFormatException ex) {
                                Debug.error(ex);
                            }
                        }
                        html.append("<td height='").append(cellHeight).append("px'>");
                        styleObj.setProperty("overflow", "hidden");
                        styleObj.setProperty("left", "0px");
                        styleObj.setProperty("right", "0px");
                        styleObj.setProperty("position", "absolute");
                        TextualStyle sortLinkStyle = new TextualStyle();
                        sortLinkStyle.setProperty("position", "relative");
                        int cellWidth = (headerW - SortableCellViewHeader.ARROW_WIDTH);
                        sortLinkStyle.setProperty("width", cellWidth + "px");
                        if (sortable) {
                            sortLinkStyle.setProperty("text-align", styleObj.getProperty("text-align"));
                            html.append("<a servoy:id='sortLink' ");
                            // if (element instanceof ISupportDataProviderID && ((ISupportDataProviderID)element).getDataProviderID() != null)
                            // {
                            // html.append("class='orderOff' ");
                            // }
                            html.append(sortLinkStyle.toString());
                            html.append('>');
                            html.append("<div servoy:id='headertext' ");
                            styleObj.setProperty("cursor", "pointer");
                            styleObj.setProperty("width", cellWidth + "px");
                            html.append(styleObj.toString());
                            html.append("></div>");
                            html.append("</a>");
                        } else {
                            html.append("<div servoy:id='sortLink' ");
                            html.append(sortLinkStyle.toString());
                            html.append('>');
                            html.append("<div servoy:id='headertext' ");
                            html.append(styleObj.toString());
                            html.append("></div>");
                            html.append("</div>");
                        }
                        html.append("</td><td valign='middle' align='right'>");
                        if (sortable) {
                            html.append("<img servoy:id='resizeBar'></img>");
                        } else {
                            html.append("<span servoy:id='resizeBar'>&nbsp;</span>");
                        // html.append("<span ");
                        // html.append(getWicketIDParameter(element));
                        // html.append(styleObj.toString());
                        // html.append("></span>");
                        }
                        html.append("</td></tr></table>\n");
                        html.append("</th>\n");
                    }
                }
            }
            // when the table has no horizontal scrollbar, then there should be no filler.
            if (!shouldFillAllHorizSpace) {
                html.append("<th");
                if (bgColor != null) {
                    html.append(" style=\"background-image: none; background-color: ");
                    html.append(PersistHelper.createColorString(bgColor));
                    html.append(";\"");
                }
                // add filler (need to be a space else safari & ie7 will not display correctly)
                html.append(">&nbsp;</th>\n");
            }
            html.append("</tr></thead>\n");
        }
        html.append("<tbody servoy:id='rowsContainerBody'>\n");
        StringBuffer columns = new StringBuffer();
        int firstComponentHeight = -1;
        if (listViewMode) {
            if (!(obj instanceof Portal)) {
                Iterator<Part> partIte = form.getParts();
                while (partIte.hasNext()) {
                    Part p = partIte.next();
                    if (p.getPartType() == Part.BODY) {
                        firstComponentHeight = p.getHeight() - startY;
                        break;
                    }
                }
            }
            StringBuffer sbElements = new StringBuffer();
            Iterator<?> it = obj instanceof Portal ? obj.getAllObjects() : form.getFormElementsSortedByFormIndex();
            while (it.hasNext()) {
                Object element = it.next();
                if (element instanceof Field || element instanceof GraphicalComponent || element instanceof Bean) {
                    Point l = ((IFormElement) element).getLocation();
                    // unknown where to add
                    if (l == null)
                        continue;
                    if (l.y >= startY && l.y < endY) {
                        if (obj instanceof Portal) {
                            Dimension d = ((IFormElement) element).getSize();
                            if (l.y + d.height - startY > firstComponentHeight)
                                firstComponentHeight = l.y + d.height - startY;
                        }
                        createTableViewComponentHTMLAndStyles((IFormElement) element, form, sbElements, css, bgColor, startY, endY, enableAnchoring, sp);
                        sbElements.append('\n');
                    }
                }
            }
            columns.append("<td><div servoy:id='listViewItem' class=\"listViewItem\" tabindex=\"-1\" style=\"position: absolute; height: ").append(firstComponentHeight - yOffset).append("px;");
            if (enableAnchoring || obj instanceof Portal) {
                columns.append(" left: 0px; right: 0px;");
            } else {
                columns.append(" width: ").append(form.getWidth()).append("px;");
            }
            columns.append("\">");
            columns.append(sbElements);
            columns.append("</div></td>\n");
        } else {
            Iterator<IPersist> it = obj.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
            while (it.hasNext()) {
                IPersist element = it.next();
                if (element instanceof Field || element instanceof GraphicalComponent || element instanceof Bean) {
                    if (element instanceof GraphicalComponent && ((GraphicalComponent) element).getLabelFor() != null) {
                        continue;
                    }
                    Point l = ((IFormElement) element).getLocation();
                    if (l == null) {
                        // unkown where to add
                        continue;
                    }
                    if (l.y >= startY && l.y < endY) {
                        columns.append("<td ");
                        if (element instanceof ISupportName) {
                            String name = ((ISupportName) element).getName();
                            if (((name != null) && (name.trim().length() > 0)) || addHeaders) {
                                // this column's cells can be made invisible (and <td> tag is the one that has to change)
                                // so we will link this <td> to a wicket component
                                columns.append("servoy:id='");
                                columns.append(ComponentFactory.getWebID(form, element));
                                columns.append("_' ");
                            }
                        }
                        if (firstComponentHeight == -1)
                            firstComponentHeight = ((IFormElement) element).getSize().height;
                        if (!addHeaders && !shouldFillAllHorizSpace) {
                            columns.append("width='");
                            int w = ((IFormElement) element).getSize().width;
                            // w = w - (2+2);  //minus left+rigth padding from css for th
                            columns.append(w);
                            columns.append("' ");
                        }
                        // columns.append("valign='middle' ");
                        columns.append('>');
                        String cssClass = TABLE_VIEW_CELL_CLASS;
                        if (element instanceof Field && ((Field) element).getDisplayType() == Field.COMBOBOX) {
                            cssClass += " " + COMBOBOX_CLASS;
                        }
                        columns.append("<div class='" + cssClass + "' style='position:relative'>");
                        TextualStyle classBasedStyle = createTableViewComponentHTMLAndStyles(element, form, columns, css, bgColor, startY, endY, false, sp);
                        if (element instanceof Field) {
                            int type = ((Field) element).getDisplayType();
                            if (type == Field.PASSWORD || type == Field.TEXT_FIELD || type == Field.TYPE_AHEAD || type == Field.TEXT_AREA) {
                                classBasedStyle.setProperty("float", "left");
                            }
                        }
                        columns.append("</div>\n");
                        columns.append("</td>\n");
                    }
                }
            }
        }
        // no filler when the tableview has no horizontal scrollbar.
        if (!shouldFillAllHorizSpace) {
            // add filler (need to be a space else safari & ie7 will not display correctly)
            columns.append("<td>&nbsp;</td>\n");
        }
        html.append("<tr servoy:id='rows' ");
        html.append("height='");
        html.append(firstComponentHeight - yOffset);
        html.append("' ");
        if ((obj instanceof ISupportRowBGColorScript) && (((ISupportRowBGColorScript) obj).getRowBGColorScript() == null || ((ISupportRowBGColorScript) obj).getRowBGColorScript().trim().length() == 0)) {
            html.append("class='even'");
        }
        html.append(">\n");
        html.append(columns);
        html.append("</tr>\n");
        html.append("</tbody></table>\n");
        html.append("</td></tr>\n");
        html.append("<tr valign='bottom'>\n");
        html.append("<td servoy:id='navigator' height='1%'>&nbsp;</td>\n");
        html.append("</tr>\n");
        html.append("</table>\n");
        if (!(obj instanceof Form)) {
            html.append("</div>\n");
        }
        html.append("\n\n");
    } finally {
        css.removeCSSBoundsHandler();
    }
}
Also used : IForm(com.servoy.j2db.IForm) Form(com.servoy.j2db.persistence.Form) WebForm(com.servoy.j2db.server.headlessclient.WebForm) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) Attribute(javax.swing.text.html.CSS.Attribute) ISupportScrollbars(com.servoy.j2db.persistence.ISupportScrollbars) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) ISupportName(com.servoy.j2db.persistence.ISupportName) Bean(com.servoy.j2db.persistence.Bean) Field(com.servoy.j2db.persistence.Field) Portal(com.servoy.j2db.persistence.Portal) ISupportRowBGColorScript(com.servoy.j2db.ui.ISupportRowBGColorScript) IStyleSheet(com.servoy.j2db.util.IStyleSheet) AbstractBase(com.servoy.j2db.persistence.AbstractBase) Point(java.awt.Point) Dimension(java.awt.Dimension) Point(java.awt.Point) IFormElement(com.servoy.j2db.persistence.IFormElement) ISupportAnchors(com.servoy.j2db.persistence.ISupportAnchors) IPersist(com.servoy.j2db.persistence.IPersist) Part(com.servoy.j2db.persistence.Part) IStyleRule(com.servoy.j2db.util.IStyleRule) MatteBorder(javax.swing.border.MatteBorder) Border(javax.swing.border.Border) TitledBorder(javax.swing.border.TitledBorder) EmptyBorder(javax.swing.border.EmptyBorder)

Example 22 with Portal

use of com.servoy.j2db.persistence.Portal in project servoy-client by Servoy.

the class SortableCellViewHeaderGroup method sort.

protected final void sort(final String name, final WebCellBasedView view, int modifiers) {
    direction = Utils.getAsBoolean(sorted.get(name));
    direction = !direction;
    FormController fc = null;
    try {
        Iterator<IPersist> it = cellview.getAllObjects();
        while (it.hasNext()) {
            IPersist element = it.next();
            if (element instanceof ISupportName && element instanceof ISupportDataProviderID) {
                if (name.equals(ComponentFactory.getWebID(form, element))) {
                    IFoundSetInternal fs = ((FoundSetListWrapper) listView.getList()).getFoundSet();
                    if (fs != null) {
                        WebForm wf = listView.findParent(WebForm.class);
                        if (wf != null)
                            fc = wf.getController();
                        GraphicalComponent gc = (GraphicalComponent) view.labelsFor.get(((ISupportName) element).getName());
                        int labelForOnActionMethodId = 0;
                        if (gc != null) {
                            labelForOnActionMethodId = gc.getOnActionMethodID();
                        }
                        if (fc != null && labelForOnActionMethodId > 0) {
                            // execute on action
                            JSEvent event = new JSEvent();
                            event.setType(JSEvent.EventType.action);
                            event.setName(RepositoryHelper.getDisplayName(StaticContentSpecLoader.PROPERTY_ONSORTCMDMETHODID.getPropertyName(), Form.class));
                            event.setFormName(view.getDataAdapterList().getFormController().getName());
                            event.setModifiers(modifiers);
                            event.setElementName(gc.getName());
                            fc.executeFunction(String.valueOf(labelForOnActionMethodId), // $NON-NLS-1$
                            Utils.arrayMerge((new Object[] { event }), Utils.parseJSExpressions(gc.getFlattenedMethodArguments("onActionMethodID"))), true, null, false, // $NON-NLS-1$
                            "onActionMethodID");
                        }
                        String id = ((ISupportDataProviderID) element).getDataProviderID();
                        if (id != null) {
                            if (cellview instanceof Portal && !ScopesUtils.isVariableScope(id)) {
                                int idx = id.lastIndexOf('.');
                                if (idx > 0) {
                                    id = id.substring(idx + 1);
                                }
                            }
                            IDataProvider dataProvider = null;
                            if (fc != null) {
                                dataProvider = fs.getFoundSetManager().getApplication().getFlattenedSolution().getDataproviderLookup(fs.getFoundSetManager(), fc.getForm()).getDataProvider(id);
                            }
                            if (!(fc != null && labelForOnActionMethodId > 0)) {
                                // in case there is no onAction definned
                                if (cellview instanceof Portal || fc == null || fc.getForm().getOnSortCmdMethodID() == 0) {
                                    List<String> sortingProviders = null;
                                    try {
                                        sortingProviders = DBValueList.getShowDataproviders(fs.getFoundSetManager().getApplication().getFlattenedSolution().getValueList(((ISupportDataProviderID) element).getValuelistID()), (Table) fs.getTable(), dataProvider == null ? id : dataProvider.getDataProviderID(), fs.getFoundSetManager());
                                    } catch (RepositoryException ex) {
                                        Debug.error(ex);
                                    }
                                    if (sortingProviders == null) {
                                        // no related sort, use sort on dataProviderID instead
                                        sortingProviders = Collections.singletonList(dataProvider == null ? id : dataProvider.getDataProviderID());
                                    }
                                    List<SortColumn> list = (modifiers & Event.SHIFT_MASK) != 0 ? fs.getSortColumns() : new ArrayList<SortColumn>();
                                    for (String sortingProvider : sortingProviders) {
                                        FoundSetManager fsm = (FoundSetManager) fs.getFoundSetManager();
                                        SortColumn sc = fsm.getSortColumn(fs.getTable(), sortingProvider, false);
                                        if (sc != null && sc.getColumn().getDataProviderType() != IColumnTypes.MEDIA) {
                                            for (SortColumn oldColumn : list) {
                                                if (oldColumn.equalsIgnoreSortorder(sc)) {
                                                    sc = oldColumn;
                                                    break;
                                                }
                                            }
                                            if (!list.contains(sc))
                                                list.add(sc);
                                            sc.setSortOrder(direction ? SortColumn.ASCENDING : SortColumn.DESCENDING);
                                        }
                                        fs.sort(list, false);
                                    }
                                } else if (fc != null && fc.getForm().getOnSortCmdMethodID() != -1) {
                                    JSEvent event = new JSEvent();
                                    event.setType(JSEvent.EventType.none);
                                    event.setName(RepositoryHelper.getDisplayName(StaticContentSpecLoader.PROPERTY_ONSORTCMDMETHODID.getPropertyName(), Form.class));
                                    event.setFormName(view.getDataAdapterList().getFormController().getName());
                                    event.setModifiers(modifiers);
                                    fc.executeFunction(String.valueOf(fc.getForm().getOnSortCmdMethodID()), Utils.arrayMerge((new Object[] { dataProvider == null ? id : dataProvider.getDataProviderID(), Boolean.valueOf(direction), event }), // $NON-NLS-1$
                                    Utils.parseJSExpressions(fc.getForm().getFlattenedMethodArguments("onSortCmdMethodID"))), true, null, false, // $NON-NLS-1$
                                    "onSortCmdMethodID");
                                }
                            }
                            if ((modifiers & Event.SHIFT_MASK) == 0) {
                                sorted.clear();
                            }
                            sorted.put(name, new Boolean(direction));
                            listView.setCurrentPage(0);
                        }
                    }
                    break;
                }
            }
        }
        listView.modelChanged();
    } catch (Exception e) {
        if (fc != null) {
            if (e instanceof ServoyException) {
                ((ServoyException) e).setContext(fc.toString());
            } else {
                ServoyException se = new ServoyException();
                se.initCause(e);
                se.setContext(fc.toString());
                e = se;
            }
        }
        Debug.error("error sorting foundset: " + sorted, e);
    }
}
Also used : Form(com.servoy.j2db.persistence.Form) WebForm(com.servoy.j2db.server.headlessclient.WebForm) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) WebForm(com.servoy.j2db.server.headlessclient.WebForm) ISupportName(com.servoy.j2db.persistence.ISupportName) FoundSetListWrapper(com.servoy.j2db.dataprocessing.FoundSetListWrapper) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IDataProvider(com.servoy.j2db.persistence.IDataProvider) SortColumn(com.servoy.j2db.dataprocessing.SortColumn) ServoyException(com.servoy.j2db.util.ServoyException) Portal(com.servoy.j2db.persistence.Portal) FormController(com.servoy.j2db.FormController) FoundSetManager(com.servoy.j2db.dataprocessing.FoundSetManager) JSEvent(com.servoy.j2db.scripting.JSEvent) Table(com.servoy.j2db.persistence.Table) ISupportDataProviderID(com.servoy.j2db.persistence.ISupportDataProviderID) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ServoyException(com.servoy.j2db.util.ServoyException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IPersist(com.servoy.j2db.persistence.IPersist)

Example 23 with Portal

use of com.servoy.j2db.persistence.Portal in project servoy-client by Servoy.

the class PersistBasedFormElementImpl method getFormElementPropertyValues.

public Map<String, Object> getFormElementPropertyValues(FlattenedSolution fs, Map<String, PropertyDescription> specProperties, PropertyPath propertyPath) {
    Map<String, String> parsedAttributes = new HashMap<String, String>();
    if (persist instanceof BaseComponent) {
        Map<String, String> attributes = new HashMap<String, String>(((BaseComponent) persist).getMergedAttributes());
        if (attributes != null && attributes.size() > 0) {
            attributes.forEach((key, value) -> {
                if (value != null && key != null)
                    parsedAttributes.put(StringEscapeUtils.escapeEcmaScript(key), value);
            });
        }
    }
    if (persist instanceof IBasicWebComponent) {
        if (FormTemplateGenerator.isWebcomponentBean(persist)) {
            JSONObject jsonProperties = ((IBasicWebComponent) persist).getFlattenedJson();
            if (jsonProperties == null)
                jsonProperties = new ServoyJSONObject();
            // convert from persist design-time value (which might be non-json) to the expected value
            Map<String, Object> jsonMap = processPersistProperties(fs, specProperties, propertyPath);
            // this is handled separately as NG component definition
            jsonMap.remove(IContentSpecConstantsBase.PROPERTY_BEANXML);
            // this is handled separately as NG component definition
            jsonMap.remove(IContentSpecConstants.PROPERTY_JSON);
            try {
                // add beanXML (which is actually a JSON string here) defined properties to the map
                formElement.convertFromJSONToFormElementValues(fs, specProperties, jsonMap, formElement.getWebComponentSpec().getHandlers(), jsonProperties, propertyPath);
            } catch (Exception ex) {
                Debug.error("Error while parsing bean design json", ex);
                jsonMap.put("error", "Error while parsing bean design json(bean not supported in NGClient?): " + persist);
            }
            if (parsedAttributes.size() > 0) {
                jsonMap.put(IContentSpecConstants.PROPERTY_ATTRIBUTES, parsedAttributes);
            }
            return jsonMap;
        } else {
            Map<String, Object> defaultProperties = new HashMap<String, Object>();
            defaultProperties.put(StaticContentSpecLoader.PROPERTY_SIZE.getPropertyName(), ((IBasicWebComponent) persist).getSize());
            defaultProperties.put(StaticContentSpecLoader.PROPERTY_NAME.getPropertyName(), ((IBasicWebComponent) persist).getName());
            defaultProperties.put("error", "Bean not supported in NGClient: " + persist);
            return defaultProperties;
        }
    } else if (persist instanceof AbstractBase) {
        Map<String, Object> map = processPersistProperties(fs, specProperties, propertyPath);
        if (persist instanceof Field && ((Field) persist).getDisplayType() == Field.MULTISELECT_LISTBOX) {
            map.put("multiselectListbox", Boolean.TRUE);
        } else if (persist instanceof TabPanel) {
            convertFromTabPanelToNGProperties((IFormElement) persist, fs, map, specProperties, propertyPath);
        } else if (persist instanceof Portal) {
            convertFromPortalToNGProperties((Portal) persist, fs, map, specProperties, propertyPath);
        }
        if (parsedAttributes.size() > 0) {
            map.put(IContentSpecConstants.PROPERTY_ATTRIBUTES, parsedAttributes);
        }
        return map;
    } else {
        return Collections.emptyMap();
    }
}
Also used : TabPanel(com.servoy.j2db.persistence.TabPanel) BaseComponent(com.servoy.j2db.persistence.BaseComponent) HashMap(java.util.HashMap) AbstractBase(com.servoy.j2db.persistence.AbstractBase) JSONException(org.json.JSONException) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) Field(com.servoy.j2db.persistence.Field) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) Portal(com.servoy.j2db.persistence.Portal) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) IBasicWebComponent(com.servoy.j2db.persistence.IBasicWebComponent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with Portal

use of com.servoy.j2db.persistence.Portal in project servoy-client by Servoy.

the class ComponentFactory method createComponent.

@SuppressWarnings("nls")
public static WebFormComponent createComponent(IApplication application, IDataAdapterList dataAdapterList, FormElement fe, Container parentToAddTo, Form form) {
    // TODO anything to do here for custom special types?
    WebFormComponent webComponent = new WebFormComponent(fe.getName(), fe, dataAdapterList);
    if (parentToAddTo != null)
        parentToAddTo.add(webComponent);
    String name = fe.getName();
    IPersist persist = fe.getPersistIfAvailable();
    int elementSecurity = 0;
    if (persist != null) {
        boolean getItDirectlyBasedOnPersistAndForm = true;
        // FormComponent's child security is the security of the FormComponent
        if (fe.isFormComponentChild()) {
            String feName = fe.getName();
            // form component children security access is currently dictated by the root form component component security settings; currently one only has the Security tab in form editors not in form component editors;
            // for example if you have a form that contains a form component component A pointing to form component X that has in it a form component component B that points to form component Y
            // then the children of both X and Y in this case have the same security settings as 'root' form component component which is A;
            // so find the 'root' form component component persist and get it's access rights; this should always be found!
            String formComponentName = feName.substring(0, feName.indexOf('$'));
            for (IPersist p : form.getFlattenedFormElementsAndLayoutContainers()) {
                if (p instanceof IFormElement && formComponentName.equals(((IFormElement) p).getName())) {
                    elementSecurity = application.getFlattenedSolution().getSecurityAccess(p.getUUID(), form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
                    getItDirectlyBasedOnPersistAndForm = false;
                    break;
                }
            }
            if (getItDirectlyBasedOnPersistAndForm)
                Debug.warn("'Root' form component including component on form " + form.getName() + " was not found when trying to determine access rights for a child of a form component: " + name);
        } else if (persist.getParent() instanceof Portal) {
            elementSecurity = application.getFlattenedSolution().getSecurityAccess(((Portal) persist.getParent()).getUUID(), form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
            getItDirectlyBasedOnPersistAndForm = false;
        }
        if (getItDirectlyBasedOnPersistAndForm) {
            elementSecurity = application.getFlattenedSolution().getSecurityAccess(persist.getUUID(), form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
        }
        if (!((elementSecurity & IRepository.VIEWABLE) != 0)) {
            webComponent.setVisible(false);
        }
    }
    WebObjectSpecification componentSpec = fe.getWebComponentSpec(false);
    // first convert formElement-to-Sablo and store them in the webComponent
    for (String propName : fe.getRawPropertyValues().keySet()) {
        // TODO this if should not be necessary. currently in the case of "printable" hidden property
        if (componentSpec.getProperty(propName) == null)
            continue;
        Object value = fe.getPropertyValueConvertedForWebComponent(propName, webComponent, (DataAdapterList) dataAdapterList);
        fillProperty(value, fe.getPropertyValue(propName), componentSpec.getProperty(propName), webComponent);
    }
    // then after all of them are converted above attach them to the webComponent (so that when attach is called on any ISmartPropertyValue at least all the other properties are converted
    // this could help initialize smart properties that depend on each other faster then if we would convert and then attach right away each value)
    webComponent.propertiesInitialized();
    // overwrite accessible
    if (persist != null) {
        if (// element not accessible
        !((elementSecurity & IRepository.ACCESSIBLE) != 0)) {
            webComponent.setProperty(WebFormUI.ENABLED, false);
            Object enableValue = webComponent.getRawPropertyValue(WebFormUI.ENABLED);
            if (enableValue instanceof NGEnabledSabloValue) {
                ((NGEnabledSabloValue) enableValue).setAccessible(false);
            }
        } else {
            int formSecurity = application.getFlattenedSolution().getSecurityAccess(form.getUUID(), form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
            if (// form not accessible
            !((formSecurity & IRepository.ACCESSIBLE) != 0)) {
                webComponent.setProperty(WebFormUI.ENABLED, false);
                Object enableValue = webComponent.getRawPropertyValue(WebFormUI.ENABLED);
                if (enableValue instanceof NGEnabledSabloValue) {
                    ((NGEnabledSabloValue) enableValue).setAccessible(false);
                }
            }
        }
    }
    boolean[] foundOnDataChangeInDPConfigFromSpec = new boolean[] { false };
    componentSpec.getProperties(DataproviderPropertyType.INSTANCE, true).forEach((propertyFromSpec) -> {
        // the property type found here is for a 'dataprovider' property from the spec file of this component
        Object configOfDPOrFoundsetLinkedDP = propertyFromSpec.getConfig();
        DataproviderConfig dpConfig;
        if (configOfDPOrFoundsetLinkedDP instanceof FoundsetLinkedConfig)
            dpConfig = (DataproviderConfig) ((FoundsetLinkedConfig) configOfDPOrFoundsetLinkedDP).getWrappedConfig();
        else
            dpConfig = (DataproviderConfig) configOfDPOrFoundsetLinkedDP;
        if (dpConfig.getOnDataChange() != null && form.getOnElementDataChangeMethodID() > 0) {
            foundOnDataChangeInDPConfigFromSpec[0] = true;
            webComponent.add(dpConfig.getOnDataChange(), form.getOnElementDataChangeMethodID());
        }
    });
    // TODO should this be a part of type conversions for handlers instead?
    for (String eventName : componentSpec.getHandlers().keySet()) {
        Object eventValue = fe.getPropertyValue(eventName);
        if (eventValue instanceof String) {
            IPersist function = application.getFlattenedSolution().getScriptMethod((String) eventValue);
            if (function == null) {
                function = application.getFlattenedSolution().searchPersist((String) eventValue);
                if (function == null) {
                    Debug.warn("Script Method of value '" + eventValue + "' for handler " + eventName + " not found trying just the form " + form);
                    IPersist child = form.getChild(UUID.fromString((String) eventValue));
                    if (child != null) {
                        Debug.warn("Script Method " + child + " on the form " + form + " with uuid " + child.getUUID());
                        function = child;
                    } else {
                        Debug.warn("Still not found on Form " + form + " Script Method of value '" + eventValue + "' for handler " + eventName);
                    }
                }
            }
            if (function != null) {
                webComponent.add(eventName, function.getID());
            } else {
                Debug.warn("Event handler for " + eventName + " with value '" + eventValue + "' not found (form " + form + ", form element " + name + ")");
            }
        } else if (eventValue instanceof Number && ((Number) eventValue).intValue() > 0) {
            webComponent.add(eventName, ((Number) eventValue).intValue());
        } else if (Utils.equalObjects(eventName, StaticContentSpecLoader.PROPERTY_ONFOCUSGAINEDMETHODID.getPropertyName()) && (form.getOnElementFocusGainedMethodID() > 0)) {
            webComponent.add(eventName, form.getOnElementFocusGainedMethodID());
        } else if (Utils.equalObjects(eventName, StaticContentSpecLoader.PROPERTY_ONFOCUSLOSTMETHODID.getPropertyName()) && (form.getOnElementFocusLostMethodID() > 0)) {
            webComponent.add(eventName, form.getOnElementFocusLostMethodID());
        } else if (!foundOnDataChangeInDPConfigFromSpec[0] && Utils.equalObjects(eventName, StaticContentSpecLoader.PROPERTY_ONDATACHANGEMETHODID.getPropertyName()) && (form.getOnElementDataChangeMethodID() > 0)) {
            // legacy behavior - based on hard-coded handler name (of component)
            webComponent.add(eventName, form.getOnElementDataChangeMethodID());
        }
    }
    // just created, it should have no changes.
    webComponent.clearChanges();
    return webComponent;
}
Also used : WebObjectSpecification(org.sablo.specification.WebObjectSpecification) FoundsetLinkedConfig(com.servoy.j2db.server.ngclient.property.FoundsetLinkedConfig) IFormElement(com.servoy.j2db.persistence.IFormElement) IPersist(com.servoy.j2db.persistence.IPersist) Portal(com.servoy.j2db.persistence.Portal) NGEnabledSabloValue(com.servoy.j2db.server.ngclient.property.types.NGEnabledSabloValue) DataproviderConfig(com.servoy.j2db.server.ngclient.property.DataproviderConfig)

Example 25 with Portal

use of com.servoy.j2db.persistence.Portal in project servoy-client by Servoy.

the class ComponentFactory method getStyleForBasicComponentInternal.

private static Pair<IStyleSheet, IStyleRule> getStyleForBasicComponentInternal(IServiceProvider sp, AbstractBase bc, Form form, Set<Integer> visited) {
    if (bc == null || sp == null)
        return null;
    // Protection agains cycle in form inheritance hierarchy.
    if (!visited.add(new Integer(form.getID())))
        return null;
    Style repos_style = getStyleForForm(sp, form);
    Pair<IStyleSheet, IStyleRule> pair = null;
    if (repos_style != null) {
        IStyleSheet ss = getCSSStyle(sp, repos_style);
        String lookupName = getLookupName(bc);
        if (lookupName != null) {
            String formLookup = "";
            ISupportChilds parent = bc.getParent();
            if (parent instanceof Form) {
                String styleClass = ((Form) parent).getStyleClass();
                if (styleClass != null && styleClass.length() != 0) {
                    formLookup = "form." + styleClass;
                } else {
                    formLookup = "form";
                }
            } else if (parent instanceof Portal) {
                String styleClass = ((Portal) parent).getStyleClass();
                if (styleClass != null && styleClass.length() != 0) {
                    formLookup = "portal." + styleClass;
                } else {
                    formLookup = "portal";
                }
                parent = ((Portal) parent).getParent();
                if (parent instanceof Form) {
                    styleClass = ((Form) parent).getStyleClass();
                    if (styleClass != null && styleClass.length() != 0) {
                        formLookup = "form." + styleClass + ' ' + formLookup;
                    } else {
                        formLookup = "form " + formLookup;
                    }
                }
            }
            IStyleRule s = null;
            String styleClass = (bc instanceof BaseComponent) ? ((BaseComponent) bc).getStyleClass() : null;
            if (bc instanceof Part) {
                styleClass = ((Part) bc).getStyleClass();
            }
            if (lookupName.equals("check") || lookupName.equals("combobox") || "radio".equals(lookupName)) {
                if (styleClass != null && styleClass.length() != 0) {
                    lookupName += '.' + styleClass;
                }
                lookupName = formLookup + ' ' + lookupName;
                s = ss.getCSSRule(lookupName);
                if (s.getAttributeCount() > 0)
                    return new Pair<IStyleSheet, IStyleRule>(ss, s);
                else
                    lookupName = "field";
            }
            if (styleClass != null && styleClass.length() != 0) {
                lookupName += '.' + styleClass;
            }
            lookupName = formLookup + ' ' + lookupName;
            s = ss.getCSSRule(lookupName);
            pair = new Pair<IStyleSheet, IStyleRule>(ss, s);
        // see BoxPainter for getBorder/getInsets/getLength examples
        }
    }
    if ((pair == null || pair.getRight() == null || (pair.getRight()).getAttributeCount() == 0)) {
        if (sp.getFlattenedSolution() != null) {
            List<Form> formHierarchy = sp.getFlattenedSolution().getFormHierarchy(form);
            for (int i = 1; i < formHierarchy.size(); i++) {
                pair = getStyleForBasicComponentInternal(sp, bc, formHierarchy.get(i), visited);
                if (pair != null && pair.getRight() != null && (pair.getRight()).getAttributeCount() != 0) {
                    break;
                }
            }
        }
    }
    return pair;
}
Also used : BaseComponent(com.servoy.j2db.persistence.BaseComponent) IStyleSheet(com.servoy.j2db.util.IStyleSheet) ISupportChilds(com.servoy.j2db.persistence.ISupportChilds) IForm(com.servoy.j2db.IForm) Form(com.servoy.j2db.persistence.Form) Part(com.servoy.j2db.persistence.Part) Style(com.servoy.j2db.persistence.Style) IStyleRule(com.servoy.j2db.util.IStyleRule) Portal(com.servoy.j2db.persistence.Portal) RuntimePortal(com.servoy.j2db.ui.scripting.RuntimePortal)

Aggregations

Portal (com.servoy.j2db.persistence.Portal)25 Point (java.awt.Point)13 RuntimePortal (com.servoy.j2db.ui.scripting.RuntimePortal)10 Form (com.servoy.j2db.persistence.Form)6 IPersist (com.servoy.j2db.persistence.IPersist)6 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)5 Field (com.servoy.j2db.persistence.Field)4 IFormElement (com.servoy.j2db.persistence.IFormElement)4 IForm (com.servoy.j2db.IForm)3 IServoyAwareBean (com.servoy.j2db.dataui.IServoyAwareBean)3 AbstractBase (com.servoy.j2db.persistence.AbstractBase)3 BaseComponent (com.servoy.j2db.persistence.BaseComponent)3 Bean (com.servoy.j2db.persistence.Bean)3 Part (com.servoy.j2db.persistence.Part)3 RepositoryException (com.servoy.j2db.persistence.RepositoryException)3 WebForm (com.servoy.j2db.server.headlessclient.WebForm)3 IComponent (com.servoy.j2db.ui.IComponent)3 ISupportAnchors (com.servoy.j2db.persistence.ISupportAnchors)2 ISupportName (com.servoy.j2db.persistence.ISupportName)2 TabPanel (com.servoy.j2db.persistence.TabPanel)2