Search in sources :

Example 1 with AttributeType

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

the class EvalPlugin method init.

@Override
public void init(final Engine engine, AccessRules rules) {
    super.init(engine, rules);
    Qualifier qualifier = StandardAttributesPlugin.getQualifiersQualifier(engine);
    engine.setPluginProperty(getName(), "Plugin", this);
    function = getFunction(qualifier);
    if (function == null) {
        function = engine.createSystemAttribute(new AttributeType(EVAL, "Function", false));
        function.setName(FUNCTION_ATTRIBUTE);
        engine.updateAttribute(function);
        qualifier.getSystemAttributes().add(function);
        engine.updateQualifier(qualifier);
    }
    functionDependences = engine.getSystemQualifier(QUALIFIER_EVAL_FUNCTION_DEPENDENCES);
    if (functionDependences == null) {
        createEvalObjects(engine);
    } else {
        functionDependence = engine.getSystemAttribute(ATTRIBUTE_EVAL_FUNCTION_DEPENDENCE);
        functionDependenceQualifier = engine.getSystemAttribute(ATTRIBUTE_EVAL_DEPENDENCE_QUALIFIER);
        functionDependenceAttribute = engine.getSystemAttribute(ATTRIBUTE_EVAL_DEPENDENCE_ATTRIBUTE);
        functionDependenceSourceAttribute = engine.getSystemAttribute(ATTRIBUTE_EVAL_FUNCTION_DEPENDENCE_SOURCE_ATTRIBUTE);
    }
    if (!StandardAttributesPlugin.isDisableAutoupdate(engine)) {
        final Util util = Util.getUtils(engine);
        util.getScriptHolders().addFunctionsChangeListener(new FunctionsChangeListener() {

            @SuppressWarnings("unchecked")
            @Override
            public void functionsChanged(FunctionsChangeEvent event) {
                IEngine iEngine = engine.getDeligate();
                if ((iEngine != null) && (iEngine instanceof IEngineImpl)) {
                    JDBCTemplate template = ((IEngineImpl) iEngine).getTemplate();
                    String prefix = ((IEngineImpl) iEngine).getPrefix();
                    for (String function : event.getFunctionNames()) {
                        List<FunctionPersistent> list = template.query("SELECT function, qualifier_attribute_id, qualifier_table_attribute_id, autochange, attribute_id, element_id FROM " + prefix + "attribute_functions WHERE function LIKE ? AND autochange=1", new RowMapper() {

                            @Override
                            public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                                FunctionPersistent persistent = new FunctionPersistent(rs.getString(1), rs.getLong(2), rs.getLong(3), rs.getInt(4));
                                persistent.setAttributeId(rs.getLong(5));
                                persistent.setElementId(rs.getLong(6));
                                return persistent;
                            }
                        }, new Object[] { "%" + function + "%" }, true);
                        for (FunctionPersistent fp : list) {
                            recalculateQualifierAttribute(engine, StandardAttributesPlugin.getQualifier(engine, engine.getElement(fp.getElementId())), util, fp);
                        }
                    }
                }
                for (String function : event.getFunctionNames()) {
                    for (CalculateInfo info : engine.findCalculateInfos("%" + function + "%", true)) {
                        recalculate(engine, info);
                    }
                }
            }
        });
        engine.addElementAttributeListener(null, new ElementAttributeListener() {

            @SuppressWarnings("unchecked")
            @Override
            public void attributeChanged(AttributeEvent event) {
                if (event.isJournaled())
                    return;
                if (DISABLE_RECALC)
                    return;
                if (event.getElement() == null) {
                    IEngine d = engine.getDeligate();
                    List<Element> allElements = null;
                    if ((d != null) && (d instanceof IEngineImpl)) {
                        JDBCTemplate template = ((IEngineImpl) d).getTemplate();
                        String prefix = ((IEngineImpl) d).getPrefix();
                        allElements = template.query("SELECT * FROM " + prefix + "elements WHERE qualifier_id in\n" + "(SELECT qualifier_id FROM " + prefix + "qualifiers_attributes WHERE attribute_id=?)", new RowMapper() {

                            @Override
                            public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                                return new Element(rs.getLong("element_id"), rs.getLong("qualifier_id"), rs.getString("element_name"));
                            }
                        }, new Object[] { event.getAttribute().getId() }, true);
                    } else {
                        Attribute attribute = event.getAttribute();
                        allElements = new ArrayList<Element>();
                        for (Qualifier qualifier : engine.getQualifiers()) {
                            if (qualifier.getAttributes().indexOf(attribute) >= 0) {
                                allElements.addAll(engine.getElements(qualifier.getId()));
                            }
                        }
                    }
                    Attribute attribute = event.getAttribute();
                    for (Element element : allElements) {
                        recalculateElement(engine, new AttributeEvent(engine, element, attribute, null, null));
                    }
                } else
                    recalculateElement(engine, event);
            }

            private void recalculateElement(final Engine engine, AttributeEvent event) {
                MetaValue metaValue = new MetaValue(event.getElement().getId(), event.getAttribute().getId());
                List<MetaValue> metaValueList = hashtable.get(Thread.currentThread());
                if (metaValueList == null) {
                    metaValueList = new ArrayList<MetaValue>();
                    hashtable.put(Thread.currentThread(), metaValueList);
                } else {
                    if (metaValueList.indexOf(metaValue) >= 0)
                        return;
                }
                metaValueList.add(metaValue);
                try {
                    for (CalculateInfo info : engine.getDependences(event.getElement().getId(), event.getAttribute().getId(), true)) {
                        recalculate(engine, info);
                    }
                    List<Element> elements = engine.findElements(functionDependences.getId(), functionDependence, event.getElement().getId());
                    for (Element e : elements) {
                        Qualifier qualifier = engine.getQualifier((Long) engine.getAttribute(e, functionDependenceQualifier));
                        Attribute attribute = engine.getAttribute((Long) engine.getAttribute(e, functionDependenceAttribute));
                        if ((qualifier != null) && (attribute != null)) {
                            Element el = StandardAttributesPlugin.getElement(event.getEngine(), qualifier.getId());
                            if (el != null)
                                for (Element child : engine.getElements(qualifier.getId())) {
                                    recalculateInQualifier(engine, Util.elementIdToValue(event.getElement().getId(), event.getAttribute().getId()), null, el, child);
                                }
                        }
                    }
                    Element element = StandardAttributesPlugin.getElement(event.getEngine(), event.getElement().getQualifierId());
                    if (element == null) {
                        Qualifier qualifier = engine.getQualifier(event.getElement().getQualifierId());
                        if (StandardAttributesPlugin.isTableQualifier(qualifier)) {
                            Element parent = StandardAttributesPlugin.getElementForTableElement(engine, event.getElement());
                            if (parent == null)
                                return;
                            Qualifier main = engine.getQualifier(parent.getQualifierId());
                            Attribute tableAttribute = null;
                            for (Attribute attr : main.getAttributes()) {
                                if (StandardAttributesPlugin.getTableQualifeirName(attr).equals(qualifier.getName())) {
                                    tableAttribute = attr;
                                    break;
                                }
                            }
                            if (tableAttribute == null)
                                return;
                            element = StandardAttributesPlugin.getElement(event.getEngine(), parent.getQualifierId());
                            if (element != null) {
                                if (event.getAttribute().equals(StandardAttributesPlugin.getTableElementIdAttribute(engine)))
                                    recalculateInQualifier(engine, null, event.getElement(), element, parent);
                                else
                                    recalculateInQualifier(engine, Util.tableAttributeToValue(tableAttribute.getId(), event.getAttribute().getId()), event.getElement(), element, parent);
                            }
                        }
                        return;
                    }
                    recalculateInQualifier(engine, Util.attributeIdToValue(event.getAttribute().getId()), null, element, event.getElement());
                } finally {
                    metaValueList.remove(metaValueList.size() - 1);
                }
            }
        });
        engine.addElementListener(null, new ElementAdapter() {

            @SuppressWarnings("unchecked")
            @Override
            public void elementCreated(ElementEvent event) {
                if (event.isJournaled())
                    return;
                Element element = StandardAttributesPlugin.getElement(event.getEngine(), event.getNewElement().getQualifierId());
                if (element == null) {
                    return;
                }
                List<FunctionPersistent> list = getFunctionAttribute(engine, element);
                if (list == null)
                    return;
                Util utils = Util.getUtils(engine);
                for (FunctionPersistent fp : list) if (fp.getAutochange() != 0) {
                    Eval eval = new Eval(fp.getFunction());
                    try {
                        utils.fillAttributes(eval, engine.getQualifier(event.getNewElement().getQualifierId()), event.getNewElement(), null, null, null, true);
                        utils.fillResult(fp.getQualifierAttributeId(), eval, event.getNewElement());
                    } catch (Exception e) {
                        utils.fillResult(fp.getQualifierAttributeId(), e, event.getNewElement());
                        if (e instanceof RuntimeException)
                            throw (RuntimeException) e;
                        throw new RuntimeException(e);
                    } finally {
                    }
                }
            }

            @SuppressWarnings("unchecked")
            @Override
            public void beforeElementDeleted(final ElementEvent event) {
                if ((event.isJournaled()) || (event.getNewElement() != null))
                    return;
                Element oldElement = event.getOldElement();
                Qualifier qualifier = engine.getQualifier(oldElement.getQualifierId());
                for (Attribute attribute : qualifier.getAttributes()) {
                    removeAttributeFromCalculateInfo(engine, oldElement, attribute);
                    CalculateInfo info = engine.getCalculateInfo(oldElement.getId(), attribute.getId());
                    if (info != null) {
                        info.setFormula(null);
                        engine.setCalculateInfo(info);
                    }
                }
                List<Element> elements = engine.findElements(functionDependences.getId(), functionDependence, oldElement.getId());
                Vector<Long> qualifiers = new Vector<Long>(elements.size());
                final String start = Util.ELEMENT_PREFIX + oldElement.getId();
                for (Element element : elements) {
                    Long q = (Long) engine.getAttribute(element, functionDependenceQualifier);
                    if (qualifiers.indexOf(q) < 0) {
                        qualifiers.add(q);
                        Element qElement = StandardAttributesPlugin.getElement(engine, q.longValue());
                        List<FunctionPersistent> fpl = (List<FunctionPersistent>) engine.getAttribute(qElement, function);
                        for (FunctionPersistent fp : fpl) {
                            try {
                                Eval eval = new Eval(fp.getFunction());
                                eval.replaceValueNames(new Replacementable() {

                                    @Override
                                    public String getNewName(String oldName) {
                                        if (oldName.startsWith(start))
                                            return "NULL";
                                        return oldName;
                                    }
                                });
                                fp.setFunction(eval.toString());
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                        engine.setAttribute(qElement, function, fpl);
                    }
                // engine.deleteElement(element.getId());
                }
            }
        });
        engine.addQualifierListener(new QualifierAdapter() {

            @SuppressWarnings("unchecked")
            @Override
            public void beforeQualifierUpdated(QualifierEvent event) {
                List<Attribute> rem = new ArrayList<Attribute>();
                for (Attribute a : event.getOldQualifier().getAttributes()) {
                    if (event.getNewQualifier().getAttributes().indexOf(a) < 0)
                        rem.add(a);
                }
                if (rem.size() > 0) {
                    List<Element> list = engine.getElements(event.getOldQualifier().getId());
                    for (Attribute attribute : rem) {
                        for (Element element : list) {
                            removeAttributeFromCalculateInfo(engine, element, attribute);
                            CalculateInfo info = engine.getCalculateInfo(element.getId(), attribute.getId());
                            if (info != null) {
                                info.setFormula(null);
                                engine.setCalculateInfo(info);
                            }
                        }
                        List<Element> elements = engine.findElements(functionDependences.getId(), functionDependenceSourceAttribute, attribute.getId());
                        final String end = Util.ATTRIBUTE_PREFIX + attribute.getId();
                        for (Element element : elements) {
                            Long id = (Long) engine.getAttribute(element, functionDependence);
                            if (engine.getQualifierIdForElement(id) == event.getNewQualifier().getId()) {
                                Long qId = (Long) engine.getAttribute(element, functionDependenceQualifier);
                                Element element2 = StandardAttributesPlugin.getElement(engine, qId);
                                List<FunctionPersistent> fpl = (List<FunctionPersistent>) engine.getAttribute(element2, function);
                                for (FunctionPersistent fp : fpl) {
                                    Eval eval = new Eval(fp.getFunction());
                                    eval.replaceValueNames(new Replacementable() {

                                        @Override
                                        public String getNewName(String oldName) {
                                            if (oldName.endsWith(end)) {
                                                return "NULL";
                                            }
                                            return oldName;
                                        }
                                    });
                                    fp.setFunction(eval.toString());
                                }
                                engine.setAttribute(element2, function, fpl);
                            }
                        }
                    }
                }
            }

            @Override
            public void qualifierDeleted(QualifierEvent event) {
                Qualifier qualifier = event.getOldQualifier();
                for (Element element : engine.findElements(functionDependences.getId(), functionDependenceQualifier, qualifier.getId())) {
                    engine.deleteElement(element.getId());
                }
            }
        });
        Qualifier qq = StandardAttributesPlugin.getQualifiersQualifier(engine);
        engine.addElementAttributeListener(qq, new ElementAttributeListener() {

            @Override
            public void attributeChanged(AttributeEvent event) {
                if (event.isJournaled())
                    return;
                if (function.equals(event.getAttribute())) {
                    recalculateFunctionOfQualifier(engine, event);
                }
            }
        });
        engine.addFormulaListener(new FormulaListener() {

            @Override
            public void formulaChanged(FormulaEvent event) {
                if (event.isJournaled())
                    return;
                CalculateInfo info = event.getNewFormula();
                recalculate(engine, info);
            }
        });
    }
}
Also used : ElementAdapter(com.ramussoft.common.event.ElementAdapter) SQLException(java.sql.SQLException) Attribute(com.ramussoft.common.Attribute) ElementAttributeListener(com.ramussoft.common.event.ElementAttributeListener) Element(com.ramussoft.common.Element) IEngine(com.ramussoft.common.IEngine) ArrayList(java.util.ArrayList) Util(com.ramussoft.eval.Util) QualifierEvent(com.ramussoft.common.event.QualifierEvent) AttributeEvent(com.ramussoft.common.event.AttributeEvent) JDBCTemplate(com.ramussoft.jdbc.JDBCTemplate) AttributeType(com.ramussoft.common.AttributeType) ResultSet(java.sql.ResultSet) Qualifier(com.ramussoft.common.Qualifier) ArrayList(java.util.ArrayList) List(java.util.List) Replacementable(com.ramussoft.eval.Replacementable) FunctionPersistent(com.ramussoft.eval.FunctionPersistent) FormulaEvent(com.ramussoft.common.event.FormulaEvent) Eval(com.ramussoft.eval.Eval) Vector(java.util.Vector) Engine(com.ramussoft.common.Engine) IEngine(com.ramussoft.common.IEngine) RowMapper(com.ramussoft.jdbc.RowMapper) QualifierAdapter(com.ramussoft.common.event.QualifierAdapter) MetaValue(com.ramussoft.eval.MetaValue) ElementEvent(com.ramussoft.common.event.ElementEvent) SQLException(java.sql.SQLException) IEngineImpl(com.ramussoft.core.impl.IEngineImpl) FunctionsChangeListener(com.ramussoft.eval.event.FunctionsChangeListener) FunctionsChangeEvent(com.ramussoft.eval.event.FunctionsChangeEvent) CalculateInfo(com.ramussoft.common.CalculateInfo) FormulaListener(com.ramussoft.common.event.FormulaListener) EObject(com.ramussoft.eval.EObject)

Example 2 with AttributeType

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

the class ChartPlugin method createDouble.

private Attribute createDouble(String attributeName) {
    Attribute attribute = engine.createSystemAttribute(new AttributeType("Core", "Double"));
    attribute.setName(attributeName);
    engine.updateAttribute(attribute);
    return attribute;
}
Also used : Attribute(com.ramussoft.common.Attribute) AttributeType(com.ramussoft.common.AttributeType)

Example 3 with AttributeType

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

the class ChartPlugin method createLong.

private Attribute createLong(String attributeName) {
    Attribute attribute = engine.createSystemAttribute(new AttributeType("Core", "Long"));
    attribute.setName(attributeName);
    engine.updateAttribute(attribute);
    return attribute;
}
Also used : Attribute(com.ramussoft.common.Attribute) AttributeType(com.ramussoft.common.AttributeType)

Example 4 with AttributeType

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

the class AttributePreferenciesDialog method init.

private void init() {
    double[][] size = { { DIV_SPACE, TableLayout.MINIMUM, DIV_SPACE, TableLayout.FILL, DIV_SPACE }, { DIV_SPACE, TableLayout.FILL, DIV_SPACE, TableLayout.FILL, DIV_SPACE } };
    AttributeType[] attributeTypes = engine.getAttributeTypes();
    LocalizedType[] types = new LocalizedType[attributeTypes.length];
    for (int i = 0; i < types.length; i++) {
        AttributeType type = attributeTypes[i];
        AttributePlugin plugin = framework.findAttributePlugin(type);
        types[i] = new LocalizedType(plugin.getString("AttributeType." + type.toString()), type);
    }
    Arrays.sort(types);
    for (LocalizedType type : types) {
        if (type.toString().length() > 0)
            typeComboBox.addItem(type);
    }
    JPanel panel = new JPanel(new TableLayout(size));
    panel.add(new JLabel(getString("AttributeName")), "1, 1");
    panel.add(nameField, "3, 1");
    panel.add(new JLabel(getString("AttributeTypeName")), "1, 3");
    panel.add(typeComboBox, "3, 3");
    typeComboBox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                SwingUtilities.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        updateAdditionalOptions();
                    }
                });
            }
        }
    });
    mainPanel = new JPanel(new BorderLayout());
    contentPanel.add(panel, BorderLayout.NORTH);
    mainPanel.add(contentPanel, BorderLayout.CENTER);
    postInit();
    this.setMainPane(mainPanel);
    pack();
    setLocationRelativeTo(null);
    int x = Options.getInteger("AttributePreferenciesDialog.X", getLocation().x);
    int y = Options.getInteger("AttributePreferenciesDialog.Y", getLocation().y);
    setLocation(x, y);
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            updateAdditionalOptions();
        }
    });
}
Also used : JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) AttributePlugin(com.ramussoft.gui.common.AttributePlugin) JLabel(javax.swing.JLabel) BorderLayout(java.awt.BorderLayout) AttributeType(com.ramussoft.common.AttributeType) ItemListener(java.awt.event.ItemListener) TableLayout(info.clearthought.layout.TableLayout)

Example 5 with AttributeType

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

the class IDEF0Plugin method init.

@Override
public void init(final Engine engine, AccessRules accessor) {
    super.init(engine, accessor);
    engine.setPluginProperty(IDEF0, PLUGIN, this);
    Qualifier crosspoints = getQualifier(CROSSPOINTS);
    if (crosspoints != null) {
        List<Element> elements = engine.getElements(crosspoints.getId());
        Attribute crosspointId = getSysteAttribute(CROSSPOINT_ID_ATTRIBUTE);
        if (elements.size() > 0) {
            Element element = elements.get(0);
            try {
                long long1 = (Long) engine.getAttribute(element, crosspointId);
                while ((long1 > engine.nextValue(CROSSPOINTS_SEQUENCE))) ;
            } catch (NullPointerException e) {
            }
            engine.deleteElement(element.getId());
        }
        crosspoints.getSystemAttributes().clear();
        engine.updateQualifier(crosspoints);
        try {
            engine.deleteAttribute(crosspointId.getId());
        } catch (Exception e) {
        }
        engine.deleteQualifier(crosspoints.getId());
    }
    functionAttributes.add(createAttribute(F_VISUAL_DATA, new AttributeType(IDEF0, "VisualData", false)));
    functionAttributes.add(createAttribute(F_PAGE_SIZE, new AttributeType("Core", "Text", true)));
    functionAttributes.add(createAttribute(F_BACKGROUND, new AttributeType(IDEF0, "Color", false)));
    functionAttributes.add(createAttribute(F_FOREGROUND, new AttributeType(IDEF0, "Color", false)));
    functionAttributes.add(createAttribute(F_BOUNDS, new AttributeType(IDEF0, "FRectangle", false)));
    functionAttributes.add(createAttribute(F_FONT, new AttributeType(IDEF0, "Font", false)));
    functionAttributes.add(createAttribute(F_STATUS, new AttributeType(IDEF0, "Status", false)));
    functionAttributes.add(createAttribute(F_TYPE, new AttributeType(IDEF0, "Type", false)));
    functionAttributes.add(createAttribute(F_OUNER_ID, new AttributeType(IDEF0, "OunerId", false)));
    functionAttributes.add(createAttribute(F_DECOMPOSITION_TYPE, new AttributeType(IDEF0, "DecompositionType", false)));
    functionAttributes.add(createAttribute(F_AUTHOR, new AttributeType("Core", "Text", true)));
    functionAttributes.add(createAttribute(F_CREATE_DATE, new AttributeType("Core", "Date", false)));
    functionAttributes.add(createAttribute(F_REV_DATE, new AttributeType("Core", "Date", false)));
    functionAttributes.add(createAttribute(F_SYSTEM_REV_DATE, new AttributeType("Core", "Date", false)));
    functionAttributes.add(createAttribute(F_LINK, new AttributeType("Core", "Long", false)));
    Attribute sectorFunction = createAttribute(F_SECTOR_FUNCTION, new AttributeType("Core", "OtherElement", false));
    Attribute sStream = createAttribute(F_SECTOR_STREAM, new AttributeType("Core", "OtherElement", false));
    Attribute sPoints = createAttribute(F_SECTOR_POINTS, new AttributeType(IDEF0, "SectorPoint", false));
    Attribute sProperties = createAttribute(F_SECTOR_PROPERTIES, new AttributeType(IDEF0, "SectorProperties", false));
    Attribute sStreamName = createAttribute(F_STREAM_NAME, new AttributeType("Core", "Text", true));
    Attribute aSector = createAttribute(F_SECTOR_ATTRIBUTE, new AttributeType(IDEF0, "Sector", false));
    Attribute aSectorBorderStart = createAttribute(F_SECTOR_BORDER_START, new AttributeType(IDEF0, "SectorBorder", false));
    Attribute aSectorBorderEnd = createAttribute(F_SECTOR_BORDER_END, new AttributeType(IDEF0, "SectorBorder", false));
    Attribute aStreamAdded = createAttribute(F_STREAM_ADDED, new AttributeType(IDEF0, "AnyToAny", false));
    baseFunctionQualifierId = createAttribute(F_BASE_FUNCTION_QUALIFIER_ID, new AttributeType("Core", "Long", true));
    visualAttributes.add(getAttribute(engine, F_BOUNDS));
    visualAttributes.add(getAttribute(engine, F_FONT));
    visualAttributes.add(getAttribute(engine, F_BACKGROUND));
    visualAttributes.add(getAttribute(engine, F_FOREGROUND));
    Qualifier sectors = createQualifier(F_SECTORS);
    if (justCreated) {
        sectors.getSystemAttributes().add(aSector);
        sectors.getSystemAttributes().add(aSectorBorderStart);
        sectors.getSystemAttributes().add(aSectorBorderEnd);
        sectors.getSystemAttributes().add(sectorFunction);
    }
    Qualifier streams = createQualifier(F_STREAMS);
    boolean updateSectors = false;
    if (justCreated) {
        Attribute hierarchical = (Attribute) engine.getPluginProperty("Core", HierarchicalPlugin.HIERARHICAL_ATTRIBUTE);
        OtherElementPropertyPersistent p = new OtherElementPropertyPersistent();
        p.setQualifier(sectors.getId());
        p.setQualifierAttribute(sStreamName.getId());
        engine.setAttribute(null, sStream, p);
        streams.getSystemAttributes().add(aStreamAdded);
        streams.getSystemAttributes().add(hierarchical);
        streams.getSystemAttributes().add(sStreamName);
        streams.setAttributeForName(sStreamName.getId());
        engine.updateQualifier(streams);
        sectors.getSystemAttributes().add(0, sStream);
        sectors.getSystemAttributes().add(hierarchical);
        updateSectors = true;
    }
    if (sectors.getSystemAttributes().indexOf(sStream) != 0) {
        sectors.getSystemAttributes().remove(sStream);
        sectors.getSystemAttributes().add(0, sStream);
        updateSectors = true;
    }
    if (sectors.getSystemAttributes().indexOf(sPoints) < 0) {
        sectors.getSystemAttributes().add(sPoints);
        sectors.getSystemAttributes().add(sProperties);
        updateSectors = true;
    }
    if (updateSectors)
        engine.updateQualifier(sectors);
    projectPreferencesAttrtibute = createAttribute(F_PROJECT_PREFERENCES, new AttributeType(IDEF0, "ProjectPreferences", false));
    baseFunctions = createQualifier(F_BASE_FUNCTIONS);
    if (justCreated) {
        baseFunctions.getSystemAttributes().add(baseFunctionQualifierId);
        baseFunctions.getSystemAttributes().add((Attribute) engine.getPluginProperty("Core", HierarchicalPlugin.HIERARHICAL_ATTRIBUTE));
        baseFunctions.getSystemAttributes().add(projectPreferencesAttrtibute);
        engine.updateQualifier(baseFunctions);
        installFunctionAttributes(baseFunctions, engine);
    } else {
        if (baseFunctions.getSystemAttributes().indexOf(projectPreferencesAttrtibute) < 0) {
            baseFunctions.getSystemAttributes().add(projectPreferencesAttrtibute);
            engine.updateQualifier(baseFunctions);
        }
        checkIDEF0Attributes(engine, baseFunctions);
    }
    Qualifier modelTree = createQualifier(F_MODEL_TREE);
    final Attribute name = StandardAttributesPlugin.getAttributeNameAttribute(engine);
    if (justCreated) {
        modelTree.getSystemAttributes().add((Attribute) engine.getPluginProperty("Core", HierarchicalPlugin.HIERARHICAL_ATTRIBUTE));
        modelTree.getSystemAttributes().add(StandardAttributesPlugin.getAttributeQualifierId(engine));
        modelTree.getAttributes().add(name);
        modelTree.setAttributeForName(name.getId());
        engine.updateQualifier(modelTree);
        checkModelTree(modelTree);
    }
    if (!StandardAttributesPlugin.isDisableAutoupdate(engine)) {
        engine.addElementAttributeListener(modelTree, new ElementAttributeListener() {

            @Override
            public void attributeChanged(AttributeEvent event) {
                if (event.isJournaled())
                    return;
                if (name.equals(event.getAttribute())) {
                    Long id = (Long) engine.getAttribute(event.getElement(), StandardAttributesPlugin.getAttributeQualifierId(engine));
                    if (id != null) {
                        Qualifier model = engine.getQualifier(id);
                        if (model != null) {
                            model.setName(String.valueOf(event.getNewValue()));
                            engine.updateQualifier(model);
                        }
                    }
                }
            }
        });
    }
}
Also used : Attribute(com.ramussoft.common.Attribute) ElementAttributeListener(com.ramussoft.common.event.ElementAttributeListener) Element(com.ramussoft.common.Element) AttributeEvent(com.ramussoft.common.event.AttributeEvent) OtherElementPropertyPersistent(com.ramussoft.core.attribute.simple.OtherElementPropertyPersistent) AttributeType(com.ramussoft.common.AttributeType) Qualifier(com.ramussoft.common.Qualifier)

Aggregations

AttributeType (com.ramussoft.common.AttributeType)20 Attribute (com.ramussoft.common.Attribute)15 Qualifier (com.ramussoft.common.Qualifier)8 Element (com.ramussoft.common.Element)5 AttributePlugin (com.ramussoft.gui.common.AttributePlugin)4 AttributeEvent (com.ramussoft.common.event.AttributeEvent)3 ElementAttributeListener (com.ramussoft.common.event.ElementAttributeListener)3 QualifierAdapter (com.ramussoft.common.event.QualifierAdapter)3 QualifierEvent (com.ramussoft.common.event.QualifierEvent)3 Journaled (com.ramussoft.common.journal.Journaled)3 HierarchicalPersistent (com.ramussoft.core.attribute.simple.HierarchicalPersistent)3 ArrayList (java.util.ArrayList)3 Hashtable (java.util.Hashtable)3 Engine (com.ramussoft.common.Engine)2 IEngine (com.ramussoft.common.IEngine)2 ElementAdapter (com.ramussoft.common.event.ElementAdapter)2 ElementEvent (com.ramussoft.common.event.ElementEvent)2 IEngineImpl (com.ramussoft.core.impl.IEngineImpl)2 JDBCTemplate (com.ramussoft.jdbc.JDBCTemplate)2 RowMapper (com.ramussoft.jdbc.RowMapper)2