org.eclipse.ui.IEditorRegistry Java Examples

The following examples show how to use org.eclipse.ui.IEditorRegistry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestEditor.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
private void initializeTitle(IEditorInput input) {

		Image oldImage = fTitleImage;
		fTitleImage = null;
		String title = ""; //$NON-NLS-1$

		if (input != null) {
			IEditorRegistry editorRegistry = PlatformUI.getWorkbench()
					.getEditorRegistry();
			IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite()
					.getId());
			ImageDescriptor imageDesc = editorDesc != null ? editorDesc
					.getImageDescriptor() : null;

			fTitleImage = imageDesc != null ? imageDesc.createImage() : null;
			title = input.getName();
		}

		setTitleImage(fTitleImage);
		setPartName(title);

		firePropertyChange(PROP_DIRTY);

		if (oldImage != null && !oldImage.isDisposed())
			oldImage.dispose();
	}
 
Example #2
Source File: PyOpenResourceAction.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void openFiles(PythonpathZipChildTreeNode[] pythonPathFilesSelected) {
    for (PythonpathZipChildTreeNode n : pythonPathFilesSelected) {
        try {
            if (PythonPathHelper.isValidSourceFile(n.zipPath)) {
                new PyOpenAction().run(new ItemPointer(n.zipStructure.file, new Location(), new Location(), null,
                        n.zipPath));
            } else {
                IEditorRegistry editorReg = PlatformUI.getWorkbench().getEditorRegistry();
                IEditorDescriptor defaultEditor = editorReg.getDefaultEditor(n.zipPath);
                PydevZipFileStorage storage = new PydevZipFileStorage(n.zipStructure.file, n.zipPath);
                PydevZipFileEditorInput input = new PydevZipFileEditorInput(storage);

                if (defaultEditor != null) {
                    IDE.openEditor(page, input, defaultEditor.getId());
                } else {
                    IDE.openEditor(page, input, EditorsUI.DEFAULT_TEXT_EDITOR_ID);
                }
            }
        } catch (PartInitException e) {
            Log.log(e);
        }
    }
}
 
Example #3
Source File: SyncGraphvizExportHandler.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
private void openFile(IFile file) {
	IEditorRegistry registry = PlatformUI.getWorkbench()
			.getEditorRegistry();
	if (registry.isSystemExternalEditorAvailable(file.getName())) {

		/**
		 * in case of opening the exported file from an other thread e.g. in
		 * case of listening to an IResourceChangeEvent
		 */
		Display.getDefault().asyncExec(new Runnable() {

			@Override
			public void run() {
				IWorkbenchPage page = PlatformUI.getWorkbench()
						.getActiveWorkbenchWindow().getActivePage();
				try {
					page.openEditor(new FileEditorInput(file),
							IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
				} catch (PartInitException e) {
					DotActivatorEx.logError(e);
				}
			}
		});
	}
}
 
Example #4
Source File: TestEditor.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
private void initializeTitle(final IEditorInput input) {

        final Image oldImage = fTitleImage;
        fTitleImage = null;
        String title = ""; //$NON-NLS-1$

        if (input != null) {
            final IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
            final IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
            final ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null;

            fTitleImage = imageDesc != null ? imageDesc.createImage() : null;
            title = input.getName();
        }

        setTitleImage(fTitleImage);
        setPartName(title);

        firePropertyChange(PROP_DIRTY);

        if (oldImage != null && !oldImage.isDisposed())
            oldImage.dispose();
    }
 
Example #5
Source File: HtmlBrowserEditor.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
	setSite(site);
	setInput(input);
	setPartName(input.getName());
	
	Image oldTitleImage = titleImage;
	if (input != null) {
		IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
		IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
		ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null;
		titleImage = imageDesc != null ? imageDesc.createImage() : null;
	}

	setTitleImage(titleImage);
	if (oldTitleImage != null && !oldTitleImage.isDisposed()) {
		oldTitleImage.dispose();
	}

	FileEditorInput fileInput = (FileEditorInput) input;
	htmlUrl = fileInput.getFile().getLocation().toOSString();
}
 
Example #6
Source File: XLIFFEditor.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 启动编辑器。
 * 
 * @param site
 *            the site
 * @param input
 *            the input
 * @throws PartInitException
 *             the part init exception
 * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite,
 *      org.eclipse.ui.IEditorInput)
 */
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
	if (LOGGER.isDebugEnabled()) {
		LOGGER.debug("init(IEditorSite site, IEditorInput input)");
	}
	setSite(site);
	setInput(input);
	// 设置Editor标题栏的显示名称,否则名称用plugin.xml中的name属性
	setPartName(input.getName());

	Image oldTitleImage = titleImage;
	if (input != null) {
		IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
		IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
		ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null;
		titleImage = imageDesc != null ? imageDesc.createImage() : null;
	}

	setTitleImage(titleImage);
	if (oldTitleImage != null && !oldTitleImage.isDisposed()) {
		oldTitleImage.dispose();
	}

	getSite().setSelectionProvider(this);
}
 
Example #7
Source File: SVNConflictResolver.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private String getEditorId(IFileStore file) {
	IWorkbench workbench = PlatformUI.getWorkbench();
	IEditorRegistry editorRegistry= workbench.getEditorRegistry();
	IEditorDescriptor descriptor= editorRegistry.getDefaultEditor(file.getName(), getContentType(file));

	// check the OS for in-place editor (OLE on Win32)
	if (descriptor == null && editorRegistry.isSystemInPlaceEditorAvailable(file.getName()))
		descriptor= editorRegistry.findEditor(IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID);
	
	// check the OS for external editor
	if (descriptor == null && editorRegistry.isSystemExternalEditorAvailable(file.getName()))
		descriptor= editorRegistry.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
	
	if (descriptor != null)
		return descriptor.getId();
	
	return EditorsUI.DEFAULT_TEXT_EDITOR_ID;
}
 
Example #8
Source File: HtmlBrowserEditor.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
	setSite(site);
	setInput(input);
	setPartName(input.getName());
	
	Image oldTitleImage = titleImage;
	if (input != null) {
		IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
		IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
		ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null;
		titleImage = imageDesc != null ? imageDesc.createImage() : null;
	}

	setTitleImage(titleImage);
	if (oldTitleImage != null && !oldTitleImage.isDisposed()) {
		oldTitleImage.dispose();
	}

	FileEditorInput fileInput = (FileEditorInput) input;
	htmlUrl = fileInput.getFile().getLocation().toOSString();
}
 
Example #9
Source File: EditorUtil.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Open a file in an editor and return the opened editor part.<br>
 * This method will try to open the file in an internal editor, unless there is no editor descriptor assigned to
 * that file type.
 * 
 * @param file
 * @return The {@link IEditorPart} that was created when the file was opened; Return null in case of an error
 */
public static IEditorPart openInEditor(File file)
{
	// NOTE: Moved from PHP's EditorUtils
	if (file == null)
	{
		IdeLog.logError(CommonEditorPlugin.getDefault(),
				"Error open a file in the editor", new IllegalArgumentException("file is null")); //$NON-NLS-1$ //$NON-NLS-2$
		return null;
	}
	try
	{
		URI uri = file.toURI();
		IEditorDescriptor desc = getEditorDescriptor(uri);
		String editorId = (desc == null) ? IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID : desc.getId();
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

		return IDE.openEditor(page, uri, editorId, true);
	}
	catch (Exception e)
	{
		IdeLog.logError(CommonEditorPlugin.getDefault(), "Error open a file in the editor", e); //$NON-NLS-1$
	}
	return null;
}
 
Example #10
Source File: OpenJavaSourceAction.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private String getEditorId( IFileStore file )
{
	IWorkbench workbench = window.getWorkbench( );
	IEditorRegistry editorRegistry = workbench.getEditorRegistry( );
	IEditorDescriptor descriptor = editorRegistry.getDefaultEditor( file.getName( ),
			getContentType( file ) );

	// check the OS for in-place editor (OLE on Win32)
	if ( descriptor == null
			&& editorRegistry.isSystemInPlaceEditorAvailable( file.getName( ) ) )
	{
		descriptor = editorRegistry.findEditor( IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID );
	}

	// check the OS for external editor
	if ( descriptor == null
			&& editorRegistry.isSystemExternalEditorAvailable( file.getName( ) ) )
	{
		descriptor = editorRegistry.findEditor( IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID );
	}

	return ( descriptor == null ) ? "" : descriptor.getId( ); //$NON-NLS-1$
}
 
Example #11
Source File: XLIFFEditor.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 启动编辑器。
 * 
 * @param site
 *            the site
 * @param input
 *            the input
 * @throws PartInitException
 *             the part init exception
 * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite,
 *      org.eclipse.ui.IEditorInput)
 */
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
	if (LOGGER.isDebugEnabled()) {
		LOGGER.debug("init(IEditorSite site, IEditorInput input)");
	}
	setSite(site);
	setInput(input);
	// 设置Editor标题栏的显示名称,否则名称用plugin.xml中的name属性
	setPartName(input.getName());

	Image oldTitleImage = titleImage;
	if (input != null) {
		IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
		IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
		ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null;
		titleImage = imageDesc != null ? imageDesc.createImage() : null;
	}

	setTitleImage(titleImage);
	if (oldTitleImage != null && !oldTitleImage.isDisposed()) {
		oldTitleImage.dispose();
	}

	getSite().setSelectionProvider(this);
}
 
Example #12
Source File: OpenEditorUtil.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 使用系统默认编辑器打开文件
 * @param file
 *            IFile 对象(工作空间内的文件);
 */
public static void OpenFileWithSystemEditor(IFile file) {
	try {
		IDE.openEditor(getCurrentPage(), file, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
	} catch (PartInitException e) {
		e.printStackTrace();
	}
}
 
Example #13
Source File: OriginalEditorSelector.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected IEditorDescriptor getXtextEditor(URI uri) {
	IResourceServiceProvider serviceProvider = resourceServiceProviderRegistry.getResourceServiceProvider(uri);
	if (serviceProvider != null) {
		XtextEditorInfo editorInfo = serviceProvider.get(XtextEditorInfo.class);
		if (editorInfo != null) {
			IEditorRegistry editorRegistry = workbench.getEditorRegistry();
			IEditorDescriptor result = editorRegistry.findEditor(editorInfo.getEditorId());
			return result; // null is ok
		}
	}
	return null;
}
 
Example #14
Source File: XLFEditor.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
	if (LOGGER.isDebugEnabled()) {
		LOGGER.debug("init(IEditorSite site, IEditorInput input)");
	}
	setSite(site);
	setInput(input);

	// 设置Editor标题栏的显示名称,否则名称用plugin.xml中的name属性
	setPartName(input.getName());

	Image oldTitleImage = titleImage;
	if (input != null) {
		IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
		IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
		ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null;
		titleImage = imageDesc != null ? imageDesc.createImage() : null;
	}

	setTitleImage(titleImage);
	if (oldTitleImage != null && !oldTitleImage.isDisposed()) {
		oldTitleImage.dispose();
	}

	getSite().setSelectionProvider(this);

	cursorIbeam = new Cursor(null, SWT.CURSOR_IBEAM);
	cursorArrow = new Cursor(null, SWT.CURSOR_ARROW);

	hookListener();
}
 
Example #15
Source File: OpenEditorUtil.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 使用系统默认编辑器打开文件
 * @param page
 *            IWorkbenchPage 对象
 * @param uri
 *            ;
 */
public static void OpenFileWithSystemEditor(IWorkbenchPage page, URI uri) {
	try {
		IDE.openEditor(page, uri, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID, true);
	} catch (PartInitException e) {
		e.printStackTrace();
	}
}
 
Example #16
Source File: OpenEditorUtil.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 使用系统默认编辑器打开文件
 * @param file
 *            IFile 对象(工作空间内的文件);
 */
public static void OpenFileWithSystemEditor(IFile file) {
	try {
		IDE.openEditor(getCurrentPage(), file, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
	} catch (PartInitException e) {
		e.printStackTrace();
	}
}
 
Example #17
Source File: OpenFileAction.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private IEditorDescriptor getEditorDescriptor( IEditorInput input,
		boolean determineContentType )
{
	if ( input == null )
	{
		throw new IllegalArgumentException( );
	}
	IContentType contentType = Platform.getContentTypeManager( )
			.findContentTypeFor( input.getName( ) );
	IEditorRegistry editorReg = PlatformUI.getWorkbench( )
			.getEditorRegistry( );
	return editorReg.getDefaultEditor( input.getName( ), contentType );
}
 
Example #18
Source File: EditorOpener.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
private String getEditorID(IFile file) throws PartInitException {
    IEditorDescriptor desc = IDE.getEditorDescriptor(file);
    if (desc == null) {
        return PydevPlugin.getDefault().getWorkbench().getEditorRegistry()
                .findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID).getId();
    }
    return desc.getId();
}
 
Example #19
Source File: PyOpenExternalAction.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void openFiles(PythonpathTreeNode[] pythonPathFilesSelected) {
    for (PythonpathTreeNode n : pythonPathFilesSelected) {
        try {
            IDE.openEditor(page, EditorInputFactory.create(n.file, false),
                    IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
        } catch (PartInitException e) {
            Log.log(e);
        }
    }
}
 
Example #20
Source File: PyOpenExternalAction.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void openFiles(PythonpathZipChildTreeNode[] pythonPathFilesSelected) {
    for (PythonpathZipChildTreeNode n : pythonPathFilesSelected) {
        try {
            PydevZipFileStorage storage = new PydevZipFileStorage(n.zipStructure.file, n.zipPath);
            PydevZipFileEditorInput input = new PydevZipFileEditorInput(storage);
            IDE.openEditor(page, input, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
        } catch (PartInitException e) {
            Log.log(e);
        }
    }
}
 
Example #21
Source File: PyOpenExternalAction.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Overridden to open the given files with the match provided by the platform.
 */
@Override
protected void openFiles(List<IFile> filesSelected) {
    for (IFile f : filesSelected) {
        try {
            IDE.openEditor(page, f, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
        } catch (PartInitException e) {
            Log.log(e);
        }
    }
}
 
Example #22
Source File: URIHyperlink.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected IEditorDescriptor getEditorDescriptor()
{
	IEditorRegistry editorReg = PlatformUI.getWorkbench().getEditorRegistry();
	if (uri.getPath() == null || uri.getPath().equals("/") || uri.getPath().trim().equals("")) //$NON-NLS-1$ //$NON-NLS-2$
	{
		return null;
	}
	IPath path = new Path(uri.getPath());
	return editorReg.getDefaultEditor(path.lastSegment());
}
 
Example #23
Source File: AbapGitStagingService.java    From ADT_Frontend with MIT License 5 votes vote down vote up
private String getEditorId(String fileName) {
	if (fileName.endsWith("xml")) { //$NON-NLS-1$
		//if file type is .xml, return the associated XML editor
		IEditorRegistry editorReg = PlatformUI.getWorkbench().getEditorRegistry();
		IEditorDescriptor desc = editorReg.getDefaultEditor(fileName, Platform.getContentTypeManager().findContentTypeFor(fileName));
		if (desc != null) {
			return desc.getId();
		}
	}
	//use eclipse default text editor for all other files
	return IDEWorkbenchPlugin.DEFAULT_TEXT_EDITOR_ID;
}
 
Example #24
Source File: XtextEditor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Image getDefaultImage() {
	IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
	IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
	ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null;
	return imageDesc != null ? imageHelper.getImage(imageDesc) : super.getDefaultImage();
}
 
Example #25
Source File: AbstractExportDialog.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
@Override
protected void perfomeOK() throws Exception {
    try {
        final ProgressMonitorDialog monitor = new ProgressMonitorDialog(getShell());

        final ExportWithProgressManager manager = getExportWithProgressManager(settings.getExportSetting());

        manager.init(diagram, getBaseDir());

        final ExportManagerRunner runner = new ExportManagerRunner(manager);

        monitor.run(true, true, runner);

        if (runner.getException() != null) {
            throw runner.getException();
        }

        if (openAfterSavedButton != null && openAfterSavedButton.getSelection()) {
            final File openAfterSaved = openAfterSaved();

            final URI uri = openAfterSaved.toURI();

            final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

            if (openWithExternalEditor()) {
                IDE.openEditor(page, uri, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID, true);

            } else {
                final IFileStore fileStore = EFS.getStore(uri);
                IDE.openEditorOnFileStore(page, fileStore);
            }
        }

        // there is a case in another project
        diagram.getEditor().refreshProject();

    } catch (final InterruptedException e) {
        throw new InputException();
    }
}
 
Example #26
Source File: OpenXMLResultsAction.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static String getEditorId(File file) {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IEditorRegistry editorRegistry = workbench.getEditorRegistry();
    IEditorDescriptor descriptor = editorRegistry.getDefaultEditor(file.getName(), getContentType(file));
    if (descriptor != null) {
        return descriptor.getId();
    }
    return EditorsUI.DEFAULT_TEXT_EDITOR_ID;
}
 
Example #27
Source File: ViewLogCommandHandler.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param filePath
 *            TODO: we should really make this into a utility function, and have the Ruble::Editor.open method use
 *            it. But I am giving up for now because Eclipse plugin dependencies drive me crazy!
 */
private void openEditorForFile(String filePath)
{
	File file = new File(filePath);
	// Process an existing file.
	if (file.exists() && file.isFile())
	{
		Path path = new Path(filePath);
		IFile fileForLocation = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
		IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
		IEditorDescriptor editorDescriptor = null;
		if (fileForLocation == null)
		{
			IContentType contentType = Platform.getContentTypeManager().findContentTypeFor(filePath);
			editorDescriptor = editorRegistry.getDefaultEditor(filePath, contentType);
		}
		else
		{
			editorDescriptor = editorRegistry.getDefaultEditor(filePath);
		}
		String editorId = (editorDescriptor == null) ? "com.aptana.editor.text" : editorDescriptor.getId(); //$NON-NLS-1$
		try
		{
			IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file.toURI(),
					editorId, true);
		}
		catch (PartInitException e)
		{
			IdeLog.logError(UIPlugin.getDefault(), e);
		}
	}
}
 
Example #28
Source File: OpenEditorUtil.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 使用系统默认编辑器打开文件
 * @param page
 *            IWorkbenchPage 对象
 * @param uri
 *            ;
 */
public static void OpenFileWithSystemEditor(IWorkbenchPage page, URI uri) {
	try {
		IDE.openEditor(page, uri, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID, true);
	} catch (PartInitException e) {
		e.printStackTrace();
	}
}
 
Example #29
Source File: EditorInputTransferDragAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void dragStart(DragSourceEvent event) {
	fEditorInputDatas= new ArrayList<EditorInputData>();

	ISelection selection= fProvider.getSelection();
	if (selection instanceof IStructuredSelection) {
		IStructuredSelection structuredSelection= (IStructuredSelection) selection;
		for (Iterator<?> iter= structuredSelection.iterator(); iter.hasNext();) {
			Object element= iter.next();
			IEditorInput editorInput= EditorUtility.getEditorInput(element);
			if (editorInput != null && editorInput.getPersistable() != null) {
				try {
					String editorId= EditorUtility.getEditorID(editorInput);
					// see org.eclipse.ui.internal.ide.EditorAreaDropAdapter.openNonExternalEditor(..):
					IEditorRegistry editorReg= PlatformUI.getWorkbench().getEditorRegistry();
					IEditorDescriptor editorDesc= editorReg.findEditor(editorId);
					if (editorDesc != null && !editorDesc.isOpenExternal()) {
						fEditorInputDatas.add(EditorInputTransfer.createEditorInputData(editorId, editorInput));
					}
				} catch (PartInitException e) {
					JavaPlugin.log(e);
				}
			}
		}
	}

	event.doit= fEditorInputDatas.size() > 0;
}
 
Example #30
Source File: XLFEditor.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
	if (LOGGER.isDebugEnabled()) {
		LOGGER.debug("init(IEditorSite site, IEditorInput input)");
	}
	setSite(site);
	setInput(input);

	// 设置Editor标题栏的显示名称,否则名称用plugin.xml中的name属性
	setPartName(input.getName());

	Image oldTitleImage = titleImage;
	if (input != null) {
		IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
		IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
		ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null;
		titleImage = imageDesc != null ? imageDesc.createImage() : null;
	}

	setTitleImage(titleImage);
	if (oldTitleImage != null && !oldTitleImage.isDisposed()) {
		oldTitleImage.dispose();
	}

	getSite().setSelectionProvider(this);

	cursorIbeam = new Cursor(null, SWT.CURSOR_IBEAM);
	cursorArrow = new Cursor(null, SWT.CURSOR_ARROW);

	hookListener();
}