Search in sources :

Example 11 with AccessRules

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);
            }
        }
    };
}
Also used : CurrencyPropertyPersistent(com.ramussoft.core.attribute.simple.CurrencyPropertyPersistent) JPanel(javax.swing.JPanel) JComboBox(javax.swing.JComboBox) Attribute(com.ramussoft.common.Attribute) Currency(java.util.Currency) AccessRules(com.ramussoft.common.AccessRules) JLabel(javax.swing.JLabel) TableLayout(info.clearthought.layout.TableLayout) AttributePreferenciesEditor(com.ramussoft.gui.common.AttributePreferenciesEditor) Engine(com.ramussoft.common.Engine)

Example 12 with AccessRules

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));
    }
}
Also used : AttributePlugin(com.ramussoft.gui.common.AttributePlugin) AccessRules(com.ramussoft.common.AccessRules) Engine(com.ramussoft.common.Engine) DialogedTableCellEditor(com.ramussoft.gui.qualifier.table.DialogedTableCellEditor)

Example 13 with AccessRules

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;
}
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 14 with AccessRules

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);
    }
}
Also used : Group(com.ramussoft.net.common.Group) PropertyChangeListener(java.beans.PropertyChangeListener) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) JXLoginFrame(org.jdesktop.swingx.JXLoginPane.JXLoginFrame) UserProvider(com.ramussoft.net.common.UserProvider) Status(org.jdesktop.swingx.JXLoginPane.Status) PrintStream(java.io.PrintStream) PropertyChangeEvent(java.beans.PropertyChangeEvent) Calendar(java.util.Calendar) IOException(java.io.IOException) LoginService(org.jdesktop.swingx.auth.LoginService) FileOutputStream(java.io.FileOutputStream) AccessRules(com.ramussoft.common.AccessRules) ResourceBundle(java.util.ResourceBundle) File(java.io.File)

Example 15 with AccessRules

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();
}
Also used : CloseEvent(com.ramussoft.gui.qualifier.table.event.CloseEvent) TabledAttributePlugin(com.ramussoft.gui.qualifier.table.TabledAttributePlugin) AttributePlugin(com.ramussoft.gui.common.AttributePlugin) Attribute(com.ramussoft.common.Attribute) TabledAttributePlugin(com.ramussoft.gui.qualifier.table.TabledAttributePlugin) ValueGetter(com.ramussoft.gui.qualifier.table.ValueGetter) CloseListener(com.ramussoft.gui.qualifier.table.event.CloseListener) TableNode(com.ramussoft.gui.qualifier.table.TableNode) AccessRules(com.ramussoft.common.AccessRules) Engine(com.ramussoft.common.Engine)

Aggregations

AccessRules (com.ramussoft.common.AccessRules)23 Engine (com.ramussoft.common.Engine)21 Attribute (com.ramussoft.common.Attribute)9 PluginFactory (com.ramussoft.common.PluginFactory)5 Row (com.ramussoft.database.common.Row)5 ArrayList (java.util.ArrayList)5 PluginProvider (com.ramussoft.common.PluginProvider)4 Qualifier (com.ramussoft.common.Qualifier)4 MemoryDatabase (com.ramussoft.database.MemoryDatabase)4 RowRootCreater (com.ramussoft.gui.qualifier.table.RowRootCreater)4 RowTreeTableComponent (com.ramussoft.gui.qualifier.table.RowTreeTableComponent)4 ActionEvent (java.awt.event.ActionEvent)4 AbstractAction (javax.swing.AbstractAction)4 AttributePreferenciesEditor (com.ramussoft.gui.common.AttributePreferenciesEditor)3 TreeTableNode (com.ramussoft.gui.qualifier.table.TreeTableNode)3 SelectionEvent (com.ramussoft.gui.qualifier.table.event.SelectionEvent)3 AbstractComponentFactory (com.ramussoft.reportgef.AbstractComponentFactory)3 Diagram (com.ramussoft.reportgef.gui.Diagram)3 Bounds (com.ramussoft.reportgef.model.Bounds)3 File (java.io.File)3