Search in sources :

Example 6 with ElementListPropertyPersistent

use of com.ramussoft.core.attribute.simple.ElementListPropertyPersistent in project ramus by Vitaliy-Yakovchuk.

the class ElementListPreferenciesEditor method apply.

@Override
public void apply(Attribute attribute, Engine engine, AccessRules accessRules) {
    ElementListPropertyPersistent p = new ElementListPropertyPersistent();
    p.setQualifier1(((Qualifier) box1.getSelectedItem()).getId());
    p.setQualifier2(((Qualifier) box2.getSelectedItem()).getId());
    p.setConnectionTypes(variantsArea.getText());
    engine.setAttribute(null, attribute, p);
}
Also used : ElementListPropertyPersistent(com.ramussoft.core.attribute.simple.ElementListPropertyPersistent)

Example 7 with ElementListPropertyPersistent

use of com.ramussoft.core.attribute.simple.ElementListPropertyPersistent in project ramus by Vitaliy-Yakovchuk.

the class HTTPParser method printMatrixProjection.

private void printMatrixProjection() throws IOException {
    final String sId = (String) params.get("matrixid");
    if (sId == null) {
        printMatrixError();
        return;
    }
    final Long id = Long.parseLong(sId);
    if (id == null) {
        printMatrixError();
        return;
    }
    Engine engine = dataPlugin.getEngine();
    Attribute mp = engine.getAttribute(id);
    if (mp == null) {
        printMatrixError();
        return;
    }
    htmlTitle = RES.getString("matrixProjection") + " " + mp.getName();
    printStartD();
    boolean rotate = "true".equals(params.get("rotate"));
    htmlStream.print("<center><h2 class=\"Ramus\">" + RES.getString("matrixProjection") + ": " + mp.getName() + "</h2></center>");
    htmlStream.println("<table width=100%>");
    htmlStream.println("<tr>");
    htmlStream.println("<td  valign=top align=center width=50%>");
    ElementListPropertyPersistent pp = (ElementListPropertyPersistent) engine.getAttribute(null, mp);
    Qualifier qualifier1 = engine.getQualifier(pp.getQualifier1());
    Qualifier qualifier2 = engine.getQualifier(pp.getQualifier2());
    if (rotate) {
        Qualifier tmp = qualifier1;
        qualifier1 = qualifier2;
        qualifier2 = tmp;
    }
    htmlStream.println("<table border=1 width=100%>");
    List<Row> rows = (List) dataPlugin.getRowSet(qualifier1.getId()).getAllRows();
    printMainTableTitle(qualifier1.getName());
    final Row leftRow = loadRowById();
    for (int i = 0; i < rows.size(); i++) {
        final Row row = (Row) rows.get(i);
        final boolean gray = i % 2 == 0;
        String sGray = "";
        String bs = "";
        String be = "";
        if (row.equals(leftRow)) {
            bs = "<i>";
            be = "</i>";
        }
        if (gray)
            sGray = " bgcolor=" + GRAY;
        String href = "matrixprojections/index.html?id=" + row.getGlobalId().toString() + "&matrixid=" + sId + (rotate ? "&rotate=true" : "");
        htmlStream.print("<tr>");
        htmlStream.print("<td" + sGray + ">");
        printStartATeg("rows/index.html?id=" + row.getElement().getId());
        htmlStream.print("^");
        printEndATeg();
        printStartATeg(href);
        htmlStream.print(bs);
        printRowKod(row, false, IDEF0Plugin.isFunction(qualifier1));
        htmlStream.print(be);
        if (href != null)
            printEndATeg();
        htmlStream.print("</td>");
        htmlStream.print("<td" + sGray + ">");
        printStartATeg(href);
        htmlStream.print(bs);
        printRowName(row, false);
        htmlStream.print(be);
        if (href != null)
            printEndATeg();
        htmlStream.print("</td>");
        htmlStream.println("</tr>");
    }
    htmlStream.println("</table>");
    htmlStream.println("</td>");
    htmlStream.println("<td valign=top align=center width=50%>");
    final String row2Name = qualifier2.getName() + " (" + RES.getString("addedElements") + (leftRow == null ? "" : " " + leftRow.getKod() + ". " + leftRow.getName()) + ")";
    if (leftRow != null) {
        List<ElementListPersistent> left = (List<ElementListPersistent>) engine.getAttribute(leftRow.getElement(), mp);
        final Vector v = new Vector();
        for (ElementListPersistent p : left) {
            if (rotate) {
                v.add(dataPlugin.findRowByGlobalId(p.getElement1Id()));
            } else {
                v.add(dataPlugin.findRowByGlobalId(p.getElement2Id()));
            }
        }
        printElements(row2Name, v.toArray(), null);
    } else {
        htmlStream.println("<table width=100%>");
        htmlStream.println("<caption>");
        printSmallTitle(row2Name);
        htmlStream.println("</caption>");
        htmlStream.println("</table>");
    }
    htmlStream.println("</td>");
    htmlStream.println("</tr>");
    htmlStream.println("</table>");
    String href = "matrixprojections/index.html?matrixid=" + sId;
    if (!rotate)
        href += "&rotate=" + "true";
    htmlStream.println("<p align=right>");
    printStartATeg(href);
    htmlStream.println(RES.getString("rotate"));
    printEndATeg();
    htmlStream.println("</p>");
    printEndD();
}
Also used : ElementListPersistent(com.ramussoft.core.attribute.simple.ElementListPersistent) Attribute(com.ramussoft.common.Attribute) ElementListPropertyPersistent(com.ramussoft.core.attribute.simple.ElementListPropertyPersistent) Qualifier(com.ramussoft.common.Qualifier) List(java.util.List) ArrayList(java.util.ArrayList) Row(com.ramussoft.pb.Row) NRow(com.ramussoft.pb.data.negine.NRow) Vector(java.util.Vector) IEngine(com.ramussoft.common.IEngine) Engine(com.ramussoft.common.Engine)

Example 8 with ElementListPropertyPersistent

use of com.ramussoft.core.attribute.simple.ElementListPropertyPersistent in project ramus by Vitaliy-Yakovchuk.

the class ElementListAttributeViewer method printAttribute.

@Override
public void printAttribute(PrintStream printStream, DataPlugin dataPlugin, Element element, Attribute attribute, HTTPParser parser, AttributeViewerCallback callback) throws IOException {
    Engine engine = dataPlugin.getEngine();
    Qualifier qualifier = engine.getQualifier(element.getQualifierId());
    List<ElementListPersistent> list = (List<ElementListPersistent>) engine.getAttribute(element, attribute);
    ElementListPropertyPersistent pp = (ElementListPropertyPersistent) engine.getAttribute(null, attribute);
    boolean left = qualifier.getId() == pp.getQualifier2();
    if (list.size() > 0) {
        callback.beforePrint(printStream);
        printStream.println("<br>");
        for (ElementListPersistent p : list) {
            long id;
            if (left)
                id = p.getElement1Id();
            else
                id = p.getElement2Id();
            Element element2 = engine.getElement(id);
            if (element2 != null) {
                printLinkToElement(element2, parser, printStream);
                printStream.println("<br>");
            }
        }
        callback.afterPrint(printStream);
    }
}
Also used : ElementListPersistent(com.ramussoft.core.attribute.simple.ElementListPersistent) Element(com.ramussoft.common.Element) ElementListPropertyPersistent(com.ramussoft.core.attribute.simple.ElementListPropertyPersistent) Qualifier(com.ramussoft.common.Qualifier) List(java.util.List) Engine(com.ramussoft.common.Engine)

Example 9 with ElementListPropertyPersistent

use of com.ramussoft.core.attribute.simple.ElementListPropertyPersistent in project ramus by Vitaliy-Yakovchuk.

the class ElistTabView method createComponent.

@Override
public JComponent createComponent() {
    final Engine engine = framework.getEngine();
    AccessRules rules = framework.getAccessRules();
    ElementListPropertyPersistent p = (ElementListPropertyPersistent) engine.getAttribute(null, elementList);
    boolean addListener = q1 == null;
    q1 = engine.getQualifier(p.getQualifier1());
    q2 = engine.getQualifier(p.getQualifier2());
    readOnly = !((rules.canUpdateAttribute(q1.getId(), elementList.getId())) && (rules.canUpdateAttribute(q2.getId(), elementList.getId())));
    if (addListener) {
        engine.addElementAttributeListener(q1, leftAttributeListener);
        engine.addElementAttributeListener(q2, rightAttributeListener);
    }
    left = new ElistPanel(framework, engine, rules, q1, elementList) {

        @Override
        public String getPropertiesPrefix() {
            return "left" + elementList.getId();
        }

        @Override
        public void changeSelection(SelectionEvent event) {
            ElistTabView.this.changeSelection(this, event);
        }

        @Override
        public JComponent createComponent() {
            unique = null;
            if (getComponent() != null) {
                left.clearSelection();
                left.setSelectType(SelectType.RADIO);
                right.clearSelection();
                right.setSelectType(SelectType.RADIO);
            }
            JComponent component2 = super.createComponent();
            getComponent().getPane().getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {

                @Override
                public void adjustmentValueChanged(AdjustmentEvent e) {
                    comp.repaint();
                }
            });
            getComponent().getTable().getModel().addTableModelListener(modelListener);
            getComponent().getTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {

                @SuppressWarnings("unchecked")
                @Override
                public void valueChanged(ListSelectionEvent e) {
                    TreeTableNode node = left.getComponent().getTable().getSelectedNode();
                    if ((node != null) && (node.getRow() != null)) {
                        leftElement = node.getRow().getElement();
                        leftValue = (List<ElementListPersistent>) engine.getAttribute(leftElement, elementList);
                        if (unique == null)
                            rightValue = null;
                    } else
                        leftValue = null;
                    comp.repaint();
                }
            });
            return component2;
        }

        @Override
        public void setSelectType(SelectType selectType) {
            if ((!readOnly) || (selectType.equals(SelectType.NONE)))
                super.setSelectType(selectType);
        }
    };
    right = new ElistPanel(framework, engine, rules, q2, elementList) {

        @Override
        public String getPropertiesPrefix() {
            return "right" + elementList.getId();
        }

        @Override
        public void changeSelection(SelectionEvent event) {
            ElistTabView.this.changeSelection(this, event);
        }

        @Override
        public JComponent createComponent() {
            unique = null;
            if (getComponent() != null) {
                left.clearSelection();
                left.setSelectType(SelectType.RADIO);
                right.clearSelection();
                right.setSelectType(SelectType.RADIO);
            }
            JComponent component2 = super.createComponent();
            getComponent().getPane().getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {

                @Override
                public void adjustmentValueChanged(AdjustmentEvent e) {
                    comp.repaint();
                }
            });
            getComponent().getTable().getModel().addTableModelListener(modelListener);
            getComponent().getTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {

                @SuppressWarnings("unchecked")
                @Override
                public void valueChanged(ListSelectionEvent e) {
                    TreeTableNode node = right.getComponent().getTable().getSelectedNode();
                    if ((node != null) && (node.getRow() != null)) {
                        rightElement = node.getRow().getElement();
                        rightValue = (List<ElementListPersistent>) engine.getAttribute(rightElement, elementList);
                        if (unique == null)
                            leftValue = null;
                    } else
                        rightValue = null;
                    comp.repaint();
                }
            });
            return component2;
        }

        @Override
        public void setSelectType(SelectType selectType) {
            if ((!readOnly) || (selectType.equals(SelectType.NONE)))
                super.setSelectType(selectType);
        }
    };
    JSplitPane pane1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    pane1.setRightComponent(rightContainer);
    comp.setBackground(Color.white);
    pane1.setLeftComponent(comp);
    JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    pane.setLeftComponent(leftContainer);
    Properties properties = engine.getProperties(getProperiesName());
    revert = Options.getBoolean("REVERT", false, properties);
    revertAction.putValue(Action.SELECTED_KEY, revert);
    addPanels();
    JPanel panel = new JPanel(new BorderLayout());
    panel.add(pane1, BorderLayout.CENTER);
    pane.setRightComponent(panel);
    component = new JPanel(new BorderLayout());
    component.add(pane, BorderLayout.CENTER);
    Options.loadOptions(component, properties);
    if (readOnly) {
        left.setSelectType(SelectType.NONE);
        right.setSelectType(SelectType.NONE);
    }
    return component;
}
Also used : JPanel(javax.swing.JPanel) TreeTableNode(com.ramussoft.gui.qualifier.table.TreeTableNode) ElementListPersistent(com.ramussoft.core.attribute.simple.ElementListPersistent) AdjustmentEvent(java.awt.event.AdjustmentEvent) ElementListPropertyPersistent(com.ramussoft.core.attribute.simple.ElementListPropertyPersistent) JComponent(javax.swing.JComponent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) SelectType(com.ramussoft.gui.qualifier.table.SelectType) Properties(java.util.Properties) ListSelectionListener(javax.swing.event.ListSelectionListener) BorderLayout(java.awt.BorderLayout) SelectionEvent(com.ramussoft.gui.qualifier.table.event.SelectionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) AdjustmentListener(java.awt.event.AdjustmentListener) AccessRules(com.ramussoft.common.AccessRules) JSplitPane(javax.swing.JSplitPane) Engine(com.ramussoft.common.Engine)

Example 10 with ElementListPropertyPersistent

use of com.ramussoft.core.attribute.simple.ElementListPropertyPersistent in project ramus by Vitaliy-Yakovchuk.

the class ElementListPlugin method createSyncAttribute.

@Override
public Attribute createSyncAttribute(Engine engine, QualifierImporter importer, Attribute sourceAttribute) {
    ElementListPropertyPersistent pp = (ElementListPropertyPersistent) importer.getSourceValue(null, sourceAttribute);
    if (pp == null)
        return null;
    Qualifier left = null;
    Qualifier right = null;
    for (Qualifier q : importer.getSourceQualifiers()) {
        if (q.getId() == pp.getQualifier1())
            left = q;
        if (q.getId() == pp.getQualifier2())
            right = q;
    }
    if ((left != null) && (right != null)) {
        Qualifier qualifier1 = importer.getDestination(left);
        Qualifier qualifier2 = importer.getDestination(right);
        Attribute result = null;
        List<Attribute> attributes = engine.getAttributes();
        for (Attribute attr : attributes) {
            if (isSameAttribute(sourceAttribute, attr)) {
                ElementListPropertyPersistent dpp = (ElementListPropertyPersistent) engine.getAttribute(null, attr);
                if ((dpp != null) && (dpp.getQualifier1() == qualifier1.getId()) && (dpp.getQualifier2() == qualifier2.getId())) {
                    result = attr;
                    break;
                }
            }
        }
        if (result != null)
            return result;
        result = engine.createAttribute(sourceAttribute.getAttributeType());
        result.setName(sourceAttribute.getName());
        engine.updateAttribute(result);
        ElementListPropertyPersistent dpp = new ElementListPropertyPersistent();
        dpp.setQualifier1(qualifier1.getId());
        dpp.setQualifier2(qualifier2.getId());
        engine.setAttribute(null, result, dpp);
    }
    return null;
}
Also used : Attribute(com.ramussoft.common.Attribute) ElementListPropertyPersistent(com.ramussoft.core.attribute.simple.ElementListPropertyPersistent) Qualifier(com.ramussoft.common.Qualifier)

Aggregations

ElementListPropertyPersistent (com.ramussoft.core.attribute.simple.ElementListPropertyPersistent)12 Attribute (com.ramussoft.common.Attribute)6 Qualifier (com.ramussoft.common.Qualifier)6 Engine (com.ramussoft.common.Engine)4 ElementListPersistent (com.ramussoft.core.attribute.simple.ElementListPersistent)3 List (java.util.List)3 BorderLayout (java.awt.BorderLayout)2 JPanel (javax.swing.JPanel)2 AccessRules (com.ramussoft.common.AccessRules)1 AttributeType (com.ramussoft.common.AttributeType)1 Element (com.ramussoft.common.Element)1 IEngine (com.ramussoft.common.IEngine)1 SelectType (com.ramussoft.gui.qualifier.table.SelectType)1 TreeTableNode (com.ramussoft.gui.qualifier.table.TreeTableNode)1 SelectionEvent (com.ramussoft.gui.qualifier.table.event.SelectionEvent)1 Row (com.ramussoft.pb.Row)1 NRow (com.ramussoft.pb.data.negine.NRow)1 TableLayout (info.clearthought.layout.TableLayout)1 AdjustmentEvent (java.awt.event.AdjustmentEvent)1 AdjustmentListener (java.awt.event.AdjustmentListener)1