1a1b4a26bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3a1b4a26bSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4a1b4a26bSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5a1b4a26bSAndrew Rist  * distributed with this work for additional information
6a1b4a26bSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7a1b4a26bSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8a1b4a26bSAndrew Rist  * "License"); you may not use this file except in compliance
9a1b4a26bSAndrew Rist  * with the License.  You may obtain a copy of the License at
10a1b4a26bSAndrew Rist  *
11a1b4a26bSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12a1b4a26bSAndrew Rist  *
13a1b4a26bSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14a1b4a26bSAndrew Rist  * software distributed under the License is distributed on an
15a1b4a26bSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16a1b4a26bSAndrew Rist  * KIND, either express or implied.  See the License for the
17a1b4a26bSAndrew Rist  * specific language governing permissions and limitations
18a1b4a26bSAndrew Rist  * under the License.
19a1b4a26bSAndrew Rist  *
20a1b4a26bSAndrew Rist  *************************************************************/
21a1b4a26bSAndrew Rist 
22a1b4a26bSAndrew Rist 
23cdf0e10cSrcweir package com.sun.star.wizards.ui;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir // import java.util.Vector;
26cdf0e10cSrcweir import com.sun.star.awt.TextEvent;
27cdf0e10cSrcweir import com.sun.star.awt.VclWindowPeerAttribute;
28cdf0e10cSrcweir import com.sun.star.awt.XControl;
29cdf0e10cSrcweir import com.sun.star.awt.XListBox;
30cdf0e10cSrcweir import com.sun.star.awt.XRadioButton;
31cdf0e10cSrcweir import com.sun.star.beans.PropertyAttribute;
32cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
33cdf0e10cSrcweir import com.sun.star.beans.XPropertyContainer;
34cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
35cdf0e10cSrcweir import com.sun.star.lang.EventObject;
36cdf0e10cSrcweir import com.sun.star.lang.IllegalArgumentException;
37cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
38cdf0e10cSrcweir import com.sun.star.sdb.SQLFilterOperator;
39cdf0e10cSrcweir import com.sun.star.sdbc.DataType;
40cdf0e10cSrcweir import com.sun.star.uno.Any;
41cdf0e10cSrcweir import com.sun.star.uno.AnyConverter;
42cdf0e10cSrcweir import com.sun.star.uno.Exception;
43cdf0e10cSrcweir import com.sun.star.uno.Type;
44cdf0e10cSrcweir import com.sun.star.uno.TypeClass;
45cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
46cdf0e10cSrcweir import com.sun.star.uno.XInterface;
47cdf0e10cSrcweir import com.sun.star.wizards.common.NumberFormatter;
48cdf0e10cSrcweir import com.sun.star.wizards.common.Helper;
49cdf0e10cSrcweir import com.sun.star.wizards.common.HelpIds;
50cdf0e10cSrcweir import com.sun.star.wizards.common.JavaTools;
51cdf0e10cSrcweir import com.sun.star.wizards.common.PropertyNames;
52cdf0e10cSrcweir import com.sun.star.wizards.db.FieldColumn;
53cdf0e10cSrcweir import com.sun.star.wizards.db.QueryMetaData;
54cdf0e10cSrcweir import com.sun.star.wizards.db.SQLQueryComposer;
55cdf0e10cSrcweir import java.util.logging.Level;
56cdf0e10cSrcweir import java.util.logging.Logger;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir public class FilterComponent
59cdf0e10cSrcweir {
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     private Integer IStep;
62cdf0e10cSrcweir     private int RowCount;
63cdf0e10cSrcweir     private static String[] sLogicOperators;
64cdf0e10cSrcweir     private XRadioButton optMatchAny;
65cdf0e10cSrcweir     private String slblFieldNames;
66cdf0e10cSrcweir     private String slblOperators;
67cdf0e10cSrcweir     private String slblValue;
68cdf0e10cSrcweir     WizardDialog CurUnoDialog;
69cdf0e10cSrcweir     private String sIncSuffix;
70cdf0e10cSrcweir     private ControlRow[] oControlRows;
71cdf0e10cSrcweir     private String sDuplicateCondition;
72cdf0e10cSrcweir     final int SOOPTORMODE = 100;
73cdf0e10cSrcweir     final int SOOPTANDMODE = 101;
74cdf0e10cSrcweir     QueryMetaData oQueryMetaData;
75cdf0e10cSrcweir     int iDateTimeFormat;
76cdf0e10cSrcweir     int iDateFormat;
77cdf0e10cSrcweir     int iTimeFormat;
78cdf0e10cSrcweir     private PropertyValue[][] filterconditions;
79cdf0e10cSrcweir     private short curtabindex;
80cdf0e10cSrcweir     XMultiServiceFactory xMSF;
81cdf0e10cSrcweir     final int SO_FIRSTFIELDNAME = 1;
82cdf0e10cSrcweir     final int SO_SECONDFIELDNAME = 2;
83cdf0e10cSrcweir     final int SO_THIRDFIELDNAME = 3;
84cdf0e10cSrcweir     final int SO_FOURTHFIELDNAME = 4;
85cdf0e10cSrcweir     int[] SO_FIELDNAMELIST = new int[]
86cdf0e10cSrcweir     {
87cdf0e10cSrcweir         SO_FIRSTFIELDNAME, SO_SECONDFIELDNAME, SO_THIRDFIELDNAME, SO_FOURTHFIELDNAME
88cdf0e10cSrcweir     };
89cdf0e10cSrcweir     final int SO_FIRSTCONDITION = 5;
90cdf0e10cSrcweir     final int SO_SECONDCONDITION = 6;
91cdf0e10cSrcweir     final int SO_THIRDCONDITION = 7;
92cdf0e10cSrcweir     final int SO_FOURTHCONDITION = 8;
93cdf0e10cSrcweir     int[] SO_CONDITIONLIST = new int[]
94cdf0e10cSrcweir     {
95cdf0e10cSrcweir         SO_FIRSTCONDITION, SO_SECONDCONDITION, SO_THIRDCONDITION, SO_FOURTHCONDITION
96cdf0e10cSrcweir     };
97cdf0e10cSrcweir     final int SO_FIRSTTEXTFIELD = 1;
98cdf0e10cSrcweir     final int SO_SECONDTEXTFIELD = 2;
99cdf0e10cSrcweir     final int SO_THIRDTEXTFIELD = 3;
100cdf0e10cSrcweir     final int SO_FOURTHTEXTFIELD = 4;
101cdf0e10cSrcweir     int[] SO_TEXTFIELDLIST = new int[]
102cdf0e10cSrcweir     {
103cdf0e10cSrcweir         SO_FIRSTTEXTFIELD, SO_SECONDTEXTFIELD, SO_THIRDTEXTFIELD, SO_FOURTHTEXTFIELD
104cdf0e10cSrcweir     };
105cdf0e10cSrcweir     final int SO_FIRSTBOOLFIELDNAME = 256 + 1;
106cdf0e10cSrcweir     final int SO_SECONDBOOLFIELDNAME = 256 + 2;
107cdf0e10cSrcweir     final int SO_THIRDBOOLFIELDNAME = 256 + 3;
108cdf0e10cSrcweir     final int SO_FOURTHBOOLFIELDNAME = 256 + 4;
109cdf0e10cSrcweir     int SO_BOOLEANLIST[] =
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     {
113cdf0e10cSrcweir         SO_FIRSTBOOLFIELDNAME, SO_SECONDBOOLFIELDNAME, SO_THIRDBOOLFIELDNAME, SO_FOURTHBOOLFIELDNAME
114cdf0e10cSrcweir     };
115cdf0e10cSrcweir     final int SO_OPTQUERYMODE = 5;
116cdf0e10cSrcweir     int SOI_MATCHALL = 0;
117cdf0e10cSrcweir     int SOI_MATCHANY = 1;
118cdf0e10cSrcweir     int curHelpID;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir     class ItemListenerImpl implements com.sun.star.awt.XItemListener
121cdf0e10cSrcweir     {
122cdf0e10cSrcweir 
itemStateChanged(com.sun.star.awt.ItemEvent EventObject)123cdf0e10cSrcweir         public void itemStateChanged(com.sun.star.awt.ItemEvent EventObject)
124cdf0e10cSrcweir         {
125cdf0e10cSrcweir             int iKey = CurUnoDialog.getControlKey(EventObject.Source, CurUnoDialog.ControlList);
126cdf0e10cSrcweir             String sControlName = PropertyNames.EMPTY_STRING;
127cdf0e10cSrcweir             switch (iKey)
128cdf0e10cSrcweir             {
129cdf0e10cSrcweir                 case SO_FIRSTFIELDNAME:
130cdf0e10cSrcweir                 case SO_SECONDFIELDNAME:
131cdf0e10cSrcweir                 case SO_THIRDFIELDNAME:
132cdf0e10cSrcweir                 case SO_FOURTHFIELDNAME:
133cdf0e10cSrcweir                     sControlName = getControlName(EventObject.Source);
134cdf0e10cSrcweir                     String sControlNameSuffix = sIncSuffix + "_" + getIndexNumber(sControlName);
135cdf0e10cSrcweir                     XListBox xCurFieldListBox = UnoRuntime.queryInterface(XListBox.class, CurUnoDialog.xDlgContainer.getControl(sControlName));
136cdf0e10cSrcweir                     String CurDisplayFieldName = xCurFieldListBox.getSelectedItem();
137cdf0e10cSrcweir                     FieldColumn CurFieldColumn = new FieldColumn(oQueryMetaData, CurDisplayFieldName);
138cdf0e10cSrcweir 
139cdf0e10cSrcweir                     String sControlNameTextValue = "txtValue" + sControlNameSuffix;
140cdf0e10cSrcweir                     XControl xValueControl = CurUnoDialog.xDlgContainer.getControl(sControlNameTextValue);
141cdf0e10cSrcweir                     XInterface xValueModel = (XInterface) UnoDialog.getModel(xValueControl);
142cdf0e10cSrcweir                     Helper.setUnoPropertyValue(xValueModel, "TreatAsNumber", Boolean.valueOf(CurFieldColumn.isNumberFormat()));
143cdf0e10cSrcweir                     final NumberFormatter aNumberFormatter = oQueryMetaData.getNumberFormatter();
144cdf0e10cSrcweir                     aNumberFormatter.setNumberFormat(xValueModel, CurFieldColumn.getDBFormatKey(), aNumberFormatter);
145cdf0e10cSrcweir 
146cdf0e10cSrcweir                     break;
147cdf0e10cSrcweir                 case SO_FIRSTCONDITION:
148cdf0e10cSrcweir                 case SO_SECONDCONDITION:
149cdf0e10cSrcweir                 case SO_THIRDCONDITION:
150cdf0e10cSrcweir                 case SO_FOURTHCONDITION:
151cdf0e10cSrcweir                     sControlName = getControlName(EventObject.Source);
152cdf0e10cSrcweir                     break;
153cdf0e10cSrcweir                 case SOOPTORMODE:
154cdf0e10cSrcweir                 case SOOPTANDMODE:
155cdf0e10cSrcweir                     return;
156cdf0e10cSrcweir 
157cdf0e10cSrcweir                 case SO_FIRSTBOOLFIELDNAME:
158cdf0e10cSrcweir                 case SO_SECONDBOOLFIELDNAME:
159cdf0e10cSrcweir                 case SO_THIRDBOOLFIELDNAME:
160cdf0e10cSrcweir                 case SO_FOURTHBOOLFIELDNAME:
161cdf0e10cSrcweir                     sControlName = getControlName(EventObject.Source);
162cdf0e10cSrcweir                     break;
163cdf0e10cSrcweir 
164cdf0e10cSrcweir                 default:
165cdf0e10cSrcweir                     break;
166cdf0e10cSrcweir             }
167cdf0e10cSrcweir             togglefollowingControlRow(sControlName);
168cdf0e10cSrcweir         }
169cdf0e10cSrcweir 
disposing(com.sun.star.lang.EventObject eventObject)170cdf0e10cSrcweir         public void disposing(com.sun.star.lang.EventObject eventObject)
171cdf0e10cSrcweir         {
172cdf0e10cSrcweir         }
173cdf0e10cSrcweir     }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir     class TextListenerImpl implements com.sun.star.awt.XTextListener
176cdf0e10cSrcweir     {
177cdf0e10cSrcweir 
textChanged(TextEvent EventObject)178cdf0e10cSrcweir         public void textChanged(TextEvent EventObject)
179cdf0e10cSrcweir         {
180cdf0e10cSrcweir             String sName = getControlName(EventObject.Source);
181cdf0e10cSrcweir             togglefollowingControlRow(sName);
182cdf0e10cSrcweir         }
183cdf0e10cSrcweir 
disposing(EventObject eventObject)184cdf0e10cSrcweir         public void disposing(EventObject eventObject)
185cdf0e10cSrcweir         {
186cdf0e10cSrcweir         }
187cdf0e10cSrcweir 
actionPerformed(com.sun.star.awt.ActionEvent actionEvent)188cdf0e10cSrcweir         public void actionPerformed(com.sun.star.awt.ActionEvent actionEvent)
189cdf0e10cSrcweir         {
190cdf0e10cSrcweir             getfilterstate();
191cdf0e10cSrcweir         }
192cdf0e10cSrcweir     }
193cdf0e10cSrcweir 
getIndexNumber(String _sStr)194cdf0e10cSrcweir     public static String getIndexNumber(String _sStr)
195cdf0e10cSrcweir     {
196cdf0e10cSrcweir         return _sStr.substring(_sStr.length() - 1, _sStr.length());
197cdf0e10cSrcweir     }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir     /**
200cdf0e10cSrcweir      * Enable the next ControlRow if the Condition is complete in the current line
201cdf0e10cSrcweir      *
202cdf0e10cSrcweir      * @param _scurName every control name ends with something like _1, _2, _3 this is the index number
203cdf0e10cSrcweir      *        we try to interpret to check which line we currently use. (number - 1)
204cdf0e10cSrcweir      */
togglefollowingControlRow(String _scurName)205cdf0e10cSrcweir     private void togglefollowingControlRow(String _scurName)
206cdf0e10cSrcweir     {
207cdf0e10cSrcweir         // String sNameSuffix = sIncSuffix + "_" + _scurName.substring(_scurName.length() - 1, _scurName.length());
208cdf0e10cSrcweir         int Index = Integer.valueOf(getIndexNumber(_scurName)).intValue();
209cdf0e10cSrcweir         if (Index < oControlRows.length)
210cdf0e10cSrcweir         {
211cdf0e10cSrcweir             boolean bValue = oControlRows[Index - 1].isConditionComplete();
212cdf0e10cSrcweir             oControlRows[Index].setEnabled(bValue);
213cdf0e10cSrcweir         }
214cdf0e10cSrcweir     }
215cdf0e10cSrcweir 
getControlName(Object _oSourceevent)216cdf0e10cSrcweir     private String getControlName(Object _oSourceevent)
217cdf0e10cSrcweir     {
218cdf0e10cSrcweir         try
219cdf0e10cSrcweir         {
220cdf0e10cSrcweir             XControl xControl = UnoRuntime.queryInterface(XControl.class, _oSourceevent);
221cdf0e10cSrcweir             XPropertySet xPSet = UnoRuntime.queryInterface(XPropertySet.class, xControl.getModel());
222cdf0e10cSrcweir             return AnyConverter.toString(xPSet.getPropertyValue(PropertyNames.PROPERTY_NAME));
223cdf0e10cSrcweir         }
224cdf0e10cSrcweir         catch (Exception e)
225cdf0e10cSrcweir         {
226cdf0e10cSrcweir             e.printStackTrace(System.out);
227cdf0e10cSrcweir         }
228cdf0e10cSrcweir         return PropertyNames.EMPTY_STRING;
229cdf0e10cSrcweir     }
230cdf0e10cSrcweir 
getFilterConditions()231cdf0e10cSrcweir     public PropertyValue[][] getFilterConditions()
232cdf0e10cSrcweir     {
233cdf0e10cSrcweir         // ControlRow CurControlRow;
234cdf0e10cSrcweir         // getfilterstate();
235cdf0e10cSrcweir         int nFilterCount = getFilterCount();
236cdf0e10cSrcweir         if (nFilterCount > 0)
237cdf0e10cSrcweir         {
238cdf0e10cSrcweir             final SQLQueryComposer composer = oQueryMetaData.getSQLQueryComposer();
239cdf0e10cSrcweir             try
240cdf0e10cSrcweir             {
241cdf0e10cSrcweir                 final String serviceName = "com.sun.star.beans.PropertyBag";
242cdf0e10cSrcweir                 final XPropertyContainer column = UnoRuntime.queryInterface(XPropertyContainer.class, oQueryMetaData.xMSF.createInstance(serviceName));
243cdf0e10cSrcweir 
244cdf0e10cSrcweir                 column.addProperty("Type", PropertyAttribute.BOUND, DataType.VARCHAR);
245cdf0e10cSrcweir                 column.addProperty(PropertyNames.PROPERTY_NAME, PropertyAttribute.BOUND, PropertyNames.EMPTY_STRING);
246cdf0e10cSrcweir                 column.addProperty("Value", (short) (PropertyAttribute.MAYBEVOID | PropertyAttribute.REMOVABLE), null);
247cdf0e10cSrcweir                 final XPropertySet columnSet = UnoRuntime.queryInterface(XPropertySet.class, column);
248cdf0e10cSrcweir 
249cdf0e10cSrcweir                 if (composer.getQuery().length() == 0)
250cdf0e10cSrcweir                 {
251cdf0e10cSrcweir                     StringBuilder sql = new StringBuilder();
252cdf0e10cSrcweir                     sql.append(composer.getSelectClause(true));
253cdf0e10cSrcweir                     sql.append(' ');
254cdf0e10cSrcweir                     sql.append(composer.getFromClause());
255cdf0e10cSrcweir                     composer.getQueryComposer().setElementaryQuery(sql.toString());
256cdf0e10cSrcweir                 }
257cdf0e10cSrcweir                 composer.getQueryComposer().setStructuredFilter(new PropertyValue[][]
258cdf0e10cSrcweir                         {
259cdf0e10cSrcweir                         });
260cdf0e10cSrcweir                 for (int i = 0; i < RowCount; i++)
261cdf0e10cSrcweir                 {
262cdf0e10cSrcweir                     ControlRow currentControlRow = oControlRows[i];
263cdf0e10cSrcweir                     if (currentControlRow.isEnabled() && currentControlRow.isConditionComplete())
264cdf0e10cSrcweir                     {
265cdf0e10cSrcweir                         String sFieldName = currentControlRow.getSelectedFieldName();
266cdf0e10cSrcweir                         int nOperator = (int) currentControlRow.getSelectedOperator();
267cdf0e10cSrcweir                         FieldColumn aFieldColumn = oQueryMetaData.getFieldColumnByDisplayName(sFieldName);
268cdf0e10cSrcweir                         columnSet.setPropertyValue(PropertyNames.PROPERTY_NAME, aFieldColumn.getFieldName());
269cdf0e10cSrcweir                         columnSet.setPropertyValue("Type", aFieldColumn.getXColumnPropertySet().getPropertyValue("Type"));
270cdf0e10cSrcweir                         Object value = currentControlRow.getValue();
271cdf0e10cSrcweir                         switch (aFieldColumn.getFieldType())
272cdf0e10cSrcweir                         {
273cdf0e10cSrcweir                             case DataType.TIMESTAMP:
274cdf0e10cSrcweir                             case DataType.DATE:
275cdf0e10cSrcweir                                 value = ((Double) value) - oQueryMetaData.getNullDateCorrection();
276cdf0e10cSrcweir                                 break;
277cdf0e10cSrcweir                         }
278cdf0e10cSrcweir                         column.removeProperty("Value");
279cdf0e10cSrcweir                         final short operator = currentControlRow.getSelectedOperator();
280cdf0e10cSrcweir                         if ((operator == SQLFilterOperator.SQLNULL)
281cdf0e10cSrcweir                                 || (operator == SQLFilterOperator.NOT_SQLNULL)
282cdf0e10cSrcweir                                 || AnyConverter.isVoid(value))
283cdf0e10cSrcweir                         {
284cdf0e10cSrcweir                             column.addProperty("Value", (short) (PropertyAttribute.MAYBEVOID | PropertyAttribute.REMOVABLE), "");
285cdf0e10cSrcweir                             value = new Any(new Type(TypeClass.VOID), null);
286cdf0e10cSrcweir                         }
287cdf0e10cSrcweir                         else
288cdf0e10cSrcweir                         {
289cdf0e10cSrcweir                             column.addProperty("Value", (short) (PropertyAttribute.MAYBEVOID | PropertyAttribute.REMOVABLE), value);
290cdf0e10cSrcweir                         }
291cdf0e10cSrcweir                         columnSet.setPropertyValue("Value", value);
292cdf0e10cSrcweir                         composer.getQueryComposer().appendFilterByColumn(columnSet, getfilterstate() == this.SOI_MATCHALL, nOperator);
293cdf0e10cSrcweir                     }
294cdf0e10cSrcweir                 }
295cdf0e10cSrcweir                 filterconditions = composer.getNormalizedStructuredFilter();
296cdf0e10cSrcweir                 int[] iduplicate = JavaTools.getDuplicateFieldIndex(filterconditions);
297cdf0e10cSrcweir                 if (iduplicate[0] != -1)
298cdf0e10cSrcweir                 {
299cdf0e10cSrcweir                     PropertyValue aduplicatecondition = filterconditions[iduplicate[0]][iduplicate[1]];
300cdf0e10cSrcweir                     String smsgDuplicateCondition = getDisplayCondition(sDuplicateCondition, aduplicatecondition, null);
301cdf0e10cSrcweir                     CurUnoDialog.showMessageBox("WarningBox", VclWindowPeerAttribute.OK, smsgDuplicateCondition);
302cdf0e10cSrcweir                     CurUnoDialog.vetoableChange(new java.beans.PropertyChangeEvent(CurUnoDialog, "Steps", Integer.valueOf(1), Integer.valueOf(2)));
303cdf0e10cSrcweir                     return new PropertyValue[][]
304cdf0e10cSrcweir                             {
305cdf0e10cSrcweir                             };
306cdf0e10cSrcweir                 }
307cdf0e10cSrcweir             }
308cdf0e10cSrcweir             catch (Exception ex)
309cdf0e10cSrcweir             {
310cdf0e10cSrcweir                 Logger.getLogger(FilterComponent.class.getName()).log(Level.SEVERE, null, ex);
311cdf0e10cSrcweir             }
312cdf0e10cSrcweir         }
313cdf0e10cSrcweir         else
314cdf0e10cSrcweir         {
315cdf0e10cSrcweir             filterconditions = new PropertyValue[0][0];
316cdf0e10cSrcweir         }
317cdf0e10cSrcweir         return filterconditions;
318cdf0e10cSrcweir     }
319cdf0e10cSrcweir 
getDisplayCondition(String _BaseString, PropertyValue _filtercondition, QueryMetaData _CurDBMetaData)320cdf0e10cSrcweir     public static String getDisplayCondition(String _BaseString, PropertyValue _filtercondition, QueryMetaData _CurDBMetaData)
321cdf0e10cSrcweir     {
322cdf0e10cSrcweir         try
323cdf0e10cSrcweir         {
324cdf0e10cSrcweir             String FieldName;
325cdf0e10cSrcweir             if (_CurDBMetaData != null)
326cdf0e10cSrcweir             {
327cdf0e10cSrcweir                 FieldColumn CurDBFieldColumn = _CurDBMetaData.getFieldColumnByDisplayName(_filtercondition.Name);
328cdf0e10cSrcweir                 FieldName = CurDBFieldColumn.getFieldTitle();
329cdf0e10cSrcweir             }
330cdf0e10cSrcweir             else
331cdf0e10cSrcweir             {
332cdf0e10cSrcweir                 FieldName = _filtercondition.Name;
333cdf0e10cSrcweir             }
334cdf0e10cSrcweir             String sreturn = JavaTools.replaceSubString(_BaseString, FieldName, "<FIELDNAME>");
335cdf0e10cSrcweir             String soperator = sLogicOperators[_filtercondition.Handle - 1];
336cdf0e10cSrcweir             sreturn = JavaTools.replaceSubString(sreturn, soperator, "<LOGICOPERATOR>");
337cdf0e10cSrcweir             String sDisplayValue = PropertyNames.EMPTY_STRING;
338cdf0e10cSrcweir             if ((_filtercondition.Handle != SQLFilterOperator.SQLNULL)
339cdf0e10cSrcweir                     && (_filtercondition.Handle != SQLFilterOperator.NOT_SQLNULL)
340cdf0e10cSrcweir                     && !AnyConverter.isVoid(_filtercondition.Value))
341cdf0e10cSrcweir             {
342cdf0e10cSrcweir                 sDisplayValue = AnyConverter.toString(_filtercondition.Value);
343cdf0e10cSrcweir             }
344cdf0e10cSrcweir             sreturn = JavaTools.replaceSubString(sreturn, sDisplayValue, "<VALUE>");
345cdf0e10cSrcweir             return sreturn;
346cdf0e10cSrcweir         }
347cdf0e10cSrcweir         catch (IllegalArgumentException e)
348cdf0e10cSrcweir         {
349cdf0e10cSrcweir             e.printStackTrace(System.out);
350cdf0e10cSrcweir         }
351cdf0e10cSrcweir         return PropertyNames.EMPTY_STRING;
352cdf0e10cSrcweir     }
353cdf0e10cSrcweir 
getfilterstate()354cdf0e10cSrcweir     private int getfilterstate()
355cdf0e10cSrcweir     {
356cdf0e10cSrcweir         boolean bisany = true;
357cdf0e10cSrcweir         int ifilterstate = SOI_MATCHALL;
358cdf0e10cSrcweir         bisany = (this.optMatchAny.getState());
359cdf0e10cSrcweir         if (bisany)
360cdf0e10cSrcweir         {
361cdf0e10cSrcweir             ifilterstate = SOI_MATCHANY;
362cdf0e10cSrcweir         }
363cdf0e10cSrcweir         else
364cdf0e10cSrcweir         {
365cdf0e10cSrcweir             ifilterstate = SOI_MATCHALL;
366cdf0e10cSrcweir         }
367cdf0e10cSrcweir         return ifilterstate;
368cdf0e10cSrcweir     }
369cdf0e10cSrcweir 
getFilterCount()370cdf0e10cSrcweir     private int getFilterCount()
371cdf0e10cSrcweir     {
372cdf0e10cSrcweir         int a = 0;
373cdf0e10cSrcweir         for (int i = 0; i < RowCount; i++)
374cdf0e10cSrcweir         {
375cdf0e10cSrcweir             if (oControlRows[i].isEnabled() && oControlRows[i].isConditionComplete())
376cdf0e10cSrcweir             {
377cdf0e10cSrcweir                 a++;
378cdf0e10cSrcweir             }
379cdf0e10cSrcweir         }
380cdf0e10cSrcweir         return a;
381cdf0e10cSrcweir     }
382cdf0e10cSrcweir 
383cdf0e10cSrcweir     /** Creates a new instance of FilterComponent
384cdf0e10cSrcweir      * @param CurUnoDialog
385cdf0e10cSrcweir      * @param _xMSF
386cdf0e10cSrcweir      * @param iStep
387cdf0e10cSrcweir      * @param iPosX
388cdf0e10cSrcweir      * @param iPosY
389cdf0e10cSrcweir      * @param iWidth
390cdf0e10cSrcweir      * @param FilterCount
391cdf0e10cSrcweir      * @param _oQueryMetaData
392cdf0e10cSrcweir      * @param _firstHelpID
393cdf0e10cSrcweir      */
FilterComponent(WizardDialog CurUnoDialog, XMultiServiceFactory _xMSF, int iStep, int iPosX, int iPosY, int iWidth, int FilterCount, QueryMetaData _oQueryMetaData, int _firstHelpID)394cdf0e10cSrcweir     public FilterComponent(WizardDialog CurUnoDialog, XMultiServiceFactory _xMSF, int iStep, int iPosX, int iPosY, int iWidth, int FilterCount, QueryMetaData _oQueryMetaData, int _firstHelpID)
395cdf0e10cSrcweir     {
396cdf0e10cSrcweir         this.curHelpID = _firstHelpID;
397cdf0e10cSrcweir         this.xMSF = _xMSF;
398cdf0e10cSrcweir         this.IStep = Integer.valueOf(iStep);
399cdf0e10cSrcweir 
400cdf0e10cSrcweir         curtabindex = UnoDialog.setInitialTabindex(iStep);
401cdf0e10cSrcweir         this.CurUnoDialog = CurUnoDialog;
402cdf0e10cSrcweir         this.RowCount = FilterCount;
403cdf0e10cSrcweir         this.oQueryMetaData = _oQueryMetaData;
404cdf0e10cSrcweir         boolean bEnabled;
405cdf0e10cSrcweir         sIncSuffix = com.sun.star.wizards.common.Desktop.getIncrementSuffix(CurUnoDialog.getDlgNameAccess(), "optMatchAll");
406cdf0e10cSrcweir 
407*2d88557cSDamjan Jovanovic         String soptMatchAll = CurUnoDialog.m_oResource.getResText(UIConsts.RID_QUERY + 9);
408*2d88557cSDamjan Jovanovic         String soptMatchAny = CurUnoDialog.m_oResource.getResText(UIConsts.RID_QUERY + 10);
409*2d88557cSDamjan Jovanovic         slblFieldNames = CurUnoDialog.m_oResource.getResText(UIConsts.RID_QUERY + 17);
410*2d88557cSDamjan Jovanovic         slblOperators = CurUnoDialog.m_oResource.getResText(UIConsts.RID_QUERY + 24);
411*2d88557cSDamjan Jovanovic         slblValue = CurUnoDialog.m_oResource.getResText(UIConsts.RID_QUERY + 25);
412*2d88557cSDamjan Jovanovic         sLogicOperators = CurUnoDialog.m_oResource.getResArray(UIConsts.RID_QUERY + 26, 10 /* 7 */); // =, <>, <, >, <=, >=, like, !like, is null, !is null
413cdf0e10cSrcweir 
414*2d88557cSDamjan Jovanovic         sDuplicateCondition = CurUnoDialog.m_oResource.getResText(UIConsts.RID_QUERY + 89);
415cdf0e10cSrcweir 
416cdf0e10cSrcweir         // create Radiobuttons
417cdf0e10cSrcweir         // * match all
418cdf0e10cSrcweir         // * match one
419cdf0e10cSrcweir         CurUnoDialog.insertRadioButton("optMatchAll" + sIncSuffix, SOOPTANDMODE, new ItemListenerImpl(),
420cdf0e10cSrcweir                 new String[]
421cdf0e10cSrcweir                 {
422cdf0e10cSrcweir                     PropertyNames.PROPERTY_HEIGHT,
423cdf0e10cSrcweir                     PropertyNames.PROPERTY_HELPURL,
424cdf0e10cSrcweir                     PropertyNames.PROPERTY_LABEL,
425cdf0e10cSrcweir                     PropertyNames.PROPERTY_POSITION_X,
426cdf0e10cSrcweir                     PropertyNames.PROPERTY_POSITION_Y,
427cdf0e10cSrcweir                     PropertyNames.PROPERTY_STATE,
428cdf0e10cSrcweir                     PropertyNames.PROPERTY_STEP,
429cdf0e10cSrcweir                     PropertyNames.PROPERTY_TABINDEX,
430cdf0e10cSrcweir                     PropertyNames.PROPERTY_WIDTH
431cdf0e10cSrcweir                 },
432cdf0e10cSrcweir                 new Object[]
433cdf0e10cSrcweir                 {
434cdf0e10cSrcweir                     Integer.valueOf(9),
435cdf0e10cSrcweir                     HelpIds.getHelpIdString(curHelpID++),
436cdf0e10cSrcweir                     soptMatchAll,
437cdf0e10cSrcweir                     Integer.valueOf(iPosX),
438cdf0e10cSrcweir                     Integer.valueOf(iPosY),
439cdf0e10cSrcweir                     Short.valueOf((short) 1),
440cdf0e10cSrcweir                     IStep,
441cdf0e10cSrcweir                     Short.valueOf(curtabindex++),
442cdf0e10cSrcweir                     Integer.valueOf(203)
443cdf0e10cSrcweir                 });
444cdf0e10cSrcweir         optMatchAny = CurUnoDialog.insertRadioButton("optMatchAny" + sIncSuffix, SOOPTORMODE, new ItemListenerImpl(),
445cdf0e10cSrcweir                 new String[]
446cdf0e10cSrcweir                 {
447cdf0e10cSrcweir                     PropertyNames.PROPERTY_HEIGHT,
448cdf0e10cSrcweir                     PropertyNames.PROPERTY_HELPURL,
449cdf0e10cSrcweir                     PropertyNames.PROPERTY_LABEL,
450cdf0e10cSrcweir                     PropertyNames.PROPERTY_POSITION_X,
451cdf0e10cSrcweir                     PropertyNames.PROPERTY_POSITION_Y,
452cdf0e10cSrcweir                     PropertyNames.PROPERTY_STEP,
453cdf0e10cSrcweir                     PropertyNames.PROPERTY_TABINDEX,
454cdf0e10cSrcweir                     PropertyNames.PROPERTY_WIDTH
455cdf0e10cSrcweir                 },
456cdf0e10cSrcweir                 new Object[]
457cdf0e10cSrcweir                 {
458cdf0e10cSrcweir                     Integer.valueOf(9),
459cdf0e10cSrcweir                     HelpIds.getHelpIdString(curHelpID++),
460cdf0e10cSrcweir                     soptMatchAny,
461cdf0e10cSrcweir                     Integer.valueOf(iPosX),
462cdf0e10cSrcweir                     Integer.valueOf(iPosY + 12),
463cdf0e10cSrcweir                     IStep,
464cdf0e10cSrcweir                     Short.valueOf(curtabindex++),
465cdf0e10cSrcweir                     Integer.valueOf(203)
466cdf0e10cSrcweir                 });
467cdf0e10cSrcweir         getfilterstate();
468cdf0e10cSrcweir 
469cdf0e10cSrcweir         oControlRows = new ControlRow[FilterCount];
470cdf0e10cSrcweir         for (int i = 0; i < FilterCount; i++)
471cdf0e10cSrcweir         {
472cdf0e10cSrcweir             bEnabled = (i == 0);
473cdf0e10cSrcweir             oControlRows[i] = new ControlRow(iPosX, iPosY + 20, i, bEnabled, (this.curHelpID + (i * 3)));
474cdf0e10cSrcweir             iPosY += 43;
475cdf0e10cSrcweir         }
476cdf0e10cSrcweir     }
477cdf0e10cSrcweir 
initialize(PropertyValue[][] _filterconditions, String[] _fieldnames)478cdf0e10cSrcweir     public void initialize(PropertyValue[][] _filterconditions, String[] _fieldnames)
479cdf0e10cSrcweir     {
480cdf0e10cSrcweir         int i;
481cdf0e10cSrcweir         for (i = 0; i < RowCount; i++)
482cdf0e10cSrcweir         {
483cdf0e10cSrcweir             oControlRows[i].setFieldNames(_fieldnames);
484cdf0e10cSrcweir             // oControlRows[i].setFieldNames(aFieldNamesWithAdditionalEmpty);
485cdf0e10cSrcweir         }
486cdf0e10cSrcweir         this.filterconditions = _filterconditions;
487cdf0e10cSrcweir         PropertyValue[] curfilterconditions;
488cdf0e10cSrcweir         // int a;
489cdf0e10cSrcweir         if (_filterconditions.length == 1)
490cdf0e10cSrcweir         {
491cdf0e10cSrcweir             curfilterconditions = filterconditions[0];
492cdf0e10cSrcweir             for (i = 0; i < curfilterconditions.length; i++)
493cdf0e10cSrcweir             {
494cdf0e10cSrcweir                 oControlRows[i].setCondition(filterconditions[0][i]);
495cdf0e10cSrcweir             }
496cdf0e10cSrcweir         }
497cdf0e10cSrcweir         else
498cdf0e10cSrcweir         {
499cdf0e10cSrcweir             for (i = 0; i < filterconditions.length; i++)
500cdf0e10cSrcweir             {
501cdf0e10cSrcweir                 oControlRows[i].setCondition(filterconditions[i][0]);
502cdf0e10cSrcweir             }
503cdf0e10cSrcweir         }
504cdf0e10cSrcweir         while (i < oControlRows.length)
505cdf0e10cSrcweir         {
506cdf0e10cSrcweir             oControlRows[i].settovoid();
507cdf0e10cSrcweir             boolean bdoenable;
508cdf0e10cSrcweir             if (i > 0)
509cdf0e10cSrcweir             {
510cdf0e10cSrcweir                 bdoenable = oControlRows[i - 1].isConditionComplete();
511cdf0e10cSrcweir             }
512cdf0e10cSrcweir             else
513cdf0e10cSrcweir             {
514cdf0e10cSrcweir                 bdoenable = true;
515cdf0e10cSrcweir             }
516cdf0e10cSrcweir             oControlRows[i].setEnabled(bdoenable);
517cdf0e10cSrcweir             i++;
518cdf0e10cSrcweir         }
519cdf0e10cSrcweir     }
520cdf0e10cSrcweir 
addNumberFormats()521cdf0e10cSrcweir     public void addNumberFormats()
522cdf0e10cSrcweir     {
523cdf0e10cSrcweir         iDateFormat = oQueryMetaData.getNumberFormatter().defineNumberFormat("YYYY-MM-DD");
524cdf0e10cSrcweir         iTimeFormat = oQueryMetaData.getNumberFormatter().defineNumberFormat("HH:MM:SS");
525cdf0e10cSrcweir         iDateTimeFormat = oQueryMetaData.getNumberFormatter().defineNumberFormat("YYYY-MM-DD HH:MM:SS");
526cdf0e10cSrcweir     }
527cdf0e10cSrcweir 
528cdf0e10cSrcweir     // -------------------------------------------------------------------------
529cdf0e10cSrcweir     //
530cdf0e10cSrcweir     //
531cdf0e10cSrcweir     // -------------------------------------------------------------------------
532cdf0e10cSrcweir     final class ControlRow
533cdf0e10cSrcweir     {
534cdf0e10cSrcweir 
535cdf0e10cSrcweir         private final static int SOLSTFIELDNAME = 3;
536cdf0e10cSrcweir         private final static int SOLSTOPERATOR = 4;
537cdf0e10cSrcweir         private final static int SOTXTVALUE = 5;
538cdf0e10cSrcweir         protected XInterface[] ControlElements = new XInterface[6];
539cdf0e10cSrcweir         private boolean m_bEnabled;
540cdf0e10cSrcweir         String[] FieldNames;
541cdf0e10cSrcweir 
ControlRow(int iCompPosX, int iCompPosY, int Index, boolean _bEnabled, int _firstRowHelpID)542cdf0e10cSrcweir         protected ControlRow(int iCompPosX, int iCompPosY, int Index, boolean _bEnabled, int _firstRowHelpID)
543cdf0e10cSrcweir         {
544cdf0e10cSrcweir             int nFieldWidth = 71;
545cdf0e10cSrcweir             int nOperatorWidth = 70;
546cdf0e10cSrcweir             int nValueWidth = 44;
547cdf0e10cSrcweir 
548cdf0e10cSrcweir             int nPosX1 = iCompPosX + 10;
549cdf0e10cSrcweir             int nPosX2 = iCompPosX + 10 + nFieldWidth + 6; // 87
550cdf0e10cSrcweir             int nPosX3 = iCompPosX + 10 + nFieldWidth + 6 + nOperatorWidth + 6;
551cdf0e10cSrcweir 
552cdf0e10cSrcweir 
553cdf0e10cSrcweir             try
554cdf0e10cSrcweir             {
555cdf0e10cSrcweir                 String sCompSuffix = sIncSuffix + "_" + String.valueOf(Index + 1);
556cdf0e10cSrcweir                 m_bEnabled = _bEnabled;
557cdf0e10cSrcweir 
558cdf0e10cSrcweir                 // Label Field
559cdf0e10cSrcweir                 ControlElements[0] = CurUnoDialog.insertLabel("lblFieldNames" + sCompSuffix,
560cdf0e10cSrcweir                         new String[]
561cdf0e10cSrcweir                         {
562cdf0e10cSrcweir                             PropertyNames.PROPERTY_ENABLED,
563cdf0e10cSrcweir                             PropertyNames.PROPERTY_HEIGHT,
564cdf0e10cSrcweir                             PropertyNames.PROPERTY_LABEL,
565cdf0e10cSrcweir                             PropertyNames.PROPERTY_POSITION_X,
566cdf0e10cSrcweir                             PropertyNames.PROPERTY_POSITION_Y,
567cdf0e10cSrcweir                             PropertyNames.PROPERTY_STEP,
568cdf0e10cSrcweir                             PropertyNames.PROPERTY_TABINDEX,
569cdf0e10cSrcweir                             PropertyNames.PROPERTY_WIDTH
570cdf0e10cSrcweir                         },
571cdf0e10cSrcweir                         new Object[]
572cdf0e10cSrcweir                         {
573cdf0e10cSrcweir                             Boolean.valueOf(isEnabled()),
574cdf0e10cSrcweir                             Integer.valueOf(9),
575cdf0e10cSrcweir                             slblFieldNames,
576cdf0e10cSrcweir                             Integer.valueOf(nPosX1),
577cdf0e10cSrcweir                             Integer.valueOf(iCompPosY + 13),
578cdf0e10cSrcweir                             IStep,
579cdf0e10cSrcweir                             Short.valueOf(curtabindex++),
580cdf0e10cSrcweir                             Integer.valueOf(nFieldWidth)
581cdf0e10cSrcweir                         });
582cdf0e10cSrcweir 
583cdf0e10cSrcweir                 // Label Operator
584cdf0e10cSrcweir                 ControlElements[1] = CurUnoDialog.insertLabel("lblOperators" + sCompSuffix,
585cdf0e10cSrcweir                         new String[]
586cdf0e10cSrcweir                         {
587cdf0e10cSrcweir                             PropertyNames.PROPERTY_ENABLED,
588cdf0e10cSrcweir                             PropertyNames.PROPERTY_HEIGHT,
589cdf0e10cSrcweir                             PropertyNames.PROPERTY_LABEL,
590cdf0e10cSrcweir                             PropertyNames.PROPERTY_POSITION_X,
591cdf0e10cSrcweir                             PropertyNames.PROPERTY_POSITION_Y,
592cdf0e10cSrcweir                             PropertyNames.PROPERTY_STEP,
593cdf0e10cSrcweir                             PropertyNames.PROPERTY_TABINDEX,
594cdf0e10cSrcweir                             PropertyNames.PROPERTY_WIDTH
595cdf0e10cSrcweir                         },
596cdf0e10cSrcweir                         new Object[]
597cdf0e10cSrcweir                         {
598cdf0e10cSrcweir                             Boolean.valueOf(isEnabled()),
599cdf0e10cSrcweir                             Integer.valueOf(9),
600cdf0e10cSrcweir                             slblOperators,
601cdf0e10cSrcweir                             Integer.valueOf(nPosX2),
602cdf0e10cSrcweir                             Integer.valueOf(iCompPosY + 13),
603cdf0e10cSrcweir                             IStep,
604cdf0e10cSrcweir                             Short.valueOf(curtabindex++),
605cdf0e10cSrcweir                             Integer.valueOf(nOperatorWidth)
606cdf0e10cSrcweir                         });
607cdf0e10cSrcweir 
608cdf0e10cSrcweir                 // Label Value
609cdf0e10cSrcweir                 ControlElements[2] = CurUnoDialog.insertLabel("lblValue" + sCompSuffix,
610cdf0e10cSrcweir                         new String[]
611cdf0e10cSrcweir                         {
612cdf0e10cSrcweir                             PropertyNames.PROPERTY_ENABLED,
613cdf0e10cSrcweir                             PropertyNames.PROPERTY_HEIGHT,
614cdf0e10cSrcweir                             PropertyNames.PROPERTY_LABEL,
615cdf0e10cSrcweir                             PropertyNames.PROPERTY_POSITION_X,
616cdf0e10cSrcweir                             PropertyNames.PROPERTY_POSITION_Y,
617cdf0e10cSrcweir                             PropertyNames.PROPERTY_STEP,
618cdf0e10cSrcweir                             PropertyNames.PROPERTY_TABINDEX,
619cdf0e10cSrcweir                             PropertyNames.PROPERTY_WIDTH
620cdf0e10cSrcweir                         },
621cdf0e10cSrcweir                         new Object[]
622cdf0e10cSrcweir                         {
623cdf0e10cSrcweir                             Boolean.valueOf(isEnabled()),
624cdf0e10cSrcweir                             Integer.valueOf(9),
625cdf0e10cSrcweir                             slblValue,
626cdf0e10cSrcweir                             Integer.valueOf(nPosX3),
627cdf0e10cSrcweir                             Integer.valueOf(iCompPosY + 13),
628cdf0e10cSrcweir                             IStep,
629cdf0e10cSrcweir                             Short.valueOf(curtabindex++),
630cdf0e10cSrcweir                             Integer.valueOf(nValueWidth)
631cdf0e10cSrcweir                         });
632cdf0e10cSrcweir 
633cdf0e10cSrcweir                 // Listbox Fields
634cdf0e10cSrcweir                 ControlElements[SOLSTFIELDNAME] = CurUnoDialog.insertListBox("lstFieldName" + sCompSuffix, SO_FIELDNAMELIST[Index], null, new ItemListenerImpl(),
635cdf0e10cSrcweir                         new String[]
636cdf0e10cSrcweir                         {
637cdf0e10cSrcweir                             PropertyNames.PROPERTY_ENABLED,
638cdf0e10cSrcweir                             "Dropdown",
639cdf0e10cSrcweir                             PropertyNames.PROPERTY_HEIGHT,
640cdf0e10cSrcweir                             PropertyNames.PROPERTY_HELPURL,
641cdf0e10cSrcweir                             "LineCount",
642cdf0e10cSrcweir                             PropertyNames.PROPERTY_POSITION_X,
643cdf0e10cSrcweir                             PropertyNames.PROPERTY_POSITION_Y,
644cdf0e10cSrcweir                             PropertyNames.PROPERTY_STEP,
645cdf0e10cSrcweir                             PropertyNames.PROPERTY_TABINDEX,
646cdf0e10cSrcweir                             PropertyNames.PROPERTY_WIDTH
647cdf0e10cSrcweir                         },
648cdf0e10cSrcweir                         new Object[]
649cdf0e10cSrcweir                         {
650cdf0e10cSrcweir                             Boolean.valueOf(isEnabled()),
651cdf0e10cSrcweir                             Boolean.TRUE,
652cdf0e10cSrcweir                             Integer.valueOf(13),
653cdf0e10cSrcweir                             HelpIds.getHelpIdString(_firstRowHelpID++),
654cdf0e10cSrcweir                             Short.valueOf(UnoDialog.getListBoxLineCount() /* 7 */),
655cdf0e10cSrcweir                             Integer.valueOf(nPosX1),
656cdf0e10cSrcweir                             Integer.valueOf(iCompPosY + 23),
657cdf0e10cSrcweir                             IStep,
658cdf0e10cSrcweir                             Short.valueOf(curtabindex++),
659cdf0e10cSrcweir                             Integer.valueOf(nFieldWidth)
660cdf0e10cSrcweir                         });
661cdf0e10cSrcweir 
662cdf0e10cSrcweir                 // Listbox Operators
663cdf0e10cSrcweir                 ControlElements[SOLSTOPERATOR] = CurUnoDialog.insertListBox("lstOperator" + sCompSuffix, SO_CONDITIONLIST[Index], null, new ItemListenerImpl(),
664cdf0e10cSrcweir                         new String[]
665cdf0e10cSrcweir                         {
666cdf0e10cSrcweir                             PropertyNames.PROPERTY_ENABLED,
667cdf0e10cSrcweir                             "Dropdown",
668cdf0e10cSrcweir                             PropertyNames.PROPERTY_HEIGHT,
669cdf0e10cSrcweir                             PropertyNames.PROPERTY_HELPURL,
670cdf0e10cSrcweir                             "LineCount",
671cdf0e10cSrcweir                             PropertyNames.PROPERTY_POSITION_X,
672cdf0e10cSrcweir                             PropertyNames.PROPERTY_POSITION_Y,
673cdf0e10cSrcweir                             PropertyNames.PROPERTY_STEP,
674cdf0e10cSrcweir                             PropertyNames.STRING_ITEM_LIST,
675cdf0e10cSrcweir                             PropertyNames.PROPERTY_TABINDEX,
676cdf0e10cSrcweir                             PropertyNames.PROPERTY_WIDTH
677cdf0e10cSrcweir                         },
678cdf0e10cSrcweir                         new Object[]
679cdf0e10cSrcweir                         {
680cdf0e10cSrcweir                             Boolean.valueOf(isEnabled()),
681cdf0e10cSrcweir                             Boolean.TRUE,
682cdf0e10cSrcweir                             Integer.valueOf(13),
683cdf0e10cSrcweir                             HelpIds.getHelpIdString(_firstRowHelpID++),
684cdf0e10cSrcweir                             Short.valueOf((short) sLogicOperators.length /* 7 */),
685cdf0e10cSrcweir                             Integer.valueOf(nPosX2),
686cdf0e10cSrcweir                             Integer.valueOf(iCompPosY + 23),
687cdf0e10cSrcweir                             IStep,
688cdf0e10cSrcweir                             sLogicOperators,
689cdf0e10cSrcweir                             Short.valueOf(curtabindex++),
690cdf0e10cSrcweir                             Integer.valueOf(nOperatorWidth)
691cdf0e10cSrcweir                         });
692cdf0e10cSrcweir                 ControlElements[SOTXTVALUE] = CurUnoDialog.insertFormattedField("txtValue" + sCompSuffix, SO_TEXTFIELDLIST[Index], new TextListenerImpl(),
693cdf0e10cSrcweir                         new String[]
694cdf0e10cSrcweir                         {
695cdf0e10cSrcweir                             PropertyNames.PROPERTY_ENABLED,
696cdf0e10cSrcweir                             PropertyNames.PROPERTY_HEIGHT,
697cdf0e10cSrcweir                             PropertyNames.PROPERTY_HELPURL,
698cdf0e10cSrcweir                             PropertyNames.PROPERTY_POSITION_X,
699cdf0e10cSrcweir                             PropertyNames.PROPERTY_POSITION_Y,
700cdf0e10cSrcweir                             PropertyNames.PROPERTY_STEP,
701cdf0e10cSrcweir                             PropertyNames.PROPERTY_TABINDEX,
702cdf0e10cSrcweir                             PropertyNames.PROPERTY_WIDTH
703cdf0e10cSrcweir                         },
704cdf0e10cSrcweir                         new Object[]
705cdf0e10cSrcweir                         {
706cdf0e10cSrcweir                             Boolean.valueOf(isEnabled()),
707cdf0e10cSrcweir                             Integer.valueOf(13),
708cdf0e10cSrcweir                             HelpIds.getHelpIdString(_firstRowHelpID++),
709cdf0e10cSrcweir                             Integer.valueOf(nPosX3),
710cdf0e10cSrcweir                             Integer.valueOf(iCompPosY + 23),
711cdf0e10cSrcweir                             IStep,
712cdf0e10cSrcweir                             Short.valueOf(curtabindex++),
713cdf0e10cSrcweir                             Integer.valueOf(nValueWidth)
714cdf0e10cSrcweir                         });
715cdf0e10cSrcweir             }
716cdf0e10cSrcweir             catch (Exception exception)
717cdf0e10cSrcweir             {
718cdf0e10cSrcweir                 exception.printStackTrace(System.out);
719cdf0e10cSrcweir             }
720cdf0e10cSrcweir         }
721cdf0e10cSrcweir 
722cdf0e10cSrcweir         /**
723cdf0e10cSrcweir          * @returns true if the current condition is complete, all needed fields are filled with values.
724cdf0e10cSrcweir          * So we can enable the next.
725cdf0e10cSrcweir          */
isConditionComplete()726cdf0e10cSrcweir         boolean isConditionComplete()
727cdf0e10cSrcweir         {
728cdf0e10cSrcweir             try
729cdf0e10cSrcweir             {
730cdf0e10cSrcweir                 short[] SelFields = (short[]) AnyConverter.toArray(Helper.getUnoPropertyValue(UnoDialog.getModel(ControlElements[SOLSTFIELDNAME]), PropertyNames.SELECTED_ITEMS));
731cdf0e10cSrcweir                 if (SelFields.length > 0)
732cdf0e10cSrcweir                 {
733cdf0e10cSrcweir                     int nSelOperator = getSelectedOperator();
734cdf0e10cSrcweir                     // short[] SelOperator = (short[]) AnyConverter.toArray(Helper.getUnoPropertyValue(UnoDialog.getModel(ControlElements[SOLSTOPERATOR]), PropertyNames.SELECTED_ITEMS));
735cdf0e10cSrcweir                     if (nSelOperator == com.sun.star.sdb.SQLFilterOperator.SQLNULL
736cdf0e10cSrcweir                             || /* is null */ nSelOperator == com.sun.star.sdb.SQLFilterOperator.NOT_SQLNULL) /* is not null */
737cdf0e10cSrcweir 
738cdf0e10cSrcweir                     {
739cdf0e10cSrcweir                         // disable value field
740cdf0e10cSrcweir                         Helper.setUnoPropertyValue(UnoDialog.getModel(ControlElements[2]), PropertyNames.PROPERTY_ENABLED, Boolean.FALSE);
741cdf0e10cSrcweir                         Helper.setUnoPropertyValue(UnoDialog.getModel(ControlElements[SOTXTVALUE]), PropertyNames.PROPERTY_ENABLED, Boolean.FALSE);
742cdf0e10cSrcweir 
743cdf0e10cSrcweir                         return true;
744cdf0e10cSrcweir                     }
745cdf0e10cSrcweir                     else
746cdf0e10cSrcweir                     {
747cdf0e10cSrcweir                         // enable value field
748cdf0e10cSrcweir                         Helper.setUnoPropertyValue(UnoDialog.getModel(ControlElements[2]), PropertyNames.PROPERTY_ENABLED, Boolean.TRUE);
749cdf0e10cSrcweir                         Helper.setUnoPropertyValue(UnoDialog.getModel(ControlElements[SOTXTVALUE]), PropertyNames.PROPERTY_ENABLED, Boolean.TRUE);
750cdf0e10cSrcweir                     }
751cdf0e10cSrcweir                     if (nSelOperator != -1)
752cdf0e10cSrcweir                     {
753cdf0e10cSrcweir                         Object oValue = Helper.getUnoPropertyValue(UnoDialog.getModel(ControlElements[SOTXTVALUE]), "EffectiveValue");
754cdf0e10cSrcweir                         if (!AnyConverter.isVoid(oValue))
755cdf0e10cSrcweir                         {
756cdf0e10cSrcweir                             String sValue = (String.valueOf(oValue));
757cdf0e10cSrcweir                             return (!sValue.equals(PropertyNames.EMPTY_STRING));
758cdf0e10cSrcweir                         }
759cdf0e10cSrcweir                     }
760cdf0e10cSrcweir                 }
761cdf0e10cSrcweir                 return false;
762cdf0e10cSrcweir             }
763cdf0e10cSrcweir             catch (Exception exception)
764cdf0e10cSrcweir             {
765cdf0e10cSrcweir                 exception.printStackTrace(System.out);
766cdf0e10cSrcweir                 return false;
767cdf0e10cSrcweir             }
768cdf0e10cSrcweir         }
769cdf0e10cSrcweir 
setCondition(PropertyValue _filtercondition)770cdf0e10cSrcweir         protected void setCondition(PropertyValue _filtercondition)
771cdf0e10cSrcweir         {
772cdf0e10cSrcweir             try
773cdf0e10cSrcweir             {
774cdf0e10cSrcweir                 XListBox xFieldsListBox = UnoRuntime.queryInterface(XListBox.class, ControlElements[SOLSTFIELDNAME]);
775cdf0e10cSrcweir                 xFieldsListBox.selectItem(_filtercondition.Name, true);
776cdf0e10cSrcweir                 XListBox xOperatorListBox = UnoRuntime.queryInterface(XListBox.class, ControlElements[SOLSTOPERATOR]);
777cdf0e10cSrcweir                 xOperatorListBox.selectItemPos((short) (_filtercondition.Handle - 1), true);
778cdf0e10cSrcweir 
779cdf0e10cSrcweir                 if (AnyConverter.isString(_filtercondition.Value))
780cdf0e10cSrcweir                 {
781cdf0e10cSrcweir                     String sValue = AnyConverter.toString(_filtercondition.Value);
782cdf0e10cSrcweir                     if (sValue.indexOf("{D '") > -1)
783cdf0e10cSrcweir                     {
784cdf0e10cSrcweir                         sValue = JavaTools.replaceSubString(sValue, PropertyNames.EMPTY_STRING, "{D '");
785cdf0e10cSrcweir                         sValue = JavaTools.replaceSubString(sValue, PropertyNames.EMPTY_STRING, "' }");
786cdf0e10cSrcweir                         try
787cdf0e10cSrcweir                         {
788cdf0e10cSrcweir                             oQueryMetaData.getNumberFormatter().convertStringToNumber(iDateFormat, sValue);
789cdf0e10cSrcweir                         }
790cdf0e10cSrcweir                         catch (java.lang.Exception ex)
791cdf0e10cSrcweir                         {
792cdf0e10cSrcweir                             Logger.getLogger(FilterComponent.class.getName()).log(Level.SEVERE, null, ex);
793cdf0e10cSrcweir                         }
794cdf0e10cSrcweir                     }
795cdf0e10cSrcweir                     else if (sValue.indexOf("{T '") > -1)
796cdf0e10cSrcweir                     {
797cdf0e10cSrcweir                         sValue = JavaTools.replaceSubString(sValue, PropertyNames.EMPTY_STRING, "{T '");
798cdf0e10cSrcweir                         sValue = JavaTools.replaceSubString(sValue, PropertyNames.EMPTY_STRING, "' }");
799cdf0e10cSrcweir                         try
800cdf0e10cSrcweir                         {
801cdf0e10cSrcweir                             oQueryMetaData.getNumberFormatter().convertStringToNumber(iTimeFormat, sValue);
802cdf0e10cSrcweir                         }
803cdf0e10cSrcweir                         catch (java.lang.Exception ex)
804cdf0e10cSrcweir                         {
805cdf0e10cSrcweir                             Logger.getLogger(FilterComponent.class.getName()).log(Level.SEVERE, null, ex);
806cdf0e10cSrcweir                         }
807cdf0e10cSrcweir                     }
808cdf0e10cSrcweir                 }
809cdf0e10cSrcweir                 else if (AnyConverter.isBoolean(_filtercondition.Value))
810cdf0e10cSrcweir                 {
811cdf0e10cSrcweir                     boolean b = AnyConverter.toBoolean(_filtercondition.Value);
812cdf0e10cSrcweir                     double nValue = 0.0;
813cdf0e10cSrcweir                     if (b)
814cdf0e10cSrcweir                     {
815cdf0e10cSrcweir                         nValue = 1.0;
816cdf0e10cSrcweir                     }
817cdf0e10cSrcweir                     Helper.setUnoPropertyValue(UnoDialog.getModel(ControlElements[SOTXTVALUE]), "EffectiveValue", nValue);
818cdf0e10cSrcweir                 }
819cdf0e10cSrcweir                 else
820cdf0e10cSrcweir                 {
821cdf0e10cSrcweir                     Helper.setUnoPropertyValue(UnoDialog.getModel(ControlElements[SOTXTVALUE]), "EffectiveValue", _filtercondition.Value);
822cdf0e10cSrcweir                 }
823cdf0e10cSrcweir             }
824cdf0e10cSrcweir             catch (Exception e)
825cdf0e10cSrcweir             {
826cdf0e10cSrcweir                 e.printStackTrace(System.out);
827cdf0e10cSrcweir             }
828cdf0e10cSrcweir         }
829cdf0e10cSrcweir 
setFieldNames(String[] _FieldNames)830cdf0e10cSrcweir         protected void setFieldNames(String[] _FieldNames)
831cdf0e10cSrcweir         {
832cdf0e10cSrcweir             Helper.setUnoPropertyValue(UnoDialog.getModel(ControlElements[SOLSTFIELDNAME]), PropertyNames.STRING_ITEM_LIST, _FieldNames);
833cdf0e10cSrcweir             FieldNames = _FieldNames;
834cdf0e10cSrcweir         }
835cdf0e10cSrcweir 
isEnabled()836cdf0e10cSrcweir         protected boolean isEnabled()
837cdf0e10cSrcweir         {
838cdf0e10cSrcweir             return m_bEnabled;
839cdf0e10cSrcweir         }
840cdf0e10cSrcweir 
settovoid()841cdf0e10cSrcweir         private void settovoid()
842cdf0e10cSrcweir         {
843cdf0e10cSrcweir             WizardDialog.deselectListBox(ControlElements[SOLSTFIELDNAME]);
844cdf0e10cSrcweir             WizardDialog.deselectListBox(ControlElements[SOLSTOPERATOR]);
845cdf0e10cSrcweir             Helper.setUnoPropertyValue(UnoDialog.getModel(ControlElements[SOTXTVALUE]), "EffectiveValue", com.sun.star.uno.Any.VOID);
846cdf0e10cSrcweir         }
847cdf0e10cSrcweir 
setEnabled(boolean _bEnabled)848cdf0e10cSrcweir         private void setEnabled(boolean _bEnabled)
849cdf0e10cSrcweir         {
850cdf0e10cSrcweir             // enable all Controls Fieldname, operator, value
851cdf0e10cSrcweir             for (int i = 0; i < ControlElements.length; i++)
852cdf0e10cSrcweir             {
853cdf0e10cSrcweir                 Helper.setUnoPropertyValue(UnoDialog.getModel(ControlElements[i]), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(_bEnabled));
854cdf0e10cSrcweir             }
855cdf0e10cSrcweir             m_bEnabled = _bEnabled;
856cdf0e10cSrcweir             if (isEnabled())
857cdf0e10cSrcweir             {
858cdf0e10cSrcweir                 short[] iselected = new short[]
859cdf0e10cSrcweir                 {
860cdf0e10cSrcweir                 };
861cdf0e10cSrcweir                 try
862cdf0e10cSrcweir                 {
863cdf0e10cSrcweir                     iselected = (short[]) AnyConverter.toArray(Helper.getUnoPropertyValue(UnoDialog.getModel(ControlElements[SOLSTOPERATOR]), PropertyNames.SELECTED_ITEMS));
864cdf0e10cSrcweir                 }
865cdf0e10cSrcweir                 catch (Exception e)
866cdf0e10cSrcweir                 {
867cdf0e10cSrcweir                     e.printStackTrace(System.out);
868cdf0e10cSrcweir                 }
869cdf0e10cSrcweir                 if ((iselected.length) == 0)
870cdf0e10cSrcweir                 {
871cdf0e10cSrcweir                     Helper.setUnoPropertyValue(UnoDialog.getModel(ControlElements[SOLSTOPERATOR]), PropertyNames.SELECTED_ITEMS, new short[]
872cdf0e10cSrcweir                             {
873cdf0e10cSrcweir                                 0
874cdf0e10cSrcweir                             });
875cdf0e10cSrcweir                 }
876cdf0e10cSrcweir             }
877cdf0e10cSrcweir             else if (!isConditionComplete())
878cdf0e10cSrcweir             {
879cdf0e10cSrcweir                 WizardDialog.deselectListBox(ControlElements[SOLSTOPERATOR]);
880cdf0e10cSrcweir             }
881cdf0e10cSrcweir         }
882cdf0e10cSrcweir 
getSelectedFieldName()883cdf0e10cSrcweir         protected String getSelectedFieldName()
884cdf0e10cSrcweir         {
885cdf0e10cSrcweir             try
886cdf0e10cSrcweir             {
887cdf0e10cSrcweir                 short[] SelFields = (short[]) AnyConverter.toArray(Helper.getUnoPropertyValue(UnoDialog.getModel(ControlElements[SOLSTFIELDNAME]), PropertyNames.SELECTED_ITEMS));
888cdf0e10cSrcweir                 return FieldNames[SelFields[0]];
889cdf0e10cSrcweir             }
890cdf0e10cSrcweir             catch (Exception exception)
891cdf0e10cSrcweir             {
892cdf0e10cSrcweir                 exception.printStackTrace(System.out);
893cdf0e10cSrcweir             }
894cdf0e10cSrcweir             return null;
895cdf0e10cSrcweir         }
896cdf0e10cSrcweir 
897cdf0e10cSrcweir         // TODO: check if it is really useful to match the indices of the listbox the API constants
898cdf0e10cSrcweir         // =, <>, <, >, <=, >=, like, !like, is null, !is null
getSelectedOperator()899cdf0e10cSrcweir         protected short getSelectedOperator()
900cdf0e10cSrcweir         {
901cdf0e10cSrcweir             try
902cdf0e10cSrcweir             {
903cdf0e10cSrcweir                 short[] SelFields = (short[]) AnyConverter.toArray(Helper.getUnoPropertyValue(UnoDialog.getModel(ControlElements[SOLSTOPERATOR]), PropertyNames.SELECTED_ITEMS));
904cdf0e10cSrcweir                 switch (SelFields[0])
905cdf0e10cSrcweir                 {
906cdf0e10cSrcweir                     case 0:
907cdf0e10cSrcweir                         return com.sun.star.sdb.SQLFilterOperator.EQUAL;
908cdf0e10cSrcweir                     case 1:
909cdf0e10cSrcweir                         return com.sun.star.sdb.SQLFilterOperator.NOT_EQUAL;
910cdf0e10cSrcweir                     case 2:
911cdf0e10cSrcweir                         return com.sun.star.sdb.SQLFilterOperator.LESS;
912cdf0e10cSrcweir                     case 3:
913cdf0e10cSrcweir                         return com.sun.star.sdb.SQLFilterOperator.GREATER;
914cdf0e10cSrcweir                     case 4:
915cdf0e10cSrcweir                         return com.sun.star.sdb.SQLFilterOperator.LESS_EQUAL;
916cdf0e10cSrcweir                     case 5:
917cdf0e10cSrcweir                         return com.sun.star.sdb.SQLFilterOperator.GREATER_EQUAL;
918cdf0e10cSrcweir                     case 6:
919cdf0e10cSrcweir                         return com.sun.star.sdb.SQLFilterOperator.LIKE;
920cdf0e10cSrcweir                     case 7:
921cdf0e10cSrcweir                         return com.sun.star.sdb.SQLFilterOperator.NOT_LIKE;
922cdf0e10cSrcweir                     case 8:
923cdf0e10cSrcweir                         return com.sun.star.sdb.SQLFilterOperator.SQLNULL;
924cdf0e10cSrcweir                     case 9:
925cdf0e10cSrcweir                         return com.sun.star.sdb.SQLFilterOperator.NOT_SQLNULL;
926cdf0e10cSrcweir                     default:
927cdf0e10cSrcweir                         return -1;
928cdf0e10cSrcweir                 }
929cdf0e10cSrcweir             }
930cdf0e10cSrcweir             catch (Exception exception)
931cdf0e10cSrcweir             {
932cdf0e10cSrcweir                 exception.printStackTrace(System.out);
933cdf0e10cSrcweir             }
934cdf0e10cSrcweir             return -1;
935cdf0e10cSrcweir         }
936cdf0e10cSrcweir 
937cdf0e10cSrcweir         // TODO make a difference between Text and Numbers
getValue()938cdf0e10cSrcweir         protected Object getValue()
939cdf0e10cSrcweir         {
940cdf0e10cSrcweir             return (Helper.getUnoPropertyValue(UnoDialog.getModel(ControlElements[SOTXTVALUE]), "EffectiveValue"));
941cdf0e10cSrcweir         }
942cdf0e10cSrcweir 
getText()943cdf0e10cSrcweir         protected Object getText()
944cdf0e10cSrcweir         {
945cdf0e10cSrcweir             return (Helper.getUnoPropertyValue(UnoDialog.getModel(ControlElements[SOTXTVALUE]), "Text"));
946cdf0e10cSrcweir         }
947cdf0e10cSrcweir 
getDateTimeString(boolean bgetDate)948cdf0e10cSrcweir         protected String getDateTimeString(boolean bgetDate)
949cdf0e10cSrcweir         {
950cdf0e10cSrcweir             double dblValue = ((Double) getValue()).doubleValue();
951cdf0e10cSrcweir             NumberFormatter oNumberFormatter = oQueryMetaData.getNumberFormatter();
952cdf0e10cSrcweir             return oNumberFormatter.convertNumberToString(iDateTimeFormat, dblValue);
953cdf0e10cSrcweir         }
954cdf0e10cSrcweir     }
955cdf0e10cSrcweir }
956