01: /*******************************************************************************
02: * Copyright (c) 2005, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.parts;
11:
12: import org.eclipse.core.runtime.Assert;
13: import org.eclipse.jface.viewers.ILabelProvider;
14: import org.eclipse.swt.SWT;
15: import org.eclipse.swt.events.SelectionAdapter;
16: import org.eclipse.swt.events.SelectionEvent;
17: import org.eclipse.swt.widgets.Button;
18: import org.eclipse.swt.widgets.Composite;
19: import org.eclipse.swt.widgets.Control;
20: import org.eclipse.swt.widgets.Shell;
21: import org.eclipse.ui.dialogs.ElementListSelectionDialog;
22:
23: public class ConditionalListSelectionDialog extends
24: ElementListSelectionDialog {
25:
26: private String fButtonText;
27: private Object[] fElements;
28: private Object[] fConditionalElements;
29:
30: public ConditionalListSelectionDialog(Shell parent,
31: ILabelProvider renderer, String buttonText) {
32: super (parent, renderer);
33: fButtonText = buttonText;
34: }
35:
36: protected Control createDialogArea(Composite parent) {
37: Composite comp = (Composite) super .createDialogArea(parent);
38: int size = ((fElements != null) ? fElements.length : 0)
39: + ((fConditionalElements != null) ? fConditionalElements.length
40: : 0);
41: final Object[] allElements = new Object[size];
42: int conditionalStart = 0;
43: if (fElements != null) {
44: System.arraycopy(fElements, 0, allElements, 0,
45: fElements.length);
46: conditionalStart = fElements.length;
47: }
48: if (fConditionalElements != null)
49: System.arraycopy(fConditionalElements, 0, allElements,
50: conditionalStart, fConditionalElements.length);
51:
52: final Button button = new Button(comp, SWT.CHECK);
53: Assert.isNotNull(fButtonText);
54: button.setText(fButtonText);
55: button.addSelectionListener(new SelectionAdapter() {
56: public void widgetSelected(SelectionEvent e) {
57: if (button.getSelection())
58: setListElements(allElements);
59: else
60: setListElements(fElements);
61: }
62: });
63: return comp;
64: }
65:
66: public void setElements(Object[] elements) {
67: super .setElements(elements);
68: fElements = elements;
69: }
70:
71: public void setConditionalElements(Object[] elements) {
72: fConditionalElements = elements;
73: }
74:
75: }
|