KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > ui > wizards > BatchOperationTypeWizardPage


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.browser.ui.wizards;
22
23
24 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
25 import org.eclipse.jface.wizard.WizardPage;
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.events.SelectionEvent;
28 import org.eclipse.swt.events.SelectionListener;
29 import org.eclipse.swt.layout.GridData;
30 import org.eclipse.swt.layout.GridLayout;
31 import org.eclipse.swt.widgets.Button;
32 import org.eclipse.swt.widgets.Composite;
33
34
35 public class BatchOperationTypeWizardPage extends WizardPage
36 {
37
38     public final static int OPERATION_TYPE_NONE = -1;
39
40     public final static int OPERATION_TYPE_MODIFY = 0;
41
42     public final static int OPERATION_TYPE_DELETE = 1;
43
44     public final static int OPERATION_TYPE_CREATE_LDIF = 2;
45
46     private final static String JavaDoc[] OPERATION_TYPES =
47         { "Modify entries", "Delete entries", "Execute LDIF changetype fragment on each entry" };
48
49     private Button[] operationTypeButtons;
50
51
52     public BatchOperationTypeWizardPage( String JavaDoc pageName, BatchOperationWizard wizard )
53     {
54         super( pageName );
55         super.setTitle( "Select Operation Type" );
56         super.setDescription( "Please select the batch operation type." );
57         super.setPageComplete( false );
58     }
59
60
61     private void validate()
62     {
63         setPageComplete( getOperationType() != OPERATION_TYPE_NONE );
64     }
65
66
67     public void createControl( Composite parent )
68     {
69
70         Composite composite = new Composite( parent, SWT.NONE );
71         GridLayout gl = new GridLayout( 1, false );
72         composite.setLayout( gl );
73         composite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
74
75         operationTypeButtons = new Button[OPERATION_TYPES.length];
76         for ( int i = 0; i < operationTypeButtons.length; i++ )
77         {
78             operationTypeButtons[i] = BaseWidgetUtils.createRadiobutton( composite, OPERATION_TYPES[i], 1 );
79             operationTypeButtons[i].addSelectionListener( new SelectionListener()
80             {
81                 public void widgetDefaultSelected( SelectionEvent e )
82                 {
83                     validate();
84                 }
85
86
87                 public void widgetSelected( SelectionEvent e )
88                 {
89                     validate();
90                 }
91             } );
92         }
93         operationTypeButtons[0].setSelection( true );
94
95         validate();
96
97         setControl( composite );
98
99     }
100
101
102     public int getOperationType()
103     {
104
105         for ( int i = 0; i < operationTypeButtons.length; i++ )
106         {
107             if ( operationTypeButtons[i].getSelection() )
108             {
109                 return i;
110             }
111         }
112
113         return OPERATION_TYPE_NONE;
114     }
115
116 }
Popular Tags