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