~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to results/plugins/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/AbstractBinaryParserPage.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
7
 
 *
8
 
 * Contributors:
9
 
 *     QNX Software Systems - Initial API and implementation
10
 
 *******************************************************************************/
11
 
 
12
 
package org.eclipse.cdt.ui.dialogs;
13
 
 
14
 
import java.util.HashMap;
15
 
import java.util.Map;
16
 
 
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;
26
 
 
27
 
public abstract class AbstractBinaryParserPage extends AbstractCOptionPage {
28
 
 
29
 
        protected ICOptionPage fCurrentBinaryParserPage;
30
 
        protected Map<String, BinaryParserPageConfiguration> fParserPageMap = null;
31
 
 
32
 
        // Composite parent provided by the block.
33
 
        protected Composite fCompositeParent;
34
 
        private ICOptionPage fCurrentPage;
35
 
 
36
 
        protected class BinaryParserPageConfiguration {
37
 
 
38
 
                ICOptionPage page;
39
 
                IConfigurationElement fElement;
40
 
 
41
 
                public BinaryParserPageConfiguration(IConfigurationElement element) {
42
 
                        fElement = element;
43
 
                }
44
 
 
45
 
                public ICOptionPage getPage() throws CoreException {
46
 
                        if (page == null) {
47
 
                                page = (ICOptionPage) fElement.createExecutableExtension("class"); //$NON-NLS-1$
48
 
                        }
49
 
                        return page;
50
 
                }
51
 
        }
52
 
 
53
 
        protected AbstractBinaryParserPage(String title) {
54
 
                super(title);
55
 
                initializeParserPageMap();
56
 
 
57
 
        }
58
 
 
59
 
        protected AbstractBinaryParserPage(String title, ImageDescriptor image) {
60
 
                super(title, image);
61
 
                initializeParserPageMap();
62
 
        }
63
 
 
64
 
        private void initializeParserPageMap() {
65
 
                fParserPageMap = new HashMap<String, BinaryParserPageConfiguration>(5);
66
 
 
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]));
73
 
                        }
74
 
                }
75
 
        }
76
 
 
77
 
        protected Composite getCompositeParent() {
78
 
                return fCompositeParent;
79
 
        }
80
 
 
81
 
        protected void setCompositeParent(Composite parent) {
82
 
                fCompositeParent = parent;
83
 
                fCompositeParent.setLayout(new TabFolderLayout());
84
 
        }
85
 
 
86
 
        @Override
87
 
        public void setVisible(boolean visible) {
88
 
                super.setVisible(visible);
89
 
                handleBinaryParserChanged();
90
 
        }
91
 
        /**
92
 
         * Notification that the user changed the selection of the Binary Parser.
93
 
         */
94
 
        protected void handleBinaryParserChanged() {
95
 
                if (getCompositeParent() == null) {
96
 
                        return;
97
 
                }
98
 
                String[] enabled = getBinaryParserIDs();
99
 
                ICOptionPage page;
100
 
                for (int i = 0; i < enabled.length; i++) { // create all enabled pages
101
 
                        page = getBinaryParserPage(enabled[i]);
102
 
                        if (page != null) {
103
 
                                if (page.getControl() == null) {
104
 
                                        Composite parent = getCompositeParent();
105
 
                                        page.setContainer(getContainer());
106
 
                                        page.createControl(parent);
107
 
                                        parent.layout(true);
108
 
                                } else {
109
 
                                        page.setVisible(false);
110
 
                                }
111
 
                        }
112
 
                }
113
 
                // Retrieve the dynamic UI for the current parser
114
 
                String parserID = getCurrentBinaryParserID();
115
 
                page = getBinaryParserPage(parserID);
116
 
                if (page != null) {
117
 
                        page.setVisible(true);
118
 
                }
119
 
                setCurrentPage(page);
120
 
        }
121
 
 
122
 
        protected ICOptionPage getCurrentPage() {
123
 
                return fCurrentPage;
124
 
        }
125
 
 
126
 
        protected void setCurrentPage(ICOptionPage page) {
127
 
                fCurrentPage = page;
128
 
        }
129
 
 
130
 
        protected ICOptionPage getBinaryParserPage(String parserID) {
131
 
                BinaryParserPageConfiguration configElement = fParserPageMap.get(parserID);
132
 
                if (configElement != null) {
133
 
                        try {
134
 
                                return configElement.getPage();
135
 
                        } catch (CoreException e) {
136
 
                        }
137
 
                }
138
 
                return null;
139
 
        }
140
 
 
141
 
        abstract protected String getCurrentBinaryParserID();
142
 
 
143
 
        abstract protected String[] getBinaryParserIDs();
144
 
 
145
 
        @Override
146
 
        abstract public void createControl(Composite parent);
147
 
 
148
 
        /*
149
 
         * (non-Javadoc)
150
 
         * 
151
 
         * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performApply(org.eclipse.core.runtime.IProgressMonitor)
152
 
         */
153
 
        @Override
154
 
        abstract public void performApply(IProgressMonitor monitor) throws CoreException;
155
 
 
156
 
        /*
157
 
         * (non-Javadoc)
158
 
         * 
159
 
         * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performDefaults()
160
 
         */
161
 
        @Override
162
 
        abstract public void performDefaults();
163
 
 
164
 
}