~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/newui/ManageConfigDialog.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) 2002, 2009 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
 
 * IBM Rational Software - Initial API and implementation
10
 
 *******************************************************************************/
11
 
package org.eclipse.cdt.ui.newui;
12
 
 
13
 
import java.util.Arrays;
14
 
 
15
 
import org.eclipse.core.resources.IProject;
16
 
import org.eclipse.core.runtime.CoreException;
17
 
import org.eclipse.core.runtime.IConfigurationElement;
18
 
import org.eclipse.core.runtime.IExtension;
19
 
import org.eclipse.core.runtime.IExtensionPoint;
20
 
import org.eclipse.core.runtime.Platform;
21
 
import org.eclipse.jface.dialogs.Dialog;
22
 
import org.eclipse.jface.dialogs.MessageDialog;
23
 
import org.eclipse.swt.SWT;
24
 
import org.eclipse.swt.events.SelectionAdapter;
25
 
import org.eclipse.swt.events.SelectionEvent;
26
 
import org.eclipse.swt.layout.GridData;
27
 
import org.eclipse.swt.layout.GridLayout;
28
 
import org.eclipse.swt.widgets.Button;
29
 
import org.eclipse.swt.widgets.Composite;
30
 
import org.eclipse.swt.widgets.Control;
31
 
import org.eclipse.swt.widgets.Shell;
32
 
import org.eclipse.swt.widgets.Table;
33
 
import org.eclipse.swt.widgets.TableColumn;
34
 
import org.eclipse.swt.widgets.TableItem;
35
 
 
36
 
import org.eclipse.cdt.core.model.util.CDTListComparator;
37
 
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
38
 
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
39
 
import org.eclipse.cdt.ui.CUIPlugin;
40
 
 
41
 
/**
42
 
 * @noextend This class is not intended to be subclassed by clients.
43
 
 */
44
 
public class ManageConfigDialog extends Dialog {
45
 
        private static final String EXTENSION_POINT_ID = "org.eclipse.cdt.ui.newCfgDialog"; //$NON-NLS-1$
46
 
        public static final String ELEMENT_NAME = "dialog"; //$NON-NLS-1$
47
 
        public static final String CLASS_NAME = "class"; //$NON-NLS-1$
48
 
        public static final String TITLE_NAME = "title"; //$NON-NLS-1$
49
 
        public static final String ID_NAME = "mbs_id"; //$NON-NLS-1$
50
 
 
51
 
        // String constants
52
 
        private static final String CMN_PREFIX = "BuildPropertyCommon"; //$NON-NLS-1$
53
 
        private static final String CMN_LABEL = CMN_PREFIX + ".label";  //$NON-NLS-1$
54
 
        private static final String NEW = CMN_LABEL + ".new";   //$NON-NLS-1$
55
 
        private static final String REMOVE = CMN_LABEL + ".remove";     //$NON-NLS-1$
56
 
        private static final String PREFIX = "ManageConfig";    //$NON-NLS-1$
57
 
        private static final String LABEL = PREFIX + ".label";  //$NON-NLS-1$
58
 
        private static final String RENAME = LABEL + ".rename"; //$NON-NLS-1$
59
 
        private static final String NEW_CONF_DLG = LABEL + ".new.config.dialog";        //$NON-NLS-1$
60
 
        private static final String RENAME_CONF_DLG = LABEL + ".rename.config.dialog";  //$NON-NLS-1$
61
 
        
62
 
        // The list of configurations to delete
63
 
        private ICProjectDescription des;
64
 
        private IProject prj;
65
 
        private String title;
66
 
        private String mbs_id;
67
 
        protected Table table;
68
 
        
69
 
        protected Button actBtn;
70
 
        protected Button newBtn;
71
 
        protected Button renBtn;
72
 
        protected Button delBtn;
73
 
 
74
 
        /**
75
 
         * @param parentShell
76
 
         */
77
 
        ManageConfigDialog(Shell parentShell, String _title, IProject _prj) {
78
 
                super(parentShell);
79
 
                setShellStyle(getShellStyle() | SWT.RESIZE);
80
 
                title = _title;
81
 
                prj = _prj;
82
 
        }
83
 
 
84
 
        @Override
85
 
        protected void configureShell(Shell shell) {
86
 
                super.configureShell(shell);
87
 
                if (title != null) shell.setText(title);
88
 
        }
89
 
        
90
 
        /* (non-Javadoc)
91
 
         * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
92
 
         */
93
 
        @Override
94
 
        protected Control createDialogArea(Composite parent) {
95
 
                Composite composite = new Composite(parent, SWT.NULL);
96
 
                composite.setFont(parent.getFont());
97
 
                composite.setLayout(new GridLayout(4, true));
98
 
                composite.setLayoutData(new GridData(GridData.FILL_BOTH));
99
 
        
100
 
                // Create the current config table
101
 
                table = new Table(composite, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
102
 
                GridData gd = new GridData(GridData.FILL_BOTH);
103
 
                gd.horizontalSpan = 4;
104
 
                table.setLayoutData(gd);
105
 
                table.setHeaderVisible(true);
106
 
                table.setLinesVisible(true);
107
 
                
108
 
                table.addSelectionListener(new SelectionAdapter() {
109
 
                        @Override
110
 
                        public void widgetSelected(SelectionEvent e) {
111
 
                                updateButtons();
112
 
                        }});
113
 
                
114
 
                TableColumn col = new TableColumn(table, SWT.NONE);
115
 
                col.setText(UIMessages.getString("ManageConfigDialog.1")); //$NON-NLS-1$
116
 
                col.setWidth(100);
117
 
                col = new TableColumn(table, SWT.NONE);
118
 
                col.setText(UIMessages.getString("ManageConfigDialog.2")); //$NON-NLS-1$
119
 
                col.setWidth(120);
120
 
                col = new TableColumn(table, SWT.NONE);
121
 
                col.setText(UIMessages.getString("ManageConfigDialog.3")); //$NON-NLS-1$
122
 
                col.setWidth(80);
123
 
 
124
 
                actBtn = new Button(composite, SWT.PUSH);
125
 
                actBtn.setText(UIMessages.getString("ManageConfigDialog.4")); //$NON-NLS-1$
126
 
                actBtn.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
127
 
                actBtn.addSelectionListener(new SelectionAdapter() {
128
 
                        @Override
129
 
                        public void widgetSelected(SelectionEvent e) {
130
 
                                TableItem[] tis = table.getSelection();
131
 
                                if (tis == null || tis.length != 1) return;
132
 
                                ICConfigurationDescription cfgd = (ICConfigurationDescription)tis[0].getData();
133
 
//                              cfgd.setActive();
134
 
                                des.setActiveConfiguration(cfgd);
135
 
                                updateData();
136
 
                        }} ); 
137
 
 
138
 
                newBtn = new Button(composite, SWT.PUSH);
139
 
                newBtn.setText(UIMessages.getString(NEW));
140
 
                newBtn.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
141
 
                newBtn.addSelectionListener(new SelectionAdapter() {
142
 
                        @Override
143
 
                        public void widgetSelected(SelectionEvent e) {
144
 
                                handleNewPressed();
145
 
                        }} ); 
146
 
 
147
 
                delBtn = new Button(composite, SWT.PUSH);
148
 
                delBtn.setText(UIMessages.getString(REMOVE));
149
 
                delBtn.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
150
 
                delBtn.addSelectionListener(new SelectionAdapter() {
151
 
                        @Override
152
 
                        public void widgetSelected(SelectionEvent e) {
153
 
                                handleRemovePressed();
154
 
                        }} ); 
155
 
 
156
 
                renBtn = new Button(composite, SWT.PUSH);
157
 
                renBtn.setText(UIMessages.getString(RENAME));
158
 
                renBtn.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
159
 
                renBtn.addSelectionListener(new SelectionAdapter() {
160
 
                        @Override
161
 
                        public void widgetSelected(SelectionEvent e) {
162
 
                                handleRenamePressed();
163
 
                        }} ); 
164
 
 
165
 
                des = CDTPropertyManager.getProjectDescription(composite, prj);
166
 
//              comp = composite;
167
 
                
168
 
                updateData();
169
 
        return composite;
170
 
        }
171
 
        /*
172
 
         * Event handler for the add button
173
 
         */
174
 
        protected void handleNewPressed() {
175
 
                INewCfgDialog dialog = handleSpecificMBS(mbs_id);
176
 
                if (dialog == null) { // default (core) implementation.
177
 
                        dialog = new NewConfigurationDialog(getShell());
178
 
                        dialog.setTitle(UIMessages.getString(NEW_CONF_DLG));
179
 
                }
180
 
                dialog.setProject(des); 
181
 
                if (dialog.open() == OK) updateData();
182
 
        }
183
 
        
184
 
        /**
185
 
         * Tries to load MBS-specific creation dialog a
186
 
         * @return false if there's no such feature 
187
 
         */
188
 
        protected INewCfgDialog handleSpecificMBS(String id) {
189
 
                IExtensionPoint extensionPoint = Platform.getExtensionRegistry()
190
 
                                .getExtensionPoint(EXTENSION_POINT_ID);
191
 
                if (extensionPoint == null) return null;
192
 
                IExtension[] extensions = extensionPoint.getExtensions();
193
 
                if (extensions == null) return null;
194
 
                for (int i = 0; i < extensions.length; ++i)     {
195
 
                        IConfigurationElement[] elements = extensions[i].getConfigurationElements();
196
 
                        for (int k = 0; k < elements.length; k++) {
197
 
                                if (elements[k].getName().equals(ELEMENT_NAME)) {
198
 
                                        if (! id.equals(elements[k].getAttribute(ID_NAME)))
199
 
                                                continue;
200
 
                                        INewCfgDialog dialog = null;
201
 
                                        try {
202
 
                                                dialog = (INewCfgDialog) elements[k].createExecutableExtension(CLASS_NAME);
203
 
                                                dialog.setTitle(elements[k].getAttribute(TITLE_NAME));
204
 
                                                dialog.setShell(getShell());
205
 
                                                return dialog;
206
 
                                        } catch (CoreException e) {
207
 
                                                System.out.println("Cannot create dialog: " + e.getLocalizedMessage()); //$NON-NLS-1$
208
 
                                                return null; 
209
 
                                        }
210
 
                                }                                       
211
 
                        }
212
 
                }
213
 
                return null;
214
 
        }
215
 
        
216
 
        /*
217
 
         * (non-javadoc) Event handler for the rename button
218
 
         */
219
 
        protected void handleRenamePressed() {
220
 
                int sel = table.getSelectionIndex();
221
 
                if (sel != -1) {
222
 
                        ICConfigurationDescription cfgd = (ICConfigurationDescription) table.getItem(sel).getData();
223
 
                        RenameConfigurationDialog dialog = new RenameConfigurationDialog(
224
 
                                        getShell(), cfgd, des.getConfigurations(),
225
 
                                        UIMessages.getString(RENAME_CONF_DLG));
226
 
                        if (dialog.open() == OK) {
227
 
                                cfgd.setName(dialog.getNewName());
228
 
                                cfgd.setDescription(dialog.getNewDescription());
229
 
                                updateData();
230
 
                        }
231
 
                }
232
 
        }
233
 
 
234
 
        /*
235
 
         * (non-javadoc) Event handler for the remove button
236
 
         */
237
 
        protected void handleRemovePressed() {
238
 
                TableItem[] tis = table.getSelection();
239
 
                if (tis == null || tis.length < 1) return;
240
 
                String[] names = new String[tis.length];
241
 
                for (int i=0; i<tis.length; i++) 
242
 
                        names[i] = tis[i].getText(0);
243
 
                // Get the confirmation from user before deleting the configuration
244
 
                Shell shell = CUIPlugin.getActiveWorkbenchShell();
245
 
                boolean shouldDelete = MessageDialog.openQuestion(shell,
246
 
                        UIMessages.getString("ManageConfig.deletedialog.title"), //$NON-NLS-1$
247
 
                        UIMessages.getFormattedString("ManageConfig.deletedialog.message",  //$NON-NLS-1$
248
 
                                names));
249
 
                if (shouldDelete) {
250
 
                        boolean wasActive = false;
251
 
                        for (int j=0; j<tis.length; j++) {
252
 
                                ICConfigurationDescription cfgd = (ICConfigurationDescription)tis[j].getData();
253
 
                                if (cfgd.isActive()) wasActive = true; 
254
 
                                des.removeConfiguration(cfgd);
255
 
                                
256
 
                        }
257
 
                        ICConfigurationDescription[] cfgds = des.getConfigurations(); 
258
 
                        if (wasActive && cfgds.length > 0) {
259
 
                                cfgds[0].setActive();
260
 
                                des.setActiveConfiguration(cfgds[0]);
261
 
                        }
262
 
                        updateData();
263
 
                }
264
 
        }
265
 
 
266
 
        private void updateButtons() {
267
 
                int sel = table.getSelectionCount();
268
 
                delBtn.setEnabled(sel > 0 & sel < table.getItemCount());
269
 
                renBtn.setEnabled(sel == 1);
270
 
                if (sel == 1) {
271
 
                        ICConfigurationDescription c = (ICConfigurationDescription)table.getSelection()[0].getData();
272
 
                        actBtn.setEnabled(c != null && !c.isActive());
273
 
                } else
274
 
                        actBtn.setEnabled(false);
275
 
        }
276
 
 
277
 
        /**
278
 
         * refresh configs table after changes
279
 
         */
280
 
        private void updateData() {
281
 
                table.removeAll();
282
 
                ICConfigurationDescription[] cfgds = des.getConfigurations();
283
 
                mbs_id = cfgds[0].getBuildSystemId();
284
 
                Arrays.sort(cfgds, CDTListComparator.getInstance());
285
 
                for (int i=0; i<cfgds.length; i++ ) {
286
 
                        TableItem t = new TableItem(table, 0);
287
 
                        t.setText(0, cfgds[i].getName());
288
 
                        t.setText(1, cfgds[i].getDescription());
289
 
                        t.setText(2, cfgds[i].isActive() ? UIMessages.getString("ManageConfigDialog.5") : ""); //$NON-NLS-1$ //$NON-NLS-2$
290
 
                        t.setData(cfgds[i]);
291
 
                }
292
 
                if (table.getItemCount() > 0) table.select(0);
293
 
                table.setFocus();
294
 
                updateButtons();
295
 
        }
296
 
        
297
 
        ICProjectDescription getProjectDescription(){
298
 
                return des;
299
 
        }
300
 
}