Search in sources :

Example 41 with Element

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

Example 42 with Element

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

Example 43 with Element

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

the class IDEF0Plugin method findElementForBaseFunction.

public static Element findElementForBaseFunction(long qualifierId, Engine engine) {
    IDEF0Plugin plugin = (IDEF0Plugin) engine.getPluginProperty(IDEF0, PLUGIN);
    List<Element> list = engine.getElements(plugin.baseFunctions.getId());
    for (Element element : list) {
        if (engine.getAttribute(element, plugin.baseFunctionQualifierId).equals(qualifierId)) {
            return element;
        }
    }
    return null;
}
Also used : Element(com.ramussoft.common.Element)

Example 44 with Element

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

the class IDEF0Plugin method installFunctionAttributes.

public static void installFunctionAttributes(Qualifier qualifier, Engine engine) {
    if (isFunction(qualifier))
        throw new RuntimeException("Qualifier is allready function.");
    IDEF0Plugin plugin = (IDEF0Plugin) engine.getPluginProperty(IDEF0, PLUGIN);
    for (Attribute a : plugin.functionAttributes) {
        qualifier.getSystemAttributes().add(a);
    }
    engine.updateQualifier(qualifier);
    Element e = engine.createElement(plugin.baseFunctions.getId());
    engine.setAttribute(e, plugin.baseFunctionQualifierId, qualifier.getId());
    engine.setAttribute(e, (Attribute) engine.getPluginProperty("Core", HierarchicalPlugin.HIERARHICAL_ATTRIBUTE), new HierarchicalPersistent());
}
Also used : Attribute(com.ramussoft.common.Attribute) HierarchicalPersistent(com.ramussoft.core.attribute.simple.HierarchicalPersistent) Element(com.ramussoft.common.Element)

Example 45 with Element

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

the class AnyToAnyPlugin method updateElements.

private void updateElements(Engine engine, Element stream, List<AnyToAnyPersistent> value, Element[] oldElements, Element newElement, Attribute attribute) {
    boolean add = false;
    for (Element element : oldElements) {
        if (isPresent(value, element)) {
            add = true;
            break;
        }
    }
    if (add) {
        ArrayList<AnyToAnyPersistent> list = new ArrayList<AnyToAnyPersistent>(value.size());
        if (!isPresent(value, newElement)) {
            AnyToAnyPersistent p = new AnyToAnyPersistent();
            p.setOtherElement(newElement.getId());
            list.add(p);
        }
        for (AnyToAnyPersistent p : value) {
            boolean toAdd = true;
            for (Element element : oldElements) {
                if (element.getId() == p.getOtherElement()) {
                    toAdd = false;
                    break;
                }
            }
            if (toAdd)
                list.add(p);
        }
        engine.setAttribute(stream, attribute, list);
    }
}
Also used : Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList)

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