Search in sources :

Example 76 with Row

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

the class SelectableTableView method showRowSelectDialog.

public static List<Row> showRowSelectDialog(Component component, GUIFramework framework, Engine engine, AccessRules rules, Qualifier qualifier, SelectType selectType, boolean readOnly, boolean selectAll) {
    final SelectableTableView view = new SelectableTableView(framework, engine, rules, qualifier, readOnly) {
    };
    JComponent createComponent = view.createComponent();
    view.setSelectType(selectType);
    Component root = SwingUtilities.getRoot(component);
    BaseDialog dialog;
    if (root instanceof JFrame)
        dialog = new BaseDialog((JFrame) root) {

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

            @Override
            protected void onOk() {
                if (view.getSelectedRows().size() == 0) {
                    JOptionPane.showMessageDialog(this, GlobalResourcesManager.getString("SelectElementDialog.NoSelection"));
                } else
                    super.onOk();
            }
        };
    else if (root instanceof JDialog)
        dialog = new BaseDialog((JDialog) root) {

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

            @Override
            protected void onOk() {
                if (view.getSelectedRows().size() == 0) {
                    JOptionPane.showMessageDialog(this, GlobalResourcesManager.getString("SelectElementDialog.NoSelection"));
                } else
                    super.onOk();
            }
        };
    dialog = new BaseDialog(framework.getMainFrame()) {

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

        @Override
        protected void onOk() {
            if (view.getSelectedRows().size() == 0) {
                JOptionPane.showMessageDialog(this, GlobalResourcesManager.getString("SelectElementDialog.NoSelection"));
            } else
                super.onOk();
        }
    };
    JPanel panel = new JPanel(new BorderLayout());
    if (!readOnly) {
        JToolBar bar = view.createToolBar();
        bar.setFloatable(false);
        panel.add(bar, BorderLayout.NORTH);
    }
    if (selectAll)
        view.getComponent().getModel().checkAll();
    panel.add(createComponent, BorderLayout.CENTER);
    dialog.setMainPane(panel);
    dialog.setLocationRelativeTo(null);
    dialog.setTitle(GlobalResourcesManager.getString("SelectElementDialog.Title"));
    Options.loadOptions(dialog);
    dialog.setVisible(true);
    Options.saveOptions(dialog);
    if (dialog.isOkPressed()) {
        List<Row> res = view.getSelectedRows();
        view.close();
        return res;
    }
    view.close();
    return null;
}
Also used : BaseDialog(com.ramussoft.gui.common.BaseDialog) JPanel(javax.swing.JPanel) JComponent(javax.swing.JComponent) JToolBar(javax.swing.JToolBar) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) Row(com.ramussoft.database.common.Row) JComponent(javax.swing.JComponent) Component(java.awt.Component) JDialog(javax.swing.JDialog)

Example 77 with Row

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

the class SelectableTableView method selectRows.

public void selectRows(List<Long> rows) {
    RowSet set = component.getRowSet();
    RowTreeTableModel model = component.getModel();
    for (Long id : rows) {
        Row row = set.findRow(id);
        if (row != null)
            model.setSelectedRow(row, true);
    }
}
Also used : RowSet(com.ramussoft.database.common.RowSet) Row(com.ramussoft.database.common.Row)

Example 78 with Row

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

the class TableCellEditorFactory method createModelEditor.

private TableCellEditor createModelEditor() {
    Qualifier qualifier = getModelTree(engine);
    Attribute nameAttribute = StandardAttributesPlugin.getAttributeNameAttribute(engine);
    RowSet rowSet = new RowSet(engine, qualifier, new Attribute[] { nameAttribute }, null, true);
    OtherElementTableCellEditor editor = new OtherElementTableCellEditor(rowSet, nameAttribute, framework, null) {

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

        private OtherElementListModel model;

        private void updateValue() {
            if (list.getSelectedIndex() == 0)
                value = null;
            else if (list.getSelectedIndex() == 1)
                value = "[ALL MODELS]";
            else {
                if (model.checked.size() == 0) {
                    value = model.wrappers[list.getSelectedIndex() - 2].row.getName();
                } else {
                    StringBuffer sb = null;
                    for (PopupRowWrapper w : model.checked.keySet()) {
                        if (sb == null)
                            sb = new StringBuffer(w.row.getName());
                        else {
                            sb.append(com.ramussoft.report.editor.xml.Attribute.QUALIFIER_DELIMETER);
                            sb.append(w.row.getName());
                        }
                    }
                    value = sb.toString();
                }
            }
        }

        @Override
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int rowIndex, int columnIndex) {
            try {
                this.table = table;
                if (value instanceof String) {
                    Row r = rowSet.findRow((String) value);
                    if (r != null) {
                        return super.getTableCellEditorComponent(table, value, isSelected, rowIndex, columnIndex);
                    } else {
                        SwingUtilities.invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                codeField.selectAll();
                                codeField.requestFocus();
                            }
                        });
                        return component;
                    }
                }
                SwingUtilities.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        codeField.selectAll();
                        codeField.requestFocus();
                    }
                });
                return super.getTableCellEditorComponent(table, value, isSelected, rowIndex, columnIndex);
            } finally {
                this.value = value;
            }
        }

        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);
                }
                model = new OtherElementListModel(wrappers);
                list = new JList(model) {

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

                    CheckCellRenderer cellRenderer;

                    public ListCellRenderer getCellRenderer() {
                        if (cellRenderer == null)
                            cellRenderer = new CheckCellRenderer(model, super.getCellRenderer());
                        return cellRenderer;
                    }
                };
                Dimension size = list.getPreferredSize();
                if (size.width > 600)
                    list.setPreferredSize(new Dimension(600, size.height));
                if (value == null)
                    list.setSelectedIndex(0);
                else {
                    List<String> slist = new ArrayList<String>();
                    String val = ((String) value);
                    StringTokenizer st = new StringTokenizer(val, com.ramussoft.report.editor.xml.Attribute.QUALIFIER_DELIMETER);
                    slist.add(val);
                    while (st.hasMoreTokens()) slist.add(st.nextToken());
                    if ("[ALL MODELS]".equals(val))
                        list.setSelectedIndex(1);
                    else {
                        List<Integer> seleted = new ArrayList<Integer>();
                        for (int i = 0; i < wrappers.length; i++) {
                            if (slist.contains(wrappers[i].row.getName())) {
                                model.select(wrappers[i]);
                                seleted.add(i + 2);
                            }
                        }
                        int[] is = new int[seleted.size()];
                        for (int i = 0; i < is.length; i++) is[i] = seleted.get(i);
                        if (is.length > 0)
                            list.setSelectedIndices(is);
                    }
                }
                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;
                        updateValue();
                        if (index == 0)
                            value = null;
                        else if (index > 1) {
                            wrapper = wrappers[index - 2];
                        }
                        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) {
                        if (e.getX() <= 20 && e.getClickCount() < 2) {
                            int index = list.getSelectedIndex();
                            if (index > 1) {
                                index -= 2;
                                model.select(wrappers[index]);
                                updateValue();
                                list.repaint();
                                return;
                            }
                        }
                        updateValue();
                        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;
        }

        @Override
        protected void edit() {
            if (menu != null) {
                menu.setVisible(false);
                menu = null;
            }
            final SelectableTableView view = new SelectableTableView(framework, engine, framework.getAccessRules(), rowSet.getQualifier()) {

                @Override
                public String getPropertiesPrefix() {
                    return "xml_edit";
                }
            };
            JComponent rc = view.createComponent();
            final RowTreeTableComponent component = view.getComponent();
            component.getTable().setComponentPopupMenu(null);
            component.getTable().setTableHeader(null);
            List<String> slist = new ArrayList<String>();
            String val = ((String) value);
            if (val != null) {
                StringTokenizer st = new StringTokenizer(val, com.ramussoft.report.editor.xml.Attribute.QUALIFIER_DELIMETER);
                slist.add(val);
                while (st.hasMoreTokens()) slist.add(st.nextToken());
                for (Row row : component.getRowSet().getAllRows()) if (slist.contains(row.getName()))
                    component.getModel().setSelectedRow(row, true);
            }
            view.setSelectType(SelectType.CHECK);
            BaseDialog dialog = new BaseDialog(framework.getMainFrame()) {

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

                @Override
                protected void onOk() {
                    List<Row> rows = view.getSelectedRows();
                    if (rows.size() == 0)
                        value = null;
                    else {
                        StringBuffer sb = null;
                        for (Row w : rows) {
                            if (sb == null)
                                sb = new StringBuffer(w.getName());
                            else {
                                sb.append(com.ramussoft.report.editor.xml.Attribute.QUALIFIER_DELIMETER);
                                sb.append(w.getName());
                            }
                        }
                        value = sb.toString();
                    }
                    stopCellEditing();
                    super.onOk();
                }
            };
            dialog.setMainPane(rc);
            dialog.setTitle(ReportResourceManager.getString("ReportAttribute.model"));
            dialog.setLocationRelativeTo(null);
            Options.loadOptions("IDEF0_models", dialog);
            dialog.setModal(true);
            dialog.setVisible(true);
            Options.saveOptions("IDEF0_models", dialog);
            try {
                view.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    return editor;
}
Also used : BaseDialog(com.ramussoft.gui.common.BaseDialog) OtherElementTableCellEditor(com.ramussoft.gui.attribute.OtherElementTableCellEditor) AbstractAction(javax.swing.AbstractAction) Action(javax.swing.Action) Attribute(com.ramussoft.common.Attribute) ActionEvent(java.awt.event.ActionEvent) RowTreeTableComponent(com.ramussoft.gui.qualifier.table.RowTreeTableComponent) RowSet(com.ramussoft.database.common.RowSet) ArrayList(java.util.ArrayList) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListCellRenderer(javax.swing.ListCellRenderer) Qualifier(com.ramussoft.common.Qualifier) AbstractAction(javax.swing.AbstractAction) SelectableTableView(com.ramussoft.gui.qualifier.table.SelectableTableView) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) JComponent(javax.swing.JComponent) Dimension(java.awt.Dimension) JPopupMenu(javax.swing.JPopupMenu) ListSelectionListener(javax.swing.event.ListSelectionListener) StringTokenizer(java.util.StringTokenizer) JTable(javax.swing.JTable) PopupRowWrapper(com.ramussoft.gui.attribute.OtherElementTableCellEditor.PopupRowWrapper) KeyStroke(javax.swing.KeyStroke) InputMap(javax.swing.InputMap) Row(com.ramussoft.database.common.Row) JList(javax.swing.JList)

Example 79 with Row

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

the class SelectRowDialog method deleteRightPanel.

private void deleteRightPanel() {
    if (selectableTableView != null) {
        selectableTableView.getComponent().getModel().removeSelectionListener(selectionListener);
        List<Row> list = selectableTableView.getComponent().getModel().getSelectedRows();
        selectedRows.put(qualifier, list);
        selectableTableView.close();
        selectableTableView = null;
        splitPane.setRightComponent(new JPanel());
    }
}
Also used : JPanel(javax.swing.JPanel) Row(com.ramussoft.database.common.Row)

Example 80 with Row

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

the class SelectRowPanel method getSelected.

public List<com.ramussoft.pb.Row> getSelected() {
    {
        List<Row> list = selectableTableView.getComponent().getModel().getSelectedRows();
        selectedRows.put(qualifier, list);
    }
    List<com.ramussoft.pb.Row> result = new ArrayList<com.ramussoft.pb.Row>();
    for (List<Row> list : selectedRows.values()) {
        for (Row row : list) {
            com.ramussoft.pb.Row r = dataPlugin.findRowByGlobalId(row.getElementId());
            if (r != null)
                result.add(r);
        }
    }
    if (qualifier != null) {
        Engine engine = dataPlugin.getEngine();
        Qualifier q = StandardAttributesPlugin.getQualifiersQualifier(engine);
        List<Element> list = engine.getElements(q.getId());
        for (Element element : list) {
            if (qualifier.equals(StandardAttributesPlugin.getQualifier(engine, element))) {
                com.ramussoft.pb.Row r = dataPlugin.findRowByGlobalId(element.getId());
                if (r != null) {
                    result.add(r);
                } else {
                    System.err.println("WARNING: Can not find element for qualifier (" + qualifier.getName() + ")");
                }
            }
        }
    }
    return result;
}
Also used : Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Qualifier(com.ramussoft.common.Qualifier) Row(com.ramussoft.database.common.Row) Engine(com.ramussoft.common.Engine)

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