KickJava   Java API By Example, From Geeks To Geeks.

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


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.WidgetModifyEvent;
25 import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyListener;
26 import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
27 import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifFile;
28 import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContainer;
29 import org.apache.directory.ldapstudio.ldifeditor.widgets.LdifEditorWidget;
30
31 import org.eclipse.jface.wizard.WizardPage;
32 import org.eclipse.swt.SWT;
33 import org.eclipse.swt.events.VerifyEvent;
34 import org.eclipse.swt.events.VerifyListener;
35 import org.eclipse.swt.layout.GridData;
36 import org.eclipse.swt.layout.GridLayout;
37 import org.eclipse.swt.widgets.Composite;
38
39
40 public class BatchOperationLdifWizardPage extends WizardPage implements WidgetModifyListener
41 {
42
43     private static final String JavaDoc LDIF_DN_PREFIX = "dn: cn=dummy" + BrowserCoreConstants.LINE_SEPARATOR;
44
45     private static final String JavaDoc LDIF_INITIAL = "changetype: modify" + BrowserCoreConstants.LINE_SEPARATOR;
46
47     private BatchOperationWizard wizard;
48
49     private LdifEditorWidget ldifEditorWidget;
50
51
52     public BatchOperationLdifWizardPage( String JavaDoc pageName, BatchOperationWizard wizard )
53     {
54         super( pageName );
55         super.setTitle( "LDIF Fragment" );
56         super.setDescription( "Please enter the LDIF fragment that should be executed on each entry." );
57         // super.setImageDescriptor(BrowserUIPlugin.getDefault().getImageDescriptor(BrowserUIConstants.IMG_ENTRY_WIZARD));
58
super.setPageComplete( false );
59
60         this.wizard = wizard;
61     }
62
63
64     public void dispose()
65     {
66         ldifEditorWidget.dispose();
67         super.dispose();
68     }
69
70
71     private void validate()
72     {
73
74         LdifFile model = ldifEditorWidget.getLdifModel();
75         LdifContainer[] containers = model.getContainers();
76         if ( containers.length == 0 )
77         {
78             setPageComplete( false );
79             return;
80         }
81         for ( int i = 0; i < containers.length; i++ )
82         {
83             if ( !containers[i].isValid() )
84             {
85                 setPageComplete( false );
86                 return;
87             }
88         }
89
90         setPageComplete( true );
91
92     }
93
94
95     public boolean isPageComplete()
96     {
97
98         if ( wizard.getTypePage().getOperationType() != BatchOperationTypeWizardPage.OPERATION_TYPE_CREATE_LDIF )
99         {
100             return true;
101         }
102
103         return super.isPageComplete();
104     }
105
106
107     public void createControl( Composite parent )
108     {
109
110         Composite composite = new Composite( parent, SWT.NONE );
111         GridLayout gl = new GridLayout( 1, false );
112         composite.setLayout( gl );
113         composite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
114
115         ldifEditorWidget = new LdifEditorWidget( null, LDIF_DN_PREFIX + LDIF_INITIAL, true );
116         ldifEditorWidget.createWidget( composite );
117         ldifEditorWidget.addWidgetModifyListener( this );
118
119         ldifEditorWidget.getSourceViewer().getTextWidget().addVerifyListener( new VerifyListener()
120         {
121             public void verifyText( VerifyEvent e )
122             {
123                 if ( e.start < LDIF_DN_PREFIX.length() || e.end < LDIF_DN_PREFIX.length() )
124                 {
125                     e.doit = false;
126                 }
127             }
128         } );
129
130         validate();
131
132         setControl( composite );
133     }
134
135
136     public String JavaDoc getLdifFragment()
137     {
138         return ldifEditorWidget.getLdifModel().toRawString().replaceAll( LDIF_DN_PREFIX, "" );
139     }
140
141
142     public void widgetModified( WidgetModifyEvent event )
143     {
144         validate();
145     }
146
147 }
Popular Tags