1*a1b4a26bSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*a1b4a26bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*a1b4a26bSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*a1b4a26bSAndrew Rist * distributed with this work for additional information 6*a1b4a26bSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*a1b4a26bSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*a1b4a26bSAndrew Rist * "License"); you may not use this file except in compliance 9*a1b4a26bSAndrew Rist * with the License. You may obtain a copy of the License at 10*a1b4a26bSAndrew Rist * 11*a1b4a26bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*a1b4a26bSAndrew Rist * 13*a1b4a26bSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*a1b4a26bSAndrew Rist * software distributed under the License is distributed on an 15*a1b4a26bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*a1b4a26bSAndrew Rist * KIND, either express or implied. See the License for the 17*a1b4a26bSAndrew Rist * specific language governing permissions and limitations 18*a1b4a26bSAndrew Rist * under the License. 19*a1b4a26bSAndrew Rist * 20*a1b4a26bSAndrew Rist *************************************************************/ 21*a1b4a26bSAndrew Rist 22*a1b4a26bSAndrew Rist 23cdf0e10cSrcweir package com.sun.star.wizards.report; 24cdf0e10cSrcweir //import com.sun.star.ucb.CommandAbortedException; 25cdf0e10cSrcweir import com.sun.star.ucb.XSimpleFileAccess; 26cdf0e10cSrcweir import com.sun.star.uno.Exception; 27cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 28cdf0e10cSrcweir import com.sun.star.uno.XInterface; 29cdf0e10cSrcweir import com.sun.star.wizards.common.Desktop; 30cdf0e10cSrcweir import com.sun.star.wizards.common.*; 31cdf0e10cSrcweir import com.sun.star.wizards.ui.*; 32cdf0e10cSrcweir import com.sun.star.awt.VclWindowPeerAttribute; 33cdf0e10cSrcweir import com.sun.star.awt.XTextComponent; 34cdf0e10cSrcweir //import com.sun.star.container.XHierarchicalNameAccess; 35cdf0e10cSrcweir //import com.sun.star.container.XNameAccess; 36cdf0e10cSrcweir //import com.sun.star.lang.EventObject; 37cdf0e10cSrcweir //import com.sun.star.lang.XMultiServiceFactory; 38cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 39cdf0e10cSrcweir import com.sun.star.wizards.db.RecordParser; 40cdf0e10cSrcweir //import com.sun.star.wizards.document.OfficeDocument; 41cdf0e10cSrcweir public class ReportFinalizer 42cdf0e10cSrcweir { 43cdf0e10cSrcweir 44cdf0e10cSrcweir WizardDialog CurUnoDialog; 45cdf0e10cSrcweir XTextComponent xTitleTextBox; 46cdf0e10cSrcweir XTextComponent[] xSaveTextBox = new XTextComponent[2]; 47cdf0e10cSrcweir Object chkTemplate; 48cdf0e10cSrcweir String CHANGEREPORTTITLE_FUNCNAME = "changeReportTitle"; 49cdf0e10cSrcweir String TOGGLESUBTEMPLATECONTROLS_FUNCNAME = "toggleSubTemplateControls"; 50cdf0e10cSrcweir // String slblHowProceed; 51cdf0e10cSrcweir // String slblChooseReportKind; 52cdf0e10cSrcweir String TemplatePath; 53cdf0e10cSrcweir String StoreName; 54cdf0e10cSrcweir boolean bfinalaskbeforeOverwrite; 55cdf0e10cSrcweir String DefaultName; 56cdf0e10cSrcweir String OldDefaultName; 57cdf0e10cSrcweir // ReportTextDocument CurReportDocument; 58cdf0e10cSrcweir IReportDocument CurReportDocument; 59cdf0e10cSrcweir // Desktop.OfficePathRetriever curofficepath; 60cdf0e10cSrcweir // short curtabindex; 61cdf0e10cSrcweir // String sMsgReportDocumentNameDuplicate; 62cdf0e10cSrcweir public static final int SOCREATEDOCUMENT = 1; 63cdf0e10cSrcweir public static final int SOCREATETEMPLATE = 2; 64cdf0e10cSrcweir public static final int SOUSETEMPLATE = 3; 65cdf0e10cSrcweir private XMultiServiceFactory m_xMSF; 66cdf0e10cSrcweir // public Finalizer(ReportTextDocument _CurReportDocument, WizardDialog _CurUnoDialog) { ReportFinalizer(XMultiServiceFactory _xMSF, IReportDocument _CurReportDocument, WizardDialog _CurUnoDialog)67cdf0e10cSrcweir public ReportFinalizer(XMultiServiceFactory _xMSF, IReportDocument _CurReportDocument, WizardDialog _CurUnoDialog) 68cdf0e10cSrcweir { 69cdf0e10cSrcweir m_xMSF = _xMSF; 70cdf0e10cSrcweir 71cdf0e10cSrcweir this.CurUnoDialog = _CurUnoDialog; 72cdf0e10cSrcweir this.CurReportDocument = _CurReportDocument; 73cdf0e10cSrcweir short curtabindex = (short) (ReportWizard.SOSTOREPAGE * 100); 74cdf0e10cSrcweir Desktop odesktop = new Desktop(); 75cdf0e10cSrcweir // curofficepath = odesktop.new OfficePathRetriever(m_xMSF); 76cdf0e10cSrcweir 77cdf0e10cSrcweir String sSaveAsTemplate = CurUnoDialog.m_oResource.getResText(UIConsts.RID_REPORT + 40); 78cdf0e10cSrcweir String sUseTemplate = CurUnoDialog.m_oResource.getResText(UIConsts.RID_REPORT + 41); 79cdf0e10cSrcweir String sEditTemplate = CurUnoDialog.m_oResource.getResText(UIConsts.RID_REPORT + 42); 80cdf0e10cSrcweir String sSaveAsDocument = CurUnoDialog.m_oResource.getResText(UIConsts.RID_REPORT + 43); 81cdf0e10cSrcweir // String sSaveAs = CurUnoDialog.m_oResource.getResText(UIConsts.RID_REPORT + 44); 82cdf0e10cSrcweir String sReportTitle = CurUnoDialog.m_oResource.getResText(UIConsts.RID_REPORT + 33); 83cdf0e10cSrcweir String slblHowProceed = CurUnoDialog.m_oResource.getResText(UIConsts.RID_REPORT + 78); 84cdf0e10cSrcweir String slblChooseReportKind = CurUnoDialog.m_oResource.getResText(UIConsts.RID_REPORT + 79); 85cdf0e10cSrcweir 86cdf0e10cSrcweir CurUnoDialog.insertControlModel("com.sun.star.awt.UnoControlFixedTextModel", "lblTitle", 87cdf0e10cSrcweir new String[] 88cdf0e10cSrcweir { 89cdf0e10cSrcweir PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 90cdf0e10cSrcweir }, 91cdf0e10cSrcweir new Object[] 92cdf0e10cSrcweir { 93cdf0e10cSrcweir 8, sReportTitle, 95, 27, new Integer(ReportWizard.SOSTOREPAGE), new Short(curtabindex++), 68 94cdf0e10cSrcweir }); 95cdf0e10cSrcweir 96cdf0e10cSrcweir xTitleTextBox = CurUnoDialog.insertTextField("txtTitle", CHANGEREPORTTITLE_FUNCNAME, this, 97cdf0e10cSrcweir new String[] 98cdf0e10cSrcweir { 99cdf0e10cSrcweir PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 100cdf0e10cSrcweir }, 101cdf0e10cSrcweir new Object[] 102cdf0e10cSrcweir { 103cdf0e10cSrcweir 12, "HID:WIZARDS_HID_DLGREPORT_4_TITLE", 95, 37, new Integer(ReportWizard.SOSTOREPAGE), new Short(curtabindex++), 209 104cdf0e10cSrcweir }); 105cdf0e10cSrcweir 106cdf0e10cSrcweir CurUnoDialog.insertControlModel("com.sun.star.awt.UnoControlFixedTextModel", "lblChooseReportKind", 107cdf0e10cSrcweir new String[] 108cdf0e10cSrcweir { 109cdf0e10cSrcweir PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 110cdf0e10cSrcweir }, 111cdf0e10cSrcweir new Object[] 112cdf0e10cSrcweir { 113cdf0e10cSrcweir 8, slblChooseReportKind, 95, 57, new Integer(ReportWizard.SOSTOREPAGE), new Short(curtabindex++), 209 114cdf0e10cSrcweir }); 115cdf0e10cSrcweir 116cdf0e10cSrcweir CurUnoDialog.insertRadioButton("optCreateDocument", TOGGLESUBTEMPLATECONTROLS_FUNCNAME, this, 117cdf0e10cSrcweir new String[] 118cdf0e10cSrcweir { 119cdf0e10cSrcweir 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 120cdf0e10cSrcweir }, 121cdf0e10cSrcweir new Object[] 122cdf0e10cSrcweir { 123cdf0e10cSrcweir 10, "HID:WIZARDS_HID_DLGREPORT_5_OPTSTATDOCUMENT", sSaveAsDocument, 95, 69, new Short((short) 0), new Integer(ReportWizard.SOSTOREPAGE), new Short(curtabindex++), 138 124cdf0e10cSrcweir }); 125cdf0e10cSrcweir 126cdf0e10cSrcweir CurUnoDialog.insertRadioButton("optCreateReportTemplate", TOGGLESUBTEMPLATECONTROLS_FUNCNAME, this, 127cdf0e10cSrcweir new String[] 128cdf0e10cSrcweir { 129cdf0e10cSrcweir 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 130cdf0e10cSrcweir }, 131cdf0e10cSrcweir new Object[] 132cdf0e10cSrcweir { 133cdf0e10cSrcweir 8, "HID:WIZARDS_HID_DLGREPORT_5_OPTDYNTEMPLATE", sSaveAsTemplate, 95, 81, new Short((short) 1), new Integer(ReportWizard.SOSTOREPAGE), new Short(curtabindex++), 209 134cdf0e10cSrcweir }); 135cdf0e10cSrcweir 136cdf0e10cSrcweir 137cdf0e10cSrcweir CurUnoDialog.insertControlModel("com.sun.star.awt.UnoControlFixedTextModel", "lblHowProceed", 138cdf0e10cSrcweir new String[] 139cdf0e10cSrcweir { 140cdf0e10cSrcweir PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 141cdf0e10cSrcweir }, 142cdf0e10cSrcweir new Object[] 143cdf0e10cSrcweir { 144cdf0e10cSrcweir 8, slblHowProceed, 105, 93, new Integer(ReportWizard.SOSTOREPAGE), new Short(curtabindex++), 209 145cdf0e10cSrcweir }); 146cdf0e10cSrcweir 147cdf0e10cSrcweir 148cdf0e10cSrcweir CurUnoDialog.insertRadioButton("optEditTemplate", TOGGLESUBTEMPLATECONTROLS_FUNCNAME, this, 149cdf0e10cSrcweir new String[] 150cdf0e10cSrcweir { 151cdf0e10cSrcweir PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 152cdf0e10cSrcweir }, 153cdf0e10cSrcweir new Object[] 154cdf0e10cSrcweir { 155cdf0e10cSrcweir 10, "HID:WIZARDS_HID_DLGREPORT_5_OPTEDITTEMPLATE", sEditTemplate, 111, 105, 6, new Short(curtabindex++), 138 156cdf0e10cSrcweir }); 157cdf0e10cSrcweir 158cdf0e10cSrcweir CurUnoDialog.insertRadioButton("optUseTemplate", TOGGLESUBTEMPLATECONTROLS_FUNCNAME, this, 159cdf0e10cSrcweir new String[] 160cdf0e10cSrcweir { 161cdf0e10cSrcweir 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 162cdf0e10cSrcweir }, 163cdf0e10cSrcweir new Object[] 164cdf0e10cSrcweir { 165cdf0e10cSrcweir 10, "HID:WIZARDS_HID_DLGREPORT_5_OPTUSETEMPLATE", sUseTemplate, 111, 115, new Short((short) 1), new Integer(ReportWizard.SOSTOREPAGE), new Short(curtabindex++), 138 166cdf0e10cSrcweir }); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir 170cdf0e10cSrcweir /* 171cdf0e10cSrcweir * This function is called if one of the radio buttons is pressed 172cdf0e10cSrcweir */ toggleSubTemplateControls()173cdf0e10cSrcweir public void toggleSubTemplateControls() 174cdf0e10cSrcweir { 175cdf0e10cSrcweir // String sStorePath = PropertyNames.EMPTY_STRING; 176cdf0e10cSrcweir Short iState = (Short) CurUnoDialog.getControlProperty("optCreateReportTemplate", PropertyNames.PROPERTY_STATE); 177cdf0e10cSrcweir boolean bDoTemplateEnable = iState.shortValue() == 1; 178cdf0e10cSrcweir CurUnoDialog.setControlProperty("optEditTemplate", PropertyNames.PROPERTY_ENABLED, bDoTemplateEnable); 179cdf0e10cSrcweir CurUnoDialog.setControlProperty("optUseTemplate", PropertyNames.PROPERTY_ENABLED, bDoTemplateEnable); 180cdf0e10cSrcweir CurUnoDialog.setControlProperty("lblHowProceed", PropertyNames.PROPERTY_ENABLED, bDoTemplateEnable); 181cdf0e10cSrcweir 182cdf0e10cSrcweir String sTitle = xTitleTextBox.getText(); 183cdf0e10cSrcweir boolean bDoEnable = sTitle.equals(PropertyNames.EMPTY_STRING); 184cdf0e10cSrcweir CurUnoDialog.enableFinishButton(!bDoEnable); 185cdf0e10cSrcweir } 186cdf0e10cSrcweir // private boolean fileexists(XMultiServiceFactory _xMSF, String _spath){ 187cdf0e10cSrcweir // try { 188cdf0e10cSrcweir // XInterface xUcbInterface = (XInterface) _xMSF.createInstance("com.sun.star.ucb.SimpleFileAccess"); 189cdf0e10cSrcweir // XSimpleFileAccess xSimpleFileAccess = (XSimpleFileAccess) com.sun.star.uno.UnoRuntime.queryInterface(XSimpleFileAccess.class, xUcbInterface); 190cdf0e10cSrcweir // return xSimpleFileAccess.exists(_spath); 191cdf0e10cSrcweir // } catch (Exception exception) { 192cdf0e10cSrcweir // exception.printStackTrace(System.out); 193cdf0e10cSrcweir // return false; 194cdf0e10cSrcweir // }} initialize(RecordParser _CurDBMetaData)195cdf0e10cSrcweir public void initialize(RecordParser _CurDBMetaData) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir String FirstCommandName = (_CurDBMetaData.getIncludedCommandNames())[0]; 198cdf0e10cSrcweir DefaultName = Desktop.getUniqueName(_CurDBMetaData.getReportDocuments(), FirstCommandName); 199cdf0e10cSrcweir if (!DefaultName.equals(OldDefaultName)) 200cdf0e10cSrcweir { 201cdf0e10cSrcweir OldDefaultName = DefaultName; 202cdf0e10cSrcweir } 203cdf0e10cSrcweir xTitleTextBox.setText(DefaultName); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir getStoreName()206cdf0e10cSrcweir public String getStoreName() 207cdf0e10cSrcweir { 208cdf0e10cSrcweir if (CurUnoDialog != null) 209cdf0e10cSrcweir { 210cdf0e10cSrcweir String LocStoreName = xTitleTextBox.getText(); 211cdf0e10cSrcweir if (!LocStoreName.equals(PropertyNames.EMPTY_STRING)) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir StoreName = LocStoreName; 214cdf0e10cSrcweir } 215cdf0e10cSrcweir } 216cdf0e10cSrcweir return (StoreName); 217cdf0e10cSrcweir } 218cdf0e10cSrcweir getStorePath()219cdf0e10cSrcweir public String getStorePath() 220cdf0e10cSrcweir { 221cdf0e10cSrcweir try 222cdf0e10cSrcweir { 223cdf0e10cSrcweir StoreName = getStoreName(); 224cdf0e10cSrcweir String StorePath; 225cdf0e10cSrcweir XInterface xInterface = (XInterface) m_xMSF.createInstance("com.sun.star.ucb.SimpleFileAccess"); 226cdf0e10cSrcweir XSimpleFileAccess xSimpleFileAccess = UnoRuntime.queryInterface(XSimpleFileAccess.class, xInterface); 227cdf0e10cSrcweir StorePath = FileAccess.getOfficePath(m_xMSF, "Temp", xSimpleFileAccess) + "/" + StoreName; 228cdf0e10cSrcweir return StorePath; 229cdf0e10cSrcweir } 230cdf0e10cSrcweir catch (Exception e) 231cdf0e10cSrcweir { 232cdf0e10cSrcweir e.printStackTrace(System.out); 233cdf0e10cSrcweir return PropertyNames.EMPTY_STRING; 234cdf0e10cSrcweir } 235cdf0e10cSrcweir } 236cdf0e10cSrcweir changeReportTitle()237cdf0e10cSrcweir public void changeReportTitle() 238cdf0e10cSrcweir { 239cdf0e10cSrcweir final String TitleName = xTitleTextBox.getText(); 240cdf0e10cSrcweir CurReportDocument.liveupdate_updateReportTitle(TitleName); 241cdf0e10cSrcweir CurUnoDialog.enableFinishButton(!PropertyNames.EMPTY_STRING.equals(TitleName)); 242cdf0e10cSrcweir } 243cdf0e10cSrcweir getReportOpenMode()244cdf0e10cSrcweir public int getReportOpenMode() 245cdf0e10cSrcweir { 246cdf0e10cSrcweir int ReportMode = SOCREATEDOCUMENT; 247cdf0e10cSrcweir boolean bcreateTemplate = ((Short) CurUnoDialog.getControlProperty("optCreateReportTemplate", PropertyNames.PROPERTY_STATE)).shortValue() == (short) 1; 248cdf0e10cSrcweir if (bcreateTemplate) 249cdf0e10cSrcweir { 250cdf0e10cSrcweir ReportMode = SOCREATETEMPLATE; 251cdf0e10cSrcweir } 252cdf0e10cSrcweir boolean buseTemplate = ((Short) CurUnoDialog.getControlProperty("optUseTemplate", PropertyNames.PROPERTY_STATE)).shortValue() == (short) 1; 253cdf0e10cSrcweir if (buseTemplate) 254cdf0e10cSrcweir { 255cdf0e10cSrcweir ReportMode = SOUSETEMPLATE; 256cdf0e10cSrcweir } 257cdf0e10cSrcweir boolean buseDocument = ((Short) CurUnoDialog.getControlProperty("optCreateDocument", PropertyNames.PROPERTY_STATE)).shortValue() == (short) 1; 258cdf0e10cSrcweir if (buseDocument) 259cdf0e10cSrcweir { 260cdf0e10cSrcweir ReportMode = SOCREATEDOCUMENT; 261cdf0e10cSrcweir } 262cdf0e10cSrcweir return ReportMode; 263cdf0e10cSrcweir } 264cdf0e10cSrcweir finish()265cdf0e10cSrcweir public boolean finish() 266cdf0e10cSrcweir { 267cdf0e10cSrcweir StoreName = getStoreName(); 268cdf0e10cSrcweir if (!CurReportDocument.getRecordParser().getReportDocuments().hasByHierarchicalName(StoreName)) 269cdf0e10cSrcweir { 270cdf0e10cSrcweir try 271cdf0e10cSrcweir { 272cdf0e10cSrcweir CurReportDocument.store(StoreName, getReportOpenMode()); 273cdf0e10cSrcweir ReportWizard.bCloseDocument = false; 274cdf0e10cSrcweir return true; 275cdf0e10cSrcweir } 276cdf0e10cSrcweir catch(Exception e) 277cdf0e10cSrcweir { 278cdf0e10cSrcweir CurUnoDialog.showMessageBox("ErrorBox", VclWindowPeerAttribute.OK,e.getLocalizedMessage() ); 279cdf0e10cSrcweir CurUnoDialog.enableFinishButton(false); 280cdf0e10cSrcweir return false; 281cdf0e10cSrcweir } 282cdf0e10cSrcweir } 283cdf0e10cSrcweir String sMsgReportDocumentNameDuplicate = CurUnoDialog.m_oResource.getResText(UIConsts.RID_REPORT + 76); 284cdf0e10cSrcweir String sShowMsgReportNameisDuplicate = JavaTools.replaceSubString(sMsgReportDocumentNameDuplicate, StoreName, "%REPORTNAME"); 285cdf0e10cSrcweir /* int iMsg = */ CurUnoDialog.showMessageBox("ErrorBox", VclWindowPeerAttribute.OK, sShowMsgReportNameisDuplicate); 286cdf0e10cSrcweir CurUnoDialog.enableFinishButton(false); 287cdf0e10cSrcweir return false; 288cdf0e10cSrcweir } 289cdf0e10cSrcweir } 290