Search in sources :

Example 1 with IFileEditorMapping

use of org.eclipse.ui.IFileEditorMapping in project epp.mpc by eclipse.

the class ShowFileSupportProposalsJob method runInUIThread.

@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
    final Shell shell = WorkbenchUtil.getShell();
    String fileExtensionLabel = DiscoverFileSupportJob.getFileExtensionLabel(fileName);
    final ShowFileSupportProposalsDialog dialog = new ShowFileSupportProposalsDialog(shell, fileExtensionLabel, defaultDescriptor);
    if (dialog.open() == IDialogConstants.OK_ID) {
        if (dialog.isShowProposals()) {
            IMarketplaceClientService marketplaceClientService = MarketplaceClient.getMarketplaceClientService();
            IMarketplaceClientConfiguration config = marketplaceClientService.newConfiguration();
            marketplaceClientService.open(config, new LinkedHashSet<INode>(nodes));
        } else if (dialog.isAssociateToExtension()) {
            List<String> fileExtensions = DiscoverFileSupportJob.getFileExtensions(fileName);
            IFileEditorMapping newMapping = createDefaultDescriptorMapping(fileExtensions.get(fileExtensions.size() - 1));
            addEditorMapping(newMapping);
        }
        return Status.OK_STATUS;
    } else {
        return Status.CANCEL_STATUS;
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) INode(org.eclipse.epp.mpc.core.model.INode) IMarketplaceClientConfiguration(org.eclipse.epp.mpc.ui.IMarketplaceClientConfiguration) IMarketplaceClientService(org.eclipse.epp.mpc.ui.IMarketplaceClientService) List(java.util.List) IFileEditorMapping(org.eclipse.ui.IFileEditorMapping)

Example 2 with IFileEditorMapping

use of org.eclipse.ui.IFileEditorMapping in project epp.mpc by eclipse.

the class ShowFileSupportProposalsJob method createDefaultDescriptorMapping.

// need internal API:
// * https://bugs.eclipse.org/bugs/show_bug.cgi?id=110602
// * https://www.eclipse.org/forums/index.php/t/98199/
@SuppressWarnings("restriction")
private IFileEditorMapping createDefaultDescriptorMapping(String fileExtension) {
    FileEditorMapping newMapping = null;
    if (fileName.equals(fileExtension)) {
        newMapping = new FileEditorMapping(fileName, null);
    } else {
        newMapping = new FileEditorMapping(fileExtension);
    }
    newMapping.setDefaultEditor(defaultDescriptor);
    return newMapping;
}
Also used : IFileEditorMapping(org.eclipse.ui.IFileEditorMapping) FileEditorMapping(org.eclipse.ui.internal.registry.FileEditorMapping)

Example 3 with IFileEditorMapping

use of org.eclipse.ui.IFileEditorMapping in project n4js by eclipse.

the class N4JSApplicationWorkbenchWindowAdvisor method updateDefaultEditorMappingIfAbsent.

private void updateDefaultEditorMappingIfAbsent() {
    final EditorRegistry registry = (EditorRegistry) WorkbenchPlugin.getDefault().getEditorRegistry();
    for (final IFileEditorMapping editorMapping : registry.getFileEditorMappings()) {
        final IEditorDescriptor defaultEditor = editorMapping.getDefaultEditor();
        if (null == defaultEditor) {
            final String extension = editorMapping.getExtension();
            LOGGER.info("No default editor is associated with files with extension: '." + extension + "'.");
            final IEditorDescriptor defaultTextEditor = registry.findEditor(DEFAULT_TEXT_EDITOR_ID);
            if (null != defaultTextEditor) {
                ((FileEditorMapping) editorMapping).setDefaultEditor(defaultTextEditor);
                String editorName = defaultTextEditor.getLabel();
                if (null == editorName) {
                    editorName = defaultTextEditor.getId();
                }
                if (null != editorName) {
                    LOGGER.info("Associated files with extension " + extension + " with '" + editorName + "'.");
                }
            }
        }
    }
    registry.saveAssociations();
    PrefUtil.savePrefs();
}
Also used : EditorRegistry(org.eclipse.ui.internal.registry.EditorRegistry) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IFileEditorMapping(org.eclipse.ui.IFileEditorMapping) FileEditorMapping(org.eclipse.ui.internal.registry.FileEditorMapping) IFileEditorMapping(org.eclipse.ui.IFileEditorMapping)

Aggregations

IFileEditorMapping (org.eclipse.ui.IFileEditorMapping)3 FileEditorMapping (org.eclipse.ui.internal.registry.FileEditorMapping)2 List (java.util.List)1 INode (org.eclipse.epp.mpc.core.model.INode)1 IMarketplaceClientConfiguration (org.eclipse.epp.mpc.ui.IMarketplaceClientConfiguration)1 IMarketplaceClientService (org.eclipse.epp.mpc.ui.IMarketplaceClientService)1 Shell (org.eclipse.swt.widgets.Shell)1 IEditorDescriptor (org.eclipse.ui.IEditorDescriptor)1 EditorRegistry (org.eclipse.ui.internal.registry.EditorRegistry)1