Search in sources :

Example 96 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project gemoc-studio by eclipse.

the class GexpressionsEditor method doSaveAs.

/**
 * This also changes the editor's input.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void doSaveAs() {
    SaveAsDialog saveAsDialog = new SaveAsDialog(getSite().getShell());
    saveAsDialog.open();
    IPath path = saveAsDialog.getResult();
    if (path != null) {
        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
        if (file != null) {
            doSaveAs(URI.createPlatformResourceURI(file.getFullPath().toString(), true), new FileEditorInput(file));
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) FileEditorInput(org.eclipse.ui.part.FileEditorInput)

Example 97 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project titan.EclipsePlug-ins by eclipse.

the class OpenDeclaration method selectAndRevealDeclaration.

/**
 * Opens an editor for the provided declaration, and in this editor the
 * location of the declaration is revealed and selected.
 *
 * @param declaration
 *                the declaration to reveal
 */
private void selectAndRevealDeclaration(final Location location) {
    IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(location.getFile().getName());
    if (desc == null) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(TTCNPPEDITORNOTFOUND);
        return;
    }
    try {
        IWorkbenchPage page = targetEditor.getSite().getPage();
        IEditorPart editorPart = page.openEditor(new FileEditorInput((IFile) location.getFile()), desc.getId());
        if (editorPart != null && (editorPart instanceof AbstractTextEditor)) {
            ((AbstractTextEditor) editorPart).selectAndReveal(location.getOffset(), location.getEndOffset() - location.getOffset());
        }
    } catch (PartInitException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) FileEditorInput(org.eclipse.ui.part.FileEditorInput) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException)

Example 98 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project mdw-designer by CenturyLinkCloud.

the class ArtifactEditor method openTempFile.

public void openTempFile(IProgressMonitor monitor) {
    tempFileEditor = null;
    try {
        IFolder folder = getTempFolder();
        if (!folder.exists())
            PluginUtil.createFoldersAsNeeded(getElement().getProject().getSourceProject(), folder, monitor);
        final IFile file = getTempFile(folder);
        final IWorkbenchPage activePage = MdwPlugin.getActivePage();
        if (file.exists()) {
            IEditorInput editorInput = new FileEditorInput(file);
            tempFileEditor = activePage.findEditor(editorInput);
            if (tempFileEditor == null) {
                // we'll refresh from attribute value
                new TempFileRemover(folder, file).remove(monitor);
            } else {
                // activate existing editor
                tempFileEditor = IDE.openEditor(activePage, file, true);
            }
        }
        if (tempFileEditor == null) {
            // either the file didn't exist or it was not currently open,
            // set from value
            byte[] value = valueProvider.getArtifactContent();
            if (value == null)
                value = "".getBytes();
            InputStream source = new ByteArrayInputStream(value);
            file.create(source, true, monitor);
            if (getElement().isReadOnly()) {
                ResourceAttributes resourceAttrs = file.getResourceAttributes();
                resourceAttrs.setReadOnly(true);
                file.setResourceAttributes(resourceAttrs);
            }
            final Display display = Display.getCurrent();
            if (display != null) {
                display.syncExec(new Runnable() {

                    public void run() {
                        try {
                            if (!valueProvider.beforeTempFileOpened())
                                return;
                            tempFileEditor = IDE.openEditor(activePage, file, true);
                            if (tempFileEditor != null) {
                                // listen for artifact made dirty and
                                // propagate to process canvas
                                tempFileEditor.addPropertyListener(new IPropertyListener() {

                                    public void propertyChanged(Object source, int propId) {
                                        if (source instanceof EditorPart && propId == IWorkbenchPartConstants.PROP_DIRTY) {
                                            if (((EditorPart) source).isDirty())
                                                // process
                                                fireValueChanged(null, true);
                                        // editor
                                        // should
                                        // show
                                        // dirty
                                        }
                                    }
                                });
                                // listen for artifact resource changes
                                ArtifactResourceListener resourceListener = new ArtifactResourceListener(getElement(), valueProvider, file);
                                getProject().addArtifactResourceListener(resourceListener);
                                // listen for workbench closed to prevent
                                // re-opening editor when the workbench is
                                // next opened
                                PlatformUI.getWorkbench().addWorkbenchListener(new ArtifactEditorWorkbenchListener(tempFileEditor));
                            }
                            valueProvider.afterTempFileOpened(tempFileEditor);
                        } catch (PartInitException ex) {
                            PluginMessages.log(ex);
                        }
                    }
                });
            }
            // register to listen to process editor events
            WorkflowProcess processVersion = null;
            if (getElement() instanceof Activity)
                processVersion = ((Activity) getElement()).getProcess();
            else if (getElement() instanceof WorkflowProcess)
                processVersion = (WorkflowProcess) getElement();
            if (processVersion != null) {
                IEditorPart processEditor = activePage.findEditor(processVersion);
                if (processEditor != null && tempFileEditor != null)
                    ((ProcessEditor) processEditor).addActiveScriptEditor(tempFileEditor);
            }
        }
    } catch (Exception ex) {
        PluginMessages.uiError(ex, "Open Temp File", getElement().getProject());
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Activity(com.centurylink.mdw.plugin.designer.model.Activity) IEditorPart(org.eclipse.ui.IEditorPart) EditorPart(org.eclipse.ui.part.EditorPart) ArtifactResourceListener(com.centurylink.mdw.plugin.workspace.ArtifactResourceListener) IEditorPart(org.eclipse.ui.IEditorPart) ResourceAttributes(org.eclipse.core.resources.ResourceAttributes) IPropertyListener(org.eclipse.ui.IPropertyListener) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) TempFileRemover(com.centurylink.mdw.plugin.workspace.TempFileRemover) ByteArrayInputStream(java.io.ByteArrayInputStream) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess) IEditorInput(org.eclipse.ui.IEditorInput) IFolder(org.eclipse.core.resources.IFolder) Display(org.eclipse.swt.widgets.Display)

Example 99 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project mdw-designer by CenturyLinkCloud.

the class WorkflowAsset method openFile.

public void openFile(IProgressMonitor monitor) {
    if (!isRawEdit()) {
        openTempFile(monitor);
        return;
    }
    assetFileEditor = null;
    try {
        final IFile file = getAssetFile();
        file.refreshLocal(0, monitor);
        boolean readOnly = getProject().isReadOnly() || !isUserAuthorized(UserRoleVO.ASSET_DESIGN);
        PluginUtil.setReadOnly(file, readOnly);
        final IWorkbenchPage activePage = MdwPlugin.getActivePage();
        IEditorInput editorInput = new FileEditorInput(file);
        assetFileEditor = activePage.findEditor(editorInput);
        if (assetFileEditor != null) {
            // activate
            assetFileEditor = IDE.openEditor(activePage, file, true);
        // existing
        // editor
        } else {
            load();
            final Display display = Display.getCurrent();
            if (display != null) {
                display.syncExec(new Runnable() {

                    public void run() {
                        try {
                            final IWorkbenchPage activePage = MdwPlugin.getActivePage();
                            beforeFileOpened();
                            if (isForceExternalEditor()) {
                                activePage.openEditor(new FileEditorInput(file), IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID, true);
                            } else {
                                assetFileEditor = IDE.openEditor(activePage, file, true);
                            }
                            afterFileOpened(assetFileEditor);
                        } catch (PartInitException ex) {
                            PluginMessages.log(ex);
                        }
                    }
                });
            }
        }
    } catch (Exception ex) {
        PluginMessages.uiError(ex, "Open Asset File", getProject());
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) MDWException(com.centurylink.mdw.common.exception.MDWException) Display(org.eclipse.swt.widgets.Display)

Example 100 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project mdw-designer by CenturyLinkCloud.

the class WorkflowAsset method openTempFile.

@SuppressWarnings("restriction")
public void openTempFile(IProgressMonitor monitor) {
    assetFileEditor = null;
    try {
        IFolder folder = getTempFolder();
        folder.refreshLocal(IResource.DEPTH_INFINITE, monitor);
        if (!folder.exists())
            PluginUtil.createFoldersAsNeeded(getProject().getSourceProject(), folder, monitor);
        final IFile file = getTempFile(folder);
        final IWorkbenchPage activePage = MdwPlugin.getActivePage();
        boolean externalEditorAlreadyOpen = false;
        if (file.exists()) {
            IEditorInput editorInput = new FileEditorInput(file);
            assetFileEditor = activePage.findEditor(editorInput);
            if (assetFileEditor == null) {
                // we'll refresh from saved value
                WorkflowAssetFactory.deRegisterWorkbenchListener(file);
                try {
                    new TempFileRemover(folder, file).remove(monitor);
                } catch (org.eclipse.core.internal.resources.ResourceException ex) {
                    if (isForceExternalEditor()) {
                        // assume this is because the temp file is already
                        // open in an external editor; reactivate
                        PluginMessages.log(ex);
                        externalEditorAlreadyOpen = true;
                        activePage.openEditor(new FileEditorInput(file), IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID, true);
                    } else {
                        throw ex;
                    }
                }
            } else {
                // activate existing editor
                assetFileEditor = IDE.openEditor(activePage, file, true);
            }
        }
        if (assetFileEditor == null) {
            // set from value
            if (!externalEditorAlreadyOpen)
                createTempFile(file, monitor);
            final Display display = Display.getCurrent();
            if (display != null) {
                display.syncExec(new Runnable() {

                    public void run() {
                        try {
                            beforeFileOpened();
                            if (isForceExternalEditor())
                                activePage.openEditor(new FileEditorInput(file), IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID, true);
                            else
                                assetFileEditor = IDE.openEditor(activePage, file, true);
                            if (assetFileEditor != null) {
                                assetFileEditor.addPropertyListener(new AssetEditorPropertyListener(assetFileEditor));
                                WorkflowAssetFactory.registerWorkbenchListener(file, new AssetWorkbenchListener(assetFileEditor));
                            }
                            afterFileOpened(assetFileEditor);
                        } catch (PartInitException ex) {
                            PluginMessages.log(ex);
                        }
                    }
                });
            }
        }
    } catch (Exception ex) {
        PluginMessages.uiError(ex, "Open Temp File", getProject());
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) MDWException(com.centurylink.mdw.common.exception.MDWException) TempFileRemover(com.centurylink.mdw.plugin.workspace.TempFileRemover) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput) IFolder(org.eclipse.core.resources.IFolder) Display(org.eclipse.swt.widgets.Display)

Aggregations

FileEditorInput (org.eclipse.ui.part.FileEditorInput)314 IFile (org.eclipse.core.resources.IFile)223 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)117 PartInitException (org.eclipse.ui.PartInitException)108 IEditorPart (org.eclipse.ui.IEditorPart)81 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)68 CoreException (org.eclipse.core.runtime.CoreException)66 IEditorInput (org.eclipse.ui.IEditorInput)66 IPath (org.eclipse.core.runtime.IPath)65 IResource (org.eclipse.core.resources.IResource)45 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)43 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)42 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)40 HashMap (java.util.HashMap)39 SaveAsDialog (org.eclipse.ui.dialogs.SaveAsDialog)39 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)38 EObject (org.eclipse.emf.ecore.EObject)37 Resource (org.eclipse.emf.ecore.resource.Resource)36 ISelection (org.eclipse.jface.viewers.ISelection)36 IEditorReference (org.eclipse.ui.IEditorReference)36