Search in sources :

Example 1 with RowNode

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

the class ModelsPanel method init.

private void init() {
    tree = new RowTreeTableComponent(engine, IDEF0Plugin.getModelTree(engine), framework.getAccessRules(), new ModelRowCreator(), new Attribute[] { StandardAttributesPlugin.getAttributeNameAttribute(engine) }, framework) {

        @Override
        protected RowTreeTableModel createRowTreeTableModel(final Engine engine, Qualifier qualifier, AccessRules accessRules, RootCreater rootCreater, Attribute[] attributes, GUIFramework framework) {
            RowTreeTableModel rowTreeTableModel = new RowTreeTableModel(engine, qualifier, attributes, accessRules, rootCreater, framework) {

                @Override
                protected RowNode newRowNode(Row row) {
                    Long id = (Long) row.getAttribute(StandardAttributesPlugin.getAttributeQualifierId(engine));
                    if (id != null) {
                        Qualifier qualifier = engine.getQualifier(id);
                        if (qualifier != null) {
                            ModelsNode node = newModelsNode(row, qualifier);
                            node.getTreeTableModel().setTable(tree.getTable());
                            node.getTreeTableModel().setModelSupport(tree.getModel().getModelSupport());
                            return node;
                        }
                    }
                    return super.newRowNode(row);
                }

                @Override
                public boolean isCellEditable(Object node, int column) {
                    if (super.isCellEditable(node, column)) {
                        if (node instanceof ModelsNode)
                            return true;
                    }
                    return false;
                }
            };
            return rowTreeTableModel;
        }

        @Override
        protected RowTreeTable createTable(AccessRules accessRules, GUIFramework framework, AttributePlugin[] plugins) {
            return new RowTreeTable(accessRules, model.getRowSet(), plugins, framework, model) {

                long treeModelsId = IDEF0Plugin.getModelTree(engine).getId();

                @Override
                public Transferable createTransferable() {
                    final int[] is = getSelectedRows();
                    final ArrayList<Integer> al = new ArrayList<Integer>();
                    long id = IDEF0Plugin.getModelTree(engine).getId();
                    Rows rows = new Rows();
                    for (final int i : is) {
                        al.add(i);
                        TreeTableNode node = (TreeTableNode) getPathForRow(i).getLastPathComponent();
                        if ((node != null) && (node.getRow() != null)) {
                            Row row = node.getRow();
                            rows.add(row);
                            if (row.getElement().getQualifierId() != id)
                                return null;
                        }
                    }
                    exporting = true;
                    return new ArrayTransferable(al, rows);
                }

                @Override
                public boolean importData(Transferable t, boolean on, int aIndex) {
                    int index = aIndex;
                    long id = IDEF0Plugin.getModelTree(engine).getId();
                    if (index >= getRowCount())
                        index--;
                    if (index < 0)
                        return false;
                    TreeTableNode node = (TreeTableNode) getPathForRow(index).getLastPathComponent();
                    if (node.getRow() != null)
                        if (node.getRow().getElement().getQualifierId() != id)
                            return false;
                    return super.importData(t, on, aIndex);
                }

                @Override
                protected Icon getDefaultIcon(Row row) {
                    if (row.getElement().getQualifierId() != treeModelsId) {
                        if (row.getChildCount() == 0)
                            return note;
                        else
                            return function;
                    }
                    if (row.getAttribute(StandardAttributesPlugin.getAttributeQualifierId(engine)) == null)
                        return null;
                    return ModelsPanel.this.model;
                }
            };
        }
    };
    fixTable((TreeTableNode) tree.getModel().getRoot());
    tree.getTable().addMouseListener(new MouseAdapter() {

        private int[] lastSelectedRows;

        private long lastClickTime;

        @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 < QualifierView.EDIT_NAME_CLICK_DELAY) && (Arrays.equals(lastSelectedRows, tree.getTable().getSelectedRows()))) {
                        if (!tree.getTable().isEditing()) {
                            editTableField();
                        }
                    } else {
                        lastClickTime = System.currentTimeMillis();
                        lastSelectedRows = tree.getTable().getSelectedRows();
                    }
                }
            }
        }
    });
    tree.getTable().setEditIfNullEvent(false);
    tree.getTable().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), "EditCell");
    tree.getTable().getActionMap().put("EditCell", new AbstractAction() {

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

        @Override
        public void actionPerformed(ActionEvent e) {
            if ((tree.getTable().getSelectedRow() >= 0) && (tree.getTable().getSelectedColumn() >= 0))
                editTableField();
        }
    });
    JScrollPane pane = new JScrollPane();
    pane.setViewportView(tree);
    this.add(pane, BorderLayout.CENTER);
}
Also used : RootCreater(com.ramussoft.gui.qualifier.table.RootCreater) RowRootCreater(com.ramussoft.gui.qualifier.table.RowRootCreater) Attribute(com.ramussoft.common.Attribute) RowTreeTableComponent(com.ramussoft.gui.qualifier.table.RowTreeTableComponent) GUIFramework(com.ramussoft.gui.common.GUIFramework) RowNode(com.ramussoft.gui.qualifier.table.RowNode) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) Qualifier(com.ramussoft.common.Qualifier) RowTreeTable(com.ramussoft.gui.qualifier.table.RowTreeTable) AbstractAction(javax.swing.AbstractAction) Engine(com.ramussoft.common.Engine) Rows(com.ramussoft.gui.qualifier.table.Rows) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) AttributePlugin(com.ramussoft.gui.common.AttributePlugin) TreeTableNode(com.ramussoft.gui.qualifier.table.TreeTableNode) Transferable(java.awt.datatransfer.Transferable) MouseAdapter(java.awt.event.MouseAdapter) RowTreeTableModel(com.ramussoft.gui.qualifier.table.RowTreeTableModel) AccessRules(com.ramussoft.common.AccessRules) IDEF0Object(com.ramussoft.pb.idef.visual.IDEF0Object) Row(com.ramussoft.database.common.Row) RootRow(com.ramussoft.database.common.RowSet.RootRow) ImageIcon(javax.swing.ImageIcon) Icon(javax.swing.Icon)

Example 2 with RowNode

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

the class ModelsPanel method showSelection.

@Override
public void showSelection(final OpenDiagram diagram) {
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            TreePath sel = null;
            int selRow = -1;
            for (int row = 0; row < getTree().getTable().getRowCount(); row++) {
                TreePath path = getTree().getTable().getPathForRow(row);
                Object object = path.getLastPathComponent();
                if (diagram.getFunctionId() == -1l) {
                    if (object instanceof ModelsNode) {
                        if (((ModelsNode) object).getQualifier().equals(diagram.getQualifier())) {
                            sel = path;
                            break;
                        }
                    }
                } else if (object instanceof RowNode) {
                    Row row2 = ((RowNode) object).getRow();
                    if ((row2.getElement() != null) && (row2.getElementId() == diagram.getFunctionId())) {
                        sel = path;
                        selRow = row;
                    }
                }
            }
            if (sel != null) {
                if (!getTree().getTable().isExpanded(sel))
                    getTree().getTable().expandPath(sel);
                getTree().getTable().getSelectionModel().clearSelection();
                getTree().getTable().getSelectionModel().addSelectionInterval(selRow, selRow);
            }
        }
    });
}
Also used : TreePath(javax.swing.tree.TreePath) RowNode(com.ramussoft.gui.qualifier.table.RowNode) IDEF0Object(com.ramussoft.pb.idef.visual.IDEF0Object) Row(com.ramussoft.database.common.Row) RootRow(com.ramussoft.database.common.RowSet.RootRow)

Example 3 with RowNode

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

the class ModelsNode method createR2Children.

public static Vector<TreeTableNode> createR2Children(Row root) {
    Vector<TreeTableNode> res = new Vector<TreeTableNode>();
    for (Row row : root.getChildren()) {
        RowNode node = new FunctionNode(createR2Children(row), row);
        node.setParent();
        res.add(node);
    }
    return res;
}
Also used : TreeTableNode(com.ramussoft.gui.qualifier.table.TreeTableNode) RowNode(com.ramussoft.gui.qualifier.table.RowNode) Row(com.ramussoft.database.common.Row) Vector(java.util.Vector)

Example 4 with RowNode

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

the class ModelsView method createModelsPanel.

protected void createModelsPanel() {
    if (this.modelsPanel != null)
        this.modelsPanel.close();
    Qualifier modelTree = IDEF0Plugin.getModelTree(engine);
    modelTree = engine.getQualifier(modelTree.getId());
    if (modelTree == null) {
        final com.ramussoft.idef0.idef0.oldmodelsview.ModelsPanel modelsPanel = new com.ramussoft.idef0.idef0.oldmodelsview.ModelsPanel(engine, framework) {

            @Override
            public boolean isDisabeUpdate() {
                return disableUpdated;
            }
        };
        modelsPanel.getTree().getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

            @Override
            public void valueChanged(TreeSelectionEvent e) {
                openDiagram.setEnabled(modelsPanel.getTree().getSelectionPath() != null);
            }
        });
        modelsPanel.getTree().setComponentPopupMenu(createPopupMenu());
        modelsPanel.getTree().addTreeSelectionListener(new TreeSelectionListener() {

            @Override
            public void valueChanged(TreeSelectionEvent e) {
                ch1();
                modelNode = getActiveNode1();
                while ((modelNode != null) && (!(modelNode instanceof ModelsNode)) && (modelNode instanceof Row)) modelNode = ((Row) modelNode).getParent();
                modelProperties.setEnabled((modelNode instanceof ModelsNode) && (rules.canUpdateQualifier(((ModelsNode) modelNode).getQualifier().getId())));
            }
        });
        modelsPanel.getTreeModel().addTreeModelListener(new TreeModelListener() {

            @Override
            public void treeNodesChanged(TreeModelEvent e) {
                ch1();
            }

            @Override
            public void treeNodesInserted(TreeModelEvent e) {
                ch1();
            }

            @Override
            public void treeNodesRemoved(TreeModelEvent e) {
                ch1();
            }

            @Override
            public void treeStructureChanged(TreeModelEvent e) {
                ch1();
            }
        });
        contentPanel.add(modelsPanel, BorderLayout.CENTER);
        modelsPanel.getTree().setComponentPopupMenu(createPopupMenu());
        this.modelsPanel = modelsPanel;
    } else {
        final ModelsPanel modelsPanel = new ModelsPanel(engine, framework) {

            @Override
            public boolean isDisabeUpdate() {
                return disableUpdated;
            }
        };
        modelsPanel.getTree().getTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                openDiagram.setEnabled(modelsPanel.canOpen());
            }
        });
        modelsPanel.getTree().setComponentPopupMenu(createPopupMenu());
        modelsPanel.getTree().getTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                ch();
                modelNode = getActiveNode();
                while ((modelNode != null) && (!(modelNode instanceof ModelsNode)) && (modelNode instanceof RowNode)) modelNode = ((RowNode) modelNode).getParent();
                modelProperties.setEnabled((modelNode instanceof ModelsNode) && (rules.canUpdateQualifier(((ModelsNode) modelNode).getQualifier().getId())));
            }
        });
        contentPanel.add(modelsPanel, BorderLayout.CENTER);
        modelsPanel.getTree().getTable().setComponentPopupMenu(createPopupMenu());
        this.modelsPanel = modelsPanel;
    }
}
Also used : TreeModelEvent(javax.swing.event.TreeModelEvent) RowNode(com.ramussoft.gui.qualifier.table.RowNode) TreeModelListener(javax.swing.event.TreeModelListener) ListSelectionEvent(javax.swing.event.ListSelectionEvent) TreeSelectionListener(javax.swing.event.TreeSelectionListener) ListSelectionListener(javax.swing.event.ListSelectionListener) Qualifier(com.ramussoft.common.Qualifier) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) Row(com.ramussoft.database.common.Row)

Aggregations

Row (com.ramussoft.database.common.Row)4 RowNode (com.ramussoft.gui.qualifier.table.RowNode)4 Qualifier (com.ramussoft.common.Qualifier)2 RootRow (com.ramussoft.database.common.RowSet.RootRow)2 TreeTableNode (com.ramussoft.gui.qualifier.table.TreeTableNode)2 IDEF0Object (com.ramussoft.pb.idef.visual.IDEF0Object)2 AccessRules (com.ramussoft.common.AccessRules)1 Attribute (com.ramussoft.common.Attribute)1 Engine (com.ramussoft.common.Engine)1 AttributePlugin (com.ramussoft.gui.common.AttributePlugin)1 GUIFramework (com.ramussoft.gui.common.GUIFramework)1 RootCreater (com.ramussoft.gui.qualifier.table.RootCreater)1 RowRootCreater (com.ramussoft.gui.qualifier.table.RowRootCreater)1 RowTreeTable (com.ramussoft.gui.qualifier.table.RowTreeTable)1 RowTreeTableComponent (com.ramussoft.gui.qualifier.table.RowTreeTableComponent)1 RowTreeTableModel (com.ramussoft.gui.qualifier.table.RowTreeTableModel)1 Rows (com.ramussoft.gui.qualifier.table.Rows)1 Transferable (java.awt.datatransfer.Transferable)1 ActionEvent (java.awt.event.ActionEvent)1 MouseAdapter (java.awt.event.MouseAdapter)1