KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.File JavaDoc;
25
26 import org.apache.directory.ldapstudio.browser.core.jobs.ImportLdifJob;
27 import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
28 import org.apache.directory.ldapstudio.browser.core.model.IBookmark;
29 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
30 import org.apache.directory.ldapstudio.browser.core.model.IEntry;
31 import org.apache.directory.ldapstudio.browser.core.model.ISearchResult;
32 import org.apache.directory.ldapstudio.browser.core.model.IValue;
33 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
34 import org.eclipse.jface.viewers.IStructuredSelection;
35 import org.eclipse.jface.wizard.Wizard;
36 import org.eclipse.swt.widgets.Composite;
37 import org.eclipse.ui.IImportWizard;
38 import org.eclipse.ui.IWorkbench;
39 import org.eclipse.ui.PlatformUI;
40
41
42 /**
43  * This class implements the Import LDIF Wizard.
44  *
45  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
46  * @version $Rev$, $Date$
47  */

48 public class ImportLdifWizard extends Wizard implements IImportWizard
49 {
50
51     /** The main page. */
52     private ImportLdifMainWizardPage mainPage;
53
54     /** The ldif filename. */
55     private String JavaDoc ldifFilename;
56
57     /** The import connection. */
58     private IConnection importConnection;
59
60     /** The enable logging flag. */
61     private boolean enableLogging;
62
63     /** The log filename. */
64     private String JavaDoc logFilename;
65
66     /** The continue on error flag. */
67     private boolean continueOnError;
68
69
70     /**
71      * Creates a new instance of ImportLdifWizard.
72      */

73     public ImportLdifWizard()
74     {
75         super();
76         setWindowTitle( "LDIF Import" );
77     }
78
79
80     /**
81      * Creates a new instance of ImportLdifWizard.
82      *
83      * @param importConnection the import connection
84      */

85     public ImportLdifWizard( IConnection importConnection )
86     {
87         super.setWindowTitle( "LDIF Import" );
88         this.importConnection = importConnection;
89     }
90
91
92     /**
93      * Gets the ID of the Import LDIF Wizard
94      *
95      * @return The ID of the Import LDIF Wizard
96      */

97     public static String JavaDoc getId()
98     {
99         return ImportLdifWizard.class.getName();
100     }
101
102
103     /**
104      * {@inheritDoc}
105      */

106     public void init( IWorkbench workbench, IStructuredSelection selection )
107     {
108         Object JavaDoc o = selection.getFirstElement();
109         if ( o instanceof IEntry )
110         {
111             importConnection = ( ( IEntry ) o ).getConnection();
112         }
113         else if ( o instanceof ISearchResult )
114         {
115             importConnection = ( ( ISearchResult ) o ).getEntry().getConnection();
116         }
117         else if ( o instanceof IBookmark )
118         {
119             importConnection = ( ( IBookmark ) o ).getConnection();
120         }
121         else if ( o instanceof IAttribute )
122         {
123             importConnection = ( ( IAttribute ) o ).getEntry().getConnection();
124         }
125         else if ( o instanceof IValue )
126         {
127             importConnection = ( ( IValue ) o ).getAttribute().getEntry().getConnection();
128         }
129         else if ( o instanceof IConnection )
130         {
131             importConnection = ( IConnection ) o;
132         }
133         else
134         {
135             importConnection = null;
136         }
137     }
138
139
140     /**
141      * {@inheritDoc}
142      */

143     public void addPages()
144     {
145         mainPage = new ImportLdifMainWizardPage( ImportLdifMainWizardPage.class.getName(), this );
146         addPage( mainPage );
147     }
148
149
150     /**
151      * {@inheritDoc}
152      */

153     public void createPageControls( Composite pageContainer )
154     {
155         super.createPageControls( pageContainer );
156
157         PlatformUI.getWorkbench().getHelpSystem().setHelp( mainPage.getControl(),
158             BrowserUIPlugin.PLUGIN_ID + "." + "tools_ldifimport_wizard" );
159     }
160
161
162     /**
163      * {@inheritDoc}
164      */

165     public boolean performFinish()
166     {
167
168         mainPage.saveDialogSettings();
169
170         if ( ldifFilename != null && !"".equals( ldifFilename ) )
171         {
172             File JavaDoc ldifFile = new File JavaDoc( ldifFilename );
173
174             if ( enableLogging )
175             {
176                 File JavaDoc logFile = new File JavaDoc( logFilename );
177                 new ImportLdifJob( importConnection, ldifFile, logFile, continueOnError ).execute();
178             }
179             else
180             {
181                 new ImportLdifJob( importConnection, ldifFile, continueOnError ).execute();
182             }
183
184             return true;
185         }
186         return false;
187     }
188
189
190     /**
191      * Gets the import connection.
192      *
193      * @return the import connection
194      */

195     public IConnection getImportConnection()
196     {
197         return importConnection;
198     }
199
200
201     /**
202      * Sets the import connection.
203      *
204      * @param importConnection the import connection
205      */

206     public void setImportConnection( IConnection importConnection )
207     {
208         this.importConnection = importConnection;
209     }
210
211
212     /**
213      * Sets the ldif filename.
214      *
215      * @param ldifFilename the ldif filename
216      */

217     public void setLdifFilename( String JavaDoc ldifFilename )
218     {
219         this.ldifFilename = ldifFilename;
220     }
221
222
223     /**
224      * Sets the continue on error flag.
225      *
226      * @param continueOnError the continue on error flag
227      */

228     public void setContinueOnError( boolean continueOnError )
229     {
230         this.continueOnError = continueOnError;
231     }
232
233
234     /**
235      * Sets the log filename.
236      *
237      * @param logFilename the log filename
238      */

239     public void setLogFilename( String JavaDoc logFilename )
240     {
241         this.logFilename = logFilename;
242     }
243
244
245     /**
246      * Sets the enable logging flag.
247      *
248      * @param b the enable logging flag
249      */

250     public void setEnableLogging( boolean b )
251     {
252         this.enableLogging = b;
253     }
254
255 }
256
Popular Tags