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.query; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import com.sun.star.awt.XRadioButton; 26cdf0e10cSrcweir import com.sun.star.awt.XTextComponent; 27cdf0e10cSrcweir import com.sun.star.lang.IllegalArgumentException; 28cdf0e10cSrcweir import com.sun.star.sdb.CommandType; 29cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 30cdf0e10cSrcweir import com.sun.star.wizards.common.HelpIds; 31cdf0e10cSrcweir import com.sun.star.wizards.common.Helper; 32cdf0e10cSrcweir import com.sun.star.wizards.common.PropertyNames; 33cdf0e10cSrcweir import com.sun.star.wizards.ui.UIConsts; 34cdf0e10cSrcweir import com.sun.star.wizards.ui.UnoDialog; 35cdf0e10cSrcweir import java.util.logging.Level; 36cdf0e10cSrcweir import java.util.logging.Logger; 37cdf0e10cSrcweir 38cdf0e10cSrcweir public class Finalizer 39cdf0e10cSrcweir { 40cdf0e10cSrcweir private QueryWizard m_queryWizard; 41cdf0e10cSrcweir private String resQuery; 42cdf0e10cSrcweir private XTextComponent m_aTxtTitle; 43cdf0e10cSrcweir private XRadioButton xRadioDisplayQuery; 44cdf0e10cSrcweir private QuerySummary CurDBMetaData; 45cdf0e10cSrcweir Finalizer( QueryWizard i_queryWizard, QuerySummary _CurDBMetaData )46cdf0e10cSrcweir public Finalizer( QueryWizard i_queryWizard, QuerySummary _CurDBMetaData ) 47cdf0e10cSrcweir { 48cdf0e10cSrcweir short curtabindex = (short) (100 * QueryWizard.SOSUMMARY_PAGE); 49cdf0e10cSrcweir String reslblQueryTitle; 50cdf0e10cSrcweir String resoptDisplayQuery; 51cdf0e10cSrcweir String resoptModifyQuery; 52cdf0e10cSrcweir String resflnSummary; 53cdf0e10cSrcweir String reslblHowGoOn; 54cdf0e10cSrcweir this.m_queryWizard = i_queryWizard; 55cdf0e10cSrcweir this.CurDBMetaData = _CurDBMetaData; 56cdf0e10cSrcweir reslblQueryTitle = m_queryWizard.m_oResource.getResText(UIConsts.RID_QUERY + 5); 57cdf0e10cSrcweir resoptDisplayQuery = m_queryWizard.m_oResource.getResText(UIConsts.RID_QUERY + 6); 58cdf0e10cSrcweir resoptModifyQuery = m_queryWizard.m_oResource.getResText(UIConsts.RID_QUERY + 7); 59cdf0e10cSrcweir resflnSummary = m_queryWizard.m_oResource.getResText(UIConsts.RID_QUERY + 87); 60cdf0e10cSrcweir reslblHowGoOn = m_queryWizard.m_oResource.getResText(UIConsts.RID_QUERY + 8); 61cdf0e10cSrcweir resQuery = m_queryWizard.m_oResource.getResText(UIConsts.RID_QUERY + 1); 62cdf0e10cSrcweir int curHelpIndex = 40955; 63cdf0e10cSrcweir 64cdf0e10cSrcweir m_queryWizard.insertLabel("lblQueryTitle", new String[] 65cdf0e10cSrcweir { 66cdf0e10cSrcweir PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 67cdf0e10cSrcweir }, 68cdf0e10cSrcweir new Object[] 69cdf0e10cSrcweir { 70cdf0e10cSrcweir 8, reslblQueryTitle, 95, 27, new Integer(QueryWizard.SOSUMMARY_PAGE), new Short(curtabindex++), 52 71cdf0e10cSrcweir }); 72cdf0e10cSrcweir m_aTxtTitle = m_queryWizard.insertTextField("txtQueryTitle", "changeTitle", this, new String[] 73cdf0e10cSrcweir { 74cdf0e10cSrcweir PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 75cdf0e10cSrcweir }, 76cdf0e10cSrcweir new Object[] 77cdf0e10cSrcweir { 78cdf0e10cSrcweir 12, HelpIds.getHelpIdString(curHelpIndex++), 95, 37, new Integer(QueryWizard.SOSUMMARY_PAGE), new Short(curtabindex++), 90 79cdf0e10cSrcweir }); 80cdf0e10cSrcweir m_queryWizard.insertLabel("lblHowGoOn", new String[] 81cdf0e10cSrcweir { 82cdf0e10cSrcweir PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_MULTILINE, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 83cdf0e10cSrcweir }, 84cdf0e10cSrcweir new Object[] 85cdf0e10cSrcweir { 86cdf0e10cSrcweir 16, reslblHowGoOn, Boolean.TRUE, 192, 27, new Integer(QueryWizard.SOSUMMARY_PAGE), new Short(curtabindex++), 112 87cdf0e10cSrcweir }); 88cdf0e10cSrcweir this.xRadioDisplayQuery = m_queryWizard.insertRadioButton("optDisplayQuery", 89cdf0e10cSrcweir new String[] 90cdf0e10cSrcweir { 91cdf0e10cSrcweir 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 92cdf0e10cSrcweir }, 93cdf0e10cSrcweir new Object[] 94cdf0e10cSrcweir { 95cdf0e10cSrcweir 9, HelpIds.getHelpIdString(curHelpIndex++), resoptDisplayQuery, 192, 46, new Short((short) 1), new Integer(QueryWizard.SOSUMMARY_PAGE), new Short(curtabindex++), 118 96cdf0e10cSrcweir }); 97cdf0e10cSrcweir 98cdf0e10cSrcweir m_queryWizard.insertRadioButton("optModifyQuery", 99cdf0e10cSrcweir new String[] 100cdf0e10cSrcweir { 101cdf0e10cSrcweir 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 102cdf0e10cSrcweir }, 103cdf0e10cSrcweir new Object[] 104cdf0e10cSrcweir { 105cdf0e10cSrcweir 10, HelpIds.getHelpIdString(curHelpIndex++), resoptModifyQuery, 192, 56, new Integer(QueryWizard.SOSUMMARY_PAGE), new Short(curtabindex++), 118 106cdf0e10cSrcweir }); 107cdf0e10cSrcweir m_queryWizard.insertFixedLine("flnSummary", 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 10, resflnSummary, 95, 68, 8, new Short(curtabindex++), 209 114cdf0e10cSrcweir }); 115cdf0e10cSrcweir m_queryWizard.insertTextField("txtSummary", 0, null, new String[] 116cdf0e10cSrcweir { 117cdf0e10cSrcweir PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_MULTILINE, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.READ_ONLY, PropertyNames.PROPERTY_STEP, "VScroll", PropertyNames.PROPERTY_WIDTH 118cdf0e10cSrcweir }, 119cdf0e10cSrcweir new Object[] 120cdf0e10cSrcweir { 121cdf0e10cSrcweir 96, HelpIds.getHelpIdString(curHelpIndex++), Boolean.TRUE, 95, 80, Boolean.TRUE, 8, Boolean.TRUE, 209 122cdf0e10cSrcweir }); 123cdf0e10cSrcweir } 124cdf0e10cSrcweir changeTitle()125cdf0e10cSrcweir public void changeTitle() 126cdf0e10cSrcweir { 127cdf0e10cSrcweir final String TitleName = m_aTxtTitle.getText(); 128cdf0e10cSrcweir m_queryWizard.enableFinishButton( TitleName.length() > 0 ); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131cdf0e10cSrcweir /* TODO: The title textbox always has to be updated when 132cdf0e10cSrcweir a new Table has been selected if it is clear that the user has not made any input meanwhile 133cdf0e10cSrcweir */ initialize()134cdf0e10cSrcweir protected String initialize() 135cdf0e10cSrcweir { 136cdf0e10cSrcweir try 137cdf0e10cSrcweir { 138cdf0e10cSrcweir String sCurQueryName = AnyConverter.toString(Helper.getUnoPropertyValue(UnoDialog.getModel(m_aTxtTitle), "Text")); 139cdf0e10cSrcweir if (sCurQueryName != null) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir if (sCurQueryName.equals(PropertyNames.EMPTY_STRING)) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir String[] sCommandNames = CurDBMetaData.getIncludedCommandNames(); 144cdf0e10cSrcweir sCurQueryName = resQuery + "_" + sCommandNames[0]; 145cdf0e10cSrcweir sCurQueryName = CurDBMetaData.suggestName( CommandType.QUERY, sCurQueryName ); 146cdf0e10cSrcweir Helper.setUnoPropertyValue(UnoDialog.getModel(m_aTxtTitle), "Text", sCurQueryName); 147cdf0e10cSrcweir } 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir CurDBMetaData.setSummaryString(); 151cdf0e10cSrcweir m_queryWizard.setControlProperty("txtSummary", "Text", CurDBMetaData.getSummaryString()); 152cdf0e10cSrcweir return sCurQueryName; 153cdf0e10cSrcweir } 154cdf0e10cSrcweir catch (com.sun.star.uno.Exception exception) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir exception.printStackTrace(System.out); 157cdf0e10cSrcweir return PropertyNames.EMPTY_STRING; 158cdf0e10cSrcweir } 159cdf0e10cSrcweir } 160cdf0e10cSrcweir getTitle()161cdf0e10cSrcweir private String getTitle() 162cdf0e10cSrcweir { 163cdf0e10cSrcweir return (String) Helper.getUnoPropertyValue(UnoDialog.getModel(m_aTxtTitle), "Text"); 164cdf0e10cSrcweir } 165cdf0e10cSrcweir finish()166cdf0e10cSrcweir public String finish() 167cdf0e10cSrcweir { 168cdf0e10cSrcweir String queryName = getTitle(); 169cdf0e10cSrcweir if ( CurDBMetaData.getSQLQueryComposer().setQueryCommand( m_queryWizard.xWindow, true, true ) 170cdf0e10cSrcweir && CurDBMetaData.createQuery( CurDBMetaData.getSQLQueryComposer(), queryName ) 171cdf0e10cSrcweir ) 172cdf0e10cSrcweir return queryName; 173cdf0e10cSrcweir 174cdf0e10cSrcweir return PropertyNames.EMPTY_STRING; 175cdf0e10cSrcweir } 176cdf0e10cSrcweir displayQueryDesign()177cdf0e10cSrcweir public final boolean displayQueryDesign() 178cdf0e10cSrcweir { 179cdf0e10cSrcweir try 180cdf0e10cSrcweir { 181cdf0e10cSrcweir final short state = AnyConverter.toShort( Helper.getUnoPropertyValue( UnoDialog.getModel( xRadioDisplayQuery ), PropertyNames.PROPERTY_STATE ) ); 182cdf0e10cSrcweir final boolean viewMode = state == (short)1; 183cdf0e10cSrcweir return !viewMode; 184cdf0e10cSrcweir } 185cdf0e10cSrcweir catch ( IllegalArgumentException ex ) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir Logger.getLogger( Finalizer.class.getName() ).log( Level.SEVERE, null, ex ); 188cdf0e10cSrcweir } 189cdf0e10cSrcweir return false; 190cdf0e10cSrcweir } 191cdf0e10cSrcweir } 192