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.ui; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import java.util.ArrayList; 26cdf0e10cSrcweir import java.util.Vector; 27cdf0e10cSrcweir import com.sun.star.wizards.common.*; 28cdf0e10cSrcweir import com.sun.star.wizards.db.*; 29cdf0e10cSrcweir import com.sun.star.lang.EventObject; 30cdf0e10cSrcweir import com.sun.star.beans.*; 31cdf0e10cSrcweir import com.sun.star.sdbc.SQLException; 32cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 33cdf0e10cSrcweir 34cdf0e10cSrcweir import com.sun.star.awt.*; 35cdf0e10cSrcweir 36cdf0e10cSrcweir public class AggregateComponent extends ControlScroller 37cdf0e10cSrcweir { 38cdf0e10cSrcweir 39cdf0e10cSrcweir String[] sFunctions; 40cdf0e10cSrcweir String[] sFunctionOperators = new String[] 41cdf0e10cSrcweir { 42cdf0e10cSrcweir "SUM", "AVG", "MIN", "MAX" 43cdf0e10cSrcweir }; 44cdf0e10cSrcweir QueryMetaData CurDBMetaData; 45cdf0e10cSrcweir XButton optDetailQuery; 46cdf0e10cSrcweir XButton optSummaryQuery; 47cdf0e10cSrcweir String soptDetailQuery; 48cdf0e10cSrcweir String soptSummaryQuery; 49cdf0e10cSrcweir String slblAggregate; 50cdf0e10cSrcweir String slblFieldNames; 51cdf0e10cSrcweir String sDuplicateAggregateFunction; 52cdf0e10cSrcweir int Count; 53cdf0e10cSrcweir int iQueryType; 54cdf0e10cSrcweir final int SOADDROW = 1; 55cdf0e10cSrcweir final int SOREMOVEROW = 2; 56cdf0e10cSrcweir final int CONTROLROWDIST = 18; 57cdf0e10cSrcweir Vector ControlRowVector; 58cdf0e10cSrcweir String OPTIONBUTTONDETAILQUERY_ITEM_CHANGED = "toggleComponent"; 59cdf0e10cSrcweir String OPTIONBUTTONSUMMARYQUERY_ITEM_CHANGED = "toggleComponent"; 60cdf0e10cSrcweir String LISTBOXFUNCTIONS_ACTION_PERFORMED; 61cdf0e10cSrcweir String LISTBOXFUNCTIONS_ITEM_CHANGED; 62cdf0e10cSrcweir String LISTBOXFIELDNAMES_ACTION_PERFORMED; 63cdf0e10cSrcweir String LISTBOXFIELDNAMES_ITEM_CHANGED; 64cdf0e10cSrcweir String COMMANDBUTTONPLUS_ACTION_PERFORMED = "addRow"; 65cdf0e10cSrcweir String COMMANDBUTTONMINUS_ACTION_PERFORMED = "removeRow"; 66cdf0e10cSrcweir Vector ControlRows; 67cdf0e10cSrcweir int curHelpID; 68cdf0e10cSrcweir int lastHelpIndex; 69cdf0e10cSrcweir 70cdf0e10cSrcweir /** Creates a new instance of AggrgateComponent */ AggregateComponent(WizardDialog _CurUnoDialog, QueryMetaData _CurDBMetaData, int _iStep, int _iPosX, int _iPosY, int _iWidth, int _uitextfieldcount, int _firstHelpID)71cdf0e10cSrcweir public AggregateComponent(WizardDialog _CurUnoDialog, QueryMetaData _CurDBMetaData, int _iStep, int _iPosX, int _iPosY, int _iWidth, int _uitextfieldcount, int _firstHelpID) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir super(_CurUnoDialog, _CurDBMetaData.xMSF, _iStep, _iPosX + 10, _iPosY, _iWidth - 12, _uitextfieldcount, 18, _firstHelpID + 2); 74cdf0e10cSrcweir try 75cdf0e10cSrcweir { 76cdf0e10cSrcweir curHelpID = _firstHelpID; 77cdf0e10cSrcweir this.CurDBMetaData = _CurDBMetaData; 78cdf0e10cSrcweir Count = 1; 79cdf0e10cSrcweir optDetailQuery = CurUnoDialog.insertRadioButton("optDetailQuery", 0, new ActionListenerImpl(), 80cdf0e10cSrcweir new String[] 81cdf0e10cSrcweir { 82cdf0e10cSrcweir 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 83cdf0e10cSrcweir }, 84cdf0e10cSrcweir new Object[] 85cdf0e10cSrcweir { 86cdf0e10cSrcweir 8, HelpIds.getHelpIdString(curHelpID), soptDetailQuery, new Integer(_iPosX), new Integer(iCompPosY - 42), new Short((short) 1), IStep, new Short(curtabindex++), new Integer(iCompWidth) 87cdf0e10cSrcweir }); 88cdf0e10cSrcweir 89cdf0e10cSrcweir optSummaryQuery = CurUnoDialog.insertRadioButton("optSummaryQuery", 0, new ActionListenerImpl(), 90cdf0e10cSrcweir new String[] 91cdf0e10cSrcweir { 92cdf0e10cSrcweir PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_MULTILINE, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 93cdf0e10cSrcweir }, 94cdf0e10cSrcweir new Object[] 95cdf0e10cSrcweir { 96cdf0e10cSrcweir 16, HelpIds.getHelpIdString(curHelpID + 1), soptSummaryQuery, Boolean.TRUE, new Integer(_iPosX), new Integer(iCompPosY - 32), IStep, new Short(curtabindex++), new Integer(iCompWidth) 97cdf0e10cSrcweir }); 98cdf0e10cSrcweir CurUnoDialog.insertLabel("lblAggregate", 99cdf0e10cSrcweir new String[] 100cdf0e10cSrcweir { 101cdf0e10cSrcweir PropertyNames.PROPERTY_HEIGHT, 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 8, slblAggregate, new Integer(iCompPosX + 5), new Integer(iCompPosY - 10), IStep, new Short(curtabindex++), 90 106cdf0e10cSrcweir }); 107cdf0e10cSrcweir CurUnoDialog.insertLabel("lblFieldnames", 108cdf0e10cSrcweir new String[] 109cdf0e10cSrcweir { 110cdf0e10cSrcweir PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 111cdf0e10cSrcweir }, 112cdf0e10cSrcweir new Object[] 113cdf0e10cSrcweir { 114cdf0e10cSrcweir 8, slblFieldNames, new Integer(iCompPosX + 101), new Integer(iCompPosY - 10), IStep, new Short(curtabindex++), 90 115cdf0e10cSrcweir }); 116cdf0e10cSrcweir this.setTotalFieldCount(1); 117cdf0e10cSrcweir FontDescriptor oFontDescriptor = new FontDescriptor(); 118cdf0e10cSrcweir oFontDescriptor.Weight = com.sun.star.awt.FontWeight.BOLD; 119cdf0e10cSrcweir oFontDescriptor.Height = (short) 14; 120cdf0e10cSrcweir 121cdf0e10cSrcweir int iButtonPosY = iCompPosY + iCompHeight + 3; 122cdf0e10cSrcweir CurUnoDialog.insertButton("btnplus", SOADDROW, new ActionListenerImpl(), 123cdf0e10cSrcweir new String[] 124cdf0e10cSrcweir { 125cdf0e10cSrcweir PropertyNames.FONT_DESCRIPTOR, 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 126cdf0e10cSrcweir }, 127cdf0e10cSrcweir new Object[] 128cdf0e10cSrcweir { 129cdf0e10cSrcweir oFontDescriptor, 14, HelpIds.getHelpIdString(lastHelpIndex + 1), "+", new Integer(_iPosX + iCompWidth - 36), new Integer(iButtonPosY), IStep, new Short((curtabindex++)), 16 130cdf0e10cSrcweir }); 131cdf0e10cSrcweir CurUnoDialog.insertButton("btnminus", SOREMOVEROW, new ActionListenerImpl(), 132cdf0e10cSrcweir new String[] 133cdf0e10cSrcweir { 134cdf0e10cSrcweir PropertyNames.FONT_DESCRIPTOR, 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 135cdf0e10cSrcweir }, 136cdf0e10cSrcweir new Object[] 137cdf0e10cSrcweir { 138cdf0e10cSrcweir oFontDescriptor, 14, HelpIds.getHelpIdString(lastHelpIndex + 2), "-", new Integer(_iPosX + iCompWidth - 16), new Integer(iButtonPosY), IStep, new Short(curtabindex++), 16 139cdf0e10cSrcweir }); 140cdf0e10cSrcweir CurDBMetaData.Type = getQueryType(); 141cdf0e10cSrcweir } 142cdf0e10cSrcweir catch (com.sun.star.uno.Exception exception) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir Resource.showCommonResourceError(CurDBMetaData.xMSF); 145cdf0e10cSrcweir } 146cdf0e10cSrcweir } 147cdf0e10cSrcweir getQueryType()148cdf0e10cSrcweir public int getQueryType() 149cdf0e10cSrcweir { 150cdf0e10cSrcweir if (((Short) CurUnoDialog.getControlProperty("optDetailQuery", PropertyNames.PROPERTY_STATE)).intValue() == 1) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir return QueryMetaData.QueryType.SODETAILQUERY; 153cdf0e10cSrcweir } 154cdf0e10cSrcweir else 155cdf0e10cSrcweir { 156cdf0e10cSrcweir return QueryMetaData.QueryType.SOSUMMARYQUERY; 157cdf0e10cSrcweir } 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir class ActionListenerImpl implements com.sun.star.awt.XActionListener 161cdf0e10cSrcweir { 162cdf0e10cSrcweir disposing(EventObject eventObject)163cdf0e10cSrcweir public void disposing(EventObject eventObject) 164cdf0e10cSrcweir { 165cdf0e10cSrcweir } 166cdf0e10cSrcweir actionPerformed(com.sun.star.awt.ActionEvent actionEvent)167cdf0e10cSrcweir public void actionPerformed(com.sun.star.awt.ActionEvent actionEvent) 168cdf0e10cSrcweir { 169cdf0e10cSrcweir try 170cdf0e10cSrcweir { 171cdf0e10cSrcweir int iKey = CurUnoDialog.getControlKey(actionEvent.Source, CurUnoDialog.ControlList); 172cdf0e10cSrcweir switch (iKey) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir case SOADDROW: 175cdf0e10cSrcweir addRow(); 176cdf0e10cSrcweir break; 177cdf0e10cSrcweir 178cdf0e10cSrcweir case SOREMOVEROW: 179cdf0e10cSrcweir removeRow(); 180cdf0e10cSrcweir break; 181cdf0e10cSrcweir 182cdf0e10cSrcweir default: 183cdf0e10cSrcweir toggleComponent(); 184cdf0e10cSrcweir break; 185cdf0e10cSrcweir } 186cdf0e10cSrcweir } 187cdf0e10cSrcweir catch (Exception exception) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir exception.printStackTrace(System.out); 190cdf0e10cSrcweir } 191cdf0e10cSrcweir } 192cdf0e10cSrcweir } 193cdf0e10cSrcweir getCount()194cdf0e10cSrcweir public int getCount() 195cdf0e10cSrcweir { 196cdf0e10cSrcweir return Count; 197cdf0e10cSrcweir } 198cdf0e10cSrcweir insertControlGroup(int i, int ypos)199cdf0e10cSrcweir protected void insertControlGroup(int i, int ypos) 200cdf0e10cSrcweir { 201cdf0e10cSrcweir if (i == 0) 202cdf0e10cSrcweir { 203cdf0e10cSrcweir int BaseID = 2300; 204cdf0e10cSrcweir soptDetailQuery = CurUnoDialog.m_oResource.getResText(BaseID + 11); 205cdf0e10cSrcweir soptSummaryQuery = CurUnoDialog.m_oResource.getResText(BaseID + 12); 206cdf0e10cSrcweir slblAggregate = CurUnoDialog.m_oResource.getResText(BaseID + 16); 207cdf0e10cSrcweir slblFieldNames = CurUnoDialog.m_oResource.getResText(BaseID + 17); 208cdf0e10cSrcweir sFunctions = CurUnoDialog.m_oResource.getResArray(BaseID + 40, 4); 209cdf0e10cSrcweir 210cdf0e10cSrcweir sDuplicateAggregateFunction = CurUnoDialog.m_oResource.getResText(BaseID + 90); 211cdf0e10cSrcweir } 212cdf0e10cSrcweir if (ControlRowVector == null) 213cdf0e10cSrcweir { 214cdf0e10cSrcweir ControlRowVector = new Vector(); 215cdf0e10cSrcweir } 216cdf0e10cSrcweir int locHelpID = curHelpIndex + (i * 2); 217cdf0e10cSrcweir ControlRow oControlRow = new ControlRow(i, ypos, locHelpID); 218cdf0e10cSrcweir ControlRowVector.add(oControlRow); 219cdf0e10cSrcweir } 220cdf0e10cSrcweir setControlGroupVisible(int _index, boolean _bIsVisible)221cdf0e10cSrcweir protected void setControlGroupVisible(int _index, boolean _bIsVisible) 222cdf0e10cSrcweir { 223cdf0e10cSrcweir ControlRow oControlRow = (ControlRow) ControlRowVector.elementAt(_index); 224cdf0e10cSrcweir oControlRow.setVisible(_bIsVisible); 225cdf0e10cSrcweir if (_index >= (this.CurDBMetaData.AggregateFieldNames.length)) 226cdf0e10cSrcweir { 227cdf0e10cSrcweir oControlRow.settovoid(); 228cdf0e10cSrcweir } 229cdf0e10cSrcweir } 230cdf0e10cSrcweir addRow()231cdf0e10cSrcweir protected void addRow() 232cdf0e10cSrcweir { 233cdf0e10cSrcweir int fieldcount = super.getTotalFieldCount(); 234cdf0e10cSrcweir registerControlGroupAtIndex(fieldcount); 235cdf0e10cSrcweir if (fieldcount < super.getBlockIncrementation()) 236cdf0e10cSrcweir { 237cdf0e10cSrcweir ControlRow oControlRow = (ControlRow) ControlRowVector.elementAt(fieldcount); 238cdf0e10cSrcweir oControlRow.setVisible(true); 239cdf0e10cSrcweir oControlRow.settovoid(); 240cdf0e10cSrcweir } 241cdf0e10cSrcweir else 242cdf0e10cSrcweir { 243cdf0e10cSrcweir ControlRow oControlRow = (ControlRow) ControlRowVector.elementAt(super.getBlockIncrementation() - 1); 244cdf0e10cSrcweir super.setScrollValue(getScrollValue() + 1, (fieldcount + 1)); 245cdf0e10cSrcweir oControlRow.settovoid(); 246cdf0e10cSrcweir } 247cdf0e10cSrcweir fieldcount++; 248cdf0e10cSrcweir super.setTotalFieldCount(fieldcount); 249cdf0e10cSrcweir toggleButtons(); 250cdf0e10cSrcweir CurUnoDialog.repaintDialogStep(); 251cdf0e10cSrcweir } 252cdf0e10cSrcweir removeRow()253cdf0e10cSrcweir protected void removeRow() 254cdf0e10cSrcweir { 255cdf0e10cSrcweir int fieldcount = super.getTotalFieldCount(); 256cdf0e10cSrcweir if (fieldcount > 0) 257cdf0e10cSrcweir { 258cdf0e10cSrcweir ControlRow oControlRow; 259cdf0e10cSrcweir fieldcount--; 260cdf0e10cSrcweir if ((fieldcount + 1) <= super.getBlockIncrementation()) 261cdf0e10cSrcweir { 262cdf0e10cSrcweir oControlRow = (ControlRow) ControlRowVector.elementAt(fieldcount); 263cdf0e10cSrcweir oControlRow.setVisible(false); 264cdf0e10cSrcweir } 265cdf0e10cSrcweir super.setScrollValue(getScrollValue() - 1, (fieldcount)); 266cdf0e10cSrcweir super.unregisterControlGroup(fieldcount); 267cdf0e10cSrcweir 268cdf0e10cSrcweir } 269cdf0e10cSrcweir toggleButtons(); 270cdf0e10cSrcweir CurUnoDialog.repaintDialogStep(); 271cdf0e10cSrcweir } 272cdf0e10cSrcweir toggleButtons()273cdf0e10cSrcweir protected void toggleButtons() 274cdf0e10cSrcweir { 275cdf0e10cSrcweir ControlRow curcontrolrow = null; 276cdf0e10cSrcweir boolean biscomplete = true; 277cdf0e10cSrcweir CurDBMetaData.Type = getQueryType(); 278cdf0e10cSrcweir CurUnoDialog.setControlProperty("btnminus", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf((super.getTotalFieldCount() > 0) && (CurDBMetaData.Type == QueryMetaData.QueryType.SOSUMMARYQUERY))); 279cdf0e10cSrcweir int fieldcount = super.getCurFieldCount(); 280cdf0e10cSrcweir if (fieldcount > 0) 281cdf0e10cSrcweir { 282cdf0e10cSrcweir curcontrolrow = (ControlRow) ControlRowVector.elementAt(super.getCurFieldCount() - 1); 283cdf0e10cSrcweir biscomplete = curcontrolrow.isComplete(); 284cdf0e10cSrcweir } 285cdf0e10cSrcweir CurUnoDialog.setControlProperty("btnplus", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(biscomplete && (CurDBMetaData.Type == QueryMetaData.QueryType.SOSUMMARYQUERY))); 286cdf0e10cSrcweir togglefollowingDialogSteps(); 287cdf0e10cSrcweir } 288cdf0e10cSrcweir toggleComponent()289cdf0e10cSrcweir public void toggleComponent() 290cdf0e10cSrcweir { 291cdf0e10cSrcweir CurDBMetaData.Type = getQueryType(); 292cdf0e10cSrcweir boolean benableComponent = isAggregateComponentEnabled(); 293cdf0e10cSrcweir CurUnoDialog.setControlProperty("lblAggregate", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(benableComponent)); 294cdf0e10cSrcweir CurUnoDialog.setControlProperty("lblFieldnames", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(benableComponent)); 295cdf0e10cSrcweir toggleButtons(); 296cdf0e10cSrcweir super.toggleComponent(benableComponent); 297cdf0e10cSrcweir super.toggleControls(benableComponent); 298cdf0e10cSrcweir togglefollowingDialogSteps(); 299cdf0e10cSrcweir } 300cdf0e10cSrcweir isAggregateComponentEnabled()301cdf0e10cSrcweir private boolean isAggregateComponentEnabled() 302cdf0e10cSrcweir { 303cdf0e10cSrcweir return (CurDBMetaData.Type == QueryMetaData.QueryType.SOSUMMARYQUERY); 304cdf0e10cSrcweir } 305cdf0e10cSrcweir isGroupingpossible()306cdf0e10cSrcweir public boolean isGroupingpossible() 307cdf0e10cSrcweir { 308cdf0e10cSrcweir try 309cdf0e10cSrcweir { 310cdf0e10cSrcweir boolean benableGroupPage = isAggregateComponentEnabled() && CurDBMetaData.xDBMetaData.supportsGroupBy() && hasonlycompletefunctions(); 311cdf0e10cSrcweir String[][] sAggregateFieldNames = this.getAggregateFieldNames(); 312cdf0e10cSrcweir if (benableGroupPage) 313cdf0e10cSrcweir { 314cdf0e10cSrcweir for (int i = 0; i < CurDBMetaData.NumericFieldNames.length; i++) 315cdf0e10cSrcweir { 316cdf0e10cSrcweir boolean bisthere = (JavaTools.FieldInTable(sAggregateFieldNames, CurDBMetaData.NumericFieldNames[i]) > -1); 317cdf0e10cSrcweir if (!bisthere) 318cdf0e10cSrcweir { 319cdf0e10cSrcweir return true; 320cdf0e10cSrcweir } 321cdf0e10cSrcweir } 322cdf0e10cSrcweir } 323cdf0e10cSrcweir } 324cdf0e10cSrcweir catch (SQLException e) 325cdf0e10cSrcweir { 326cdf0e10cSrcweir e.printStackTrace(System.out); 327cdf0e10cSrcweir } 328cdf0e10cSrcweir return false; 329cdf0e10cSrcweir } 330cdf0e10cSrcweir togglefollowingDialogSteps()331cdf0e10cSrcweir private void togglefollowingDialogSteps() 332cdf0e10cSrcweir { 333cdf0e10cSrcweir boolean benabletherest = true; 334cdf0e10cSrcweir boolean benableGroupPage = isGroupingpossible(); 335cdf0e10cSrcweir CurUnoDialog.setStepEnabled(UIConsts.SOGROUPSELECTIONPAGE, benableGroupPage); 336cdf0e10cSrcweir CurUnoDialog.setStepEnabled(UIConsts.SOGROUPFILTERPAGE, benableGroupPage && CurDBMetaData.GroupFieldNames.length > 0); 337cdf0e10cSrcweir if (isAggregateComponentEnabled()) 338cdf0e10cSrcweir { 339cdf0e10cSrcweir benabletherest = hasonlycompletefunctions(); 340cdf0e10cSrcweir } 341cdf0e10cSrcweir CurUnoDialog.enablefromStep(UIConsts.SOTITLESPAGE, benabletherest); 342cdf0e10cSrcweir CurUnoDialog.enableNextButton(benabletherest); 343cdf0e10cSrcweir } 344cdf0e10cSrcweir hideControlRowsfromindex(int _index)345cdf0e10cSrcweir private void hideControlRowsfromindex(int _index) 346cdf0e10cSrcweir { 347cdf0e10cSrcweir if (_index < this.ControlRowVector.size()) 348cdf0e10cSrcweir { 349cdf0e10cSrcweir for (int i = _index; i < ControlRowVector.size(); i++) 350cdf0e10cSrcweir { 351cdf0e10cSrcweir ControlRow oControlRow = (ControlRow) ControlRowVector.elementAt(i); 352cdf0e10cSrcweir // if (i == _index) 353cdf0e10cSrcweir // oControlRow.settovoid(); 354cdf0e10cSrcweir // else 355cdf0e10cSrcweir oControlRow.setVisible(false); 356cdf0e10cSrcweir } 357cdf0e10cSrcweir } 358cdf0e10cSrcweir 359cdf0e10cSrcweir } 360cdf0e10cSrcweir getAggregateFieldNames()361cdf0e10cSrcweir public String[][] getAggregateFieldNames() 362cdf0e10cSrcweir { 363cdf0e10cSrcweir try 364cdf0e10cSrcweir { 365cdf0e10cSrcweir CurDBMetaData.Type = getQueryType(); 366cdf0e10cSrcweir if (CurDBMetaData.Type == QueryMetaData.QueryType.SOSUMMARYQUERY) 367cdf0e10cSrcweir { 368cdf0e10cSrcweir ArrayList<String[]> aggregatevector = new ArrayList<String[]>(); 369cdf0e10cSrcweir PropertyValue[][] aggregatelist = this.getScrollFieldValues(); 370cdf0e10cSrcweir PropertyValue[] currowproperties; 371cdf0e10cSrcweir PropertyValue curaggregateproperty; 372cdf0e10cSrcweir if (CurDBMetaData.AggregateFieldNames != null) 373cdf0e10cSrcweir { 374cdf0e10cSrcweir for (int i = 0; i < aggregatelist.length; i++) 375cdf0e10cSrcweir { 376cdf0e10cSrcweir currowproperties = aggregatelist[i]; 377cdf0e10cSrcweir if ((currowproperties[0].Value != null) && (currowproperties[1].Value != null)) 378cdf0e10cSrcweir { 379cdf0e10cSrcweir short[] iselfield = (short[]) AnyConverter.toArray(currowproperties[1].Value); 380cdf0e10cSrcweir short[] iselfunction = (short[]) AnyConverter.toArray(currowproperties[0].Value); 381cdf0e10cSrcweir if ((iselfield.length > 0) && (iselfunction.length > 0)) 382cdf0e10cSrcweir { 383cdf0e10cSrcweir String[] curaggregatename = new String[2]; 384cdf0e10cSrcweir curaggregatename[0] = CurDBMetaData.NumericFieldNames[iselfield[0]]; 385cdf0e10cSrcweir curaggregatename[1] = this.sFunctionOperators[iselfunction[0]]; 386cdf0e10cSrcweir aggregatevector.add(curaggregatename); 387cdf0e10cSrcweir } 388cdf0e10cSrcweir } 389cdf0e10cSrcweir } 390cdf0e10cSrcweir } 391cdf0e10cSrcweir CurDBMetaData.AggregateFieldNames = new String[aggregatevector.size()][2]; 392cdf0e10cSrcweir aggregatevector.toArray(CurDBMetaData.AggregateFieldNames); 393cdf0e10cSrcweir } 394cdf0e10cSrcweir 395cdf0e10cSrcweir int iduplicate = JavaTools.getDuplicateFieldIndex(CurDBMetaData.AggregateFieldNames); 396cdf0e10cSrcweir if (iduplicate != -1) 397cdf0e10cSrcweir { 398cdf0e10cSrcweir sDuplicateAggregateFunction = JavaTools.replaceSubString(sDuplicateAggregateFunction, CurDBMetaData.AggregateFieldNames[iduplicate][0], "<NUMERICFIELD>"); 399cdf0e10cSrcweir int index = JavaTools.FieldInList(sFunctionOperators, CurDBMetaData.AggregateFieldNames[iduplicate][1]); 400cdf0e10cSrcweir String sDisplayFunction = sFunctions[index]; 401cdf0e10cSrcweir sDuplicateAggregateFunction = JavaTools.replaceSubString(sDuplicateAggregateFunction, sDisplayFunction, "<FUNCTION>"); 402cdf0e10cSrcweir CurUnoDialog.showMessageBox("WarningBox", VclWindowPeerAttribute.OK, sDuplicateAggregateFunction); 403cdf0e10cSrcweir CurUnoDialog.vetoableChange(new java.beans.PropertyChangeEvent(CurUnoDialog, "Steps", 1, 2)); 404cdf0e10cSrcweir return new String[][] 405cdf0e10cSrcweir { 406cdf0e10cSrcweir }; 407cdf0e10cSrcweir } 408cdf0e10cSrcweir else 409cdf0e10cSrcweir { 410cdf0e10cSrcweir return CurDBMetaData.AggregateFieldNames; 411cdf0e10cSrcweir } 412cdf0e10cSrcweir } 413cdf0e10cSrcweir catch (Exception exception) 414cdf0e10cSrcweir { 415cdf0e10cSrcweir exception.printStackTrace(System.out); 416cdf0e10cSrcweir return null; 417cdf0e10cSrcweir } 418cdf0e10cSrcweir } 419cdf0e10cSrcweir initialize()420cdf0e10cSrcweir public void initialize() 421cdf0e10cSrcweir { 422cdf0e10cSrcweir CurDBMetaData.setNumericFields(); 423cdf0e10cSrcweir initializeScrollFields(); 424cdf0e10cSrcweir int icount = CurDBMetaData.AggregateFieldNames.length; 425cdf0e10cSrcweir if (icount == 0) 426cdf0e10cSrcweir { 427cdf0e10cSrcweir super.initialize(1); 428cdf0e10cSrcweir hideControlRowsfromindex(1); 429cdf0e10cSrcweir } 430cdf0e10cSrcweir else 431cdf0e10cSrcweir { 432cdf0e10cSrcweir super.initialize(icount); 433cdf0e10cSrcweir hideControlRowsfromindex(icount); 434cdf0e10cSrcweir } 435cdf0e10cSrcweir toggleComponent(); 436cdf0e10cSrcweir CurUnoDialog.repaintDialogStep(); 437cdf0e10cSrcweir } 438cdf0e10cSrcweir initializeScrollFields()439cdf0e10cSrcweir protected void initializeScrollFields() 440cdf0e10cSrcweir { 441cdf0e10cSrcweir ControlRow curControlRow; 442cdf0e10cSrcweir if (CurDBMetaData.AggregateFieldNames != null) 443cdf0e10cSrcweir { 444cdf0e10cSrcweir for (int i = 0; i < this.getBlockIncrementation(); i++) 445cdf0e10cSrcweir { 446cdf0e10cSrcweir curControlRow = (ControlRow) ControlRowVector.elementAt(i); 447cdf0e10cSrcweir curControlRow.insertFieldNames(); 448cdf0e10cSrcweir } 449cdf0e10cSrcweir for (int i = 0; i <= CurDBMetaData.AggregateFieldNames.length; i++) 450cdf0e10cSrcweir { 451cdf0e10cSrcweir registerControlGroupAtIndex(i); 452cdf0e10cSrcweir } 453cdf0e10cSrcweir } 454cdf0e10cSrcweir } 455cdf0e10cSrcweir registerControlGroupAtIndex(int _index)456cdf0e10cSrcweir private void registerControlGroupAtIndex(int _index) 457cdf0e10cSrcweir { 458cdf0e10cSrcweir short[] iselfunctionlist = new short[] 459cdf0e10cSrcweir { 460cdf0e10cSrcweir }; 461cdf0e10cSrcweir short[] iselfieldslist = new short[] 462cdf0e10cSrcweir { 463cdf0e10cSrcweir }; 464cdf0e10cSrcweir PropertyValue[] currowproperties = new PropertyValue[2]; 465cdf0e10cSrcweir if (_index < CurDBMetaData.AggregateFieldNames.length) 466cdf0e10cSrcweir { 467cdf0e10cSrcweir short iselfieldsindex = (short) JavaTools.FieldInList(CurDBMetaData.NumericFieldNames, CurDBMetaData.AggregateFieldNames[_index][0]); 468cdf0e10cSrcweir iselfieldslist = new short[] 469cdf0e10cSrcweir { 470cdf0e10cSrcweir iselfieldsindex 471cdf0e10cSrcweir }; 472cdf0e10cSrcweir short iselfunctionindex = (short) JavaTools.FieldInList(sFunctionOperators, CurDBMetaData.AggregateFieldNames[_index][1]); 473cdf0e10cSrcweir iselfunctionlist = new short[] 474cdf0e10cSrcweir { 475cdf0e10cSrcweir iselfunctionindex 476cdf0e10cSrcweir }; 477cdf0e10cSrcweir } 478cdf0e10cSrcweir currowproperties[0] = Properties.createProperty(getFunctionControlName(_index), iselfunctionlist, _index); 479cdf0e10cSrcweir currowproperties[1] = Properties.createProperty(getFieldsControlName(_index), iselfieldslist, _index); //getTitleName(i) 480cdf0e10cSrcweir super.registerControlGroup(currowproperties, _index); 481cdf0e10cSrcweir } 482cdf0e10cSrcweir getFunctionControlName(int _index)483cdf0e10cSrcweir private String getFunctionControlName(int _index) 484cdf0e10cSrcweir { 485cdf0e10cSrcweir String namesuffix = "_" + String.valueOf(_index + 1); 486cdf0e10cSrcweir return "lstfunctions" + namesuffix; 487cdf0e10cSrcweir } 488cdf0e10cSrcweir getFieldsControlName(int _index)489cdf0e10cSrcweir private String getFieldsControlName(int _index) 490cdf0e10cSrcweir { 491cdf0e10cSrcweir String namesuffix = "_" + String.valueOf(_index + 1); 492cdf0e10cSrcweir return "lstFieldnames" + namesuffix; 493cdf0e10cSrcweir } 494cdf0e10cSrcweir hasonlycompletefunctions()495cdf0e10cSrcweir private boolean hasonlycompletefunctions() 496cdf0e10cSrcweir { 497cdf0e10cSrcweir int maxfieldcount = super.getCurFieldCount(); 498cdf0e10cSrcweir if (maxfieldcount > 0) 499cdf0e10cSrcweir { 500cdf0e10cSrcweir ControlRow curcontrolrow = (ControlRow) this.ControlRowVector.elementAt(maxfieldcount - 1); 501cdf0e10cSrcweir return curcontrolrow.isComplete(); 502cdf0e10cSrcweir } 503cdf0e10cSrcweir else 504cdf0e10cSrcweir { 505cdf0e10cSrcweir return false; 506cdf0e10cSrcweir } 507cdf0e10cSrcweir } 508cdf0e10cSrcweir 509cdf0e10cSrcweir protected class ControlRow 510cdf0e10cSrcweir { 511cdf0e10cSrcweir 512cdf0e10cSrcweir private XListBox xFieldListBox; 513cdf0e10cSrcweir private XListBox xFunctionListBox; 514cdf0e10cSrcweir private int index; 515cdf0e10cSrcweir ControlRow(int _index, int ypos, int _curHelpID)516cdf0e10cSrcweir protected ControlRow(int _index, int ypos, int _curHelpID) 517cdf0e10cSrcweir { 518cdf0e10cSrcweir try 519cdf0e10cSrcweir { 520cdf0e10cSrcweir this.index = _index; 521cdf0e10cSrcweir xFunctionListBox = CurUnoDialog.insertListBox(getFunctionControlName(index), 1, null, new ItemListenerImpl(), 522cdf0e10cSrcweir new String[] 523cdf0e10cSrcweir { 524cdf0e10cSrcweir "Dropdown", PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.STRING_ITEM_LIST, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 525cdf0e10cSrcweir }, 526cdf0e10cSrcweir new Object[] 527cdf0e10cSrcweir { 528cdf0e10cSrcweir Boolean.TRUE, 12, HelpIds.getHelpIdString(_curHelpID++), new Integer(iCompPosX + 4), new Integer(ypos), UIConsts.INVISIBLESTEP, sFunctions, new Short(curtabindex++), 88 529cdf0e10cSrcweir }); 530cdf0e10cSrcweir 531cdf0e10cSrcweir xFieldListBox = CurUnoDialog.insertListBox(getFieldsControlName(index), 1, null, new ItemListenerImpl(), 532cdf0e10cSrcweir new String[] 533cdf0e10cSrcweir { 534cdf0e10cSrcweir "Dropdown", PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 535cdf0e10cSrcweir }, 536cdf0e10cSrcweir new Object[] 537cdf0e10cSrcweir { 538cdf0e10cSrcweir Boolean.TRUE, 12, HelpIds.getHelpIdString(_curHelpID++), new Integer(iCompPosX + 98), new Integer(ypos), UIConsts.INVISIBLESTEP, new Short(curtabindex++), 86 539cdf0e10cSrcweir }); 540cdf0e10cSrcweir lastHelpIndex = _curHelpID - 1; 541cdf0e10cSrcweir } 542cdf0e10cSrcweir catch (Exception exception) 543cdf0e10cSrcweir { 544cdf0e10cSrcweir exception.printStackTrace(System.out); 545cdf0e10cSrcweir } 546cdf0e10cSrcweir } 547cdf0e10cSrcweir getSelectedFieldName()548cdf0e10cSrcweir private String getSelectedFieldName() 549cdf0e10cSrcweir { 550cdf0e10cSrcweir return xFieldListBox.getSelectedItem(); 551cdf0e10cSrcweir } 552cdf0e10cSrcweir getSelectedFunction()553cdf0e10cSrcweir private String getSelectedFunction() 554cdf0e10cSrcweir { 555cdf0e10cSrcweir return xFunctionListBox.getSelectedItem(); 556cdf0e10cSrcweir } 557cdf0e10cSrcweir setVisible(boolean _bvisible)558cdf0e10cSrcweir private void setVisible(boolean _bvisible) 559cdf0e10cSrcweir { 560cdf0e10cSrcweir CurUnoDialog.setControlVisible(getFunctionControlName(index), _bvisible); 561cdf0e10cSrcweir CurUnoDialog.setControlVisible(getFieldsControlName(index), _bvisible); 562cdf0e10cSrcweir } 563cdf0e10cSrcweir insertFieldNames()564cdf0e10cSrcweir private void insertFieldNames() 565cdf0e10cSrcweir { 566cdf0e10cSrcweir Helper.setUnoPropertyValue(UnoDialog.getModel(xFieldListBox), PropertyNames.STRING_ITEM_LIST, CurDBMetaData.NumericFieldNames); 567cdf0e10cSrcweir } 568cdf0e10cSrcweir isComplete()569cdf0e10cSrcweir private boolean isComplete() 570cdf0e10cSrcweir { 571cdf0e10cSrcweir boolean bfieldnameisselected = (Helper.getUnoArrayPropertyValue(UnoDialog.getModel(xFieldListBox), PropertyNames.SELECTED_ITEMS) != null); 572cdf0e10cSrcweir boolean bfunctionisselected = (Helper.getUnoArrayPropertyValue(UnoDialog.getModel(xFunctionListBox), PropertyNames.SELECTED_ITEMS) != null); 573cdf0e10cSrcweir return (bfieldnameisselected && bfunctionisselected); 574cdf0e10cSrcweir } 575cdf0e10cSrcweir settovoid()576cdf0e10cSrcweir private void settovoid() 577cdf0e10cSrcweir { 578cdf0e10cSrcweir CurUnoDialog.deselectListBox(xFieldListBox); 579cdf0e10cSrcweir CurUnoDialog.deselectListBox(xFunctionListBox); 580cdf0e10cSrcweir } 581cdf0e10cSrcweir 582cdf0e10cSrcweir protected class ItemListenerImpl implements com.sun.star.awt.XItemListener 583cdf0e10cSrcweir { 584cdf0e10cSrcweir itemStateChanged(com.sun.star.awt.ItemEvent EventObject)585cdf0e10cSrcweir public void itemStateChanged(com.sun.star.awt.ItemEvent EventObject) 586cdf0e10cSrcweir { 587cdf0e10cSrcweir try 588cdf0e10cSrcweir { 589cdf0e10cSrcweir toggleButtons(); 590cdf0e10cSrcweir togglefollowingDialogSteps(); 591cdf0e10cSrcweir } 592cdf0e10cSrcweir catch (Exception exception) 593cdf0e10cSrcweir { 594cdf0e10cSrcweir exception.printStackTrace(System.out); 595cdf0e10cSrcweir } 596cdf0e10cSrcweir } 597cdf0e10cSrcweir disposing(com.sun.star.lang.EventObject eventObject)598cdf0e10cSrcweir public void disposing(com.sun.star.lang.EventObject eventObject) 599cdf0e10cSrcweir { 600cdf0e10cSrcweir } 601cdf0e10cSrcweir } 602cdf0e10cSrcweir } 603cdf0e10cSrcweir } 604