Search in sources :

Example 1 with IPropertyListener

use of org.eclipse.ui.IPropertyListener in project gfm_viewer by satyagraha.

the class MarkdownEditorTrackerTest method shouldNotNotifyOnEditorPartInput.

@Test
public void shouldNotNotifyOnEditorPartInput() throws Exception {
    // given
    given(editorPart.getEditorInput()).willReturn(editorInput);
    willDoNothing().given(editorPart).addPropertyListener(propertyListenerCaptor.capture());
    given(editorInput.getAdapter(IFile.class)).willReturn(editorIFile);
    given(fileNature.isTrackableFile(editorIFile)).willReturn(true);
    // when
    editorTracker.start();
    editorTracker.addListener(markdownListener);
    editorTracker.editorShown(editorPart);
    IPropertyListener propertyListener = propertyListenerCaptor.getValue();
    given(editorPart.isDirty()).willReturn(false);
    propertyListener.propertyChanged(editorPart, IEditorPart.PROP_INPUT);
    // then
    verify(markdownListener, times(1)).notifyEditorFile(editorIFile);
    verifyNoMoreInteractions(markdownListener);
}
Also used : IPropertyListener(org.eclipse.ui.IPropertyListener) Test(org.junit.Test)

Example 2 with IPropertyListener

use of org.eclipse.ui.IPropertyListener in project gfm_viewer by satyagraha.

the class MarkdownEditorTrackerTest method shouldNotifyOnEditorPartSaved.

@Test
public void shouldNotifyOnEditorPartSaved() throws Exception {
    // given
    given(editorPart.getEditorInput()).willReturn(editorInput);
    willDoNothing().given(editorPart).addPropertyListener(propertyListenerCaptor.capture());
    given(editorInput.getAdapter(IFile.class)).willReturn(editorIFile);
    given(fileNature.isTrackableFile(editorIFile)).willReturn(true);
    // when
    editorTracker.start();
    editorTracker.addListener(markdownListener);
    editorTracker.editorShown(editorPart);
    IPropertyListener propertyListener = propertyListenerCaptor.getValue();
    given(editorPart.isDirty()).willReturn(false);
    propertyListener.propertyChanged(editorPart, IEditorPart.PROP_DIRTY);
    // then
    verify(markdownListener, times(2)).notifyEditorFile(editorIFile);
    verifyNoMoreInteractions(markdownListener);
}
Also used : IPropertyListener(org.eclipse.ui.IPropertyListener) Test(org.junit.Test)

Example 3 with IPropertyListener

use of org.eclipse.ui.IPropertyListener in project tdi-studio-se by Talend.

the class AbstractMultiPageTalendEditor method turnToJobScriptPage.

protected void turnToJobScriptPage(int newPageIndex) {
    if (jobletEditor != getEditor(newPageIndex)) {
        return;
    }
    ICreateXtextProcessService convertJobtoScriptService = CorePlugin.getDefault().getCreateXtextProcessService();
    try {
        final String scriptValue = convertJobtoScriptService.convertJobtoScript(getProcess().saveXmlFile());
        IFile file = (IFile) jobletEditor.getEditorInput().getAdapter(IResource.class);
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(scriptValue.getBytes());
        if (file.exists()) {
            jobletEditor.getDocumentProvider().getDocument(jobletEditor.getEditorInput()).set(scriptValue);
            boolean isProcessReadOnly = ((JobEditorInput) getEditor(0).getEditorInput()).isReadOnly();
            IProxyRepositoryFactory rFactory = ProxyRepositoryFactory.getInstance();
            if (isProcessReadOnly || rFactory.isUserReadOnlyOnCurrentProject()) {
                IDocumentProvider provider = jobletEditor.getDocumentProvider();
                Class p = provider.getClass();
                Class[] type = new Class[1];
                type[0] = Boolean.TYPE;
                Object[] para = new Object[1];
                para[0] = Boolean.TRUE;
                Method method = p.getMethod("setReadOnly", type);
                method.invoke(provider, para);
            }
            //$NON-NLS-1$
            IAction action = jobletEditor.getAction("FoldingRestore");
            action.run();
            jobletEditor.doSave(null);
        } else {
            file.create(byteArrayInputStream, true, null);
        }
        if (propertyListener == null) {
            propertyListener = new IPropertyListener() {

                @Override
                public void propertyChanged(Object source, int propId) {
                    if (source instanceof IEditorPart && ((IEditorPart) source).isDirty()) {
                        getProcess().setProcessModified(true);
                        getProcess().setNeedRegenerateCode(true);
                    }
                }
            };
            jobletEditor.addPropertyListener(propertyListener);
        }
    } catch (PartInitException e) {
        ExceptionHandler.process(e);
    } catch (CoreException e) {
        ExceptionHandler.process(e);
    } catch (IOException e) {
        ExceptionHandler.process(e);
    } catch (SecurityException e) {
        ExceptionHandler.process(e);
    } catch (NoSuchMethodException e) {
        ExceptionHandler.process(e);
    } catch (IllegalArgumentException e) {
        ExceptionHandler.process(e);
    } catch (IllegalAccessException e) {
        ExceptionHandler.process(e);
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
    }
    changeContextsViewStatus(false);
}
Also used : IFile(org.eclipse.core.resources.IFile) ICreateXtextProcessService(org.talend.core.services.ICreateXtextProcessService) IPropertyListener(org.eclipse.ui.IPropertyListener) PartInitException(org.eclipse.ui.PartInitException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IAction(org.eclipse.jface.action.IAction) Method(java.lang.reflect.Method) IEditorPart(org.eclipse.ui.IEditorPart) IOException(java.io.IOException) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) InvocationTargetException(java.lang.reflect.InvocationTargetException) JobEditorInput(org.talend.core.ui.editor.JobEditorInput) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PlatformObject(org.eclipse.core.runtime.PlatformObject) IResource(org.eclipse.core.resources.IResource)

Example 4 with IPropertyListener

use of org.eclipse.ui.IPropertyListener in project gfm_viewer by satyagraha.

the class MarkdownEditorTrackerTest method shouldNotNotifyOnEditorPartialSave.

@Test
public void shouldNotNotifyOnEditorPartialSave() throws Exception {
    // given
    given(editorPart.getEditorInput()).willReturn(editorInput);
    willDoNothing().given(editorPart).addPropertyListener(propertyListenerCaptor.capture());
    given(editorInput.getAdapter(IFile.class)).willReturn(editorIFile);
    given(fileNature.isTrackableFile(editorIFile)).willReturn(true);
    // when
    editorTracker.start();
    editorTracker.addListener(markdownListener);
    editorTracker.editorShown(editorPart);
    IPropertyListener propertyListener = propertyListenerCaptor.getValue();
    given(editorPart.isDirty()).willReturn(true);
    propertyListener.propertyChanged(editorPart, IEditorPart.PROP_DIRTY);
    // then
    verify(markdownListener, times(1)).notifyEditorFile(editorIFile);
    verifyNoMoreInteractions(markdownListener);
}
Also used : IPropertyListener(org.eclipse.ui.IPropertyListener) Test(org.junit.Test)

Aggregations

IPropertyListener (org.eclipse.ui.IPropertyListener)4 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)1 PlatformObject (org.eclipse.core.runtime.PlatformObject)1 IAction (org.eclipse.jface.action.IAction)1 IEditorPart (org.eclipse.ui.IEditorPart)1 PartInitException (org.eclipse.ui.PartInitException)1 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)1 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)1 ICreateXtextProcessService (org.talend.core.services.ICreateXtextProcessService)1 JobEditorInput (org.talend.core.ui.editor.JobEditorInput)1 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)1