1 /* 2 ************************************************************************ 3 * 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * Copyright 2000, 2010 Oracle and/or its affiliates. 7 * 8 * OpenOffice.org - a multi-platform office productivity suite 9 * 10 * This file is part of OpenOffice.org. 11 * 12 * OpenOffice.org is free software: you can redistribute it and/or modify 13 * it under the terms of the GNU Lesser General Public License version 3 14 * only, as published by the Free Software Foundation. 15 * 16 * OpenOffice.org is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU Lesser General Public License version 3 for more details 20 * (a copy is included in the LICENSE file that accompanied this code). 21 * 22 * You should have received a copy of the GNU Lesser General Public License 23 * version 3 along with OpenOffice.org. If not, see 24 * <http://www.openoffice.org/license.html> 25 * for a copy of the LGPLv3 License. 26 * 27 ************************************************************************/ 28 package com.sun.star.wizards.letter; 29 30 import java.util.Vector; 31 import com.sun.star.lang.IllegalArgumentException; 32 import com.sun.star.lang.WrappedTargetException; 33 import com.sun.star.lang.XMultiServiceFactory; 34 import com.sun.star.wizards.common.Configuration; 35 import com.sun.star.wizards.common.Desktop; 36 import com.sun.star.wizards.common.NoValidPathException; 37 import com.sun.star.wizards.common.SystemDialog; 38 import com.sun.star.wizards.common.PropertyNames; 39 import com.sun.star.awt.VclWindowPeerAttribute; 40 import com.sun.star.awt.XTextComponent; 41 import com.sun.star.awt.XWindow; 42 import com.sun.star.awt.XWindowPeer; 43 import com.sun.star.beans.PropertyValue; 44 import com.sun.star.container.NoSuchElementException; 45 import com.sun.star.document.MacroExecMode; 46 import com.sun.star.document.XDocumentProperties; 47 import com.sun.star.document.XDocumentPropertiesSupplier; 48 import com.sun.star.ucb.CommandAbortedException; 49 import com.sun.star.uno.AnyConverter; 50 import com.sun.star.uno.Exception; 51 import com.sun.star.uno.UnoRuntime; 52 import com.sun.star.wizards.text.*; 53 import com.sun.star.wizards.common.*; 54 import com.sun.star.task.XInteractionHandler; 55 import com.sun.star.text.XTextFrame; 56 import com.sun.star.text.XTextDocument; 57 import com.sun.star.uno.XInterface; 58 import com.sun.star.util.CloseVetoException; 59 import com.sun.star.util.XCloseable; 60 import com.sun.star.wizards.document.*; 61 import com.sun.star.wizards.ui.*; 62 import com.sun.star.wizards.ui.event.*; 63 import com.sun.star.wizards.common.Helper; 64 65 public class LetterWizardDialogImpl extends LetterWizardDialog 66 { 67 68 protected void enterStep(int OldStep, int NewStep) 69 { 70 } 71 72 protected void leaveStep(int OldStep, int NewStep) 73 { 74 } 75 static LetterDocument myLetterDoc; 76 static boolean running; 77 XMultiServiceFactory xmsf; 78 XTextDocument xTextDocument; 79 PathSelection myPathSelection; 80 CGLetterWizard myConfig; 81 Vector mainDA = new Vector(); 82 Vector letterDA = new Vector(); 83 Vector businessDA = new Vector(); 84 String[][] BusinessFiles; 85 String[][] OfficialFiles; 86 String[][] PrivateFiles; 87 String[] Norms; 88 String[] NormPaths; 89 String[] NormNames; 90 String sTemplatePath; 91 String sUserTemplatePath; 92 String sBitmapPath; 93 String sLetterPath; 94 String sLetterLangPackPath; 95 String sWorkPath; 96 String sCurrentNorm; 97 String sPath; 98 boolean bEditTemplate; 99 boolean bSaveSuccess = false; 100 private boolean filenameChanged = false; 101 LetterDocument.BusinessPaperObject BusCompanyLogo = null; 102 LetterDocument.BusinessPaperObject BusCompanyAddress = null; 103 LetterDocument.BusinessPaperObject BusCompanyAddressReceiver = null; 104 LetterDocument.BusinessPaperObject BusFooter = null; 105 final static int RM_TYPESTYLE = 1; 106 final static int RM_BUSINESSPAPER = 2; 107 final static int RM_ELEMENTS = 3; 108 final static int RM_SENDERRECEIVER = 4; 109 final static int RM_FOOTER = 5; 110 final static int RM_FINALSETTINGS = 6; 111 112 public LetterWizardDialogImpl(XMultiServiceFactory xmsf) 113 { 114 super(xmsf); 115 this.xmsf = xmsf; 116 } 117 118 public static void main(String args[]) 119 { 120 //only being called when starting wizard remotely 121 String ConnectStr = "uno:socket,host=127.0.0.1,port=8100;urp,negotiate=0,forcesynchronous=1;StarOffice.ServiceManager"; 122 XMultiServiceFactory xLocMSF = null; 123 try 124 { 125 xLocMSF = Desktop.connect(ConnectStr); 126 } 127 catch (Exception e) 128 { 129 e.printStackTrace(); 130 } 131 catch (java.lang.Exception e) 132 { 133 e.printStackTrace(); 134 } 135 LetterWizardDialogImpl lw = new LetterWizardDialogImpl(xLocMSF); 136 lw.startWizard(xLocMSF, null); 137 138 } 139 140 public void startWizard(XMultiServiceFactory xMSF, Object[] CurPropertyValue) 141 { 142 143 running = true; 144 try 145 { 146 //Number of steps on WizardDialog: 147 setMaxStep(6); 148 149 //instatiate The Document Frame for the Preview 150 myLetterDoc = new LetterDocument(xMSF, this); 151 152 //create the dialog: 153 drawNaviBar(); 154 buildStep1(); 155 buildStep2(); 156 buildStep3(); 157 buildStep4(); 158 buildStep5(); 159 buildStep6(); 160 161 initializePaths(); 162 initializeNorms(); 163 initializeSalutation(); 164 initializeGreeting(); 165 166 167 //special Control for setting the save Path: 168 insertPathSelectionControl(); 169 170 //load the last used settings from the registry and apply listeners to the controls: 171 initConfiguration(); 172 173 //set the language according to the Linguistic 174 int oL = getOfficeLinguistic(); 175 myConfig.cp_BusinessLetter.cp_Norm = oL; 176 myConfig.cp_PrivateOfficialLetter.cp_Norm = oL; 177 myConfig.cp_PrivateLetter.cp_Norm = oL; 178 initializeTemplates(xMSF); 179 180 if (myConfig.cp_BusinessLetter.cp_Greeting.equals(PropertyNames.EMPTY_STRING)) 181 { 182 myConfig.cp_BusinessLetter.cp_Greeting = resources.GreetingLabels[0]; 183 } 184 if (myConfig.cp_BusinessLetter.cp_Salutation.equals(PropertyNames.EMPTY_STRING)) 185 { 186 myConfig.cp_BusinessLetter.cp_Salutation = resources.SalutationLabels[0]; 187 } 188 if (myConfig.cp_PrivateOfficialLetter.cp_Greeting.equals(PropertyNames.EMPTY_STRING)) 189 { 190 myConfig.cp_PrivateOfficialLetter.cp_Greeting = resources.GreetingLabels[1]; 191 } 192 if (myConfig.cp_PrivateOfficialLetter.cp_Salutation.equals(PropertyNames.EMPTY_STRING)) 193 { 194 myConfig.cp_PrivateOfficialLetter.cp_Salutation = resources.SalutationLabels[1]; 195 } 196 if (myConfig.cp_PrivateLetter.cp_Greeting.equals(PropertyNames.EMPTY_STRING)) 197 { 198 myConfig.cp_PrivateLetter.cp_Greeting = resources.GreetingLabels[2]; 199 } 200 if (myConfig.cp_PrivateLetter.cp_Salutation.equals(PropertyNames.EMPTY_STRING)) 201 { 202 myConfig.cp_PrivateLetter.cp_Salutation = resources.SalutationLabels[2]; 203 } 204 205 //update the dialog UI according to the loaded Configuration 206 updateUI(); 207 208 if (myPathSelection.xSaveTextBox.getText().equalsIgnoreCase(PropertyNames.EMPTY_STRING)) 209 { 210 myPathSelection.initializePath(); 211 } 212 213 XWindow xContainerWindow = myLetterDoc.xFrame.getContainerWindow(); 214 XWindowPeer xWindowPeer = UnoRuntime.queryInterface(XWindowPeer.class, xContainerWindow); 215 createWindowPeer(xWindowPeer); 216 217 //add the Roadmap to the dialog: 218 insertRoadmap(); 219 220 //load the last used document and apply last used settings: 221 setConfiguration(); 222 223 //If the configuration does not define Greeting/Salutation yet choose a default 224 setDefaultForGreetingAndSalutation(); 225 226 //disable funtionality that is not supported by the template: 227 initializeElements(); 228 229 //disable the document, so that the user cannot change anything: 230 myLetterDoc.xFrame.getComponentWindow().setEnable(false); 231 232 executeDialog(myLetterDoc.xFrame); 233 removeTerminateListener(); 234 closeDocument(); 235 running = false; 236 237 } 238 catch (Exception exception) 239 { 240 removeTerminateListener(); 241 exception.printStackTrace(System.out); 242 running = false; 243 } 244 } 245 246 public void cancelWizard() 247 { 248 xDialog.endExecute(); 249 running = false; 250 } 251 252 public boolean finishWizard() 253 { 254 switchToStep(getCurrentStep(), getMaxStep()); 255 try 256 { 257 //myLetterDoc.xTextDocument.lockControllers(); 258 FileAccess fileAccess = new FileAccess(xMSF); 259 sPath = myPathSelection.getSelectedPath(); 260 if (sPath.equals(PropertyNames.EMPTY_STRING)) 261 { 262 myPathSelection.triggerPathPicker(); 263 sPath = myPathSelection.getSelectedPath(); 264 } 265 sPath = fileAccess.getURL(sPath); 266 267 //first, if the filename was not changed, thus 268 //it is coming from a saved session, check if the 269 // file exists and warn the user. 270 if (!filenameChanged) 271 { 272 if (fileAccess.exists(sPath, true)) 273 { 274 275 int answer = SystemDialog.showMessageBox(xMSF, xControl.getPeer(), "MessBox", VclWindowPeerAttribute.YES_NO + VclWindowPeerAttribute.DEF_NO, resources.resOverwriteWarning); 276 if (answer == 3) // user said: no, do not overwrite.... 277 { 278 return false; 279 } 280 } 281 } 282 myLetterDoc.setWizardTemplateDocInfo(resources.resLetterWizardDialog_title, resources.resTemplateDescription); 283 myLetterDoc.killEmptyUserFields(); 284 myLetterDoc.keepLogoFrame = (chkUseLogo.getState() != 0); 285 if ((chkBusinessPaper.getState() != 0) && (chkPaperCompanyLogo.getState() != 0)) 286 { 287 myLetterDoc.keepLogoFrame = false; 288 } 289 myLetterDoc.keepBendMarksFrame = (chkUseBendMarks.getState() != 0); 290 myLetterDoc.keepLetterSignsFrame = (chkUseSigns.getState() != 0); 291 myLetterDoc.keepSenderAddressRepeatedFrame = (chkUseAddressReceiver.getState() != 0); 292 293 if (optBusinessLetter.getState()) 294 { 295 if ((chkBusinessPaper.getState() != 0) && (chkCompanyReceiver.getState() != 0)) 296 { 297 myLetterDoc.keepSenderAddressRepeatedFrame = false; 298 } 299 if ((chkBusinessPaper.getState() != 0) && (chkPaperCompanyAddress.getState() != 0)) 300 { 301 myLetterDoc.keepAddressFrame = false; 302 } 303 } 304 305 myLetterDoc.killEmptyFrames(); 306 307 308 bSaveSuccess = OfficeDocument.store(xMSF, xTextDocument, sPath, "writer8_template", false); 309 310 if (bSaveSuccess) 311 { 312 saveConfiguration(); 313 XInteractionHandler xIH = UnoRuntime.queryInterface(XInteractionHandler.class, xMSF.createInstance("com.sun.star.comp.uui.UUIInteractionHandler")); 314 PropertyValue loadValues[] = new PropertyValue[4]; 315 loadValues[0] = new PropertyValue(); 316 loadValues[0].Name = "AsTemplate"; 317 loadValues[1] = new PropertyValue(); 318 loadValues[1].Name = "MacroExecutionMode"; 319 loadValues[1].Value = new Short(MacroExecMode.ALWAYS_EXECUTE); 320 loadValues[2] = new PropertyValue(); 321 loadValues[2].Name = "UpdateDocMode"; 322 loadValues[2].Value = new Short(com.sun.star.document.UpdateDocMode.FULL_UPDATE); 323 loadValues[3] = new PropertyValue(); 324 loadValues[3].Name = "InteractionHandler"; 325 loadValues[3].Value = xIH; 326 327 if (bEditTemplate) 328 { 329 loadValues[0].Value = Boolean.FALSE; 330 } 331 else 332 { 333 loadValues[0].Value = Boolean.TRUE; 334 } 335 Object oDoc = OfficeDocument.load(Desktop.getDesktop(xMSF), sPath, "_default", loadValues); 336 XTextDocument xTextDocument = (com.sun.star.text.XTextDocument) oDoc; 337 XMultiServiceFactory xDocMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 338 ViewHandler myViewHandler = new ViewHandler(xDocMSF, xTextDocument); 339 myViewHandler.setViewSetting("ZoomType", new Short(com.sun.star.view.DocumentZoomType.OPTIMAL)); 340 } 341 else 342 { 343 //TODO: Error Handling 344 } 345 } 346 catch (Exception e) 347 { 348 e.printStackTrace(); 349 } 350 finally 351 { 352 xDialog.endExecute(); 353 running = false; 354 } 355 return true; 356 } 357 358 public void closeDocument() 359 { 360 try 361 { 362 //xComponent.dispose(); 363 XCloseable xCloseable = UnoRuntime.queryInterface(XCloseable.class, myLetterDoc.xFrame); 364 xCloseable.close(false); 365 } 366 catch (CloseVetoException e) 367 { 368 e.printStackTrace(); 369 } 370 } 371 372 public void optBusinessLetterItemChanged() 373 { 374 DataAware.setDataObject(letterDA, myConfig.cp_BusinessLetter, true); 375 setControlProperty("lblBusinessStyle", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 376 setControlProperty("lstBusinessStyle", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 377 setControlProperty("chkBusinessPaper", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 378 setControlProperty("lblPrivOfficialStyle", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 379 setControlProperty("lstPrivOfficialStyle", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 380 setControlProperty("lblPrivateStyle", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 381 setControlProperty("lstPrivateStyle", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 382 lstBusinessStyleItemChanged(); 383 enableSenderReceiver(); 384 setPossibleFooter(true); 385 if (myPathSelection.xSaveTextBox.getText().equalsIgnoreCase(PropertyNames.EMPTY_STRING)) 386 { 387 myPathSelection.initializePath(); 388 } 389 } 390 391 public void optPrivOfficialLetterItemChanged() 392 { 393 DataAware.setDataObject(letterDA, myConfig.cp_PrivateOfficialLetter, true); 394 setControlProperty("lblBusinessStyle", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 395 setControlProperty("lstBusinessStyle", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 396 setControlProperty("chkBusinessPaper", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 397 setControlProperty("lblPrivOfficialStyle", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 398 setControlProperty("lstPrivOfficialStyle", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 399 setControlProperty("lblPrivateStyle", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 400 setControlProperty("lstPrivateStyle", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 401 lstPrivOfficialStyleItemChanged(); 402 disableBusinessPaper(); 403 enableSenderReceiver(); 404 setPossibleFooter(true); 405 if (myPathSelection.xSaveTextBox.getText().equalsIgnoreCase(PropertyNames.EMPTY_STRING)) 406 { 407 myPathSelection.initializePath(); 408 } 409 } 410 411 public void optPrivateLetterItemChanged() 412 { 413 DataAware.setDataObject(letterDA, myConfig.cp_PrivateLetter, true); 414 setControlProperty("lblBusinessStyle", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 415 setControlProperty("lstBusinessStyle", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 416 setControlProperty("chkBusinessPaper", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 417 setControlProperty("lblPrivOfficialStyle", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 418 setControlProperty("lstPrivOfficialStyle", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 419 setControlProperty("lblPrivateStyle", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 420 setControlProperty("lstPrivateStyle", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 421 lstPrivateStyleItemChanged(); 422 disableBusinessPaper(); 423 disableSenderReceiver(); 424 setPossibleFooter(false); 425 if (myPathSelection.xSaveTextBox.getText().equalsIgnoreCase(PropertyNames.EMPTY_STRING)) 426 { 427 myPathSelection.initializePath(); 428 } 429 } 430 431 public void optSenderPlaceholderItemChanged() 432 { 433 setControlProperty("lblSenderName", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 434 setControlProperty("lblSenderStreet", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 435 setControlProperty("lblPostCodeCity", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 436 setControlProperty("txtSenderName", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 437 setControlProperty("txtSenderStreet", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 438 setControlProperty("txtSenderPostCode", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 439 setControlProperty("txtSenderState", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 440 setControlProperty("txtSenderCity", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 441 myLetterDoc.fillSenderWithUserData(); 442 } 443 444 public void optSenderDefineItemChanged() 445 { 446 setControlProperty("lblSenderName", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 447 setControlProperty("lblSenderStreet", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 448 setControlProperty("lblPostCodeCity", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 449 setControlProperty("txtSenderName", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 450 setControlProperty("txtSenderStreet", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 451 setControlProperty("txtSenderPostCode", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 452 setControlProperty("txtSenderState", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 453 setControlProperty("txtSenderCity", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 454 txtSenderNameTextChanged(); 455 txtSenderStreetTextChanged(); 456 txtSenderPostCodeTextChanged(); 457 txtSenderStateTextChanged(); 458 txtSenderCityTextChanged(); 459 } 460 461 public void optCreateLetterItemChanged() 462 { 463 bEditTemplate = false; 464 } 465 466 public void optMakeChangesItemChanged() 467 { 468 bEditTemplate = true; 469 } 470 471 public void optReceiverPlaceholderItemChanged() 472 { 473 OfficeDocument.attachEventCall(xTextDocument, "OnNew", "StarBasic", "macro:///Template.Correspondence.Placeholder()"); 474 } 475 476 public void optReceiverDatabaseItemChanged() 477 { 478 OfficeDocument.attachEventCall(xTextDocument, "OnNew", "StarBasic", "macro:///Template.Correspondence.Database()"); 479 } 480 481 public void lstBusinessStyleItemChanged() 482 { 483 xTextDocument = myLetterDoc.loadAsPreview(BusinessFiles[1][lstBusinessStyle.getSelectedItemPos()], false); 484 myLetterDoc.xTextDocument.lockControllers(); 485 initializeElements(); 486 chkBusinessPaperItemChanged(); 487 setElements(false); 488 myLetterDoc.xTextDocument.unlockControllers(); 489 activate(); 490 } 491 492 public void lstPrivOfficialStyleItemChanged() 493 { 494 xTextDocument = myLetterDoc.loadAsPreview(OfficialFiles[1][lstPrivOfficialStyle.getSelectedItemPos()], false); 495 myLetterDoc.xTextDocument.lockControllers(); 496 initializeElements(); 497 setPossibleSenderData(true); 498 setElements(false); 499 myLetterDoc.xTextDocument.unlockControllers(); 500 activate(); 501 } 502 503 public void lstPrivateStyleItemChanged() 504 { 505 xTextDocument = myLetterDoc.loadAsPreview(PrivateFiles[1][lstPrivateStyle.getSelectedItemPos()], false); 506 myLetterDoc.xTextDocument.lockControllers(); 507 initializeElements(); 508 setElements(true); 509 myLetterDoc.xTextDocument.unlockControllers(); 510 activate(); 511 } 512 513 public void numLogoHeightTextChanged() 514 { 515 BusCompanyLogo.iHeight = (int) (numLogoHeight.getValue() * 1000); 516 BusCompanyLogo.setFramePosition(); 517 } 518 519 public void numLogoWidthTextChanged() 520 { 521 BusCompanyLogo.iWidth = (int) (numLogoWidth.getValue() * 1000); 522 BusCompanyLogo.setFramePosition(); 523 } 524 525 public void numLogoXTextChanged() 526 { 527 BusCompanyLogo.iXPos = (int) (numLogoX.getValue() * 1000); 528 BusCompanyLogo.setFramePosition(); 529 } 530 531 public void numLogoYTextChanged() 532 { 533 BusCompanyLogo.iYPos = (int) (numLogoY.getValue() * 1000); 534 BusCompanyLogo.setFramePosition(); 535 } 536 537 public void numAddressWidthTextChanged() 538 { 539 BusCompanyAddress.iWidth = (int) (numAddressWidth.getValue() * 1000); 540 BusCompanyAddress.setFramePosition(); 541 } 542 543 public void numAddressXTextChanged() 544 { 545 BusCompanyAddress.iXPos = (int) (numAddressX.getValue() * 1000); 546 BusCompanyAddress.setFramePosition(); 547 } 548 549 public void numAddressYTextChanged() 550 { 551 BusCompanyAddress.iYPos = (int) (numAddressY.getValue() * 1000); 552 BusCompanyAddress.setFramePosition(); 553 } 554 555 public void numAddressHeightTextChanged() 556 { 557 BusCompanyAddress.iHeight = (int) (numAddressHeight.getValue() * 1000); 558 BusCompanyAddress.setFramePosition(); 559 } 560 561 public void numFooterHeightTextChanged() 562 { 563 BusFooter.iHeight = (int) (numFooterHeight.getValue() * 1000); 564 BusFooter.iYPos = myLetterDoc.DocSize.Height - BusFooter.iHeight; 565 BusFooter.setFramePosition(); 566 } 567 568 public void chkPaperCompanyLogoItemChanged() 569 { 570 if (chkPaperCompanyLogo.getState() != 0) 571 { 572 //minimal value is required, otherwise the frame creation fails 573 if (numLogoWidth.getValue() == 0) 574 { 575 numLogoWidth.setValue(0.1); 576 } 577 if (numLogoHeight.getValue() == 0) 578 { 579 numLogoHeight.setValue(0.1); 580 } 581 BusCompanyLogo = myLetterDoc.new BusinessPaperObject("Company Logo", (int) (numLogoWidth.getValue() * 1000), (int) (numLogoHeight.getValue() * 1000), (int) (numLogoX.getValue() * 1000), (int) (numLogoY.getValue() * 1000)); 582 setControlProperty("numLogoHeight", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 583 setControlProperty("lblCompanyLogoHeight", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 584 setControlProperty("numLogoWidth", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 585 setControlProperty("lblCompanyLogoWidth", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 586 setControlProperty("numLogoX", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 587 setControlProperty("lblCompanyLogoX", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 588 setControlProperty("numLogoY", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 589 setControlProperty("lblCompanyLogoY", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 590 setPossibleLogo(false); 591 } 592 else 593 { 594 if (BusCompanyLogo != null) 595 { 596 BusCompanyLogo.removeFrame(); 597 } 598 setControlProperty("numLogoHeight", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 599 setControlProperty("lblCompanyLogoHeight", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 600 setControlProperty("numLogoWidth", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 601 setControlProperty("lblCompanyLogoWidth", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 602 setControlProperty("numLogoX", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 603 setControlProperty("lblCompanyLogoX", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 604 setControlProperty("numLogoY", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 605 setControlProperty("lblCompanyLogoY", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 606 setPossibleLogo(true); 607 } 608 } 609 610 public void chkPaperCompanyAddressItemChanged() 611 { 612 if (chkPaperCompanyAddress.getState() != 0) 613 { 614 // minimal value is required, otherwise the frame creation fails 615 if (numAddressWidth.getValue() == 0) 616 { 617 numAddressWidth.setValue(0.1); 618 } 619 if (numAddressHeight.getValue() == 0) 620 { 621 numAddressHeight.setValue(0.1); 622 } 623 BusCompanyAddress = myLetterDoc.new BusinessPaperObject("Company Address", (int) (numAddressWidth.getValue() * 1000), (int) (numAddressHeight.getValue() * 1000), (int) (numAddressX.getValue() * 1000), (int) (numAddressY.getValue() * 1000)); 624 setControlProperty("numAddressHeight", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 625 setControlProperty("lblCompanyAddressHeight", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 626 setControlProperty("numAddressWidth", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 627 setControlProperty("lblCompanyAddressWidth", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 628 setControlProperty("numAddressX", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 629 setControlProperty("lblCompanyAddressX", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 630 setControlProperty("numAddressY", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 631 setControlProperty("lblCompanyAddressY", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 632 if (myLetterDoc.hasElement("Sender Address")) 633 { 634 myLetterDoc.switchElement("Sender Address", (false)); 635 } 636 if (chkCompanyReceiver.getState() != 0) 637 { 638 setPossibleSenderData(false); 639 } 640 } 641 else 642 { 643 if (BusCompanyAddress != null) 644 { 645 BusCompanyAddress.removeFrame(); 646 } 647 setControlProperty("numAddressHeight", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 648 setControlProperty("lblCompanyAddressHeight", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 649 setControlProperty("numAddressWidth", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 650 setControlProperty("lblCompanyAddressWidth", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 651 setControlProperty("numAddressX", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 652 setControlProperty("lblCompanyAddressX", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 653 setControlProperty("numAddressY", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 654 setControlProperty("lblCompanyAddressY", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 655 if (myLetterDoc.hasElement("Sender Address")) 656 { 657 myLetterDoc.switchElement("Sender Address", (true)); 658 } 659 setPossibleSenderData(true); 660 if (optSenderDefine.getState()) 661 { 662 optSenderDefineItemChanged(); 663 } 664 if (optSenderPlaceholder.getState()) 665 { 666 optSenderPlaceholderItemChanged(); 667 } 668 } 669 } 670 671 public void chkCompanyReceiverItemChanged() 672 { 673 XTextFrame xReceiverFrame = null; 674 675 if (chkCompanyReceiver.getState() != 0) 676 { 677 try 678 { 679 xReceiverFrame = TextFrameHandler.getFrameByName("Receiver Address", xTextDocument); 680 Integer FrameWidth = (Integer) Helper.getUnoPropertyValue(xReceiverFrame, PropertyNames.PROPERTY_WIDTH); 681 int iFrameWidth = FrameWidth.intValue(); 682 Integer FrameX = (Integer) Helper.getUnoPropertyValue(xReceiverFrame, "HoriOrientPosition"); 683 int iFrameX = FrameX.intValue(); 684 Integer FrameY = (Integer) Helper.getUnoPropertyValue(xReceiverFrame, "VertOrientPosition"); 685 int iFrameY = FrameY.intValue(); 686 687 //Height of the Company Address in the Receiver Field 688 int iReceiverHeight = (int) (0.5 * 1000); 689 BusCompanyAddressReceiver = myLetterDoc.new BusinessPaperObject(PropertyNames.SPACE, iFrameWidth, iReceiverHeight, iFrameX, (iFrameY - iReceiverHeight)); 690 691 setPossibleAddressReceiver(false); 692 } 693 catch (NoSuchElementException e) 694 { 695 // TODO Error Message: Template modified! 696 e.printStackTrace(); 697 } 698 catch (WrappedTargetException e) 699 { 700 e.printStackTrace(); 701 } 702 if (chkPaperCompanyAddress.getState() != 0) 703 { 704 setPossibleSenderData(false); 705 } 706 } 707 else 708 { 709 if (BusCompanyAddressReceiver != null) 710 { 711 BusCompanyAddressReceiver.removeFrame(); 712 } 713 setPossibleAddressReceiver(true); 714 setPossibleSenderData(true); 715 if (optSenderDefine.getState()) 716 { 717 optSenderDefineItemChanged(); 718 } 719 if (optSenderPlaceholder.getState()) 720 { 721 optSenderPlaceholderItemChanged(); 722 } 723 } 724 } 725 726 public void chkPaperFooterItemChanged() 727 { 728 729 if (chkPaperFooter.getState() != 0) 730 { 731 //minimal value is required, otherwise the frame creation fails 732 if (numFooterHeight.getValue() == 0) 733 { 734 numFooterHeight.setValue(0.1); 735 } 736 BusFooter = myLetterDoc.new BusinessPaperObject("Footer", myLetterDoc.DocSize.Width, (int) (numFooterHeight.getValue() * 1000), 0, (int) (myLetterDoc.DocSize.Height - (numFooterHeight.getValue() * 1000))); 737 this.setControlProperty("numFooterHeight", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 738 this.setControlProperty("lblFooterHeight", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 739 setPossibleFooter(false); 740 } 741 else 742 { 743 if (BusFooter != null) 744 { 745 BusFooter.removeFrame(); 746 } 747 setControlProperty("numFooterHeight", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 748 setControlProperty("lblFooterHeight", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 749 setPossibleFooter(true); 750 } 751 } 752 753 //switch Elements on/off ------------------------------------------------------- 754 public void chkUseLogoItemChanged() 755 { 756 try 757 { 758 if (myLetterDoc.hasElement("Company Logo")) 759 { 760 boolean logostatus = AnyConverter.toBoolean(getControlProperty("chkUseLogo", PropertyNames.PROPERTY_ENABLED)) && (chkUseLogo.getState() != 0); 761 myLetterDoc.switchElement("Company Logo", logostatus); 762 } 763 } 764 catch (IllegalArgumentException e) 765 { 766 e.printStackTrace(); 767 } 768 } 769 770 public void chkUseAddressReceiverItemChanged() 771 { 772 try 773 { 774 if (myLetterDoc.hasElement("Sender Address Repeated")) 775 { 776 boolean rstatus = AnyConverter.toBoolean(getControlProperty("chkUseAddressReceiver", PropertyNames.PROPERTY_ENABLED)) && (chkUseAddressReceiver.getState() != 0); 777 myLetterDoc.switchElement("Sender Address Repeated", rstatus); 778 } 779 } 780 catch (IllegalArgumentException e) 781 { 782 e.printStackTrace(); 783 } 784 } 785 786 public void chkUseSignsItemChanged() 787 { 788 if (myLetterDoc.hasElement("Letter Signs")) 789 { 790 myLetterDoc.switchElement("Letter Signs", (chkUseSigns.getState() != 0)); 791 } 792 } 793 794 public void chkUseSubjectItemChanged() 795 { 796 if (myLetterDoc.hasElement("Subject Line")) 797 { 798 myLetterDoc.switchElement("Subject Line", (chkUseSubject.getState() != 0)); 799 } 800 } 801 802 public void chkUseBendMarksItemChanged() 803 { 804 if (myLetterDoc.hasElement("Bend Marks")) 805 { 806 myLetterDoc.switchElement("Bend Marks", (chkUseBendMarks.getState() != 0)); 807 } 808 } 809 810 public void chkUseFooterItemChanged() 811 { 812 try 813 { 814 boolean bFooterPossible = (chkUseFooter.getState() != 0) && AnyConverter.toBoolean(getControlProperty("chkUseFooter", PropertyNames.PROPERTY_ENABLED)); 815 816 if (chkFooterNextPages.getState() != 0) 817 { 818 myLetterDoc.switchFooter("First Page", false, (chkFooterPageNumbers.getState() != 0), txtFooter.getText()); 819 myLetterDoc.switchFooter("Standard", bFooterPossible, (chkFooterPageNumbers.getState() != 0), txtFooter.getText()); 820 } 821 else 822 { 823 myLetterDoc.switchFooter("First Page", bFooterPossible, (chkFooterPageNumbers.getState() != 0), txtFooter.getText()); 824 myLetterDoc.switchFooter("Standard", bFooterPossible, (chkFooterPageNumbers.getState() != 0), txtFooter.getText()); 825 } 826 827 //enable/disable roadmap item for footer page 828 XInterface BPaperItem = getRoadmapItemByID(RM_FOOTER); 829 Helper.setUnoPropertyValue(BPaperItem, PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bFooterPossible)); 830 831 } 832 catch (Exception exception) 833 { 834 exception.printStackTrace(System.out); 835 } 836 } 837 838 public void chkFooterNextPagesItemChanged() 839 { 840 chkUseFooterItemChanged(); 841 } 842 843 public void chkFooterPageNumbersItemChanged() 844 { 845 chkUseFooterItemChanged(); 846 } 847 848 private void setPossibleFooter(boolean bState) 849 { 850 setControlProperty("chkUseFooter", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bState)); 851 chkUseFooterItemChanged(); 852 } 853 854 private void setPossibleAddressReceiver(boolean bState) 855 { 856 if (myLetterDoc.hasElement("Sender Address Repeated")) 857 { 858 setControlProperty("chkUseAddressReceiver", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bState)); 859 chkUseAddressReceiverItemChanged(); 860 } 861 } 862 863 private void setPossibleLogo(boolean bState) 864 { 865 if (myLetterDoc.hasElement("Company Logo")) 866 { 867 setControlProperty("chkUseLogo", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bState)); 868 chkUseLogoItemChanged(); 869 } 870 } 871 872 public void txtFooterTextChanged() 873 { 874 chkUseFooterItemChanged(); 875 } 876 877 public void txtSenderNameTextChanged() 878 { 879 TextFieldHandler myFieldHandler = new TextFieldHandler(myLetterDoc.xMSF, xTextDocument); 880 myFieldHandler.changeUserFieldContent("Company", txtSenderName.getText()); 881 } 882 883 public void txtSenderStreetTextChanged() 884 { 885 TextFieldHandler myFieldHandler = new TextFieldHandler(myLetterDoc.xMSF, xTextDocument); 886 myFieldHandler.changeUserFieldContent("Street", txtSenderStreet.getText()); 887 } 888 889 public void txtSenderCityTextChanged() 890 { 891 TextFieldHandler myFieldHandler = new TextFieldHandler(myLetterDoc.xMSF, xTextDocument); 892 myFieldHandler.changeUserFieldContent("City", txtSenderCity.getText()); 893 } 894 895 public void txtSenderPostCodeTextChanged() 896 { 897 TextFieldHandler myFieldHandler = new TextFieldHandler(myLetterDoc.xMSF, xTextDocument); 898 myFieldHandler.changeUserFieldContent("PostCode", txtSenderPostCode.getText()); 899 } 900 901 public void txtSenderStateTextChanged() 902 { 903 TextFieldHandler myFieldHandler = new TextFieldHandler(myLetterDoc.xMSF, xTextDocument); 904 myFieldHandler.changeUserFieldContent(PropertyNames.PROPERTY_STATE, txtSenderState.getText()); 905 } 906 907 public void txtTemplateNameTextChanged() 908 { 909 XDocumentPropertiesSupplier xDocPropsSuppl = UnoRuntime.queryInterface(XDocumentPropertiesSupplier.class, xTextDocument); 910 XDocumentProperties xDocProps = xDocPropsSuppl.getDocumentProperties(); 911 String TitleName = txtTemplateName.getText(); 912 xDocProps.setTitle(TitleName); 913 } 914 915 public void chkUseSalutationItemChanged() 916 { 917 XTextComponent xTextComponent = UnoRuntime.queryInterface(XTextComponent.class, lstSalutation); 918 myLetterDoc.switchUserField("Salutation", xTextComponent.getText(), (chkUseSalutation.getState() != 0)); 919 setControlProperty("lstSalutation", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(chkUseSalutation.getState() != 0)); 920 } 921 922 public void lstSalutationItemChanged() 923 { 924 XTextComponent xTextComponent = UnoRuntime.queryInterface(XTextComponent.class, lstSalutation); 925 myLetterDoc.switchUserField("Salutation", xTextComponent.getText(), (chkUseSalutation.getState() != 0)); 926 } 927 928 public void lstSalutationTextChanged() 929 { 930 } 931 932 public void chkUseGreetingItemChanged() 933 { 934 XTextComponent xTextComponent = UnoRuntime.queryInterface(XTextComponent.class, lstGreeting); 935 myLetterDoc.switchUserField("Greeting", xTextComponent.getText(), (chkUseGreeting.getState() != 0)); 936 setControlProperty("lstGreeting", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(chkUseGreeting.getState() != 0)); 937 } 938 939 private void setDefaultForGreetingAndSalutation() 940 { 941 XTextComponent xTextComponent; 942 xTextComponent = UnoRuntime.queryInterface(XTextComponent.class, lstSalutation); 943 if (xTextComponent.getText().equals(PropertyNames.EMPTY_STRING)) 944 { 945 xTextComponent.setText(resources.SalutationLabels[0]); 946 } 947 xTextComponent = UnoRuntime.queryInterface(XTextComponent.class, lstGreeting); 948 if (xTextComponent.getText().equals(PropertyNames.EMPTY_STRING)) 949 { 950 xTextComponent.setText(resources.GreetingLabels[0]); 951 } 952 } 953 954 public void lstGreetingItemChanged() 955 { 956 XTextComponent xTextComponent = UnoRuntime.queryInterface(XTextComponent.class, lstGreeting); 957 myLetterDoc.switchUserField("Greeting", xTextComponent.getText(), (chkUseGreeting.getState() != 0)); 958 } 959 960 public void lstGreetingTextChanged() 961 { 962 } 963 964 // ---------------------------------------------------------------------------- 965 public void chkBusinessPaperItemChanged() 966 { 967 //enable/disable Roadmap Entry Business Paper 968 if (chkBusinessPaper.getState() != 0) 969 { 970 enableBusinessPaper(); 971 } 972 else 973 { 974 disableBusinessPaper(); 975 setPossibleSenderData(true); 976 } 977 } 978 979 private int getOfficeLinguistic() 980 { 981 int oL = 0; 982 boolean found = false; 983 String OfficeLinguistic = Configuration.getOfficeLinguistic(xMSF); 984 for (int i = 0; i < Norms.length; i++) 985 { 986 if (Norms[i].equalsIgnoreCase(OfficeLinguistic)) 987 { 988 oL = i; 989 found = true; 990 break; 991 } 992 } 993 if (!found) 994 { 995 //fall back to English: 996 for (int i = 0; i < Norms.length; i++) 997 { 998 if (Norms[i].equalsIgnoreCase("en-US")) 999 { 1000 oL = i; 1001 found = true; 1002 break; 1003 } 1004 } 1005 } 1006 return oL; 1007 } 1008 1009 private void setPossibleSenderData(boolean bState) 1010 { 1011 setControlProperty("optSenderDefine", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bState)); 1012 setControlProperty("optSenderPlaceholder", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bState)); 1013 setControlProperty("lblSenderAddress", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bState)); 1014 if (!bState) 1015 { 1016 setControlProperty("txtSenderCity", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bState)); 1017 setControlProperty("txtSenderName", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bState)); 1018 setControlProperty("txtSenderPostCode", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bState)); 1019 setControlProperty("txtSenderStreet", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bState)); 1020 setControlProperty("txtSenderCity", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bState)); 1021 setControlProperty("txtSenderState", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bState)); 1022 setControlProperty("lblSenderName", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bState)); 1023 setControlProperty("lblSenderStreet", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bState)); 1024 setControlProperty("lblPostCodeCity", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bState)); 1025 } 1026 } 1027 1028 private void enableSenderReceiver() 1029 { 1030 XInterface BPaperItem = getRoadmapItemByID(RM_SENDERRECEIVER); 1031 Helper.setUnoPropertyValue(BPaperItem, PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 1032 } 1033 1034 private void disableSenderReceiver() 1035 { 1036 XInterface BPaperItem = getRoadmapItemByID(RM_SENDERRECEIVER); 1037 Helper.setUnoPropertyValue(BPaperItem, PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 1038 } 1039 1040 private void enableBusinessPaper() 1041 { 1042 XInterface BPaperItem = getRoadmapItemByID(RM_BUSINESSPAPER); 1043 Helper.setUnoPropertyValue(BPaperItem, PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 1044 chkPaperCompanyLogoItemChanged(); 1045 chkPaperCompanyAddressItemChanged(); 1046 chkPaperFooterItemChanged(); 1047 chkCompanyReceiverItemChanged(); 1048 } 1049 1050 private void disableBusinessPaper() 1051 { 1052 XInterface BPaperItem = getRoadmapItemByID(RM_BUSINESSPAPER); 1053 Helper.setUnoPropertyValue(BPaperItem, PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 1054 if (BusCompanyLogo != null) 1055 { 1056 BusCompanyLogo.removeFrame(); 1057 } 1058 if (BusCompanyAddress != null) 1059 { 1060 BusCompanyAddress.removeFrame(); 1061 } 1062 if (BusFooter != null) 1063 { 1064 BusFooter.removeFrame(); 1065 } 1066 if (BusCompanyAddressReceiver != null) 1067 { 1068 BusCompanyAddressReceiver.removeFrame(); 1069 } 1070 setPossibleAddressReceiver(true); 1071 setPossibleFooter(true); 1072 setPossibleLogo(true); 1073 if (myLetterDoc.hasElement("Sender Address")) 1074 { 1075 myLetterDoc.switchElement("Sender Address", (true)); 1076 } 1077 1078 } 1079 1080 public void lstLetterNormItemChanged() 1081 { 1082 //when the norm changes, the correct template needs to be reloaded 1083 sCurrentNorm = Norms[getCurrentLetter().cp_Norm]; 1084 initializeTemplates(xMSF); 1085 if (optBusinessLetter.getState()) 1086 { 1087 lstBusinessStyleItemChanged(); 1088 } 1089 if (optPrivOfficialLetter.getState()) 1090 { 1091 lstPrivOfficialStyleItemChanged(); 1092 } 1093 if (optPrivateLetter.getState()) 1094 { 1095 lstPrivateStyleItemChanged(); 1096 } 1097 } 1098 1099 public void initializeSalutation() 1100 { 1101 setControlProperty("lstSalutation", PropertyNames.STRING_ITEM_LIST, resources.SalutationLabels); 1102 } 1103 1104 public void initializeGreeting() 1105 { 1106 setControlProperty("lstGreeting", PropertyNames.STRING_ITEM_LIST, resources.GreetingLabels); 1107 } 1108 1109 public void initializeNorms() 1110 { 1111 1112 LocaleCodes lc = new LocaleCodes(xmsf); 1113 String[] allLocales = lc.getIDs(); 1114 Object[] nameList = 1115 { 1116 PropertyNames.EMPTY_STRING, PropertyNames.EMPTY_STRING 1117 }; 1118 String[] nameList1 = 1119 { 1120 PropertyNames.EMPTY_STRING, PropertyNames.EMPTY_STRING 1121 }; 1122 String[] nameList1b = 1123 { 1124 PropertyNames.EMPTY_STRING, PropertyNames.EMPTY_STRING 1125 }; 1126 String[] nameList2 = 1127 { 1128 PropertyNames.EMPTY_STRING, PropertyNames.EMPTY_STRING 1129 }; 1130 Vector allPaths = new Vector(); 1131 String sLetterSubPath = "/wizard/letter/"; 1132 1133 try 1134 { 1135 sTemplatePath = FileAccess.deleteLastSlashfromUrl(sTemplatePath); 1136 String[] PathParts = sTemplatePath.split("/"); 1137 String nuString = PropertyNames.EMPTY_STRING; 1138 String sMainPath; 1139 for (int i = 0; i < (PathParts.length - 1); i++) 1140 { 1141 nuString = nuString + PathParts[i] + "/"; 1142 } 1143 String sLocLetterPath; 1144 sMainPath = nuString; 1145 sMainPath = FileAccess.deleteLastSlashfromUrl(sMainPath); 1146 1147 sLetterPath = sMainPath + sLetterSubPath; 1148 //sLetterLangPackPath = FileAccess.combinePaths(xMSF, sTemplatePath, sLetterSubPath); 1149 1150 XInterface xInterface = (XInterface) xMSF.createInstance("com.sun.star.ucb.SimpleFileAccess"); 1151 com.sun.star.ucb.XSimpleFileAccess xSimpleFileAccess = UnoRuntime.queryInterface(com.sun.star.ucb.XSimpleFileAccess.class, xInterface); 1152 nameList1 = xSimpleFileAccess.getFolderContents(sMainPath, true); 1153 nameList2 = xSimpleFileAccess.getFolderContents(sLetterPath, true); 1154 for (int i = 0; i < nameList1.length; i++) 1155 { 1156 String theFileName = FileAccess.getFilename(nameList1[i]); 1157 if (!theFileName.equalsIgnoreCase("wizard")) 1158 { 1159 sLocLetterPath = FileAccess.deleteLastSlashfromUrl(nameList1[i] + sLetterSubPath); 1160 try 1161 { 1162 nameList1b = xSimpleFileAccess.getFolderContents(sLocLetterPath, true); 1163 for (int j = 0; j < nameList1b.length; j++) 1164 { 1165 String theFileNameb = FileAccess.getFilename(nameList1b[j]); 1166 allPaths.add(nameList1[i] + sLetterSubPath + theFileNameb); 1167 } 1168 } 1169 catch (Exception e) 1170 { 1171 //if the path is invalid an exception is thrown - try the fallback below then 1172 } 1173 } 1174 } 1175 for (int i = 0; i < nameList2.length; i++) 1176 { 1177 boolean found = false; 1178 for (int t = 0; t < nameList1.length; t++) 1179 { 1180 if (FileAccess.getFilename(nameList2[i]).equalsIgnoreCase(FileAccess.getFilename(nameList1[t]))) 1181 { 1182 found = true; 1183 } 1184 } 1185 if (!found) 1186 { 1187 allPaths.add(nameList2[i]); 1188 } 1189 } 1190 nameList = allPaths.toArray(); 1191 1192 1193 } 1194 catch (CommandAbortedException e) 1195 { 1196 // TODO Auto-generated catch block 1197 e.printStackTrace(); 1198 //} catch (NoValidPathException e) { 1199 // TODO Auto-generated catch block 1200 // e.printStackTrace(); 1201 } 1202 catch (Exception e) 1203 { 1204 // TODO Auto-generated catch block 1205 e.printStackTrace(); 1206 } 1207 1208 Vector NormsVector = new Vector(); 1209 Vector NormsPathVector = new Vector(); 1210 Vector LanguageLabelsVector = new Vector(); 1211 String[] LanguageLabels; 1212 1213 boolean found = false; 1214 String cIsoCode = PropertyNames.EMPTY_STRING; 1215 String MSID = PropertyNames.EMPTY_STRING; 1216 int z = 0; 1217 for (int i = 0; i < nameList.length; i++) 1218 { 1219 found = false; 1220 cIsoCode = FileAccess.getFilename((String) nameList[i]); 1221 for (int t = 0; t < allLocales.length; t++) 1222 { 1223 String[] aLang = allLocales[t].split(PropertyNames.SEMI_COLON); 1224 if (cIsoCode.equalsIgnoreCase(aLang[1])) 1225 { 1226 MSID = aLang[2]; 1227 found = true; 1228 t = allLocales.length; 1229 } 1230 } 1231 if (!found) 1232 { 1233 for (int t = 0; t < allLocales.length; t++) 1234 { 1235 String[] aLang = allLocales[t].split(PropertyNames.SEMI_COLON); 1236 if (cIsoCode.equalsIgnoreCase(aLang[1].substring(0, 2))) 1237 { 1238 MSID = aLang[2]; 1239 found = true; 1240 t = allLocales.length; 1241 } 1242 } 1243 } 1244 1245 if (found) 1246 { 1247 NormsVector.add(cIsoCode); 1248 NormsPathVector.add(nameList[i]); 1249 LanguageLabelsVector.add(lc.getLanguageString(MSID)); 1250 /* 1251 Norms[z] = cIsoCode; 1252 NormPaths[z] = (String) nameList[i]; 1253 LanguageLabels[z] = lc.getLanguageString(MSID); 1254 z++; 1255 **/ 1256 } 1257 } 1258 1259 1260 Norms = new String[NormsVector.size()]; 1261 NormsVector.toArray(Norms); 1262 1263 NormPaths = new String[NormsPathVector.size()]; 1264 NormsPathVector.toArray(NormPaths); 1265 1266 LanguageLabels = new String[LanguageLabelsVector.size()]; 1267 LanguageLabelsVector.toArray(LanguageLabels); 1268 1269 //Norms = new String[nameList.length]; 1270 //NormPaths = new String[nameList.length]; 1271 //LanguageLabels = new String[Norms.length]; 1272 1273 setControlProperty("lstLetterNorm", PropertyNames.STRING_ITEM_LIST, LanguageLabels); 1274 } 1275 1276 private CGLetter getCurrentLetter() 1277 { 1278 switch (myConfig.cp_LetterType) 1279 { 1280 case 0: 1281 return myConfig.cp_BusinessLetter; 1282 case 1: 1283 return myConfig.cp_PrivateOfficialLetter; 1284 case 2: 1285 return myConfig.cp_PrivateLetter; 1286 default: 1287 return null; 1288 } 1289 } 1290 1291 private void initializePaths() 1292 { 1293 try 1294 { 1295 sTemplatePath = FileAccess.getOfficePath(xMSF, "Template", "share", "/wizard"); 1296 sUserTemplatePath = FileAccess.getOfficePath(xMSF, "Template", "user", PropertyNames.EMPTY_STRING); 1297 sBitmapPath = FileAccess.combinePaths(xMSF, sTemplatePath, "/../wizard/bitmap"); 1298 } 1299 catch (NoValidPathException e) 1300 { 1301 e.printStackTrace(); 1302 } 1303 } 1304 1305 public boolean initializeTemplates(XMultiServiceFactory xMSF) 1306 { 1307 sCurrentNorm = Norms[getCurrentLetter().cp_Norm]; 1308 //creation of the language independent path: 1309 String sLetterPath = NormPaths[getCurrentLetter().cp_Norm]; 1310 1311 // try 1312 // { 1313 BusinessFiles = FileAccess.getFolderTitles(xMSF, "bus", sLetterPath); 1314 OfficialFiles = FileAccess.getFolderTitles(xMSF, "off", sLetterPath); 1315 PrivateFiles = FileAccess.getFolderTitles(xMSF, "pri", sLetterPath); 1316 1317 setControlProperty("lstBusinessStyle", PropertyNames.STRING_ITEM_LIST, BusinessFiles[0]); 1318 setControlProperty("lstPrivOfficialStyle", PropertyNames.STRING_ITEM_LIST, OfficialFiles[0]); 1319 setControlProperty("lstPrivateStyle", PropertyNames.STRING_ITEM_LIST, PrivateFiles[0]); 1320 1321 setControlProperty("lstBusinessStyle", PropertyNames.SELECTED_ITEMS, new short[] 1322 { 1323 0 1324 }); 1325 setControlProperty("lstPrivOfficialStyle", PropertyNames.SELECTED_ITEMS, new short[] 1326 { 1327 0 1328 }); 1329 setControlProperty("lstPrivateStyle", PropertyNames.SELECTED_ITEMS, new short[] 1330 { 1331 0 1332 }); 1333 // } 1334 // catch (com.sun.star.wizards.common.NoValidPathException e) 1335 // { 1336 // return false; 1337 // } 1338 return true; 1339 } 1340 1341 public void initializeElements() 1342 { 1343 setControlProperty("chkUseLogo", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(myLetterDoc.hasElement("Company Logo"))); 1344 setControlProperty("chkUseBendMarks", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(myLetterDoc.hasElement("Bend Marks"))); 1345 setControlProperty("chkUseAddressReceiver", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(myLetterDoc.hasElement("Sender Address Repeated"))); 1346 setControlProperty("chkUseSubject", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(myLetterDoc.hasElement("Subject Line"))); 1347 setControlProperty("chkUseSigns", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(myLetterDoc.hasElement("Letter Signs"))); 1348 myLetterDoc.updateDateFields(); 1349 } 1350 1351 public void setConfiguration() 1352 { 1353 //set correct Configuration tree: 1354 1355 if (optBusinessLetter.getState()) 1356 { 1357 optBusinessLetterItemChanged(); 1358 } 1359 if (optPrivOfficialLetter.getState()) 1360 { 1361 optPrivOfficialLetterItemChanged(); 1362 } 1363 if (optPrivateLetter.getState()) 1364 { 1365 optPrivateLetterItemChanged(); 1366 } 1367 } 1368 1369 public void setElements(boolean privLetter) 1370 { 1371 //UI relevant: 1372 if (optSenderDefine.getState()) 1373 { 1374 optSenderDefineItemChanged(); 1375 } 1376 if (optSenderPlaceholder.getState()) 1377 { 1378 optSenderPlaceholderItemChanged(); 1379 } 1380 chkUseSignsItemChanged(); 1381 chkUseSubjectItemChanged(); 1382 chkUseSalutationItemChanged(); 1383 chkUseGreetingItemChanged(); 1384 chkUseBendMarksItemChanged(); 1385 chkUseAddressReceiverItemChanged(); 1386 txtTemplateNameTextChanged(); 1387 1388 //not UI relevant: 1389 if (optReceiverDatabase.getState() && !privLetter) 1390 { 1391 optReceiverDatabaseItemChanged(); 1392 } 1393 if (optReceiverPlaceholder.getState() && !privLetter) 1394 { 1395 optReceiverPlaceholderItemChanged(); 1396 } 1397 if (optCreateLetter.getState()) 1398 { 1399 optCreateLetterItemChanged(); 1400 } 1401 if (optMakeChanges.getState()) 1402 { 1403 optMakeChangesItemChanged(); 1404 } 1405 } 1406 1407 public void insertRoadmap() 1408 { 1409 addRoadmap(); 1410 int i = 0; 1411 i = insertRoadmapItem(0, true, resources.RoadmapLabels[RM_TYPESTYLE], RM_TYPESTYLE); 1412 i = insertRoadmapItem(i, false, resources.RoadmapLabels[RM_BUSINESSPAPER], RM_BUSINESSPAPER); 1413 i = insertRoadmapItem(i, true, resources.RoadmapLabels[RM_ELEMENTS], RM_ELEMENTS); 1414 i = insertRoadmapItem(i, true, resources.RoadmapLabels[RM_SENDERRECEIVER], RM_SENDERRECEIVER); 1415 i = insertRoadmapItem(i, false, resources.RoadmapLabels[RM_FOOTER], RM_FOOTER); 1416 i = insertRoadmapItem(i, true, resources.RoadmapLabels[RM_FINALSETTINGS], RM_FINALSETTINGS); 1417 setRoadmapInteractive(true); 1418 setRoadmapComplete(true); 1419 setCurrentRoadmapItemID((short) 1); 1420 } 1421 1422 private class myPathSelectionListener implements XPathSelectionListener 1423 { 1424 1425 public void validatePath() 1426 { 1427 if (myPathSelection.usedPathPicker) 1428 { 1429 filenameChanged = true; 1430 } 1431 myPathSelection.usedPathPicker = false; 1432 } 1433 } 1434 1435 public void insertPathSelectionControl() 1436 { 1437 myPathSelection = new PathSelection(xMSF, this, PathSelection.TransferMode.SAVE, PathSelection.DialogTypes.FILE); 1438 myPathSelection.insert(6, 97, 70, 205, (short) 45, resources.reslblTemplatePath_value, true, HelpIds.getHelpIdString(HID + 47), HelpIds.getHelpIdString(HID + 48)); 1439 myPathSelection.sDefaultDirectory = sUserTemplatePath; 1440 myPathSelection.sDefaultName = "myLetterTemplate.ott"; 1441 myPathSelection.sDefaultFilter = "writer8_template"; 1442 myPathSelection.addSelectionListener(new myPathSelectionListener()); 1443 } 1444 1445 public void initConfiguration() 1446 { 1447 try 1448 { 1449 myConfig = new CGLetterWizard(); 1450 Object root = Configuration.getConfigurationRoot(xMSF, "/org.openoffice.Office.Writer/Wizards/Letter", false); 1451 myConfig.readConfiguration(root, "cp_"); 1452 mainDA.add(RadioDataAware.attachRadioButtons(myConfig, "cp_LetterType", new Object[] 1453 { 1454 optBusinessLetter, optPrivOfficialLetter, optPrivateLetter 1455 }, null, true)); 1456 mainDA.add(UnoDataAware.attachListBox(myConfig.cp_BusinessLetter, "cp_Style", lstBusinessStyle, null, true)); 1457 mainDA.add(UnoDataAware.attachListBox(myConfig.cp_PrivateOfficialLetter, "cp_Style", lstPrivOfficialStyle, null, true)); 1458 mainDA.add(UnoDataAware.attachListBox(myConfig.cp_PrivateLetter, "cp_Style", lstPrivateStyle, null, true)); 1459 mainDA.add(UnoDataAware.attachCheckBox(myConfig.cp_BusinessLetter, "cp_BusinessPaper", chkBusinessPaper, null, true)); 1460 1461 CGLetter cgl = myConfig.cp_BusinessLetter; 1462 1463 CGPaperElementLocation cgpl = myConfig.cp_BusinessLetter.cp_CompanyLogo; 1464 CGPaperElementLocation cgpa = myConfig.cp_BusinessLetter.cp_CompanyAddress; 1465 1466 businessDA.add(UnoDataAware.attachCheckBox(cgpl, "cp_Display", chkPaperCompanyLogo, null, true)); 1467 businessDA.add(UnoDataAware.attachNumericControl(cgpl, "cp_Width", numLogoWidth, null, true)); 1468 businessDA.add(UnoDataAware.attachNumericControl(cgpl, "cp_Height", numLogoHeight, null, true)); 1469 businessDA.add(UnoDataAware.attachNumericControl(cgpl, "cp_X", numLogoX, null, true)); 1470 businessDA.add(UnoDataAware.attachNumericControl(cgpl, "cp_Y", numLogoY, null, true)); 1471 businessDA.add(UnoDataAware.attachCheckBox(cgpa, "cp_Display", chkPaperCompanyAddress, null, true)); 1472 businessDA.add(UnoDataAware.attachNumericControl(cgpa, "cp_Width", numAddressWidth, null, true)); 1473 businessDA.add(UnoDataAware.attachNumericControl(cgpa, "cp_Height", numAddressHeight, null, true)); 1474 businessDA.add(UnoDataAware.attachNumericControl(cgpa, "cp_X", numAddressX, null, true)); 1475 businessDA.add(UnoDataAware.attachNumericControl(cgpa, "cp_Y", numAddressY, null, true)); 1476 1477 businessDA.add(UnoDataAware.attachCheckBox(cgl, "cp_PaperCompanyAddressReceiverField", chkCompanyReceiver, null, true)); 1478 businessDA.add(UnoDataAware.attachCheckBox(cgl, "cp_PaperFooter", chkPaperFooter, null, true)); 1479 businessDA.add(UnoDataAware.attachNumericControl(cgl, "cp_PaperFooterHeight", numFooterHeight, null, true)); 1480 1481 letterDA.add(UnoDataAware.attachListBox(cgl, "cp_Norm", lstLetterNorm, null, true)); 1482 letterDA.add(UnoDataAware.attachCheckBox(cgl, "cp_PrintCompanyLogo", chkUseLogo, null, true)); 1483 letterDA.add(UnoDataAware.attachCheckBox(cgl, "cp_PrintCompanyAddressReceiverField", chkUseAddressReceiver, null, true)); 1484 letterDA.add(UnoDataAware.attachCheckBox(cgl, "cp_PrintLetterSigns", chkUseSigns, null, true)); 1485 letterDA.add(UnoDataAware.attachCheckBox(cgl, "cp_PrintSubjectLine", chkUseSubject, null, true)); 1486 letterDA.add(UnoDataAware.attachCheckBox(cgl, "cp_PrintSalutation", chkUseSalutation, null, true)); 1487 letterDA.add(UnoDataAware.attachCheckBox(cgl, "cp_PrintBendMarks", chkUseBendMarks, null, true)); 1488 letterDA.add(UnoDataAware.attachCheckBox(cgl, "cp_PrintGreeting", chkUseGreeting, null, true)); 1489 letterDA.add(UnoDataAware.attachCheckBox(cgl, "cp_PrintFooter", chkUseFooter, null, true)); 1490 letterDA.add(UnoDataAware.attachEditControl(cgl, "cp_Salutation", lstSalutation, null, true)); 1491 letterDA.add(UnoDataAware.attachEditControl(cgl, "cp_Greeting", lstGreeting, null, true)); 1492 letterDA.add(RadioDataAware.attachRadioButtons(cgl, "cp_SenderAddressType", new Object[] 1493 { 1494 optSenderDefine, optSenderPlaceholder 1495 }, null, true)); 1496 letterDA.add(UnoDataAware.attachEditControl(cgl, "cp_SenderCompanyName", txtSenderName, null, true)); 1497 letterDA.add(UnoDataAware.attachEditControl(cgl, "cp_SenderStreet", txtSenderStreet, null, true)); 1498 letterDA.add(UnoDataAware.attachEditControl(cgl, "cp_SenderPostCode", txtSenderPostCode, null, true)); 1499 letterDA.add(UnoDataAware.attachEditControl(cgl, "cp_SenderState", txtSenderState, null, true)); 1500 letterDA.add(UnoDataAware.attachEditControl(cgl, "cp_SenderCity", txtSenderCity, null, true)); 1501 letterDA.add(RadioDataAware.attachRadioButtons(cgl, "cp_ReceiverAddressType", new Object[] 1502 { 1503 optReceiverDatabase, optReceiverPlaceholder 1504 }, null, true)); 1505 letterDA.add(UnoDataAware.attachEditControl(cgl, "cp_Footer", txtFooter, null, true)); 1506 letterDA.add(UnoDataAware.attachCheckBox(cgl, "cp_FooterOnlySecondPage", chkFooterNextPages, null, true)); 1507 letterDA.add(UnoDataAware.attachCheckBox(cgl, "cp_FooterPageNumbers", chkFooterPageNumbers, null, true)); 1508 letterDA.add(RadioDataAware.attachRadioButtons(cgl, "cp_CreationType", new Object[] 1509 { 1510 optCreateLetter, optMakeChanges 1511 }, null, true)); 1512 letterDA.add(UnoDataAware.attachEditControl(cgl, "cp_TemplateName", txtTemplateName, null, true)); 1513 letterDA.add(UnoDataAware.attachEditControl(cgl, "cp_TemplatePath", myPathSelection.xSaveTextBox, null, true)); 1514 1515 } 1516 catch (Exception exception) 1517 { 1518 exception.printStackTrace(); 1519 } 1520 1521 } 1522 1523 private void updateUI() 1524 { 1525 UnoDataAware.updateUI(mainDA); 1526 UnoDataAware.updateUI(letterDA); 1527 UnoDataAware.updateUI(businessDA); 1528 } 1529 1530 public void saveConfiguration() 1531 { 1532 try 1533 { 1534 Object root = Configuration.getConfigurationRoot(xMSF, "/org.openoffice.Office.Writer/Wizards/Letter", true); 1535 myConfig.writeConfiguration(root, "cp_"); 1536 Configuration.commit(root); 1537 } 1538 catch (Exception e) 1539 { 1540 e.printStackTrace(); 1541 } 1542 } 1543 } 1544