Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLakshminarayana Nekkanti2019-08-01 11:00:11 +0000
committerMickael Istria2019-08-05 09:00:49 +0000
commit607288719f0b9ee2a5a9383dc71663a83d1d9c07 (patch)
tree174d1fa5e674e67a10f7a872fed07cf9dd10c1e8
parent33b7dfb9416086a6c58115ee7a08eb532a502c0c (diff)
downloadeclipse.platform.text-607288719f0b9ee2a5a9383dc71663a83d1d9c07.tar.gz
eclipse.platform.text-607288719f0b9ee2a5a9383dc71663a83d1d9c07.tar.xz
eclipse.platform.text-607288719f0b9ee2a5a9383dc71663a83d1d9c07.zip
Bug 549665 - [generic editor] Package Explorer should supportY20190805-0900
content-type specific icons for generic editor (edit) Change-Id: I51760d6d50729d4d159c18059f1dc67caf937d5b Signed-off-by: Lakshminarayana Nekkanti <narayana.nekkanti@gmail.com>
-rw-r--r--org.eclipse.ui.genericeditor/plugin.xml6
-rw-r--r--org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericEditorAssociationOverride.java64
-rw-r--r--org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericEditorDescriptor.java77
3 files changed, 147 insertions, 0 deletions
diff --git a/org.eclipse.ui.genericeditor/plugin.xml b/org.eclipse.ui.genericeditor/plugin.xml
index bb3ea5b8a..fa452caaa 100644
--- a/org.eclipse.ui.genericeditor/plugin.xml
+++ b/org.eclipse.ui.genericeditor/plugin.xml
@@ -224,4 +224,10 @@
id="org.eclipse.ui.genericeditor.compareViewer">
</viewer>
</extension>
+ <extension
+ point="org.eclipse.ui.ide.editorAssociationOverride">
+ <editorAssociationOverride
+ class="org.eclipse.ui.internal.genericeditor.GenericEditorAssociationOverride"
+ id="org.eclipse.ui.internal.genericeditor.GenericEditorAssociationOverride"/>
+ </extension>
</plugin>
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericEditorAssociationOverride.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericEditorAssociationOverride.java
new file mode 100644
index 000000000..ab275f14d
--- /dev/null
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericEditorAssociationOverride.java
@@ -0,0 +1,64 @@
+/********************************************************************************
+ * Copyright (c) 2019 Lakshminarayana Nekkanti(narayana.nekkanti@gmail.com)
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * SPDX-License-Identifier: EPL-2.0 3
+ *
+ * Contributor
+ * Lakshminarayana Nekkanti - initial API and implementation
+ ********************************************************************************/
+package org.eclipse.ui.internal.genericeditor;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.ide.IEditorAssociationOverride;
+
+public class GenericEditorAssociationOverride implements IEditorAssociationOverride {
+
+ private Map<String, IEditorDescriptor> descriptorMap = new HashMap<String, IEditorDescriptor>();
+
+ @Override
+ public IEditorDescriptor[] overrideEditors(IEditorInput editorInput, IContentType contentType,
+ IEditorDescriptor[] editorDescriptors) {
+ return overrideEditors(editorInput.getName(), contentType, editorDescriptors);
+ }
+
+ @Override
+ public IEditorDescriptor[] overrideEditors(String fileName, IContentType contentType,
+ IEditorDescriptor[] editorDescriptors) {
+ return Arrays.stream(editorDescriptors).map(descripter -> {
+ return getEditorDescriptorForFile(descripter, fileName);
+ }).toArray(size -> new IEditorDescriptor[size]);
+ }
+
+ @Override
+ public IEditorDescriptor overrideDefaultEditor(IEditorInput editorInput, IContentType contentType,
+ IEditorDescriptor editorDescriptor) {
+ return overrideDefaultEditor(editorInput.getName(), contentType, editorDescriptor);
+ }
+
+ @Override
+ public IEditorDescriptor overrideDefaultEditor(String fileName, IContentType contentType,
+ IEditorDescriptor editorDescriptor) {
+ return getEditorDescriptorForFile(editorDescriptor, fileName);
+ }
+
+ private IEditorDescriptor getEditorDescriptorForFile(IEditorDescriptor defaultDescripter, String fileName) {
+ if (defaultDescripter != null
+ && "org.eclipse.ui.genericeditor.GenericEditor".equals(defaultDescripter.getId())) { //$NON-NLS-1$
+ if (!descriptorMap.containsKey(fileName)) {
+ descriptorMap.put(fileName, new GenericEditorDescriptor(fileName, defaultDescripter));
+ }
+ return descriptorMap.get(fileName);
+ }
+ return defaultDescripter;
+ }
+}
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericEditorDescriptor.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericEditorDescriptor.java
new file mode 100644
index 000000000..39942aa49
--- /dev/null
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericEditorDescriptor.java
@@ -0,0 +1,77 @@
+/********************************************************************************
+ * Copyright (c) 2019 Lakshminarayana Nekkanti(narayana.nekkanti@gmail.com)
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * SPDX-License-Identifier: EPL-2.0 3
+ *
+ * Contributor
+ * Lakshminarayana Nekkanti - initial API and implementation
+ ********************************************************************************/
+package org.eclipse.ui.internal.genericeditor;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IEditorMatchingStrategy;
+
+public class GenericEditorDescriptor implements IEditorDescriptor {
+ private IEditorDescriptor editorDescriptor;
+ private String fileName;
+
+ public GenericEditorDescriptor(String fileName, IEditorDescriptor editorDescriptor) {
+ Assert.isNotNull(editorDescriptor);
+ this.fileName = fileName;
+ this.editorDescriptor = editorDescriptor;
+ }
+
+ @Override
+ public String getId() {
+ return this.editorDescriptor.getId();
+ }
+
+ @Override
+ public ImageDescriptor getImageDescriptor() {
+ try {
+ ImageDescriptor image = GenericEditorPlugin.getDefault().getContentTypeImagesRegistry()
+ .getImageDescriptor(Platform.getContentTypeManager().findContentTypesFor(fileName));
+ if (image != null) {
+ return image;
+ }
+ } catch (Exception e) {
+ GenericEditorPlugin.getDefault().getLog()
+ .log(new Status(IStatus.ERROR, GenericEditorPlugin.BUNDLE_ID, e.getMessage(), e));
+ }
+ return this.editorDescriptor.getImageDescriptor();
+ }
+
+ @Override
+ public String getLabel() {
+ return this.editorDescriptor.getLabel();
+ }
+
+ @Override
+ public boolean isInternal() {
+ return this.editorDescriptor.isInternal();
+ }
+
+ @Override
+ public boolean isOpenInPlace() {
+ return this.editorDescriptor.isOpenInPlace();
+ }
+
+ @Override
+ public boolean isOpenExternal() {
+ return this.editorDescriptor.isOpenExternal();
+ }
+
+ @Override
+ public IEditorMatchingStrategy getEditorMatchingStrategy() {
+ return this.editorDescriptor.getEditorMatchingStrategy();
+ }
+}

Back to the top