简体   繁体   English

将类添加到org.eclipse.swt

[英]Add classes to org.eclipse.swt

I'm working on a Eclipse plugin which need to modify classes from the core packages of Eclipse. 我正在开发一个Eclipse插件,该插件需要修改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. 我想编写自己的org.eclipse.swt.StyledText(不要通过源代码复制扩展并修改某些行为),并在org.eclipse.jface.text.TextViewer中实例化它,而不是默认的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. 似乎修改TextViewer的最好方法是制作自己的org.eclipse.jface插件版本并将其包装到功能项目中。

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. 但是将类添加到swt包似乎更困难,首先是因为根据所使用的操作系统(org.eclipse.swt.cocoa,org.eclipse.swt.gtk ....)存在不同的jar,并且还因为复制粘贴了代码StyledText的实现不是那么容易,因为需要调用外部方法来等待严格的StyledText。

Any ideas ? 有任何想法吗 ?

I did something similar with the org.eclipse.jface.preference.ColorSelector . 我对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. 再次,正如greg和Baz提到的,这是一个维护地狱。 Say you want to include this widget of yours in an RCP plugin. 假设您要在RCP插件中包含此小部件。 Then what do you do? 那你怎么办 The RCP platform provides its own SWT packages. RCP平台提供了自己的SWT程序包。

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 ). 但是在您的情况下,您似乎遇到了多个类( TextViewerStyledText )。 Still, I would go with the copy-paste method ONLY if the desired behaviour exceeds the platform capabilities. 不过,只有在所需行为超出平台功能的情况下,我才使用复制粘贴方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM