Search in sources :

Example 36 with Element

use of com.ramussoft.common.Element 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 37 with Element

use of com.ramussoft.common.Element 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 38 with Element

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

the class HTTPParser method printReport.

private void printReport(final String string) throws IOException {
    final long num = Long.parseLong(string);
    Element report = null;
    report = dataPlugin.getEngine().getElement(num);
    if (report == null) {
        printError(RES.getString("reportEror"));
        return;
    }
    htmlTitle = report.getName();
    printStartD();
    Query query = null;
    Qualifier qualifier = ((ReportQuery) dataPlugin.getEngine()).getHTMLReportQuery(report);
    if (qualifier != null) {
        query = new Query(null);
        List<Element> elements = new ArrayList<Element>();
        for (Row row : getSelRows(qualifier)) {
            elements.add(row.getElement());
        }
        query.setElements(elements);
    }
    printReport(report, query);
    printEndD();
}
Also used : ReportQuery(com.ramussoft.report.ReportQuery) Query(com.ramussoft.report.Query) ReportQuery(com.ramussoft.report.ReportQuery) Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList) Qualifier(com.ramussoft.common.Qualifier) Row(com.ramussoft.pb.Row) NRow(com.ramussoft.pb.data.negine.NRow)

Example 39 with Element

use of com.ramussoft.common.Element 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 40 with Element

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

Aggregations

Element (com.ramussoft.common.Element)142 Attribute (com.ramussoft.common.Attribute)70 Qualifier (com.ramussoft.common.Qualifier)59 ArrayList (java.util.ArrayList)48 Engine (com.ramussoft.common.Engine)27 SQLException (java.sql.SQLException)14 List (java.util.List)14 Hashtable (java.util.Hashtable)13 Row (com.ramussoft.database.common.Row)12 ElementEvent (com.ramussoft.common.event.ElementEvent)11 HierarchicalPersistent (com.ramussoft.core.attribute.simple.HierarchicalPersistent)11 Eval (com.ramussoft.eval.Eval)9 AttributeEvent (com.ramussoft.common.event.AttributeEvent)8 ElementListPersistent (com.ramussoft.core.attribute.simple.ElementListPersistent)8 Row (com.ramussoft.pb.Row)8 Journaled (com.ramussoft.common.journal.Journaled)7 FunctionPersistent (com.ramussoft.eval.FunctionPersistent)7 Util (com.ramussoft.eval.Util)7 EObject (com.ramussoft.eval.EObject)6 IOException (java.io.IOException)6