-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix groovy source image for resources outside classpath (source folders)
GroovyImageDecorator moves image selection into GroovyImageProvider (for PackageExplorer) and GroovyNavigatorLabelProvider (for ProjectExplorer). See #388
- Loading branch information
1 parent
5237482
commit 3ae1193
Showing
5 changed files
with
251 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...us.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/ui/GroovyNavigatorLabelProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2009-2018 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.codehaus.groovy.eclipse.ui; | ||
|
||
import static org.eclipse.jdt.internal.ui.JavaPlugin.getImageDescriptorRegistry; | ||
|
||
import org.codehaus.groovy.eclipse.ui.decorators.GroovyPluginImages; | ||
import org.codehaus.jdt.groovy.model.GroovyCompilationUnit; | ||
import org.eclipse.core.resources.IFile; | ||
import org.eclipse.jdt.groovy.core.util.ContentTypeUtils; | ||
import org.eclipse.jface.viewers.ILabelProvider; | ||
import org.eclipse.jface.viewers.ILabelProviderListener; | ||
import org.eclipse.swt.graphics.Image; | ||
|
||
public class GroovyNavigatorLabelProvider implements ILabelProvider { | ||
|
||
@Override | ||
public void addListener(ILabelProviderListener listener) { | ||
} | ||
|
||
@Override | ||
public void removeListener(ILabelProviderListener listener) { | ||
} | ||
|
||
@Override | ||
public void dispose() { | ||
} | ||
|
||
@Override | ||
public Image getImage(Object element) { | ||
if (element instanceof GroovyCompilationUnit) { | ||
return newGroovySourceImage(); | ||
} | ||
|
||
boolean isGradle = false; | ||
if (element instanceof IFile && ContentTypeUtils.isGroovyLikeFileName(((IFile) element).getName()) && | ||
!(isGradle = ContentTypeUtils.isGradleLikeFileName(((IFile) element).getName()))) { | ||
return newGroovySourceImage(); | ||
} | ||
if (isGradle) { | ||
newGradleScriptImage(); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public String getText(Object element) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isLabelProperty(Object element, String property) { | ||
return true; | ||
} | ||
|
||
private static Image newGradleScriptImage() { | ||
return getImageDescriptorRegistry().get( | ||
// Gradle files are a special case; image should be from Buildship plugin if it's present otherwise use Groovy's | ||
GroovyPluginImages.DESC_GRADLE_FILE != null ? GroovyPluginImages.DESC_GRADLE_FILE : GroovyPluginImages.DESC_GROOVY_FILE); | ||
} | ||
|
||
private static Image newGroovySourceImage() { | ||
return getImageDescriptorRegistry().get(GroovyPluginImages.DESC_GROOVY_FILE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
....groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/ui/decorators/GroovyImageProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* Copyright 2009-2018 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.codehaus.groovy.eclipse.ui.decorators; | ||
|
||
import org.codehaus.jdt.groovy.model.GroovyCompilationUnit; | ||
import org.eclipse.core.resources.IFile; | ||
import org.eclipse.jdt.core.IJavaElement; | ||
import org.eclipse.jdt.groovy.core.util.ContentTypeUtils; | ||
import org.eclipse.jdt.groovy.core.util.ReflectionUtils; | ||
import org.eclipse.jdt.internal.ui.packageview.PackageExplorerLabelProvider; | ||
import org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart; | ||
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider; | ||
import org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider; | ||
import org.eclipse.jface.resource.ImageDescriptor; | ||
import org.eclipse.ui.IPartListener2; | ||
import org.eclipse.ui.IWindowListener; | ||
import org.eclipse.ui.IWorkbenchPart; | ||
import org.eclipse.ui.IWorkbenchPartReference; | ||
import org.eclipse.ui.IWorkbenchWindow; | ||
import org.eclipse.ui.PlatformUI; | ||
|
||
public class GroovyImageProvider extends JavaElementImageProvider { | ||
|
||
private IWindowListener listener = new IWindowListener() { | ||
@Override | ||
public void windowOpened(IWorkbenchWindow window) { | ||
window.getActivePage().addPartListener(new IPartListener2() { | ||
@Override | ||
public void partOpened(IWorkbenchPartReference partRef) { | ||
IWorkbenchPart part = partRef.getPart(false); | ||
if (part instanceof PackageExplorerPart) { | ||
enhance((PackageExplorerPart) part); | ||
} | ||
} | ||
|
||
@Override | ||
public void partClosed(IWorkbenchPartReference partRef) { | ||
IWorkbenchPart part = partRef.getPart(false); | ||
if (part instanceof PackageExplorerPart) { | ||
} | ||
} | ||
|
||
@Override | ||
public void partActivated(IWorkbenchPartReference partRef) {} | ||
@Override | ||
public void partDeactivated(IWorkbenchPartReference partRef) {} | ||
@Override | ||
public void partHidden(IWorkbenchPartReference partRef) {} | ||
@Override | ||
public void partVisible(IWorkbenchPartReference partRef) {} | ||
@Override | ||
public void partBroughtToTop(IWorkbenchPartReference partRef) {} | ||
@Override | ||
public void partInputChanged(IWorkbenchPartReference partRef) {} | ||
}); | ||
} | ||
@Override | ||
public void windowClosed(IWorkbenchWindow window) {} | ||
@Override | ||
public void windowActivated(IWorkbenchWindow window) {} | ||
@Override | ||
public void windowDeactivated(IWorkbenchWindow window) {} | ||
}; | ||
|
||
//-------------------------------------------------------------------------- | ||
|
||
public GroovyImageProvider() { | ||
PlatformUI.getWorkbench().addWindowListener(listener); | ||
|
||
listener.windowOpened(PlatformUI.getWorkbench().getActiveWorkbenchWindow()); | ||
|
||
PackageExplorerPart packageExplorer = PackageExplorerPart.getFromActivePerspective(); | ||
if (packageExplorer != null) { | ||
enhance(packageExplorer); | ||
} | ||
} | ||
|
||
public void disconnect() { | ||
PlatformUI.getWorkbench().removeWindowListener(listener); | ||
} | ||
|
||
protected void enhance(PackageExplorerPart packageExplorer) { | ||
PackageExplorerLabelProvider fLabelProvider = ReflectionUtils.getPrivateField(PackageExplorerPart.class, "fLabelProvider", packageExplorer); | ||
if (fLabelProvider != null) { | ||
JavaElementImageProvider fImageLabelProvider = ReflectionUtils.getPrivateField(JavaUILabelProvider.class, "fImageLabelProvider", fLabelProvider); | ||
if (fImageLabelProvider != null && fImageLabelProvider != this) { fImageLabelProvider.dispose(); | ||
ReflectionUtils.setPrivateField(JavaUILabelProvider.class, "fImageLabelProvider", fLabelProvider, this); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public ImageDescriptor getCUResourceImageDescriptor(IFile file, int flags) { | ||
if (ContentTypeUtils.isGroovyLikeFileName(file.getName())) { | ||
return GroovyPluginImages.DESC_GROOVY_FILE; | ||
} | ||
return super.getCUResourceImageDescriptor(file, flags); | ||
} | ||
|
||
@Override | ||
public ImageDescriptor getJavaImageDescriptor(IJavaElement element, int flags) { | ||
if (element instanceof GroovyCompilationUnit) { | ||
return GroovyPluginImages.DESC_GROOVY_FILE; | ||
} | ||
return super.getJavaImageDescriptor(element, flags); | ||
} | ||
} |