org.eclipse.ui.IFileEditorMapping源码实例Demo

类org.eclipse.ui.IFileEditorMapping源码实例Demo

下面列出了org.eclipse.ui.IFileEditorMapping 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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();
}
 
源代码2 项目: gwt-eclipse-plugin   文件: Util.java
public static void resetDefaultEditor(String extension) {
  EditorRegistry editorRegistry = (EditorRegistry) PlatformUI.getWorkbench().getEditorRegistry();
  IFileEditorMapping[] editorMappings = editorRegistry.getFileEditorMappings();

  // Search the file=>editor mappings for the specified extension
  for (IFileEditorMapping editorMapping : editorMappings) {
    if (extension.equals(editorMapping.getExtension())) {
      FileEditorMapping internalMapping = (FileEditorMapping) editorMapping;
      // Only need to do anything if there's an explicit default set
      if (internalMapping.getDeclaredDefaultEditors().length > 0) {
        // Clear any default editor associations for this extension

        List<IEditorDescriptor> list = new ArrayList<IEditorDescriptor>();
        internalMapping.setDefaultEditors(list);

        // Save the updated editor registry to disk
        editorRegistry.saveAssociations();

        // TODO: remove
        GWTPluginLog.logInfo("Reset default editor for extension: "
            + extension);
      }
      break;
    }
  }
}
 
源代码3 项目: jd-eclipse   文件: JavaDecompilerPlugin.java
public void run() {
	EditorRegistry registry = (EditorRegistry)WorkbenchPlugin.getDefault().getEditorRegistry();
	
	IFileEditorMapping[] mappings = registry.getFileEditorMappings();
	IFileEditorMapping c = null;
	IFileEditorMapping cws = null;
	
	// Search Class file editor mappings
	for (IFileEditorMapping mapping : mappings) {
		if (mapping.getExtension().equals("class")) {
			// ... Helios 3.6, Indigo 3.7, Juno 4.2, Kepler 4.3, ...
			c = mapping;
		} else if (mapping.getExtension().equals("class without source")) {
			// Juno 4.2, Kepler 4.3, ...
			cws = mapping;
		}
	}

	if ((c != null) && (cws != null)) {
		// Search JD editor descriptor on "class" extension
		for (IEditorDescriptor descriptor : c.getEditors()) {		
			if (descriptor.getId().equals(EDITOR_ID)) {
				// Remove JD editor on "class" extension
				((FileEditorMapping)c).removeEditor((EditorDescriptor)descriptor);

				// Set JD as default editor on "class without source" extension
				registry.setDefaultEditor("." + cws.getExtension(), descriptor.getId());
				break;
			}
		}
		
		// Restore the default editor for "class" extension
		IEditorDescriptor defaultClassFileEditor = registry.findEditor(JavaUI.ID_CF_EDITOR);
		
		if (defaultClassFileEditor != null) {
			registry.setDefaultEditor("." + c.getExtension(), JavaUI.ID_CF_EDITOR);
		}				
		
		registry.setFileEditorMappings((FileEditorMapping[]) mappings);
		registry.saveAssociations();			
	}
}
 
private Image getImageForJarEntry(IStorage element) {
	if (element instanceof IJarEntryResource && !((IJarEntryResource) element).isFile()) {
		return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
	}

	if (fJarImageMap == null)
		return getDefaultImage();

	if (element == null || element.getName() == null)
		return getDefaultImage();

	// Try to find icon for full name
	String name= element.getName();
	Image image= fJarImageMap.get(name);
	if (image != null)
		return image;
	IFileEditorMapping[] mappings= getEditorRegistry().getFileEditorMappings();
	int i= 0;
	while (i < mappings.length) {
		if (mappings[i].getLabel().equals(name))
			break;
		i++;
	}
	String key= name;
	if (i == mappings.length) {
		// Try to find icon for extension
		IPath path= element.getFullPath();
		if (path == null)
			return getDefaultImage();
		key= path.getFileExtension();
		if (key == null)
			return getDefaultImage();
		image= fJarImageMap.get(key);
		if (image != null)
			return image;
	}

	// Get the image from the editor registry
	ImageDescriptor desc= getEditorRegistry().getImageDescriptor(name);
	image= desc.createImage();

	fJarImageMap.put(key, image);

	return image;
}
 
@Override
public void earlyStartup() {
    if (PlatformUtil.isHeadless()) {
        return;//Do not execute earlyStartup in headless mode
    }
    final IConfigurationElement[] elements = BonitaStudioExtensionRegistryManager.getInstance()
            .getConfigurationElements(
                    "org.bonitasoft.studio.common.poststartup"); //$NON-NLS-1$
    for (final IConfigurationElement elem : elements) {
        final Workbench workbench = (Workbench) PlatformUI.getWorkbench();
        try {
            IPostStartupContribution contrib = (IPostStartupContribution) ContextInjectionFactory
                    .make(Platform.getBundle(elem.getDeclaringExtension().getNamespaceIdentifier())
                            .loadClass(elem.getAttribute("class")), workbench.getContext());
            Display.getDefault().asyncExec(contrib::execute);
        } catch (InjectionException | ClassNotFoundException | InvalidRegistryObjectException e) {
            BonitaStudioLog.error(e);
        }
    }

    preLoad();
    
    // Fix issue with asciidoctor plugin overriding text content-type
    final EditorRegistry editorRegistry = (EditorRegistry) WorkbenchPlugin.getDefault().getEditorRegistry();
    IFileEditorMapping[] fileEditorMappings = editorRegistry.getFileEditorMappings();
    List<IFileEditorMapping> mappings = Stream.of(fileEditorMappings).collect(Collectors.toList());
    FileEditorMapping mapping = new FileEditorMapping("*", "log");
    mapping.setDefaultEditor(editorRegistry.findEditor("org.eclipse.ui.DefaultTextEditor"));
    mappings.add(mapping);
    Display.getDefault().asyncExec(()-> editorRegistry.setFileEditorMappings(mappings.toArray(new FileEditorMapping[] {})));
    editorRegistry.setDefaultEditor("*.txt", "org.eclipse.ui.DefaultTextEditor");
    
    final long startupDuration = System.currentTimeMillis() - BonitaStudioApplication.START_TIME;
    BonitaStudioLog.info("Startup duration : " + DateUtil.getDisplayDuration(startupDuration),
            ApplicationPlugin.PLUGIN_ID);
    ApplicationPlugin.getDefault().getPreferenceStore().setDefault(FIRST_STARTUP, true);
    if (isFirstStartup()) {
        new OpenReleaseNoteHandler().setFocus(false).asView().openBrowser();
    }
    ApplicationPlugin.getDefault().getPreferenceStore().setValue(FIRST_STARTUP, false);
}
 
源代码评论
动弹
沙发等你来抢
 类所在包
 类方法
 同包方法