Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1806376b9ddfe248dee5f7b5738b57088745751a (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
/*******************************************************************************
 * Copyright (c) 2009 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *     Yury Chernikov <Yury.Chernikov@borland.com> - Bug 271447 [ui] Bad layout in 'Install available software' dialog
 *******************************************************************************/
package org.eclipse.equinox.internal.p2.ui.dialogs;

import com.ibm.icu.text.Collator;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.ui.*;
import org.eclipse.equinox.internal.p2.ui.query.IUViewQueryContext;
import org.eclipse.equinox.internal.provisional.p2.repository.RepositoryEvent;
import org.eclipse.equinox.p2.engine.ProvisioningContext;
import org.eclipse.equinox.p2.operations.RepositoryTracker;
import org.eclipse.equinox.p2.repository.IRepository;
import org.eclipse.equinox.p2.repository.IRepositoryManager;
import org.eclipse.equinox.p2.ui.ProvisioningUI;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.fieldassist.ControlDecoration;
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.wizard.IWizardContainer;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;

/**
 * A RepositorySelectionGroup is a reusable UI component that displays 
 * available repositories and allows the user to select them.  
 * 
 * @since 3.5
 */
public class RepositorySelectionGroup {

	private static final String SITE_NONE = ProvUIMessages.AvailableIUsPage_NoSites;
	private static final String SITE_ALL = ProvUIMessages.AvailableIUsPage_AllSites;
	private static final String SITE_LOCAL = ProvUIMessages.AvailableIUsPage_LocalSites;
	private static final int INDEX_SITE_NONE = 0;
	private static final int INDEX_SITE_ALL = 1;
	private static final int DEC_MARGIN_WIDTH = 2;
	private static final String LINKACTION = "linkAction"; //$NON-NLS-1$

	// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=245569
	private static final int COUNT_VISIBLE_ITEMS = 20;
	IWizardContainer container;
	ProvisioningUI ui;
	IUViewQueryContext queryContext;

	ListenerList listeners = new ListenerList();

	Combo repoCombo;
	Link repoManipulatorLink;
	ControlDecoration repoDec;
	ComboAutoCompleteField repoAutoComplete;
	ProvUIProvisioningListener comboRepoListener;

	Image info, warning, error;
	URI[] comboRepos; // the URIs shown in the combo, kept in sync with combo items
	HashMap<String, URI> disabledRepoProposals = new HashMap<String, URI>(); // proposal string -> disabled URI 

	public RepositorySelectionGroup(ProvisioningUI ui, IWizardContainer container, Composite parent, IUViewQueryContext queryContext) {
		this.container = container;
		this.queryContext = queryContext;
		this.ui = ui;
		createControl(parent);
	}

	public Control getDefaultFocusControl() {
		return repoCombo;
	}

	public void addRepositorySelectionListener(IRepositorySelectionListener listener) {
		listeners.add(listener);
	}

	protected void createControl(Composite parent) {
		final RepositoryTracker tracker = ProvisioningUI.getDefaultUI().getRepositoryTracker();
		// Get the possible field error indicators
		info = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage();
		warning = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_WARNING).getImage();
		error = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).getImage();

		// Combo that filters sites
		Composite comboComposite = new Composite(parent, SWT.NONE);
		GridLayout layout = new GridLayout();
		layout.marginTop = 0;
		layout.marginBottom = IDialogConstants.VERTICAL_SPACING;
		layout.numColumns = 3;
		comboComposite.setLayout(layout);
		GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
		comboComposite.setLayoutData(gd);

		Label label = new Label(comboComposite, SWT.NONE);
		label.setText(ProvUIMessages.AvailableIUsPage_RepoFilterLabel);

		repoCombo = new Combo(comboComposite, SWT.DROP_DOWN);
		repoCombo.addSelectionListener(new SelectionListener() {

			public void widgetDefaultSelected(SelectionEvent e) {
				repoComboSelectionChanged();
			}

			public void widgetSelected(SelectionEvent e) {
				repoComboSelectionChanged();
			}

		});
		// Auto complete - install before our own key listeners, so that auto complete gets first shot.
		repoAutoComplete = new ComboAutoCompleteField(repoCombo);
		repoCombo.setVisibleItemCount(COUNT_VISIBLE_ITEMS);
		repoCombo.addKeyListener(new KeyAdapter() {

			public void keyPressed(KeyEvent e) {
				if (e.keyCode == SWT.CR)
					addRepository(false);
			}
		});

		// We don't ever want this to be interpreted as a default
		// button event
		repoCombo.addTraverseListener(new TraverseListener() {
			public void keyTraversed(TraverseEvent e) {
				if (e.detail == SWT.TRAVERSE_RETURN) {
					e.doit = false;
				}
			}
		});

		gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
		// breathing room for info dec
		gd.horizontalIndent = DEC_MARGIN_WIDTH * 2;
		repoCombo.setLayoutData(gd);
		repoCombo.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent event) {
				URI location = null;
				IStatus status = null;
				String text = repoCombo.getText().trim();
				int index = getComboIndex(text);
				// only validate text that doesn't match existing text in combo
				if (index < 0) {
					location = tracker.locationFromString(repoCombo.getText());
					if (location == null) {
						status = tracker.getInvalidLocationStatus(repoCombo.getText());
					} else {
						status = tracker.validateRepositoryLocation(ui.getSession(), location, false, new NullProgressMonitor());
					}
				} else {
					// user typed or pasted an existing location.  Select it.
					repoComboSelectionChanged();
				}
				setRepoComboDecoration(status);
			}
		});

		repoDec = new ControlDecoration(repoCombo, SWT.LEFT | SWT.TOP);
		repoDec.setMarginWidth(DEC_MARGIN_WIDTH);

		DropTarget target = new DropTarget(repoCombo, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK);
		target.setTransfer(new Transfer[] {URLTransfer.getInstance(), FileTransfer.getInstance()});
		target.addDropListener(new URLDropAdapter(true) {
			/* (non-Javadoc)
			 * @see org.eclipse.equinox.internal.provisional.p2.ui.dialogs.URLDropAdapter#handleURLString(java.lang.String, org.eclipse.swt.dnd.DropTargetEvent)
			 */
			protected void handleDrop(String urlText, DropTargetEvent event) {
				repoCombo.setText(urlText);
				event.detail = DND.DROP_LINK;
				addRepository(false);
			}
		});

		Button button = new Button(comboComposite, SWT.PUSH);
		button.setText(ProvUIMessages.AvailableIUsPage_AddButton);
		button.addSelectionListener(new SelectionListener() {
			public void widgetDefaultSelected(SelectionEvent e) {
				addRepository(true);
			}

			public void widgetSelected(SelectionEvent e) {
				addRepository(true);
			}
		});
		setButtonLayoutData(button);

		// Link to repository manipulator
		repoManipulatorLink = createLink(comboComposite, new Action() {
			public void runWithEvent(Event event) {
				ui.manipulateRepositories(repoCombo.getShell());
			}
		}, getLinkLabel());
		gd = new GridData(SWT.END, SWT.FILL, true, false);
		gd.horizontalSpan = 3;
		repoManipulatorLink.setLayoutData(gd);

		addComboProvisioningListeners();
		parent.addDisposeListener(new DisposeListener() {
			public void widgetDisposed(DisposeEvent e) {
				removeProvisioningListeners();
			}

		});
	}

	private String getLinkLabel() {
		if (ui.getPolicy().getRepositoryPreferencePageId() != null) {
			String pageName = ui.getPolicy().getRepositoryPreferencePageName();
			if (pageName == null)
				pageName = ProvUIMessages.RepositorySelectionGroup_PrefPageName;
			return NLS.bind(ProvUIMessages.RepositorySelectionGroup_PrefPageLink, pageName);
		}
		return ProvUIMessages.RepositorySelectionGroup_GenericSiteLinkTitle;
	}

	private void setButtonLayoutData(Button button) {
		GridData data = new GridData(SWT.FILL, SWT.CENTER, false, false);
		GC gc = new GC(button);
		gc.setFont(JFaceResources.getDialogFont());
		FontMetrics fm = gc.getFontMetrics();
		gc.dispose();
		int widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
		Point minSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
		data.widthHint = Math.max(widthHint, minSize.x);
		button.setLayoutData(data);
	}

	public void setRepositorySelection(int scope, URI location) {
		switch (scope) {
			case AvailableIUGroup.AVAILABLE_ALL :
				fillRepoCombo(SITE_ALL);
				break;
			case AvailableIUGroup.AVAILABLE_LOCAL :
				fillRepoCombo(SITE_LOCAL);
				break;
			case AvailableIUGroup.AVAILABLE_SPECIFIED :
				fillRepoCombo(getSiteString(location));
				break;
			default :
				fillRepoCombo(SITE_NONE);
		}
		setRepoComboDecoration(null);
	}

	protected void setRepoComboDecoration(final IStatus status) {
		if (status == null || status.isOK() || status.getSeverity() == IStatus.CANCEL) {
			repoDec.setShowOnlyOnFocus(true);
			repoDec.setDescriptionText(ProvUIMessages.AvailableIUsPage_RepoFilterInstructions);
			repoDec.setImage(info);
			// We may have been previously showing an error or warning
			// hover.  We will need to dismiss it, but if there is no text
			// typed, don't do this, so that the user gets the info cue
			if (repoCombo.getText().length() > 0)
				repoDec.showHoverText(null);
			return;
		}
		Image image;
		if (status.getSeverity() == IStatus.WARNING)
			image = warning;
		else if (status.getSeverity() == IStatus.ERROR)
			image = error;
		else
			image = info;
		repoDec.setImage(image);
		repoDec.setDescriptionText(status.getMessage());
		repoDec.setShowOnlyOnFocus(false);
		// use a delay to show the validation method because the very next
		// selection or keystroke might fix it
		repoCombo.getDisplay().timerExec(500, new Runnable() {
			public void run() {
				if (repoDec != null && repoDec.getImage() != info)
					repoDec.showHoverText(status.getMessage());
			}
		});

	}

	/*
	 * Fill the repo combo and use the specified string
	 * as the selection.  If the selection is null, then the
	 * current selection should be preserved if applicable.
	 */
	void fillRepoCombo(final String selection) {
		RepositoryTracker tracker = ui.getRepositoryTracker();
		URI[] sites = tracker.getKnownRepositories(ui.getSession());
		boolean hasLocalSites = getLocalSites().length > 0;
		final String[] items;
		if (hasLocalSites) {
			// None, All, repo1, repo2....repo n, Local
			comboRepos = new URI[sites.length + 3];
			items = new String[sites.length + 3];
		} else {
			// None, All, repo1, repo2....repo n
			comboRepos = new URI[sites.length + 2];
			items = new String[sites.length + 2];
		}
		items[INDEX_SITE_NONE] = SITE_NONE;
		items[INDEX_SITE_ALL] = SITE_ALL;
		for (int i = 0; i < sites.length; i++) {
			items[i + 2] = getSiteString(sites[i]);
			comboRepos[i + 2] = sites[i];
		}
		if (hasLocalSites)
			items[items.length - 1] = SITE_LOCAL;
		if (sites.length > 0)
			sortRepoItems(items, comboRepos, hasLocalSites);
		Runnable runnable = new Runnable() {
			public void run() {
				if (repoCombo == null || repoCombo.isDisposed())
					return;
				String repoToSelect = selection;
				if (repoToSelect == null) {
					// If the combo is open and something is selected, use that index if we
					// weren't given a string to select.
					int selIndex = repoCombo.getSelectionIndex();
					if (selIndex >= 0)
						repoToSelect = repoCombo.getItem(selIndex);
					else
						repoToSelect = repoCombo.getText();
				}
				repoCombo.setItems(items);
				repoAutoComplete.setProposalStrings(getComboProposals());
				boolean selected = false;
				for (int i = 0; i < items.length; i++)
					if (items[i].equals(repoToSelect)) {
						selected = true;
						if (repoCombo.getListVisible())
							repoCombo.select(i);
						repoCombo.setText(repoToSelect);
						break;
					}
				if (!selected) {
					if (repoCombo.getListVisible())
						repoCombo.select(INDEX_SITE_NONE);
					repoCombo.setText(SITE_NONE);
				}
				repoComboSelectionChanged();
			}
		};
		if (Display.getCurrent() == null)
			repoCombo.getDisplay().asyncExec(runnable);
		else
			runnable.run();
	}

	String getSiteString(URI uri) {
		String nickname = ui.getSession().getMetadataRepositoryManager().getRepositoryProperty(uri, IRepository.PROP_NICKNAME);
		if (nickname != null && nickname.length() > 0)
			return NLS.bind(ProvUIMessages.AvailableIUsPage_NameWithLocation, nickname, URIUtil.toUnencodedString(uri));
		return URIUtil.toUnencodedString(uri);
	}

	private Link createLink(Composite parent, IAction action, String text) {
		Link link = new Link(parent, SWT.PUSH);
		link.setText(text);

		link.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event event) {
				IAction linkAction = getLinkAction(event.widget);
				if (linkAction != null) {
					linkAction.runWithEvent(event);
				}
			}
		});
		link.setToolTipText(action.getToolTipText());
		link.setData(LINKACTION, action);
		return link;
	}

	IAction getLinkAction(Widget widget) {
		Object data = widget.getData(LINKACTION);
		if (data == null || !(data instanceof IAction)) {
			return null;
		}
		return (IAction) data;
	}

	private void sortRepoItems(String[] strings, URI[] locations, boolean hasLocalSites) {
		int sortStart = 2;
		int sortEnd = hasLocalSites ? strings.length - 2 : strings.length - 1;
		if (sortStart >= sortEnd)
			return;
		final HashMap<URI, String> uriToString = new HashMap<URI, String>();
		for (int i = sortStart; i <= sortEnd; i++) {
			uriToString.put(locations[i], strings[i]);
		}
		final Collator collator = Collator.getInstance(Locale.getDefault());
		Comparator<String> stringComparator = new Comparator<String>() {
			public int compare(String a, String b) {
				return collator.compare(a, b);
			}
		};
		Comparator<URI> uriComparator = new Comparator<URI>() {
			public int compare(URI a, URI b) {
				return collator.compare(uriToString.get(a), uriToString.get(b));
			}
		};

		Arrays.sort(strings, sortStart, sortEnd, stringComparator);
		Arrays.sort(locations, sortStart, sortEnd, uriComparator);
	}

	private URI[] getLocalSites() {
		// use our current visibility flags plus the local filter
		int flags = ui.getRepositoryTracker().getMetadataRepositoryFlags() | IRepositoryManager.REPOSITORIES_LOCAL;
		return ui.getSession().getMetadataRepositoryManager().getKnownRepositories(flags);
	}

	String[] getComboProposals() {
		int flags = ui.getRepositoryTracker().getMetadataRepositoryFlags() | IRepositoryManager.REPOSITORIES_DISABLED;
		String[] items = repoCombo.getItems();
		// Clear any previously remembered disabled repos
		disabledRepoProposals = new HashMap<String, URI>();
		URI[] disabled = ui.getSession().getMetadataRepositoryManager().getKnownRepositories(flags);
		String[] disabledItems = new String[disabled.length];
		for (int i = 0; i < disabledItems.length; i++) {
			disabledItems[i] = getSiteString(disabled[i]);
			disabledRepoProposals.put(disabledItems[i], disabled[i]);
		}
		String[] both = new String[items.length + disabledItems.length];
		System.arraycopy(items, 0, both, 0, items.length);
		System.arraycopy(disabledItems, 0, both, items.length, disabledItems.length);
		return both;
	}

	int getComboIndex(String repoText) {
		// Callers have typically done this already, but just in case
		repoText = repoText.trim();
		// First look for exact match to the combo string.
		// This includes the name, etc.
		if (repoText.length() > 0) {
			String[] items = repoCombo.getItems();
			for (int i = 0; i < items.length; i++)
				if (repoText.equals(items[i])) {
					return i;
				}
		}
		// Look for URI match - the user may have pasted or dragged 
		// in a location that matches one we already know about, even
		// if the text does not match completely.  (slashes, no name, etc.)
		try {
			URI location = URIUtil.fromString(repoText);
			for (int i = 0; i < comboRepos.length; i++)
				if (URIUtil.sameURI(location, comboRepos[i])) {
					return i;
				}
		} catch (URISyntaxException e) {
			// never mind
		}
		return -1;
	}

	void addComboProvisioningListeners() {
		// We need to monitor repository events so that we can adjust the repo combo.
		comboRepoListener = new ProvUIProvisioningListener(ProvUIProvisioningListener.PROV_EVENT_METADATA_REPOSITORY) {
			protected void repositoryAdded(RepositoryEvent e) {
				fillRepoCombo(getSiteString(e.getRepositoryLocation()));
			}

			protected void repositoryRemoved(RepositoryEvent e) {
				fillRepoCombo(null);
			}

			protected void refreshAll() {
				fillRepoCombo(null);
			}
		};
		ProvUI.addProvisioningListener(comboRepoListener);
	}

	void removeProvisioningListeners() {
		if (comboRepoListener != null) {
			ProvUI.removeProvisioningListener(comboRepoListener);
			comboRepoListener = null;
		}

	}

	/*
	 *  Add a repository using the text in the combo or launch a dialog if the text
	 *  represents an already known repo.  For any add operation spawned by this
	 *  method, we do not want to notify the UI with a special listener.  This is to
	 *  prevent a multiple update flash because we intend to reset the available IU
	 *  filter as soon as the new repo is added.
	 */
	void addRepository(boolean alwaysPrompt) {
		final RepositoryTracker manipulator = ui.getRepositoryTracker();
		final String selectedRepo = repoCombo.getText().trim();
		int selectionIndex = getComboIndex(selectedRepo);
		final boolean isNewText = selectionIndex < 0;
		// If we are adding something already in the combo, just
		// select that item.
		if (!alwaysPrompt && !isNewText && selectionIndex != repoCombo.getSelectionIndex()) {
			repoComboSelectionChanged();
		} else if (alwaysPrompt) {
			AddRepositoryDialog dialog = new AddRepositoryDialog(repoCombo.getShell(), ui) {

				protected String getInitialLocationText() {
					if (isNewText)
						return selectedRepo;
					return super.getInitialLocationText();
				}

			};
			dialog.setTitle(ProvUIMessages.AddRepositoryDialog_Title);
			dialog.open();
			URI location = dialog.getAddedLocation();
			if (location != null)
				fillRepoCombo(getSiteString(location));
		} else if (isNewText) {
			try {
				container.run(false, false, new IRunnableWithProgress() {
					public void run(IProgressMonitor monitor) {
						URI location;
						IStatus status;
						// This might be a disabled repo.  If so, no need to validate further.
						if (disabledRepoProposals.containsKey(selectedRepo)) {
							location = disabledRepoProposals.get(selectedRepo);
							status = Status.OK_STATUS;
						} else {
							location = manipulator.locationFromString(selectedRepo);
							if (location == null)
								status = manipulator.getInvalidLocationStatus(selectedRepo);
							else {
								status = manipulator.validateRepositoryLocation(ui.getSession(), location, false, monitor);
							}
						}
						if (status.isOK() && location != null) {
							manipulator.addRepository(location, null, ui.getSession());
							fillRepoCombo(getSiteString(location));
						}
						setRepoComboDecoration(status);
					}
				});
			} catch (InvocationTargetException e) {
				// ignore
			} catch (InterruptedException e) {
				// ignore
			}
		}
	}

	public ProvisioningContext getProvisioningContext() {
		int siteSel = getComboIndex(repoCombo.getText().trim());
		if (siteSel < 0 || siteSel == INDEX_SITE_ALL || siteSel == INDEX_SITE_NONE)
			return new ProvisioningContext();
		URI[] locals = getLocalSites();
		// If there are local sites, the last item in the combo is "Local Sites Only"
		// Use all local sites in this case
		// We have to set metadata repositories and artifact repositories in the
		// provisioning context because the artifact repositories are used for
		// sizing.
		if (locals.length > 0 && siteSel == repoCombo.getItemCount() - 1) {
			ProvisioningContext context = new ProvisioningContext(locals);
			context.setArtifactRepositories(locals);
			return context;
		}
		// A single site is selected.
		ProvisioningContext context = new ProvisioningContext(new URI[] {comboRepos[siteSel]});
		context.setArtifactRepositories(new URI[] {comboRepos[siteSel]});
		return context;
	}

	void repoComboSelectionChanged() {
		int repoChoice = -1;
		URI repoLocation = null;

		int selection = -1;
		if (repoCombo.getListVisible()) {
			selection = repoCombo.getSelectionIndex();
		} else {
			selection = getComboIndex(repoCombo.getText().trim());
		}
		int localIndex = getLocalSites().length == 0 ? repoCombo.getItemCount() : repoCombo.getItemCount() - 1;
		if (comboRepos == null || selection < 0) {
			selection = INDEX_SITE_NONE;
		}

		if (selection == INDEX_SITE_NONE) {
			repoChoice = AvailableIUGroup.AVAILABLE_NONE;
		} else if (selection == INDEX_SITE_ALL) {
			repoChoice = AvailableIUGroup.AVAILABLE_ALL;
		} else if (selection >= localIndex) {
			repoChoice = AvailableIUGroup.AVAILABLE_LOCAL;
		} else {
			repoChoice = AvailableIUGroup.AVAILABLE_SPECIFIED;
			repoLocation = comboRepos[selection];
		}

		Object[] selectionListeners = listeners.getListeners();
		for (int i = 0; i < selectionListeners.length; i++) {
			((IRepositorySelectionListener) selectionListeners[i]).repositorySelectionChanged(repoChoice, repoLocation);
		}
	}
}

Back to the top