How to Write
Bad Eclipse Plug-ins
Alex Blewitt
@alblue
Originally presented at Eclipse Night London
16 September 2015
Slide 2
Slide 2 text
Bad Eclipse Plug-ins
• This talk will present anti-patterns for
Eclipse plug-in development
• Use these techniques in order to degrade a
user's experience of Eclipse
• Bad plug-ins don't just happen by accident!
Slide 3
Slide 3 text
Bad Eclipse Plug-ins
• This talk will present anti-patterns for
Eclipse plug-in development
• Use these techniques in order to degrade a
user's experience of Eclipse
• Bad plug-ins don't just happen by accident!
Slide 4
Slide 4 text
First impressions
• First impressions last - make them count
• Display a splash screen specifically for your plug-in
• Otherwise how will they know what plug-in they
have installed?
• Use new Shell() and resize to size of window for
maximum effect
• Preferably whilst they're in the middle of something
Slide 5
Slide 5 text
First impressions
• First impressions last - make them count
• Display a splash screen specifically for your plug-in
• Otherwise how will they know what plug-in they
have installed?
• Use new Shell() and resize to size of window for
maximum effect
• Preferably whilst they're in the middle of something
Slide 6
Slide 6 text
Have a Dialog with user
• If a splash screen won't fit then consider a
Dialog instead
• For maximum benefit, show whilst typing –
easier to accidentally press one of the buttons
• Register a KeyListener on the SWT container
to receive notifications of when they are typing
Slide 7
Slide 7 text
Rentware
• Dialogs are great for rentware
• Remind the user to pay up or the software will
stop working
• Allow the dialog to be dismissed, but come back
• Bonus points for having it in a different place
• Punch the Money!
Slide 8
Slide 8 text
Rentware
• Dialogs are great for rentware
• Remind the user to pay up or the software will
stop working
• Allow the dialog to be dismissed, but come back
• Bonus points for having it in a different place
• Punch the Money!
Slide 9
Slide 9 text
Rentware
• Dialogs are great for rentware
• Remind the user to pay up or the software will
stop working
• Allow the dialog to be dismissed, but come back
• Bonus points for having it in a different place
• Punch the Money!
Slide 10
Slide 10 text
Rentware
• Dialogs are great for rentware
• Remind the user to pay up or the software will
stop working
• Allow the dialog to be dismissed, but come back
• Bonus points for having it in a different place
• Punch the Money!
Slide 11
Slide 11 text
Interactive dialog
• Dialogs can be interactive too
• Why not add a payment field into the dialog?
• Take a credit card number
• Add a field listener to validate number; use the
LUHN check to determine if card is valid
• Enable payment button when valid
Slide 12
Slide 12 text
Interactive dialog
• Dialogs can be interactive too
• Why not add a payment field into the dialog?
• Take a credit card number
• Add a field listener to validate number; use the
LUHN check to determine if card is valid
• Enable payment button when valid
Slide 13
Slide 13 text
Interactive dialog
• Dialogs can be interactive too
• Why not add a payment field into the dialog?
• Take a credit card number
• Add a field listener to validate number; use the
LUHN check to determine if card is valid
• Enable payment button when valid
Slide 14
Slide 14 text
Notifications
• Another option is to use Mylyn Notifications
• Pop-up dialogs in bottom right of screen
• Problems with this approach
• Notification goes away after inactivity
• User doesn't get distracted
• Limited click-through conversion rate!
Slide 15
Slide 15 text
Combine them!
• Splash screen AND field input
• What's not to like?
• Use them to unlock functionality
• Good way of populating marketing lists
Slide 16
Slide 16 text
Combine them!
• Splash screen AND field input
• What's not to like?
• Use them to unlock functionality
• Good way of populating marketing lists
Slide 17
Slide 17 text
Assume the Networks
• Only successful people use Eclipse
• Clearly they can afford in-flight WiFi ✈
• If their computer isn't connected, it's their fault
• Make sure to log lots of errors (or just fail)
• Automated Error Reporter is lonely
• Who uses firewalls anyway? ⛔
Slide 18
Slide 18 text
On the Job – the UIJob
• Your plug-in is the most important plug-in the
user has installed
• Instead of running a Job in the background, use
UIJob instead
• Especially if using the filesystem or network
• Everyone loves the beachball!
Slide 19
Slide 19 text
Reporting Progress
• IProgressMonitor allows progress to be reported
• Can avoid giving any hints by avoiding setting
amount of work - use UNKNOWN (-1)
• Ignore cancellations
• Pretty animations!
Slide 20
Slide 20 text
Bundle Activator
• Bundle-Activator is an opportunity for delays
• Eclipse start-up is serial activation of activators
• Single bundle can take down Eclipse!
• Thread.sleep(1000000…)
• Even if bundle does nothing useful, leave the
Activator in there – shows you used a template
Slide 21
Slide 21 text
Bundle Activator
• Bundle-Activator is an opportunity for delays
• Eclipse start-up is serial activation of activators
• Single bundle can take down Eclipse!
• Thread.sleep(1000000…)
• Even if bundle does nothing useful, leave the
Activator in there – shows you used a template
258 classes out of
762 bundles can't
be wrong!
Slide 22
Slide 22 text
Activators are the
• When you reference a class from a bundle it
triggers activation automatically if the following:
• Bundle-ActivationPolicy: lazy
• Referring to a class is enough to cause delays!
• Useful in combination with static blocks
Slide 23
Slide 23 text
Activators are the
• When you reference a class from a bundle it
triggers activation automatically if the following:
• Bundle-ActivationPolicy: lazy
• Referring to a class is enough to cause delays!
• Useful in combination with static blocks
static {
ImageDescriptor img = …
JFaceResources.
getImageRegistry().
put(…,img)
}
Added 100k+ to application load by
triggering ImageRegistry creation
Slide 24
Slide 24 text
Laziness is overrated
• Why be lazy when you can be active?
• Better to be fit
• IStartup provides ultimate active extension
• earlyStartup() – use resources actively at start
• Use UIJob().schedule(0) for immediate effect
• Don't use declarative services – multi threaded
Slide 25
Slide 25 text
IInterface and
IImplementation
• Eclipse ❤ Iinterfaces
• Put IInterface and IImplementation in same
bundle so they won't get lost
• Bonus: refer to the interface, activate the
bundle!
• Ensure you always cast the interface to hidden
internal implementation class to prevent reuse!
Slide 26
Slide 26 text
IInterface2
• Even better, interfaces can be versioned!
• IInterface2
• IInterface3
• IInterface4
• IInterface∞
!
!
Never delete code!
Never revoke an API!
If it was good enough for Eclipse
2.1 then it is good enough for you!
Slide 27
Slide 27 text
Avoid new-fangled code
• Most Eclipse APIs don't use generics –
why should you?
• Avoid new annotations like @Inject and
@EventTopic – these aren't yet decades old
• Why use command and handler when Action is
still used by the platform?
Slide 28
Slide 28 text
Graphics Leaks
• SWT is a great library for being able to leak resources
• ERROR_NO_HANDLES
• Just forget to call dispose() on your Resource
• Don't use:
• ImageRegistry, ColorRegistry, FontRegistry
• Sleak, SWTBot
Slide 29
Slide 29 text
Summary
• Use splash screens, dialogs and interruptions
• Rentware is highly popular
• Assume the network is always available
• Use UIJob instead of Job to block the interface
• Don't estimate progress; or check for cancel
Slide 30
Slide 30 text
Summary
• Put all your complex logic in Bundle Activators
• Run tasks in IStartup with zero delay for priority
• Use static blocks of code to avoid lazy code
• Mix interface & implementation in same bundle
• Avoid declarative services, @Inject, commands