1
/*******************************************************************************
2
* Copyright (c) 2003, 2008 IBM Corporation and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* QNX Software Systems - Initial API and implementation
10
*******************************************************************************/
12
package org.eclipse.cdt.ui.dialogs;
14
import java.util.HashMap;
17
import org.eclipse.cdt.ui.CUIPlugin;
18
import org.eclipse.cdt.utils.ui.controls.TabFolderLayout;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IConfigurationElement;
21
import org.eclipse.core.runtime.IExtensionPoint;
22
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.Platform;
24
import org.eclipse.jface.resource.ImageDescriptor;
25
import org.eclipse.swt.widgets.Composite;
27
public abstract class AbstractBinaryParserPage extends AbstractCOptionPage {
29
protected ICOptionPage fCurrentBinaryParserPage;
30
protected Map<String, BinaryParserPageConfiguration> fParserPageMap = null;
32
// Composite parent provided by the block.
33
protected Composite fCompositeParent;
34
private ICOptionPage fCurrentPage;
36
protected class BinaryParserPageConfiguration {
39
IConfigurationElement fElement;
41
public BinaryParserPageConfiguration(IConfigurationElement element) {
45
public ICOptionPage getPage() throws CoreException {
47
page = (ICOptionPage) fElement.createExecutableExtension("class"); //$NON-NLS-1$
53
protected AbstractBinaryParserPage(String title) {
55
initializeParserPageMap();
59
protected AbstractBinaryParserPage(String title, ImageDescriptor image) {
61
initializeParserPageMap();
64
private void initializeParserPageMap() {
65
fParserPageMap = new HashMap<String, BinaryParserPageConfiguration>(5);
67
IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(CUIPlugin.PLUGIN_ID, "BinaryParserPage"); //$NON-NLS-1$
68
IConfigurationElement[] infos = extensionPoint.getConfigurationElements();
69
for (int i = 0; i < infos.length; i++) {
70
if (infos[i].getName().equals("parserPage")) { //$NON-NLS-1$
71
String id = infos[i].getAttribute("parserID"); //$NON-NLS-1$
72
fParserPageMap.put(id, new BinaryParserPageConfiguration(infos[i]));
77
protected Composite getCompositeParent() {
78
return fCompositeParent;
81
protected void setCompositeParent(Composite parent) {
82
fCompositeParent = parent;
83
fCompositeParent.setLayout(new TabFolderLayout());
87
public void setVisible(boolean visible) {
88
super.setVisible(visible);
89
handleBinaryParserChanged();
92
* Notification that the user changed the selection of the Binary Parser.
94
protected void handleBinaryParserChanged() {
95
if (getCompositeParent() == null) {
98
String[] enabled = getBinaryParserIDs();
100
for (int i = 0; i < enabled.length; i++) { // create all enabled pages
101
page = getBinaryParserPage(enabled[i]);
103
if (page.getControl() == null) {
104
Composite parent = getCompositeParent();
105
page.setContainer(getContainer());
106
page.createControl(parent);
109
page.setVisible(false);
113
// Retrieve the dynamic UI for the current parser
114
String parserID = getCurrentBinaryParserID();
115
page = getBinaryParserPage(parserID);
117
page.setVisible(true);
119
setCurrentPage(page);
122
protected ICOptionPage getCurrentPage() {
126
protected void setCurrentPage(ICOptionPage page) {
130
protected ICOptionPage getBinaryParserPage(String parserID) {
131
BinaryParserPageConfiguration configElement = fParserPageMap.get(parserID);
132
if (configElement != null) {
134
return configElement.getPage();
135
} catch (CoreException e) {
141
abstract protected String getCurrentBinaryParserID();
143
abstract protected String[] getBinaryParserIDs();
146
abstract public void createControl(Composite parent);
151
* @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performApply(org.eclipse.core.runtime.IProgressMonitor)
154
abstract public void performApply(IProgressMonitor monitor) throws CoreException;
159
* @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performDefaults()
162
abstract public void performDefaults();