use of com.ramussoft.common.AccessRules in project ramus by Vitaliy-Yakovchuk.
the class CurrencyAttributePlugin method getAttributePreferenciesEditor.
@Override
public AttributePreferenciesEditor getAttributePreferenciesEditor() {
return new AttributePreferenciesEditor() {
private JComboBox comboBox = new JComboBox();
@Override
public JComponent createComponent(Attribute attribute, Engine engine, AccessRules accessRules) {
CurrencyPropertyPersistent p = null;
if (attribute != null)
p = (CurrencyPropertyPersistent) engine.getAttribute(null, attribute);
comboBox.addItem(GlobalResourcesManager.getString("ByDefault"));
int i = 1;
int index = 0;
for (Currency currency : getCurrencies()) {
comboBox.addItem(currency);
if ((p != null) && (p.getCode() != null) && (p.getCode().equals(currency.getCurrencyCode())))
index = i;
i++;
}
comboBox.setSelectedIndex(index);
double[][] size = { { 5, TableLayout.MINIMUM, 5, TableLayout.FILL, 5 }, { 5, TableLayout.MINIMUM, 5 } };
TableLayout layout = new TableLayout(size);
JPanel panel = new JPanel(layout);
panel.add(new JLabel(GlobalResourcesManager.getString("Attribute.CurrencyCode")), "1,1");
panel.add(comboBox, "3,1");
return panel;
}
@Override
public boolean canApply() {
return true;
}
@Override
public void apply(Attribute attribute, Engine engine, AccessRules accessRules) {
if (comboBox.getSelectedIndex() == 0) {
engine.setAttribute(null, attribute, null);
} else {
CurrencyPropertyPersistent p = new CurrencyPropertyPersistent();
p.setCode(((Currency) comboBox.getSelectedItem()).getCurrencyCode());
engine.setAttribute(null, attribute, p);
}
}
};
}
use of com.ramussoft.common.AccessRules in project ramus by Vitaliy-Yakovchuk.
the class TableEditorTable method setModel.
@Override
public void setModel(TableModel dataModel) {
super.setModel(dataModel);
if (!(dataModel instanceof TableEditorModel))
return;
TableEditorModel model = (TableEditorModel) dataModel;
Engine engine = framework.getEngine();
AccessRules rules = framework.getAccessRules();
for (int i = 0; i < plugins.length; i++) {
AttributePlugin plugin = framework.findAttributePlugin(attributes.get(i));
plugins[i] = plugin;
cellEditors[i] = plugin.getTableCellEditor(engine, rules, attributes.get(i));
if (cellEditors[i] == null) {
cellEditors[i] = new DialogedTableCellEditor(engine, rules, attributes.get(i), plugins[i], framework);
model.setSaveValue(i, false);
}
cellRenderers[i] = plugin.getTableCellRenderer(engine, rules, attributes.get(i));
}
}
use of com.ramussoft.common.AccessRules 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.AccessRules in project ramus by Vitaliy-Yakovchuk.
the class TcpLightClient method start.
protected void start(final String[] args) throws Exception {
if (args.length < 2) {
System.err.println("Usage java -jar ... url ..., for example: java -jar my.jar localhost 38617 ");
return;
}
try {
String lookAndFeel = Options.getString("LookAndFeel");
if (lookAndFeel != null)
UIManager.setLookAndFeel(lookAndFeel);
else {
if ("com.sun.java.swing.plaf.gtk.GTKLookAndFeel".equals(UIManager.getSystemLookAndFeelClassName()))
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
else
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
UIManager.put("swing.boldMetal", Boolean.FALSE);
} catch (Exception e1) {
e1.printStackTrace();
}
StandardAttributesPlugin.setDefaultDisableAutoupdate(true);
this.host = args[0];
this.port = args[1];
try {
final PrintStream old = System.err;
System.setErr(new PrintStream(new OutputStream() {
FileOutputStream fos = null;
private boolean err = false;
@Override
public void write(final int b) throws IOException {
getFos();
if (!err)
fos.write(b);
old.write(b);
}
private FileOutputStream getFos() throws IOException {
if (fos == null) {
try {
System.out.println("Getting calendar");
final Calendar c = Calendar.getInstance();
System.out.println("Getting options path");
String name = System.getProperty("user.home");
if (!name.equals(File.separator))
name += File.separator;
name += ".ramus" + File.separator + "log";
System.out.println("Creating dir: " + name);
new File(name).mkdirs();
name += File.separator + c.get(Calendar.YEAR) + "_" + c.get(Calendar.MONTH) + "_" + c.get(Calendar.DAY_OF_MONTH) + "_" + c.get(Calendar.HOUR_OF_DAY) + "_" + c.get(Calendar.MINUTE) + "_" + c.get(Calendar.SECOND) + "_" + c.get(Calendar.MILLISECOND) + "-client.log";
fos = new FileOutputStream(name);
} catch (final Exception e) {
err = true;
e.printStackTrace(System.out);
// throw e;
}
}
return fos;
}
}));
connection = new TcpClientConnection(args[0], Integer.parseInt(args[1])) {
private boolean exitShown = false;
@Override
protected void objectReaded(Object object) {
if (tcpClientEngine != null)
tcpClientEngine.call((EvenstHolder) object);
}
@Override
protected void showDialogEndExit(String message) {
if (exitShown)
return;
exitShown = true;
System.err.println("Connection lost");
// JOptionPane.showMessageDialog(framework.getMainFrame(),
// message);
System.exit(1);
}
};
connection.start();
Boolean canLogin = (Boolean) connection.invoke("canLogin", new Object[] {});
if (!canLogin) {
ResourceBundle bundle = ResourceBundle.getBundle("com.ramussoft.client.client");
JOptionPane.showMessageDialog(null, bundle.getString("Message.ServerBusy"));
System.exit(1);
return;
}
final JXLoginFrame frame = JXLoginPane.showLoginFrame(new LoginService() {
@Override
public boolean authenticate(String name, char[] passwordChars, String server) throws Exception {
String password = new String(passwordChars);
try {
sessionId = (Long) connection.invoke("login", new Object[] { name, password });
if ((sessionId == null) || (sessionId.longValue() < 0l)) {
return false;
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
return sessionId != null;
}
@Override
public void cancelAuthentication() {
System.exit(0);
}
});
frame.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/ramussoft/gui/application.png")));
frame.setVisible(true);
frame.addPropertyChangeListener("status", new PropertyChangeListener() {
private boolean run = false;
{
Thread t = new Thread() {
@Override
public void run() {
try {
Thread.sleep(120000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (!run)
System.exit(0);
}
};
t.start();
}
@Override
public void propertyChange(PropertyChangeEvent evt) {
Status status = frame.getStatus();
if ((status.equals(Status.CANCELLED)) || (status.equals(Status.NOT_STARTED)) || (status.equals(Status.FAILED)) || (status.equals(Status.IN_PROGRESS))) {
return;
}
if (run)
return;
run = true;
userProvider = (UserProvider) createDeligate(UserProvider.class);
if (season) {
boolean exit = true;
for (Group g : getMe().getGroups()) {
if (("admin".equals(g.getName())) || ("season".equals(g.getName()))) {
exit = false;
}
}
if (exit) {
JOptionPane.showMessageDialog(null, "Тільки користувач групи season або admin може працювати з системою планування");
System.exit(5);
return;
}
}
rules = (AccessRules) createDeligate(AccessRules.class);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
TcpLightClient.this.run(args);
}
});
}
});
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Неможливо з’єднатись з сервером, дивіться log-файл для деталей " + e.getLocalizedMessage());
System.exit(1);
}
}
use of com.ramussoft.common.AccessRules in project ramus by Vitaliy-Yakovchuk.
the class ElementAttributesEditor method reload.
protected void reload() {
CloseEvent event = new CloseEvent(this);
CloseListener[] listeners = getCloseListeners();
for (CloseListener listener : listeners) {
listener.closed(event);
removeCloseListener(listener);
}
loadCurrentQualifierAttributes();
Engine engine = framework.getEngine();
AccessRules rules = framework.getAccessRules();
getters = new ValueGetter[attributes.size()];
renderers = new TableCellRenderer[attributes.size()];
values = new Object[attributes.size()];
saveValues = new boolean[attributes.size()];
Arrays.fill(saveValues, true);
Arrays.fill(getters, new ValueGetter() {
@Override
public Object getValue(TableNode node, int index) {
return node.getValueAt(index);
}
});
for (int i = 0; i < attributes.size(); i++) {
Attribute attr = attributes.get(i).attribute;
AttributePlugin plugin = framework.findAttributePlugin(attr);
if (plugin instanceof TabledAttributePlugin) {
ValueGetter getter = ((TabledAttributePlugin) plugin).getValueGetter(attr, engine, framework, this);
if (getter != null)
getters[i] = getter;
}
renderers[i] = plugin.getTableCellRenderer(engine, rules, attr);
}
loadElement();
}
Aggregations