use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class JSDataSourceNode method removeCalculation.
/**
* Removes the calculation specified by name.
*
* @sample
* var calc1 = solutionModel.getDataSourceNode("db:/example_data/customers").newCalculation("function myCalculation1() { return 123; }", JSVariable.INTEGER);
* var calc2 = solutionModel.getDataSourceNode("db:/example_data/customers").newCalculation("function myCalculation2() { return '20'; }");
*
* var c = solutionModel.getDataSourceNode("db:/example_data/customers").getCalculation("myCalculation1");
* application.output("Name: " + c.getName() + ", Stored: " + c.isStored());
*
* solutionModel.getDataSourceNode("db:/example_data/customers").removeCalculation("myCalculation1");
* c = solutionModel.getDataSourceNode("db:/example_data/customers").getCalculation("myCalculation1");
* if (c != null) {
* application.output("myCalculation could not be removed.");
* }
*
* var allCalcs = solutionModel.getDataSourceNode("db:/example_data/customers").getCalculations();
* for (var i = 0; i < allCalcs.length; i++) {
* application.output(allCalcs[i]);
* }
*
* @param name the name of the calculation to be removed
*
* @return true if the removal was successful, false otherwise
*/
@JSFunction
public boolean removeCalculation(String name) {
try {
FlattenedSolution fs = application.getFlattenedSolution();
TableNode tablenode = fs.getSolutionCopyTableNode(dataSource);
ScriptCalculation sc = tablenode.getScriptCalculation(name);
if (sc != null) {
tablenode.removeChild(sc);
return true;
}
// it is a design time calculation, therefore we "hide" it
sc = fs.getScriptCalculation(name, dataSource);
if (sc != null) {
fs.addToRemovedPersists(sc);
return true;
}
// not found
return false;
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
}
use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class PersistHelper method getOrderedStyleSheets.
public static List<String> getOrderedStyleSheets(FlattenedSolution fs) {
List<String> styleSheets = new ArrayList<String>();
List<Solution> orderedModules = new ArrayList<Solution>();
orderedModules.add(fs.getSolution());
if (fs.getModules() != null) {
buildOrderedModulesList(fs.getSolution(), orderedModules, new ArrayList<Solution>(Arrays.asList(fs.getModules())));
}
for (Solution solution : orderedModules) {
if (solution.getStyleSheetID() > 0) {
Media media = fs.getMedia(solution.getStyleSheetID());
if (media != null) {
if (!styleSheets.contains(media.getName())) {
styleSheets.add(media.getName());
}
} else {
// $NON-NLS-1$ //$NON-NLS-2$
Debug.warn("Stylesheet set for solution '" + solution.getName() + "' cannot be found");
}
}
}
return styleSheets;
}
use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class SwingFormManager method fillScriptMenu.
// fill the scripts menu
@Override
public void fillScriptMenu() {
JMenu menu = getScriptMenu();
// Remove old script methods.
menu.removeAll();
FlattenedSolution sol = getApplication().getFlattenedSolution();
if (sol.getSolution() == null)
return;
List<ScriptMenuItem> globalMenus = new ArrayList<ScriptMenuItem>();
int menuCount = 1;
Iterator<ScriptMethod> globalMethods = sol.getScriptMethods(true);
while (globalMethods.hasNext()) {
ScriptMethod sm = globalMethods.next();
ScriptMenuItem item = getScriptMenuItem(sm, new FunctionDefinition(ScriptVariable.SCOPES_DOT_PREFIX + sm.getScopeName(), sm.getName()), menuCount);
if (item != null) {
globalMenus.add(item);
if (menuCount > 0 && menuCount < 9) {
menuCount++;
} else {
menuCount = -1;
}
// just break after 50, doesn't make sense to have more in the menu..
if (globalMenus.size() > 50)
break;
}
}
JMenu globalMenu = menu;
if (// if big create sub menu for global methods
globalMenus.size() > 20) {
globalMenu = new JMenu(Messages.getString("servoy.formManager.menuGlobalMethods"));
menu.add(globalMenu);
}
Iterator<ScriptMenuItem> it = globalMenus.iterator();
while (it.hasNext()) {
ScriptMenuItem item = it.next();
globalMenu.add(item);
}
boolean insertSeparator = menu.getMenuComponentCount() > 0;
FormController fp = getCurrentMainShowingFormController();
if (fp != null) {
int nformmethods = 0;
Form form = fp.getForm();
Iterator<ScriptMethod> formMethods = form.getScriptMethods(true);
while (formMethods.hasNext()) {
ScriptMethod sm = formMethods.next();
ScriptMenuItem item = getScriptMenuItem(sm, new FunctionDefinition(form.getName(), sm.getName()), -1);
if (item != null) {
if (insertSeparator) {
menu.add(new JSeparator());
insertSeparator = false;
}
nformmethods++;
menu.add(item);
}
}
if (form.getDataSource() != null) {
insertSeparator |= nformmethods > 0;
Iterator<ScriptMethod> foundsetMethods = fp.getApplication().getFlattenedSolution().getFoundsetMethods(fp.getDataSource(), true);
while (foundsetMethods.hasNext()) {
ScriptMethod sm = foundsetMethods.next();
ScriptMenuItem item = getScriptMenuItem(sm, new FunctionDefinition(form.getName(), sm.getName()), -1);
if (item != null) {
if (insertSeparator) {
menu.add(new JSeparator());
insertSeparator = false;
}
menu.add(item);
}
}
}
}
menu.setEnabled(menu.getMenuComponentCount() > 0);
}
use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class CSSPositionPropertyType method toJSON.
public JSONWriter toJSON(JSONWriter writer, String key, CSSPosition object, PropertyDescription pd, DataConversion clientConversion, IBrowserConverterContext dataConverterContext) throws JSONException {
FormElement fe = null;
if (dataConverterContext != null && dataConverterContext.getWebObject() instanceof WebFormComponent) {
fe = ((WebFormComponent) dataConverterContext.getWebObject()).getFormElement();
}
FlattenedSolution fs = null;
Form form = null;
if (dataConverterContext != null && dataConverterContext.getWebObject() instanceof IContextProvider) {
fs = ((IContextProvider) dataConverterContext.getWebObject()).getDataConverterContext().getApplication().getFlattenedSolution();
if (((IContextProvider) dataConverterContext.getWebObject()).getDataConverterContext().getForm() != null) {
form = ((IContextProvider) dataConverterContext.getWebObject()).getDataConverterContext().getForm().getForm();
}
}
return toJSON(writer, key, object, pd, clientConversion, fe, fs, form);
}
use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class FormComponentPropertyType method toRhinoValue.
@Override
public Object toRhinoValue(Object webComponentValue, PropertyDescription pd, IWebObjectContext componentOrService, Scriptable startScriptable) {
Scriptable newObject = DefaultScope.newObject(startScriptable);
WebFormComponent webFormComponent = (WebFormComponent) componentOrService;
FlattenedSolution fs = webFormComponent.getDataConverterContext().getSolution();
FormComponentCache cache = null;
if (webComponentValue instanceof FormComponentSabloValue) {
cache = ((FormComponentSabloValue) webComponentValue).getCache();
} else {
Form form = getForm(webComponentValue, fs);
if (form == null)
return null;
// TODO return here a NativeScriptable object that understand the full hiearchy?
cache = FormElementHelper.INSTANCE.getFormComponentCache(webFormComponent.getFormElement(), pd, (JSONObject) webComponentValue, form, fs);
}
IWebFormUI formUI = webFormComponent.findParent(IWebFormUI.class);
String prefix = FormElementHelper.getStartElementName(webFormComponent.getFormElement(), pd);
for (FormElement fe : cache.getFormComponentElements()) {
String name = fe.getName();
if (name != null && !name.startsWith(FormElement.SVY_NAME_PREFIX)) {
RuntimeWebComponent webComponent = formUI.getRuntimeWebComponent(fe.getRawName());
if (webComponent != null) {
newObject.put(name.substring(prefix.length()), newObject, webComponent);
}
}
}
return newObject;
}
Aggregations