Search in sources :

Example 36 with Attribute

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

the class StandardAttributesPlugin method getElementLists.

public static Attribute[] getElementLists(Engine engine) {
    List<Attribute> list = engine.getAttributes();
    List<Attribute> res = new ArrayList<Attribute>();
    for (Attribute attribute : list) {
        if (attribute.getAttributeType().toString().equals("Core.ElementList")) {
            res.add(attribute);
        }
    }
    return res.toArray(new Attribute[res.size()]);
}
Also used : Attribute(com.ramussoft.common.Attribute) ArrayList(java.util.ArrayList)

Example 37 with Attribute

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

the class OtherElementPlugin method replaceElements.

@Override
public void replaceElements(Engine engine, Element[] oldElements, Element newElement) {
    for (Qualifier qualifier : getAllNotSystemQualifiers(engine)) {
        List<Attribute> attributes = new ArrayList<Attribute>();
        for (Attribute attribute : qualifier.getAttributes()) {
            if ((attribute.getAttributeType().getPluginName().equals(getName())) && (attribute.getAttributeType().getTypeName().equals(getTypeName()))) {
                OtherElementPropertyPersistent p = (OtherElementPropertyPersistent) engine.getAttribute(null, attribute);
                if (p.getQualifier() == newElement.getQualifierId())
                    attributes.add(attribute);
            }
        }
        Hashtable<Element, Object[]> hash = engine.getElements(qualifier, attributes);
        Enumeration<Element> keys = hash.keys();
        while (keys.hasMoreElements()) {
            Element key = keys.nextElement();
            Object[] objects = hash.get(key);
            int aIndex = 0;
            for (Object object : objects) if (object != null) {
                Long l = (Long) object;
                for (Element element : oldElements) {
                    if (element.getId() == l.longValue()) {
                        engine.setAttribute(key, attributes.get(aIndex), newElement.getId());
                        break;
                    }
                }
                aIndex++;
            }
        }
    }
}
Also used : Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList) Qualifier(com.ramussoft.common.Qualifier) FindObject(com.ramussoft.common.attribute.FindObject)

Example 38 with Attribute

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

the class MainFrame method loadData.

private void loadData() {
    data.clear();
    ArrayList<Attribute> attrs = new ArrayList<Attribute>();
    for (Attribute attribute : ATTRIBUTES) attrs.add(attribute);
    // We can use engine.getAttribute(Element, Attribute) method to cat all
    // attributes, but this method works match faster for a set of elements.
    Hashtable<Element, Object[]> hash = engine.getElements(engine.getSystemQualifier(Application.QUALIFIER1), attrs);
    for (Entry<Element, Object[]> entry : hash.entrySet()) {
        data.add(new Row(entry.getKey(), entry.getValue()));
    }
    Collections.sort(data, new Comparator<Row>() {

        @Override
        public int compare(Row o1, Row o2) {
            if (o1.element.getId() < o2.element.getId())
                return -1;
            if (o2.element.getId() < o1.element.getId())
                return 1;
            return 0;
        }
    });
}
Also used : Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList)

Example 39 with Attribute

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

the class OwnersConnection method getConnected.

@Override
public Rows getConnected(final Data data, Row row) {
    Integer type = (Integer) row.getAttribute(IDEF0Plugin.getFunctionTypeAttribute(row.getEngine()));
    if (type != null && type.intValue() == 1003) {
        Long id = (Long) row.getAttribute(IDEF0Plugin.getLinkAttribute(row.getEngine()));
        Rows rows = new Rows(row.getRowSet(), data, false);
        if (id != null) {
            Row row2 = data.findRow(id);
            if (row2 != null) {
                List<AnyToAnyPersistent> list = (List) row2.getAttribute(IDEF0Plugin.getStreamAddedAttribute(row2.getEngine()));
                for (AnyToAnyPersistent anyPersistent : list) {
                    Row row3 = data.findRow(anyPersistent.getOtherElement());
                    row3.setElementStatus(anyPersistent.getElementStatus());
                    rows.add(row3);
                }
            }
        }
        return rows;
    }
    OwnersConnection connection = (OwnersConnection) data.get("OunersConnection");
    if (connection != null)
        return connection.getOuners(data, row);
    final Engine engine = data.getEngine();
    ArrayList<Long> ounerQualifierIds = loadOunerIDs(engine);
    owners = new Hashtable<Row, List<Row>>();
    final Attribute ounerAttribute = IDEF0Plugin.getFunctionOunerAttribute(engine);
    final Hashtable<Row, List<Row>> mech = new Hashtable<Row, List<Row>>();
    RowMapper mapper = new RowMapper() {

        @Override
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            RowSet rowSet = data.getRowSet(rs.getLong(1));
            Row row = (Row) rowSet.findRow(rs.getLong(2));
            if (row == null)
                return null;
            Long o = (Long) row.getAttribute(ounerAttribute);
            if (o != null) {
                Element element = engine.getElement(o);
                if (element != null) {
                    RowSet ounerRowSet = data.getRowSet(element.getQualifierId());
                    Row owner = (Row) ounerRowSet.findRow(o);
                    if (row == null || owner == null)
                        return null;
                    mech.put(row, Arrays.asList(owner));
                }
                return null;
            }
            RowSet ounerRowSet = data.getRowSet(rs.getLong(3));
            Row ouner = (Row) ounerRowSet.findRow(rs.getLong(4));
            if (row == null || ouner == null)
                return null;
            List<Row> l = mech.get(row);
            if (l == null) {
                l = new ArrayList<Row>(2);
                mech.put(row, l);
            }
            if (!l.contains(ouner))
                l.add(ouner);
            return null;
        }
    };
    if (ounerQualifierIds.size() > 0) {
        data.getTemplate().queryWithoutResults("SELECT b.qualifier_id, function, ramus_elements.qualifier_id, ramus_elements.element_id FROM\n" + "ramus_attribute_sector_borders, ramus_attribute_other_elements, ramus_attribute_any_to_any_elements, ramus_elements, ramus_elements b\n" + "WHERE ramus_attribute_any_to_any_elements.element_id=ramus_attribute_other_elements.other_element\n" + "AND ramus_elements.element_id=ramus_attribute_any_to_any_elements.other_element\n" + "AND ramus_attribute_sector_borders.element_id = ramus_attribute_other_elements.element_id\n" + "AND function_type=1 AND ramus_attribute_sector_borders.attribute_id in\n" + "(SELECT attribute_id FROM ramus_attributes WHERE attribute_system=true AND attribute_name='F_SECTOR_BORDER_END')\n" + "AND b.element_id=function\n" + "AND ramus_elements.qualifier_id in " + toIns(ounerQualifierIds), mapper, true);
    }
    try {
        data.getTemplate().queryWithoutResults("SELECT (SELECT qualifier_id FROM ramus_elements WHERE element_id=ouner_id) as function_qualifier_id, " + "ouner_id AS function,  " + "(SELECT qualifier_id FROM ramus_elements WHERE element_id=other_element) as ouner_qualifier_id, " + "other_element as ouner_id FROM ramus_attribute_any_to_any_elements, ramus_attribute_function_ouners " + "WHERE ramus_attribute_any_to_any_elements.element_id IN " + "(SELECT value FROM ramus_attribute_longs WHERE ramus_attribute_longs.element_id=ramus_attribute_function_ouners.element_id)", mapper, true);
    } catch (Exception e) {
        e.printStackTrace();
    }
    data.getTemplate().queryWithoutResults("SELECT ramus_attribute_function_ouners.element_id,\n" + "(SELECT MAX(ramus_elements.qualifier_id) FROM ramus_elements WHERE ramus_elements.element_id=ramus_attribute_function_ouners.element_id),\n" + "ramus_elements.qualifier_id,\n" + " ouner_id FROM ramus_elements, ramus_attribute_function_ouners WHERE ramus_elements.element_id=ouner_id " + "AND ramus_attribute_function_ouners.ouner_id IN (SELECT element_id FROM ramus_attribute_function_types WHERE type<1001)", new RowMapper() {

        @Override
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            RowSet rowSet = data.getRowSet(rs.getLong(2));
            Row row = (Row) rowSet.findRow(rs.getLong(1));
            RowSet ounerRowSet = data.getRowSet(rs.getLong(3));
            Row ouner = (Row) ounerRowSet.findRow(rs.getLong(4));
            if (ouner != null && row != null) {
                List<Row> l = mech.get(row);
                if (l == null) {
                    l = new ArrayList<Row>(2);
                    mech.put(row, l);
                }
                if (!l.contains(ouner))
                    l.add(ouner);
            }
            return null;
        }
    }, true);
    RowSet rowSet = data.getRowSet(row.getQualifier());
    setRecOuners(rowSet.getRoot(), mech, null);
    data.put("OunersConnection", this);
    return getOuners(data, row);
}
Also used : Attribute(com.ramussoft.common.Attribute) SQLException(java.sql.SQLException) Element(com.ramussoft.common.Element) RowSet(com.ramussoft.report.data.RowSet) ArrayList(java.util.ArrayList) AnyToAnyPersistent(com.ramussoft.idef0.attribute.AnyToAnyPersistent) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) Engine(com.ramussoft.common.Engine) Rows(com.ramussoft.report.data.Rows) RowMapper(com.ramussoft.jdbc.RowMapper) Hashtable(java.util.Hashtable) IOException(java.io.IOException) InvalidPropertiesFormatException(java.util.InvalidPropertiesFormatException) SQLException(java.sql.SQLException) DataException(com.ramussoft.report.data.DataException) Row(com.ramussoft.report.data.Row)

Example 40 with Attribute

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

the class TableChartAttributePlugin method getAttributePreferenciesEditor.

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

        private RowTreeTableComponent component;

        @Override
        public JComponent createComponent(Attribute attribute, Engine engine, AccessRules accessRules) {
            component = new RowTreeTableComponent(engine, ChartPlugin.getCharts(engine), accessRules, new RowRootCreater(), new Attribute[] { StandardAttributesPlugin.getAttributeNameAttribute(engine) }, framework);
            component.setSelectType(SelectType.RADIO);
            return component;
        }

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

        @Override
        public void apply(Attribute attribute, Engine engine, AccessRules accessRules) {
            Row row = component.getModel().getSelectedRows().get(0);
            TableChartPersistent tcp = new TableChartPersistent();
            tcp.setOtherElementId(row.getElementId());
            engine.setAttribute(null, attribute, tcp);
        }
    };
}
Also used : Attribute(com.ramussoft.common.Attribute) RowTreeTableComponent(com.ramussoft.gui.qualifier.table.RowTreeTableComponent) AccessRules(com.ramussoft.common.AccessRules) RowRootCreater(com.ramussoft.gui.qualifier.table.RowRootCreater) TableChartPersistent(com.ramussoft.chart.core.TableChartPersistent) Row(com.ramussoft.database.common.Row) AttributePreferenciesEditor(com.ramussoft.gui.common.AttributePreferenciesEditor) Engine(com.ramussoft.common.Engine)

Aggregations

Attribute (com.ramussoft.common.Attribute)203 Qualifier (com.ramussoft.common.Qualifier)72 Element (com.ramussoft.common.Element)70 ArrayList (java.util.ArrayList)53 Engine (com.ramussoft.common.Engine)32 List (java.util.List)20 Row (com.ramussoft.database.common.Row)19 Hashtable (java.util.Hashtable)19 SQLException (java.sql.SQLException)16 AttributeType (com.ramussoft.common.AttributeType)15 FindObject (com.ramussoft.common.attribute.FindObject)11 AttributeEvent (com.ramussoft.common.event.AttributeEvent)11 ResultSet (java.sql.ResultSet)11 AttributePlugin (com.ramussoft.gui.common.AttributePlugin)10 AccessRules (com.ramussoft.common.AccessRules)9 Transaction (com.ramussoft.common.persistent.Transaction)9 HierarchicalPersistent (com.ramussoft.core.attribute.simple.HierarchicalPersistent)9 RowMapper (com.ramussoft.jdbc.RowMapper)9 Row (com.ramussoft.pb.Row)9 ImageIcon (javax.swing.ImageIcon)9