Search in sources :

Example 21 with IPersist

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

the class FlattenedSolution method getAllDataProvidersForTable.

public Map<String, IDataProvider> getAllDataProvidersForTable(ITable table) throws RepositoryException {
    if (table == null)
        return null;
    synchronized (this) {
        if (allProvidersForTable == null)
            allProvidersForTable = new ConcurrentHashMap<ITable, Map<String, IDataProvider>>(64, 0.9f, 16);
    }
    Map<String, IDataProvider> dataProvidersMap = allProvidersForTable.get(table);
    if (dataProvidersMap == null) {
        dataProvidersMap = new HashMap<String, IDataProvider>(16, 0.9f);
        // 1) first the columns
        Iterator<Column> columns = table.getColumns().iterator();
        while (columns.hasNext()) {
            Column col = columns.next();
            ColumnInfo ci = col.getColumnInfo();
            if (ci != null && ci.isExcluded()) {
                continue;
            }
            dataProvidersMap.put(col.getDataProviderID(), col);
        }
        // 2) last the scriptcalculations and aggregates so the overlap the columns in case of stored calcs
        Iterator<TableNode> tableNodes = getTableNodes(table);
        while (tableNodes.hasNext()) {
            TableNode tableNode = tableNodes.next();
            if (tableNode != null) {
                Iterator<IPersist> it2 = tableNode.getAllObjects();
                while (it2.hasNext()) {
                    IPersist persist = it2.next();
                    if (persist instanceof IDataProvider) {
                        dataProvidersMap.put(((IDataProvider) persist).getDataProviderID(), (IDataProvider) persist);
                    }
                }
            }
        }
        Map<String, IDataProvider> currentValue = allProvidersForTable.putIfAbsent(table, dataProvidersMap);
        if (currentValue != null)
            dataProvidersMap = currentValue;
    }
    return dataProvidersMap;
}
Also used : QueryColumn(com.servoy.j2db.query.QueryColumn) Column(com.servoy.j2db.persistence.Column) IColumn(com.servoy.j2db.persistence.IColumn) IPersist(com.servoy.j2db.persistence.IPersist) TableNode(com.servoy.j2db.persistence.TableNode) ColumnInfo(com.servoy.j2db.persistence.ColumnInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IDataProvider(com.servoy.j2db.persistence.IDataProvider)

Example 22 with IPersist

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

the class FlattenedSolution method revertForm.

public Form revertForm(String name) {
    Form form = getForm(name);
    if (form == null) {
        // then revert the remove/delete
        for (IPersist persist : getIndex().getRemoved()) {
            if (persist instanceof Form && name.equals(((Form) persist).getName())) {
                getIndex().removeRemoved(persist);
                flush(persist);
                form = getForm(name);
                break;
            }
        }
    }
    if (form != null) {
        deletePersistCopy(form, true);
        form = getForm(name);
        if (form != null)
            registerChangedForm(form);
    }
    return form;
}
Also used : Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) IPersist(com.servoy.j2db.persistence.IPersist)

Example 23 with IPersist

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

the class FlattenedSolution method clonePersist.

@SuppressWarnings({ "unchecked", "nls" })
public <T extends AbstractBase> T clonePersist(T persist, String newName, AbstractBase newParent) {
    T clone = (T) persist.clonePersist(persist.getParent() == newParent ? null : newParent);
    final Map<Object, Object> updatedElementIds = AbstractPersistFactory.resetUUIDSRecursively(clone, getPersistFactory(), false);
    if (persist.getParent() == newParent) {
        newParent.addChild(clone);
    }
    // make sure that this persist is not seen as a copy a real persist/form
    clone.setRuntimeProperty(CLONE_PROPERTY, null);
    if (clone instanceof ISupportUpdateableName) {
        try {
            ((ISupportUpdateableName) clone).updateName(new ScriptNameValidator(this), newName);
        } catch (Exception e) {
            if (newParent != null) {
                newParent.removeChild(clone);
            }
            throw new RuntimeException("name '" + newName + "' invalid for the clone of " + ((ISupportName) persist).getName() + ", error: " + e.getMessage());
        }
    }
    if (clone instanceof ISupportChilds) {
        clone.acceptVisitor(new IPersistVisitor() {

            public Object visit(IPersist o) {
                if (o instanceof AbstractBase) {
                    Map<String, Object> propertiesMap = ((AbstractBase) o).getPropertiesMap();
                    for (Map.Entry<String, Object> entry : propertiesMap.entrySet()) {
                        Object elementId = updatedElementIds.get(entry.getValue());
                        if (elementId instanceof Integer) {
                            Element element = StaticContentSpecLoader.getContentSpec().getPropertyForObjectTypeByName(o.getTypeID(), entry.getKey());
                            if (element.getTypeID() == IRepository.ELEMENTS)
                                ((AbstractBase) o).setProperty(entry.getKey(), elementId);
                        } else if (entry.getValue() instanceof JSONObject) {
                            updateElementReferences((JSONObject) entry.getValue(), updatedElementIds);
                        }
                    }
                }
                return null;
            }
        });
    }
    if (securityAccess != null) {
        ConcurrentMap<Object, Integer> securityValues = securityAccess.getLeft();
        for (Object elementUUID : new HashSet(securityValues.keySet())) {
            if (updatedElementIds.containsKey(elementUUID.toString())) {
                UUID uuid = Utils.getAsUUID(updatedElementIds.get(elementUUID.toString()), false);
                if (uuid != null) {
                    securityValues.put(uuid, securityValues.get(elementUUID));
                }
            }
        }
    }
    flush(persist);
    getIndex().reload();
    return clone;
}
Also used : ISupportUpdateableName(com.servoy.j2db.persistence.ISupportUpdateableName) ISupportChilds(com.servoy.j2db.persistence.ISupportChilds) IScriptElement(com.servoy.j2db.persistence.IScriptElement) Element(com.servoy.j2db.persistence.ContentSpec.Element) AbstractBase(com.servoy.j2db.persistence.AbstractBase) RemoteException(java.rmi.RemoteException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IGlobalValueEntry(com.servoy.j2db.dataprocessing.IGlobalValueEntry) JSONObject(org.json.JSONObject) IPersist(com.servoy.j2db.persistence.IPersist) IPersistVisitor(com.servoy.j2db.persistence.IPersistVisitor) JSONObject(org.json.JSONObject) IRootObject(com.servoy.j2db.persistence.IRootObject) ScriptNameValidator(com.servoy.j2db.persistence.ScriptNameValidator) UUID(com.servoy.j2db.util.UUID) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet)

Example 24 with IPersist

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

the class ComponentFactory method createSplitPane.

private static IComponent createSplitPane(IApplication application, Form form, TabPanel meta, IScriptExecuter el) {
    RuntimeSplitPane scriptable = new RuntimeSplitPane(application.getItemFactory().createChangesRecorder(), application);
    ISplitPane splitPane = application.getItemFactory().createSplitPane(scriptable, getWebID(form, meta), meta.getTabOrientation());
    scriptable.setComponent(splitPane, meta);
    applyBasicComponentProperties(application, splitPane, meta, getStyleForBasicComponent(application, meta, form));
    try {
        int index = 0;
        Iterator<IPersist> it = meta.getTabs();
        while (it.hasNext() && index < 2) {
            Tab tab = (Tab) it.next();
            Form f = application.getFlattenedSolution().getForm(tab.getContainsFormID());
            if (f != null) {
                IFormLookupPanel flp = splitPane.createFormLookupPanel(tab.getName(), tab.getRelationName(), f.getName());
                if (index < 1)
                    splitPane.setLeftForm(flp);
                else
                    splitPane.setRightForm(flp);
                index++;
            }
        }
    } catch (Exception ex) {
        Debug.error(ex);
    }
    splitPane.setDividerLocation(meta.getTabOrientation() == TabPanel.SPLIT_HORIZONTAL ? splitPane.getSize().width / 2 : splitPane.getSize().height / 2);
    if (el != null && meta.getOnChangeMethodID() > 0) {
        splitPane.setOnDividerChangeMethodCmd((Integer.toString(meta.getOnChangeMethodID())));
        splitPane.addScriptExecuter(el);
    }
    return splitPane;
}
Also used : ISplitPane(com.servoy.j2db.ui.ISplitPane) Tab(com.servoy.j2db.persistence.Tab) IPersist(com.servoy.j2db.persistence.IPersist) IForm(com.servoy.j2db.IForm) Form(com.servoy.j2db.persistence.Form) RuntimeSplitPane(com.servoy.j2db.ui.scripting.RuntimeSplitPane) JSONException(org.json.JSONException) IOException(java.io.IOException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IFormLookupPanel(com.servoy.j2db.ui.IFormLookupPanel)

Example 25 with IPersist

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

the class ComponentFactory method createTabPanel.

private static IComponent createTabPanel(IApplication application, Form form, TabPanel meta, IScriptExecuter el) {
    // HACK:To set the selected color on a tabpanel
    Color oldColor = null;
    if (meta.getSelectedTabColor() != null) {
        oldColor = UIManager.getColor("TabbedPane.selected");
        UIManager.put("TabbedPane.selected", meta.getSelectedTabColor());
    }
    int orient = meta.getTabOrientation();
    AbstractRuntimeTabPaneAlike scriptable = null;
    ITabPanel tabs;
    if (meta.getTabOrientation() == TabPanel.ACCORDION_PANEL) {
        scriptable = new RuntimeAccordionPanel(application.getItemFactory().createChangesRecorder(), application);
        tabs = application.getItemFactory().createAccordionPanel((RuntimeAccordionPanel) scriptable, getWebID(form, meta));
    } else {
        scriptable = new RuntimeTabPanel(application.getItemFactory().createChangesRecorder(), application);
        tabs = application.getItemFactory().createTabPanel((RuntimeTabPanel) scriptable, getWebID(form, meta), orient, meta.hasOneTab());
    }
    scriptable.setComponent(tabs, meta);
    if (meta.getScrollTabs()) {
        tabs.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    } else {
        tabs.setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT);
    }
    if (el != null && meta.getOnTabChangeMethodID() > 0) {
        tabs.setOnTabChangeMethodCmd(Integer.toString(meta.getOnTabChangeMethodID()), Utils.parseJSExpressions(meta.getFlattenedMethodArguments("onTabChangeMethodID")));
        tabs.addScriptExecuter(el);
    }
    applyBasicComponentProperties(application, tabs, meta, getStyleForBasicComponent(application, meta, form));
    if (meta.getHorizontalAlignment() >= 0) {
        tabs.setHorizontalAlignment(meta.getHorizontalAlignment());
    }
    // HACK:restore so not all tabpanel get that color!
    if (meta.getSelectedTabColor() != null)
        UIManager.put("TabbedPane.selected", oldColor);
    try {
        int index = 0;
        Iterator<IPersist> it = meta.getTabs();
        while (it.hasNext()) {
            Tab tab = (Tab) it.next();
            Form f = application.getFlattenedSolution().getForm(tab.getContainsFormID());
            if (f != null) {
                IFormLookupPanel flp = tabs.createFormLookupPanel(tab.getName(), tab.getRelationName(), f.getName());
                tabs.addTab(application.getI18NMessageIfPrefixed(tab.getText()), tab.getImageMediaID(), flp, application.getI18NMessageIfPrefixed(tab.getToolTipText()));
                Color fg = tab.getForeground();
                Color bg = tab.getBackground();
                if (fg != null)
                    tabs.setTabForegroundAt(index, fg);
                if (bg != null)
                    tabs.setTabBackgroundAt(index, bg);
                String mnemonic = application.getI18NMessageIfPrefixed(tab.getMnemonic());
                if (mnemonic != null && mnemonic.length() > 0) {
                    tabs.setMnemonicAt(index, mnemonic.charAt(0));
                }
                index++;
            }
        }
    } catch (Exception ex) {
        Debug.error(ex);
    }
    return tabs;
}
Also used : AbstractRuntimeTabPaneAlike(com.servoy.j2db.ui.scripting.AbstractRuntimeTabPaneAlike) IForm(com.servoy.j2db.IForm) Form(com.servoy.j2db.persistence.Form) Color(java.awt.Color) ITabPanel(com.servoy.j2db.ui.ITabPanel) RuntimeAccordionPanel(com.servoy.j2db.ui.scripting.RuntimeAccordionPanel) JSONException(org.json.JSONException) IOException(java.io.IOException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IFormLookupPanel(com.servoy.j2db.ui.IFormLookupPanel) Tab(com.servoy.j2db.persistence.Tab) RuntimeTabPanel(com.servoy.j2db.ui.scripting.RuntimeTabPanel) IPersist(com.servoy.j2db.persistence.IPersist)

Aggregations

IPersist (com.servoy.j2db.persistence.IPersist)84 Point (java.awt.Point)26 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)23 Form (com.servoy.j2db.persistence.Form)22 ArrayList (java.util.ArrayList)22 IFormElement (com.servoy.j2db.persistence.IFormElement)20 BaseComponent (com.servoy.j2db.persistence.BaseComponent)19 HashMap (java.util.HashMap)16 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)14 IComponent (com.servoy.j2db.ui.IComponent)13 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)13 Component (org.apache.wicket.Component)13 AbstractBase (com.servoy.j2db.persistence.AbstractBase)12 JSONObject (org.json.JSONObject)10 PropertyDescription (org.sablo.specification.PropertyDescription)10 RepositoryException (com.servoy.j2db.persistence.RepositoryException)8 Tab (com.servoy.j2db.persistence.Tab)8 IPortalComponent (com.servoy.j2db.ui.IPortalComponent)8 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)7 ISupportAnchors (com.servoy.j2db.persistence.ISupportAnchors)7