Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 304890
Collapse All | Expand All

(-)src/org/eclipse/ui/forms/editor/FormEditor.java (-30 / +74 lines)
Lines 12-17 Link Here
12
12
13
import java.util.Vector;
13
import java.util.Vector;
14
14
15
import org.eclipse.core.runtime.ListenerList;
16
import org.eclipse.jface.dialogs.IPageChangeProvider;
17
import org.eclipse.jface.dialogs.IPageChangedListener;
18
import org.eclipse.jface.dialogs.PageChangedEvent;
19
import org.eclipse.jface.util.SafeRunnable;
20
15
import org.eclipse.jface.viewers.ISelection;
21
import org.eclipse.jface.viewers.ISelection;
16
import org.eclipse.jface.viewers.ISelectionProvider;
22
import org.eclipse.jface.viewers.ISelectionProvider;
17
import org.eclipse.jface.viewers.SelectionChangedEvent;
23
import org.eclipse.jface.viewers.SelectionChangedEvent;
Lines 50-59 Link Here
50
 * FormEditor is a page change provider. It allows listeners to attach to it and
56
 * FormEditor is a page change provider. It allows listeners to attach to it and
51
 * get notified when pages are changed. This new API in JFace allows dynamic
57
 * get notified when pages are changed. This new API in JFace allows dynamic
52
 * help to update on page changes.
58
 * help to update on page changes.
53
 * 
59
 *
54
 * @since 1.0
60
 * @since 1.0
55
 */
61
 */
56
public abstract class FormEditor extends MultiPageEditorPart  {
62
// RAP [if] As RAP is still using workbench 3.4 the implementation of
63
// IPageChangeProvider is missing from MultiPageEditorPart. Remove this code
64
// with the adoption of workbench > 3.5
65
//public abstract class FormEditor extends MultiPageEditorPart  {
66
public abstract class FormEditor extends MultiPageEditorPart implements
67
        IPageChangeProvider {
57
68
58
	/**
69
	/**
59
	 * An array of pages currently in the editor. Page objects are not limited
70
	 * An array of pages currently in the editor. Page objects are not limited
Lines 131-137 Link Here
131
142
132
	/**
143
	/**
133
	 * Creates the common toolkit for this editor and adds pages to the editor.
144
	 * Creates the common toolkit for this editor and adds pages to the editor.
134
	 * 
145
	 *
135
	 * @see #addPages
146
	 * @see #addPages
136
	 */
147
	 */
137
	protected void createPages() {
148
	protected void createPages() {
Lines 153-159 Link Here
153
	 * use of this method would be to create the form toolkit using one shared
164
	 * use of this method would be to create the form toolkit using one shared
154
	 * <code>FormColors</code> object to share resources across the multiple
165
	 * <code>FormColors</code> object to share resources across the multiple
155
	 * editor instances.
166
	 * editor instances.
156
	 * 
167
	 *
157
	 * @param display
168
	 * @param display
158
	 *            the display to use when creating the toolkit
169
	 *            the display to use when creating the toolkit
159
	 * @return the newly created toolkit instance
170
	 * @return the newly created toolkit instance
Lines 170-176 Link Here
170
181
171
	/*
182
	/*
172
	 * (non-Javadoc)
183
	 * (non-Javadoc)
173
	 * 
184
	 *
174
	 * @see org.eclipse.jface.dialogs.IPageChangeProvider#getSelectedPage()
185
	 * @see org.eclipse.jface.dialogs.IPageChangeProvider#getSelectedPage()
175
	 */
186
	 */
176
	public Object getSelectedPage() {
187
	public Object getSelectedPage() {
Lines 181-187 Link Here
181
	 * Adds the form page to this editor. Form page will be loaded lazily. Its
192
	 * Adds the form page to this editor. Form page will be loaded lazily. Its
182
	 * part control will not be created until it is activated for the first
193
	 * part control will not be created until it is activated for the first
183
	 * time.
194
	 * time.
184
	 * 
195
	 *
185
	 * @param page
196
	 * @param page
186
	 *            the form page to add
197
	 *            the form page to add
187
	 */
198
	 */
Lines 195-201 Link Here
195
	 * Adds the form page to this editor at the specified index (0-based). Form
206
	 * Adds the form page to this editor at the specified index (0-based). Form
196
	 * page will be loaded lazily. Its part control will not be created until it
207
	 * page will be loaded lazily. Its part control will not be created until it
197
	 * is activated for the first time.
208
	 * is activated for the first time.
198
	 * 
209
	 *
199
	 * @param index
210
	 * @param index
200
	 *            the position to add the page at (0-based)
211
	 *            the position to add the page at (0-based)
201
	 * @param page
212
	 * @param page
Lines 210-216 Link Here
210
	/**
221
	/**
211
	 * Adds a simple SWT control as a page. Overrides superclass implementation
222
	 * Adds a simple SWT control as a page. Overrides superclass implementation
212
	 * to keep track of pages.
223
	 * to keep track of pages.
213
	 * 
224
	 *
214
	 * @param control
225
	 * @param control
215
	 *            the page control to add
226
	 *            the page control to add
216
	 * @return the 0-based index of the newly added page
227
	 * @return the 0-based index of the newly added page
Lines 228-234 Link Here
228
	/**
239
	/**
229
	 * Adds a simple SWT control as a page. Overrides superclass implementation
240
	 * Adds a simple SWT control as a page. Overrides superclass implementation
230
	 * to keep track of pages.
241
	 * to keep track of pages.
231
	 * 
242
	 *
232
	 * @param control
243
	 * @param control
233
	 *            the page control to add
244
	 *            the page control to add
234
	 * @param index
245
	 * @param index
Lines 248-254 Link Here
248
	 * Tests whether the editor is dirty by checking all the pages that
259
	 * Tests whether the editor is dirty by checking all the pages that
249
	 * implement <code>IFormPage</code>. If none of them is dirty, the method
260
	 * implement <code>IFormPage</code>. If none of them is dirty, the method
250
	 * delegates further processing to <code>super.isDirty()</code>.
261
	 * delegates further processing to <code>super.isDirty()</code>.
251
	 * 
262
	 *
252
	 * @return <code>true</code> if any of the pages in the editor are dirty,
263
	 * @return <code>true</code> if any of the pages in the editor are dirty,
253
	 *         <code>false</code> otherwise.
264
	 *         <code>false</code> otherwise.
254
	 */
265
	 */
Lines 261-278 Link Here
261
					IFormPage fpage = (IFormPage) page;
272
					IFormPage fpage = (IFormPage) page;
262
					if (fpage.isDirty())
273
					if (fpage.isDirty())
263
						return true;
274
						return true;
264
						
275
265
				} else if (page instanceof IEditorPart) {
276
				} else if (page instanceof IEditorPart) {
266
					IEditorPart editor = (IEditorPart) page;
277
					IEditorPart editor = (IEditorPart) page;
267
					if (editor.isDirty()) {
278
					if (editor.isDirty()) {
268
						return true;
279
						return true;
269
					}	
280
					}
270
				}
281
				}
271
			}
282
			}
272
		}
283
		}
273
		return super.isDirty();
284
		return super.isDirty();
274
	}
285
	}
275
	
286
276
	/**
287
	/**
277
	 * Commits all dirty pages in the editor. This method should
288
	 * Commits all dirty pages in the editor. This method should
278
	 * be called as a first step of a 'save' operation.
289
	 * be called as a first step of a 'save' operation.
Lines 291-302 Link Here
291
						mform.commit(onSave);
302
						mform.commit(onSave);
292
				}
303
				}
293
			}
304
			}
294
		}	
305
		}
295
	}
306
	}
296
307
297
	/**
308
	/**
298
	 * Adds a complete editor part to the multi-page editor.
309
	 * Adds a complete editor part to the multi-page editor.
299
	 * 
310
	 *
300
	 * @see MultiPageEditorPart#addPage(IEditorPart, IEditorInput)
311
	 * @see MultiPageEditorPart#addPage(IEditorPart, IEditorInput)
301
	 */
312
	 */
302
	public int addPage(IEditorPart editor, IEditorInput input)
313
	public int addPage(IEditorPart editor, IEditorInput input)
Lines 312-318 Link Here
312
	/**
323
	/**
313
	 * Adds a complete editor part to the multi-page editor at the specified
324
	 * Adds a complete editor part to the multi-page editor at the specified
314
	 * position.
325
	 * position.
315
	 * 
326
	 *
316
	 * @see MultiPageEditorPart#addPage(int, IEditorPart, IEditorInput)
327
	 * @see MultiPageEditorPart#addPage(int, IEditorPart, IEditorInput)
317
	 */
328
	 */
318
	public void addPage(int index, IEditorPart editor, IEditorInput input)
329
	public void addPage(int index, IEditorPart editor, IEditorInput input)
Lines 322-333 Link Here
322
			configurePage(index, (IFormPage) editor);
333
			configurePage(index, (IFormPage) editor);
323
		else
334
		else
324
			registerPage(index, editor);
335
			registerPage(index, editor);
325
		updatePageIndices(index+1);	
336
		updatePageIndices(index+1);
326
	}
337
	}
327
338
328
	/**
339
	/**
329
	 * Configures the form page.
340
	 * Configures the form page.
330
	 * 
341
	 *
331
	 * @param index
342
	 * @param index
332
	 *            the page index
343
	 *            the page index
333
	 * @param page
344
	 * @param page
Lines 345-351 Link Here
345
356
346
	/**
357
	/**
347
	 * Overrides the superclass to remove the page from the page table.
358
	 * Overrides the superclass to remove the page from the page table.
348
	 * 
359
	 *
349
	 * @param pageIndex
360
	 * @param pageIndex
350
	 *            the 0-based index of the page in the editor
361
	 *            the 0-based index of the page in the editor
351
	 */
362
	 */
Lines 409-415 Link Here
409
420
410
	/**
421
	/**
411
	 * Returns the toolkit owned by this editor.
422
	 * Returns the toolkit owned by this editor.
412
	 * 
423
	 *
413
	 * @return the toolkit object
424
	 * @return the toolkit object
414
	 */
425
	 */
415
	public FormToolkit getToolkit() {
426
	public FormToolkit getToolkit() {
Lines 418-424 Link Here
418
429
419
	/**
430
	/**
420
	 * Widens the visibility of the method in the superclass.
431
	 * Widens the visibility of the method in the superclass.
421
	 * 
432
	 *
422
	 * @return the active nested editor
433
	 * @return the active nested editor
423
	 */
434
	 */
424
	public IEditorPart getActiveEditor() {
435
	public IEditorPart getActiveEditor() {
Lines 433-439 Link Here
433
	 * Another important difference is during the editor closing. When the tab
444
	 * Another important difference is during the editor closing. When the tab
434
	 * folder is disposed, 'getActivePage()' will return -1, while this method
445
	 * folder is disposed, 'getActivePage()' will return -1, while this method
435
	 * will still return the last active page.
446
	 * will still return the last active page.
436
	 * 
447
	 *
437
	 * @see #getActivePage
448
	 * @see #getActivePage
438
	 * @return the currently selected page or -1 if no page is currently
449
	 * @return the currently selected page or -1 if no page is currently
439
	 *         selected
450
	 *         selected
Lines 480-496 Link Here
480
				&& pages.get(newPageIndex) instanceof IFormPage)
491
				&& pages.get(newPageIndex) instanceof IFormPage)
481
			((IFormPage) pages.get(newPageIndex)).setActive(true);
492
			((IFormPage) pages.get(newPageIndex)).setActive(true);
482
		if (oldPageIndex != -1 && pages.size() > oldPageIndex
493
		if (oldPageIndex != -1 && pages.size() > oldPageIndex
483
				&& newPageIndex != oldPageIndex && 
494
				&& newPageIndex != oldPageIndex &&
484
				pages.get(oldPageIndex) instanceof IFormPage)
495
				pages.get(oldPageIndex) instanceof IFormPage)
485
			((IFormPage) pages.get(oldPageIndex)).setActive(false);
496
			((IFormPage) pages.get(oldPageIndex)).setActive(false);
486
		// Call super - this will cause pages to switch
497
		// Call super - this will cause pages to switch
487
		super.pageChange(newPageIndex);
498
		super.pageChange(newPageIndex);
499
// RAP [if] As RAP is still using workbench 3.4 the implementation of
500
// IPageChangeProvider is missing from MultiPageEditorPart. Remove this code
501
// with the adoption of workbench > 3.5
502
		IFormPage newPage = getActivePageInstance();
503
        if (newPage != null)
504
            firePageChanged(new PageChangedEvent(this, newPage));
505
// RAPEND [if]
488
		this.currentPage = newPageIndex;
506
		this.currentPage = newPageIndex;
489
	}
507
	}
490
508
491
	/**
509
	/**
492
	 * Sets the active page using the unique page identifier.
510
	 * Sets the active page using the unique page identifier.
493
	 * 
511
	 *
494
	 * @param pageId
512
	 * @param pageId
495
	 *            the id of the page to switch to
513
	 *            the id of the page to switch to
496
	 * @return page that was set active or <samp>null </samp> if not found.
514
	 * @return page that was set active or <samp>null </samp> if not found.
Lines 511-517 Link Here
511
529
512
	/**
530
	/**
513
	 * Finds the page instance that has the provided id.
531
	 * Finds the page instance that has the provided id.
514
	 * 
532
	 *
515
	 * @param pageId
533
	 * @param pageId
516
	 *            the id of the page to find
534
	 *            the id of the page to find
517
	 * @return page with the matching id or <code>null</code> if not found.
535
	 * @return page with the matching id or <code>null</code> if not found.
Lines 531-537 Link Here
531
	/**
549
	/**
532
	 * Sets the active page using the unique page identifier and sets its input
550
	 * Sets the active page using the unique page identifier and sets its input
533
	 * to the provided object.
551
	 * to the provided object.
534
	 * 
552
	 *
535
	 * @param pageId
553
	 * @param pageId
536
	 *            the id of the page to switch to
554
	 *            the id of the page to switch to
537
	 * @param pageInput
555
	 * @param pageInput
Lines 551-557 Link Here
551
	/**
569
	/**
552
	 * Iterates through the pages calling similar method until a page is found
570
	 * Iterates through the pages calling similar method until a page is found
553
	 * that contains the desired page input.
571
	 * that contains the desired page input.
554
	 * 
572
	 *
555
	 * @param pageInput
573
	 * @param pageInput
556
	 *            the object to select and reveal
574
	 *            the object to select and reveal
557
	 * @return the page that accepted the request or <code>null</code> if no
575
	 * @return the page that accepted the request or <code>null</code> if no
Lines 573-579 Link Here
573
	/**
591
	/**
574
	 * Returns active page instance if the currently selected page index is not
592
	 * Returns active page instance if the currently selected page index is not
575
	 * -1, or <code>null</code> if it is.
593
	 * -1, or <code>null</code> if it is.
576
	 * 
594
	 *
577
	 * @return active page instance if selected, or <code>null</code> if no
595
	 * @return active page instance if selected, or <code>null</code> if no
578
	 *         page is currently active.
596
	 *         page is currently active.
579
	 */
597
	 */
Lines 605-611 Link Here
605
623
606
	/**
624
	/**
607
	 * Notifies action bar contributor about page change.
625
	 * Notifies action bar contributor about page change.
608
	 * 
626
	 *
609
	 * @param pageIndex
627
	 * @param pageIndex
610
	 *            the index of the new page
628
	 *            the index of the new page
611
	 */
629
	 */
Lines 623-629 Link Here
623
641
624
	/**
642
	/**
625
	 * Closes the editor programmatically.
643
	 * Closes the editor programmatically.
626
	 * 
644
	 *
627
	 * @param save
645
	 * @param save
628
	 *            if <code>true</code>, the content should be saved before
646
	 *            if <code>true</code>, the content should be saved before
629
	 *            closing.
647
	 *            closing.
Lines 652-655 Link Here
652
				fpage.init(getEditorSite(), getEditorInput());
670
				fpage.init(getEditorSite(), getEditorInput());
653
		}
671
		}
654
	}
672
	}
673
674
// RAP [if] As RAP is still using workbench 3.4 the implementation of
675
// IPageChangeProvider is missing from MultiPageEditorPart. Remove this code
676
// with the adoption of workbench > 3.5
677
	private ListenerList pageListeners = new ListenerList();
678
679
	public void addPageChangedListener(IPageChangedListener listener) {
680
      pageListeners.add(listener);
681
    }
682
683
	public void removePageChangedListener(IPageChangedListener listener) {
684
      pageListeners.remove(listener);
685
    }
686
687
	private void firePageChanged(final PageChangedEvent event) {
688
      Object[] listeners = pageListeners.getListeners();
689
      for (int i = 0; i < listeners.length; ++i) {
690
          final IPageChangedListener l = (IPageChangedListener) listeners[i];
691
          SafeRunnable.run(new SafeRunnable() {
692
              public void run() {
693
                  l.pageChanged(event);
694
              }
695
          });
696
      }
697
    }
698
// RAPEND [if]
655
}
699
}

Return to bug 304890