Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 220735 Details for
Bug 154341
Make table row height smaller.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Helper class to work around bug 154341
EclipseBug154341Hack.java (text/x-java), 2.71 KB, created by
Torsten Witte
on 2012-09-05 10:30:47 EDT
(
hide
)
Description:
Helper class to work around bug 154341
Filename:
MIME Type:
Creator:
Torsten Witte
Created:
2012-09-05 10:30:47 EDT
Size:
2.71 KB
patch
obsolete
>import java.lang.reflect.InvocationTargetException; >import java.lang.reflect.Method; > >import org.eclipse.jface.viewers.TreeViewer; >import org.eclipse.swt.widgets.Tree; > >/** > * Hack to work around Eclipse Bug 154341. > * See <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=154341">https://bugs.eclipse.org/bugs/show_bug.cgi?id=154341</a> > */ >class EclipseBug154341Hack { > > /* > How it works: > > We use the workaround described by Chris Williams: > > Setting the font on the tree doesn't shrink it at all. > Returning a smaller height for all rows via a MeasureItem listener doesn't either. > > I'd prefer not to have to go down that low level to do custom drawing just to set the row height again. > I have platform specific code in reflection for mac and windows to handle this, but it's pretty ugly. > When font size changes on windows I call setItemHeight on the tree through reflection. > For Mac Cocoa I call setRowHeight on the view field on the Tree control via reflection. > */ > > /** > * Sets the item height of the given {@link TreeViewer} to the specified value. > * @param viewer the tree viewer to set the item height > * @param height the height to set, must be > 0 > */ > static void setItemHeight(TreeViewer viewer, int height) { > setItemHeight(viewer.getTree(), height); > } > > /** > * Sets the item height of the given {@link Tree} to the specified value. > * @param tree the tree to set the item height > * @param height the height to set, must be > 0 > */ > static void setItemHeight(Tree tree, int height) { > try { > Method method = null; > > Method[] methods = tree.getClass().getDeclaredMethods(); > method = findMethod(methods, "setItemHeight", 1); //$NON-NLS-1$ > if (method != null) { > boolean accessible = method.isAccessible(); > method.setAccessible(true); > method.invoke(tree, Integer.valueOf(height)); > method.setAccessible(accessible); > } > } catch (SecurityException e) { > // ignore > } catch (IllegalArgumentException e) { > // ignore > } catch (IllegalAccessException e) { > // ignore > } catch (InvocationTargetException e) { > // ignore > } > } > > /** > * Finds the method with the given name and parameter count from the specified methods. > * @param methods the methods to search through > * @param name the name of the method to find > * @param parameterCount the count of parameters of the method to find > * @return the method or <code>null</code> if not found > */ > private static Method findMethod(Method[] methods, String name, int parameterCount) { > for (Method method : methods) { > if (method.getName().equals(name) && method.getParameterTypes().length == parameterCount) { > return method; > } > } > return null; > } > >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 154341
: 220735