Search in sources :

Example 6 with TreeTableNode

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

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

the class ElistPanel method getElementInfo.

public ElementInfo getElementInfo(long elementId) {
    int c = table.getRowCount();
    for (int row = 0; row < c; row++) {
        TreeTableNode node = (TreeTableNode) table.getPathForRow(row).getLastPathComponent();
        Row r = node.getRow();
        if ((r != null) && (r.getElementId() == elementId)) {
            return new ElementInfo(getRowY(row), false);
        }
        if (table.isCollapsed(row)) {
            if (isPresent(node, elementId)) {
                return new ElementInfo(getRowY(row), true);
            }
        }
    }
    return null;
}
Also used : TreeTableNode(com.ramussoft.gui.qualifier.table.TreeTableNode) Row(com.ramussoft.database.common.Row)

Example 8 with TreeTableNode

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

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

the class ChartsView method deleteDiagram.

public void deleteDiagram() {
    List<Row> rows = new ArrayList<Row>();
    int[] sels = table.getSelectedRows();
    for (int i : sels) {
        TreePath path = table.getPathForRow(i);
        if (path != null) {
            TreeTableNode node = (TreeTableNode) path.getLastPathComponent();
            if (node != null) {
                Row row = node.getRow();
                if (row != null)
                    rows.add(row);
            }
        }
    }
    if (rows.size() > 0) {
        if (JOptionPane.showConfirmDialog(component, GlobalResourcesManager.getString("DeleteActiveElementsDialog.Warning"), GlobalResourcesManager.getString("ConfirmMessage.Title"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION)
            return;
        Engine engine = framework.getEngine();
        ((Journaled) engine).startUserTransaction();
        for (Row row : rows) ChartPlugin.deleteChart(engine, row.getElement());
        ((Journaled) engine).commitUserTransaction();
    }
}
Also used : Journaled(com.ramussoft.common.journal.Journaled) TreePath(javax.swing.tree.TreePath) TreeTableNode(com.ramussoft.gui.qualifier.table.TreeTableNode) ArrayList(java.util.ArrayList) Row(com.ramussoft.database.common.Row) Engine(com.ramussoft.common.Engine)

Example 10 with TreeTableNode

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

the class ModelPropertiesDialog method refreshActions.

protected void refreshActions() {
    RowTreeTable table = component.getTable();
    createAttributeAction.setEnabled(rules.canCreateAttribute());
    if (table.getTreeSelectionModel().getSelectionPath() == null) {
        deleteAttributeAction.setEnabled(false);
        attributePreferencesAction.setEnabled(false);
    } else {
        attributePreferencesAction.setEnabled(true);
        boolean e = true;
        TreePath[] paths = table.getTreeSelectionModel().getSelectionPaths();
        for (TreePath path : paths) {
            Row row = ((TreeTableNode) path.getLastPathComponent()).getRow();
            if (row == null) {
                e = false;
                break;
            }
            if (row.getChildCount() > 0) {
                e = false;
                break;
            }
            Long long1 = (Long) row.getAttribute(attributeId);
            if (long1 == null)
                break;
            long attrId = long1;
            if (!rules.canDeleteAttribute(attrId)) {
                e = false;
                break;
            }
        }
        deleteAttributeAction.setEnabled(e);
    }
}
Also used : TreePath(javax.swing.tree.TreePath) TreeTableNode(com.ramussoft.gui.qualifier.table.TreeTableNode) Row(com.ramussoft.database.common.Row) RowTreeTable(com.ramussoft.gui.qualifier.table.RowTreeTable)

Aggregations

TreeTableNode (com.ramussoft.gui.qualifier.table.TreeTableNode)22 Row (com.ramussoft.database.common.Row)20 TreePath (javax.swing.tree.TreePath)10 Engine (com.ramussoft.common.Engine)7 Attribute (com.ramussoft.common.Attribute)6 ArrayList (java.util.ArrayList)6 RootRow (com.ramussoft.database.common.RowSet.RootRow)5 RowTreeTable (com.ramussoft.gui.qualifier.table.RowTreeTable)5 AccessRules (com.ramussoft.common.AccessRules)4 Qualifier (com.ramussoft.common.Qualifier)3 Journaled (com.ramussoft.common.journal.Journaled)3 RowRootCreater (com.ramussoft.gui.qualifier.table.RowRootCreater)3 RowTreeTableComponent (com.ramussoft.gui.qualifier.table.RowTreeTableComponent)3 SelectionEvent (com.ramussoft.gui.qualifier.table.event.SelectionEvent)3 ActionEvent (java.awt.event.ActionEvent)3 MouseAdapter (java.awt.event.MouseAdapter)3 MouseEvent (java.awt.event.MouseEvent)3 AbstractAction (javax.swing.AbstractAction)3 RowNode (com.ramussoft.gui.qualifier.table.RowNode)2 RowTreeTableModel (com.ramussoft.gui.qualifier.table.RowTreeTableModel)2