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