17
17
18
18
import static org .eclipse .swt .events .SelectionListener .widgetSelectedAdapter ;
19
19
20
+ import java .beans .PropertyChangeListener ;
20
21
import java .util .ArrayList ;
21
22
import java .util .List ;
22
23
import org .eclipse .core .commands .AbstractHandler ;
32
33
import org .eclipse .jface .dialogs .IPageChangeProvider ;
33
34
import org .eclipse .jface .dialogs .IPageChangedListener ;
34
35
import org .eclipse .jface .dialogs .PageChangedEvent ;
36
+ import org .eclipse .jface .preference .IPreferenceStore ;
35
37
import org .eclipse .jface .resource .ImageDescriptor ;
38
+ import org .eclipse .jface .util .PropertyChangeEvent ;
36
39
import org .eclipse .jface .util .SafeRunnable ;
37
40
import org .eclipse .jface .viewers .ISelectionProvider ;
38
41
import org .eclipse .jface .viewers .SelectionChangedEvent ;
56
59
import org .eclipse .ui .IPartService ;
57
60
import org .eclipse .ui .IWorkbenchPart ;
58
61
import org .eclipse .ui .IWorkbenchPartSite ;
62
+ import org .eclipse .ui .IWorkbenchPreferenceConstants ;
59
63
import org .eclipse .ui .PartInitException ;
60
64
import org .eclipse .ui .handlers .IHandlerService ;
61
65
import org .eclipse .ui .internal .PartSite ;
62
66
import org .eclipse .ui .internal .WorkbenchPlugin ;
63
67
import org .eclipse .ui .internal .misc .Policy ;
64
68
import org .eclipse .ui .internal .services .INestable ;
65
69
import org .eclipse .ui .internal .services .IServiceLocatorCreator ;
70
+ import org .eclipse .ui .internal .util .PrefUtil ;
66
71
import org .eclipse .ui .services .IDisposable ;
67
72
import org .eclipse .ui .services .IServiceLocator ;
68
73
@@ -149,10 +154,31 @@ public abstract class MultiPageEditorPart extends EditorPart implements IPageCha
149
154
private ListenerList <IPageChangedListener > pageChangeListeners = new ListenerList <>(ListenerList .IDENTITY );
150
155
151
156
/**
152
- * Creates an empty multi-page editor with no pages.
157
+ * Creates an empty multi-page editor with no pages and registers a
158
+ * {@link PropertyChangeListener} to listen for changes to the editor's
159
+ * preference..
153
160
*/
154
161
protected MultiPageEditorPart () {
155
162
super ();
163
+ getAPIPreferenceStore ().addPropertyChangeListener (event -> {
164
+ handlePropertyChange (event );
165
+ });
166
+ }
167
+
168
+ /**
169
+ * Handles property change events related to editor preferences.
170
+ *
171
+ * <p>
172
+ * This method is invoked when a property change occurs in the preference store.
173
+ * </p>
174
+ *
175
+ * @param event the {@link PropertyChangeEvent} triggered by a change in the
176
+ * preference store
177
+ */
178
+ private void handlePropertyChange (PropertyChangeEvent event ) {
179
+ if (event .getProperty ().equals (IWorkbenchPreferenceConstants .ALIGN_MULTI_PAGE_EDITOR_TABS_ON_TOP )) {
180
+ updateContainer ();
181
+ }
156
182
}
157
183
158
184
/**
@@ -264,7 +290,7 @@ protected CTabFolder createContainer(Composite parent) {
264
290
// use SWT.FLAT style so that an extra 1 pixel border is not reserved
265
291
// inside the folder
266
292
parent .setLayout (new FillLayout ());
267
- final CTabFolder newContainer = new CTabFolder (parent , SWT . BOTTOM | SWT . FLAT );
293
+ final CTabFolder newContainer = new CTabFolder (parent , getPreferredTabStyle () );
268
294
newContainer .addSelectionListener (widgetSelectedAdapter (e -> {
269
295
int newPageIndex = newContainer .indexOf ((CTabItem ) e .item );
270
296
pageChange (newPageIndex );
@@ -291,6 +317,31 @@ protected CTabFolder createContainer(Composite parent) {
291
317
return newContainer ;
292
318
}
293
319
320
+ /**
321
+ * Determines the preferred tab style based on user preferences.
322
+ * <p>
323
+ * This method retrieves the user preference for aligning multi-page editor tabs
324
+ * on top or bottom, and returns the corresponding SWT style constant.
325
+ * </p>
326
+ *
327
+ * @return {@code SWT.TOP} if the user prefers tabs to be aligned on top,
328
+ * {@code SWT.BOTTOM} if the user prefers tabs to be aligned on the
329
+ * bottom.
330
+ */
331
+ private int getPreferredTabStyle () {
332
+ boolean alignTabsOnTop = getAPIPreferenceStore ()
333
+ .getBoolean (IWorkbenchPreferenceConstants .ALIGN_MULTI_PAGE_EDITOR_TABS_ON_TOP );
334
+ int style = alignTabsOnTop ? SWT .TOP : SWT .BOTTOM ;
335
+ return style ;
336
+ }
337
+
338
+ /**
339
+ * @since 3.133
340
+ */
341
+ protected IPreferenceStore getAPIPreferenceStore () {
342
+ return PrefUtil .getAPIPreferenceStore ();
343
+ }
344
+
294
345
/**
295
346
* Creates a tab item at the given index and places the given control in the new
296
347
* item. The item is a CTabItem with no style bits set.
@@ -1230,4 +1281,13 @@ public void run() {
1230
1281
});
1231
1282
}
1232
1283
}
1284
+
1285
+ private void updateContainer () {
1286
+ Composite container = getContainer ();
1287
+ if (container instanceof CTabFolder tabFolder ) {
1288
+ tabFolder .setTabPosition (getPreferredTabStyle ());
1289
+ tabFolder .requestLayout ();
1290
+ }
1291
+ }
1292
+
1233
1293
}
0 commit comments