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 java.util.ArrayList; 26 import java.util.Vector; 27 28 import com.sun.star.awt.ItemEvent; 29 import com.sun.star.awt.XFixedText; 30 import com.sun.star.awt.XItemListener; 31 import com.sun.star.awt.XListBox; 32 import com.sun.star.awt.XRadioButton; 33 import com.sun.star.beans.PropertyValue; 34 import com.sun.star.container.XNameAccess; 35 import com.sun.star.lang.EventObject; 36 import com.sun.star.lang.Locale; 37 import com.sun.star.lang.XMultiServiceFactory; 38 import com.sun.star.wizards.common.Configuration; 39 import com.sun.star.wizards.common.Desktop; 40 import com.sun.star.wizards.common.Helper; 41 import com.sun.star.wizards.common.JavaTools; 42 import com.sun.star.wizards.common.PropertyNames; 43 import com.sun.star.wizards.db.TableDescriptor; 44 import com.sun.star.wizards.ui.FieldSelection; 45 import com.sun.star.wizards.ui.UIConsts; 46 import com.sun.star.wizards.ui.UnoDialog; 47 import com.sun.star.wizards.ui.XFieldSelectionListener; 48 49 /** 50 * @author Administrator 51 * 52 * To change the template for this generated type comment go to 53 * Window>Preferences>Java>Code Generation>Code and Comments 54 */ 55 public class ScenarioSelector extends FieldSelection implements XItemListener, XFieldSelectionListener 56 { 57 final static int PRIVATE = 0; 58 final static int BUSINESS = 1; 59 60 private XFixedText lblExplanation; 61 private XFixedText lblCategories; 62 private XRadioButton optBusiness; 63 private XRadioButton optPrivate; 64 private XListBox xTableListBox; 65 private TableWizard CurTableWizardUnoDialog; 66 private TableDescriptor curtabledescriptor; 67 private CGCategory oCGCategory; 68 protected CGTable oCGTable; 69 private String SELECTCATEGORY = "selectCategory"; 70 private int curcategory; 71 protected boolean bcolumnnameislimited; 72 private int imaxcolumnchars; 73 private String smytable; 74 private Locale aLocale; 75 private XMultiServiceFactory xMSF; 76 ScenarioSelector(TableWizard _CurUnoDialog, TableDescriptor _curtabledescriptor, String _reslblFields, String _reslblSelFields)77 public ScenarioSelector(TableWizard _CurUnoDialog, TableDescriptor _curtabledescriptor, String _reslblFields, String _reslblSelFields) 78 { 79 super(_CurUnoDialog, TableWizard.SOMAINPAGE, 91, 108, 230, 80, _reslblFields, _reslblSelFields, 41209, true); 80 CurTableWizardUnoDialog = _CurUnoDialog; 81 xMSF = CurUnoDialog.xMSF; 82 aLocale = Configuration.getOfficeLocale(xMSF); 83 curtabledescriptor = _curtabledescriptor; 84 imaxcolumnchars = this.curtabledescriptor.getMaxColumnNameLength(); 85 bcolumnnameislimited = (imaxcolumnchars > 0) && (imaxcolumnchars < 16); 86 addFieldSelectionListener(this); 87 short pretabindex = (short) (50); 88 String sExplanation = CurUnoDialog.m_oResource.getResText(UIConsts.RID_TABLE + 14); 89 String sCategories = CurUnoDialog.m_oResource.getResText(UIConsts.RID_TABLE + 15); 90 String sBusiness = CurUnoDialog.m_oResource.getResText(UIConsts.RID_TABLE + 16); 91 String sPrivate = CurUnoDialog.m_oResource.getResText(UIConsts.RID_TABLE + 17); 92 String sTableNames = CurUnoDialog.m_oResource.getResText(UIConsts.RID_TABLE + 18); 93 smytable = CurUnoDialog.m_oResource.getResText(UIConsts.RID_TABLE + 44); 94 Integer IMAINSTEP = new Integer(TableWizard.SOMAINPAGE); 95 oCGCategory = new CGCategory(CurUnoDialog.xMSF); 96 oCGTable = new CGTable(CurUnoDialog.xMSF); 97 lblExplanation = CurUnoDialog.insertLabel("lblScenarioExplanation", 98 new String[] 99 { 100 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 101 }, 102 new Object[] 103 { 104 32, sExplanation, Boolean.TRUE, 91, 27, IMAINSTEP, new Short(pretabindex++), 233 105 }); 106 107 lblCategories = CurUnoDialog.insertLabel("lblCategories", 108 new String[] 109 { 110 PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 111 }, 112 new Object[] 113 { 114 8, sCategories, 91, 60, IMAINSTEP, new Short(pretabindex++), 100 115 }); 116 117 optBusiness = CurTableWizardUnoDialog.insertRadioButton("optBusiness", SELECTCATEGORY, this, 118 new String[] 119 { 120 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 121 }, 122 new Object[] 123 { 124 UIConsts.INTEGERS[8], "HID:WIZARDS_HID_DLGTABLE_OPTBUSINESS", sBusiness, 98, 70, new Short((short) 1), IMAINSTEP, new Short(pretabindex++), 78 125 }); 126 127 optPrivate = CurTableWizardUnoDialog.insertRadioButton("optPrivate", SELECTCATEGORY, this, 128 new String[] 129 { 130 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 131 }, 132 new Object[] 133 { 134 UIConsts.INTEGERS[8], "HID:WIZARDS_HID_DLGTABLE_OPTPRIVATE", sPrivate, 182, 70, IMAINSTEP, new Short(pretabindex++), 90 135 }); 136 137 CurUnoDialog.insertLabel("lblTableNames", 138 new String[] 139 { 140 PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 141 }, 142 new Object[] 143 { 144 8, sTableNames, 91, 82, IMAINSTEP, new Short(pretabindex++), 80 145 }); 146 147 try 148 { 149 xTableListBox = CurUnoDialog.insertListBox("lstTableNames", 3, null, this, 150 new String[] 151 { 152 "Dropdown", PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, "LineCount", PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 153 }, 154 new Object[] 155 { 156 Boolean.TRUE, 12, "HID:WIZARDS_HID_DLGTABLE_LBTABLES", new Short(UnoDialog.getListBoxLineCount()), 91, 92, IMAINSTEP, new Short(pretabindex++), getListboxWidth() 157 }); 158 } 159 catch (Exception e) 160 { 161 e.printStackTrace(System.out); 162 } 163 initializeCategory(BUSINESS); 164 } 165 selectCategory()166 public void selectCategory() 167 { 168 if (optBusiness.getState()) 169 { 170 initializeCategory(BUSINESS); 171 } 172 else 173 { 174 initializeCategory(PRIVATE); 175 } 176 } 177 initializeCategory(int _iCategory)178 public void initializeCategory(int _iCategory) 179 { 180 try 181 { 182 oCGCategory.initialize( 183 _iCategory == PRIVATE ? "private" : "business"); 184 xTableListBox.removeItems((short) 0, xTableListBox.getItemCount()); 185 xTableListBox.addItems(oCGCategory.getTableNames(), (short) _iCategory); 186 initializeTable(0); 187 } 188 catch (Exception e) 189 { 190 e.printStackTrace(System.out); 191 } 192 } 193 initializeTable(int _iTable)194 public void initializeTable(int _iTable) 195 { 196 Helper.setUnoPropertyValue(UnoDialog.getModel(xTableListBox), PropertyNames.SELECTED_ITEMS, new short[] 197 { 198 (short) _iTable 199 }); 200 oCGTable.initialize(oCGCategory.xNameAccessTablesNode, _iTable); 201 super.initialize(oCGTable.getFieldNames(bcolumnnameislimited, imaxcolumnchars), true); 202 } 203 getSelectedFieldNames()204 public String[] getSelectedFieldNames() 205 { 206 String[] displayfieldnames = super.getSelectedFieldNames(); 207 ArrayList<String> afieldnameVector = new ArrayList<String>(); 208 for (int i = 0; i < displayfieldnames.length; i++) 209 { 210 try 211 { 212 FieldDescription ofielddescription = (FieldDescription) CurTableWizardUnoDialog.fielditems.get(displayfieldnames[i]); 213 if (ofielddescription != null) 214 { 215 afieldnameVector.add(ofielddescription.getName()); 216 } 217 } 218 catch (RuntimeException e) 219 { 220 e.printStackTrace(System.out); 221 } 222 } 223 String[] fieldnames = new String[afieldnameVector.size()]; 224 return afieldnameVector.toArray(fieldnames); 225 } 226 iscompleted()227 public boolean iscompleted() 228 { 229 return getSelectedFieldNames().length > 0; 230 } 231 addColumnsToDescriptor()232 public void addColumnsToDescriptor() 233 { 234 XNameAccess xNameAccessFieldNode; 235 String[] fieldnames = getSelectedFieldNames(); 236 for (int i = 0; i < fieldnames.length; i++) 237 { 238 try 239 { 240 FieldDescription curfielddescription = (FieldDescription) CurTableWizardUnoDialog.fielditems.get(fieldnames[i]); 241 PropertyValue[] aProperties = curfielddescription.getPropertyValues(); 242 this.curtabledescriptor.addColumn(aProperties); 243 } 244 catch (RuntimeException e) 245 { 246 e.printStackTrace(System.out); 247 } 248 } 249 } 250 getTableName()251 public String getTableName() 252 { 253 return xTableListBox.getSelectedItem(); 254 } 255 getFirstTableName()256 public String getFirstTableName() 257 { 258 String[] fieldnames = super.getSelectedFieldNames(); 259 if ((fieldnames.length) > 0) 260 { 261 for (int i = 0; i < CurTableWizardUnoDialog.fielditems.size(); i++) 262 { 263 String stablename = PropertyNames.EMPTY_STRING; 264 try 265 { 266 FieldDescription ofielddescription = (FieldDescription) CurTableWizardUnoDialog.fielditems.get(fieldnames[i]); 267 stablename = ofielddescription.gettablename(); 268 } 269 catch (RuntimeException e) 270 { 271 e.printStackTrace(System.out); 272 } 273 if (!stablename.equals(PropertyNames.EMPTY_STRING)) 274 { 275 return stablename; 276 } 277 } 278 } 279 return smytable; 280 } 281 fillupTables()282 public void fillupTables() 283 { 284 // if (optBusiness.getState()) 285 // else 286 } 287 fillupFieldsListbox()288 public void fillupFieldsListbox() 289 { 290 super.emptyFieldsListBoxes(); 291 } 292 293 294 /* (non-Javadoc) 295 * @see com.sun.star.awt.XItemListener#itemStateChanged(com.sun.star.awt.ItemEvent) 296 */ itemStateChanged(ItemEvent arg0)297 public void itemStateChanged(ItemEvent arg0) 298 { 299 initializeTable((int) xTableListBox.getSelectedItemPos()); 300 } 301 302 /* (non-Javadoc) 303 * @see com.sun.star.lang.XEventListener#disposing(com.sun.star.lang.EventObject) 304 */ disposing(EventObject arg0)305 public void disposing(EventObject arg0) 306 { 307 } 308 protected int ID; 309 getID()310 public int getID() 311 { 312 return ID; 313 } 314 setID(String sIncSuffix)315 public void setID(String sIncSuffix) 316 { 317 } 318 shiftFromLeftToRight(String[] SelItems, String[] NewItems)319 public void shiftFromLeftToRight(String[] SelItems, String[] NewItems) 320 { 321 if (!CurTableWizardUnoDialog.verifyfieldcount(NewItems.length)) 322 { 323 for (int i = 0; i < SelItems.length; i++) 324 { 325 int selindex = JavaTools.FieldInList(NewItems, SelItems[i]); 326 super.xSelectedFieldsListBox.removeItems((short) selindex, (short) 1); 327 /**TODO In this context the items should be better placed at their original position. 328 * but how is this position retrieved? 329 */ 330 super.xFieldsListBox.addItem(SelItems[i], xFieldsListBox.getItemCount()); 331 } 332 } 333 else 334 { 335 for (int i = 0; i < NewItems.length; i++) 336 { 337 int iduplicate; 338 if (CurTableWizardUnoDialog.fielditems.containsKey(NewItems[i])) 339 { 340 iduplicate = JavaTools.getDuplicateFieldIndex(NewItems, NewItems[i]); 341 if (iduplicate != -1) 342 { 343 XNameAccess xNameAccessFieldNode; 344 String sdisplayname = Desktop.getUniqueName(NewItems, NewItems[iduplicate], PropertyNames.EMPTY_STRING); 345 FieldDescription curfielddescription = new FieldDescription(xMSF, aLocale, this, sdisplayname, NewItems[iduplicate], imaxcolumnchars); 346 CurTableWizardUnoDialog.fielditems.put(sdisplayname, curfielddescription); 347 NewItems[iduplicate] = sdisplayname; 348 setSelectedFieldNames(NewItems); 349 } 350 } 351 else 352 { 353 CurTableWizardUnoDialog.fielditems.put(NewItems[i], new FieldDescription(xMSF, aLocale, this, NewItems[i], NewItems[i], imaxcolumnchars)); 354 } 355 } 356 } 357 CurTableWizardUnoDialog.setcompleted(TableWizard.SOMAINPAGE, NewItems.length > 0); 358 } 359 shiftFromRightToLeft(String[] SelItems, String[] NewItems)360 public void shiftFromRightToLeft(String[] SelItems, String[] NewItems) 361 { 362 for (int i = 0; i < SelItems.length; i++) 363 { 364 if (CurTableWizardUnoDialog.fielditems.containsKey(SelItems[i])) 365 { 366 CurTableWizardUnoDialog.fielditems.remove(SelItems[i]); 367 this.curtabledescriptor.dropColumnbyName(SelItems[i]); 368 } 369 } 370 CurTableWizardUnoDialog.setcompleted(TableWizard.SOMAINPAGE, NewItems.length > 0); 371 } 372 moveItemDown(String item)373 public void moveItemDown(String item) 374 { 375 } 376 moveItemUp(String item)377 public void moveItemUp(String item) 378 { 379 } 380 } 381