Search in sources :

Example 1 with SelectableTableView

use of com.ramussoft.gui.qualifier.table.SelectableTableView in project ramus by Vitaliy-Yakovchuk.

the class SelectRowPanel method createRightComponent.

private void createRightComponent() {
    if (qualifierView == null)
        return;
    qualifier = qualifierView.getSelectedQualifier();
    boolean b = qualifier != null;
    if (b) {
        framework.setOpenDynamikViewEvent(new ActionEvent(QualifierPlugin.OPEN_QUALIFIER, qualifier));
        selectableTableView = new SelectableTableView(framework, dataPlugin.getEngine(), accessRules, qualifier) {
        };
        int dl = splitPane.getDividerLocation();
        splitPane.setRightComponent(createComponent());
        for (Row row : getSelectedRows(qualifier)) selectableTableView.getComponent().getModel().setSelectedRow(selectableTableView.getComponent().getRowSet().findRow(row.getElementId()), true);
        splitPane.revalidate();
        splitPane.repaint();
        splitPane.setDividerLocation(dl);
        selectableTableView.getComponent().getModel().addSelectionListener(selectionListener);
        if (!getSelectType().equals(SelectType.CHECK))
            selectableTableView.setSelectType(getSelectType());
    }
}
Also used : ActionEvent(com.ramussoft.gui.common.event.ActionEvent) Row(com.ramussoft.database.common.Row) SelectableTableView(com.ramussoft.gui.qualifier.table.SelectableTableView)

Example 2 with SelectableTableView

use of com.ramussoft.gui.qualifier.table.SelectableTableView in project ramus by Vitaliy-Yakovchuk.

the class SelectRowDialog method createRightComponent.

private void createRightComponent() {
    if (qualifierView == null)
        return;
    qualifier = qualifierView.getSelectedQualifier();
    boolean b = qualifier != null;
    addQualifier = b;
    if (b) {
        framework.setOpenDynamikViewEvent(new ActionEvent(QualifierPlugin.OPEN_QUALIFIER, qualifier));
        selectableTableView = new SelectableTableView(framework, dataPlugin.getEngine(), accessRules, qualifier) {
        };
        int dl = splitPane.getDividerLocation();
        splitPane.setRightComponent(createComponent());
        for (Row row : getSelectedRows(qualifier)) selectableTableView.getComponent().getModel().setSelectedRow(row, true);
        splitPane.revalidate();
        splitPane.repaint();
        splitPane.setDividerLocation(dl);
        selectableTableView.getComponent().getModel().addSelectionListener(selectionListener);
        if (!getSelectType().equals(SelectType.CHECK))
            selectableTableView.setSelectType(getSelectType());
    }
}
Also used : ActionEvent(com.ramussoft.gui.common.event.ActionEvent) Row(com.ramussoft.database.common.Row) SelectableTableView(com.ramussoft.gui.qualifier.table.SelectableTableView)

Example 3 with SelectableTableView

use of com.ramussoft.gui.qualifier.table.SelectableTableView 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 4 with SelectableTableView

use of com.ramussoft.gui.qualifier.table.SelectableTableView in project ramus by Vitaliy-Yakovchuk.

the class OtherElementEditor method getComponent.

@Override
public JComponent getComponent() {
    if (resultComponent != null)
        return resultComponent;
    view = new SelectableTableView(framework, engine, rules, qualifier) {

        @Override
        public String getPropertiesPrefix() {
            return propertiesPrefix;
        }
    };
    resultComponent = view.createComponent();
    component = view.getComponent();
    view.setSelectType(SelectType.RADIO);
    return resultComponent;
}
Also used : SelectableTableView(com.ramussoft.gui.qualifier.table.SelectableTableView)

Example 5 with SelectableTableView

use of com.ramussoft.gui.qualifier.table.SelectableTableView in project ramus by Vitaliy-Yakovchuk.

the class ElementListAttributeEditor method getComponent.

@Override
public JComponent getComponent() {
    if (resultComponent != null)
        return resultComponent;
    view = new SelectableTableView(framework, qualifier) {

        @Override
        protected Attribute[] getAttributes() {
            if (qualifier.equals(engine.getPluginProperty("Core", StandardAttributesPlugin.ATTRIBUTES_QUALIFIER)))
                return new Attribute[] { (Attribute) engine.getPluginProperty("Core", StandardAttributesPlugin.ATTRIBUTE_NAME), (Attribute) engine.getPluginProperty("Core", StandardAttributesPlugin.ATTRIBUTE_TYPE_NAME) };
            else
                return super.getAttributes();
        }

        @Override
        public String getPropertiesPrefix() {
            return propertiesPrefix;
        }
    };
    resultComponent = view.createComponent();
    component = view.getComponent();
    if (qualifier.equals(framework.getEngine().getPluginProperty("Core", StandardAttributesPlugin.ATTRIBUTES_QUALIFIER))) {
        component.getTable().setEditable(false);
    }
    return resultComponent;
}
Also used : Attribute(com.ramussoft.common.Attribute) SelectableTableView(com.ramussoft.gui.qualifier.table.SelectableTableView)

Aggregations

SelectableTableView (com.ramussoft.gui.qualifier.table.SelectableTableView)9 Row (com.ramussoft.database.common.Row)5 JComponent (javax.swing.JComponent)5 Attribute (com.ramussoft.common.Attribute)4 Qualifier (com.ramussoft.common.Qualifier)3 ArrayList (java.util.ArrayList)3 JPopupMenu (javax.swing.JPopupMenu)3 ActionEvent (com.ramussoft.gui.common.event.ActionEvent)2 Dimension (java.awt.Dimension)2 ActionEvent (java.awt.event.ActionEvent)2 List (java.util.List)2 StringTokenizer (java.util.StringTokenizer)2 AbstractAction (javax.swing.AbstractAction)2 Action (javax.swing.Action)2 JLabel (javax.swing.JLabel)2 JScrollPane (javax.swing.JScrollPane)2 AccessRules (com.ramussoft.common.AccessRules)1 Engine (com.ramussoft.common.Engine)1 TableGroupablePropertyPersistent (com.ramussoft.core.attribute.simple.TableGroupablePropertyPersistent)1 RowSet (com.ramussoft.database.common.RowSet)1