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