Search in sources :

Example 6 with ElementEvent

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

the class CreateElementCommand method redo.

@Override
public void redo(IEngine iEngine) {
    Element element = iEngine.createElement(qualifierId, elementId);
    ElementEvent event = new ElementEvent(engine, null, element, qualifierId, true);
    engine.elementCreated(event);
}
Also used : Element(com.ramussoft.common.Element) ElementEvent(com.ramussoft.common.event.ElementEvent)

Example 7 with ElementEvent

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

the class ElementListPlugin method init.

@Override
public void init(Engine engine, AccessRules accessor) {
    super.init(engine, accessor);
    if (!StandardAttributesPlugin.isDisableAutoupdate(engine))
        engine.addElementListener(null, new ElementAdapter() {

            @Override
            public void beforeElementDeleted(ElementEvent event) {
                if (event.isJournaled())
                    return;
                long id = event.getQualifierId();
                Qualifier q = event.getEngine().getQualifier(id);
                cleanAttribute(q.getAttributes(), event);
                cleanAttribute(q.getSystemAttributes(), event);
                super.beforeElementDeleted(event);
            }

            private void cleanAttribute(List<Attribute> attributes, ElementEvent event) {
                for (Attribute a : attributes) {
                    if (isMyType(a)) {
                        event.getEngine().setAttribute(event.getOldElement(), a, new ArrayList<Persistent>(0));
                    }
                }
            }
        });
}
Also used : ElementAdapter(com.ramussoft.common.event.ElementAdapter) Attribute(com.ramussoft.common.Attribute) Qualifier(com.ramussoft.common.Qualifier) ArrayList(java.util.ArrayList) List(java.util.List) Persistent(com.ramussoft.common.persistent.Persistent) ElementEvent(com.ramussoft.common.event.ElementEvent)

Example 8 with ElementEvent

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

the class TcpClientEngine method setEngine.

public void setEngine(Engine engine) {
    this.engine = engine;
    engine.addElementListener(null, new ElementAdapter() {

        @Override
        public void elementCreated(ElementEvent event) {
            qualifirsForElements.put(event.getNewElement().getId(), event.getNewElement().getQualifierId());
        }

        @Override
        public void elementDeleted(ElementEvent event) {
            qualifirsForElements.remove(event.getOldElement().getId());
        }
    });
}
Also used : ElementAdapter(com.ramussoft.common.event.ElementAdapter) ElementEvent(com.ramussoft.common.event.ElementEvent)

Example 9 with ElementEvent

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

the class JournaledEngine method setElementQualifier.

@Override
public void setElementQualifier(long elementId, long qualifierId) {
    qualifirsForElements.remove(elementId);
    Element element = getElement(elementId);
    Qualifier current = getQualifier(element.getQualifierId());
    Qualifier newQualifier = getQualifier(qualifierId);
    final List<Attribute> attrs = new ArrayList<Attribute>();
    addNotPresentAttributes(current.getAttributes(), newQualifier.getAttributes(), attrs);
    addNotPresentAttributes(current.getSystemAttributes(), newQualifier.getSystemAttributes(), attrs);
    Transaction[] data = getAttributesWhatWillBeDeleted(elementId, attrs);
    ElementEvent event = new ElementEvent(this, element, new Element(element.getId(), qualifierId, element.getName()), element.getQualifierId());
    beforeElementDeleted(event);
    deligate.setElementQualifier(elementId, qualifierId);
    synchronized (swithJournalLock) {
        journal.store(new SetElementQualifierCommand(this, element.getQualifierId(), qualifierId, elementId, data));
    }
    elementDeleted(event);
    event = new ElementEvent(this, element, new Element(element.getId(), qualifierId, element.getName()), qualifierId);
    qualifirsForElements.remove(element.getId());
    elementCreated(event);
}
Also used : Transaction(com.ramussoft.common.persistent.Transaction) Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList) SetElementQualifierCommand(com.ramussoft.common.journal.command.SetElementQualifierCommand) Qualifier(com.ramussoft.common.Qualifier) ElementEvent(com.ramussoft.common.event.ElementEvent)

Example 10 with ElementEvent

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

the class JournaledEngine method registerCreation.

private Element registerCreation(long qualifierId, Element element) {
    synchronized (swithJournalLock) {
        journal.store(new CreateElementCommand(this, qualifierId, element.getId()));
    }
    ElementEvent event = new ElementEvent(this, null, element, qualifierId);
    elementCreated(event);
    return element;
}
Also used : CreateElementCommand(com.ramussoft.common.journal.command.CreateElementCommand) ElementEvent(com.ramussoft.common.event.ElementEvent)

Aggregations

ElementEvent (com.ramussoft.common.event.ElementEvent)15 Element (com.ramussoft.common.Element)11 Attribute (com.ramussoft.common.Attribute)6 Qualifier (com.ramussoft.common.Qualifier)6 ElementAdapter (com.ramussoft.common.event.ElementAdapter)6 AttributeEvent (com.ramussoft.common.event.AttributeEvent)5 ArrayList (java.util.ArrayList)5 ElementAttributeListener (com.ramussoft.common.event.ElementAttributeListener)3 QualifierAdapter (com.ramussoft.common.event.QualifierAdapter)3 QualifierEvent (com.ramussoft.common.event.QualifierEvent)3 List (java.util.List)3 AttributeType (com.ramussoft.common.AttributeType)2 Engine (com.ramussoft.common.Engine)2 IEngine (com.ramussoft.common.IEngine)2 Transaction (com.ramussoft.common.persistent.Transaction)2 IEngineImpl (com.ramussoft.core.impl.IEngineImpl)2 ActionEvent (com.ramussoft.gui.common.event.ActionEvent)2 ActionListener (com.ramussoft.gui.common.event.ActionListener)2 TabbedEvent (com.ramussoft.gui.common.event.TabbedEvent)2 ViewTitleEvent (com.ramussoft.gui.common.event.ViewTitleEvent)2