Skip to main content
summaryrefslogtreecommitdiffstats
blob: 062155d8d2fc0cb62c801018da18176ddbb758c2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
/*******************************************************************************
 * Copyright (c) 2007, 2009 Intel Corporation, QNX Software Systems, and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Intel Corporation - Initial API and implementation
 * QNX Software Systems - [269571] Apply button failure on tool changes
 *******************************************************************************/
package org.eclipse.cdt.managedbuilder.ui.properties;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;

import org.eclipse.cdt.core.settings.model.ICResourceDescription;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IFileInfo;
import org.eclipse.cdt.managedbuilder.core.IFolderInfo;
import org.eclipse.cdt.managedbuilder.core.IHoldsOptions;
import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.IOptionCategory;
import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration;
import org.eclipse.cdt.managedbuilder.core.IResourceInfo;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.internal.core.MultiConfiguration;
import org.eclipse.cdt.managedbuilder.internal.macros.BuildMacroProvider;
import org.eclipse.cdt.ui.newui.AbstractPage;
import org.eclipse.cdt.ui.newui.PageLayout;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.preference.IPreferencePageContainer;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.ScrollBar;


public class ToolSettingsTab extends AbstractCBuildPropertyTab implements IPreferencePageContainer {
		/*
		 * Dialog widgets
		 */
		private TreeViewer optionList;
		private SashForm sashForm;
		private Composite settingsPageContainer;
		private ScrolledComposite containerSC;

		/*
		 * Bookeeping variables
		 */
		private Map<String, List<AbstractToolSettingUI>> configToPageListMap;
		private IPreferenceStore settingsStore;
		private AbstractToolSettingUI currentSettingsPage;
		private ToolListElement selectedElement;
		private ToolListContentProvider listprovider;
		private Object propertyObject;

		private IResourceInfo fInfo;
		
		@Override
		public void createControls(Composite par)  {
			super.createControls(par);
			usercomp.setLayout(new GridLayout());

			configToPageListMap = new HashMap<String, List<AbstractToolSettingUI>>();
			settingsStore = ToolSettingsPrefStore.getDefault();
			
			// Create the sash form
			sashForm = new SashForm(usercomp, SWT.NONE);
			sashForm.setOrientation(SWT.HORIZONTAL);
			sashForm.setLayoutData(new GridData(GridData.FILL_BOTH));
			
			GridLayout layout = new GridLayout();
			layout.numColumns = 2;
			layout.marginHeight = 5;
			sashForm.setLayout(layout);
			createSelectionArea(sashForm);
			createEditArea(sashForm);
			
			usercomp.addControlListener(new ControlAdapter() {
				@Override
				public void controlResized(ControlEvent e) {
					specificResize();
				}});
			
			propertyObject = page.getElement();
			setValues();
		}
		
		private void specificResize() {
			Point p1 = optionList.getTree().computeSize(-1, -1);
			Point p2 = optionList.getTree().getSize();
			Point p3 = usercomp.getSize();
			p1.x += calcExtra();
			if (p3.x >= p1.x && (p1.x < p2.x || (p2.x * 2 < p3.x))) {
				optionList.getTree().setSize(p1.x , p2.y);
				sashForm.setWeights(new int[] {p1.x, (p3.x - p1.x)});
			} 
		}
		
		private int calcExtra() {
			int x = optionList.getTree().getBorderWidth() * 2;
			ScrollBar sb = optionList.getTree().getVerticalBar();
			if (sb != null) x += sb.getSize().x;
			return x;
		}
		
		protected void createSelectionArea (Composite parent) {
			optionList = new TreeViewer(parent, SWT.SINGLE|SWT.H_SCROLL|SWT.V_SCROLL|SWT.BORDER);
			optionList.addSelectionChangedListener(new ISelectionChangedListener() {
				public void selectionChanged(SelectionChangedEvent event) {
					handleOptionSelection();
				}});
			optionList.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
			optionList.setLabelProvider(new ToolListLabelProvider());
			optionList.addFilter(new ViewerFilter() {
				@Override
				public boolean select(Viewer viewer,
										Object parent,
										Object element) {
					if(parent instanceof IResourceConfiguration && element instanceof ITool) {
						return !((ITool)element).getCustomBuildStep();
					} else {
						return true;
					}
				}
			});
		}

		/* (non-Javadoc)
		 * Method displayOptionsForCategory
		 * @param category
		 */
		private void displayOptionsForCategory(ToolListElement toolListElement) {
			
			selectedElement = toolListElement;
			IOptionCategory category = toolListElement.getOptionCategory();
			IHoldsOptions optionHolder = toolListElement.getHoldOptions();

			AbstractToolSettingUI oldPage = currentSettingsPage;
			currentSettingsPage = null;

			// Create a new settings page if necessary
			List<AbstractToolSettingUI> pages = getPagesForConfig();
			ListIterator<AbstractToolSettingUI> iter = pages.listIterator();
			
			while (iter.hasNext()) {
				AbstractToolSettingUI page = iter.next();
				if (page.isFor(optionHolder, category)) {
					currentSettingsPage = page;
					break;
				}
			}
			if (currentSettingsPage == null) {
				currentSettingsPage = new BuildOptionSettingsUI(
						this, 
						fInfo, 
						optionHolder, 
						category);
				pages.add(currentSettingsPage);
				currentSettingsPage.setContainer(this);
				if (currentSettingsPage.getControl() == null) {
					currentSettingsPage.createControl(settingsPageContainer);
				}
			}
			
			// Make all the other pages invisible
			Control[] children = settingsPageContainer.getChildren();
			Control currentControl = currentSettingsPage.getControl();
			for (int i = 0; i < children.length; i++) {
				if (children[i] != currentControl)
					children[i].setVisible(false);
			}
			currentSettingsPage.setVisible(true);
			currentSettingsPage.updateFields();
			
			if (oldPage != null  && oldPage != currentSettingsPage)
				oldPage.setVisible(false);

			// Set the size of the scrolled area
			containerSC.setMinSize(currentSettingsPage.computeSize());
			settingsPageContainer.layout();
		}

		/* (non-Javadoc)
		 * Method displayOptionsForTool
		 * @param tool
		 */
		private void displayOptionsForTool(ToolListElement toolListElement) {
			selectedElement = toolListElement;
			ITool tool = toolListElement.getTool();
			
			// Cache the current build setting page
			AbstractToolSettingUI oldPage = currentSettingsPage;
			currentSettingsPage = null;

			// Create a new page if we need one
			List<AbstractToolSettingUI> pages = getPagesForConfig();
			ListIterator<AbstractToolSettingUI> iter = pages.listIterator();
			while (iter.hasNext()) {
				AbstractToolSettingUI page = iter.next();
				if (page.isFor(tool, null)) {
					currentSettingsPage = page;
					break;
				}
			}
			
			if (currentSettingsPage == null) {
				currentSettingsPage = new BuildToolSettingUI(this, fInfo, tool);
				pages.add(currentSettingsPage);
				currentSettingsPage.setContainer(this);
				if (currentSettingsPage.getControl() == null) {
					currentSettingsPage.createControl(settingsPageContainer);
				}
			}
			// Make all the other pages invisible
			Control[] children = settingsPageContainer.getChildren();
			Control currentControl = currentSettingsPage.getControl();
			for (int i = 0; i < children.length; i++) {
				if (children[i] != currentControl)
					children[i].setVisible(false);
			}
			
			// Make the current page visible
			currentSettingsPage.setVisible(true);

			// Save the last page build options.
			if (oldPage != null && oldPage != currentSettingsPage){
				oldPage.storeSettings();
			}
			currentSettingsPage.setValues();

			if (oldPage != null && oldPage != currentSettingsPage)
				oldPage.setVisible(false);

			// Set the size of the scrolled area
			containerSC.setMinSize(currentSettingsPage.computeSize());
			settingsPageContainer.layout();
		}
		
		/* (non-Javadoc)
		 * Add the tabs relevant to the project to edit area tab folder.
		 */
		protected void createEditArea(Composite parent) {
			containerSC = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
			containerSC.setExpandHorizontal(true);
			containerSC.setExpandVertical(true);
			
			// Add a container for the build settings page
			settingsPageContainer = new Composite(containerSC, SWT.NULL);
			settingsPageContainer.setLayout(new PageLayout());

			containerSC.setContent(settingsPageContainer);
			containerSC.setMinSize(settingsPageContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT));
			settingsPageContainer.layout();
		}

		@Override
		public void setVisible(boolean visible){
			if(visible){
				selectedElement = null;
				updateData(page.getResDesc());
			}
			super.setVisible(visible);
		}

		protected void setValues() {
			/*
			 *  This method updates the context of the build property pages
			 *   - Which configuration/resource configuration is selected
			 *   - Which tool/option category is selected
			 *    
			 *  It is called:
			 *   - When a property page becomes visible
			 *   - When the user changes the configuration selection
			 *   - When the user changes the "exclude" setting for a resource
			 */

			//  Create the Tree Viewer content provider if first time
			if (listprovider == null) {
				IResource resource = (IResource) propertyObject;
				listprovider = new ToolListContentProvider(resource.getType());
				optionList.setContentProvider(listprovider);
			}

			//  Update the selected configuration and the Tree Viewer
			ToolListElement[] newElements;
			
			optionList.setInput(fInfo);	
			newElements = (ToolListElement[])listprovider.getElements(fInfo);
			optionList.expandAll();
			
			//  Determine what the selection in the tree should be
			//  If the saved selection is not null, try to match the saved selection
			//  with an object in the new element list.
			//  Otherwise, select the first tool in the tree
			Object primaryObject = null;
			if (selectedElement != null) {
				selectedElement = matchSelectionElement(selectedElement, newElements);
			}
				
			if (selectedElement == null) {
				selectedElement = (newElements != null && newElements.length > 0 ? newElements[0] : null);
			}
				
			if (selectedElement != null) {
				primaryObject = selectedElement.getTool();
				if (primaryObject == null) {
					primaryObject = selectedElement.getOptionCategory();
				}
				if (primaryObject != null) {
					if (primaryObject instanceof IOptionCategory) {
						((ToolSettingsPrefStore)settingsStore).setSelection(getResDesc(), selectedElement, (IOptionCategory)primaryObject);
					}
					optionList.setSelection(new StructuredSelection(selectedElement), true);
				}
			}
			specificResize();
		}
							
		private ToolListElement matchSelectionElement(ToolListElement currentElement, ToolListElement[] elements) {
			//  First, look for an exact match
			ToolListElement match = exactMatchSelectionElement(currentElement, elements);
			if (match == null)
				//  Else, look for the same tool/category in the new set of elements
				match = equivalentMatchSelectionElement(currentElement, elements);
			return match;
		}

		private ToolListElement exactMatchSelectionElement(ToolListElement currentElement, ToolListElement[] elements) {
			for (int i=0; i<elements.length; i++) {
				ToolListElement e = elements[i];
				if (e == currentElement) {
					return currentElement;
				}
				e = exactMatchSelectionElement(currentElement, e.getChildElements());
				if (e != null) return e;
			}
			return null;
		}

		private ToolListElement equivalentMatchSelectionElement(ToolListElement currentElement, ToolListElement[] elements) {
			for (int i=0; i<elements.length; i++) {
				ToolListElement e = elements[i];
				if (e.isEquivalentTo(currentElement)) {
					return e;
				}
				e = equivalentMatchSelectionElement(currentElement, e.getChildElements());
				if (e != null) return e;
			}
			return null;
		}
		
		private void handleOptionSelection() {
			// Get the selection from the tree list
			if (optionList == null) return;
			IStructuredSelection selection = (IStructuredSelection) optionList.getSelection();
		
			// Set the option page based on the selection
			ToolListElement toolListElement = (ToolListElement)selection.getFirstElement();
			if (toolListElement != null) {
				IOptionCategory cat = toolListElement.getOptionCategory();
				if (cat == null)
					cat = (IOptionCategory)toolListElement.getTool();
				if (cat != null) 
					((ToolSettingsPrefStore)settingsStore).setSelection(getResDesc(), toolListElement, cat);

				cat = toolListElement.getOptionCategory();
				if (cat != null) {
					displayOptionsForCategory(toolListElement);
				} else {
					displayOptionsForTool(toolListElement);
				}
				
				ScrollBar sb = containerSC.getHorizontalBar();
				if (sb != null && sb.isVisible()) {
					settingsPageContainer.pack(true);
					containerSC.setMinSize(settingsPageContainer.getSize());
					((AbstractPage)page).resize();
				}
			}
		}

		/*
		 *  (non-Javadoc)
		 * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performDefaults()
		 */
		@Override
		protected void performDefaults() {
			if (page.isForProject()) {
				ManagedBuildManager.resetConfiguration(page.getProject(), getCfg());
			} else {
				ManagedBuildManager.resetOptionSettings(fInfo);
			}
			ITool tools[];
			if (page.isForProject()) 
				tools = getCfg().getFilteredTools();
			else
				tools = getResCfg(getResDesc()).getTools();
			for( int i = 0; i < tools.length; i++ ){
				if(!tools[i].getCustomBuildStep()) {
					tools[i].setToolCommand(null);
					tools[i].setCommandLinePattern(null);
				}
			}
			// Reset the category or tool selection and run selection event handler
			selectedElement = null;
			handleOptionSelection();
			setDirty(true);
		}

		/*
		 *  (non-Javadoc)
		 * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performApply(IProgressMonitor)
		 */
		private void copyHoldsOptions(IHoldsOptions src, IHoldsOptions dst, IResourceInfo res){
			if(src instanceof ITool) {
				ITool t1 = (ITool)src;
				ITool t2 = (ITool)dst;
				if (t1.getCustomBuildStep()) return; 
				t2.setToolCommand(t1.getToolCommand());
				t2.setCommandLinePattern(t1.getCommandLinePattern());
			}
			IOption op1[] = src.getOptions();
			IOption op2[] = dst.getOptions();
			for(int i = 0; i < op1.length; i++) {
				setOption(op1[i], op2[i], dst, res);
			}
		}
		
		protected void addFilter(ViewerFilter filter) {
			optionList.addFilter(filter);
		}
		
		@SuppressWarnings("unchecked")
		protected void setOption(IOption op1, IOption op2, IHoldsOptions dst, IResourceInfo res){
			try {
				switch (op1.getValueType()) {
					case IOption.BOOLEAN :
						boolean boolVal = op1.getBooleanValue();
						ManagedBuildManager.setOption(res, dst, op2, boolVal);
						break;
					case IOption.ENUMERATED :
						String enumVal = op1.getStringValue();
						String enumId = op1.getEnumeratedId(enumVal);
						String out = (enumId != null && enumId.length() > 0) ? enumId : enumVal;
						ManagedBuildManager.setOption(res, dst, op2, out);
						break;
					case IOption.STRING :
						ManagedBuildManager.setOption(res, dst, op2, op1.getStringValue());
						break;
					case IOption.STRING_LIST :
					case IOption.INCLUDE_PATH :
					case IOption.PREPROCESSOR_SYMBOLS :
					case IOption.LIBRARIES :
					case IOption.OBJECTS :
					case IOption.INCLUDE_FILES:
					case IOption.LIBRARY_PATHS:
					case IOption.LIBRARY_FILES:
					case IOption.MACRO_FILES:
					case IOption.UNDEF_INCLUDE_PATH:
					case IOption.UNDEF_PREPROCESSOR_SYMBOLS:
					case IOption.UNDEF_INCLUDE_FILES:
					case IOption.UNDEF_LIBRARY_PATHS:
					case IOption.UNDEF_LIBRARY_FILES:
					case IOption.UNDEF_MACRO_FILES:
						String[] data = ((List<String>)op1.getValue()).toArray(new String[0]);
						ManagedBuildManager.setOption(res, dst, op2, data);
						break;
					default :
						break;
				}
			} catch (BuildException e) {
			} catch (ClassCastException e) {
			}
		}
		
		protected boolean containsDefaults(){
			IConfiguration parentCfg = fInfo.getParent().getParent();
			ITool tools[] = fInfo.getParent().getTools();
			for(int i = 0; i < tools.length; i++){
				ITool tool = tools[i];
				if(!tool.getCustomBuildStep()){
					ITool cfgTool = parentCfg.getToolChain().getTool(tool.getSuperClass().getId());
					//  Check for a non-default command or command-line-pattern
					if(cfgTool != null){
						if (!(tool.getToolCommand().equals(cfgTool.getToolCommand()))) return false;
						if (!(tool.getCommandLinePattern().equals(cfgTool.getCommandLinePattern()))) return false;
					}
					//  Check for a non-default option
					IOption options[] = tool.getOptions();
					for( int j = 0; j < options.length; j++){
						IOption option = options[j];
						if(option.getParent() == tool){
							IOption ext = option;
							do{
								if(ext.isExtensionElement())
									break;
							} while((ext = ext.getSuperClass()) != null);

							if(ext != null){
								if(cfgTool != null){
									IOption defaultOpt = cfgTool.getOptionBySuperClassId(ext.getId());
									try {								
										if(defaultOpt != null && defaultOpt.getValueType() == option.getValueType()){
											Object value = option.getValue();
											Object defaultVal = defaultOpt.getValue();
											
											if(value.equals(defaultVal))
												continue;
											//TODO: check list also
										}
									}catch (BuildException e) {
									}
								}
							}
							return false;
						}
					}
				}
			}
			return true;
		}

		/* (non-Javadoc)
		 * Answers the list of settings pages for the selected configuration 
		 */
		private List<AbstractToolSettingUI> getPagesForConfig() {
			if (getCfg() == null) return null;
			List<AbstractToolSettingUI> pages = configToPageListMap.get(getCfg().getId());
			if (pages == null) {
				pages = new ArrayList<AbstractToolSettingUI>();
				configToPageListMap.put(getCfg().getId(), pages);	
			}
			return pages;
		}

		public IPreferenceStore getPreferenceStore() {
			return settingsStore;
		}

		/**
		 * Sets the "dirty" state
		 */
		public void setDirty(boolean b) {
			List<AbstractToolSettingUI> pages = getPagesForConfig();
			if (pages == null) return;
			ListIterator<AbstractToolSettingUI> iter = pages.listIterator();
			while (iter.hasNext()) {
				AbstractToolSettingUI page = iter.next();
				if (page == null) continue;
				page.setDirty(b);
			}
		}

		/**
		 * Returns the "dirty" state
		 */
		public boolean isDirty() {
			// Check each settings page
			List<AbstractToolSettingUI> pages = getPagesForConfig();
			// Make sure we have something to work on
			if (pages == null) {
				// Nothing to do
				return false;
			}
			ListIterator<AbstractToolSettingUI> iter = pages.listIterator();
			while (iter.hasNext()) {
				AbstractToolSettingUI page = iter.next();
				if (page == null) continue;
				if (page.isDirty()) return true;
			}
			return false;
		}
		
		/**
		 * Returns the build macro provider to be used for macro resolution
		 * In case the "Build Macros" tab is available, returns the BuildMacroProvider
		 * supplied by that tab. 
		 * Unlike the default provider, that provider also contains
		 * the user-modified macros that are not applied yet
		 * If the "Build Macros" tab is not available, returns the default BuildMacroProvider
		 */
		public BuildMacroProvider obtainMacroProvider(){
			return (BuildMacroProvider)ManagedBuildManager.getBuildMacroProvider();
		}
	
	@Override
	public void updateData(ICResourceDescription cfgd) {
			fInfo = getResCfg(cfgd);
			setValues();
			handleOptionSelection();
	}

	@Override
	protected void performApply(ICResourceDescription src, ICResourceDescription dst) {
		IResourceInfo ri1 = getResCfg(src);
		IResourceInfo ri2 = getResCfg(dst);
		copyHoldsOptions(ri1.getParent().getToolChain(), ri2.getParent().getToolChain(), ri2);
		ITool[] t1, t2;
		if (ri1 instanceof IFolderInfo){
			t1 = ((IFolderInfo)ri1).getFilteredTools();
			t2 = ((IFolderInfo)ri2).getFilteredTools();
		} else if (ri1 instanceof IFileInfo) {
			t1 = ((IFileInfo)ri1).getToolsToInvoke();
			t2 = ((IFileInfo)ri2).getToolsToInvoke();
		} else return;
		
		// get the corresponding pairs of tools for which we can copy settings
		// and do the copy
		for (Map.Entry<ITool, ITool> pair : getToolCorrespondence(t1, t2).entrySet()) {
			copyHoldsOptions(pair.getKey(), pair.getValue(), ri2);
		}
		
		setDirty(false);
	}
	
	/**
	 * Computes the correspondence of tools in the copy-from set (<tt>t1</tt>) and the
	 * copy-to set (<tt>t2</tt>) in an apply operation.  The resulting pairs are in the order
	 * of the <tt>t2</tt> array.  Note that tools that have no correspondence do not appear in
	 * the result, and that order is not significant.  Also, in case of replication of tools
	 * in a chain (?) they are matched one-for one in the order in which they are found in
	 * each chain.
	 * 
	 * @param t1,&nbsp;t2 two groups of tools.  Neither may be <code>null</code>
	 * @return the one-for-one correspondence of tools, in order of <tt>t2</tt>
	 */
	private Map<ITool, ITool> getToolCorrespondence(ITool[] t1, ITool[] t2) {
		Map<ITool, ITool> result = new java.util.LinkedHashMap<ITool, ITool>();
		Map<ITool, List<ITool>> realT1Tools = new java.util.LinkedHashMap<ITool, List<ITool>>();
		
		for (ITool next : t1) {
			ITool real = ManagedBuildManager.getRealTool(next);
			List<ITool> list = realT1Tools.get(real);
			if (list == null) {
				// the immutable singleton list is efficient in storage
				realT1Tools.put(real, Collections.singletonList(next));
			} else {
				if (list.size() == 1) {
					// make the list mutable
					list = new java.util.ArrayList<ITool>(list);
					realT1Tools.put(real, list);
				}
				list.add(next);
			}
		}

		for (ITool next : t2) {
			ITool real = ManagedBuildManager.getRealTool(next);
			List<ITool> correspondents = realT1Tools.get(real);
			if (correspondents != null) {
				result.put(correspondents.get(0), next);
				
				// consume the correspondent
				if (correspondents.size() == 1) {
					// remove the list; no more entries to consume
					realT1Tools.remove(real);
				} else {
					// cost of removal in array-list is not a concern
					// considering that this is a UI Apply button and
					// replication of tools is a fringe case
					correspondents.remove(0);
				}
			}
		}
		
		return result;
	}

	// IPreferencePageContainer methods
	@Override
	public void updateButtons() {}
	public void updateMessage() {}
	public void updateTitle() {}

	@Override
	public boolean canBeVisible() {
		IConfiguration cfg = getCfg();
		if (cfg instanceof MultiConfiguration) 
			return ((MultiConfiguration)cfg).isManagedBuildOn();
		else	
			return cfg.getBuilder().isManagedBuildOn();
	}
}

Back to the top