Search in sources :

Example 51 with Qualifier

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

the class Util method decompileValue.

protected String decompileValue(final Element element, String oldName) {
    MetaValue value = toMetaValue(oldName);
    Attribute attribute = engine.getAttribute(value.getAttributeId());
    if ((element != null) && (value.getElementId() == element.getId())) {
        return toCanonicalValue(attribute.getName());
    } else {
        Element e = engine.getElement(value.getElementId());
        if (e.getName().length() == 0)
            return toCanonicalValue(ELEMENT_PREFIX + e.getId() + "." + attribute.getName());
        if ((element != null) && (e.getQualifierId() == element.getQualifierId())) {
            return toCanonicalValue(e.getName() + "." + attribute.getName());
        } else {
            Qualifier qualifier = engine.getQualifier(e.getQualifierId());
            return toCanonicalValue(replaceDots(qualifier.getName()) + "." + replaceDots(e.getName()) + "." + replaceDots(attribute.getName()));
        }
    }
}
Also used : Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) Qualifier(com.ramussoft.common.Qualifier)

Example 52 with Qualifier

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

the class Util method compile.

public String compile(Qualifier qualifier, String userFunction) {
    List<Attribute> attrs = qualifier.getAttributes();
    final Hashtable<String, String> hash = new Hashtable<String, String>(attrs.size());
    for (Attribute attr : attrs) {
        AttributeType type = attr.getAttributeType();
        if (type.toString().equals("Core.Table")) {
            Qualifier table = engine.getSystemQualifier("TableQualifier_" + attr.getId());
            for (Attribute tAttr : table.getAttributes()) {
                hash.put(toCanonicalValue(attr.getName() + "." + tAttr.getName()), getAttributeEId(attr.getId(), tAttr.getId()));
            }
        }
        hash.put(toCanonicalValue(attr.getName()), getAttributeEId(attr.getId()));
    }
    Eval eval = new Eval(userFunction);
    eval.replaceValueNames(new Replacementable() {

        @Override
        public String getNewName(String oldName) {
            if ("ELEMENT".equals(oldName))
                return oldName;
            String name = hash.get(oldName);
            if (name == null) {
                name = compileValue(null, oldName);
            }
            return name;
        }
    });
    return eval.toString();
}
Also used : Attribute(com.ramussoft.common.Attribute) Hashtable(java.util.Hashtable) AttributeType(com.ramussoft.common.AttributeType) Qualifier(com.ramussoft.common.Qualifier)

Example 53 with Qualifier

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

the class IDEF0ViewPlugin method getProjectPreferences.

@Override
public Preferences[] getProjectPreferences() {
    List<Qualifier> list = IDEF0Plugin.getBaseQualifiers(engine);
    Preferences[] res = new Preferences[((list.size() > 0) ? 1 : 0)];
    final DataPlugin dataPlugin;
    if (list.size() == 0)
        dataPlugin = null;
    else
        dataPlugin = NDataPluginFactory.getDataPlugin(list.get(0), engine, rules);
    if (res.length > 0)
        res[res.length - 1] = new AbstractPreferences() {

            private OwnerClasificators c = new OwnerClasificators(dataPlugin);

            {
                c.updateOuners();
            }

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

            @Override
            public String getTitle() {
                return ResourceLoader.getString("Owners.Clasificators");
            }

            @Override
            public boolean save(JDialog dialog) {
                c.apply();
                return true;
            }
        };
    return res;
}
Also used : AbstractPreferences(com.ramussoft.gui.common.prefrence.AbstractPreferences) Qualifier(com.ramussoft.common.Qualifier) OwnerClasificators(com.ramussoft.pb.frames.setup.OwnerClasificators) Preferences(com.ramussoft.gui.common.prefrence.Preferences) AbstractPreferences(com.ramussoft.gui.common.prefrence.AbstractPreferences) DataPlugin(com.ramussoft.pb.DataPlugin) NDataPlugin(com.ramussoft.pb.data.negine.NDataPlugin) JDialog(javax.swing.JDialog)

Example 54 with Qualifier

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

the class ModelsPanel method canOpen.

public boolean canOpen() {
    RowTreeTable table = tree.getTable();
    final List<OpenDiagram> models = new ArrayList<OpenDiagram>();
    Qualifier modelTree = IDEF0Plugin.getModelTree(engine);
    for (int i : table.getSelectedRows()) {
        if (i >= 0) {
            TreePath path = table.getPathForRow(i);
            if (path != null) {
                TreeTableNode node = (TreeTableNode) path.getLastPathComponent();
                if (node != null) {
                    Row row = node.getRow();
                    if (row != null) {
                        if (row.getElement().getQualifierId() == modelTree.getId()) {
                            Long id = (Long) row.getAttribute(StandardAttributesPlugin.getAttributeQualifierId(engine));
                            if (id != null) {
                                Qualifier model = engine.getQualifier(id);
                                if (model != null) {
                                    OpenDiagram openDiagram = new OpenDiagram(model, -1l);
                                    models.add(openDiagram);
                                }
                            }
                        } else {
                            if (row.getChildCount() <= 0)
                                row = row.getParent();
                            OpenDiagram openDiagram = new OpenDiagram(row.getRowSet().getQualifier(), row.getElementId());
                            models.add(openDiagram);
                        }
                    }
                }
            }
        }
    }
    return models.size() > 0;
}
Also used : TreePath(javax.swing.tree.TreePath) TreeTableNode(com.ramussoft.gui.qualifier.table.TreeTableNode) ArrayList(java.util.ArrayList) Qualifier(com.ramussoft.common.Qualifier) Row(com.ramussoft.database.common.Row) RootRow(com.ramussoft.database.common.RowSet.RootRow) RowTreeTable(com.ramussoft.gui.qualifier.table.RowTreeTable)

Example 55 with Qualifier

use of com.ramussoft.common.Qualifier 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)

Aggregations

Qualifier (com.ramussoft.common.Qualifier)157 Attribute (com.ramussoft.common.Attribute)72 Element (com.ramussoft.common.Element)59 ArrayList (java.util.ArrayList)45 Engine (com.ramussoft.common.Engine)22 Row (com.ramussoft.database.common.Row)17 Row (com.ramussoft.pb.Row)14 List (java.util.List)12 Hashtable (java.util.Hashtable)11 QualifierEvent (com.ramussoft.common.event.QualifierEvent)10 ResultSet (java.sql.ResultSet)9 SQLException (java.sql.SQLException)9 AttributeType (com.ramussoft.common.AttributeType)8 RowSet (com.ramussoft.database.common.RowSet)8 DataPlugin (com.ramussoft.pb.DataPlugin)8 NFunction (com.ramussoft.pb.data.negine.NFunction)8 AttributeEvent (com.ramussoft.common.event.AttributeEvent)7 Journaled (com.ramussoft.common.journal.Journaled)7 RowMapper (com.ramussoft.jdbc.RowMapper)7 IEngine (com.ramussoft.common.IEngine)6