Search in sources :

Example 1 with Workspace

use of org.eclipse.core.internal.resources.Workspace in project tdi-studio-se by Talend.

the class StandAloneTalendJavaEditor method doSetInput.

@Override
public void doSetInput(IEditorInput input) throws CoreException {
    // Lock the process :
    IRepositoryService service = DesignerPlugin.getDefault().getRepositoryService();
    IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
    if (input instanceof RepositoryEditorInput) {
        rEditorInput = (RepositoryEditorInput) input;
    } else {
        FileEditorInput fileInput = (FileEditorInput) input;
        rEditorInput = new RepositoryEditorInput(fileInput.getFile(), rEditorInput.getItem());
    }
    if (rEditorInput.getRepositoryNode() == null) {
        // retrieve node
        rEditorInput.setRepositoryNode(null);
    }
    try {
        // see bug 1321
        item = (FileItem) rEditorInput.getItem();
        if (!rEditorInput.isReadOnly()) {
            if (getRepositoryFactory().getStatus(item).isPotentiallyEditable()) {
                item.getProperty().eAdapters().add(dirtyListener);
                repFactory.lock(item);
            }
        } else {
            rEditorInput.getFile().setReadOnly(true);
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    rEditorInput.getFile().refreshLocal(IResource.DEPTH_ONE, null);
    super.doSetInput(rEditorInput);
    setName();
    // only for sql template
    if (item instanceof SQLPatternItem) {
        Workspace ws = (Workspace) ResourcesPlugin.getWorkspace();
        ws.broadcastBuildEvent(item, IResourceChangeEvent.POST_CHANGE, 1);
    }
}
Also used : RepositoryEditorInput(org.talend.core.repository.ui.editor.RepositoryEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) LoginException(org.talend.commons.exception.LoginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryService(org.talend.repository.model.IRepositoryService) Workspace(org.eclipse.core.internal.resources.Workspace) IWorkspace(org.eclipse.core.resources.IWorkspace)

Example 2 with Workspace

use of org.eclipse.core.internal.resources.Workspace in project tdi-studio-se by Talend.

the class StandAloneTalendJavaEditor method dispose.

@SuppressWarnings("restriction")
@Override
public void dispose() {
    // remove the Runtines .java file in the .Java Project.
    // try {
    // rEditorInput.getFile().delete(true, null);
    // } catch (CoreException e1) {
    // RuntimeExceptionHandler.process(e1);
    // }
    super.dispose();
    if (lockService != null) {
        lockService.unregister();
    }
    // Unlock the process :
    IRepositoryService service = DesignerPlugin.getDefault().getRepositoryService();
    IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
    try {
        item.getProperty().eAdapters().remove(dirtyListener);
        repFactory.unlock(item);
    } catch (PersistenceException e) {
        // e.printStackTrace();
        ExceptionHandler.process(e);
    } catch (LoginException e) {
        ExceptionHandler.process(e);
    }
    // }
    if (!isEditable) {
        rEditorInput.getFile().setReadOnly(false);
    }
    // dispose custom color
    if (bgColorForReadOnlyItem != null) {
        bgColorForReadOnlyItem.dispose();
    }
    if (bgColorForEditabeItem != null) {
        bgColorForEditabeItem.dispose();
    }
    ITalendProcessJavaProject talendProcessJavaProject = CorePlugin.getDefault().getRunProcessService().getTalendProcessJavaProject();
    if (talendProcessJavaProject != null) {
        talendProcessJavaProject.updateRoutinesPom(true, true);
    }
    // only for sql template
    if (item instanceof SQLPatternItem) {
        IProject jProject = talendProcessJavaProject.getProject();
        ResourceChangeEvent event = new ResourceChangeEvent(item, IResourceChangeEvent.PRE_CLOSE, 1, null);
        try {
            //$NON-NLS-1$
            Field resourceField = event.getClass().getDeclaredField("resource");
            resourceField.setAccessible(true);
            resourceField.set(event, jProject);
        } catch (Exception e) {
            ExceptionHandler.process(e);
        }
        Workspace ws = (Workspace) ResourcesPlugin.getWorkspace();
        ws.getNotificationManager().broadcastChanges(ws.getElementTree(), event, false);
    }
}
Also used : Field(java.lang.reflect.Field) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) ResourceChangeEvent(org.eclipse.core.internal.events.ResourceChangeEvent) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) LoginException(org.talend.commons.exception.LoginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryService(org.talend.repository.model.IRepositoryService) Workspace(org.eclipse.core.internal.resources.Workspace) IWorkspace(org.eclipse.core.resources.IWorkspace)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Workspace (org.eclipse.core.internal.resources.Workspace)2 IWorkspace (org.eclipse.core.resources.IWorkspace)2 CoreException (org.eclipse.core.runtime.CoreException)2 PartInitException (org.eclipse.ui.PartInitException)2 LoginException (org.talend.commons.exception.LoginException)2 PersistenceException (org.talend.commons.exception.PersistenceException)2 SQLPatternItem (org.talend.core.model.properties.SQLPatternItem)2 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)2 IRepositoryService (org.talend.repository.model.IRepositoryService)2 Field (java.lang.reflect.Field)1 ResourceChangeEvent (org.eclipse.core.internal.events.ResourceChangeEvent)1 IProject (org.eclipse.core.resources.IProject)1 IResourceChangeEvent (org.eclipse.core.resources.IResourceChangeEvent)1 FileEditorInput (org.eclipse.ui.part.FileEditorInput)1 RepositoryEditorInput (org.talend.core.repository.ui.editor.RepositoryEditorInput)1 ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)1