Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 9dad7fb04b9dbf36eb7bee3ea610ca86034bddeb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*******************************************************************************
 * Copyright (c) 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     
 *******************************************************************************/
package org.eclipse.wst.dtd.ui.internal;

import org.eclipse.jface.viewers.IPostSelectionProvider;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.views.properties.IPropertySheetPage;
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import org.eclipse.wst.sse.ui.StructuredTextEditor;

/**
 * A DTD Editor subclass StructuredTextEditor, required to supply a complete
 * replacement for the property sheet page. When a better solution is found,
 * this class will be removed.
 */
public class DTDEditor extends StructuredTextEditor {
	class DTDPropertySheetPageContributor implements ITabbedPropertySheetPageContributor {
		DTDPropertySheetPageContributor() {
			super();
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor#getContributorId()
		 */
		public String getContributorId() {
			return getEditorSite().getId();
		}
	}

	TabbedPropertySheetPage fPropertySheetPage;

	public DTDEditor() {
		super();
	}

	/*
	 * @see IAdaptable#getAdapter(Class)
	 */
	public Object getAdapter(Class required) {
		if (IPropertySheetPage.class.equals(required)) {
			if (fPropertySheetPage == null) {
				fPropertySheetPage = new DTDTabbedPropertySheetPage(new DTDPropertySheetPageContributor());
				/*
				 * Add the property sheet page as a direct post selection
				 * listener so standard cursor navigation triggers a selection
				 * notification. The default tabbed property sheet does not
				 * listen to post selection.
				 */
				((IPostSelectionProvider) getSelectionProvider()).addPostSelectionChangedListener(new ISelectionChangedListener() {
					public void selectionChanged(SelectionChangedEvent event) {
						if (fPropertySheetPage != null && !fPropertySheetPage.getControl().isDisposed()) {
							fPropertySheetPage.selectionChanged(DTDEditor.this, getSelectionProvider().getSelection());
						}
					}
				});
			}
			return fPropertySheetPage;
		}
		return super.getAdapter(required);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.wst.sse.ui.StructuredTextEditor#init(org.eclipse.ui.IEditorSite,
	 *      org.eclipse.ui.IEditorInput)
	 */
	public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException {
		super.init(site, editorInput);

		IWorkbenchWindow dw = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		IWorkbenchPage page = dw.getActivePage();
		try {
			if (page != null) {
				page.showView(IPageLayout.ID_PROP_SHEET);
			}
		}
		catch (PartInitException e) {
			Logger.logException(e);
		}
	}
}

Back to the top