Search in sources :

Example 61 with Engine

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

the class ChartSetsView method createComponent.

@Override
public JComponent createComponent() {
    Engine engine = framework.getEngine();
    AccessRules accessRules = framework.getAccessRules();
    component = new RowTreeTableComponent(engine, ChartPlugin.getChartSets(engine), accessRules, new RowRootCreater(), new Attribute[] { StandardAttributesPlugin.getAttributeNameAttribute(engine) }, framework);
    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)) {
                    openChartSet();
                } 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.addSelectionListener(new SelectionListener() {

        @Override
        public void changeSelection(SelectionEvent event) {
            TreeTableNode selectedNode = component.getTable().getSelectedNode();
            if (selectedNode == null)
                openChartSetAction.setEnabled(false);
            else {
                Row row = selectedNode.getRow();
                openChartSetAction.setEnabled(row != null);
            }
            deleteChartSetAction.setEnabled(openChartSetAction.isEnabled());
        }
    });
    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();
        }
    });
    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 62 with Engine

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

the class ChartSetsView 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) engine.deleteElement(row.getElementId());
        ((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 63 with Engine

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

the class ChartSetsView method deleteChartSet.

public void deleteChartSet() {
    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.deleteChartSet(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 64 with Engine

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

the class ChartPreferencesDialog method onOk.

@Override
protected void onOk() {
    Engine engine = framework.getEngine();
    try {
        ((Journaled) engine).startUserTransaction();
        chart.setName(name.getText());
        Element element = chart.getElement();
        editor.save(element);
        ((Journaled) engine).commitUserTransaction();
    } catch (Exception e) {
        ((Journaled) engine).rollbackUserTransaction();
        e.printStackTrace();
        JOptionPane.showMessageDialog(framework.getMainFrame(), e.getLocalizedMessage());
    }
    super.onOk();
}
Also used : Journaled(com.ramussoft.common.journal.Journaled) Element(com.ramussoft.common.Element) Engine(com.ramussoft.common.Engine)

Example 65 with Engine

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

the class OtherElementPlugin method getAttributePreferenciesEditor.

@Override
public AttributePreferenciesEditor getAttributePreferenciesEditor() {
    return new AttributePreferenciesEditor() {

        private JComboBox qualifierBox = new JComboBox();

        private JComboBox attributeBox = new JComboBox();

        @Override
        public void apply(Attribute attribute, Engine engine, AccessRules accessRules) {
            OtherElementPropertyPersistent p = new OtherElementPropertyPersistent();
            p.setQualifier(((Qualifier) qualifierBox.getSelectedItem()).getId());
            p.setQualifierAttribute(((Attribute) attributeBox.getSelectedItem()).getId());
            engine.setAttribute(null, attribute, p);
        }

        @Override
        public boolean canApply() {
            return (qualifierBox.getSelectedItem() != null) && (attributeBox.getSelectedItem() != null);
        }

        @Override
        public JComponent createComponent(Attribute attribute, Engine engine, AccessRules accessRules) {
            double[][] size = { { 5, TableLayout.FILL, 5, TableLayout.FILL, 5 }, { 5, TableLayout.MINIMUM, 5, TableLayout.MINIMUM, 5 } };
            JPanel panel = new JPanel(new TableLayout(size));
            panel.add(new JLabel(GlobalResourcesManager.getString("OtherElement.Qualifier")), "1, 1");
            panel.add(new JLabel(GlobalResourcesManager.getString("OtherElement.Attribute")), "3, 1");
            for (Qualifier qualifier : engine.getQualifiers()) {
                qualifierBox.addItem(qualifier);
            }
            if (attribute != null) {
                OtherElementPropertyPersistent p = (OtherElementPropertyPersistent) engine.getAttribute(null, attribute);
                qualifierBox.setSelectedItem(engine.getQualifier(p.getQualifier()));
                long attributeId = p.getQualifierAttribute();
                if (attributeId >= 0)
                    attributeBox.setSelectedItem(engine.getAttribute(attributeId));
                qualifierBox.setEnabled(false);
            }
            qualifierBox.addItemListener(new ItemListener() {

                @Override
                public void itemStateChanged(ItemEvent e) {
                    if (e.getStateChange() == ItemEvent.SELECTED) {
                        loadAttributes();
                    }
                }
            });
            loadAttributes();
            panel.add(qualifierBox, "1, 3");
            panel.add(attributeBox, "3, 3");
            return panel;
        }

        private void loadAttributes() {
            attributeBox.removeAllItems();
            Qualifier qualifier = (Qualifier) qualifierBox.getSelectedItem();
            if (qualifier == null)
                return;
            for (Attribute attribute : qualifier.getAttributes()) {
                attributeBox.addItem(attribute);
            }
        }
    };
}
Also used : JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) JComboBox(javax.swing.JComboBox) Attribute(com.ramussoft.common.Attribute) JLabel(javax.swing.JLabel) AttributePreferenciesEditor(com.ramussoft.gui.common.AttributePreferenciesEditor) OtherElementPropertyPersistent(com.ramussoft.core.attribute.simple.OtherElementPropertyPersistent) AccessRules(com.ramussoft.common.AccessRules) Qualifier(com.ramussoft.common.Qualifier) ItemListener(java.awt.event.ItemListener) TableLayout(info.clearthought.layout.TableLayout) Engine(com.ramussoft.common.Engine)

Aggregations

Engine (com.ramussoft.common.Engine)85 Attribute (com.ramussoft.common.Attribute)32 ArrayList (java.util.ArrayList)30 Element (com.ramussoft.common.Element)27 Qualifier (com.ramussoft.common.Qualifier)22 AccessRules (com.ramussoft.common.AccessRules)21 List (java.util.List)19 IEngine (com.ramussoft.common.IEngine)15 Row (com.ramussoft.database.common.Row)13 IOException (java.io.IOException)11 SQLException (java.sql.SQLException)11 PluginFactory (com.ramussoft.common.PluginFactory)8 PluginProvider (com.ramussoft.common.PluginProvider)8 Journaled (com.ramussoft.common.journal.Journaled)8 CachedEngine (com.ramussoft.common.cached.CachedEngine)7 Hashtable (java.util.Hashtable)7 TreeTableNode (com.ramussoft.gui.qualifier.table.TreeTableNode)6 JournaledEngine (com.ramussoft.common.journal.JournaledEngine)5 FileIEngineImpl (com.ramussoft.core.impl.FileIEngineImpl)5 MemoryDatabase (com.ramussoft.database.MemoryDatabase)5