Search in sources :

Example 31 with Row

use of com.ramussoft.database.common.Row in project ramus by Vitaliy-Yakovchuk.

the class SelectableTableView method getSelectedElements.

public List<Element> getSelectedElements() {
    List<Row> rows = getSelectedRows();
    List<Element> result = new ArrayList<Element>(rows.size());
    for (Row r : rows) result.add(r.getElement());
    return result;
}
Also used : Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList) Row(com.ramussoft.database.common.Row)

Example 32 with Row

use of com.ramussoft.database.common.Row in project ramus by Vitaliy-Yakovchuk.

the class TreeModel method valueForPathChanged.

@Override
public void valueForPathChanged(TreePath path, Object newValue) {
    Object o = path.getLastPathComponent();
    Row row = (Row) o;
    ((Journaled) row.getEngine()).startUserTransaction();
    row.setName(String.valueOf(newValue));
    ((Journaled) row.getEngine()).commitUserTransaction();
}
Also used : Journaled(com.ramussoft.common.journal.Journaled) Row(com.ramussoft.database.common.Row)

Example 33 with Row

use of com.ramussoft.database.common.Row in project ramus by Vitaliy-Yakovchuk.

the class TableTabView method convertFirstLevelToQualifiers.

public void convertFirstLevelToQualifiers() {
    Qualifier qq = StandardAttributesPlugin.getQualifiersQualifier(engine);
    HierarchicalPersistent hp = new HierarchicalPersistent();
    Element element = StandardAttributesPlugin.getElement(engine, getQualifier().getId());
    hp.setParentElementId(element.getId());
    hp.setPreviousElementId(-1l);
    Attribute hAttribute = StandardAttributesPlugin.getHierarchicalAttribute(engine);
    Attribute nameAttribute = StandardAttributesPlugin.getAttributeNameAttribute(engine);
    for (Row row : toArray(component.getRowSet().getRoot().getChildren())) {
        String name = row.getName();
        Row[] children = toArray(row.getChildren());
        engine.setElementQualifier(row.getElementId(), qq.getId());
        row.getElement().setQualifierId(qq.getId());
        engine.setAttribute(row.getElement(), hAttribute, hp);
        engine.setAttribute(row.getElement(), nameAttribute, name);
        hp.setPreviousElementId(row.getElementId());
        Qualifier qualifier = StandardAttributesPlugin.getQualifier(engine, row.getElement());
        for (Attribute attribute : getQualifier().getAttributes()) {
            if (qualifier.getAttributes().indexOf(attribute) < 0)
                qualifier.getAttributes().add(attribute);
        }
        engine.updateQualifier(qualifier);
        for (Row row2 : children) {
            moveRows(row2, qualifier.getId());
            HierarchicalPersistent h = (HierarchicalPersistent) engine.getAttribute(row2.getElement(), hAttribute);
            h.setParentElementId(-1l);
            row2.setAttribute(hAttribute, h);
        }
    }
    Attribute nameAttr = null;
    for (Attribute attribute : qualifier.getAttributes()) if (attribute.getId() == qualifier.getAttributeForName())
        nameAttr = attribute;
    getQualifier().getAttributes().clear();
    if (nameAttr != null)
        getQualifier().getAttributes().add(nameAttr);
    engine.updateQualifier(getQualifier());
}
Also used : HierarchicalPersistent(com.ramussoft.core.attribute.simple.HierarchicalPersistent) Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) Qualifier(com.ramussoft.common.Qualifier) Row(com.ramussoft.database.common.Row)

Example 34 with Row

use of com.ramussoft.database.common.Row 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 };
        }
    };
}
Also used : ImageIcon(javax.swing.ImageIcon) Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) Attribute(com.ramussoft.common.Attribute) ActionEvent(java.awt.event.ActionEvent) JTabbedPane(javax.swing.JTabbedPane) ArrayList(java.util.ArrayList) AttributePreferenciesEditor(com.ramussoft.gui.common.AttributePreferenciesEditor) AttributeOrderEditPanel(com.ramussoft.gui.qualifier.AttributeOrderEditPanel) Qualifier(com.ramussoft.common.Qualifier) ArrayList(java.util.ArrayList) List(java.util.List) ChangeListener(javax.swing.event.ChangeListener) TableGroupablePropertyPersistent(com.ramussoft.core.attribute.simple.TableGroupablePropertyPersistent) AbstractAction(javax.swing.AbstractAction) SelectableTableView(com.ramussoft.gui.qualifier.table.SelectableTableView) Engine(com.ramussoft.common.Engine) Hashtable(java.util.Hashtable) JComponent(javax.swing.JComponent) JPopupMenu(javax.swing.JPopupMenu) TreePath(javax.swing.tree.TreePath) ChangeEvent(javax.swing.event.ChangeEvent) AccessRules(com.ramussoft.common.AccessRules) Row(com.ramussoft.database.common.Row)

Example 35 with Row

use of com.ramussoft.database.common.Row in project ramus by Vitaliy-Yakovchuk.

the class OtherElementTableCellEditor method getMenu.

protected JPopupMenu getMenu(Attribute attribute) {
    if (menu == null) {
        menu = new JPopupMenu(attribute.getName());
        menu.setMaximumSize(new Dimension(600, 500));
        JScrollPane pane = new JScrollPane();
        List<Row> allRows = rowSet.getAllRows();
        wrappers = new PopupRowWrapper[allRows.size()];
        for (int i = 0; i < wrappers.length; i++) {
            wrappers[i] = new PopupRowWrapper(allRows.get(i), attribute);
        }
        list = new JList(new AbstractListModel() {

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

            @Override
            public int getSize() {
                return wrappers.length + 1;
            }

            @Override
            public Object getElementAt(int index) {
                if (index == 0)
                    return "<html><body><i>" + GlobalResourcesManager.getString("EmptyValue") + "</i></body></html>";
                return wrappers[index - 1];
            }
        });
        Dimension size = list.getPreferredSize();
        if (size.width > 600)
            list.setPreferredSize(new Dimension(600, size.height));
        if (value == null)
            list.setSelectedIndex(0);
        else {
            for (int i = 0; i < wrappers.length; i++) {
                if (wrappers[i].row.getElementId() == ((Long) value).longValue()) {
                    list.setSelectedIndex(i + 1);
                    break;
                }
            }
        }
        list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                list.ensureIndexIsVisible(list.getSelectedIndex());
            }
        });
        list.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            private boolean rec = false;

            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (rec)
                    return;
                rec = true;
                int index = list.getSelectedIndex();
                PopupRowWrapper wrapper = null;
                if (index < 0)
                    return;
                if (index == 0)
                    value = null;
                else {
                    wrapper = wrappers[index - 1];
                    value = wrapper.row.getElementId();
                }
                if (updateFields) {
                    codeField.setBackground(fieldDefaultBackground);
                    valueField.setBackground(fieldDefaultBackground);
                    if (wrapper == null) {
                        codeField.setText("");
                        valueField.setText("");
                    } else {
                        codeField.setText(wrapper.code);
                        codeField.setCaretPosition(0);
                        valueField.setText(wrapper.value);
                        valueField.setCaretPosition(0);
                    }
                }
                rec = false;
            }
        });
        list.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                stopCellEditing();
            }
        });
        InputMap inputMap = list.getInputMap();
        KeyStroke[] allKeys = inputMap.allKeys();
        for (Object actionName : actionsToReplace) {
            for (KeyStroke stroke : allKeys) {
                Object value = inputMap.get(stroke);
                if (actionName.equals(value)) {
                    codeField.getInputMap().put(stroke, actionName);
                    valueField.getInputMap().put(stroke, actionName);
                    final Action source = list.getActionMap().get(actionName);
                    if (source != null) {
                        Action action = new AbstractAction() {

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

                            @Override
                            public void actionPerformed(ActionEvent e) {
                                if (list != null) {
                                    updateFields = true;
                                    e.setSource(list);
                                    source.actionPerformed(e);
                                    updateFields = false;
                                }
                            }
                        };
                        valueField.getActionMap().put(actionName, action);
                        codeField.getActionMap().put(actionName, action);
                    }
                }
            }
        }
        pane.setViewportView(list);
        menu.add(pane);
        menu.pack();
    }
    return menu;
}
Also used : JScrollPane(javax.swing.JScrollPane) Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) MouseEvent(java.awt.event.MouseEvent) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) MouseAdapter(java.awt.event.MouseAdapter) Dimension(java.awt.Dimension) AbstractListModel(javax.swing.AbstractListModel) JPopupMenu(javax.swing.JPopupMenu) ListSelectionListener(javax.swing.event.ListSelectionListener) KeyStroke(javax.swing.KeyStroke) InputMap(javax.swing.InputMap) Row(com.ramussoft.database.common.Row) AbstractAction(javax.swing.AbstractAction) JList(javax.swing.JList)

Aggregations

Row (com.ramussoft.database.common.Row)81 TreeTableNode (com.ramussoft.gui.qualifier.table.TreeTableNode)20 Attribute (com.ramussoft.common.Attribute)19 ArrayList (java.util.ArrayList)18 Qualifier (com.ramussoft.common.Qualifier)17 TreePath (javax.swing.tree.TreePath)15 Engine (com.ramussoft.common.Engine)13 Element (com.ramussoft.common.Element)12 RootRow (com.ramussoft.database.common.RowSet.RootRow)12 RowSet (com.ramussoft.database.common.RowSet)9 ActionEvent (java.awt.event.ActionEvent)8 AbstractAction (javax.swing.AbstractAction)8 RowTreeTable (com.ramussoft.gui.qualifier.table.RowTreeTable)6 MouseAdapter (java.awt.event.MouseAdapter)6 MouseEvent (java.awt.event.MouseEvent)6 JComponent (javax.swing.JComponent)6 JScrollPane (javax.swing.JScrollPane)6 AccessRules (com.ramussoft.common.AccessRules)5 Journaled (com.ramussoft.common.journal.Journaled)5 RowTreeTableComponent (com.ramussoft.gui.qualifier.table.RowTreeTableComponent)5