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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations