1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package com.sun.star.wizards.report;
24 
25 import com.sun.star.wizards.common.JavaTools;
26 import com.sun.star.wizards.common.PropertyNames;
27 import com.sun.star.wizards.ui.*;
28 import com.sun.star.wizards.db.*;
29 
30 import java.util.Vector;
31 
32 public class GroupFieldHandler extends FieldSelection
33 {
34 
35     private IReportDocument CurReportDocument;
36     private Vector GroupFieldVector = new Vector();
37     private QueryMetaData CurDBMetaData;
38     private WizardDialog oWizardDialog;
39     private static final short MAXSELFIELDS = 4;
40 
GroupFieldHandler(IReportDocument _CurReportDocument, WizardDialog _CurUnoDialog)41     public GroupFieldHandler(IReportDocument _CurReportDocument, WizardDialog _CurUnoDialog)
42     {
43         super(_CurUnoDialog, ReportWizard.SOGROUPPAGE, 95, 27, 210, 127,
44                 _CurUnoDialog.m_oResource.getResText(UIConsts.RID_REPORT + 19),
45                 _CurUnoDialog.m_oResource.getResText(UIConsts.RID_REPORT + 50), 34340, false);
46 
47         try
48         {
49             this.oWizardDialog = _CurUnoDialog;
50             this.CurReportDocument = _CurReportDocument;
51             this.CurDBMetaData = CurReportDocument.getRecordParser();
52             CurUnoDialog.setControlProperty("lstFields_2", "MultiSelection", Boolean.FALSE);
53             CurUnoDialog.setControlProperty("lstSelFields_2", "MultiSelection", Boolean.FALSE);
54             addFieldSelectionListener(new FieldSelectionListener());
55             String sNote = ReportWizard.getBlindTextNote(_CurReportDocument, _CurUnoDialog.m_oResource);
56             CurUnoDialog.insertControlModel("com.sun.star.awt.UnoControlFixedTextModel", "lblBlindTextNote_1",
57                     new String[]
58                     {
59                         PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_MULTILINE, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_WIDTH
60                     },
61                     new Object[]
62                     {
63                             Boolean.FALSE, 18, sNote, Boolean.TRUE, 95, 158, new Integer(ReportWizard.SOGROUPPAGE), 209
64                     });
65         }
66         catch (Exception exception)
67         {
68             exception.printStackTrace(System.out);
69         }
70     }
71 
isGroupField(String _FieldName)72     public boolean isGroupField(String _FieldName)
73     {
74         return (JavaTools.FieldInList(CurDBMetaData.GroupFieldNames, _FieldName) != -1);
75     }
76 
initialize()77     public void initialize()
78     {
79         try
80         {
81             Vector NormalFieldsVector = new Vector();
82             Vector SelFieldsVector = new Vector();
83             String[] sFieldNames = CurDBMetaData.getFieldNames();
84             for (int i = 0; i < sFieldNames.length; i++)
85             {
86                 String sfieldtitle = sFieldNames[i]; // CurDBMetaData.getFieldTitle(sFieldNames[i]);
87                 if (isGroupField(sFieldNames[i]))
88                 {
89                     SelFieldsVector.add(sfieldtitle);
90                 }
91                 else
92                 {
93                     NormalFieldsVector.add(sfieldtitle);
94                 }
95             }
96             String[] SelFields = new String[SelFieldsVector.size()];
97             SelFieldsVector.toArray(SelFields);
98             String[] NormalFields = new String[NormalFieldsVector.size()];
99             NormalFieldsVector.toArray(NormalFields);
100             super.initialize(NormalFields, SelFields, true);
101         }
102         catch (Exception exception)
103         {
104             exception.printStackTrace(System.out);
105         }
106     }
107 
removeGroupFieldNames()108     public void removeGroupFieldNames()
109     {
110         emptyFieldsListBoxes();
111         GroupFieldVector.removeAllElements();
112         CurUnoDialog.setControlProperty("lblBlindTextNote_1", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE);
113     }
114 
getGroupFieldNames(CommandMetaData CurDBMetaData)115     public void getGroupFieldNames(CommandMetaData CurDBMetaData)
116     {
117         String[] GroupFieldNames = new String[GroupFieldVector.size()];
118         GroupFieldVector.copyInto(GroupFieldNames);
119         CurDBMetaData.GroupFieldNames = GroupFieldNames;
120     }
121     // @Override
toggleListboxButtons(short iFieldsSelIndex, short iSelFieldsSelIndex)122     protected void toggleListboxButtons(short iFieldsSelIndex, short iSelFieldsSelIndex)
123     {
124         super.toggleListboxButtons(iFieldsSelIndex, iSelFieldsSelIndex);
125         int iSelCount = xSelectedFieldsListBox.getItemCount();
126         if (iSelCount >= MAXSELFIELDS)
127             {
128             CurUnoDialog.setControlProperty("cmdMoveSelected" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, Boolean.FALSE);
129         }
130     }
131 
selectFields(boolean bMoveAll)132     public void selectFields(boolean bMoveAll)
133     {
134         int iSelCount = xSelectedFieldsListBox.getItemCount();
135         if (iSelCount < MAXSELFIELDS)
136             {
137             super.selectFields(bMoveAll);
138         }
139 
140     }
141 
142     /* protected */ class FieldSelectionListener implements com.sun.star.wizards.ui.XFieldSelectionListener
143     {
144 
moveItemDown(String Selitem)145         public void moveItemDown(String Selitem)
146         {
147             CurReportDocument.refreshGroupFields(xSelectedFieldsListBox.getItems());
148         }
149 
moveItemUp(String item)150         public void moveItemUp(String item)
151         {
152             CurReportDocument.refreshGroupFields(xSelectedFieldsListBox.getItems());
153         }
154 
shiftFromLeftToRight(String[] Selitems, String[] Newitems)155         public void shiftFromLeftToRight(String[] Selitems, String[] Newitems)
156         {
157             String CurGroupTitle = Selitems[0];
158             int iSelCount = xSelectedFieldsListBox.getItemCount();
159             String[] CurGroupNames = xFieldsListBox.getItems();
160             CurReportDocument.liveupdate_addGroupNametoDocument(CurGroupNames, CurGroupTitle, GroupFieldVector, CurReportDocument.getReportPath(), iSelCount);
161             CurUnoDialog.setControlProperty("lblBlindTextNote_1", PropertyNames.PROPERTY_ENABLED, Boolean.TRUE);
162             if (iSelCount >= MAXSELFIELDS)
163             {
164                 toggleMoveButtons(false, false);
165             }
166         }
167 
shiftFromRightToLeft(String[] OldSelitems, String[] Newitems)168         public void shiftFromRightToLeft(String[] OldSelitems, String[] Newitems)
169         {
170             int iSelPos = OldSelitems.length;
171             if (iSelPos > 0)
172             {
173                 String OldGroupTitle = OldSelitems[0];
174                 String[] NewSelList = xSelectedFieldsListBox.getItems();
175                 CurReportDocument.liveupdate_removeGroupName(NewSelList, OldGroupTitle, GroupFieldVector);
176                 String[] NewSelGroupNames = xSelectedFieldsListBox.getItems();
177                 CurUnoDialog.setControlProperty("lblBlindTextNote_1", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(NewSelGroupNames.length == 0));
178 
179             // CurReportDocument.refreshGroupFields(xSelectedFieldsListBox.getItems());
180             }
181         }
182 
getID()183         public int getID()
184         {
185             // TODO: here is a good place for a comment, isn't it?
186             return 2;
187         }
188 
setID(String sIncSuffix)189         public void setID(String sIncSuffix)
190         {
191         }
192     }
193 }
194