Search in sources :

Example 6 with ListenerList

use of org.eclipse.core.runtime.ListenerList in project liferay-ide by liferay.

the class LiferayPropertiesFileDescriber method describe.

public int describe(Reader contents, IContentDescription description) throws IOException {
    try {
        Class<?> contentClass = contents.getClass();
        Field documentReaderField = contentClass.getDeclaredField("in");
        documentReaderField.setAccessible(true);
        Object documentReader = documentReaderField.get(contents);
        Class<?> documentReaderClass = documentReader.getClass();
        Field fDocumentField = documentReaderClass.getDeclaredField("fDocument");
        fDocumentField.setAccessible(true);
        Object fDocument = fDocumentField.get(documentReader);
        Class<?> documentClass = fDocument.getClass();
        Class<?> clazz = documentClass.getSuperclass();
        Field fDocumentListenersField = clazz.getSuperclass().getDeclaredField("fDocumentListeners");
        fDocumentListenersField.setAccessible(true);
        ListenerList fDocumentListeners = (ListenerList) fDocumentListenersField.get(fDocument);
        Object[] listeners = fDocumentListeners.getListeners();
        for (Object listener : listeners) {
            try {
                Class<?> listenerClass = listener.getClass();
                Class<?> superClass = listenerClass.getEnclosingClass().getSuperclass();
                Field fFileField = superClass.getDeclaredField("fFile");
                fFileField.setAccessible(true);
                // get enclosing instance of listener
                Field thisField = listenerClass.getDeclaredField("this$0");
                thisField.setAccessible(true);
                Object enclosingObject = thisField.get(listener);
                Object fFile = fFileField.get(enclosingObject);
                if (fFile instanceof IFile) {
                    IFile file = (IFile) fFile;
                    if (isPropertiesFile(file)) {
                        return VALID;
                    }
                }
            } catch (Exception e) {
            }
        }
    } catch (Exception e) {
    // ignore errors
    }
    return INVALID;
}
Also used : ListenerList(org.eclipse.core.runtime.ListenerList) Field(java.lang.reflect.Field) IFile(org.eclipse.core.resources.IFile) IOException(java.io.IOException)

Example 7 with ListenerList

use of org.eclipse.core.runtime.ListenerList in project mdw-designer by CenturyLinkCloud.

the class PropertyEditor method dispose.

public void dispose() {
    disposeWidget();
    valueChangeListeners = new ListenerList();
}
Also used : ListenerList(org.eclipse.core.runtime.ListenerList)

Aggregations

ListenerList (org.eclipse.core.runtime.ListenerList)7 Field (java.lang.reflect.Field)3 IOException (java.io.IOException)2 IFile (org.eclipse.core.resources.IFile)2 IOperationHistoryListener (org.eclipse.core.commands.operations.IOperationHistoryListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 ContentDescriberForJSP (org.eclipse.jst.jsp.core.internal.contenttype.ContentDescriberForJSP)1 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)1