Search in sources :

Example 76 with FileEditorInput

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

the class AbstractMultiPageTalendEditor method createPage2.

// create jobscript editor
protected void createPage2() {
    if (!GlobalServiceRegister.getDefault().isServiceRegistered(ICreateXtextProcessService.class)) {
        return;
    }
    String scriptValue = "";
    try {
        IProject currentProject = ResourceUtils.getProject(ProjectManager.getInstance().getCurrentProject());
        String jobScriptVersion = "";
        if (getEditorInput() != null && getEditorInput() instanceof RepositoryEditorInput) {
            Item item = ((RepositoryEditorInput) getEditorInput()).getItem();
            if (item != null) {
                Property property = item.getProperty();
                if (property != null) {
                    jobScriptVersion = "_" + property.getVersion();
                }
            }
        }
        IFile file = currentProject.getFolder("temp").getFile(getEditorInput().getName() + jobScriptVersion + "_job" + ".jobscript");
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(scriptValue.getBytes());
        if (file.exists()) {
            file.delete(true, null);
            file.create(byteArrayInputStream, true, null);
            file.setContents(byteArrayInputStream, 0, null);
        } else {
            file.create(byteArrayInputStream, true, null);
        }
        String pointId = "org.talend.metalanguage.jobscript.JobScriptForMultipage";
        // the way to get the xtextEditor programmly
        IEditorInput editorInput = new FileEditorInput(file);
        IExtensionPoint ep = RegistryFactory.getRegistry().getExtensionPoint("org.eclipse.ui.editors");
        IExtension[] extensions = ep.getExtensions();
        IExtension ex;
        IConfigurationElement confElem = null;
        for (IExtension extension : extensions) {
            ex = extension;
            if (ex.getContributor().getName().equals("org.talend.metalanguage.jobscript.ui")) {
                for (IConfigurationElement c : ex.getConfigurationElements()) {
                    if (c.getName().equals("editor") && c.getAttribute("id").equals(pointId)) {
                        confElem = c;
                        break;
                    }
                }
            }
        }
        if (confElem != null) {
            jobletEditor = (AbstractDecoratedTextEditor) confElem.createExecutableExtension("class");
            if (jobletEditor != null) {
                int index = addPage(jobletEditor, editorInput);
                setPageText(index, "Jobscript");
            }
        }
    } catch (PartInitException e) {
        ExceptionHandler.process(e);
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    } catch (CoreException e) {
        ExceptionHandler.process(e);
    }
}
Also used : RepositoryEditorInput(org.talend.core.repository.ui.editor.RepositoryEditorInput) IFile(org.eclipse.core.resources.IFile) ICreateXtextProcessService(org.talend.core.services.ICreateXtextProcessService) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IProject(org.eclipse.core.resources.IProject) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IExtension(org.eclipse.core.runtime.IExtension) FileEditorInput(org.eclipse.ui.part.FileEditorInput) PersistenceException(org.talend.commons.exception.PersistenceException) PartInitException(org.eclipse.ui.PartInitException) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IEditorInput(org.eclipse.ui.IEditorInput)

Example 77 with FileEditorInput

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

the class TalendDefaultJavaEditor method doSetInput.

@Override
protected void doSetInput(IEditorInput input) throws CoreException {
    if (input instanceof FileEditorInput) {
        try {
            // IRepositoryService repositoryService = DesignerPlugin.getDefault().getRepositoryService();
            // IProxyRepositoryFactory repFactory = repositoryService.getProxyRepositoryFactory();
            IRunProcessService runProcessService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
            // I think runProcessService can't be null, and should throw exception if it is null
            ITalendProcessJavaProject talendJavaProject = runProcessService.getTalendProcessJavaProject();
            if (talendJavaProject == null) {
                return;
            }
            //$NON-NLS-1$
            final String pathSeperator = "/";
            String routinesFolderName = ERepositoryObjectType.ROUTINES.getFolder().split(pathSeperator)[1];
            String talendSrcFolderPath = talendJavaProject.getSrcFolder().getLocation().toString() + pathSeperator;
            String routineFolderPath = talendSrcFolderPath + routinesFolderName + pathSeperator;
            IFile openedFile = ((FileEditorInput) input).getFile();
            String openedFilePath = openedFile.getLocation().toString();
            boolean isRoutine = openedFilePath.startsWith(routineFolderPath);
            boolean isTalendGeneratedFile = openedFilePath.startsWith(talendSrcFolderPath);
            //$NON-NLS-1$
            String systemRoutineFolderName = "system";
            String systemRoutineFolderPath = routineFolderPath + systemRoutineFolderName + pathSeperator;
            boolean isSystemRoutine = openedFilePath.startsWith(systemRoutineFolderPath);
            if (isSystemRoutine) {
                fileType = FILE_TYPE_TALEND_GENERATED_READONLY;
            } else if (isRoutine) {
                fileType = FILE_TYPE_TALEND_GENERATED_READONLY;
            } else if (isTalendGeneratedFile) {
                fileType = FILE_TYPE_TALEND_GENERATED_READONLY;
            } else {
                fileType = FILE_TYPE_OTHERS;
            }
        } catch (Throwable e) {
            CommonExceptionHandler.process(e, Priority.WARN);
            fileType = FILE_TYPE_OTHERS;
        }
    }
    super.doSetInput(input);
}
Also used : IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject)

Example 78 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project bndtools by bndtools.

the class BndEditor method resourceChanged.

@Override
public void resourceChanged(IResourceChangeEvent event) {
    IResource myResource = ResourceUtil.getResource(getEditorInput());
    IResourceDelta delta = event.getDelta();
    if (delta == null)
        return;
    IPath fullPath = myResource.getFullPath();
    delta = delta.findMember(fullPath);
    if (delta == null)
        return;
    // Delegate to any interested pages
    for (Object page : pages) {
        if (page instanceof IResourceChangeListener) {
            ((IResourceChangeListener) page).resourceChanged(event);
        }
    }
    // Close editor if file removed or switch to new location if file moved
    if (delta.getKind() == IResourceDelta.REMOVED) {
        if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
            IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(delta.getMovedToPath());
            final FileEditorInput newInput = new FileEditorInput(file);
            setInput(newInput);
            Display display = getEditorSite().getShell().getDisplay();
            if (display != null) {
                SWTConcurrencyUtil.execForDisplay(display, true, new Runnable() {

                    @Override
                    public void run() {
                        setPartNameForInput(newInput);
                        sourcePage.setInput(newInput);
                    }
                });
            }
        } else {
            close(false);
        }
    } else // File content updated externally => reload all pages
    if ((delta.getKind() & IResourceDelta.CHANGED) > 0 && (delta.getFlags() & IResourceDelta.CONTENT) > 0) {
        if (!saving.get()) {
            final IDocumentProvider docProvider = sourcePage.getDocumentProvider();
            // #1625: Ensure the IDocumentProvider is not null.
            if (docProvider != null) {
                final IDocument document = docProvider.getDocument(getEditorInput());
                SWTConcurrencyUtil.execForControl(getEditorSite().getShell(), true, new Runnable() {

                    @Override
                    public void run() {
                        try {
                            model.loadFrom(new IDocumentWrapper(document));
                            updateIncludedPages();
                        } catch (IOException e) {
                            logger.logError("Failed to reload document", e);
                        }
                    }
                });
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) IOException(java.io.IOException) IDocumentWrapper(bndtools.editor.model.IDocumentWrapper) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IFileEditorInput(org.eclipse.ui.IFileEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IResource(org.eclipse.core.resources.IResource) IDocument(org.eclipse.jface.text.IDocument) IResourceDelta(org.eclipse.core.resources.IResourceDelta) Display(org.eclipse.swt.widgets.Display)

Example 79 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project eclipse.platform.text by eclipse.

the class AbstratGenericEditorTest method createAndOpenFile.

/**
 * Creates a new file in the project, opens it, and associate that file with the test state
 * @param name name of the file in the project
 * @param contents content of the file
 * @throws Exception ex
 * @since 1.1
 */
protected void createAndOpenFile(String name, String contents) throws Exception {
    this.file = project.getFile(name);
    this.file.create(new ByteArrayInputStream(contents.getBytes("UTF-8")), true, null);
    this.file.setCharset("UTF-8", null);
    this.editor = (ExtensionBasedTextEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(new FileEditorInput(this.file), "org.eclipse.ui.genericeditor.GenericEditor");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileEditorInput(org.eclipse.ui.part.FileEditorInput)

Example 80 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project eclipse.platform.text by eclipse.

the class AbstractDecoratedTextEditor method performSaveAs.

/**
 * This implementation asks the user for the workspace path of a file resource and saves the document there.
 *
 * @param progressMonitor the progress monitor to be used
 * @since 3.2
 */
@Override
protected void performSaveAs(IProgressMonitor progressMonitor) {
    Shell shell = PlatformUI.getWorkbench().getModalDialogShellProvider().getShell();
    final IEditorInput input = getEditorInput();
    IDocumentProvider provider = getDocumentProvider();
    final IEditorInput newInput;
    if (input instanceof IURIEditorInput && !(input instanceof IFileEditorInput)) {
        FileDialog dialog = new FileDialog(shell, SWT.SAVE);
        IPath oldPath = URIUtil.toPath(((IURIEditorInput) input).getURI());
        if (oldPath != null && !oldPath.isEmpty()) {
            dialog.setFileName(oldPath.lastSegment());
            dialog.setFilterPath(oldPath.removeLastSegments(1).toOSString());
        }
        String path = dialog.open();
        if (path == null) {
            if (progressMonitor != null)
                progressMonitor.setCanceled(true);
            return;
        }
        // Check whether file exists and if so, confirm overwrite
        final File localFile = new File(path);
        if (localFile.exists()) {
            MessageDialog overwriteDialog = new MessageDialog(shell, TextEditorMessages.AbstractDecoratedTextEditor_saveAs_overwrite_title, null, NLSUtility.format(TextEditorMessages.AbstractDecoratedTextEditor_saveAs_overwrite_message, path), MessageDialog.WARNING, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, // 'No' is the default
            1);
            if (overwriteDialog.open() != Window.OK) {
                if (progressMonitor != null) {
                    progressMonitor.setCanceled(true);
                    return;
                }
            }
        }
        IFileStore fileStore;
        try {
            fileStore = EFS.getStore(localFile.toURI());
        } catch (CoreException ex) {
            EditorsPlugin.log(ex.getStatus());
            String title = TextEditorMessages.AbstractDecoratedTextEditor_error_saveAs_title;
            String msg = NLSUtility.format(TextEditorMessages.AbstractDecoratedTextEditor_error_saveAs_message, ex.getMessage());
            MessageDialog.openError(shell, title, msg);
            return;
        }
        IFile file = getWorkspaceFile(fileStore);
        if (file != null)
            newInput = new FileEditorInput(file);
        else
            newInput = new FileStoreEditorInput(fileStore);
    } else {
        SaveAsDialog dialog = new SaveAsDialog(shell);
        IFile original = (input instanceof IFileEditorInput) ? ((IFileEditorInput) input).getFile() : null;
        if (original != null)
            dialog.setOriginalFile(original);
        else
            dialog.setOriginalName(input.getName());
        dialog.create();
        if (provider.isDeleted(input) && original != null) {
            String message = NLSUtility.format(TextEditorMessages.AbstractDecoratedTextEditor_warning_saveAs_deleted, original.getName());
            dialog.setErrorMessage(null);
            dialog.setMessage(message, IMessageProvider.WARNING);
        }
        if (dialog.open() == Window.CANCEL) {
            if (progressMonitor != null)
                progressMonitor.setCanceled(true);
            return;
        }
        IPath filePath = dialog.getResult();
        if (filePath == null) {
            if (progressMonitor != null)
                progressMonitor.setCanceled(true);
            return;
        }
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IFile file = workspace.getRoot().getFile(filePath);
        newInput = new FileEditorInput(file);
    }
    if (provider == null) {
        // editor has programmatically been  closed while the dialog was open
        return;
    }
    boolean success = false;
    try {
        provider.aboutToChange(newInput);
        provider.saveDocument(progressMonitor, newInput, provider.getDocument(input), true);
        success = true;
    } catch (CoreException x) {
        final IStatus status = x.getStatus();
        if (status == null || status.getSeverity() != IStatus.CANCEL) {
            String title = TextEditorMessages.AbstractDecoratedTextEditor_error_saveAs_title;
            String msg = NLSUtility.format(TextEditorMessages.AbstractDecoratedTextEditor_error_saveAs_message, x.getMessage());
            MessageDialog.openError(shell, title, msg);
        }
    } finally {
        provider.changed(newInput);
        if (success)
            setInput(newInput);
    }
    if (progressMonitor != null)
        progressMonitor.setCanceled(!success);
}
Also used : IURIEditorInput(org.eclipse.ui.IURIEditorInput) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) Shell(org.eclipse.swt.widgets.Shell) CoreException(org.eclipse.core.runtime.CoreException) IFileEditorInput(org.eclipse.ui.IFileEditorInput) IFileEditorInput(org.eclipse.ui.IFileEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkspace(org.eclipse.core.resources.IWorkspace) IFileStore(org.eclipse.core.filesystem.IFileStore) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) FileDialog(org.eclipse.swt.widgets.FileDialog) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IEditorInput(org.eclipse.ui.IEditorInput) IURIEditorInput(org.eclipse.ui.IURIEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Aggregations

FileEditorInput (org.eclipse.ui.part.FileEditorInput)87 IFile (org.eclipse.core.resources.IFile)55 CoreException (org.eclipse.core.runtime.CoreException)31 IEditorPart (org.eclipse.ui.IEditorPart)29 PartInitException (org.eclipse.ui.PartInitException)24 ArrayList (java.util.ArrayList)20 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)19 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)18 IEditorReference (org.eclipse.ui.IEditorReference)17 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)16 IEditorInput (org.eclipse.ui.IEditorInput)16 FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)15 IProject (org.eclipse.core.resources.IProject)13 File (java.io.File)11 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)11 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)11 ByteArrayInputStream (java.io.ByteArrayInputStream)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 ExecutionException (org.eclipse.core.commands.ExecutionException)9 List (java.util.List)7