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.report; 24 25 import com.sun.star.awt.XListBox; 26 // import com.sun.star.awt.XTextComponent; 27 import com.sun.star.lang.EventObject; 28 import com.sun.star.lang.XMultiServiceFactory; 29 import com.sun.star.wizards.common.*; 30 import com.sun.star.wizards.ui.*; 31 32 public class ReportLayouter 33 { 34 35 UnoDialog CurUnoDialog; 36 // static String sOrientationHeader; 37 // static String sOrientVertical; 38 // static String sOrientHorizontal; 39 final int SOTXTTITLE = 28; 40 final int SOCONTENTLST = 29; 41 final static public int SOOPTLANDSCAPE = 30; 42 final static public int SOOPTPORTRAIT = 31; 43 final int SOLAYOUTLST = 32; 44 // static String sReportTitle; 45 // static String slblDataStructure; 46 // static String slblPageLayout; 47 // static String sOrganizeFields; 48 XListBox xContentListBox; 49 XListBox xLayoutListBox; 50 int iOldContentPos; 51 int iOldLayoutPos; 52 // ReportTextDocument CurReportDocument; 53 IReportDocument CurReportDocument; 54 public String[][] LayoutFiles; 55 public String[][] ContentFiles; 56 // private Desktop.OfficePathRetriever curofficepath; 57 Object aOrientationImage; 58 // boolean m_bLandscape = true; 59 private XMultiServiceFactory m_xMSF; 60 ReportLayouter(XMultiServiceFactory _xMSF, IReportDocument _CurReportDocument, UnoDialog _CurUnoDialog)61 public ReportLayouter(XMultiServiceFactory _xMSF, IReportDocument _CurReportDocument, UnoDialog _CurUnoDialog) 62 { 63 m_xMSF = _xMSF; 64 try 65 { 66 short curtabindex = (short) (100 * ReportWizard.SOTEMPLATEPAGE); 67 this.CurUnoDialog = _CurUnoDialog; 68 this.CurReportDocument = _CurReportDocument; 69 //TODO the constructor for the OfficePathRetriever is redundant and should be instantiated elsewhere 70 // Desktop odesktop = new Desktop(); 71 // curofficepath = odesktop.new OfficePathRetriever(m_xMSF); 72 String slblDataStructure = CurUnoDialog.m_oResource.getResText(UIConsts.RID_REPORT + 15); 73 String slblPageLayout = CurUnoDialog.m_oResource.getResText(UIConsts.RID_REPORT + 16); 74 // String sOrganizeFields = CurUnoDialog.m_oResource.getResText(UIConsts.RID_REPORT + 19); 75 76 String sOrientationHeader = CurUnoDialog.m_oResource.getResText(UIConsts.RID_REPORT + 22); 77 String sOrientVertical = CurUnoDialog.m_oResource.getResText(UIConsts.RID_REPORT + 23); 78 String sOrientHorizontal = CurUnoDialog.m_oResource.getResText(UIConsts.RID_REPORT + 24); 79 80 // XInterface xUcbInterface = (XInterface) m_xMSF.createInstance("com.sun.star.ucb.SimpleFileAccess"); 81 // XSimpleFileAccess xSimpleFileAccess = (XSimpleFileAccess) com.sun.star.uno.UnoRuntime.queryInterface(XSimpleFileAccess.class, xUcbInterface); 82 // boolean bcntexists = xSimpleFileAccess.exists(CurReportDocument.getReportPath() + "/cnt-default.ott"); 83 // boolean bstlexists = xSimpleFileAccess.exists(CurReportDocument.getReportPath() + "/stl-default.ott"); 84 // if ((bcntexists == false) || (bstlexists == false)) 85 // throw new NoValidPathException(CurReportDocument.xMSF); 86 87 88 CurUnoDialog.insertControlModel("com.sun.star.awt.UnoControlFixedTextModel", "lblContent", 89 new String[] 90 { 91 PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 92 }, 93 new Object[] 94 { 95 8, slblDataStructure, 95, 27, new Integer(ReportWizard.SOTEMPLATEPAGE), new Short(curtabindex++), 99 96 }); 97 98 short iSelPos = 0; 99 // ContentFiles = FileAccess.getFolderTitles(m_xMSF, "cnt", CurReportDocument.getReportPath()); 100 ContentFiles = CurReportDocument.getDataLayout(); 101 iSelPos = (short) JavaTools.FieldInList(ContentFiles[1], CurReportDocument.getContentPath()); 102 if (iSelPos < 0) 103 { 104 iSelPos = 0; 105 } 106 iOldContentPos = (int) iSelPos; 107 xContentListBox = CurUnoDialog.insertListBox("lstContent", SOCONTENTLST, new ActionListenerImpl(), new ItemListenerImpl(), 108 new String[] 109 { 110 PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.SELECTED_ITEMS, PropertyNames.PROPERTY_STEP, PropertyNames.STRING_ITEM_LIST, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 111 }, 112 new Object[] 113 { 114 108, "HID:WIZARDS_HID_DLGREPORT_4_DATALAYOUT", 95, 37, new short[] 115 { 116 iSelPos 117 }, new Integer(ReportWizard.SOTEMPLATEPAGE), ContentFiles[0], new Short(curtabindex++), 99 118 }); 119 120 CurUnoDialog.insertControlModel("com.sun.star.awt.UnoControlFixedTextModel", "lblLayout", 121 new String[] 122 { 123 PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 124 }, 125 new Object[] 126 { 127 8, slblPageLayout, 205, 27, new Integer(ReportWizard.SOTEMPLATEPAGE), new Short(curtabindex++), 99 128 }); 129 130 short iSelLayoutPos = 0; 131 // LayoutFiles = FileAccess.getFolderTitles(m_xMSF, "stl", CurReportDocument.getReportPath()); 132 LayoutFiles = CurReportDocument.getHeaderLayout(); 133 iSelLayoutPos = (short) JavaTools.FieldInList(LayoutFiles[1], CurReportDocument.getLayoutPath()); 134 if (iSelLayoutPos < 0) 135 { 136 iSelLayoutPos = (short) JavaTools.FieldInList(LayoutFiles[0], CurReportDocument.getLayoutPath()); 137 if (iSelLayoutPos < 0) 138 { 139 iSelLayoutPos = 0; 140 } 141 } 142 xLayoutListBox = CurUnoDialog.insertListBox("lstLayout", SOLAYOUTLST, new ActionListenerImpl(), new ItemListenerImpl(), 143 new String[] 144 { 145 PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.SELECTED_ITEMS, PropertyNames.PROPERTY_STEP, PropertyNames.STRING_ITEM_LIST, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 146 }, 147 new Object[] 148 { 149 108, "HID:WIZARDS_HID_DLGREPORT_4_PAGELAYOUT", 205, 37, new short[] 150 { 151 iSelLayoutPos 152 }, new Integer(ReportWizard.SOTEMPLATEPAGE), LayoutFiles[0], new Short(curtabindex++), 99 153 }); 154 iOldLayoutPos = (int) iSelPos; 155 CurUnoDialog.insertControlModel("com.sun.star.awt.UnoControlFixedTextModel", "lblOrientation", 156 new String[] 157 { 158 PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 159 }, 160 new Object[] 161 { 162 8, sOrientationHeader, 95, 148, new Integer(ReportWizard.SOTEMPLATEPAGE), new Short(curtabindex++), 74 163 }); 164 165 short m_nLandscapeState = CurReportDocument.getDefaultPageOrientation() == SOOPTLANDSCAPE ? (short) 1 : 0; 166 CurUnoDialog.insertRadioButton("optLandscape", SOOPTLANDSCAPE, new ItemListenerImpl(), 167 new String[] 168 { 169 PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STATE, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 170 }, 171 new Object[] 172 { 173 10, "HID:WIZARDS_HID_DLGREPORT_4_LANDSCAPE", sOrientHorizontal, 101, 158, new Short(m_nLandscapeState), new Integer(ReportWizard.SOTEMPLATEPAGE), new Short(curtabindex++), 60 174 }); 175 176 short m_nPortraitState = CurReportDocument.getDefaultPageOrientation() == SOOPTPORTRAIT ? (short) 1 : (short) 0; 177 CurUnoDialog.insertRadioButton("optPortrait", SOOPTPORTRAIT, new ItemListenerImpl(), 178 new String[] 179 { 180 PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STATE, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 181 }, 182 new Object[] 183 { 184 10, "HID:WIZARDS_HID_DLGREPORT_4_PORTRAIT", sOrientVertical, 101, 171, new Short(m_nPortraitState), new Integer(ReportWizard.SOTEMPLATEPAGE), new Short(curtabindex++), 60 185 }); 186 187 aOrientationImage = CurUnoDialog.insertControlModel("com.sun.star.awt.UnoControlImageControlModel", "imgOrientation", 188 new String[] 189 { 190 PropertyNames.PROPERTY_BORDER, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, "ScaleImage", PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_WIDTH 191 }, 192 new Object[] 193 { 194 new Short("0"), 23, 164, 158, Boolean.FALSE, new Integer(ReportWizard.SOTEMPLATEPAGE), 30 195 }); 196 197 String sNote = ReportWizard.getBlindTextNote(CurReportDocument, CurUnoDialog.m_oResource); 198 CurUnoDialog.insertControlModel("com.sun.star.awt.UnoControlFixedTextModel", "lblBlindTextNote_2", 199 new String[] 200 { 201 PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_MULTILINE, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_WIDTH 202 }, 203 new Object[] 204 { 205 34, sNote, Boolean.TRUE, 205, 148, new Integer(ReportWizard.SOTEMPLATEPAGE), 99 206 }); 207 if (m_nLandscapeState == 1) 208 { 209 CurUnoDialog.getPeerConfiguration().setImageUrl(aOrientationImage, 1002, 1003); 210 } 211 else 212 { 213 CurUnoDialog.getPeerConfiguration().setImageUrl(aOrientationImage, 1000, 1001); 214 } 215 } 216 catch (Exception exception) 217 { 218 exception.printStackTrace(System.out); 219 } 220 } 221 initialize(String _defaultTemplatePath)222 public void initialize(String _defaultTemplatePath) 223 { 224 // CurReportDocument.getDoc().xTextDocument.lockControllers(); 225 CurReportDocument.layout_setupRecordSection(_defaultTemplatePath); 226 if (CurUnoDialog.getControlProperty("txtTitle", "Text").equals(PropertyNames.EMPTY_STRING)) 227 { 228 String[] sCommandNames = CurReportDocument.getRecordParser().getIncludedCommandNames(); 229 CurUnoDialog.setControlProperty("txtTitle", "Text", sCommandNames[0]); 230 } 231 // CurReportDocument.getDoc().oViewHandler.selectFirstPage(CurReportDocument.getDoc().oTextTableHandler); 232 CurReportDocument.layout_selectFirstPage(); 233 CurUnoDialog.setFocus("lblContent"); 234 // CurReportDocument.getDoc().unlockallControllers(); 235 } 236 237 class ItemListenerImpl implements com.sun.star.awt.XItemListener 238 { 239 itemStateChanged(com.sun.star.awt.ItemEvent EventObject)240 public void itemStateChanged(com.sun.star.awt.ItemEvent EventObject) 241 { 242 try 243 { 244 int iPos; 245 Helper.setUnoPropertyValue(CurUnoDialog.xDialogModel, PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 246 // LLA: should we lock controllers here? 247 // CurReportDocument.getDoc().xTextDocument.lockControllers(); 248 int iKey = CurUnoDialog.getControlKey(EventObject.Source, CurUnoDialog.ControlList); 249 switch (iKey) 250 { 251 case SOCONTENTLST: 252 iPos = xContentListBox.getSelectedItemPos(); 253 if (iPos != iOldContentPos) 254 { 255 iOldContentPos = iPos; 256 CurReportDocument.liveupdate_changeContentTemplate(ContentFiles[1][iPos]); 257 } 258 break; 259 260 case SOLAYOUTLST: 261 iPos = xLayoutListBox.getSelectedItemPos(); 262 if (iPos != iOldLayoutPos) 263 { 264 iOldLayoutPos = iPos; 265 CurReportDocument.liveupdate_changeLayoutTemplate(LayoutFiles[1][iPos]/*, Desktop.getBitmapPath(m_xMSF)*/); 266 } 267 break; 268 269 case SOOPTLANDSCAPE: 270 // CurReportDocument.getDoc().changePageOrientation(true); 271 try 272 { 273 CurReportDocument.setPageOrientation(SOOPTLANDSCAPE); 274 } 275 catch (com.sun.star.lang.IllegalArgumentException e) 276 { 277 } 278 Helper.setUnoPropertyValue(aOrientationImage, PropertyNames.PROPERTY_IMAGEURL, CurUnoDialog.getWizardImageUrl(1002, 1003)); 279 280 break; 281 282 case SOOPTPORTRAIT: 283 // CurReportDocument.getDoc().changePageOrientation( false); 284 try 285 { 286 CurReportDocument.setPageOrientation(SOOPTPORTRAIT); 287 } 288 catch (com.sun.star.lang.IllegalArgumentException e) 289 { 290 } 291 292 CurUnoDialog.setControlProperty("imgOrientation", PropertyNames.PROPERTY_IMAGEURL, Desktop.getBitmapPath(m_xMSF) + "/portrait.gif"); 293 Helper.setUnoPropertyValue(aOrientationImage, PropertyNames.PROPERTY_IMAGEURL, CurUnoDialog.getWizardImageUrl(1000, 1001)); 294 break; 295 296 default: 297 break; 298 } 299 } 300 catch (RuntimeException e) 301 { 302 e.printStackTrace(); 303 } 304 // CurReportDocument.getDoc().unlockallControllers(); 305 Helper.setUnoPropertyValue(CurUnoDialog.xDialogModel, PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 306 } 307 disposing(EventObject eventObject)308 public void disposing(EventObject eventObject) 309 { 310 } 311 } 312 313 class ActionListenerImpl implements com.sun.star.awt.XActionListener 314 { 315 disposing(EventObject eventObject)316 public void disposing(EventObject eventObject) 317 { 318 } 319 actionPerformed(com.sun.star.awt.ActionEvent actionEvent)320 public void actionPerformed(com.sun.star.awt.ActionEvent actionEvent) 321 { 322 try 323 { 324 Helper.setUnoPropertyValue(CurUnoDialog.xDialogModel, PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 325 // CurReportDocument.getDoc().xTextDocument.lockControllers(); 326 boolean blandscape = (((Short) CurUnoDialog.getControlProperty("optLandscape", PropertyNames.PROPERTY_STATE)).shortValue() == 1); 327 CurReportDocument.setPageOrientation((blandscape) ? SOOPTLANDSCAPE : SOOPTPORTRAIT); 328 } 329 catch (Exception exception) 330 { 331 exception.printStackTrace(System.out); 332 } 333 // CurReportDocument.getDoc().unlockallControllers(); 334 Helper.setUnoPropertyValue(CurUnoDialog.xDialogModel, PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); 335 } 336 } 337 } 338