Search in sources :

Example 1 with NDataPlugin

use of com.ramussoft.pb.data.negine.NDataPlugin 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)

Example 2 with NDataPlugin

use of com.ramussoft.pb.data.negine.NDataPlugin in project ramus by Vitaliy-Yakovchuk.

the class NDataPluginFactory method fullRefrash.

public static void fullRefrash(GUIFramework framework) {
    Engine engine = framework.getEngine();
    Long long1 = (Long) engine.getPluginProperty("IDEF0", "NDataPluginRefreshId");
    if (long1 == null)
        return;
    long id = framework.getActionId(Commands.FULL_REFRESH);
    if (id == long1.longValue())
        return;
    engine.setPluginProperty("IDEF0", "NDataPluginRefreshId", new Long(id));
    List<NDataPluginFactory> list = (List<NDataPluginFactory>) engine.getPluginProperty("IDEF0", "NDataPluginFactoryList");
    NDataPlugin dataPlugin = getExistingDataPlugin(engine);
    dataPlugin.close();
    dataPlugin = new NDataPlugin(dataPlugin.getEngine(), dataPlugin.getAccessRules());
    for (NDataPluginFactory f : list) {
        f.dataPlugin = dataPlugin;
        f.rowBaseFunction = null;
    }
    engine.setPluginProperty("IDEF0", "DataPlugin", dataPlugin);
}
Also used : NDataPlugin(com.ramussoft.pb.data.negine.NDataPlugin) ArrayList(java.util.ArrayList) List(java.util.List) Engine(com.ramussoft.common.Engine)

Example 3 with NDataPlugin

use of com.ramussoft.pb.data.negine.NDataPlugin in project ramus by Vitaliy-Yakovchuk.

the class IDEF0ViewPlugin method setFramework.

@Override
public void setFramework(final GUIFramework framework) {
    super.setFramework(framework);
    this.engine = framework.getEngine();
    this.rules = framework.getAccessRules();
    this.frame.setEngine(framework);
    addOpenDiagramListener();
    addOpenStreamsViewListener();
    framework.addCloseMainFrameListener(new CloseMainFrameAdapter() {

        @Override
        public void closed() {
            Options.save();
            if (navigator != null)
                navigator.dispose();
            if (engine.getPluginProperty("Core", "MainFrame") == framework.getMainFrame()) {
                NDataPlugin dataPlugin = (NDataPlugin) engine.getPluginProperty("IDEF0", "DataPlugin");
                if (dataPlugin != null) {
                    dataPlugin.clear();
                    dataPlugin.clearAll();
                }
            }
            if (server != null) {
                try {
                    server.getServer().close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                server.interrupt();
            }
        }
    });
    framework.addActionListener("FileOpened", new ActionListener() {

        @Override
        public void onAction(ActionEvent event) {
            if (event.getValue() == null) {
                SwingUtilities.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        NewProjectDialog dialog = new NewProjectDialog(framework.getMainFrame());
                        dialog.showModal(engine, rules, framework);
                    }
                });
            }
        }
    });
    framework.addActionListener(Commands.FULL_REFRESH, new ActionListener() {

        @Override
        public void onAction(ActionEvent event) {
            if (NDataPluginFactory.getExistingDataPlugin(engine) != null)
                NDataPluginFactory.fullRefrash(framework);
        }
    });
    framework.setSystemAttributeName(IDEF0Plugin.getBackgroundColorAttribute(engine), ResourceLoader.getString("bk_color"));
    framework.setSystemAttributeName(IDEF0Plugin.getForegroundColorAttribute(engine), ResourceLoader.getString("fg_color"));
    framework.setSystemAttributeName(IDEF0Plugin.getFontAttribute(engine), ResourceLoader.getString("font"));
    framework.setSystemAttributeName(IDEF0Plugin.getFunctionTypeAttribute(engine), ResourceLoader.getString("function_type"));
    framework.setSystemAttributeName(IDEF0Plugin.getFunctionOunerAttribute(engine), ResourceLoader.getString("select_owner"));
    StreamAttributePlugin plugin = new StreamAttributePlugin();
    plugin.setFramework(framework);
    framework.setSystemAttributePlugin(IDEF0Plugin.getStreamAttribute(engine), plugin);
    framework.setSystemAttributeName(IDEF0Plugin.getStreamAttribute(engine), ResourceLoader.getString("stream"));
    framework.setSystemAttributePlugin(IDEF0Plugin.getSectorBorderEndAttribute(engine), new SectorFontAttributePlugin());
    framework.setSystemAttributeName(IDEF0Plugin.getSectorBorderEndAttribute(engine), ResourceLoader.getString("font"));
    framework.setSystemAttributePlugin(IDEF0Plugin.getSectorBorderStartAttribute(engine), new SectorColorAttributePlugin());
    framework.setSystemAttributeName(IDEF0Plugin.getSectorBorderStartAttribute(engine), ResourceLoader.getString("color"));
    framework.setSystemAttributePlugin(IDEF0Plugin.getSectorFunctionAttribute(engine), new LineStyleAttributePlugin());
    framework.setSystemAttributeName(IDEF0Plugin.getSectorFunctionAttribute(engine), ResourceLoader.getString("arrow"));
}
Also used : NewProjectDialog(com.ramussoft.pb.master.NewProjectDialog) SectorFontAttributePlugin(com.ramussoft.idef0.attribute.SectorFontAttributePlugin) StreamAttributePlugin(com.ramussoft.idef0.attribute.StreamAttributePlugin) CloseMainFrameAdapter(com.ramussoft.gui.common.event.CloseMainFrameAdapter) NDataPlugin(com.ramussoft.pb.data.negine.NDataPlugin) ActionListener(com.ramussoft.gui.common.event.ActionListener) ActionEvent(com.ramussoft.gui.common.event.ActionEvent) IOException(java.io.IOException) SectorColorAttributePlugin(com.ramussoft.idef0.attribute.SectorColorAttributePlugin) LineStyleAttributePlugin(com.ramussoft.idef0.attribute.LineStyleAttributePlugin)

Example 4 with NDataPlugin

use of com.ramussoft.pb.data.negine.NDataPlugin in project ramus by Vitaliy-Yakovchuk.

the class NDataPluginFactory method getDataPlugin.

public static DataPlugin getDataPlugin(Qualifier baseFunction, Engine e, AccessRules accessRules) {
    NDataPlugin dataPlugin = getExistingDataPlugin(e);
    if (dataPlugin == null) {
        dataPlugin = new NDataPlugin(e, accessRules);
        e.setPluginProperty("IDEF0", "DataPlugin", dataPlugin);
    }
    if (baseFunction == null)
        return dataPlugin;
    DataPlugin dp = (DataPlugin) e.getPluginProperty("IDEF0", "BaseFunction_" + baseFunction.getId());
    if (dp == null) {
        NDataPluginFactory dataPluginFactory = new NDataPluginFactory(e, baseFunction, dataPlugin);
        List<NDataPluginFactory> list = (List<NDataPluginFactory>) e.getPluginProperty("IDEF0", "NDataPluginFactoryList");
        if (list == null) {
            list = new ArrayList<NDataPluginFactory>();
            e.setPluginProperty("IDEF0", "NDataPluginFactoryList", list);
            e.setPluginProperty("IDEF0", "NDataPluginRefreshId", new Long(-1l));
        }
        list.add(dataPluginFactory);
        dp = dataPluginFactory.createDataPlugin();
        e.setPluginProperty("IDEF0", "BaseFunction_" + baseFunction.getId(), dp);
    }
    initTemplate();
    return dp;
}
Also used : NDataPlugin(com.ramussoft.pb.data.negine.NDataPlugin) ArrayList(java.util.ArrayList) List(java.util.List) DataPlugin(com.ramussoft.pb.DataPlugin) NDataPlugin(com.ramussoft.pb.data.negine.NDataPlugin)

Example 5 with NDataPlugin

use of com.ramussoft.pb.data.negine.NDataPlugin in project ramus by Vitaliy-Yakovchuk.

the class AbstractDataPlugin method createParalel.

public boolean createParalel(final Function base, final boolean copyAllRows, final boolean clearElements, final File file, final GUIFramework framework, final DataPlugin dataPlugin) throws IOException {
    Thread thread = new Thread("Model-paraleler") {

        public void run() {
            try {
                framework.propertyChanged(ModelsView.SET_UPDATE_ALL_MODELS, false);
                framework.propertyChanged(IDEF0TabView.DISABLE_SILENT_REFRESH, true);
                framework.showAnimation(ResourceLoader.getString("Wait.Message"));
                MemoryDatabase md = new MemoryDatabase() {

                    protected String getJournalDirectoryName(String tmp) {
                        return null;
                    }
                };
                final NDataPlugin fdp = new NDataPlugin(md.getEngine("idef0"), md.getAccessRules("idef0"));
                final ModelParaleler paraleler = new ModelParaleler(AbstractDataPlugin.this, fdp, framework);
                paraleler.createParalel(base, copyAllRows);
                FileIEngineImpl impl = (FileIEngineImpl) md.getEngine("idef0").getDeligate();
                impl.saveToFile(file);
                impl.close();
                if (clearElements) {
                    ((Journaled) getEngine()).startUserTransaction();
                    try {
                        paraleler.clear(base);
                    } finally {
                        ((Journaled) getEngine()).commitUserTransaction();
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                JOptionPane.showMessageDialog(framework.getMainFrame(), e.getLocalizedMessage());
            } finally {
                framework.propertyChanged(IDEF0TabView.DISABLE_SILENT_REFRESH, false);
                framework.propertyChanged(ModelsView.SET_UPDATE_ALL_MODELS, true);
                framework.propertyChanged(ModelsView.REFRESH_ALL_MODELS);
                framework.hideAnimation();
            }
        }
    };
    thread.start();
    return true;
}
Also used : Journaled(com.ramussoft.common.journal.Journaled) FileIEngineImpl(com.ramussoft.core.impl.FileIEngineImpl) NDataPlugin(com.ramussoft.pb.data.negine.NDataPlugin) ModelParaleler(com.ramussoft.idef0.ModelParaleler) MemoryDatabase(com.ramussoft.database.MemoryDatabase) IOException(java.io.IOException)

Aggregations

NDataPlugin (com.ramussoft.pb.data.negine.NDataPlugin)5 Engine (com.ramussoft.common.Engine)2 DataPlugin (com.ramussoft.pb.DataPlugin)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ProjectOptions (com.dsoft.pb.idef.elements.ProjectOptions)1 Attribute (com.ramussoft.common.Attribute)1 Element (com.ramussoft.common.Element)1 Qualifier (com.ramussoft.common.Qualifier)1 Journaled (com.ramussoft.common.journal.Journaled)1 FileIEngineImpl (com.ramussoft.core.impl.FileIEngineImpl)1 MemoryDatabase (com.ramussoft.database.MemoryDatabase)1 ElementCreationCallback (com.ramussoft.database.common.ElementCreationCallback)1 Row (com.ramussoft.database.common.Row)1 RowSet (com.ramussoft.database.common.RowSet)1 ActionEvent (com.ramussoft.gui.common.event.ActionEvent)1 ActionListener (com.ramussoft.gui.common.event.ActionListener)1 CloseMainFrameAdapter (com.ramussoft.gui.common.event.CloseMainFrameAdapter)1 ModelParaleler (com.ramussoft.idef0.ModelParaleler)1