use of com.ramussoft.common.AccessRules in project ramus by Vitaliy-Yakovchuk.
the class Client method run.
public void run(final String[] args) {
final SplashScreen screen = new SplashScreen() {
/**
*/
private static final long serialVersionUID = -4641958771849938048L;
@Override
protected String getImageName() {
for (String s : args) if (s.equals("-season"))
return "/com/ramussoft/season/about.png";
return "/com/ramussoft/gui/about.png";
}
};
if (Metadata.CLIENT) {
Metadata.REGISTERED_FOR = ClientConnection.getName();
Metadata.DEMO_REGISTERED = ClientConnection.getName() != null;
}
screen.setLocationRelativeTo(null);
boolean hide = false;
for (String s : args) if ("--hide-splash".equals(s))
hide = true;
if (!hide)
screen.setVisible(true);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
List<PluginProvider> suits = new ArrayList<PluginProvider>();
suits.add(new SimpleAttributePluginSuit());
initAdditionalPluginSuits(suits);
PluginFactory factory = createPluginFactory(suits);
PersistentFactory persistentFactory = new PersistentFactory(null, factory.getAttributePlugins(), null);
persistentFactory.reinit();
Engine engine = getEngine(factory, persistentFactory);
AccessRules rules = getAccessRules();
e = engine;
e.setPluginProperty("Core", "PluginList", factory.getPlugins());
e.setPluginProperty("Core", "PluginFactory", factory);
LightClient.staticEngine = e;
LightClient.staticAccessRules = rules;
List<GUIPlugin> list = new ArrayList<GUIPlugin>();
QualifierPluginSuit.addPlugins(list, e, rules);
initAdditionalGuiPlugins(list);
User me = getMe();
List<Group> groups = me.getGroups();
String[] grps = new String[groups.size()];
for (int i = 0; i < grps.length; i++) grps[i] = groups.get(i).getName();
AbstractGUIPluginFactory factory1;
String ws = Options.getString("WindowsControl", "simple");
if (ws.equals("simple"))
factory1 = new SimleGUIPluginFactory(list, e, rules, getType(), grps, loadPlugins);
else
factory1 = new GUIPluginFactory(list, e, rules, getType(), grps, loadPlugins);
framework = factory1.getFramework();
framework.addCloseMainFrameListener(new CloseMainFrameAdapter() {
@Override
public void afterClosed() {
Client.this.close();
}
});
final JFrame frame = factory1.getMainFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String title = getTitle();
frame.setTitle(title);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
frame.setVisible(true);
screen.setVisible(false);
}
});
}
});
t.start();
Thread thread = new Thread("Icons-buffer-cleaner") {
@Override
public void run() {
while (true) {
try {
Thread.sleep(20000);
IconFactory.clearIconsBuffer(LightClient.staticEngine);
IconFactory.clearQualifierIconsBuffer(LightClient.staticEngine);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
thread.setDaemon(true);
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
}
use of com.ramussoft.common.AccessRules in project ramus by Vitaliy-Yakovchuk.
the class MemoryDatabase method createJournaledEngine.
private JournaledEngine createJournaledEngine(PluginFactory factory, PersistentFactory persistentFactory) throws ClassNotFoundException {
if (cached) {
JournaledEngine journaledEngine2 = new JournaledEngine(factory, impl, persistentFactory.getRows(), journalFactory, accessor) {
@Override
protected void initPlugins(PluginFactory pluginFactory, AccessRules accessor) {
}
};
CachedEngine cachedEngine = new CachedEngine(journaledEngine2);
for (Plugin plugin : factory.getPlugins()) plugin.init(cachedEngine, accessor);
this.engine = cachedEngine;
return journaledEngine2;
} else {
JournaledEngine journaledEngine2 = new JournaledEngine(factory, impl, persistentFactory.getRows(), journalFactory, accessor);
this.engine = journaledEngine2;
return journaledEngine2;
}
}
use of com.ramussoft.common.AccessRules in project ramus by Vitaliy-Yakovchuk.
the class ModelsPanel method init.
private void init() {
tree = new RowTreeTableComponent(engine, IDEF0Plugin.getModelTree(engine), framework.getAccessRules(), new ModelRowCreator(), new Attribute[] { StandardAttributesPlugin.getAttributeNameAttribute(engine) }, framework) {
@Override
protected RowTreeTableModel createRowTreeTableModel(final Engine engine, Qualifier qualifier, AccessRules accessRules, RootCreater rootCreater, Attribute[] attributes, GUIFramework framework) {
RowTreeTableModel rowTreeTableModel = new RowTreeTableModel(engine, qualifier, attributes, accessRules, rootCreater, framework) {
@Override
protected RowNode newRowNode(Row row) {
Long id = (Long) row.getAttribute(StandardAttributesPlugin.getAttributeQualifierId(engine));
if (id != null) {
Qualifier qualifier = engine.getQualifier(id);
if (qualifier != null) {
ModelsNode node = newModelsNode(row, qualifier);
node.getTreeTableModel().setTable(tree.getTable());
node.getTreeTableModel().setModelSupport(tree.getModel().getModelSupport());
return node;
}
}
return super.newRowNode(row);
}
@Override
public boolean isCellEditable(Object node, int column) {
if (super.isCellEditable(node, column)) {
if (node instanceof ModelsNode)
return true;
}
return false;
}
};
return rowTreeTableModel;
}
@Override
protected RowTreeTable createTable(AccessRules accessRules, GUIFramework framework, AttributePlugin[] plugins) {
return new RowTreeTable(accessRules, model.getRowSet(), plugins, framework, model) {
long treeModelsId = IDEF0Plugin.getModelTree(engine).getId();
@Override
public Transferable createTransferable() {
final int[] is = getSelectedRows();
final ArrayList<Integer> al = new ArrayList<Integer>();
long id = IDEF0Plugin.getModelTree(engine).getId();
Rows rows = new Rows();
for (final int i : is) {
al.add(i);
TreeTableNode node = (TreeTableNode) getPathForRow(i).getLastPathComponent();
if ((node != null) && (node.getRow() != null)) {
Row row = node.getRow();
rows.add(row);
if (row.getElement().getQualifierId() != id)
return null;
}
}
exporting = true;
return new ArrayTransferable(al, rows);
}
@Override
public boolean importData(Transferable t, boolean on, int aIndex) {
int index = aIndex;
long id = IDEF0Plugin.getModelTree(engine).getId();
if (index >= getRowCount())
index--;
if (index < 0)
return false;
TreeTableNode node = (TreeTableNode) getPathForRow(index).getLastPathComponent();
if (node.getRow() != null)
if (node.getRow().getElement().getQualifierId() != id)
return false;
return super.importData(t, on, aIndex);
}
@Override
protected Icon getDefaultIcon(Row row) {
if (row.getElement().getQualifierId() != treeModelsId) {
if (row.getChildCount() == 0)
return note;
else
return function;
}
if (row.getAttribute(StandardAttributesPlugin.getAttributeQualifierId(engine)) == null)
return null;
return ModelsPanel.this.model;
}
};
}
};
fixTable((TreeTableNode) tree.getModel().getRoot());
tree.getTable().addMouseListener(new MouseAdapter() {
private int[] lastSelectedRows;
private long lastClickTime;
@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 < QualifierView.EDIT_NAME_CLICK_DELAY) && (Arrays.equals(lastSelectedRows, tree.getTable().getSelectedRows()))) {
if (!tree.getTable().isEditing()) {
editTableField();
}
} else {
lastClickTime = System.currentTimeMillis();
lastSelectedRows = tree.getTable().getSelectedRows();
}
}
}
}
});
tree.getTable().setEditIfNullEvent(false);
tree.getTable().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), "EditCell");
tree.getTable().getActionMap().put("EditCell", new AbstractAction() {
/**
*/
private static final long serialVersionUID = 3229634866196074563L;
@Override
public void actionPerformed(ActionEvent e) {
if ((tree.getTable().getSelectedRow() >= 0) && (tree.getTable().getSelectedColumn() >= 0))
editTableField();
}
});
JScrollPane pane = new JScrollPane();
pane.setViewportView(tree);
this.add(pane, BorderLayout.CENTER);
}
use of com.ramussoft.common.AccessRules in project ramus by Vitaliy-Yakovchuk.
the class NDataPluginFactory method createTemplateDataPlugin.
private static DataPlugin createTemplateDataPlugin() {
MemoryDatabase database = new MemoryDatabase() {
@Override
protected Collection<? extends PluginProvider> getAdditionalSuits() {
ArrayList<PluginProvider> ps = new ArrayList<PluginProvider>(1);
ps.add(new IDEF0PluginProvider());
return ps;
}
@Override
protected String getJournalDirectoryName(String tmp) {
return null;
}
@Override
protected FileIEngineImpl createFileIEngine(PluginFactory factory) throws ClassNotFoundException, ZipException, IOException {
return createNotSessionedFileIEngine(factory);
}
};
Engine e = database.getEngine(null);
AccessRules rules = database.getAccessRules(null);
Qualifier q = e.createQualifier();
IDEF0Plugin.installFunctionAttributes(q, e);
return getDataPlugin(q, e, rules);
}
use of com.ramussoft.common.AccessRules in project ramus by Vitaliy-Yakovchuk.
the class TablePlugin method getAttributePreferenciesEditor.
@Override
public AttributePreferenciesEditor getAttributePreferenciesEditor() {
return new AttributePreferenciesEditor() {
private SelectableTableView view;
private AttributeOrderEditPanel attributeOrderEditPanel = new AttributeOrderEditPanel(new ArrayList<Attribute>(), true);
private Action createAttributeAction = new AbstractAction() {
/**
*/
private static final long serialVersionUID = -2190162251129929137L;
{
this.putValue(ACTION_COMMAND_KEY, "CreateAttribute");
this.putValue(SMALL_ICON, new ImageIcon(getClass().getResource("/com/ramussoft/gui/table/add.png")));
this.putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_ADD, KeyEvent.CTRL_MASK));
}
@Override
public void actionPerformed(ActionEvent e) {
new AttributePreferenciesDialog(framework).setVisible(true);
}
};
private Action deleteAttributeAction = new AbstractAction() {
{
this.putValue(ACTION_COMMAND_KEY, "DeleteAttribute");
this.putValue(SMALL_ICON, new ImageIcon(getClass().getResource("/com/ramussoft/gui/table/delete.png")));
this.putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
}
/**
*/
private static final long serialVersionUID = 895892525217269346L;
@Override
public void actionPerformed(ActionEvent e) {
if (JOptionPane.showConfirmDialog(framework.getMainFrame(), GlobalResourcesManager.getString("DeleteActiveElementsDialog.Warning"), UIManager.getString("OptionPane.titleText"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
TreePath[] paths = view.getComponent().getTable().getTreeSelectionModel().getSelectionPaths();
if (paths.length == 0) {
System.err.println("Trying to delete element, but no elements are selected");
return;
}
for (TreePath path : paths) {
Row row = ((TreeTableNode) path.getLastPathComponent()).getRow();
if (row == null) {
System.err.println("Trying to delete node, which conatain no row");
return;
}
long attrId = (Long) row.getAttribute((Attribute) view.getComponent().getRowSet().getEngine().getPluginProperty("Core", StandardAttributesPlugin.ATTRIBUTE_ID));
view.getComponent().getRowSet().startUserTransaction();
view.getComponent().getRowSet().getEngine().deleteAttribute(attrId);
view.getComponent().getRowSet().commitUserTransaction();
}
}
}
};
@Override
public void apply(Attribute attribute, Engine engine, AccessRules accessRules) {
String qualifierName = StandardAttributesPlugin.getTableQualifeirName(attribute);
Qualifier qualifier = engine.getSystemQualifier(qualifierName);
if (qualifier == null) {
qualifier = engine.createSystemQualifier();
qualifier.setName(qualifierName);
}
List<Attribute> attributes = attributeOrderEditPanel.getAttributes();
fillAttributes(engine, attributes);
qualifier.setAttributes(attributes);
qualifier.getSystemAttributes().clear();
qualifier.getSystemAttributes().add(StandardAttributesPlugin.getTableElementIdAttribute(engine));
engine.updateQualifier(qualifier);
List<TableGroupablePropertyPersistent> list = new ArrayList<TableGroupablePropertyPersistent>();
int i = 0;
for (String group : attributeOrderEditPanel.getAttributeGroups()) {
if (group != null) {
TableGroupablePropertyPersistent p = new TableGroupablePropertyPersistent();
p.setAttribute(attribute.getId());
p.setName(group);
p.setOtherAttribute(attributes.get(i).getId());
list.add(p);
}
i++;
}
engine.setAttribute(null, attribute, list);
}
private void fillAttributes(Engine engine, List<Attribute> attributes) {
List<Row> rows = view.getSelectedRows();
ArrayList<Attribute> toRemove = new ArrayList<Attribute>(attributes);
for (Row row : rows) {
Attribute attr = StandardAttributesPlugin.getAttribute(engine, row.getElement());
toRemove.remove(attr);
if (attributes.indexOf(attr) < 0)
attributes.add(attr);
}
for (Attribute attribute : toRemove) attributes.remove(attribute);
}
@Override
public boolean canApply() {
return view.getSelectedRows().size() > 0;
}
@SuppressWarnings("unchecked")
@Override
public JComponent createComponent(Attribute attribute, final Engine engine, AccessRules accessRules) {
view = new SelectableTableView(framework, engine, accessRules, StandardAttributesPlugin.getAttributesQualifier(engine)) {
@Override
protected Attribute[] getAttributes() {
return new Attribute[] { StandardAttributesPlugin.getAttributeNameAttribute(engine), StandardAttributesPlugin.getAttributeTypeNameAttribute(engine) };
}
};
JComponent component = view.createComponent();
view.getComponent().getModel().setEditable(0, false);
view.getComponent().getModel().setEditable(1, false);
JTabbedPane pane = new JTabbedPane();
pane.addTab(GlobalResourcesManager.getString("attributes"), component);
pane.addTab(GlobalResourcesManager.getString("AttributesOrder"), attributeOrderEditPanel);
pane.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
fillAttributes(engine, attributeOrderEditPanel.getAttributes());
attributeOrderEditPanel.refresh();
}
});
if (attribute != null) {
Qualifier qualifier = StandardAttributesPlugin.getTableQualifierForAttribute(engine, attribute);
attributeOrderEditPanel.setAttributes(qualifier.getAttributes());
Hashtable<Attribute, String> groups = new Hashtable<Attribute, String>();
List<TableGroupablePropertyPersistent> pList = (List) engine.getAttribute(null, attribute);
for (TableGroupablePropertyPersistent p : pList) for (Attribute attribute2 : qualifier.getAttributes()) {
if ((p.getOtherAttribute() == attribute2.getId()) && (p.getName() != null))
groups.put(attribute2, p.getName());
}
attributeOrderEditPanel.setGroups(groups);
List<Row> list = view.getComponent().getRowSet().getAllRows();
for (Row row : list) {
Attribute attr = StandardAttributesPlugin.getAttribute(engine, row.getElement());
if (qualifier.getAttributes().indexOf(attr) >= 0) {
view.setSelectedRow(row, true);
}
}
}
view.getComponent().getTable().setComponentPopupMenu(createPopupMenu());
return pane;
}
private JPopupMenu createPopupMenu() {
JPopupMenu menu = new JPopupMenu();
for (Action action : getActions()) {
if (action == null)
menu.addSeparator();
else {
action.putValue(Action.NAME, GlobalResourcesManager.getString((String) action.getValue(Action.ACTION_COMMAND_KEY)));
menu.add(action);
}
}
return menu;
}
private Action[] getActions() {
return new Action[] { createAttributeAction, new AbstractAction() {
/**
*/
private static final long serialVersionUID = 3284967628905643862L;
{
this.putValue(ACTION_COMMAND_KEY, "Action.SortByName");
this.putValue(SMALL_ICON, new ImageIcon(getClass().getResource("/com/ramussoft/gui/table/sort-incr.png")));
}
@Override
public void actionPerformed(ActionEvent e) {
view.getComponent().getRowSet().startUserTransaction();
view.getComponent().getRowSet().sortByName();
view.getComponent().getRowSet().commitUserTransaction();
}
}, deleteAttributeAction };
}
};
}
Aggregations