KickJava   Java API By Example, From Geeks To Geeks.

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


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.ModWidget;
25 import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyEvent;
26 import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyListener;
27 import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
28 import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifFile;
29 import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContainer;
30 import org.apache.directory.ldapstudio.browser.core.model.ldif.parser.LdifParser;
31 import org.apache.directory.ldapstudio.browser.core.model.schema.Schema;
32 import org.eclipse.jface.wizard.WizardPage;
33 import org.eclipse.swt.SWT;
34 import org.eclipse.swt.layout.GridData;
35 import org.eclipse.swt.layout.GridLayout;
36 import org.eclipse.swt.widgets.Composite;
37
38
39 public class BatchOperationModifyWizardPage extends WizardPage implements WidgetModifyListener
40 {
41
42     private BatchOperationWizard wizard;
43
44     private ModWidget modWidget;
45
46
47     public BatchOperationModifyWizardPage( String JavaDoc pageName, BatchOperationWizard wizard )
48     {
49         super( pageName );
50         super.setTitle( "Define Modification" );
51         super.setDescription( "Please define the modifcations." );
52         // super.setImageDescriptor(BrowserUIPlugin.getDefault().getImageDescriptor(BrowserUIConstants.IMG_ENTRY_WIZARD));
53
super.setPageComplete( false );
54
55         this.wizard = wizard;
56     }
57
58
59     private void validate()
60     {
61
62         String JavaDoc dummyLdif = "dn: cn=dummy" + BrowserCoreConstants.LINE_SEPARATOR + modWidget.getLdifFragment();
63         LdifFile model = new LdifParser().parse( dummyLdif );
64         LdifContainer[] containers = model.getContainers();
65         if ( containers.length == 0 )
66         {
67             setPageComplete( false );
68             return;
69         }
70         for ( int i = 0; i < containers.length; i++ )
71         {
72             if ( !containers[i].isValid() )
73             {
74                 setPageComplete( false );
75                 return;
76             }
77         }
78
79         setPageComplete( true );
80
81     }
82
83
84     public void createControl( Composite parent )
85     {
86
87         Composite composite = new Composite( parent, SWT.NONE );
88         GridLayout gl = new GridLayout( 1, false );
89         composite.setLayout( gl );
90         composite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
91
92         modWidget = new ModWidget( wizard.getConnection() != null ? wizard.getConnection().getSchema()
93             : Schema.DEFAULT_SCHEMA );
94         modWidget.createContents( composite );
95         modWidget.addWidgetModifyListener( this );
96
97         validate();
98
99         setControl( composite );
100
101     }
102
103
104     public String JavaDoc getLdifFragment()
105     {
106         return modWidget.getLdifFragment();
107     }
108
109     public void widgetModified( WidgetModifyEvent event )
110     {
111         validate();
112     }
113
114 }
115
Popular Tags