Search in sources :

Example 51 with Attribute

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

the class NDataPlugin method getRowSet.

public RowSet getRowSet(final long id) {
    RowSet res = rowSets.get(id);
    if (res == null) {
        final Qualifier qualifier = engine.getQualifier(id);
        boolean create = true;
        if (IDEF0Plugin.isFunction(qualifier)) {
            create = false;
            List<Attribute> list = new ArrayList<Attribute>(qualifier.getSystemAttributes());
            list.addAll(qualifier.getAttributes());
            final Qualifier baseFunctions = IDEF0Plugin.getBaseFunctions(engine);
            res = new RowSet(engine, qualifier, list.toArray(new Attribute[list.size()]), new RowSet.RowCreater() {

                @Override
                public com.ramussoft.database.common.Row createRow(Element element, RowSet data, Attribute[] attributes, Object[] objects) {
                    if (element != null)
                        return new NFunction(NDataPlugin.this, element, data, attributes, objects) {

                            @Override
                            public long getQualifierId() {
                                if (id == baseFunctions.getId()) {
                                    return IDEF0Plugin.getBaseQualifierId(engine, getElement());
                                }
                                return id;
                            }
                        };
                    return new NFunction(NDataPlugin.this, IDEF0Plugin.findElementForBaseFunction(id, engine), data, attributes, objects) {

                        @Override
                        public String getName() {
                            return qualifier.getName();
                        }

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

                        @Override
                        public boolean isElement() {
                            return false;
                        }

                        @Override
                        public long getQualifierId() {
                            return id;
                        }
                    };
                }
            }) {

                @Override
                protected boolean filter(Element element) {
                    return false;
                }
            };
        }
        if (create)
            res = new RowSet(engine, qualifier, qualifier.getAttributes().toArray(new Attribute[qualifier.getAttributes().size()]), new RowSet.RowCreater() {

                @Override
                public com.ramussoft.database.common.Row createRow(Element element, RowSet data, Attribute[] attributes, Object[] objects) {
                    NRow row = new NRow(NDataPlugin.this, element, data, attributes, objects);
                    row.setElement(true);
                    return row;
                }
            });
        rowSets.put(id, res);
    }
    return res;
}
Also used : Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) RowSet(com.ramussoft.database.common.RowSet) ArrayList(java.util.ArrayList) Qualifier(com.ramussoft.common.Qualifier) Row(com.ramussoft.pb.Row)

Example 52 with Attribute

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

the class SectorColorAttributePlugin method getAttributeEditor.

@Override
public AttributeEditor getAttributeEditor(final Engine engine, final AccessRules rules, final Element element, final Attribute attribute, AttributeEditor old) {
    if (old != null)
        old.close();
    return new AbstractAttributeEditor() {

        private PaintSector.Pin pin;

        private JColorChooser component;

        private Color color;

        {
            component = new JColorChooser();
        }

        @Override
        public Object setValue(Object value) {
            this.pin = (PaintSector.Pin) value;
            color = pin.getSector().getColor();
            component.setColor(color);
            return value;
        }

        @Override
        public Object getValue() {
            return pin;
        }

        @Override
        public void apply(Engine engine, Element element, Attribute attribute, Object value) {
            SectorColorAttributePlugin.this.apply(component.getColor(), pin);
        }

        @Override
        public JComponent getComponent() {
            return component;
        }

        @Override
        public boolean isSaveAnyway() {
            return !color.equals(component.getColor());
        }
    };
}
Also used : AbstractAttributeEditor(com.ramussoft.gui.common.AbstractAttributeEditor) Pin(com.ramussoft.pb.idef.elements.PaintSector.Pin) PaintSector(com.ramussoft.pb.idef.elements.PaintSector) Attribute(com.ramussoft.common.Attribute) Color(java.awt.Color) Element(com.ramussoft.common.Element) JColorChooser(javax.swing.JColorChooser) Engine(com.ramussoft.common.Engine)

Example 53 with Attribute

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

the class HTTPParser method printRowAttributes.

private void printRowAttributes(final Row row) throws IOException {
    Element element = row.getElement();
    Qualifier qualifier = dataPlugin.getEngine().getQualifier(element.getQualifierId());
    List<Attribute> attributes = qualifier.getAttributes();
    for (Attribute attr : attributes) {
        if (attr.getId() != qualifier.getAttributeForName()) {
            factory.printAttribute(htmlStream, dataPlugin, element, this, attr);
        }
    }
    IEngine deligate = dataPlugin.getEngine().getDeligate();
    if (deligate instanceof IEngineImpl) {
        final IEngineImpl impl = (IEngineImpl) deligate;
        String prefix = impl.getPrefix();
        JDBCTemplate template = impl.getTemplate();
        List<OtherElementMetadata> list = template.query("SELECT * FROM " + prefix + "attribute_other_elements a WHERE other_element=? AND value_branch_id IN (SELECT branch_id FROM " + prefix + "attributes_data_metadata WHERE attribute_id=a.attribute_id AND element_id=a.element_id)", new RowMapper() {

            private Hashtable<Long, Attribute> attrs = new Hashtable<Long, Attribute>();

            private Hashtable<Long, Qualifier> qualifiers = new Hashtable<Long, Qualifier>();

            @Override
            public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                OtherElementMetadata metadata = new OtherElementMetadata();
                Element element = impl.getElement(rs.getLong("element_id"));
                if (element == null)
                    return null;
                metadata.element = element;
                metadata.qualifier = getQualifier(element.getQualifierId());
                metadata.attribute = getAttribute(rs.getLong("attribute_id"));
                return metadata;
            }

            private Attribute getAttribute(Long id) {
                Attribute attribute = attrs.get(id);
                if (attribute == null) {
                    attribute = dataPlugin.getEngine().getAttribute(id);
                    attrs.put(id, attribute);
                }
                return attribute;
            }

            private Qualifier getQualifier(Long id) {
                Qualifier qualifier = qualifiers.get(id);
                if (qualifier == null) {
                    qualifier = dataPlugin.getEngine().getQualifier(id);
                    qualifiers.put(id, qualifier);
                }
                return qualifier;
            }
        }, new Object[] { row.getElement().getId() }, true);
        boolean print = false;
        for (OtherElementMetadata data : list) if (data.isNotSystem()) {
            print = true;
            break;
        }
        if (print) {
            Collections.sort(list);
            htmlStream.println("<table border=1>");
            htmlStream.println("<tr>");
            htmlStream.print("<td><b>");
            htmlStream.print(RES.getString("clasificator"));
            htmlStream.print("</b></td>");
            htmlStream.print("<td><b>");
            htmlStream.print(RES.getString("rowAttribute"));
            htmlStream.print("</b></td>");
            htmlStream.print("<td><b>");
            htmlStream.print(RES.getString("element"));
            htmlStream.print("</b></td>");
            htmlStream.println("</tr>");
            Hashtable<Qualifier, Element> hash = new Hashtable<Qualifier, Element>();
            for (OtherElementMetadata data : list) if (data.isNotSystem()) {
                Element element2 = hash.get(data.qualifier);
                if (element2 == null) {
                    element2 = StandardAttributesPlugin.getElement(dataPlugin.getEngine(), data.qualifier.getId());
                    hash.put(data.qualifier, element2);
                }
                htmlStream.println("<tr>");
                htmlStream.print("<td>");
                printStartATeg("rows/index.html?id=" + element2.getId());
                htmlStream.print(data.qualifier.getName());
                printEndATeg();
                htmlStream.print("</td>");
                htmlStream.print("<td>");
                htmlStream.print(data.attribute.getName());
                htmlStream.print("</td>");
                htmlStream.print("<td>");
                printStartATeg("rows/index.html?id=" + data.element.getId());
                htmlStream.print(data.element.getName());
                printEndATeg();
                htmlStream.print("</td>");
                htmlStream.println("</tr>");
            }
            htmlStream.println("</table><br>");
        }
    }
}
Also used : Attribute(com.ramussoft.common.Attribute) SQLException(java.sql.SQLException) Hashtable(java.util.Hashtable) Element(com.ramussoft.common.Element) IEngine(com.ramussoft.common.IEngine) IEngineImpl(com.ramussoft.core.impl.IEngineImpl) JDBCTemplate(com.ramussoft.jdbc.JDBCTemplate) ResultSet(java.sql.ResultSet) Qualifier(com.ramussoft.common.Qualifier) RowMapper(com.ramussoft.jdbc.RowMapper)

Example 54 with Attribute

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

the class OtherElementAttributeViewer method printAttribute.

@Override
public void printAttribute(PrintStream printStream, DataPlugin dataPlugin, Element element, Attribute attribute, HTTPParser parser, AttributeViewerCallback callback) throws IOException {
    Engine engine = dataPlugin.getEngine();
    Long id = (Long) engine.getAttribute(element, attribute);
    if (id != null) {
        Element element2 = engine.getElement(id);
        if (element2 != null) {
            OtherElementPropertyPersistent pp = (OtherElementPropertyPersistent) engine.getAttribute(null, attribute);
            Attribute other = engine.getAttribute(pp.getQualifierAttribute());
            if (other != null) {
                callback.beforePrint(printStream);
                printLinkToElement(element2, engine.getAttribute(element2, other), parser, printStream);
                callback.afterPrint(printStream);
            }
        }
    }
}
Also used : Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) Engine(com.ramussoft.common.Engine) OtherElementPropertyPersistent(com.ramussoft.core.attribute.simple.OtherElementPropertyPersistent)

Example 55 with Attribute

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

the class TableAttributeViewer method printAttribute.

@Override
public void printAttribute(PrintStream printStream, DataPlugin dataPlugin, Element element, Attribute attribute, HTTPParser parser, AttributeViewerCallback callback) throws IOException {
    Engine engine = dataPlugin.getEngine();
    List<Element> list = StandardAttributesPlugin.getTableElements(engine, attribute, element);
    Qualifier qualifier = StandardAttributesPlugin.getTableQualifierForAttribute(engine, attribute);
    if (list.size() > 0) {
        callback.beforePrint(printStream);
        printStream.println("<br>");
        printStream.println("<table border=1><tr>");
        List<Attribute> add = new ArrayList<Attribute>();
        List<TableGroupablePropertyPersistent> l = (List) engine.getAttribute(null, attribute);
        for (Attribute attr : qualifier.getAttributes()) if (add.indexOf(attr) < 0) {
            String name = attr.getName();
            int colspan = 1;
            int rowspan = 2;
            for (TableGroupablePropertyPersistent p : l) {
                if ((p.getOtherAttribute() == attr.getId()) && (p.getName() != null) && (p.getName().length() > 0)) {
                    name = p.getName();
                    rowspan = 1;
                    colspan = 0;
                    for (Attribute a1 : qualifier.getAttributes()) for (TableGroupablePropertyPersistent p1 : l) {
                        if ((name.equals(p1.getName())) && (p1.getOtherAttribute() == a1.getId())) {
                            colspan++;
                            add.add(a1);
                        }
                    }
                }
            }
            printStream.print("<td align=\"center\" rowspan=\"" + rowspan + "\" colspan=\"" + colspan + "\"><b>" + name + "</b></td>");
        }
        printStream.println("</tr>");
        printStream.println("<tr>");
        for (Attribute a : add) {
            printStream.print("<td align=\"center\"><b>" + a.getName() + "</b></td>");
        }
        printStream.println("</tr>");
        AttributeViewerFactory factory = AttributeViewerFactory.getAttributeViewverFactory();
        for (Element element2 : list) {
            printStream.println("<tr>");
            for (Attribute attribute2 : qualifier.getAttributes()) {
                printStream.print("<td>");
                AttributeViewer viewer = factory.getAttributeViewer(attribute2);
                if (viewer != null) {
                    EmptyAttributeViewerCallback callback2 = new EmptyAttributeViewerCallback();
                    viewer.printAttribute(printStream, dataPlugin, element2, attribute2, parser, callback2);
                    if (!callback2.isBefore())
                        printStream.print("<center>-</center>");
                } else
                    printStream.print("<center>-</center>");
                printStream.println("</td>");
            }
            printStream.println("</tr>");
        }
        printStream.println("</table>");
        callback.afterPrint(printStream);
    }
}
Also used : Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList) AttributeViewer(com.ramussoft.pb.print.AttributeViewer) Qualifier(com.ramussoft.common.Qualifier) ArrayList(java.util.ArrayList) List(java.util.List) TableGroupablePropertyPersistent(com.ramussoft.core.attribute.simple.TableGroupablePropertyPersistent) 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