KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > refactoring > VisibilityControlUtil


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.jdt.internal.ui.refactoring;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.jdt.core.dom.Modifier;
17
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.events.SelectionAdapter;
20 import org.eclipse.swt.events.SelectionEvent;
21 import org.eclipse.swt.layout.GridData;
22 import org.eclipse.swt.layout.GridLayout;
23 import org.eclipse.swt.widgets.Button;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.Group;
26
27 public class VisibilityControlUtil {
28     private VisibilityControlUtil(){}
29     
30     public static Composite createVisibilityControl(Composite parent, final IVisibilityChangeListener visibilityChangeListener, int[] availableVisibilities, int correctVisibility) {
31         List JavaDoc allowedVisibilities= convertToIntegerList(availableVisibilities);
32         if (allowedVisibilities.size() == 1)
33             return null;
34         
35         Group group= new Group(parent, SWT.NONE);
36         group.setText(RefactoringMessages.VisibilityControlUtil_Access_modifier);
37         GridData gd= new GridData(GridData.FILL_HORIZONTAL);
38         group.setLayoutData(gd);
39         GridLayout layout= new GridLayout();
40         layout.makeColumnsEqualWidth= true;
41         layout.numColumns= 4;
42         group.setLayout(layout);
43         
44         String JavaDoc[] labels= new String JavaDoc[] {
45             "&public", //$NON-NLS-1$
46
"pro&tected", //$NON-NLS-1$
47
RefactoringMessages.VisibilityControlUtil_defa_ult_4,
48             "pri&vate" //$NON-NLS-1$
49
};
50         Integer JavaDoc[] data= new Integer JavaDoc[] {
51                     new Integer JavaDoc(Modifier.PUBLIC),
52                     new Integer JavaDoc(Modifier.PROTECTED),
53                     new Integer JavaDoc(Modifier.NONE),
54                     new Integer JavaDoc(Modifier.PRIVATE)};
55         Integer JavaDoc initialVisibility= new Integer JavaDoc(correctVisibility);
56         for (int i= 0; i < labels.length; i++) {
57             Button radio= new Button(group, SWT.RADIO);
58             Integer JavaDoc visibilityCode= data[i];
59             radio.setText(labels[i]);
60             radio.setData(visibilityCode);
61             radio.setSelection(visibilityCode.equals(initialVisibility));
62             radio.setEnabled(allowedVisibilities.contains(visibilityCode));
63             radio.addSelectionListener(new SelectionAdapter() {
64                 public void widgetSelected(SelectionEvent event) {
65                     visibilityChangeListener.visibilityChanged(((Integer JavaDoc)event.widget.getData()).intValue());
66                 }
67             });
68         }
69         group.setLayoutData((new GridData(GridData.FILL_HORIZONTAL)));
70         return group;
71     }
72
73     private static List JavaDoc convertToIntegerList(int[] array) {
74         List JavaDoc result= new ArrayList JavaDoc(array.length);
75         for (int i= 0; i < array.length; i++) {
76             result.add(new Integer JavaDoc(array[i]));
77         }
78         return result;
79     }
80 }
81
Popular Tags