Skip to main content
summaryrefslogtreecommitdiffstats
blob: c8b00f2325db2bcda9557f9e36032600af44835d (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*******************************************************************************
 * Copyright (c) 2004, 2006 Sybase, Inc. 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:
 *     Sybase, Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.jsf.facesconfig.ui;

import org.eclipse.emf.edit.ui.action.EditingDomainActionBarContributor;
import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jst.jsf.facesconfig.ui.pageflow.PageflowActionBarContributor;
import org.eclipse.jst.jsf.facesconfig.ui.pageflow.PageflowEditor;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.part.EditorActionBarContributor;
import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
import org.eclipse.wst.xml.ui.internal.tabletree.SourcePageActionContributor;

/**
 * The faces-config editor itself is composed by a set of pages. Each page has
 * its own action contributor. This FacesConfigActionBarContributor will work as
 * a proxy to delegate the action contributing to target nested action
 * contributor.
 * 
 * @author hmeng
 */

public class FacesConfigActionBarContributor extends
		MultiPageEditorActionBarContributor {
	protected SourcePageActionContributor sourceActionContributor = null;

	protected PageflowActionBarContributor pageflowActionContributor = null;

	protected EditingDomainActionBarContributor formbasedPageActionContributor = null;

	private IEditorPart activeNestedEditor;

	//private IEditorPart targetEditor;

	public FacesConfigActionBarContributor() {
		super();
	}

	public void setActivePage(IEditorPart activeEditor) {
		if (activeEditor != activeNestedEditor) {
			if (getActionContributor(activeNestedEditor) != null) {
				getActionContributor(activeNestedEditor).setActiveEditor(
						activeEditor);
			}
			activeNestedEditor = activeEditor;
			EditorActionBarContributor activeContributor = getActionContributor(activeEditor);
			if (activeContributor != null)
				activeContributor.setActiveEditor(activeEditor);
			else
				super.setActiveEditor(activeEditor);
			updateActionBars();
		}
	}

	public void contributeToCoolBar(ICoolBarManager coolBarManager) {
		EditorActionBarContributor activeContributor = getActionContributor(activeNestedEditor);
		if (activeContributor != null)
			activeContributor.contributeToCoolBar(coolBarManager);
	}

	public void contributeToMenu(IMenuManager menuManager) {
		EditorActionBarContributor activeContributor = getActionContributor(activeNestedEditor);
		if (activeContributor != null) {
			activeContributor.contributeToMenu(menuManager);
		}
	}

	public void contributeToStatusLine(IStatusLineManager statusLineManager) {
		EditorActionBarContributor activeContributor = getActionContributor(activeNestedEditor);
		if (activeContributor != null) {
			activeContributor.contributeToStatusLine(statusLineManager);
		}
	}

	public void contributeToToolBar(IToolBarManager toolBarManager) {
		EditorActionBarContributor activeContributor = getActionContributor(activeNestedEditor);
		if (activeContributor != null) {
			activeContributor.contributeToToolBar(toolBarManager);
		}
	}

	public void dispose() {
		getFormbasedPageActionContributor().dispose();
		getPageflowActionContributor().dispose();
		getSourceActionContributor().dispose();
	}

	public IActionBars getActionBars() {
		EditorActionBarContributor activeContributor = getActionContributor(activeNestedEditor);
		if (activeContributor != null) {
			return activeContributor.getActionBars();
		}
        return super.getActionBars();
	}

	public IWorkbenchPage getPage() {
		return super.getPage();
	}

	public void init(IActionBars bars, IWorkbenchPage page) {
		getPageflowActionContributor().init(bars, page);
		getSourceActionContributor().init(bars, page);
		getFormbasedPageActionContributor().init(bars, page);
		super.init(bars, page);
	}

//	private IEditorPart getActiveNestedEditor(IEditorPart targetEditor) {
//		IEditorPart activeNestedEditor_;
//		if (targetEditor instanceof FormEditor) {
//			activeNestedEditor_ = ((FormEditor) targetEditor).getActiveEditor();
//		} else {
//			activeNestedEditor_ = targetEditor;
//		}
//		return activeNestedEditor_;
//	}

	private EditorActionBarContributor getActionContributor(
			IEditorPart activeNestedEditor_) {
		EditorActionBarContributor activeContributor = null;
		if (activeNestedEditor_ instanceof PageflowEditor) {
			activeContributor = getPageflowActionContributor();
		} else if (activeNestedEditor_ instanceof StructuredTextEditor) {
			activeContributor = getSourceActionContributor();
		} else if (activeNestedEditor_ != null) {
			activeContributor = getFormbasedPageActionContributor();
		}
		return activeContributor;
	}

	public SourcePageActionContributor getSourceActionContributor() {
		if (sourceActionContributor == null) {
			sourceActionContributor = new SourcePageActionContributor();
		}
		return sourceActionContributor;
	}

	public EditingDomainActionBarContributor getFormbasedPageActionContributor() {
		if (formbasedPageActionContributor == null) {
			formbasedPageActionContributor = new MyEditingDomainActionContributor();
		}
		return formbasedPageActionContributor;
	}

//	protected void declareGlobalActionKeys() {
//        // 
//	}

	public PageflowActionBarContributor getPageflowActionContributor() {
		if (pageflowActionContributor == null) {
			pageflowActionContributor = new PageflowActionBarContributor();
		}
		return pageflowActionContributor;

	}

	public void updateActionBars() {
		EditorActionBarContributor activeContributor = getActionContributor(activeNestedEditor);
		if (activeContributor instanceof INestedActionContributor)
			((INestedActionContributor) activeContributor).update();
		// getActionBars().getMenuManager().removeAll();
		// activeContributor.contributeToMenu(getActionBars().getMenuManager());
		getActionBars().updateActionBars();
	}
}

Back to the top