Search in sources :

Example 81 with FileEditorInput

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

the class ChangeLogAction method getDocumentLocation.

protected String getDocumentLocation(IEditorPart currentEditor, boolean appendRoot) {
    IFile loc = getDocumentIFile(currentEditor);
    IEditorInput cc = null;
    String WorkspaceRoot;
    IWorkspaceRoot myWorkspaceRoot = getWorkspaceRoot();
    WorkspaceRoot = myWorkspaceRoot.getLocation().toOSString();
    if (currentEditor instanceof MultiPageEditorPart) {
        Object ed = ((MultiPageEditorPart) currentEditor).getSelectedPage();
        if (ed instanceof IEditorPart)
            cc = ((IEditorPart) ed).getEditorInput();
        if (cc instanceof FileEditorInput)
            return (appendRoot) ? WorkspaceRoot + ((FileEditorInput) cc).getFile().getFullPath().toOSString() : ((FileEditorInput) cc).getFile().getFullPath().toOSString();
    }
    cc = currentEditor.getEditorInput();
    if (cc == null)
        return "";
    if ((cc instanceof SyncInfoCompareInput) || (cc instanceof CompareEditorInput)) {
        CompareEditorInput test = (CompareEditorInput) cc;
        if (test.getCompareResult() == null) {
            return "";
        } else if (test.getCompareResult() instanceof ICompareInput) {
            ITypedElement leftCompare = ((ICompareInput) test.getCompareResult()).getLeft();
            if (leftCompare instanceof IResourceProvider) {
                String localPath = ((IResourceProvider) leftCompare).getResource().getFullPath().toString();
                if (appendRoot) {
                    return WorkspaceRoot + localPath;
                }
                return localPath;
            }
        } else {
            if (appendRoot)
                return WorkspaceRoot + test.getCompareResult().toString();
            return test.getCompareResult().toString();
        }
    } else if (cc instanceof FileStoreEditorInput) {
        return ((FileStoreEditorInput) cc).getName();
    }
    if (appendRoot) {
        return WorkspaceRoot + loc.getFullPath().toOSString();
    } else if (loc != null) {
        return loc.getFullPath().toOSString();
    } else {
        return "";
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) ITypedElement(org.eclipse.compare.ITypedElement) ICompareInput(org.eclipse.compare.structuremergeviewer.ICompareInput) IEditorPart(org.eclipse.ui.IEditorPart) IResourceProvider(org.eclipse.compare.IResourceProvider) CompareEditorInput(org.eclipse.compare.CompareEditorInput) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IFileEditorInput(org.eclipse.ui.IFileEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) SyncInfoCompareInput(org.eclipse.team.ui.synchronize.SyncInfoCompareInput) IEditorInput(org.eclipse.ui.IEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 82 with FileEditorInput

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

the class FileTestCase method newFile.

protected void newFile(String contents) {
    try {
        testFile.setContents(new ByteArrayInputStream(contents.getBytes()), false, false, null);
    } catch (CoreException e) {
        fail(e.getMessage());
    }
    testDocument = new Document(contents);
    fei = new FileEditorInput(testFile);
    try {
        SpecfileEditor.getSpecfileDocumentProvider().disconnect(fei);
        SpecfileEditor.getSpecfileDocumentProvider().connect(fei);
    } catch (CoreException e) {
    // let failures occur
    }
    errorHandler = new SpecfileErrorHandler(fei, testDocument);
    parser.setErrorHandler(errorHandler);
    specfile = parser.parse(testDocument);
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileEditorInput(org.eclipse.ui.part.FileEditorInput) Document(org.eclipse.jface.text.Document) SpecfileErrorHandler(org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileErrorHandler)

Example 83 with FileEditorInput

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

the class STLink2SourceSupport method findFileInCommonSourceLookup.

private static IEditorInput findFileInCommonSourceLookup(IPath path) {
    try {
        AbstractSourceLookupDirector director = CDebugCorePlugin.getDefault().getCommonSourceLookupDirector();
        ISourceContainer[] c = director.getSourceContainers();
        for (ISourceContainer sourceContainer : c) {
            Object[] o = sourceContainer.findSourceElements(path.toOSString());
            for (Object object : o) {
                if (object instanceof IFile) {
                    return new FileEditorInput((IFile) object);
                } else if (object instanceof LocalFileStorage) {
                    LocalFileStorage storage = (LocalFileStorage) object;
                    IFileStore ifs = EFS.getStore(storage.getFile().toURI());
                    return new FileStoreEditorInput(ifs);
                }
            }
        }
    } catch (CoreException e) {
    // do nothing
    }
    return null;
}
Also used : AbstractSourceLookupDirector(org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) LocalFileStorage(org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage) IFileStore(org.eclipse.core.filesystem.IFileStore) IBinaryObject(org.eclipse.cdt.core.IBinaryParser.IBinaryObject) ISourceContainer(org.eclipse.debug.core.sourcelookup.ISourceContainer) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 84 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project knime-core by knime.

the class MoveModelProvider method validateChange.

/**
 * Checks if a KNIIME workflow project is intended to be renamed. The reason
 * is, that at the moment the KNIME core saves an absolute path for storage
 * reasons. If renamed save actions would fail.
 *
 * @see org.eclipse.core.resources.mapping.ModelProvider#
 *      validateChange(org.eclipse.core.resources.IResourceDelta,
 *      org.eclipse.core.runtime.IProgressMonitor)
 */
@Override
public IStatus validateChange(final IResourceDelta delta, final IProgressMonitor monitor) {
    try {
        // check whether this is a knime project
        IProject project = null;
        IFile workflowFile = null;
        for (IResourceDelta affectedChild : delta.getAffectedChildren()) {
            project = affectedChild.getResource().getProject();
            workflowFile = project.getFile(WorkflowPersistor.WORKFLOW_FILE);
            // break if we found the project with a knime workflow
            if (workflowFile.exists()) {
                break;
            }
        }
        // check whether this is a move delta
        IResourceDelta[] deltas = delta.getAffectedChildren();
        boolean moveAction = false;
        for (IResourceDelta curDelta : deltas) {
            if ((curDelta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
                moveAction = true;
                break;
            }
        }
        if (workflowFile.exists() && moveAction) {
            // check if an editor is opened on this resource
            boolean editorOpen = false;
            IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
            for (IWorkbenchWindow window : windows) {
                IWorkbenchPage[] pages = window.getPages();
                for (IWorkbenchPage page : pages) {
                    IEditorPart editorPart = page.findEditor(new FileEditorInput(workflowFile));
                    if (editorPart != null) {
                        editorOpen = true;
                        break;
                    }
                }
            }
            if (editorOpen) {
                return new ModelStatus(IStatus.WARNING, ResourcesPlugin.PI_RESOURCES, getModelProviderId(), "Renaming " + project.getName() + " may have undesirable side effects " + "since this workflow is currently open." + " You may loose some or all of your " + "data if you continue (although the " + "settings will" + " not be affected). Consider closing the " + "workflow before renaming it.");
            }
        }
    } catch (Exception e) {
    // do nothing
    }
    // else performe the default behavior
    return super.validateChange(delta, monitor);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ModelStatus(org.eclipse.core.resources.mapping.ModelStatus) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 85 with FileEditorInput

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

the class OPIEditor method doSaveAs.

/**
 * {@inheritDoc}
 */
@Override
public void doSaveAs() {
    SaveAsDialog saveAsDialog = new SaveAsDialog(getEditorSite().getShell());
    if (getEditorInput() instanceof FileEditorInput)
        saveAsDialog.setOriginalFile(((FileEditorInput) getEditorInput()).getFile());
    else if (getEditorInput() instanceof FileStoreEditorInput)
        saveAsDialog.setOriginalName(((FileStoreEditorInput) getEditorInput()).getName());
    int ret = saveAsDialog.open();
    try {
        if (ret == Window.OK) {
            IPath targetPath = saveAsDialog.getResult();
            IFile targetFile = ResourcesPlugin.getWorkspace().getRoot().getFile(targetPath);
            if (!targetFile.exists()) {
                targetFile.create(null, true, null);
            }
            FileEditorInput editorInput = new FileEditorInput(targetFile);
            setInput(editorInput);
            setPartName(targetFile.getName());
            performSave();
        }
    } catch (CoreException e) {
        MessageDialog.openError(getSite().getShell(), "IO Error", e.getMessage());
        // $NON-NLS-1$
        OPIBuilderPlugin.getLogger().log(Level.WARNING, "File save error", e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) FileEditorInput(org.eclipse.ui.part.FileEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput) Point(org.eclipse.draw2d.geometry.Point)

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