1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package com.sun.star.wizards.table;
24 
25 import com.sun.star.awt.XListBox;
26 import com.sun.star.awt.XRadioButton;
27 import com.sun.star.awt.XTextComponent;
28 import com.sun.star.sdbc.SQLException;
29 import com.sun.star.wizards.common.Desktop;
30 import com.sun.star.wizards.common.JavaTools;
31 import com.sun.star.wizards.common.PropertyNames;
32 import com.sun.star.wizards.db.TableDescriptor;
33 import com.sun.star.wizards.ui.*;
34 
35 public class Finalizer
36 {
37 
38     TableWizard CurUnoDialog;
39     short curtabindex;
40     XRadioButton optModifyTable;
41     XRadioButton optWorkWithTable;
42     XRadioButton optStartFormWizard;
43     XTextComponent txtTableName;
44     XListBox xCatalogListBox;
45     XListBox xSchemaListBox;
46     TableDescriptor curtabledescriptor;
47     public String SETCOMPLETIONFLAG = "setCompletionFlag";
48     public static int WORKWITHTABLEMODE = 0;
49     public static int MODIFYTABLEMODE = 1;
50     public static int STARTFORMWIZARDMODE = 2;
51 
Finalizer(TableWizard _CurUnoDialog, TableDescriptor _curtabledescriptor)52     public Finalizer(TableWizard _CurUnoDialog, TableDescriptor _curtabledescriptor)
53     {
54         try
55         {
56             this.CurUnoDialog = _CurUnoDialog;
57             this.curtabledescriptor = _curtabledescriptor;
58             curtabindex = (short) (TableWizard.SOFINALPAGE * 100);
59             Integer IFINALSTEP = new Integer(TableWizard.SOFINALPAGE);
60             String slblTableName = CurUnoDialog.m_oResource.getResText(UIConsts.RID_TABLE + 34);
61             String slblProceed = CurUnoDialog.m_oResource.getResText(UIConsts.RID_TABLE + 36);
62             String sWorkWithTable = CurUnoDialog.m_oResource.getResText(UIConsts.RID_TABLE + 38);
63             String sStartFormWizard = CurUnoDialog.m_oResource.getResText(UIConsts.RID_TABLE + 39);
64             String sModifyTable = CurUnoDialog.m_oResource.getResText(UIConsts.RID_TABLE + 37);
65             String sCongratulations = CurUnoDialog.m_oResource.getResText(UIConsts.RID_TABLE + 35);
66             String slblCatalog = CurUnoDialog.m_oResource.getResText(UIConsts.RID_TABLE + 49);
67             String slblSchema = CurUnoDialog.m_oResource.getResText(UIConsts.RID_TABLE + 50);
68             String[] sCatalogNames = curtabledescriptor.getCatalogNames();
69             String[] sSchemaNames = curtabledescriptor.getSchemaNames();
70             int nListBoxPosX = 97;
71             int ndiffPosY = 0;
72             boolean bsupportsSchemata = false;
73             boolean bsupportsCatalogs = false;
74 
75             CurUnoDialog.insertLabel("lblTableName",
76                     new String[]
77                     {
78                         PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_WIDTH
79                     },
80                     new Object[]
81                     {
82                         UIConsts.INTEGERS[8], slblTableName, 97, 25, IFINALSTEP, 220
83                     });
84             txtTableName = CurUnoDialog.insertTextField("txtTableName", SETCOMPLETIONFLAG, this,
85                     new String[]
86                     {
87                         PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, "Text", PropertyNames.PROPERTY_WIDTH
88                     },
89                     new Object[]
90                     {
91                         UIConsts.INTEGER_12, "HID:WIZARDS_HID_DLGTABLE_TXT_NAME", 97, 35, IFINALSTEP, new Short(curtabindex++), PropertyNames.EMPTY_STRING, 223
92                     });
93             txtTableName.addTextListener(CurUnoDialog);
94             txtTableName.setMaxTextLen((short) this.curtabledescriptor.getMaxTableNameLength());
95             if (this.curtabledescriptor.xDBMetaData.supportsCatalogsInTableDefinitions())
96             {
97                 if (sCatalogNames != null)
98                 {
99                     if (sCatalogNames.length > 0)
100                     {
101                         bsupportsCatalogs = true;
102                         String sCatalog = PropertyNames.EMPTY_STRING;
103                         try
104                         {
105                             sCatalog = curtabledescriptor.DBConnection.getCatalog();
106                         }
107                         catch (SQLException e1)
108                         {
109                             e1.printStackTrace(System.out);
110                         }
111                         CurUnoDialog.insertLabel("lblCatalog",
112                                 new String[]
113                                 {
114                                     PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
115                                 },
116                                 new Object[]
117                                 {
118                                     8, slblCatalog, new Integer(nListBoxPosX), 52, IFINALSTEP, new Short(curtabindex++), 120
119                                 });
120 
121                         try
122                         {
123                             xCatalogListBox = CurUnoDialog.insertListBox("lstCatalog", null, null,
124                                     new String[]
125                                     {
126                                         "Dropdown", PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, "LineCount", PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.STRING_ITEM_LIST, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
127                                     },
128                                     new Object[]
129                                     {
130                                         Boolean.TRUE, 12, "HID:WIZARDS_HID_DLGTABLE_LST_CATALOG", new Short(UnoDialog.getListBoxLineCount()), new Integer(nListBoxPosX), 62, IFINALSTEP, sCatalogNames, new Short(curtabindex++), 80
131                                     });
132                             int isel = JavaTools.FieldInList(sCatalogNames, sCatalog);
133                             if (isel < 0)
134                             {
135                                 isel = 0;
136                             }
137                             CurUnoDialog.setControlProperty("lstCatalog", PropertyNames.SELECTED_ITEMS, new short[]
138                                     {
139                                         (short) isel
140                                     });
141                         }
142                         catch (Exception e)
143                         {
144                             e.printStackTrace(System.out);
145                         }
146                         nListBoxPosX = 200;
147                     }
148                 }
149             }
150             if (this.curtabledescriptor.xDBMetaData.supportsSchemasInTableDefinitions())
151             {
152                 if (sSchemaNames != null)
153                 {
154                     if (sSchemaNames.length > 0)
155                     {
156                         bsupportsSchemata = true;
157                         String sSchema = PropertyNames.EMPTY_STRING;
158                         try
159                         {
160                             sSchema = (String) curtabledescriptor.getDataSourcePropertySet().getPropertyValue("User");
161                         }
162                         catch (Exception e1)
163                         {
164                             e1.printStackTrace(System.out);
165                         }
166                         CurUnoDialog.insertLabel("lblSchema",
167                                 new String[]
168                                 {
169                                     PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
170                                 },
171                                 new Object[]
172                                 {
173                                     8, slblSchema, new Integer(nListBoxPosX), 52, IFINALSTEP, new Short(curtabindex++), 80
174                                 });
175 
176                         try
177                         {
178                             xSchemaListBox = CurUnoDialog.insertListBox("lstSchema", null, null,
179                                     new String[]
180                                     {
181                                         "Dropdown", PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, "LineCount", PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.STRING_ITEM_LIST, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
182                                     },
183                                     new Object[]
184                                     {
185                                         Boolean.TRUE, 12, "HID:WIZARDS_HID_DLGTABLE_LST_SCHEMA", new Short(UnoDialog.getListBoxLineCount()), new Integer(nListBoxPosX), 62, IFINALSTEP, sSchemaNames, new Short(curtabindex++), 80
186                                     });
187                             int isel = JavaTools.FieldInList(sSchemaNames, sSchema);
188                             if (isel < 0)
189                             {
190                                 isel = 0;
191                             }
192                             CurUnoDialog.setControlProperty("lstSchema", PropertyNames.SELECTED_ITEMS, new short[]
193                                     {
194                                         (short) isel
195                                     });
196                         }
197                         catch (Exception e)
198                         {
199                             e.printStackTrace(System.out);
200                         }
201                     }
202                 }
203             }
204             if ((!bsupportsCatalogs) && (!bsupportsSchemata))
205             {
206                 CurUnoDialog.insertLabel("lblcongratulations",
207                         new String[]
208                         {
209                             PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_MULTILINE, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
210                         },
211                         new Object[]
212                         {
213                             16, sCongratulations, Boolean.TRUE, 97, 62, IFINALSTEP, new Short(curtabindex++), 226
214                         });
215             }
216             else
217             {
218                 ndiffPosY = 10;
219             }
220             CurUnoDialog.insertLabel("lblProceed",
221                     new String[]
222                     {
223                         PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
224                     },
225                     new Object[]
226                     {
227                         UIConsts.INTEGERS[8], slblProceed, 97, new Integer(82 + ndiffPosY), IFINALSTEP, new Short(curtabindex++), 227
228                     });
229             optWorkWithTable = CurUnoDialog.insertRadioButton("optWorkWithTable", null,
230                     new String[]
231                     {
232                         PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STATE, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
233                     },
234                     new Object[]
235                     {
236                         UIConsts.INTEGERS[8], "HID:WIZARDS_HID_DLGTABLE_OPT_WORKWITHTABLE", sWorkWithTable, 101, new Integer(97 + ndiffPosY), new Short((short) 1), IFINALSTEP, new Short(curtabindex++), 177
237                     });
238             optModifyTable = CurUnoDialog.insertRadioButton("optModifyTable", null,
239                     new String[]
240                     {
241                         PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
242                     },
243                     new Object[]
244                     {
245                         UIConsts.INTEGERS[8], "HID:WIZARDS_HID_DLGTABLE_OPT_MODIFYTABLE", sModifyTable, 101, new Integer(109 + ndiffPosY), IFINALSTEP, new Short(curtabindex++), 177
246                     });
247             optStartFormWizard = CurUnoDialog.insertRadioButton("optStartFormWizard", null,
248                     new String[]
249                     {
250                         PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
251                     },
252                     new Object[]
253                     {
254                         UIConsts.INTEGERS[8], "HID:WIZARDS_HID_DLGTABLE_OPT_STARTFORMWIZARD", sStartFormWizard, 101, new Integer(121 + ndiffPosY), IFINALSTEP, new Short(curtabindex++), 177
255                     });
256         }
257         catch (SQLException e)
258         {
259             e.printStackTrace(System.out);
260         }
261     }
262 
initialize(String _firsttablename)263     public void initialize(String _firsttablename)
264     {
265         setTableName(_firsttablename);
266     }
267 
finish()268     public int finish()
269     {
270         if (optWorkWithTable.getState())
271         {
272             return WORKWITHTABLEMODE;
273         }
274         else if (optModifyTable.getState())
275         {
276             return MODIFYTABLEMODE;
277         }
278         else
279         {
280             return STARTFORMWIZARDMODE;
281         }
282     }
283 
getComposedTableName(String _stablename)284     public String getComposedTableName(String _stablename)
285     {
286         String scatalogname = null;
287         String sschemaname = null;
288         if (xCatalogListBox != null)
289         {
290             scatalogname = xCatalogListBox.getSelectedItem();
291         }
292         if (xSchemaListBox != null)
293         {
294             sschemaname = xSchemaListBox.getSelectedItem();
295         }
296         return curtabledescriptor.getComposedTableName(scatalogname, sschemaname, _stablename);
297     }
298 
setTableName(String _tablename)299     public void setTableName(String _tablename)
300     {
301         if (txtTableName.getText().equals(PropertyNames.EMPTY_STRING))
302         {
303             String ssuffix = Desktop.getIncrementSuffix(curtabledescriptor.getTableNamesAsNameAccess(), getComposedTableName(_tablename));
304             txtTableName.setText(_tablename + ssuffix);
305             setCompletionFlag();
306         }
307     }
308 
getTableName()309     public String getTableName()
310     {
311         return txtTableName.getText();
312     }
313 
getTableName(String _firsttablename)314     public String getTableName(String _firsttablename)
315     {
316         if (txtTableName.getText().equals(PropertyNames.EMPTY_STRING))
317         {
318             setTableName(_firsttablename);
319         }
320         return txtTableName.getText();
321     }
322 
getSchemaName()323     public String getSchemaName()
324     {
325         if (xSchemaListBox != null)
326         {
327             return this.xSchemaListBox.getSelectedItem();
328         }
329         else
330         {
331             return PropertyNames.EMPTY_STRING;
332         }
333     }
334 
getCatalogName()335     public String getCatalogName()
336     {
337         if (xCatalogListBox != null)
338         {
339             return this.xCatalogListBox.getSelectedItem();
340         }
341         else
342         {
343             return PropertyNames.EMPTY_STRING;
344         }
345     }
346 
iscompleted()347     public boolean iscompleted()
348     {
349         return (txtTableName.getText().length() > 0);
350     }
351 
setCompletionFlag()352     public void setCompletionFlag()
353     {
354         CurUnoDialog.setcompleted(TableWizard.SOFINALPAGE, iscompleted());
355     }
356 
setFocusToTableNameControl()357     public void setFocusToTableNameControl()
358     {
359         CurUnoDialog.setFocus("txtTableName");
360     }
361 }
362