1
/*******************************************************************************
2
* Copyright (c) 2007, 2008 Intel 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
* Intel Corporation - Initial API and implementation
11
*******************************************************************************/
12
package org.eclipse.cdt.managedbuilder.ui.properties;
14
import java.util.ArrayList;
15
import java.util.Collections;
16
import java.util.Iterator;
17
import java.util.List;
19
import org.eclipse.cdt.internal.ui.CPluginImages;
20
import org.eclipse.cdt.managedbuilder.core.BuildListComparator;
21
import org.eclipse.cdt.managedbuilder.core.IFolderInfo;
22
import org.eclipse.cdt.managedbuilder.core.IModificationStatus;
23
import org.eclipse.cdt.managedbuilder.core.IResourceInfo;
24
import org.eclipse.cdt.managedbuilder.core.ITool;
25
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
26
import org.eclipse.cdt.managedbuilder.tcmodification.CompatibilityStatus;
27
import org.eclipse.cdt.managedbuilder.tcmodification.IModificationOperation;
28
import org.eclipse.cdt.managedbuilder.tcmodification.IToolListModification;
29
import org.eclipse.cdt.managedbuilder.tcmodification.IToolModification;
30
import org.eclipse.jface.dialogs.Dialog;
31
import org.eclipse.jface.dialogs.IDialogConstants;
32
import org.eclipse.jface.resource.JFaceResources;
33
import org.eclipse.swt.SWT;
34
import org.eclipse.swt.custom.CLabel;
35
import org.eclipse.swt.events.SelectionAdapter;
36
import org.eclipse.swt.events.SelectionEvent;
37
import org.eclipse.swt.events.SelectionListener;
38
import org.eclipse.swt.graphics.Color;
39
import org.eclipse.swt.graphics.Font;
40
import org.eclipse.swt.graphics.Image;
41
import org.eclipse.swt.layout.GridData;
42
import org.eclipse.swt.layout.GridLayout;
43
import org.eclipse.swt.widgets.Button;
44
import org.eclipse.swt.widgets.Composite;
45
import org.eclipse.swt.widgets.Control;
46
import org.eclipse.swt.widgets.Display;
47
import org.eclipse.swt.widgets.Label;
48
import org.eclipse.swt.widgets.Shell;
49
import org.eclipse.swt.widgets.Table;
50
import org.eclipse.swt.widgets.TableColumn;
51
import org.eclipse.swt.widgets.TableItem;
52
import org.eclipse.swt.widgets.Text;
54
public class ToolSelectionDialog extends Dialog {
56
static private final Image IMG_ARROW = CPluginImages.get(CPluginImages.IMG_PREFERRED);
57
static private final String EMPTY_STR = ""; //$NON-NLS-1$
58
static private final int COL_WIDTH = 300;
59
static private Font boldFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT);
60
static private Color red = Display.getDefault().getSystemColor(SWT.COLOR_RED);
61
static private Color gray = Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY);
64
private Button b_add, b_del, b_rep, b_all;
65
private CLabel errorLabel, l1;
67
private ArrayList<ITool> left, right;
69
public ArrayList<ITool> added, removed;
70
public ITool[] all, used;
71
public IFolderInfo fi;
72
public IToolListModification mod = null;
74
public ToolSelectionDialog(Shell shell, IResourceInfo ri) {
76
setShellStyle(getShellStyle() | SWT.RESIZE);
80
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
82
protected void configureShell(Shell shell) {
83
super.configureShell(shell);
84
shell.setText(Messages.getString("ToolSelectionDialog.0")); //$NON-NLS-1$
87
protected Control createDialogArea(Composite parent) {
88
Composite composite = new Composite(parent, SWT.NULL);
89
composite.setFont(parent.getFont());
90
composite.setLayout(new GridLayout(3, false));
91
GridData gd = new GridData(GridData.FILL_BOTH);
93
composite.setLayoutData(gd);
95
added = new ArrayList<ITool>();
96
removed = new ArrayList<ITool>();
97
left = new ArrayList<ITool>();
98
right = new ArrayList<ITool>();
100
Composite c1 = new Composite(composite, SWT.NONE);
101
c1.setLayoutData(new GridData(GridData.FILL_BOTH));
102
c1.setLayout(new GridLayout(1, false));
104
Composite c2 = new Composite(composite, SWT.BORDER);
105
c2.setLayoutData(new GridData(GridData.FILL_VERTICAL));
106
c2.setLayout(new GridLayout(1, false));
108
Composite c3 = new Composite(composite, SWT.NONE);
109
c3.setLayoutData(new GridData(GridData.FILL_BOTH));
110
c3.setLayout(new GridLayout(1, false));
112
t1 = new Table(c1, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
113
gd = new GridData(GridData.FILL_BOTH);
114
t1.setLayoutData(gd);
115
t1.setHeaderVisible(true);
116
t1.setLinesVisible(true);
117
t1.addSelectionListener(new SelectionListener() {
118
public void widgetDefaultSelected(SelectionEvent e) {
121
public void widgetSelected(SelectionEvent e) {
125
TableColumn col = new TableColumn(t1, SWT.NONE);
126
col.setText(Messages.getString("ToolSelectionDialog.1")); //$NON-NLS-1$
127
col.setWidth(COL_WIDTH);
129
l1 = new CLabel(c1, SWT.BORDER);
130
l1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
132
t2 = new Table(c3, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
133
t2.setLayoutData(new GridData(GridData.FILL_BOTH));
134
t2.setHeaderVisible(true);
135
t2.setLinesVisible(true);
136
t2.addSelectionListener(new SelectionListener() {
137
public void widgetDefaultSelected(SelectionEvent e) {
140
public void widgetSelected(SelectionEvent e) {
144
col = new TableColumn(t2, SWT.NONE);
145
col.setText(Messages.getString("ToolSelectionDialog.2")); //$NON-NLS-1$
146
col.setWidth(COL_WIDTH);
148
txt2 = new Text(c3, SWT.BORDER | SWT.WRAP | SWT.MULTI |
149
SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
150
gd = new GridData(GridData.FILL_BOTH);
152
gd.minimumHeight = 100;
153
txt2.setLayoutData(gd);
155
b_add = new Button(c2, SWT.PUSH);
156
b_add.setText(Messages.getString("ToolSelectionDialog.12")); //$NON-NLS-1$
157
b_add.addSelectionListener(new SelectionAdapter() {
158
public void widgetSelected(SelectionEvent e) {
159
int x = t1.getSelectionIndex();
162
ITool tool = (ITool)t1.getItem(x).getData();
165
mod.changeProjectTools(null, tool);
168
b_add.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false));
170
b_rep = new Button(c2, SWT.PUSH);
171
b_rep.setText(Messages.getString("ToolSelectionDialog.14")); //$NON-NLS-1$
172
b_rep.addSelectionListener(new SelectionAdapter() {
173
public void widgetSelected(SelectionEvent e) {
176
b_rep.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false));
178
b_del = new Button(c2, SWT.PUSH);
179
b_del.setText(Messages.getString("ToolSelectionDialog.13")); //$NON-NLS-1$
180
b_del.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
181
b_del.addSelectionListener(new SelectionAdapter() {
182
public void widgetSelected(SelectionEvent e) {
183
int x = t2.getSelectionIndex();
186
ITool tool = (ITool)t2.getItem(x).getData();
188
left.add(ManagedBuildManager.getRealTool(tool));
190
mod.changeProjectTools(tool, null);
194
b_del.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false));
197
new Label(c2, SWT.NONE).setLayoutData(new GridData(GridData.FILL, SWT.FILL, true, true));
199
b_all = new Button(c2, SWT.CHECK | SWT.WRAP);
200
b_all.setText(Messages.getString("ToolSelectionDialog.15")); //$NON-NLS-1$
201
b_all.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
202
b_all.addSelectionListener(new SelectionAdapter() {
203
public void widgetSelected(SelectionEvent e) {
206
b_all.setLayoutData(new GridData(GridData.FILL, SWT.END, true, false));
208
errorLabel = new CLabel(composite, SWT.NONE);
209
gd = new GridData(GridData.FILL_HORIZONTAL);
210
gd.horizontalSpan = 3;
211
errorLabel.setLayoutData(gd);
212
errorLabel.setForeground(red);
214
used = fi.getTools();
215
for (int i=0; i< used.length; i++) {
217
for (int j = 0; j<all.length; j++) {
218
if (all[j] != null && all[j].matches(used[i]))
222
for (int j = 0; j<all.length; j++) {
223
if (all[j] != null) left.add(all[j]);
231
* Reaction for <Replace> button press or double-click.
233
private void handleReplace() {
234
if (! b_rep.isEnabled())
236
int x1 = t1.getSelectionIndex();
237
int x2 = t2.getSelectionIndex();
238
if (x1 == -1 || x2 == -1)
240
ITool tool1 = (ITool)t1.getItem(x1).getData();
241
ITool tool2 = (ITool)t2.getItem(x2).getData();
245
left.add(ManagedBuildManager.getRealTool(tool2));
247
mod.changeProjectTools(tool2, tool1);
253
* Removes "triangle" marks from all table's items.
254
* @param t - affected table.
256
private void removeArrows(Table t) {
257
for (int j=0; j<t.getItemCount(); j++) {
258
TableItem ti = t.getItem(j);
259
if (IMG_ARROW.equals(ti.getImage()))
260
ti.setImage((Image)null);
265
* Adds "triangle" marks for items which can replace selected one.
267
* @param src - table where selected element is located
268
* @param dst - table where marks should be set
269
* @param b - button (add or del) to be enabled
271
private void markReplace(Table src, Table dst, Button b) {
272
int x = src.getSelectionIndex();
275
ITool tool = (ITool)src.getItem(x).getData();
276
IToolModification tm = mod.getToolModification(tool);
279
IModificationOperation[] mo = tm.getSupportedOperations();
280
if (mo == null || mo.length == 0)
282
for (int j=0; j<dst.getItemCount(); j++) {
283
TableItem ti = dst.getItem(j);
284
ITool tt = (ITool)ti.getData();
285
for (int i=0; i<mo.length; i++) { // List of modifications
286
ITool t = mo[i].getReplacementTool();
288
b.setEnabled(true); // enable Add or Del
289
else if (t.matches(tt)) {
290
ti.setImage(IMG_ARROW);
291
break; // exit from modif. loop
298
* Called after user has selected item either in t1 or in t2.
300
private void handleSelection() {
303
b_add.setEnabled(b_all.getSelection() && t1.getItemCount() > 0);
304
b_rep.setEnabled(b_all.getSelection() && t1.getItemCount() > 0 && t2.getItemCount() > 0);
305
b_del.setEnabled(b_all.getSelection() && t2.getItemCount() > 0);
307
if (t1.isFocusControl()) {
308
markReplace(t1, t2, b_add);
309
int j = adjustPosition(t2);
310
markReplace(t2, t1, b_del);
312
b_rep.setEnabled(true);
314
markReplace(t2, t1, b_del);
315
int j = adjustPosition(t1);
316
markReplace(t1, t2, b_add);
318
b_rep.setEnabled(true);
320
showErrorMessage(t1, false);
321
showErrorMessage(t2, true);
325
* Changes position of inactive table
326
* to enable replacement, if possible.
328
* returns new position or -1 if there's no tools to replace.
330
private int adjustPosition(Table t) {
331
int j = t.getSelectionIndex();
332
TableItem ti = t.getItem(j);
333
if (IMG_ARROW.equals(ti.getImage()))
335
for (j=0; j<t.getItemCount(); j++) {
337
if (IMG_ARROW.equals(ti.getImage())) {
346
* Displays appropriate error message for selected tool.
348
* @param t - affected table
349
* @param isPrj - whether
351
private void showErrorMessage(Table t, boolean isPrj) {
352
int x = t.getSelectionIndex();
354
txt2.setText(EMPTY_STR);
356
l1.setText(EMPTY_STR);
361
String message = EMPTY_STR;
363
TableItem ti = t.getItem(x);
364
ITool tool = (ITool)ti.getData();
365
IToolModification tm = mod.getToolModification(tool);
366
if (tm == null || tm.isCompatible()) {
367
if (IMG_ARROW.equals(ti.getImage()) && !isPrj) {
368
TableItem[] tis = t2.getSelection();
369
if (tis != null && tis.length > 0) {
370
message = Messages.getString("ToolSelectionDialog.16") + //$NON-NLS-1$
371
((ITool)tis[0].getData()).getUniqueRealName();
375
CompatibilityStatus cs = tm.getCompatibilityStatus();
377
message = ToolChainEditTab.getCompatibilityMessage(cs);
379
message = cs.getMessage() + cs.getSeverity();
380
image = ToolChainEditTab.getErrorIcon(cs);
384
txt2.setText(message); // tmp
392
* Adds given tool to the table, sets appropriate font.
394
* @param tool - tool to add
395
* @param table - affected table
396
* @param bold - whether the tool should be marked by bold font.
398
private void add(ITool tool, Table table, boolean bold) {
399
IToolModification tm = mod.getToolModification(tool);
400
TableItem ti = new TableItem(table, 0);
401
ti.setText(tool.getUniqueRealName());
403
ti.setFont(boldFont);
405
if (tm != null /*&& table.equals(t2)*/ && !tm.isCompatible())
406
ti.setForeground(table.equals(t2) ? red : gray);
410
* Refresh data in t1 and t2 tables
412
private void updateData() {
415
int t1_pos = t1.getSelectionIndex();
416
int t2_pos = t2.getSelectionIndex();
420
Collections.sort(left, BuildListComparator.getInstance());
422
for (ITool t : left) {
423
boolean exists = false;
424
for (int i=0; i<all.length; i++) {
425
if (all[i] != null && t.matches(all[i])) {
430
if (!exists) removed.add(t);
433
for (ITool t : right) {
434
boolean exists = false;
435
for (int i=0; i<used.length; i++) {
436
if (t.matches(used[i])) {
441
if (!exists) added.add(t);
444
IModificationStatus st = fi.getToolChainModificationStatus(
445
(ITool[])removed.toArray(new ITool[removed.size()]),
446
(ITool[])added.toArray(new ITool[added.size()]));
448
errorLabel.setText(EMPTY_STR);
449
if(getButton(IDialogConstants.OK_ID) != null)
450
getButton(IDialogConstants.OK_ID).setEnabled(true);
452
int c = st.getCode();
453
String s = EMPTY_STR;
454
if ((c & IModificationStatus.TOOLS_CONFLICT) != 0) {
455
s = s + Messages.getString("ToolSelectionDialog.7"); //$NON-NLS-1$
456
ITool[][] tools = st.getToolsConflicts();
457
List<String> conflictTools = new ArrayList<String>();
458
for (int k=0; k<t2.getItemCount(); k++) {
459
TableItem ti = t2.getItem(k);
460
ITool t = (ITool)ti.getData();
462
for (int i=0;i<tools.length;i++) {
463
for (int j=0;j<tools[i].length;j++) {
464
if (t.matches(tools[i][j])) {
465
conflictTools.add(ti.getText());
466
ti.setForeground(red);
472
//bug 189229 - provide more information in the error message for accessibility
473
Iterator<String> iterator = conflictTools.iterator();
474
s = s+" "+ iterator.next(); //$NON-NLS-1$
475
while (iterator.hasNext()) {
476
s = s + ", " + iterator.next(); //$NON-NLS-1$
479
if ((c & IModificationStatus.TOOLS_DONT_SUPPORT_MANAGED_BUILD) != 0) {
480
s = s + Messages.getString("ToolSelectionDialog.8"); //$NON-NLS-1$
481
ITool[] tools = st.getNonManagedBuildTools();
482
for (int k=0; k<t2.getItemCount(); k++) {
483
TableItem ti = t2.getItem(k);
484
ITool t = (ITool)ti.getData();
485
for (int i=0;i<tools.length;i++) {
486
if (t.matches(tools[i])) {
487
// ti.setBackground(gray);
493
if ((c & IModificationStatus.PROPS_NOT_DEFINED) != 0) {
494
s = s + Messages.getString("ToolSelectionDialog.9"); //$NON-NLS-1$
496
if ((c & IModificationStatus.PROPS_NOT_SUPPORTED) != 0) {
497
s = s + Messages.getString("ToolSelectionDialog.10"); //$NON-NLS-1$
499
if ((c & IModificationStatus.REQUIRED_PROPS_NOT_SUPPORTED) != 0) {
500
s = s + Messages.getString("ToolSelectionDialog.11"); //$NON-NLS-1$
502
errorLabel.setText(s);
503
// if(getButton(IDialogConstants.OK_ID) != null)
504
// getButton(IDialogConstants.OK_ID).setEnabled(false);
506
if (t1_pos > -1 && t1_pos < t1.getItemCount())
508
else if (t1.getItemCount() > 0)
510
if (t2_pos > -1 && t2_pos < t2.getItemCount())
512
else if (t2.getItemCount() > 0)