EditorPart and close button [message #449461] |
Mon, 24 January 2005 21:48 |
Eclipse User |
|
|
|
Originally posted by: wiz.vball.net
Hi,
I know for Views you can do the following
getViewLayout( PrioritiesView.ID_VIEW).setCloseable( false );
which gets rid of the close button for the view and the tab simply
shows name and icon... can this be applied to EditorPart... so i could
open an editor part and display its name and icon but not close button
so it can not be closed.
thanks,
Parwiz
|
|
|
|
Re: EditorPart and close button [message #449537 is a reply to message #449461] |
Tue, 25 January 2005 23:15 |
Eclipse User |
|
|
|
Originally posted by: barry.rapidmoney.com
FireFly wrote:
> Hi,
> I know for Views you can do the following
> getViewLayout( PrioritiesView.ID_VIEW).setCloseable( false );
> which gets rid of the close button for the view and the tab simply
> shows name and icon... can this be applied to EditorPart... so i could
> open an editor part and display its name and icon but not close button
> so it can not be closed.
> thanks,
> Parwiz
You can do it, but it's painful (at least the way I did it.) It basically
comes down to plugging in your own custom PresentationFactory. The way I
did it was in 4 steps:
1. Add an extension in your plugin.xml that looks like the following:
<extension
point="org.eclipse.ui.presentationFactories">
<factory
class="com.my.MySpecialPresentationFactory"
name="My Special Presentation"
id="my.SpecialPresentation"/>
</extension>
2. Write your PresentationFactory class, which subclasses the default
"WorkbenchPresentationFactory". You only need to override one method,
which is called "createEditorPresentation(...)" What I did was to copy
the source from the original method, and replace the first few lines with
the following...
public class MySpecialPresentationFactory extends
WorkbenchPresentationFactory {
public StackPresentation createEditorPresentation(Composite parent,
IStackPresentationSite site) {
DefaultTabFolder folder = new MySpecialTabFolder(parent, SWT.BORDER,
site.supportsState(IStackPresentationSite.STATE_MINIMIZED),
site.supportsState(IStackPresentationSite.STATE_MAXIMIZED));
... rest of method remains unchanged ...
3. Create your MySpecialTabFolder class as follows:
public class MySpecialTabFolder extends DefaultTabFolder {
public MySpecialTabFolder(Composite parent, int flags, boolean allowMin,
boolean allowMax) {
super(parent, flags, allowMin, allowMax);
}
public AbstractTabItem add(int index, int flags) {
// in our "special" editor tabs don't want "close" controls, so
// we remove them here
return super.add(index, flags ^ SWT.CLOSE);
}
}
4. Register your presentation factory. In your WorkbenchAdvisor class,
add the following line. (I added it in the preWindowOpen() method)
configurer.setPresentationFactory(new MySpecialPresentationFactory());
So, basically, this "special" tab folder removes the "CLOSE" bit from the
style flag, and you end up with a editor tab that cannot be closed by the
user.
Yes, a lot of steps, but it does work nicely.
Let me know if you have any more questions about this.
|
|
|
Powered by
FUDForum. Page generated in 0.01880 seconds