~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/AbstractGNUBinaryParserPage.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.io.File;
15
 
 
16
 
import org.eclipse.core.resources.IProject;
17
 
import org.eclipse.core.runtime.CoreException;
18
 
import org.eclipse.core.runtime.IConfigurationElement;
19
 
import org.eclipse.core.runtime.IExtensionPoint;
20
 
import org.eclipse.core.runtime.IProgressMonitor;
21
 
import org.eclipse.core.runtime.NullProgressMonitor;
22
 
import org.eclipse.core.runtime.Platform;
23
 
import org.eclipse.core.runtime.Preferences;
24
 
import org.eclipse.swt.SWT;
25
 
import org.eclipse.swt.events.ModifyEvent;
26
 
import org.eclipse.swt.events.ModifyListener;
27
 
import org.eclipse.swt.events.SelectionAdapter;
28
 
import org.eclipse.swt.events.SelectionEvent;
29
 
import org.eclipse.swt.layout.GridData;
30
 
import org.eclipse.swt.layout.GridLayout;
31
 
import org.eclipse.swt.widgets.Button;
32
 
import org.eclipse.swt.widgets.Composite;
33
 
import org.eclipse.swt.widgets.FileDialog;
34
 
import org.eclipse.swt.widgets.Group;
35
 
import org.eclipse.swt.widgets.Label;
36
 
import org.eclipse.swt.widgets.Text;
37
 
 
38
 
import org.eclipse.cdt.core.CCorePlugin;
39
 
import org.eclipse.cdt.core.ICExtensionReference;
40
 
import org.eclipse.cdt.ui.CUIPlugin;
41
 
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
42
 
 
43
 
import org.eclipse.cdt.internal.ui.CUIMessages;
44
 
 
45
 
/**
46
 
 * Abstract base binary parser page for GNU binutils based binary parsers
47
 
 */
48
 
public abstract class AbstractGNUBinaryParserPage extends AbstractCOptionPage {
49
 
 
50
 
        public final static String PREF_ADDR2LINE_PATH = CUIPlugin.PLUGIN_ID + ".addr2line"; //$NON-NLS-1$
51
 
        public final static String PREF_CPPFILT_PATH = CUIPlugin.PLUGIN_ID + ".cppfilt"; //$NON-NLS-1$
52
 
 
53
 
        protected Text fAddr2LineCommandText;
54
 
        protected Text fCPPFiltCommandText;
55
 
        private String parserID = null;
56
 
 
57
 
        /*
58
 
         * (non-Javadoc)
59
 
         * 
60
 
         * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performApply(org.eclipse.core.runtime.IProgressMonitor)
61
 
         */
62
 
        @Override
63
 
        public void performApply(IProgressMonitor monitor) throws CoreException {
64
 
                if (monitor == null) {
65
 
                        monitor = new NullProgressMonitor();
66
 
                }
67
 
 
68
 
                String addr2line = fAddr2LineCommandText.getText().trim();
69
 
                String cppfilt = fCPPFiltCommandText.getText().trim();
70
 
 
71
 
                monitor.beginTask(CUIMessages.BinaryParserPage_task_savingAttributes, 1); 
72
 
                IProject proj = getContainer().getProject();
73
 
                if (proj != null) {
74
 
                        ICExtensionReference[] cext = CCorePlugin.getDefault().getBinaryParserExtensions(proj);
75
 
                        if (cext.length > 0) {
76
 
                                initializeParserId();
77
 
                                for (int i = 0; i < cext.length; i++) {
78
 
                                        if (cext[i].getID().equals(parserID)) {
79
 
                                                String orig = cext[i].getExtensionData("addr2line"); //$NON-NLS-1$
80
 
                                                if (orig == null || !orig.equals(addr2line)) {
81
 
                                                        cext[i].setExtensionData("addr2line", addr2line); //$NON-NLS-1$
82
 
                                                }
83
 
                                                orig = cext[i].getExtensionData("c++filt"); //$NON-NLS-1$
84
 
                                                if (orig == null || !orig.equals(cppfilt)) {
85
 
                                                        cext[i].setExtensionData("c++filt", cppfilt); //$NON-NLS-1$
86
 
                                                }
87
 
                                        }
88
 
                                }
89
 
                        }
90
 
                } else {
91
 
                        Preferences store = getContainer().getPreferences();
92
 
                        if (store != null) {
93
 
                                store.setValue(PREF_ADDR2LINE_PATH, addr2line);
94
 
                                store.setValue(PREF_CPPFILT_PATH, cppfilt);
95
 
                        }
96
 
                }
97
 
        }
98
 
 
99
 
        private void initializeParserId() {
100
 
                if (parserID == null) {
101
 
                        IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CUIPlugin.PLUGIN_ID, "BinaryParserPage"); //$NON-NLS-1$
102
 
                        IConfigurationElement[] infos = point.getConfigurationElements();
103
 
                        for (int i = 0; i < infos.length; i++) {
104
 
                                String id = infos[i].getAttribute("parserID"); //$NON-NLS-1$
105
 
                                String clazz = infos[i].getAttribute("class"); //$NON-NLS-1$
106
 
                                String ego = getRealBinaryParserPage().getClass().getName();
107
 
                                if (clazz != null && clazz.equals(ego)) {
108
 
                                        parserID = id;
109
 
                                        return;
110
 
                                }
111
 
                        }
112
 
                        parserID = "";  //$NON-NLS-1$
113
 
                }
114
 
        }
115
 
 
116
 
        /**
117
 
         * If this class is inherited from then this method MUST be implemented
118
 
         * in the derived class.
119
 
         */
120
 
        abstract protected AbstractGNUBinaryParserPage getRealBinaryParserPage();
121
 
 
122
 
        /*
123
 
         * (non-Javadoc)
124
 
         * 
125
 
         * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performDefaults()
126
 
         */
127
 
        @Override
128
 
        public void performDefaults() {
129
 
                String addr2line = null;
130
 
                String cppfilt = null;
131
 
                IProject proj = getContainer().getProject();
132
 
                Preferences store = getContainer().getPreferences();
133
 
                if (store != null) {
134
 
                        if (proj != null) {
135
 
                                addr2line = store.getString(PREF_ADDR2LINE_PATH);
136
 
                                cppfilt = store.getString(PREF_CPPFILT_PATH);
137
 
                        } else {
138
 
                                addr2line = store.getDefaultString(PREF_ADDR2LINE_PATH);
139
 
                                cppfilt = store.getDefaultString(PREF_CPPFILT_PATH);
140
 
                        }
141
 
                        fAddr2LineCommandText.setText((addr2line == null || addr2line.length() == 0) ? "addr2line" : addr2line); //$NON-NLS-1$
142
 
                        fCPPFiltCommandText.setText((cppfilt == null || cppfilt.length() == 0) ? "c++filt" : cppfilt); //$NON-NLS-1$
143
 
                }
144
 
        }
145
 
 
146
 
        /*
147
 
         * (non-Javadoc)
148
 
         * 
149
 
         * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
150
 
         */
151
 
        @Override
152
 
        public void createControl(Composite parent) {
153
 
                Group comp = new Group(parent, SWT.SHADOW_ETCHED_IN);
154
 
                comp.setText(CUIMessages.BinaryParserBlock_binaryParserOptions); 
155
 
                comp.setLayout(new GridLayout(2, true));
156
 
                comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
157
 
                ((GridLayout) comp.getLayout()).makeColumnsEqualWidth = false;
158
 
                
159
 
                Label label = ControlFactory.createLabel(comp, CUIMessages.BinaryParserPage_label_addr2lineCommand); 
160
 
                GridData gd = new GridData();
161
 
                gd.horizontalSpan = 2;
162
 
                label.setLayoutData(gd);
163
 
 
164
 
                fAddr2LineCommandText = ControlFactory.createTextField(comp, SWT.SINGLE | SWT.BORDER);
165
 
                fAddr2LineCommandText.addModifyListener(new ModifyListener() {
166
 
 
167
 
                        public void modifyText(ModifyEvent evt) {
168
 
                                //updateLaunchConfigurationDialog();
169
 
                        }
170
 
                });
171
 
 
172
 
                Button button = ControlFactory.createPushButton(comp, CUIMessages.BinaryParserPage_label_browse); 
173
 
                button.addSelectionListener(new SelectionAdapter() {
174
 
 
175
 
                        @Override
176
 
                        public void widgetSelected(SelectionEvent evt) {
177
 
                                handleAddr2LineButtonSelected();
178
 
                                //updateLaunchConfigurationDialog();
179
 
                        }
180
 
 
181
 
                        private void handleAddr2LineButtonSelected() {
182
 
                                FileDialog dialog = new FileDialog(getShell(), SWT.NONE);
183
 
                                dialog.setText(CUIMessages.BinaryParserPage_label_addr2lineCommand); 
184
 
                                String command = fAddr2LineCommandText.getText().trim();
185
 
                                int lastSeparatorIndex = command.lastIndexOf(File.separator);
186
 
                                if (lastSeparatorIndex != -1) {
187
 
                                        dialog.setFilterPath(command.substring(0, lastSeparatorIndex));
188
 
                                }
189
 
                                String res = dialog.open();
190
 
                                if (res == null) {
191
 
                                        return;
192
 
                                }
193
 
                                fAddr2LineCommandText.setText(res);
194
 
                        }
195
 
                });
196
 
 
197
 
                label = ControlFactory.createLabel(comp, CUIMessages.BinaryParserPage_label_cppfiltCommand); 
198
 
                gd = new GridData();
199
 
                gd.horizontalSpan = 2;
200
 
                label.setLayoutData(gd);
201
 
 
202
 
                fCPPFiltCommandText = ControlFactory.createTextField(comp, SWT.SINGLE | SWT.BORDER);
203
 
                gd = new GridData(GridData.FILL_HORIZONTAL);
204
 
                fCPPFiltCommandText.setLayoutData(gd);
205
 
                fCPPFiltCommandText.addModifyListener(new ModifyListener() {
206
 
 
207
 
                        public void modifyText(ModifyEvent evt) {
208
 
                                //updateLaunchConfigurationDialog();
209
 
                        }
210
 
                });
211
 
                button = ControlFactory.createPushButton(comp, CUIMessages.BinaryParserPage_label_browse1); 
212
 
                button.addSelectionListener(new SelectionAdapter() {
213
 
 
214
 
                        @Override
215
 
                        public void widgetSelected(SelectionEvent evt) {
216
 
                                handleCPPFiltButtonSelected();
217
 
                                //updateLaunchConfigurationDialog();
218
 
                        }
219
 
 
220
 
                        private void handleCPPFiltButtonSelected() {
221
 
                                FileDialog dialog = new FileDialog(getShell(), SWT.NONE);
222
 
                                dialog.setText(CUIMessages.BinaryParserPage_label_cppfiltCommand); 
223
 
                                String command = fCPPFiltCommandText.getText().trim();
224
 
                                int lastSeparatorIndex = command.lastIndexOf(File.separator);
225
 
                                if (lastSeparatorIndex != -1) {
226
 
                                        dialog.setFilterPath(command.substring(0, lastSeparatorIndex));
227
 
                                }
228
 
                                String res = dialog.open();
229
 
                                if (res == null) {
230
 
                                        return;
231
 
                                }
232
 
                                fCPPFiltCommandText.setText(res);
233
 
                        }
234
 
                });
235
 
 
236
 
                setControl(comp);
237
 
                initialziedValues();
238
 
        }
239
 
        
240
 
        private void initialziedValues() {
241
 
                String addr2line = null;
242
 
                String cppfilt = null;
243
 
                IProject proj = getContainer().getProject();
244
 
                if (proj != null) {
245
 
                        try {
246
 
                                ICExtensionReference[] cext = CCorePlugin.getDefault().getBinaryParserExtensions(proj);
247
 
                                if (cext.length > 0) {
248
 
                                        initializeParserId();
249
 
                                        for (int i = 0; i < cext.length; i++) {
250
 
                                                if (cext[i].getID().equals(parserID)) {
251
 
                                                        addr2line = cext[0].getExtensionData("addr2line"); //$NON-NLS-1$
252
 
                                                        cppfilt = cext[0].getExtensionData("c++filt"); //$NON-NLS-1$
253
 
                                                        break;
254
 
                                                }
255
 
                                        }
256
 
                                }
257
 
                        } catch (CoreException e) {
258
 
                        }
259
 
                } else {
260
 
                        Preferences store = getContainer().getPreferences();
261
 
                        if (store != null) {
262
 
                                addr2line = store.getString(PREF_ADDR2LINE_PATH);
263
 
                                cppfilt = store.getString(PREF_CPPFILT_PATH);
264
 
                        }
265
 
                }
266
 
                fAddr2LineCommandText.setText((addr2line == null || addr2line.length() == 0) ? "addr2line" : addr2line); //$NON-NLS-1$
267
 
                fCPPFiltCommandText.setText((cppfilt == null || cppfilt.length() == 0) ? "c++filt" : cppfilt); //$NON-NLS-1$
268
 
        }
269
 
 
270
 
}