Search in sources :

Example 36 with Engine

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

the class IDEF0Object method createEditFrame.

@Override
protected void createEditFrame() {
    final GUIFramework framework = movingArea.getPanel().getFramework();
    final Engine engine = framework.getEngine();
    long id = getFunction().getLink();
    Element element2 = null;
    if (id >= 0)
        element2 = engine.getElement(id);
    if (element2 == null)
        element2 = getFunction().getElement();
    final Element element = element2;
    Qualifier qualifier = engine.getQualifier(element.getQualifierId());
    Attribute name = null;
    if (qualifier.getAttributeForName() >= 0)
        name = engine.getAttribute(qualifier.getAttributeForName());
    if (name == null) {
        JOptionPane.showMessageDialog(framework.getMainFrame(), ResourceLoader.getString("NameAttributeNotSet"));
        return;
    }
    final Attribute nameAttribute = name;
    AttributePlugin plugin = framework.findAttributePlugin(name);
    final AttributeEditor editor = plugin.getAttributeEditor(engine, framework.getAccessRules(), element, name, "activity_name", null);
    setTextComponent(new JScrollPane(editor.getLastComponent()));
    final Object value = engine.getAttribute(element, name);
    editor.setValue(value);
    final Rectangle r = movingArea.getIBounds(getBounds());
    final JTextArea textArea = (JTextArea) editor.getLastComponent();
    processTextArea(textArea);
    // textArea.setBackground(getFunction().getBackground());
    // textArea.setForeground(getFunction().getForeground());
    // textArea.setFont(movingArea.getFont(getFont()));
    // textArea.setCaretColor(getFunction().getForeground());
    final JPopupMenu menu = textArea.getComponentPopupMenu();
    textArea.setComponentPopupMenu(null);
    movingArea.getPanel().setActionDisable(true);
    textArea.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER && e.isControlDown()) {
                stopEdit(element, engine, nameAttribute, editor, value, textArea, menu);
            } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
                cancelEdit(editor, textArea, menu);
        }
    });
    textArea.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            stopEdit(element, engine, nameAttribute, editor, value, textArea, menu);
        }

        @Override
        public void focusGained(FocusEvent e) {
        }
    });
    movingArea.add(getTextComponent());
    movingArea.setbImage(null);
    getTextComponent().setBounds(r);
    movingArea.revalidate();
    movingArea.repaint();
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            textArea.requestFocus();
        }
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) JTextArea(javax.swing.JTextArea) AttributePlugin(com.ramussoft.gui.common.AttributePlugin) Attribute(com.ramussoft.common.Attribute) GUIFramework(com.ramussoft.gui.common.GUIFramework) Element(com.ramussoft.common.Element) KeyAdapter(java.awt.event.KeyAdapter) Rectangle(java.awt.Rectangle) FRectangle(com.dsoft.pb.types.FRectangle) FocusEvent(java.awt.event.FocusEvent) JPopupMenu(javax.swing.JPopupMenu) KeyEvent(java.awt.event.KeyEvent) AttributeEditor(com.ramussoft.gui.common.AttributeEditor) Qualifier(com.ramussoft.common.Qualifier) FocusListener(java.awt.event.FocusListener) Engine(com.ramussoft.common.Engine)

Example 37 with Engine

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

the class TablePlugin method getAttributePreferenciesEditor.

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

        private SelectableTableView view;

        private AttributeOrderEditPanel attributeOrderEditPanel = new AttributeOrderEditPanel(new ArrayList<Attribute>(), true);

        private Action createAttributeAction = new AbstractAction() {

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

            {
                this.putValue(ACTION_COMMAND_KEY, "CreateAttribute");
                this.putValue(SMALL_ICON, new ImageIcon(getClass().getResource("/com/ramussoft/gui/table/add.png")));
                this.putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_ADD, KeyEvent.CTRL_MASK));
            }

            @Override
            public void actionPerformed(ActionEvent e) {
                new AttributePreferenciesDialog(framework).setVisible(true);
            }
        };

        private Action deleteAttributeAction = new AbstractAction() {

            {
                this.putValue(ACTION_COMMAND_KEY, "DeleteAttribute");
                this.putValue(SMALL_ICON, new ImageIcon(getClass().getResource("/com/ramussoft/gui/table/delete.png")));
                this.putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
            }

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

            @Override
            public void actionPerformed(ActionEvent e) {
                if (JOptionPane.showConfirmDialog(framework.getMainFrame(), GlobalResourcesManager.getString("DeleteActiveElementsDialog.Warning"), UIManager.getString("OptionPane.titleText"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                    TreePath[] paths = view.getComponent().getTable().getTreeSelectionModel().getSelectionPaths();
                    if (paths.length == 0) {
                        System.err.println("Trying to delete element, but no elements are selected");
                        return;
                    }
                    for (TreePath path : paths) {
                        Row row = ((TreeTableNode) path.getLastPathComponent()).getRow();
                        if (row == null) {
                            System.err.println("Trying to delete node, which conatain no row");
                            return;
                        }
                        long attrId = (Long) row.getAttribute((Attribute) view.getComponent().getRowSet().getEngine().getPluginProperty("Core", StandardAttributesPlugin.ATTRIBUTE_ID));
                        view.getComponent().getRowSet().startUserTransaction();
                        view.getComponent().getRowSet().getEngine().deleteAttribute(attrId);
                        view.getComponent().getRowSet().commitUserTransaction();
                    }
                }
            }
        };

        @Override
        public void apply(Attribute attribute, Engine engine, AccessRules accessRules) {
            String qualifierName = StandardAttributesPlugin.getTableQualifeirName(attribute);
            Qualifier qualifier = engine.getSystemQualifier(qualifierName);
            if (qualifier == null) {
                qualifier = engine.createSystemQualifier();
                qualifier.setName(qualifierName);
            }
            List<Attribute> attributes = attributeOrderEditPanel.getAttributes();
            fillAttributes(engine, attributes);
            qualifier.setAttributes(attributes);
            qualifier.getSystemAttributes().clear();
            qualifier.getSystemAttributes().add(StandardAttributesPlugin.getTableElementIdAttribute(engine));
            engine.updateQualifier(qualifier);
            List<TableGroupablePropertyPersistent> list = new ArrayList<TableGroupablePropertyPersistent>();
            int i = 0;
            for (String group : attributeOrderEditPanel.getAttributeGroups()) {
                if (group != null) {
                    TableGroupablePropertyPersistent p = new TableGroupablePropertyPersistent();
                    p.setAttribute(attribute.getId());
                    p.setName(group);
                    p.setOtherAttribute(attributes.get(i).getId());
                    list.add(p);
                }
                i++;
            }
            engine.setAttribute(null, attribute, list);
        }

        private void fillAttributes(Engine engine, List<Attribute> attributes) {
            List<Row> rows = view.getSelectedRows();
            ArrayList<Attribute> toRemove = new ArrayList<Attribute>(attributes);
            for (Row row : rows) {
                Attribute attr = StandardAttributesPlugin.getAttribute(engine, row.getElement());
                toRemove.remove(attr);
                if (attributes.indexOf(attr) < 0)
                    attributes.add(attr);
            }
            for (Attribute attribute : toRemove) attributes.remove(attribute);
        }

        @Override
        public boolean canApply() {
            return view.getSelectedRows().size() > 0;
        }

        @SuppressWarnings("unchecked")
        @Override
        public JComponent createComponent(Attribute attribute, final Engine engine, AccessRules accessRules) {
            view = new SelectableTableView(framework, engine, accessRules, StandardAttributesPlugin.getAttributesQualifier(engine)) {

                @Override
                protected Attribute[] getAttributes() {
                    return new Attribute[] { StandardAttributesPlugin.getAttributeNameAttribute(engine), StandardAttributesPlugin.getAttributeTypeNameAttribute(engine) };
                }
            };
            JComponent component = view.createComponent();
            view.getComponent().getModel().setEditable(0, false);
            view.getComponent().getModel().setEditable(1, false);
            JTabbedPane pane = new JTabbedPane();
            pane.addTab(GlobalResourcesManager.getString("attributes"), component);
            pane.addTab(GlobalResourcesManager.getString("AttributesOrder"), attributeOrderEditPanel);
            pane.addChangeListener(new ChangeListener() {

                @Override
                public void stateChanged(ChangeEvent e) {
                    fillAttributes(engine, attributeOrderEditPanel.getAttributes());
                    attributeOrderEditPanel.refresh();
                }
            });
            if (attribute != null) {
                Qualifier qualifier = StandardAttributesPlugin.getTableQualifierForAttribute(engine, attribute);
                attributeOrderEditPanel.setAttributes(qualifier.getAttributes());
                Hashtable<Attribute, String> groups = new Hashtable<Attribute, String>();
                List<TableGroupablePropertyPersistent> pList = (List) engine.getAttribute(null, attribute);
                for (TableGroupablePropertyPersistent p : pList) for (Attribute attribute2 : qualifier.getAttributes()) {
                    if ((p.getOtherAttribute() == attribute2.getId()) && (p.getName() != null))
                        groups.put(attribute2, p.getName());
                }
                attributeOrderEditPanel.setGroups(groups);
                List<Row> list = view.getComponent().getRowSet().getAllRows();
                for (Row row : list) {
                    Attribute attr = StandardAttributesPlugin.getAttribute(engine, row.getElement());
                    if (qualifier.getAttributes().indexOf(attr) >= 0) {
                        view.setSelectedRow(row, true);
                    }
                }
            }
            view.getComponent().getTable().setComponentPopupMenu(createPopupMenu());
            return pane;
        }

        private JPopupMenu createPopupMenu() {
            JPopupMenu menu = new JPopupMenu();
            for (Action action : getActions()) {
                if (action == null)
                    menu.addSeparator();
                else {
                    action.putValue(Action.NAME, GlobalResourcesManager.getString((String) action.getValue(Action.ACTION_COMMAND_KEY)));
                    menu.add(action);
                }
            }
            return menu;
        }

        private Action[] getActions() {
            return new Action[] { createAttributeAction, new AbstractAction() {

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

                {
                    this.putValue(ACTION_COMMAND_KEY, "Action.SortByName");
                    this.putValue(SMALL_ICON, new ImageIcon(getClass().getResource("/com/ramussoft/gui/table/sort-incr.png")));
                }

                @Override
                public void actionPerformed(ActionEvent e) {
                    view.getComponent().getRowSet().startUserTransaction();
                    view.getComponent().getRowSet().sortByName();
                    view.getComponent().getRowSet().commitUserTransaction();
                }
            }, deleteAttributeAction };
        }
    };
}
Also used : ImageIcon(javax.swing.ImageIcon) Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) Attribute(com.ramussoft.common.Attribute) ActionEvent(java.awt.event.ActionEvent) JTabbedPane(javax.swing.JTabbedPane) ArrayList(java.util.ArrayList) AttributePreferenciesEditor(com.ramussoft.gui.common.AttributePreferenciesEditor) AttributeOrderEditPanel(com.ramussoft.gui.qualifier.AttributeOrderEditPanel) Qualifier(com.ramussoft.common.Qualifier) ArrayList(java.util.ArrayList) List(java.util.List) ChangeListener(javax.swing.event.ChangeListener) TableGroupablePropertyPersistent(com.ramussoft.core.attribute.simple.TableGroupablePropertyPersistent) AbstractAction(javax.swing.AbstractAction) SelectableTableView(com.ramussoft.gui.qualifier.table.SelectableTableView) Engine(com.ramussoft.common.Engine) Hashtable(java.util.Hashtable) JComponent(javax.swing.JComponent) JPopupMenu(javax.swing.JPopupMenu) TreePath(javax.swing.tree.TreePath) ChangeEvent(javax.swing.event.ChangeEvent) AccessRules(com.ramussoft.common.AccessRules) Row(com.ramussoft.database.common.Row)

Example 38 with Engine

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

the class ElistTabView method close.

@Override
public void close() {
    Engine engine = framework.getEngine();
    super.close();
    Properties properties = new Properties();
    Options.setBoolean("REVERT", revert, properties);
    Options.saveOptions(component, properties);
    engine.setProperties(getProperiesName(), properties);
    left.close();
    right.close();
    engine.removeAttributeListener(listener);
    engine.removeElementAttributeListener(q1, leftAttributeListener);
    engine.removeElementAttributeListener(q2, rightAttributeListener);
}
Also used : Properties(java.util.Properties) Engine(com.ramussoft.common.Engine)

Example 39 with Engine

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

the class CurrencyAttributePlugin method getAttributePreferenciesEditor.

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

        private JComboBox comboBox = new JComboBox();

        @Override
        public JComponent createComponent(Attribute attribute, Engine engine, AccessRules accessRules) {
            CurrencyPropertyPersistent p = null;
            if (attribute != null)
                p = (CurrencyPropertyPersistent) engine.getAttribute(null, attribute);
            comboBox.addItem(GlobalResourcesManager.getString("ByDefault"));
            int i = 1;
            int index = 0;
            for (Currency currency : getCurrencies()) {
                comboBox.addItem(currency);
                if ((p != null) && (p.getCode() != null) && (p.getCode().equals(currency.getCurrencyCode())))
                    index = i;
                i++;
            }
            comboBox.setSelectedIndex(index);
            double[][] size = { { 5, TableLayout.MINIMUM, 5, TableLayout.FILL, 5 }, { 5, TableLayout.MINIMUM, 5 } };
            TableLayout layout = new TableLayout(size);
            JPanel panel = new JPanel(layout);
            panel.add(new JLabel(GlobalResourcesManager.getString("Attribute.CurrencyCode")), "1,1");
            panel.add(comboBox, "3,1");
            return panel;
        }

        @Override
        public boolean canApply() {
            return true;
        }

        @Override
        public void apply(Attribute attribute, Engine engine, AccessRules accessRules) {
            if (comboBox.getSelectedIndex() == 0) {
                engine.setAttribute(null, attribute, null);
            } else {
                CurrencyPropertyPersistent p = new CurrencyPropertyPersistent();
                p.setCode(((Currency) comboBox.getSelectedItem()).getCurrencyCode());
                engine.setAttribute(null, attribute, p);
            }
        }
    };
}
Also used : CurrencyPropertyPersistent(com.ramussoft.core.attribute.simple.CurrencyPropertyPersistent) JPanel(javax.swing.JPanel) JComboBox(javax.swing.JComboBox) Attribute(com.ramussoft.common.Attribute) Currency(java.util.Currency) AccessRules(com.ramussoft.common.AccessRules) JLabel(javax.swing.JLabel) TableLayout(info.clearthought.layout.TableLayout) AttributePreferenciesEditor(com.ramussoft.gui.common.AttributePreferenciesEditor) Engine(com.ramussoft.common.Engine)

Example 40 with Engine

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

the class TableEditorTable method setModel.

@Override
public void setModel(TableModel dataModel) {
    super.setModel(dataModel);
    if (!(dataModel instanceof TableEditorModel))
        return;
    TableEditorModel model = (TableEditorModel) dataModel;
    Engine engine = framework.getEngine();
    AccessRules rules = framework.getAccessRules();
    for (int i = 0; i < plugins.length; i++) {
        AttributePlugin plugin = framework.findAttributePlugin(attributes.get(i));
        plugins[i] = plugin;
        cellEditors[i] = plugin.getTableCellEditor(engine, rules, attributes.get(i));
        if (cellEditors[i] == null) {
            cellEditors[i] = new DialogedTableCellEditor(engine, rules, attributes.get(i), plugins[i], framework);
            model.setSaveValue(i, false);
        }
        cellRenderers[i] = plugin.getTableCellRenderer(engine, rules, attributes.get(i));
    }
}
Also used : AttributePlugin(com.ramussoft.gui.common.AttributePlugin) AccessRules(com.ramussoft.common.AccessRules) Engine(com.ramussoft.common.Engine) DialogedTableCellEditor(com.ramussoft.gui.qualifier.table.DialogedTableCellEditor)

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