Search in sources :

Example 1 with ElementCreationCallback

use of com.ramussoft.database.common.ElementCreationCallback in project ramus by Vitaliy-Yakovchuk.

the class NDataPluginFactory method createDataPlugin.

private DataPlugin createDataPlugin() {
    DataPlugin plugin = (DataPlugin) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { DataPlugin.class }, new InvocationHandler() {

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            try {
                String name = method.getName();
                if ("getBaseFunction".equals(name)) {
                    if (rowBaseFunction == null) {
                        rowBaseFunction = getBaseFunction(dataPlugin, baseFunction);
                    }
                    return rowBaseFunction;
                }
                if ("getBaseFunctionQualifier".equals(name))
                    return baseFunction;
                if ("isReadOnly".equals(name))
                    return !dataPlugin.getAccessRules().canUpdateQualifier(baseFunction.getId());
                if ("createRow".equals(name)) {
                    com.ramussoft.pb.Row parent = (com.ramussoft.pb.Row) args[0];
                    RowSet set = dataPlugin.getRowSet(baseFunction.getId());
                    if (parent instanceof Function) {
                        Row row = set.createRow((Row) parent);
                        ((NFunction) row).setDefaultValues();
                        ((NFunction) row).setDecompositionType(((Function) parent).getDecompositionType());
                        return row;
                    }
                } else if ("createFunction".equals(name)) {
                    com.ramussoft.pb.Function parent = (com.ramussoft.pb.Function) args[0];
                    final Integer type = (Integer) args[1];
                    RowSet set = dataPlugin.getRowSet(baseFunction.getId());
                    if (parent instanceof Function) {
                        Row row = set.createRow((Row) parent, new ElementCreationCallback() {

                            @Override
                            public void created(Element element) {
                                Engine engine = dataPlugin.getEngine();
                                Attribute attribute = IDEF0Plugin.getFunctionTypeAttribute(engine);
                                engine.setAttribute(element, attribute, type);
                            }
                        });
                        ((NFunction) row).setDefaultValues();
                        ((NFunction) row).setDecompositionType(((Function) parent).getDecompositionType());
                        return row;
                    }
                } else if ((("getChilds".equals(name)) || ("getRecChilds".equals(name))) && (args[0] == null) && (((Boolean) args[1]) == false)) {
                    Vector v = (Vector) method.invoke(dataPlugin, args);
                    v.add(0, dataPlugin.getBaseStream());
                    v.add(0, getBaseFunction(dataPlugin, baseFunction));
                    return v;
                }
                if ("getProjectOptions".equals(name))
                    return getProjectOptions();
                if ("setProjectOptions".equals(name))
                    return setProjectOptions((ProjectOptions) args[0]);
                if ("refresh".equals(name)) {
                    fullRefrash((GUIFramework) args[0]);
                    return null;
                }
                return method.invoke(dataPlugin, args);
            } catch (InvocationTargetException e) {
                throw e.getTargetException();
            }
        }

        private Row getBaseFunction(final NDataPlugin dataPlugin, final Qualifier baseFunction) {
            return dataPlugin.getNBaseFunction(baseFunction.getId());
        }

        protected Object setProjectOptions(ProjectOptions projectOptions) {
            getBaseFunction(dataPlugin, baseFunction).setAttribute(IDEF0Plugin.getProjectPreferencesAttrtibute(dataPlugin.getEngine()), projectOptions);
            return null;
        }

        protected Object getProjectOptions() {
            return getBaseFunction(dataPlugin, baseFunction).getAttribute(IDEF0Plugin.getProjectPreferencesAttrtibute(dataPlugin.getEngine()));
        }
    });
    plugin.getBaseFunction();
    return plugin;
}
Also used : NFunction(com.ramussoft.pb.data.negine.NFunction) Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) RowSet(com.ramussoft.database.common.RowSet) Function(com.ramussoft.pb.Function) NFunction(com.ramussoft.pb.data.negine.NFunction) ElementCreationCallback(com.ramussoft.database.common.ElementCreationCallback) Qualifier(com.ramussoft.common.Qualifier) Vector(java.util.Vector) Engine(com.ramussoft.common.Engine) NDataPlugin(com.ramussoft.pb.data.negine.NDataPlugin) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) InvocationTargetException(java.lang.reflect.InvocationTargetException) Row(com.ramussoft.database.common.Row) DataPlugin(com.ramussoft.pb.DataPlugin) NDataPlugin(com.ramussoft.pb.data.negine.NDataPlugin) ProjectOptions(com.dsoft.pb.idef.elements.ProjectOptions)

Aggregations

ProjectOptions (com.dsoft.pb.idef.elements.ProjectOptions)1 Attribute (com.ramussoft.common.Attribute)1 Element (com.ramussoft.common.Element)1 Engine (com.ramussoft.common.Engine)1 Qualifier (com.ramussoft.common.Qualifier)1 ElementCreationCallback (com.ramussoft.database.common.ElementCreationCallback)1 Row (com.ramussoft.database.common.Row)1 RowSet (com.ramussoft.database.common.RowSet)1 DataPlugin (com.ramussoft.pb.DataPlugin)1 Function (com.ramussoft.pb.Function)1 NDataPlugin (com.ramussoft.pb.data.negine.NDataPlugin)1 NFunction (com.ramussoft.pb.data.negine.NFunction)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Vector (java.util.Vector)1