Search in sources :

Example 41 with Engine

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

the class LightClient method getEngine.

@Override
protected Engine getEngine(PluginFactory factory, PersistentFactory persistentFactory) {
    try {
        Journal journal = new Journal(null, -1l);
        journal.setEnable(false);
        final JournaledEngine journaledEngine = new JournaledEngine(factory, impl, persistentFactory.getRows(), new DirectoryJournalFactory(null), accessor);
        Engine engine = (Engine) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { Engine.class, Journaled.class }, new InvocationHandler() {

            private Journaled journaled = new Journaled() {

                boolean started = false;

                @Override
                public void undoUserTransaction() {
                }

                @Override
                public void startUserTransaction() {
                    started = true;
                }

                @Override
                public void setNoUndoPoint() {
                }

                @Override
                public void setEnable(boolean b) {
                }

                @Override
                public void rollbackUserTransaction() {
                    started = false;
                }

                @Override
                public void removeJournalListener(JournalListener listener) {
                }

                @Override
                public void redoUserTransaction() {
                }

                @Override
                public boolean isUserTransactionStarted() {
                    return started;
                }

                @Override
                public boolean isEnable() {
                    return false;
                }

                @Override
                public JournalListener[] getJournalListeners() {
                    return new JournalListener[] {};
                }

                @Override
                public void commitUserTransaction() {
                    started = false;
                }

                @Override
                public void close() {
                }

                @Override
                public boolean canUndo() {
                    return false;
                }

                @Override
                public boolean canRedo() {
                    return false;
                }

                @Override
                public void addJournalListener(JournalListener listener) {
                }

                @Override
                public long getBranch() {
                    return -1l;
                }
            };

            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                if (method.getDeclaringClass().equals(Journaled.class))
                    return method.invoke(journaled, args);
                return method.invoke(journaledEngine, args);
            }
        });
        return engine;
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : DirectoryJournalFactory(com.ramussoft.common.journal.DirectoryJournalFactory) JournalListener(com.ramussoft.common.journal.event.JournalListener) Journal(com.ramussoft.common.journal.Journal) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) Journaled(com.ramussoft.common.journal.Journaled) JournaledEngine(com.ramussoft.common.journal.JournaledEngine) Engine(com.ramussoft.common.Engine) IEngine(com.ramussoft.common.IEngine) JournaledEngine(com.ramussoft.common.journal.JournaledEngine)

Example 42 with Engine

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

the class ChartsView method createComponent.

@Override
public JComponent createComponent() {
    Engine engine = framework.getEngine();
    AccessRules accessRules = framework.getAccessRules();
    component = new RowTreeTableComponent(engine, ChartPlugin.getCharts(engine), accessRules, new RowRootCreater(), new Attribute[] { StandardAttributesPlugin.getAttributeNameAttribute(engine) }, framework);
    component.getTable().addSelectionListener(new SelectionListener() {

        @Override
        public void changeSelection(SelectionEvent event) {
            TreeTableNode selectedNode = component.getTable().getSelectedNode();
            if (selectedNode == null)
                chartPrefernecesAction.setEnabled(false);
            else {
                Row row = selectedNode.getRow();
                chartPrefernecesAction.setEnabled(row != null);
            }
            openChartAction.setEnabled(chartPrefernecesAction.isEnabled());
            deleteChartAction.setEnabled(chartPrefernecesAction.isEnabled());
        }
    });
    table = component.getTable();
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1) {
                if ((e.getClickCount() % 2 == 0) && (e.getClickCount() > 0)) {
                    openDiagram();
                } else {
                    if ((e.getClickCount() == 1) && (System.currentTimeMillis() - lastClickTime < EDIT_NAME_CLICK_DELAY) && (Arrays.equals(lastSelectedRows, table.getSelectedRows()))) {
                        if (!table.isEditing()) {
                            editTableField();
                        }
                    } else {
                        lastClickTime = System.currentTimeMillis();
                        lastSelectedRows = table.getSelectedRows();
                    }
                }
            }
        }
    });
    table.setEditIfNullEvent(false);
    table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), "EditCell");
    table.getActionMap().put("EditCell", new AbstractAction() {

        /**
         */
        private static final long serialVersionUID = 3229634866196074563L;

        @Override
        public void actionPerformed(ActionEvent e) {
            if ((table.getSelectedRow() >= 0) && (table.getSelectedColumn() >= 0))
                editTableField();
        }
    });
    table.setExportRows(true);
    return component;
}
Also used : MouseEvent(java.awt.event.MouseEvent) TreeTableNode(com.ramussoft.gui.qualifier.table.TreeTableNode) Attribute(com.ramussoft.common.Attribute) RowTreeTableComponent(com.ramussoft.gui.qualifier.table.RowTreeTableComponent) ActionEvent(java.awt.event.ActionEvent) MouseAdapter(java.awt.event.MouseAdapter) SelectionEvent(com.ramussoft.gui.qualifier.table.event.SelectionEvent) AccessRules(com.ramussoft.common.AccessRules) RowRootCreater(com.ramussoft.gui.qualifier.table.RowRootCreater) Row(com.ramussoft.database.common.Row) AbstractAction(javax.swing.AbstractAction) Engine(com.ramussoft.common.Engine) SelectionListener(com.ramussoft.gui.qualifier.table.event.SelectionListener)

Example 43 with Engine

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

the class ChartsView method deleteDiagram.

public void deleteDiagram() {
    List<Row> rows = new ArrayList<Row>();
    int[] sels = table.getSelectedRows();
    for (int i : sels) {
        TreePath path = table.getPathForRow(i);
        if (path != null) {
            TreeTableNode node = (TreeTableNode) path.getLastPathComponent();
            if (node != null) {
                Row row = node.getRow();
                if (row != null)
                    rows.add(row);
            }
        }
    }
    if (rows.size() > 0) {
        if (JOptionPane.showConfirmDialog(component, GlobalResourcesManager.getString("DeleteActiveElementsDialog.Warning"), GlobalResourcesManager.getString("ConfirmMessage.Title"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION)
            return;
        Engine engine = framework.getEngine();
        ((Journaled) engine).startUserTransaction();
        for (Row row : rows) ChartPlugin.deleteChart(engine, row.getElement());
        ((Journaled) engine).commitUserTransaction();
    }
}
Also used : Journaled(com.ramussoft.common.journal.Journaled) TreePath(javax.swing.tree.TreePath) TreeTableNode(com.ramussoft.gui.qualifier.table.TreeTableNode) ArrayList(java.util.ArrayList) Row(com.ramussoft.database.common.Row) Engine(com.ramussoft.common.Engine)

Example 44 with Engine

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

the class TcpLightClient method getEngine.

@SuppressWarnings("rawtypes")
@Override
protected Engine getEngine(PluginFactory factory, PersistentFactory persistentFactory) {
    tcpClientEngine = new TcpClientEngine((EngineInvocker) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { EngineInvocker.class }, new InvocationHandler() {

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            return connection.invoke(method.getName(), args);
        }
    }), connection);
    List<Class> interfaces = new ArrayList<Class>();
    interfaces.add(Engine.class);
    interfaces.add(Journaled.class);
    interfaces.add(ILog.class);
    for (Plugin plugin : factory.getPlugins()) if (plugin.getFunctionalInterface() != null)
        interfaces.add(plugin.getFunctionalInterface());
    final Engine engine1 = (Engine) Proxy.newProxyInstance(getClass().getClassLoader(), interfaces.toArray(new Class[interfaces.size()]), tcpClientEngine);
    final Engine cachedEngine = createCachedEngine(engine1);
    final Hashtable<Method, Object> hashtable = new Hashtable<Method, Object>();
    for (Method m : Engine.class.getMethods()) {
        hashtable.put(m, cachedEngine);
    }
    for (Method m : Cached.class.getMethods()) {
        hashtable.put(m, cachedEngine);
    }
    interfaces.add(Cached.class);
    Engine engine = (Engine) Proxy.newProxyInstance(getClass().getClassLoader(), interfaces.toArray(new Class[interfaces.size()]), new InvocationHandler() {

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            Object o = hashtable.get(method);
            if (o == null)
                return tcpClientEngine.invoke(proxy, method, args);
            return method.invoke(o, args);
        }
    });
    tcpClientEngine.setEngine(engine);
    for (Plugin plugin : factory.getPlugins()) plugin.init(engine, rules);
    return engine;
}
Also used : EngineInvocker(com.ramussoft.net.common.tcp.EngineInvocker) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) Engine(com.ramussoft.common.Engine) CachedEngine(com.ramussoft.common.cached.CachedEngine) StandardAttributesPlugin(com.ramussoft.core.attribute.standard.StandardAttributesPlugin) LogPlugin(com.ramussoft.client.log.LogPlugin) Plugin(com.ramussoft.common.Plugin) UndoRedoPlugin(com.ramussoft.gui.common.UndoRedoPlugin) GUIPlugin(com.ramussoft.gui.common.GUIPlugin)

Example 45 with Engine

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

the class LogPlugin method modify.

@Override
public Action[] modify(Action[] actions, final TableEditor tableEditor) {
    actions = Arrays.copyOf(actions, actions.length + 1);
    actions[actions.length - 1] = new AbstractAction("Log", new ImageIcon(getClass().getResource("/com/ramussoft/client/log/log.png"))) {

        /**
         */
        private static final long serialVersionUID = 8698485078278772063L;

        {
            putValue(LONG_DESCRIPTION, getString("EventType.qualifierLog"));
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            GUIFramework framework = tableEditor.getFramework();
            Engine engine = framework.getEngine();
            long qId = StandardAttributesPlugin.getTableQualifierForAttribute(engine, tableEditor.getAttribute()).getId();
            List<Event> events = ((ILog) engine).getEventsWithParams(new String[] { EngineLogExtension.QUALIFIER_ID }, new Object[] { qId }, 750);
            List<Event> events2 = new ArrayList<Event>();
            Attribute attribute = StandardAttributesPlugin.getTableElementIdAttribute(engine);
            Element el = tableEditor.getElement();
            for (Event event : events) {
                Long elementId = (Long) event.getAttribute("element_id");
                if (elementId != null) {
                    Element element = engine.getElement(elementId);
                    if (element != null) {
                        Long l = (Long) engine.getAttribute(element, attribute);
                        if (l != null && l.equals(el.getId()))
                            events2.add(event);
                    }
                }
            }
            ElementLogDialog dialog = new ElementLogDialog(events2, engine);
            dialog.setSize(800, 600);
            dialog.setLocationRelativeTo(null);
            dialog.setTitle(getString("EventType.qualifierLog"));
            Options.loadOptions(dialog);
            dialog.setVisible(true);
            Options.saveOptions(dialog);
        }
    };
    return actions;
}
Also used : ImageIcon(javax.swing.ImageIcon) Attribute(com.ramussoft.common.Attribute) ActionEvent(java.awt.event.ActionEvent) GUIFramework(com.ramussoft.gui.common.GUIFramework) Element(com.ramussoft.common.Element) Event(com.ramussoft.common.logger.Event) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) List(java.util.List) AbstractAction(javax.swing.AbstractAction) Engine(com.ramussoft.common.Engine)

Aggregations

Engine (com.ramussoft.common.Engine)85 Attribute (com.ramussoft.common.Attribute)32 ArrayList (java.util.ArrayList)30 Element (com.ramussoft.common.Element)27 Qualifier (com.ramussoft.common.Qualifier)22 AccessRules (com.ramussoft.common.AccessRules)21 List (java.util.List)19 IEngine (com.ramussoft.common.IEngine)15 Row (com.ramussoft.database.common.Row)13 IOException (java.io.IOException)11 SQLException (java.sql.SQLException)11 PluginFactory (com.ramussoft.common.PluginFactory)8 PluginProvider (com.ramussoft.common.PluginProvider)8 Journaled (com.ramussoft.common.journal.Journaled)8 CachedEngine (com.ramussoft.common.cached.CachedEngine)7 Hashtable (java.util.Hashtable)7 TreeTableNode (com.ramussoft.gui.qualifier.table.TreeTableNode)6 JournaledEngine (com.ramussoft.common.journal.JournaledEngine)5 FileIEngineImpl (com.ramussoft.core.impl.FileIEngineImpl)5 MemoryDatabase (com.ramussoft.database.MemoryDatabase)5