Search in sources :

Example 6 with User

use of com.ramussoft.net.common.User 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();
}
Also used : PersistentFactory(com.ramussoft.core.persistent.PersistentFactory) SimleGUIPluginFactory(com.ramussoft.gui.core.simple.SimleGUIPluginFactory) User(com.ramussoft.net.common.User) AbstractGUIPluginFactory(com.ramussoft.gui.common.AbstractGUIPluginFactory) SimleGUIPluginFactory(com.ramussoft.gui.core.simple.SimleGUIPluginFactory) GUIPluginFactory(com.ramussoft.gui.core.GUIPluginFactory) PluginProvider(com.ramussoft.common.PluginProvider) CloseMainFrameAdapter(com.ramussoft.gui.common.event.CloseMainFrameAdapter) SimpleAttributePluginSuit(com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit) JFrame(javax.swing.JFrame) SplashScreen(com.ramussoft.gui.common.SplashScreen) AccessRules(com.ramussoft.common.AccessRules) ArrayList(java.util.ArrayList) List(java.util.List) AbstractGUIPluginFactory(com.ramussoft.gui.common.AbstractGUIPluginFactory) SimleGUIPluginFactory(com.ramussoft.gui.core.simple.SimleGUIPluginFactory) GUIPluginFactory(com.ramussoft.gui.core.GUIPluginFactory) PluginFactory(com.ramussoft.common.PluginFactory) Engine(com.ramussoft.common.Engine) GUIPlugin(com.ramussoft.gui.common.GUIPlugin) AbstractGUIPluginFactory(com.ramussoft.gui.common.AbstractGUIPluginFactory)

Example 7 with User

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

the class UserProviderImpl method changePassword.

@Override
public void changePassword(String newPassword) {
    User me = me();
    me.setPassword(newPassword);
    factory.updateUser(me);
}
Also used : User(com.ramussoft.net.common.User)

Example 8 with User

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

the class ClientPlugin method getActionDescriptors.

@Override
public ActionDescriptor[] getActionDescriptors() {
    ActionDescriptor changePassword = new ActionDescriptor();
    changePassword.setAction(new AbstractAction() {

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

        {
            putValue(ACTION_COMMAND_KEY, "Action.ChangePassword");
        }

        public void actionPerformed(ActionEvent e) {
            final JPasswordField oldPassword = new JPasswordField();
            final JPasswordField newPassword = new JPasswordField();
            final JPasswordField conformNewPassword = new JPasswordField();
            double[][] size = { { 5, TableLayout.FILL, 5 }, { 5, TableLayout.FILL, 5, TableLayout.FILL, 5, TableLayout.FILL, 5, TableLayout.FILL, 5, TableLayout.FILL, 5, TableLayout.FILL, 5 } };
            final JPanel panel = new JPanel(new TableLayout(size));
            panel.add(new JLabel(getString("Message.OldPassword")), "1,1");
            panel.add(oldPassword, "1,3");
            panel.add(new JLabel(getString("Message.NewPassword")), "1,5");
            panel.add(newPassword, "1,7");
            panel.add(new JLabel(getString("Message.ConformNewPassword")), "1,9");
            panel.add(conformNewPassword, "1,11");
            BaseDialog dialog = new BaseDialog(framework.getMainFrame(), true) {

                {
                    setTitle(getString("ChangePasswordDialog.Title"));
                    setMainPane(panel);
                }

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

                @Override
                protected void onOk() {
                    if (!Arrays.equals(newPassword.getPassword(), conformNewPassword.getPassword())) {
                        JOptionPane.showMessageDialog(framework.getMainFrame(), getString("Message.ConforPasswordsFailded"));
                        return;
                    }
                    User user = provider.me();
                    if (Arrays.equals(user.getPassword().toCharArray(), oldPassword.getPassword())) {
                        provider.changePassword(new String(newPassword.getPassword()));
                        super.onOk();
                    } else {
                        JOptionPane.showMessageDialog(framework.getMainFrame(), getString("Message.OldPasswordWrong"));
                    }
                }
            };
            dialog.pack();
            dialog.setResizable(false);
            dialog.setLocationRelativeTo(null);
            dialog.setVisible(true);
        }
    });
    changePassword.setMenu("Net");
    ActionDescriptor refresh = new ActionDescriptor();
    refreshAction.putValue(Action.ACTION_COMMAND_KEY, "Refresh");
    refreshAction.putValue(Action.SMALL_ICON, getIcon("/com/ramussoft/gui/refresh.png"));
    // refreshAction.putValue(Action.LARGE_ICON_KEY,
    // getIcon("/com/ramussoft/gui/22x22/refresh.png"));
    refresh.setAction(refreshAction);
    refresh.setMenu("Edit");
    refresh.setToolBar("Edit");
    if (refreshSupport)
        return new ActionDescriptor[] { changePassword, refresh };
    else
        return new ActionDescriptor[] { changePassword };
}
Also used : JPanel(javax.swing.JPanel) BaseDialog(com.ramussoft.gui.common.BaseDialog) User(com.ramussoft.net.common.User) JPasswordField(javax.swing.JPasswordField) ActionEvent(java.awt.event.ActionEvent) ActionDescriptor(com.ramussoft.gui.common.ActionDescriptor) JLabel(javax.swing.JLabel) AbstractAction(javax.swing.AbstractAction) TableLayout(info.clearthought.layout.TableLayout)

Example 9 with User

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

the class EditUsersDialog method createModels.

private void createModels() {
    userModel = new AbstractTableModel() {

        /**
         */
        private static final long serialVersionUID = -5788741544620802246L;

        private String[] columnNames = new String[] { plugin.getString("Column.User.Login"), plugin.getString("Column.User.Name") };

        public int getColumnCount() {
            return 2;
        }

        public int getRowCount() {
            return users.size();
        }

        public Object getValueAt(int rowIndex, int columnIndex) {
            User user = users.get(rowIndex);
            return (columnIndex == 0) ? user.getLogin() : user.getName();
        }

        public String getColumnName(int column) {
            return columnNames[column];
        }
    };
    groupModel = new AbstractTableModel() {

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

        private String[] columnNames = new String[] { plugin.getString("Column.Selected"), plugin.getString("Column.Group.Name") };

        public int getColumnCount() {
            return 2;
        }

        public int getRowCount() {
            return groups.size();
        }

        public Object getValueAt(int rowIndex, int columnIndex) {
            if (columnIndex == 0) {
                if (getActiveUser() != null) {
                    return getActiveUser().getGroups().indexOf(groups.get(rowIndex)) >= 0;
                } else
                    return false;
            }
            return groups.get(rowIndex).getName();
        }

        public Class<?> getColumnClass(int columnIndex) {
            if (columnIndex == 0)
                return Boolean.class;
            return super.getColumnClass(columnIndex);
        }

        public String getColumnName(int column) {
            return columnNames[column];
        }

        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return (columnIndex == 0) && (getActiveUser() != null);
        }

        public void setValueAt(Object value, int rowIndex, int columnIndex) {
            User user = getActiveUser();
            if (user != null) {
                updateUser(user);
                Group group = groups.get(rowIndex);
                if ((Boolean) value)
                    user.getGroups().add(group);
                else
                    user.getGroups().remove(group);
            }
        }
    };
    qualifierModel = new AbstractTableModel() {

        /**
         */
        private static final long serialVersionUID = -8072350565904373494L;

        private String[] columnNames = new String[] { plugin.getString("Column.Selected"), plugin.getString("Column.Qualifier.Name") };

        public int getColumnCount() {
            return 2;
        }

        public int getRowCount() {
            return qualifiers.size();
        }

        public Object getValueAt(int rowIndex, int columnIndex) {
            if (columnIndex == 0) {
                if (getActiveGroup() != null) {
                    return getActiveGroup().getQualifierIds().indexOf(qualifiers.get(rowIndex).getId()) >= 0;
                } else
                    return Boolean.FALSE;
            }
            return qualifiers.get(rowIndex).getName();
        }

        public Class<?> getColumnClass(int columnIndex) {
            if (columnIndex == 0)
                return Boolean.class;
            return super.getColumnClass(columnIndex);
        }

        public String getColumnName(int column) {
            return columnNames[column];
        }

        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return (columnIndex == 0) && (getActiveGroup() != null);
        }

        public void setValueAt(Object value, int rowIndex, int columnIndex) {
            Group group = getActiveGroup();
            if (group != null) {
                updateGroup(group);
                long qualifierId = qualifiers.get(rowIndex).getId();
                if ((Boolean) value)
                    group.getQualifierIds().add(qualifierId);
                else
                    group.getQualifierIds().remove(qualifierId);
            }
        }
    };
}
Also used : Group(com.ramussoft.net.common.Group) User(com.ramussoft.net.common.User) AbstractTableModel(javax.swing.table.AbstractTableModel)

Example 10 with User

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

the class EditUsersDialog method updateUser.

private void updateUser(User user) {
    User u = findUser(user.getLogin(), usersToUpdate);
    if (u != null)
        usersToUpdate.remove(u);
    usersToUpdate.add(user);
}
Also used : User(com.ramussoft.net.common.User)

Aggregations

User (com.ramussoft.net.common.User)17 Group (com.ramussoft.net.common.Group)7 ResultSet (java.sql.ResultSet)3 JDBCCallback (com.ramussoft.jdbc.JDBCCallback)2 ActionEvent (java.awt.event.ActionEvent)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AbstractAction (javax.swing.AbstractAction)2 AccessRules (com.ramussoft.common.AccessRules)1 Engine (com.ramussoft.common.Engine)1 PluginFactory (com.ramussoft.common.PluginFactory)1 PluginProvider (com.ramussoft.common.PluginProvider)1 Qualifier (com.ramussoft.common.Qualifier)1 SimpleAttributePluginSuit (com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit)1 IntegrityAccessorSuit (com.ramussoft.core.impl.IntegrityAccessorSuit)1 PersistentFactory (com.ramussoft.core.persistent.PersistentFactory)1 AbstractGUIPluginFactory (com.ramussoft.gui.common.AbstractGUIPluginFactory)1 ActionDescriptor (com.ramussoft.gui.common.ActionDescriptor)1