Search in sources :

Example 61 with Row

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

the class OtherElementEditor method setValue.

@Override
public Object setValue(Object value) {
    component.getModel().clearSelection();
    if (value != null) {
        long elementId = (Long) value;
        if (elementId > -1l) {
            RowSet rowSet = component.getRowSet();
            Row row = rowSet.findRow(elementId);
            if (row != null) {
                component.getModel().setSelectedRow(row, true);
                int indexOfRow = component.getTable().indexOfRow(row);
                if (indexOfRow >= 0)
                    component.getTable().scrollRowToVisible(indexOfRow);
            } else
                return null;
        } else
            return null;
    }
    return value;
}
Also used : RowSet(com.ramussoft.database.common.RowSet) Row(com.ramussoft.database.common.Row)

Example 62 with Row

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

the class QualifierPlugin method getProjectPreferences.

@Override
public Preferences[] getProjectPreferences() {
    return new Preferences[] { new AbstractPreferences() {

        class Button extends JRadioButton {

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

            private Language language;

            public Button(Language language) {
                this.language = language;
            }

            public Language getLanguage() {
                return language;
            }
        }

        private JPanel component;

        private Button[] buttons;

        private JCheckBox box;

        {
            Properties ps = engine.getProperties(TextAttributePlugin.USER_GUI_SPELL_PROPERTIES);
            Language language = getCurrentLanguage(ps);
            Language[] languages = SpellFactory.getLanguages();
            box = new JCheckBox(GlobalResourcesManager.getString("Editor.SpellCheck"));
            box.setSelected(Options.getBoolean(TextAttributePlugin.SPELL_CHECK, true, ps));
            JPanel languagesPanel = new JPanel();
            languagesPanel.setLayout(new BoxLayout(languagesPanel, BoxLayout.Y_AXIS));
            buttons = new Button[languages.length];
            ButtonGroup group = new ButtonGroup();
            for (int i = 0; i < languages.length; i++) {
                Button button = new Button(languages[i]);
                button.setText(languages[i].getLocalizedName());
                languagesPanel.add(button);
                buttons[i] = button;
                if (languages[i].equals(language))
                    button.setSelected(true);
                group.add(button);
            }
            JScrollPane pane = new JScrollPane();
            pane.setViewportView(languagesPanel);
            component = new JPanel(new BorderLayout());
            component.add(pane, BorderLayout.CENTER);
            component.add(box, BorderLayout.NORTH);
        }

        @Override
        public JComponent createComponent() {
            return component;
        }

        @Override
        public String getTitle() {
            return GlobalResourcesManager.getString("Preferences.SpellChecking");
        }

        @Override
        public boolean save(JDialog dialog) {
            Properties ps = engine.getProperties(TextAttributePlugin.USER_GUI_SPELL_PROPERTIES);
            Options.setBoolean(TextAttributePlugin.SPELL_CHECK, box.isSelected(), ps);
            String l = "";
            for (Button button : buttons) if (button.isSelected()) {
                l = button.getLanguage().getName();
                break;
            }
            Options.setString(TextAttributePlugin.LANGUAGE, l, ps);
            engine.setProperties(TextAttributePlugin.USER_GUI_SPELL_PROPERTIES, ps);
            return true;
        }

        private Language getCurrentLanguage(Properties ps) {
            String langName = Options.getString(TextAttributePlugin.LANGUAGE, "", ps);
            Language language;
            if ((langName == null) || (langName.equals("")))
                language = SpellFactory.getDefaultLanguage();
            else
                language = SpellFactory.findLanguage(langName);
            return language;
        }
    }, new AbstractPreferences() {

        SelectableTableView tableView;

        JComboBox attributeForName = new JComboBox();

        private JPanel panel;

        {
            tableView = new SelectableTableView(framework, engine, accessor, StandardAttributesPlugin.getAttributesQualifier(engine)) {

                @Override
                protected Attribute[] getAttributes() {
                    return new Attribute[] { StandardAttributesPlugin.getAttributeNameAttribute(engine), StandardAttributesPlugin.getAttributeTypeNameAttribute(engine) };
                }
            };
            double[][] size = { { 5, TableLayout.MINIMUM, 5, TableLayout.FILL, 5 }, { 5, TableLayout.MINIMUM, 5 } };
            JPanel attrForName = new JPanel(new TableLayout(size));
            attrForName.add(new JLabel(GlobalResourcesManager.getString("Qualifier.AttributeForName")), "1, 1");
            attrForName.add(attributeForName, "3, 1");
            panel = new JPanel(new BorderLayout());
            panel.add(tableView.createComponent(), BorderLayout.CENTER);
            panel.add(attrForName, BorderLayout.SOUTH);
            Properties ps = engine.getProperties(AutochangePlugin.AUTO_ADD_ATTRIBUTES);
            String ids = ps.getProperty(AutochangePlugin.AUTO_ADD_ATTRIBUTE_IDS);
            if (ids == null)
                ids = "";
            String aForName = ps.getProperty(AutochangePlugin.ATTRIBUTE_FOR_NAME);
            StringTokenizer st = new StringTokenizer(ids, " ,");
            List<Row> rows = tableView.getComponent().getRowSet().getAllRows();
            attributeForName.addItem(null);
            while (st.hasMoreElements()) {
                String s = st.nextToken();
                Long long1 = new Long(s);
                Row row = findRow(long1, rows);
                if (row != null) {
                    tableView.setSelectedRow(row, true);
                    attributeForName.addItem(row);
                    if (s.equals(aForName))
                        attributeForName.setSelectedItem(row);
                }
            }
            attributeForName.addPopupMenuListener(new PopupMenuListener() {

                @Override
                public void popupMenuCanceled(PopupMenuEvent e) {
                }

                @Override
                public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
                }

                @Override
                public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
                    attributeForName.removeAllItems();
                    List<Row> list = tableView.getSelectedRows();
                    for (Row p : list) {
                        Attribute a = StandardAttributesPlugin.getAttribute(engine, p.getElement());
                        if (StandardAttributesPlugin.isNameType(a.getAttributeType()))
                            attributeForName.addItem(p);
                    }
                    JComboBox box = (JComboBox) e.getSource();
                    Object comp = box.getUI().getAccessibleChild(box, 0);
                    if (!(comp instanceof JPopupMenu))
                        return;
                    JComponent scrollPane = (JComponent) ((JPopupMenu) comp).getComponent(0);
                    Dimension size = new Dimension();
                    size.width = box.getPreferredSize().width;
                    size.height = scrollPane.getPreferredSize().height;
                    scrollPane.setPreferredSize(size);
                }
            });
        }

        @Override
        public JComponent createComponent() {
            return panel;
        }

        private Row findRow(Long long1, List<Row> rows) {
            Attribute attr = engine.getAttribute(long1.longValue());
            if (attr != null) {
                for (Row row : rows) {
                    Long long2 = StandardAttributesPlugin.getAttributeId(engine, row.getElement());
                    if (long2 != null) {
                        if (attr.getId() == long2.longValue())
                            return row;
                    }
                }
            }
            return null;
        }

        @Override
        public String getTitle() {
            return GlobalResourcesManager.getString("Preferences.AutoaddAttributes");
        }

        @Override
        public boolean save(JDialog dialog) {
            List<Row> list = tableView.getSelectedRows();
            StringBuffer sb = new StringBuffer();
            for (Row row : list) {
                Long id = StandardAttributesPlugin.getAttributeId(engine, row.getElement());
                if (id != null)
                    sb.append(id + " ");
            }
            Properties properties = engine.getProperties(AutochangePlugin.AUTO_ADD_ATTRIBUTES);
            properties.setProperty(AutochangePlugin.AUTO_ADD_ATTRIBUTE_IDS, sb.toString());
            Row row = (Row) attributeForName.getSelectedItem();
            if (row != null)
                properties.setProperty(AutochangePlugin.ATTRIBUTE_FOR_NAME, Long.toString(StandardAttributesPlugin.getAttributeId(engine, row.getElement())));
            engine.setProperties(AutochangePlugin.AUTO_ADD_ATTRIBUTES, properties);
            return true;
        }

        @Override
        public void close() {
            tableView.close();
        }
    } };
}
Also used : JPanel(javax.swing.JPanel) Attribute(com.ramussoft.common.Attribute) BoxLayout(javax.swing.BoxLayout) PopupMenuListener(javax.swing.event.PopupMenuListener) Properties(java.util.Properties) PopupMenuEvent(javax.swing.event.PopupMenuEvent) Language(com.ramussoft.gui.spell.Language) BorderLayout(java.awt.BorderLayout) JRadioButton(javax.swing.JRadioButton) List(java.util.List) Preferences(com.ramussoft.gui.common.prefrence.Preferences) AbstractPreferences(com.ramussoft.gui.common.prefrence.AbstractPreferences) TableLayout(info.clearthought.layout.TableLayout) SelectableTableView(com.ramussoft.gui.qualifier.table.SelectableTableView) JScrollPane(javax.swing.JScrollPane) JComboBox(javax.swing.JComboBox) AbstractPreferences(com.ramussoft.gui.common.prefrence.AbstractPreferences) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JPopupMenu(javax.swing.JPopupMenu) JCheckBox(javax.swing.JCheckBox) StringTokenizer(java.util.StringTokenizer) ButtonGroup(javax.swing.ButtonGroup) Row(com.ramussoft.database.common.Row) JDialog(javax.swing.JDialog)

Example 63 with Row

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

the class QualifierPreferencesPanel method setupAttribute.

public void setupAttribute() {
    Row row = attributeEditor.getSelectedRow();
    if (row == null)
        return;
    AttributePreferenciesDialog d;
    if (dialog == null)
        d = new AttributePreferenciesDialog(framework);
    else
        d = new AttributePreferenciesDialog(framework, dialog);
    Attribute attribute = engine.getAttribute((Long) row.getAttribute(attributeId));
    d.setAttribute(attribute);
    d.getOKButton().setEnabled(rules.canUpdateAttribute(attribute.getId()));
    d.setVisible(true);
}
Also used : Attribute(com.ramussoft.common.Attribute) AttributePreferenciesDialog(com.ramussoft.gui.attribute.AttributePreferenciesDialog) Row(com.ramussoft.database.common.Row)

Example 64 with Row

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

the class QualifierView method refreshActions.

@Override
protected void refreshActions() {
    super.refreshActions();
    TreePath selectionPath = table.getTreeSelectionModel().getSelectionPath();
    boolean anySelected = selectionPath != null;
    qualifierPreferenciesAction.setEnabled(anySelected);
    Row sRow = null;
    if (selectionPath != null)
        sRow = ((TreeTableNode) selectionPath.getLastPathComponent()).getRow();
    if (sRow == null)
        convertQualifierToElementsAction.setEnabled(false);
    else {
        if ((sRow.getChildCount() == 0) || (table.getTreeSelectionModel().getSelectionPaths().length > 1))
            convertQualifierToElementsAction.setEnabled(false);
        else
            convertQualifierToElementsAction.setEnabled(canDeleteLastLeveleOfQualifiers(sRow, qAttribute));
    }
    openQualifier.setEnabled(anySelected && sRow != null && sRow.getChildCount() == 0);
    if (deleteElementAction.isEnabled()) {
        TreePath[] paths = table.getTreeSelectionModel().getSelectionPaths();
        boolean e = true;
        for (TreePath path : paths) {
            Row row = ((TreeTableNode) path.getLastPathComponent()).getRow();
            if (engine.getElement(row.getElementId()) == null)
                row = null;
            if (row == null) {
                e = false;
                break;
            }
            if (row.getChildCount() > 0) {
                e = false;
                break;
            }
            Long attribute = (Long) row.getAttribute(qAttribute);
            if ((attribute != null) && (!accessRules.canDeleteQualifier(attribute))) {
                e = false;
                break;
            }
        }
        deleteElementAction.setEnabled(e);
    }
}
Also used : TreePath(javax.swing.tree.TreePath) TreeTableNode(com.ramussoft.gui.qualifier.table.TreeTableNode) Row(com.ramussoft.database.common.Row) RootRow(com.ramussoft.database.common.RowSet.RootRow)

Example 65 with Row

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

the class RowTreeTable method getBodyText.

public String getBodyText(String tableName) {
    StringBuffer sb = new StringBuffer();
    sb.append("<h1>" + tableName + "</h1>\n<hr>\n");
    sb.append("<table>\n");
    RowTreeTableModel model = (RowTreeTableModel) getTreeTableModel();
    sb.append("<tr>");
    sb.append("<td><b><i>");
    sb.append(GlobalResourcesManager.getString("Code"));
    sb.append("</i></b></td>\n");
    for (int j = 0; j < getColumnCount(); j++) {
        int column = convertColumnIndexToModel(j);
        sb.append("<td><b>");
        String name = getModel().getColumnName(column);
        if (name != null) {
            if (name.startsWith("<html><body><center>"))
                name = name.substring("<html><body><center>".length(), name.length() - "</center></body></html>".length());
            sb.append(name);
        }
        sb.append("</b></td>\n");
    }
    sb.append("</tr>\n");
    for (int i = 0; i < getRowCount(); i++) {
        int row = convertRowIndexToModel(i);
        sb.append("<tr>");
        sb.append("<td>");
        TreeTableNode node = (TreeTableNode) getPathForRow(row).getLastPathComponent();
        Row row2 = node.getRow();
        if (row2 != null)
            sb.append("<i>" + row2.getCode() + "</i>");
        sb.append("</td>");
        for (int j = 0; j < getColumnCount(); j++) {
            boolean rightAlign = false;
            int column = convertColumnIndexToModel(j);
            TableCellRenderer renderer = getCellRenderer(row, column);
            String value;
            if (renderer instanceof JLabel) {
                if (((JLabel) renderer).getHorizontalAlignment() == SwingConstants.RIGHT)
                    rightAlign = true;
            }
            Object object = model.getValueAt(node, column);
            if (object == null)
                value = null;
            else
                value = object.toString();
            if (rightAlign)
                sb.append("<td align=\"right\">");
            else
                sb.append("<td>");
            if (value != null)
                sb.append(value);
            sb.append("</td>\n");
        }
        sb.append("</tr>\n");
    }
    sb.append("</table>\n");
    return sb.toString();
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) JLabel(javax.swing.JLabel) EventObject(java.util.EventObject) Row(com.ramussoft.database.common.Row)

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