SegFault
SegFault

Reputation: 1094

Add classes to org.eclipse.swt

I'm working on a Eclipse plugin which need to modify classes from the core packages of Eclipse. I want to write my own org.eclipse.swt.StyledText (not extend byt copy past the source code and modify some behaviors) and to instantiate it in org.eclipse.jface.text.TextViewer instead of the default StyledText.

It seems that the best way to modify TextViewer is to make my own version of the org.eclipse.jface plugin and to release it wrapped into a feature project.

But adding a class to swt package seems harder, first because there is different jars depending on the operating system used (org.eclipse.swt.cocoa, org.eclipse.swt.gtk ....) and also because copy pasting the code of StyledText is not that easy since there is call to external methods waiting for a strict StyledText.

Any ideas ?

Upvotes: 0

Views: 72

Answers (1)

Georgian
Georgian

Reputation: 8960

I did something similar with the org.eclipse.jface.preference.ColorSelector. I really needed a color widget that could accept a null value. This would be impossible to achieve without refactoring the widget.

Since overriding the respective class wasn't enough, because a lot of the functionality is encapsulated, I too wanted to modify the whole class directly.

Then again, as greg and Baz mentioned, it is a maintenance hell. Say you want to include this widget of yours in an RCP plugin. Then what do you do? The RCP platform provides its own SWT packages.

My solution was simple and straightforward. You copy-paste the entire class into a new one of your own, and simply use that one in your app.

But in your case, it seems that you are hitting more than one class (TextViewer and StyledText). Still, I would go with the copy-paste method ONLY if the desired behaviour exceeds the platform capabilities.

Upvotes: 1

Related Questions