Example usage for java.util EventObject getSource

List of usage examples for java.util EventObject getSource

Introduction

In this page you can find the example usage for java.util EventObject getSource.

Prototype

public Object getSource() 

Source Link

Document

The object on which the Event initially occurred.

Usage

From source file:org.polymap.core.model.event.RegexPropertyEventFilter.java

public boolean apply(EventObject ev) {
    Object source = ev.getSource();
    return pattern.matcher(source.getClass().getName()).matches();
}

From source file:org.polymap.core.model.event.SourceClassPropertyEventFilter.java

public boolean apply(EventObject ev) {
    Class<? extends Object> sourceClass = ev.getSource().getClass();
    for (Class cl : allowed) {
        if (!cl.isAssignableFrom(sourceClass)) {
            return false;
        }//from   ww  w . j a  va2 s  . c  o m
    }
    return true;
}

From source file:org.polymap.core.qi4j.event.ModulePropertyEventFilter.java

public boolean apply(EventObject ev) {
    QiEntity entity = (QiEntity) ev.getSource();
    try {//from w  w w  .  j  av  a 2s  .  co  m
        module.findEntity(entity.getCompositeType(), entity.id());
        return true;
    } catch (NoSuchEntityException e) {
        return false;
    }
}

From source file:org.polymap.core.qi4j.QiModule.java

/**
 * //from   w  ww . jav  a 2 s . co m
 */
public void addEntityListener(Object handler, EventFilter... filters) {
    EventManager.instance().subscribe(handler, ObjectArrays.concat(new EventFilter<EventObject>() {
        public boolean apply(EventObject ev) {
            // ModelChangeEvent (dies not have entity as source)
            if (ev instanceof ModelChangeEvent) {
                return true;
            }
            //
            else if (ev instanceof EntityStateEvent) {
                // XXX is there a way to check if entity of this module are changed
                return true;
            }
            // PropertyChangeEvent
            else if (ev.getSource() instanceof QiEntity) {
                QiEntity entity = (QiEntity) ev.getSource();
                try {
                    // check if entity is part of this module
                    findEntity(entity.getCompositeType(), entity.id());
                    return true;
                } catch (UnitOfWorkException e) {
                    return false;
                }
            }
            return false;
        }
    }, filters));
}

From source file:org.polymap.p4.data.importer.ImportsContentProvider.java

@EventHandler(display = true)
protected void contentChanged(EventObject ev) {
    log.debug("Remove cache for: " + ev.getSource().getClass().getSimpleName());
    cache.remove(ev.getSource());//w  w  w. j a  v  a  2 s .c  om

    // new contextIn (root) or prompt (child) -> structural change 
    if (ev instanceof ContextChangeEvent) {
        assert ev.getSource() instanceof ImporterContext;
        viewer.refresh(ev.getSource(), true);

        //deferredSelection = ev.getSource();
    }
    // labels or icon
    else if (ev instanceof ConfigChangeEvent) {
        //  ImporterSite
        if (ev.getSource() instanceof ImporterSite) {
            viewer.update(((ImporterSite) ev.getSource()).context(), null);
        }
        // ImporterPrompt
        else if (ev.getSource() instanceof ImporterPrompt) {
            ImporterPrompt prompt = (ImporterPrompt) ev.getSource();
            viewer.update(prompt, null);
            viewer.update(prompt.context(), null); // status might have changed 
        } else {
            throw new RuntimeException("Unknown source of ConfigChangeEvent: " + ev.getSource());
        }
    } else {
        throw new RuntimeException("Unknown event type: " + ev);
    }
}

From source file:org.polymap.p4.data.imports.ImportsContentProvider.java

@EventHandler(display = true)
protected void contentChanged(EventObject ev) {
    log.info("Remove cache for: " + ev.getSource().getClass().getSimpleName());
    cache.remove(ev.getSource());//from  w  w  w.  j a  va 2 s  . c  o  m

    // new contextIn (root) or prompt (child) -> structural change 
    if (ev instanceof ContextChangeEvent) {
        assert ev.getSource() instanceof ImporterContext;
        viewer.refresh(ev.getSource(), true);

        //deferredSelection = ev.getSource();
    }
    // labels or icon
    else if (ev instanceof ConfigChangeEvent) {
        //  ImporterSite
        if (ev.getSource() instanceof ImporterSite) {
            viewer.update(((ImporterSite) ev.getSource()).context(), null);
        }
        // ImporterPrompt
        else if (ev.getSource() instanceof ImporterPrompt) {
            ImporterPrompt prompt = (ImporterPrompt) ev.getSource();
            viewer.update(prompt, null);
            viewer.update(prompt.context(), null); // status might have changed 
        } else {
            throw new RuntimeException("Unknown source of ConfigChangeEvent: " + ev.getSource());
        }
    } else {
        throw new RuntimeException("Unknown event type: " + ev);
    }
}

From source file:org.wso2.developerstudio.eclipse.ds.presentation.DsEditor.java

/**
 * This sets up the editing domain for the model editor.
 * <!-- begin-user-doc/* w  w  w  .j a  v a 2s. co m*/
 * --> <!-- end-user-doc -->
 * 
 * @generated
 */
protected void initializeEditingDomain() {
    // Create an adapter factory that yields item providers.
    //
    adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);

    adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new DsItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());

    // Create the command stack that will notify this editor as commands are
    // executed.
    //
    BasicCommandStack commandStack = new BasicCommandStack();

    // Add a listener to set the most recent command's affected objects to
    // be the selection of the viewer with focus.
    //
    commandStack.addCommandStackListener(new CommandStackListener() {
        public void commandStackChanged(final EventObject event) {
            getContainer().getDisplay().asyncExec(new Runnable() {
                public void run() {
                    firePropertyChange(IEditorPart.PROP_DIRTY);

                    // Try to select the affected objects.
                    //
                    Command mostRecentCommand = ((CommandStack) event.getSource()).getMostRecentCommand();
                    if (mostRecentCommand != null && mdPage != null && mdPage.getOutLineBlock() != null) {
                        mdPage.getOutLineBlock().setSelectionToViewer(mostRecentCommand.getAffectedObjects());
                    }
                    if (propertySheetPage != null && !propertySheetPage.getControl().isDisposed()) {
                        propertySheetPage.refresh();
                    }
                }
            });
        }
    });

    // Create the editing domain with a special command stack.
    //
    editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack,
            new HashMap<Resource, Boolean>());
}

From source file:org.wso2.developerstudio.eclipse.esb.presentation.EsbEditor.java

/**
 * This sets up the editing domain for the model editor. <!-- begin-user-doc
 * --> <!-- end-user-doc -->//from   w  w  w . j  a  v  a  2s  .  c  om
 */
protected void initializeEditingDomain() {
    // Create an adapter factory that yields item providers.
    //
    adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);

    adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new EsbItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new MediatorsItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());

    // Create the command stack that will notify this editor as commands are
    // executed.
    //
    BasicCommandStack commandStack = new BasicCommandStack();

    // Add a listener to set the most recent command's affected objects to
    // be the selection of the viewer with focus.
    //
    commandStack.addCommandStackListener(new CommandStackListener() {
        public void commandStackChanged(final EventObject event) {
            getContainer().getDisplay().asyncExec(new Runnable() {
                public void run() {
                    firePropertyChange(IEditorPart.PROP_DIRTY);

                    // Try to select the affected objects.
                    //
                    Command mostRecentCommand = ((CommandStack) event.getSource()).getMostRecentCommand();
                    if (mostRecentCommand != null) {
                        setSelectionToViewer(mostRecentCommand.getAffectedObjects());
                    }
                    if (propertySheetPage != null && !propertySheetPage.getControl().isDisposed()) {
                        propertySheetPage.refresh();
                    }
                }
            });
        }
    });

    // Create the editing domain with a special command stack.
    //
    editingDomain = new EsbAdapterFactoryEditingDomain(adapterFactory, commandStack,
            new HashMap<Resource, Boolean>());
}