KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > parts > ConditionalListSelectionDialog


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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 Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.parts;
12
13 import org.eclipse.core.runtime.Assert;
14 import org.eclipse.jface.viewers.ILabelProvider;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.events.SelectionAdapter;
17 import org.eclipse.swt.events.SelectionEvent;
18 import org.eclipse.swt.widgets.Button;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21 import org.eclipse.swt.widgets.Shell;
22 import org.eclipse.ui.dialogs.ElementListSelectionDialog;
23
24 public class ConditionalListSelectionDialog extends ElementListSelectionDialog {
25
26     private String JavaDoc fButtonText;
27     private Object JavaDoc[] fElements;
28     private Object JavaDoc[] fConditionalElements;
29     
30     public ConditionalListSelectionDialog(Shell parent, ILabelProvider renderer, String JavaDoc buttonText) {
31         super(parent, renderer);
32         fButtonText = buttonText;
33     }
34     
35     protected Control createDialogArea(Composite parent) {
36         Composite comp = (Composite) super.createDialogArea(parent);
37         int size = ((fElements != null) ? fElements.length : 0) +
38                     ((fConditionalElements != null) ? fConditionalElements.length : 0);
39         final Object JavaDoc[] allElements = new Object JavaDoc[size];
40         int conditionalStart = 0;
41         if (fElements != null) {
42             System.arraycopy(fElements, 0, allElements, 0, fElements.length);
43             conditionalStart = fElements.length;
44         }
45         if (fConditionalElements != null)
46             System.arraycopy(fConditionalElements, 0, allElements, conditionalStart, fConditionalElements.length);
47         
48         final Button button = new Button(comp, SWT.CHECK);
49         Assert.isNotNull(fButtonText);
50         button.setText(fButtonText);
51         button.addSelectionListener(new SelectionAdapter() {
52             public void widgetSelected(SelectionEvent e) {
53                 if (button.getSelection())
54                     setListElements(allElements);
55                 else
56                     setListElements(fElements);
57             }
58         });
59         return comp;
60     }
61     
62     public void setElements(Object JavaDoc[] elements) {
63         super.setElements(elements);
64         fElements = elements;
65     }
66
67     public void setConditionalElements(Object JavaDoc[] elements) {
68         fConditionalElements = elements;
69     }
70     
71 }
72
Popular Tags