KickJava   Java API By Example, From Geeks To Geeks.

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


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.ImportDsmlJob;
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 DSML Wizard.
44  *
45  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
46  * @version $Rev$, $Date$
47  */

48 public class ImportDsmlWizard extends Wizard implements IImportWizard
49 {
50     /** Page Title */
51     public static final String JavaDoc WIZARD_TITLE = "DSML Import";
52
53     /** The connection attached to the import */
54     private IConnection importConnection;
55
56     /** The main page of the wizard */
57     private ImportDsmlMainWizardPage mainPage;
58
59     /** The DSML Filename */
60     private String JavaDoc dsmlFilename;
61
62     /** The Save Filename */
63     private String JavaDoc responseFilename;
64
65     /** The Save Response flag */
66     private boolean saveResponse;
67
68
69     /**
70      * Creates a new instance of ImportDsmlWizard.
71      */

72     public ImportDsmlWizard()
73     {
74         super();
75         setWindowTitle( WIZARD_TITLE );
76     }
77
78
79     /**
80      * Creates a new instance of ImportDsmlWizard.
81      * @param selectedConnection
82      * The connection to use
83      */

84     public ImportDsmlWizard( IConnection selectedConnection )
85     {
86         setWindowTitle( WIZARD_TITLE );
87         this.importConnection = selectedConnection;
88     }
89
90
91     /**
92      * Gets the ID of the Import DSML Wizard
93      * @return The ID of the Import DSML Wizard
94      */

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

104     public boolean performFinish()
105     {
106         mainPage.saveDialogSettings();
107
108         if ( dsmlFilename != null && !"".equals( dsmlFilename ) )
109         {
110             File JavaDoc dsmlFile = new File JavaDoc( dsmlFilename );
111
112             if ( saveResponse )
113             {
114                 File JavaDoc responseFile = new File JavaDoc( responseFilename );
115                 new ImportDsmlJob( importConnection, dsmlFile, responseFile ).execute();
116             }
117             else
118             {
119                 new ImportDsmlJob( importConnection, dsmlFile ).execute();
120             }
121
122             return true;
123         }
124         return false;
125     }
126
127
128     /**
129      * {@inheritDoc}
130      */

131     public void init( IWorkbench workbench, IStructuredSelection selection )
132     {
133         Object JavaDoc o = selection.getFirstElement();
134         if ( o instanceof IEntry )
135         {
136             importConnection = ( ( IEntry ) o ).getConnection();
137         }
138         else if ( o instanceof ISearchResult )
139         {
140             importConnection = ( ( ISearchResult ) o ).getEntry().getConnection();
141         }
142         else if ( o instanceof IBookmark )
143         {
144             importConnection = ( ( IBookmark ) o ).getConnection();
145         }
146         else if ( o instanceof IAttribute )
147         {
148             importConnection = ( ( IAttribute ) o ).getEntry().getConnection();
149         }
150         else if ( o instanceof IValue )
151         {
152             importConnection = ( ( IValue ) o ).getAttribute().getEntry().getConnection();
153         }
154         else if ( o instanceof IConnection )
155         {
156             importConnection = ( IConnection ) o;
157         }
158         else
159         {
160             importConnection = null;
161         }
162     }
163
164
165     /**
166      * {@inheritDoc}
167      */

168     public void addPages()
169     {
170         mainPage = new ImportDsmlMainWizardPage( ImportDsmlMainWizardPage.class.getName(), this );
171         addPage( mainPage );
172     }
173
174
175     /**
176      * {@inheritDoc}
177      */

178     public void createPageControls( Composite pageContainer )
179     {
180         super.createPageControls( pageContainer );
181
182         // set help context ID
183
PlatformUI.getWorkbench().getHelpSystem().setHelp( mainPage.getControl(),
184             BrowserUIPlugin.PLUGIN_ID + "." + "tools_dsmlimport_wizard" );
185     }
186
187
188     /**
189      * Get the connection attached to the Import
190      * @return The connection attached to the Import
191      */

192     public IConnection getImportConnection()
193     {
194         return importConnection;
195     }
196
197
198     /**
199      * Sets the connection attached to the Import
200      * @param connection
201      * The connection attached to the Import
202      */

203     public void setImportConnection( IConnection connection )
204     {
205         this.importConnection = connection;
206     }
207
208
209     /**
210      * Sets the DSML Filename
211      * @param dsmlFilename
212      * The DSML Filename
213      */

214     public void setDsmlFilename( String JavaDoc dsmlFilename )
215     {
216         this.dsmlFilename = dsmlFilename;
217     }
218
219
220     /**
221      * Sets the Save Filename
222      * @param saveFilename
223      * The Save Filename
224      */

225     public void setResponseFilename( String JavaDoc saveFilename )
226     {
227         this.responseFilename = saveFilename;
228     }
229
230
231     /**
232      * Sets the SaveResponse flag
233      * @param b
234      * The SaveResponse flag
235      */

236     public void setSaveResponse( boolean b )
237     {
238         this.saveResponse = b;
239     }
240 }
241
Popular Tags